diff --git a/rust/ares/src/hamt.rs b/rust/ares/src/hamt.rs index 5c63173..e940b36 100644 --- a/rust/ares/src/hamt.rs +++ b/rust/ares/src/hamt.rs @@ -259,6 +259,9 @@ assert_eq_size!(&[Entry<()>], Stem<()>); pub struct Hamt(Stem); impl Hamt { + pub fn is_null(&self) -> bool { + self.0.bitmap == 0 + } // Make a new, empty HAMT pub fn new() -> Self { Hamt(Stem { diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 58aaa98..1c24f0e 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -17,6 +17,7 @@ use ares_macros::tas; use assert_no_alloc::assert_no_alloc; use bitvec::prelude::{BitSlice, Lsb0}; use either::Either::*; +use std::result; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -284,6 +285,8 @@ impl From for Error { } } +pub type Result = result::Result; + #[allow(unused_variables)] fn debug_assertions(stack: &mut NockStack, noun: Noun) { assert_acyclic!(noun); @@ -292,7 +295,7 @@ fn debug_assertions(stack: &mut NockStack, noun: Noun) { } /** Interpret nock */ -pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Result { +pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Result { let terminator = Arc::clone(&TERMINATOR); let orig_subject = subject; // for debugging let virtual_frame: *const u64 = context.stack.get_frame_pointer(); @@ -671,51 +674,54 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } NockWork::Work11D(mut dint) => match dint.todo { Todo11D::ComputeHint => { - match hint::match_pre_hint(context, subject, dint.tag, dint.hint, dint.body) + if let Some(ret) = + hint::match_pre_hint(context, subject, dint.tag, dint.hint, dint.body) { - Ok(Some(found)) => { - res = found; - context.stack.pop::(); - } - Ok(None) => { - dint.todo = Todo11D::ComputeResult; - *context.stack.top() = NockWork::Work11D(dint); - push_formula(&mut context.stack, dint.hint, false)?; - } - Err(err) => { - break Err(err); + match ret { + Ok(found) => { + res = found; + context.stack.pop::(); + } + Err(err) => { + break Err(err); + } } + } else { + dint.todo = Todo11D::ComputeResult; + *context.stack.top() = NockWork::Work11D(dint); + push_formula(&mut context.stack, dint.hint, false)?; } } Todo11D::ComputeResult => { - match hint::match_pre_nock( + if let Some(ret) = hint::match_pre_nock( context, subject, dint.tag, Some((dint.hint, res)), dint.body, ) { - Ok(Some(found)) => { - res = found; - context.stack.pop::(); - } - Ok(None) => { - if dint.tail { + match ret { + Ok(found) => { + res = found; context.stack.pop::(); - } else { - dint.todo = Todo11D::Done; - dint.hint = res; - *context.stack.top() = NockWork::Work11D(dint); } - push_formula(&mut context.stack, dint.body, dint.tail)?; + Err(err) => { + break Err(err); + } } - Err(err) => { - break Err(err); + } else { + if dint.tail { + context.stack.pop::(); + } else { + dint.todo = Todo11D::Done; + dint.hint = res; + *context.stack.top() = NockWork::Work11D(dint); } + push_formula(&mut context.stack, dint.body, dint.tail)?; } } Todo11D::Done => { - match hint::match_post_nock( + if let Some(found) = hint::match_post_nock( context, subject, dint.tag, @@ -723,41 +729,40 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res dint.body, res, ) { - Ok(Some(found)) => res = found, - Err(err) => break Err(err), - _ => {} + res = found; } context.stack.pop::(); } }, NockWork::Work11S(mut sint) => match sint.todo { Todo11S::ComputeResult => { - match hint::match_pre_nock(context, subject, sint.tag, None, sint.body) { - Ok(Some(found)) => { - res = found; - context.stack.pop::(); - } - Ok(None) => { - if sint.tail { + if let Some(ret) = + hint::match_pre_nock(context, subject, sint.tag, None, sint.body) + { + match ret { + Ok(found) => { + res = found; context.stack.pop::(); - } else { - sint.todo = Todo11S::Done; - *context.stack.top() = NockWork::Work11S(sint); } - push_formula(&mut context.stack, sint.body, sint.tail)?; + Err(err) => { + break Err(err); + } } - Err(err) => { - break Err(err); + } else { + if sint.tail { + context.stack.pop::(); + } else { + sint.todo = Todo11S::Done; + *context.stack.top() = NockWork::Work11S(sint); } + push_formula(&mut context.stack, sint.body, sint.tail)?; } } Todo11S::Done => { - match hint::match_post_nock( - context, subject, sint.tag, None, sint.body, res, - ) { - Ok(Some(found)) => res = found, - Err(err) => break Err(err), - _ => {} + if let Some(found) = + hint::match_post_nock(context, subject, sint.tag, None, sint.body, res) + { + res = found; } context.stack.pop::(); } @@ -849,7 +854,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } } -fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> Result<(), Error> { +fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> result::Result<(), Error> { unsafe { if let Ok(formula_cell) = formula.as_cell() { // Formula @@ -1077,6 +1082,7 @@ pub fn exit(context: &mut Context, virtual_frame: *const u64, error: Error) -> E while (stack).get_frame_pointer() != virtual_frame { (stack).preserve(&mut preserve); + // (stack).preserve(&mut context.cold); (stack).frame_pop(); } @@ -1222,12 +1228,12 @@ mod hint { tag: Atom, hint: Noun, body: Noun, - ) -> Result, Error> { + ) -> Option { // XX: handle IndirectAtom tags - match tag.as_direct()?.data() { + match tag.direct()?.data() { tas!(b"sham") => { if cfg!(feature = "sham_hints") { - let jet_formula = hint.as_cell()?; + let jet_formula = hint.cell()?; // XX: what is the head here? let jet_name = jet_formula.tail(); @@ -1258,9 +1264,9 @@ mod hint { let tape = tape(stack, "jet mismatch"); let mean = T(stack, &[D(tas!(b"mean")), tape]); mean_push(stack, mean); - Err(Error::Deterministic(D(0))) + Some(Err(Error::Deterministic(D(0)))) } else { - Ok(Some(nock_res)) + Some(Ok(nock_res)) } } Err(error) => { @@ -1277,17 +1283,17 @@ mod hint { match error { Error::NonDeterministic(_) => { - Err(Error::NonDeterministic(D(0))) + Some(Err(Error::NonDeterministic(D(0)))) } - _ => Err(Error::Deterministic(D(0))), + _ => Some(Err(Error::Deterministic(D(0)))), } } } } else { - Ok(Some(jet_res)) + Some(Ok(jet_res)) } } - Err(JetErr::Punt) => Ok(None), + Err(JetErr::Punt) => None, Err(err) => { let stack = &mut context.stack; // XX: need string interpolation without allocation @@ -1295,22 +1301,22 @@ mod hint { let tape = tape(stack, "jet error"); let mean = T(stack, &[D(tas!(b"mean")), tape]); mean_push(stack, mean); - Err(err.into()) + Some(Err(err.into())) } } } else { - Ok(None) + None } } else { - Ok(None) + None } } tas!(b"memo") => { let stack = &mut context.stack; let mut key = Cell::new(stack, subject, body).as_noun(); - Ok(context.cache.lookup(stack, &mut key)) + context.cache.lookup(stack, &mut key).map(Ok) } - _ => Ok(None), + _ => None, } } @@ -1321,32 +1327,30 @@ mod hint { tag: Atom, hint: Option<(Noun, Noun)>, _body: Noun, - ) -> Result, Error> { + ) -> Option { // XX: handle IndirectAtom tags - match tag.as_direct()?.data() { + match tag.direct()?.data() { tas!(b"slog") => { let stack = &mut context.stack; let newt = &mut context.newt; - let (_form, clue) = hint.ok_or(Error::Deterministic(D(0)))?; - let slog_cell = clue.as_cell()?; - let pri = slog_cell.head().as_direct()?.data(); + let (_form, clue) = hint?; + let slog_cell = clue.cell()?; + let pri = slog_cell.head().direct()?.data(); let tank = slog_cell.tail(); newt.slog(stack, pri, tank); - Ok(None) } tas!(b"hand") | tas!(b"hunk") | tas!(b"lose") | tas!(b"mean") | tas!(b"spot") => { let terminator = Arc::clone(&TERMINATOR); if (*terminator).load(Ordering::Relaxed) { - return Err(Error::NonDeterministic(D(0))); + return Some(Err(Error::NonDeterministic(D(0)))); } let stack = &mut context.stack; - let (_form, clue) = hint.ok_or(Error::Deterministic(D(0)))?; + let (_form, clue) = hint?; let noun = T(stack, &[tag.as_noun(), clue]); mean_push(stack, noun); - Ok(None) } tas!(b"hela") => { // XX: This only prints the trace down to the bottom of THIS @@ -1361,10 +1365,7 @@ mod hint { let newt = &mut context.newt; if unsafe { !toon.head().raw_equals(D(2)) } { - let tape = tape(stack, "%hela failed: toon not %2"); - let mean = T(stack, &[D(tas!(b"mean")), tape]); - mean_push(stack, mean); - return Err(Error::Deterministic(D(0))); + panic!("serf: %hela: mook returned invalid tone"); } let mut list = toon.tail(); @@ -1373,25 +1374,28 @@ mod hint { break; } - let cell = list.as_cell().unwrap(); - newt.slog(stack, 0, cell.head()); - - list = cell.tail(); + if let Ok(cell) = list.as_cell() { + newt.slog(stack, 0, cell.head()); + list = cell.tail(); + } else { + let stack = &mut context.stack; + let tape = tape(stack, "serf: %hela: list ends without ~"); + slog_leaf(stack, newt, tape); + break; + } } - - Ok(None) } - Err(err) => { + Err(_) => { let stack = &mut context.stack; - let tape = tape(stack, "%hela failed: mook error"); - let mean = T(stack, &[D(tas!(b"mean")), tape]); - mean_push(stack, mean); - Err(err.into()) + let tape = tape(stack, "serf: %hela: mook error"); + slog_leaf(stack, &mut context.newt, tape); } } } - _ => Ok(None), - } + _ => {} + }; + + None } /** Match static and dynamic hints after the nock formula is evaluated */ @@ -1402,7 +1406,7 @@ mod hint { hint: Option, body: Noun, res: Noun, - ) -> Result, Error> { + ) -> Option { let stack = &mut context.stack; let newt = &mut context.newt; let cold = &mut context.cold; @@ -1410,7 +1414,7 @@ mod hint { let cache = &mut context.cache; // XX: handle IndirectAtom tags - match tag.as_direct()?.data() { + match tag.direct()?.data() { tas!(b"memo") => { let mut key = Cell::new(stack, subject, body).as_noun(); context.cache = cache.insert(stack, &mut key, res); @@ -1422,12 +1426,32 @@ mod hint { if !cfg!(feature = "sham_hints") { if let Some(clue) = hint { let cold_res: cold::Result = { - let chum = clue.slot(2)?; - let parent_formula_op = clue.slot(12)?.as_atom()?.as_direct()?; - let parent_formula_ax = clue.slot(13)?.as_atom()?; + let chum = clue.slot(2).ok()?; + + let mut parent = clue.slot(6).ok()?; + loop { + if let Ok(parent_cell) = parent.as_cell() { + if unsafe { parent_cell.head().raw_equals(D(11)) } { + match parent.slot(7) { + Ok(noun) => { + parent = noun; + } + Err(_) => { + return None; + } + } + } else { + break; + } + } else { + return None; + } + } + let parent_formula_op = parent.slot(2).ok()?.atom()?.direct()?; + let parent_formula_ax = parent.slot(3).ok()?.atom()?; if parent_formula_op.data() == 1 { - if parent_formula_ax.as_direct()?.data() == 0 { + if parent_formula_ax.direct()?.data() == 0 { cold.register(stack, res, parent_formula_ax, chum) } else { // XX: Need better message in slog; need better slogging tools @@ -1472,7 +1496,7 @@ mod hint { _ => {} } - Ok(None) + None } fn slog_leaf(stack: &mut NockStack, newt: &mut Newt, tape: Noun) { diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index 78fc9a2..ae2a8de 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -20,6 +20,7 @@ use crate::jets::form::*; use crate::jets::hash::*; use crate::jets::hot::Hot; use crate::jets::list::*; +use crate::jets::lute::*; use crate::jets::math::*; use crate::jets::nock::*; use crate::jets::serial::*; diff --git a/rust/ares/src/jets/bits.rs b/rust/ares/src/jets/bits.rs index 0271362..3898c4f 100644 --- a/rust/ares/src/jets/bits.rs +++ b/rust/ares/src/jets/bits.rs @@ -293,6 +293,12 @@ pub fn jet_rsh(context: &mut Context, subject: Noun) -> Result { } } +pub fn jet_xeb(_context: &mut Context, subject: Noun) -> Result { + let sam = slot(subject, 6)?; + let a = slot(sam, 1)?.as_atom()?; + Ok(D(util::met(0, a) as u64)) +} + /* * Bit logic */ @@ -337,12 +343,6 @@ pub fn jet_mix(context: &mut Context, subject: Noun) -> Result { } } -pub fn jet_xeb(_context: &mut Context, subject: Noun) -> Result { - let sam = slot(subject, 6)?; - let a = slot(sam, 1)?.as_atom()?; - Ok(D(util::met(0, a) as u64)) -} - pub mod util { use crate::jets::util::*; use crate::jets::Result; diff --git a/rust/ares/src/jets/cold.rs b/rust/ares/src/jets/cold.rs index 1aa998a..84f2c2b 100644 --- a/rust/ares/src/jets/cold.rs +++ b/rust/ares/src/jets/cold.rs @@ -309,6 +309,14 @@ impl Preserve for Cold { } impl Cold { + pub fn is_null(&self) -> bool { + unsafe { + (*self.0).battery_to_paths.is_null() + || (*self.0).battery_to_paths.is_null() + || (*self.0).root_to_paths.is_null() + } + } + pub fn new(stack: &mut NockStack) -> Self { let battery_to_paths = Hamt::new(); let root_to_paths = Hamt::new(); diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index ee63f56..bc2d564 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -1,59 +1,363 @@ use crate::jets::*; -use crate::noun::{Atom, DirectAtom, Noun, D, T}; +use crate::noun::{Atom, DirectAtom, IndirectAtom, Noun, D, T}; use ares_macros::tas; use either::Either::{self, Left, Right}; use std::ptr::null_mut; -const A_50: Either = Right((tas!(b"a"), 50)); +// const A_50: Either = Right((b"a", 50)); +const K_139: Either<&[u8], (u64, u64)> = Right((tas!(b"k"), 139)); + +// // This is the const state all in one spot as literals +// #[allow(clippy::complexity)] +// const SHAM_HOT_STATE: &[(&[Either], u64, Jet)] = &[ +// (&[A_50, Left(b"add")], 1, jet_add), +// (&[A_50, Left(b"dec")], 1, jet_dec), +// (&[A_50, Left(b"div")], 1, jet_div), +// (&[A_50, Left(b"dvr")], 1, jet_dvr), +// (&[A_50, Left(b"gth")], 1, jet_gth), +// (&[A_50, Left(b"gte")], 1, jet_gte), +// (&[A_50, Left(b"lte")], 1, jet_lte), +// (&[A_50, Left(b"lth")], 1, jet_lth), +// (&[A_50, Left(b"mod")], 1, jet_mod), +// (&[A_50, Left(b"mul")], 1, jet_mul), +// (&[A_50, Left(b"sub")], 1, jet_sub), +// // +// (&[A_50, Left(b"cap")], 1, jet_cap), +// (&[A_50, Left(b"mas")], 1, jet_mas), +// // +// (&[A_50, Left(b"lent")], 1, jet_lent), +// (&[A_50, Left(b"flop")], 1, jet_flop), +// // +// (&[A_50, Left(b"bex")], 1, jet_bex), +// (&[A_50, Left(b"can")], 1, jet_can), +// (&[A_50, Left(b"cat")], 1, jet_cat), +// (&[A_50, Left(b"cut")], 1, jet_cut), +// (&[A_50, Left(b"end")], 1, jet_end), +// (&[A_50, Left(b"lsh")], 1, jet_lsh), +// (&[A_50, Left(b"met")], 1, jet_met), +// (&[A_50, Left(b"rap")], 1, jet_rap), +// (&[A_50, Left(b"rep")], 1, jet_rep), +// (&[A_50, Left(b"rev")], 1, jet_rev), +// (&[A_50, Left(b"rip")], 1, jet_rip), +// (&[A_50, Left(b"rsh")], 1, jet_rsh), +// (&[A_50, Left(b"xeb")], 1, jet_xeb), +// // +// (&[A_50, Left(b"con")], 1, jet_con), +// (&[A_50, Left(b"dis")], 1, jet_dis), +// (&[A_50, Left(b"mix")], 1, jet_mix), +// // +// (&[A_50, Left(b"mug")], 1, jet_mug), +// // +// (&[A_50, Left(b"dor")], 1, jet_dor), +// (&[A_50, Left(b"gor")], 1, jet_gor), +// (&[A_50, Left(b"mor")], 1, jet_mor), +// // +// (&[A_50, Left(b"scow")], 1, jet_scow), +// // +// (&[A_50, Left(b"mink")], 1, jet_mink), +// ]; -// This is the const state all in one spot as literals #[allow(clippy::complexity)] -const HOT_STATE: &[(&[Either], u64, Jet)] = &[ - (&[A_50, Left(tas!(b"add"))], 1, jet_add), - (&[A_50, Left(tas!(b"dec"))], 1, jet_dec), - (&[A_50, Left(tas!(b"div"))], 1, jet_div), - (&[A_50, Left(tas!(b"dvr"))], 1, jet_dvr), - (&[A_50, Left(tas!(b"gth"))], 1, jet_gth), - (&[A_50, Left(tas!(b"gte"))], 1, jet_gte), - (&[A_50, Left(tas!(b"lte"))], 1, jet_lte), - (&[A_50, Left(tas!(b"lth"))], 1, jet_lth), - (&[A_50, Left(tas!(b"mod"))], 1, jet_mod), - (&[A_50, Left(tas!(b"mul"))], 1, jet_mul), - (&[A_50, Left(tas!(b"sub"))], 1, jet_sub), +const TRUE_HOT_STATE: &[(&[Either<&[u8], (u64, u64)>], u64, Jet)] = &[ + (&[K_139, Left(b"one"), Left(b"add")], 1, jet_add), + (&[K_139, Left(b"one"), Left(b"dec")], 1, jet_dec), + (&[K_139, Left(b"one"), Left(b"div")], 1, jet_div), + (&[K_139, Left(b"one"), Left(b"dvr")], 1, jet_dvr), + (&[K_139, Left(b"one"), Left(b"gte")], 1, jet_gte), + (&[K_139, Left(b"one"), Left(b"gth")], 1, jet_gth), + (&[K_139, Left(b"one"), Left(b"lte")], 1, jet_lte), + (&[K_139, Left(b"one"), Left(b"lth")], 1, jet_lth), + (&[K_139, Left(b"one"), Left(b"max")], 1, jet_max), + (&[K_139, Left(b"one"), Left(b"min")], 1, jet_min), + (&[K_139, Left(b"one"), Left(b"mod")], 1, jet_mod), + (&[K_139, Left(b"one"), Left(b"mul")], 1, jet_mul), + (&[K_139, Left(b"one"), Left(b"sub")], 1, jet_sub), // - (&[A_50, Left(tas!(b"cap"))], 1, jet_cap), - (&[A_50, Left(tas!(b"mas"))], 1, jet_mas), + (&[K_139, Left(b"one"), Left(b"cap")], 1, jet_cap), + (&[K_139, Left(b"one"), Left(b"mas")], 1, jet_mas), + (&[K_139, Left(b"one"), Left(b"peg")], 1, jet_peg), // - (&[A_50, Left(tas!(b"lent"))], 1, jet_lent), - (&[A_50, Left(tas!(b"flop"))], 1, jet_flop), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"flop")], + 1, + jet_flop, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"lent")], + 1, + jet_lent, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"zing")], + 1, + jet_zing, + ), // - (&[A_50, Left(tas!(b"bex"))], 1, jet_bex), - (&[A_50, Left(tas!(b"can"))], 1, jet_can), - (&[A_50, Left(tas!(b"cat"))], 1, jet_cat), - (&[A_50, Left(tas!(b"cut"))], 1, jet_cut), - (&[A_50, Left(tas!(b"end"))], 1, jet_end), - (&[A_50, Left(tas!(b"lsh"))], 1, jet_lsh), - (&[A_50, Left(tas!(b"met"))], 1, jet_met), - (&[A_50, Left(tas!(b"rap"))], 1, jet_rap), - (&[A_50, Left(tas!(b"rep"))], 1, jet_rep), - (&[A_50, Left(tas!(b"rev"))], 1, jet_rev), - (&[A_50, Left(tas!(b"rip"))], 1, jet_rip), - (&[A_50, Left(tas!(b"rsh"))], 1, jet_rsh), - (&[A_50, Left(tas!(b"xeb"))], 1, jet_xeb), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"bex")], + 1, + jet_bex, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"can")], + 1, + jet_can, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"cat")], + 1, + jet_cat, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"cut")], + 1, + jet_cut, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"end")], + 1, + jet_end, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"lsh")], + 1, + jet_lsh, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"met")], + 1, + jet_met, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"rap")], + 1, + jet_rap, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"rep")], + 1, + jet_rep, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"rev")], + 1, + jet_rev, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"rip")], + 1, + jet_rip, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"rsh")], + 1, + jet_rsh, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"xeb")], + 1, + jet_xeb, + ), // - (&[A_50, Left(tas!(b"con"))], 1, jet_con), - (&[A_50, Left(tas!(b"dis"))], 1, jet_dis), - (&[A_50, Left(tas!(b"mix"))], 1, jet_mix), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"con")], + 1, + jet_con, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"dis")], + 1, + jet_dis, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"mix")], + 1, + jet_mix, + ), // - (&[A_50, Left(tas!(b"mug"))], 1, jet_mug), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"mug")], + 1, + jet_mug, + ), // - (&[A_50, Left(tas!(b"dor"))], 1, jet_dor), - (&[A_50, Left(tas!(b"gor"))], 1, jet_gor), - (&[A_50, Left(tas!(b"mor"))], 1, jet_mor), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"dor")], + 1, + jet_dor, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"gor")], + 1, + jet_gor, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"mor")], + 1, + jet_mor, + ), // - (&[A_50, Left(tas!(b"scow"))], 1, jet_scow), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"cue")], + 1, + jet_cue, + ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"jam")], + 1, + jet_jam, + ), // - (&[A_50, Left(tas!(b"mink"))], 1, jet_mink), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"scow"), + ], + 1, + jet_scow, + ), + // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"mink"), + ], + 1, + jet_mink, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"mole"), + ], + 1, + jet_mole, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"mule"), + ], + 1, + jet_mule, + ), + // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"crop"), + ], + 1, + jet_ut_crop, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"fish"), + ], + 1, + jet_ut_fish, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"fuse"), + ], + 1, + jet_ut_fuse, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"mint"), + ], + 1, + jet_ut_mint, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"mull"), + ], + 1, + jet_ut_mull, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"nest"), + Left(b"nest-in"), + Left(b"nest-dext"), + ], + 1, + jet_ut_nest_dext, + ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"pen"), + Left(b"ut"), + Left(b"rest"), + ], + 1, + jet_ut_rest, + ), ]; #[derive(Copy, Clone)] @@ -63,15 +367,15 @@ impl Hot { pub fn init(stack: &mut NockStack) -> Self { unsafe { let mut next = Hot(null_mut()); - for (htap, axe, jet) in HOT_STATE { + for (htap, axe, jet) in TRUE_HOT_STATE { let mut a_path = D(0); for i in *htap { match i { Left(tas) => { - a_path = T( - stack, - &[DirectAtom::new_panic(*tas).as_atom().as_noun(), a_path], - ); + let chum = IndirectAtom::new_raw_bytes_ref(stack, tas) + .normalize_as_atom() + .as_noun(); + a_path = T(stack, &[chum, a_path]); } Right((tas, ver)) => { let chum = T( diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index 966ff1d..9610407 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -8,7 +8,7 @@ use ares_macros::tas; crate::gdb!(); -pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_crop(context: &mut Context, subject: Noun) -> Result { let rff = slot(subject, 6)?; let van = slot(subject, 7)?; @@ -37,7 +37,7 @@ pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { } } -pub fn jet_fish(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_fish(context: &mut Context, subject: Noun) -> Result { // axe must be Atom, though we use it as Noun let axe = slot(subject, 6)?.as_atom()?; let van = slot(subject, 7)?; @@ -149,7 +149,7 @@ pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result { } } -pub fn jet_ut_nest(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_nest_dext(context: &mut Context, subject: Noun) -> Result { let nest_in_core = slot(subject, 3)?; let seg = slot(nest_in_core, 12)?; diff --git a/rust/ares/src/jets/nock.rs b/rust/ares/src/jets/nock.rs index 8548665..108b63f 100644 --- a/rust/ares/src/jets/nock.rs +++ b/rust/ares/src/jets/nock.rs @@ -252,19 +252,20 @@ pub mod util { let tape = rip(stack, 3, 1, atom)?; T(stack, &[LEAF, tape]) } - Right(cell) => { - 'tank: { - if let Ok(tone) = mink(context, dat, cell.head()) { - if let Some(cell) = tone.cell() { - if cell.head().raw_equals(D(0)) { - // XX: need to check that this is - // actually a path; - // return leaf+"mook.mean" if not - break 'tank cell.tail(); - } - } - } + Right(_cell) => { + // 'tank: { + // if let Ok(tone) = mink(context, dat, cell.head()) { + // if let Some(cell) = tone.cell() { + // if cell.head().raw_equals(D(0)) { + // // XX: need to check that this is + // // actually a path; + // // return leaf+"mook.mean" if not + // break 'tank cell.tail(); + // } + // } + // } + { let stack = &mut context.stack; let tape = tape(stack, "####"); T(stack, &[LEAF, tape]) diff --git a/rust/ares/src/jets/sort.rs b/rust/ares/src/jets/sort.rs index 929a5ff..ef0319c 100644 --- a/rust/ares/src/jets/sort.rs +++ b/rust/ares/src/jets/sort.rs @@ -9,24 +9,12 @@ use std::cmp::Ordering; crate::gdb!(); -pub fn jet_mor(context: &mut Context, subject: Noun) -> jets::Result { - let stack = &mut context.stack; - +pub fn jet_dor(context: &mut Context, subject: Noun) -> jets::Result { let sam = slot(subject, 6)?; let a = slot(sam, 2)?; let b = slot(sam, 3)?; - let c = mug(stack, a); - let d = mug(stack, b); - - let e = mug(stack, c.as_noun()); - let f = mug(stack, d.as_noun()); - - match e.data().cmp(&f.data()) { - Ordering::Greater => Ok(NO), - Ordering::Less => Ok(YES), - Ordering::Equal => Ok(util::dor(stack, a, b)), - } + Ok(util::dor(&mut context.stack, a, b)) } pub fn jet_gor(context: &mut Context, subject: Noun) -> jets::Result { @@ -46,12 +34,24 @@ pub fn jet_gor(context: &mut Context, subject: Noun) -> jets::Result { } } -pub fn jet_dor(context: &mut Context, subject: Noun) -> jets::Result { +pub fn jet_mor(context: &mut Context, subject: Noun) -> jets::Result { + let stack = &mut context.stack; + let sam = slot(subject, 6)?; let a = slot(sam, 2)?; let b = slot(sam, 3)?; - Ok(util::dor(&mut context.stack, a, b)) + let c = mug(stack, a); + let d = mug(stack, b); + + let e = mug(stack, c.as_noun()); + let f = mug(stack, d.as_noun()); + + match e.data().cmp(&f.data()) { + Ordering::Greater => Ok(NO), + Ordering::Less => Ok(YES), + Ordering::Equal => Ok(util::dor(stack, a, b)), + } } pub mod util { diff --git a/rust/ares/src/noun.rs b/rust/ares/src/noun.rs index 59f1353..c151126 100644 --- a/rust/ares/src/noun.rs +++ b/rust/ares/src/noun.rs @@ -358,6 +358,10 @@ impl IndirectAtom { *(indirect.normalize()) } + pub unsafe fn new_raw_bytes_ref(allocator: &mut A, data: &[u8]) -> Self { + IndirectAtom::new_raw_bytes(allocator, data.len(), data.as_ptr()) + } + /** Make an indirect atom that can be written into. Return the atom (which should not be used * until it is written and normalized) and a mutable pointer which is the data buffer for the * indirect atom, to be written into. diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 7ba67a9..b887062 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -3,7 +3,7 @@ use crate::interpreter; use crate::interpreter::{inc, interpret, Error}; use crate::jets::cold::Cold; use crate::jets::hot::Hot; -use crate::jets::list::util::*; +use crate::jets::list::util::{lent, zing}; use crate::jets::nock::util::mook; use crate::jets::warm::Warm; use crate::mem::NockStack; @@ -38,7 +38,7 @@ impl Context { // TODO: switch to Pma when ready // let snap = &mut snapshot::pma::Pma::new(snap_path); let mut snapshot = DoubleJam::new(snap_path); - let mut stack = NockStack::new(256 << 10 << 10, 0); + let mut stack = NockStack::new(1024 << 10 << 10, 0); let newt = Newt::new(); let cache = Hamt::::new();