From 6f5e87aa05933cf2dee3c53e5edc974d7eaf0f77 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Fri, 27 Jan 2023 13:38:47 -0700 Subject: [PATCH] add decrement test and make it pass --- rust/ares/Cargo.lock | 28 ++++++++++++++-------------- rust/ares/src/interpreter.rs | 4 +++- rust/ares/src/main.rs | 8 ++++---- rust/ares/src/mem.rs | 24 +++++++++++++++--------- rust/ares/test_data/decrement.jam | Bin 0 -> 64 bytes 5 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 rust/ares/test_data/decrement.jam diff --git a/rust/ares/Cargo.lock b/rust/ares/Cargo.lock index 5f2326b..d589f6e 100644 --- a/rust/ares/Cargo.lock +++ b/rust/ares/Cargo.lock @@ -2,6 +2,20 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ares" +version = "0.1.0" +dependencies = [ + "bitvec", + "either", + "intmap", + "libc", + "memmap", + "murmur3", + "num-derive", + "num-traits", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -38,20 +52,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b357564d111300f8a33b79e06795235529a627a1f7078d2b1db7f7dcdf032874" -[[package]] -name = "iron-planet" -version = "0.1.0" -dependencies = [ - "bitvec", - "either", - "intmap", - "libc", - "memmap", - "murmur3", - "num-derive", - "num-traits", -] - [[package]] name = "libc" version = "0.2.126" diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 1292fe8..88584ad 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -262,7 +262,7 @@ pub fn interpret(stack: &mut NockStack, mut subject: Noun, formula: Noun) -> Nou } Nock8RestoreSubject => { unsafe { - subject = *(stack.local_noun_pointer(2)); + subject = *(stack.local_noun_pointer(1)); stack.pop(&mut res); }; } @@ -305,6 +305,8 @@ pub fn interpret(stack: &mut NockStack, mut subject: Noun, formula: Noun) -> Nou let tree = *stack.local_noun_pointer(3); res = edit(stack, edit_axis.as_bitslice(), res, tree); stack.pop(&mut res); + } else { + panic!("Axis into tree must be atom"); } }, Nock11ComputeHint => unsafe { diff --git a/rust/ares/src/main.rs b/rust/ares/src/main.rs index dc8a0d0..5007a46 100644 --- a/rust/ares/src/main.rs +++ b/rust/ares/src/main.rs @@ -1,7 +1,7 @@ -use iron_planet::interpreter::interpret; -use iron_planet::mem::NockStack; -use iron_planet::noun::IndirectAtom; -use iron_planet::serialization::{cue, jam}; +use ares::interpreter::interpret; +use ares::mem::NockStack; +use ares::noun::IndirectAtom; +use ares::serialization::{cue, jam}; use memmap::Mmap; use memmap::MmapMut; use std::env; diff --git a/rust/ares/src/mem.rs b/rust/ares/src/mem.rs index 453f6c3..4a1793c 100644 --- a/rust/ares/src/mem.rs +++ b/rust/ares/src/mem.rs @@ -1,4 +1,4 @@ -use crate::noun::{CellMemory, IndirectAtom, Noun, NounAllocator}; +use crate::noun::{CellMemory, IndirectAtom, Noun, NounAllocator, Cell}; use either::Either::{self, Left, Right}; use libc::{c_void, memcmp}; use memmap::MmapMut; @@ -328,7 +328,7 @@ impl NockStack { *next_dest = new_allocated.as_noun(); } Option::None => { - if (allocated.to_raw_pointer() as *const u64) > work_start + if (allocated.to_raw_pointer() as *const u64) >= work_start && (allocated.to_raw_pointer() as *const u64) < self.frame_pointer { match allocated.as_either() { @@ -363,9 +363,6 @@ impl NockStack { (*new_cell_alloc).metadata = (*cell.to_raw_pointer()).metadata; - // Set the forwarding pointer - cell.set_forwarding_pointer(new_cell_alloc); - // Push the tail and the head to the work stack self.stack_pointer = self.stack_pointer.sub(4); *(self.stack_pointer as *mut Noun) = cell.tail(); @@ -374,6 +371,12 @@ impl NockStack { *(self.stack_pointer.add(2) as *mut Noun) = cell.head(); *(self.stack_pointer.add(3) as *mut *mut Noun) = &mut (*new_cell_alloc).head; + + // Set the forwarding pointer + cell.set_forwarding_pointer(new_cell_alloc); + + *next_dest = + Cell::from_raw_pointer(new_cell_alloc).as_noun(); } } } else { @@ -437,7 +440,7 @@ impl NockStack { } Option::None => { if (allocated.to_raw_pointer() as *const u64) < work_start - && (allocated.to_raw_pointer() as *const u64) > self.frame_pointer + && (allocated.to_raw_pointer() as *const u64) >= self.frame_pointer { match allocated.as_either() { Either::Left(mut indirect) => { @@ -471,9 +474,6 @@ impl NockStack { (*new_cell_alloc).metadata = (*cell.to_raw_pointer()).metadata; - // Set the forwarding pointer - cell.set_forwarding_pointer(new_cell_alloc); - *(self.stack_pointer as *mut Noun) = cell.tail(); *(self.stack_pointer.add(1) as *mut *mut Noun) = &mut (*new_cell_alloc).tail; @@ -481,6 +481,12 @@ impl NockStack { *(self.stack_pointer.add(3) as *mut *mut Noun) = &mut (*new_cell_alloc).head; self.stack_pointer = self.stack_pointer.add(4); + + // Set the forwarding pointer + cell.set_forwarding_pointer(new_cell_alloc); + + *next_dest = + Cell::from_raw_pointer(new_cell_alloc).as_noun(); } } } else { diff --git a/rust/ares/test_data/decrement.jam b/rust/ares/test_data/decrement.jam new file mode 100644 index 0000000000000000000000000000000000000000..46a2d558dd5d515b29a847f6cb58de4a37afa1ba GIT binary patch literal 64 zcmb1S$u8S?G*LWnaYE8`v)zFkZh|