diff --git a/rust/ares/Cargo.lock b/rust/ares/Cargo.lock index 93df99f..c4cacef 100644 --- a/rust/ares/Cargo.lock +++ b/rust/ares/Cargo.lock @@ -13,6 +13,7 @@ name = "ares" version = "0.1.0" dependencies = [ "ares_macros", + "assert_no_alloc", "bitvec", "criterion", "either", @@ -33,6 +34,12 @@ dependencies = [ "syn", ] +[[package]] +name = "assert_no_alloc" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ca83137a482d61d916ceb1eba52a684f98004f18e0cafea230fe5579c178a3" + [[package]] name = "atty" version = "0.2.14" diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index 3a1cce5..5ad9637 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -18,6 +18,7 @@ num-traits = "0.2" num-derive = "0.3" criterion = "0.4" ibig = "0.3.6" +assert_no_alloc = "1.1.2" [[bin]] name = "cue_pill" diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 3e3e6d2..f2efcc5 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -5,6 +5,7 @@ use crate::mem::NockStack; use crate::newt::Newt; use crate::noun::{Atom, Cell, DirectAtom, IndirectAtom, Noun}; use ares_macros::tas; +use assert_no_alloc::assert_no_alloc; use bitvec::prelude::{BitSlice, Lsb0}; use either::Either::*; use num_traits::cast::{FromPrimitive, ToPrimitive}; @@ -80,7 +81,7 @@ pub fn interpret( *(stack.local_noun_pointer(0)) = work_to_noun(Done); } push_formula(stack, formula); - loop { + assert_no_alloc(|| loop { match unsafe { noun_to_work(*(stack.local_noun_pointer(0))) } { Done => { stack.pop(&mut res); @@ -350,7 +351,7 @@ pub fn interpret( stack.pop(&mut res); } }; - } + }); res } diff --git a/rust/ares/src/main.rs b/rust/ares/src/main.rs index bace6be..2502fe5 100644 --- a/rust/ares/src/main.rs +++ b/rust/ares/src/main.rs @@ -3,6 +3,7 @@ use ares::mem::NockStack; use ares::noun::IndirectAtom; use ares::serf::serf; use ares::serialization::{cue, jam}; +use assert_no_alloc::AllocDisabler; use memmap::Mmap; use memmap::MmapMut; use std::env; @@ -13,6 +14,10 @@ use std::mem; use std::ptr::copy_nonoverlapping; use std::ptr::write_bytes; +#[cfg(debug_assertions)] +#[global_allocator] +static A: AllocDisabler = AllocDisabler; + fn main() -> io::Result<()> { let filename = env::args().nth(1).expect("Must provide input filename");