mirror of
https://github.com/urbit/ares.git
synced 2024-12-23 21:31:57 +03:00
now runs to completion on hurray.jam without crashing
This commit is contained in:
parent
a418d66e22
commit
ffdd91c341
@ -72,6 +72,7 @@ pub fn interpret(stack: &mut NockStack, mut subject: Noun, formula: Noun) -> Nou
|
||||
loop {
|
||||
match unsafe { noun_to_work(*(stack.local_noun_pointer(0))) } {
|
||||
Done => {
|
||||
stack.pop(&mut res);
|
||||
break;
|
||||
}
|
||||
NockCellComputeHead => {
|
||||
|
@ -37,7 +37,7 @@ fn main() -> io::Result<()> {
|
||||
let input_cell = input.as_cell().expect("Input must be jam of subject/formula pair");
|
||||
let result = interpret(&mut stack, input_cell.head(), input_cell.tail());
|
||||
let jammed_result = jam(&mut stack, result);
|
||||
let f_out = OpenOptions::new().write(true).open(output_filename)?;
|
||||
let f_out = OpenOptions::new().read(true).write(true).create(true).open(output_filename)?;
|
||||
f_out.set_len((jammed_result.size() << 3) as u64)?;
|
||||
unsafe {
|
||||
let mut out_map = MmapMut::map_mut(&f_out)?;
|
||||
|
@ -198,7 +198,7 @@ impl NockStack {
|
||||
}
|
||||
|
||||
unsafe fn top_in_previous_frame_west<T>(&mut self) -> *mut T {
|
||||
let prev_stack_pointer_pointer = self.previous_stack_pointer_pointer_east();
|
||||
let prev_stack_pointer_pointer = self.previous_stack_pointer_pointer_west();
|
||||
*prev_stack_pointer_pointer as *mut T
|
||||
}
|
||||
|
||||
@ -298,7 +298,7 @@ impl NockStack {
|
||||
unsafe fn copy_east(&mut self, noun: &mut Noun) {
|
||||
let noun_ptr = noun as *mut Noun;
|
||||
let work_start = self.stack_pointer;
|
||||
let mut other_stack_pointer = *self.previous_stack_pointer_pointer_east();
|
||||
let mut other_stack_pointer = *(self.previous_stack_pointer_pointer_east());
|
||||
self.stack_pointer = self.stack_pointer.sub(2);
|
||||
*(self.stack_pointer as *mut Noun) = *noun;
|
||||
*(self.stack_pointer.add(1) as *mut *mut Noun) = noun_ptr;
|
||||
@ -406,7 +406,7 @@ impl NockStack {
|
||||
unsafe fn copy_west(&mut self, noun: &mut Noun) {
|
||||
let noun_ptr = noun as *mut Noun;
|
||||
let work_start = self.stack_pointer;
|
||||
let mut other_stack_pointer = *self.previous_stack_pointer_pointer_west();
|
||||
let mut other_stack_pointer = *(self.previous_stack_pointer_pointer_west());
|
||||
self.stack_pointer = self.stack_pointer.add(2);
|
||||
*(self.stack_pointer.sub(2) as *mut Noun) = *noun;
|
||||
*(self.stack_pointer.sub(1) as *mut *mut Noun) = noun_ptr;
|
||||
|
@ -130,8 +130,8 @@ impl IndirectAtom {
|
||||
|
||||
pub unsafe fn forwarding_pointer(&self) -> Option<IndirectAtom> {
|
||||
let size_raw = *self.to_raw_pointer().add(1);
|
||||
if size_raw | FORWARDING_MASK == FORWARDING_TAG {
|
||||
// we can replace this by masking out thge forwarding pointer and putting in the
|
||||
if size_raw & FORWARDING_MASK == FORWARDING_TAG {
|
||||
// we can replace this by masking out the forwarding pointer and putting in the
|
||||
// indirect tag
|
||||
Some(Self::from_raw_pointer((size_raw << 3) as *const u64))
|
||||
} else {
|
||||
@ -280,7 +280,7 @@ impl Cell {
|
||||
|
||||
pub unsafe fn forwarding_pointer(&self) -> Option<Cell> {
|
||||
let head_raw = (*self.to_raw_pointer()).head.raw;
|
||||
if head_raw | FORWARDING_MASK == FORWARDING_TAG {
|
||||
if head_raw & FORWARDING_MASK == FORWARDING_TAG {
|
||||
// we can replace this by masking out the forwarding pointer and putting in the cell
|
||||
// tag
|
||||
Some(Self::from_raw_pointer((head_raw << 3) as *const CellMemory))
|
||||
@ -305,11 +305,11 @@ impl Cell {
|
||||
}
|
||||
|
||||
pub fn head(&self) -> Noun {
|
||||
unsafe { (*self.to_raw_pointer()).head }
|
||||
unsafe { (*(self.to_raw_pointer())).head }
|
||||
}
|
||||
|
||||
pub fn tail(&self) -> Noun {
|
||||
unsafe { (*self.to_raw_pointer()).tail }
|
||||
unsafe { (*(self.to_raw_pointer())).tail }
|
||||
}
|
||||
|
||||
pub fn as_allocated(&self) -> Allocated {
|
||||
|
@ -87,10 +87,10 @@ fn get_size(cursor: &mut usize, buffer: &BitSlice<u64, Lsb0>) -> usize {
|
||||
let mut bitsize: usize = 0;
|
||||
loop {
|
||||
if buffer[*cursor + bitsize] {
|
||||
break;
|
||||
} else {
|
||||
bitsize += 1;
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if bitsize == 0 {
|
||||
@ -171,7 +171,7 @@ pub fn jam(stack: &mut NockStack, noun: Noun) -> Atom {
|
||||
if unsafe { stack.prev_stack_pointer_equals_local(0) } {
|
||||
break;
|
||||
} else {
|
||||
let mut noun = unsafe { *(stack.top_in_previous_frame()) };
|
||||
let mut noun = unsafe { *(stack.top_in_previous_frame::<Noun>()) };
|
||||
let mug = mug_u32(stack, noun);
|
||||
match backref_map.get_mut(mug as u64) {
|
||||
None => {}
|
||||
@ -334,13 +334,13 @@ fn mat(
|
||||
if state.cursor + c_b_size + c_b_size + b_atom_size > state.slice.len() {
|
||||
Err(())
|
||||
} else {
|
||||
state.slice[state.cursor..state.cursor + c_b_size + 1].fill(true); // a 1 bit for each bit in the atom size
|
||||
state.slice.set(state.cursor + c_b_size + 1, false); // a terminating 0 bit
|
||||
state.slice[state.cursor + c_b_size + 2..state.cursor + c_b_size + c_b_size]
|
||||
state.slice[state.cursor..state.cursor + c_b_size].fill(false); // a 1 bit for each bit in the atom size
|
||||
state.slice.set(state.cursor + c_b_size, true); // a terminating 1 bit
|
||||
state.slice[state.cursor + c_b_size + 1..state.cursor + c_b_size + c_b_size]
|
||||
.copy_from_bitslice(&b_atom_size_atom.as_bitslice()[0..c_b_size - 1]); // the atom size excepting the most significant 1 (since we know where that is from the size-of-the-size)
|
||||
state.slice[state.cursor + c_b_size + c_b_size
|
||||
..state.cursor + c_b_size + c_b_size + b_atom_size]
|
||||
.copy_from_bitslice(atom.as_bitslice()); // the atom itself
|
||||
.copy_from_bitslice(&atom.as_bitslice()[0..b_atom_size]); // the atom itself
|
||||
state.cursor += c_b_size + c_b_size + b_atom_size;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user