From 66845cddfe4da2bb876bf8d16d40e9f3e9a32d7d Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 19 Oct 2023 09:11:35 -0400 Subject: [PATCH 01/11] wip: `++ut:crop` --- rust/ares/src/jets.rs | 1 + rust/ares/src/jets/lute.rs | 106 +++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 rust/ares/src/jets/lute.rs diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index 53a349f..4a1c80a 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -5,6 +5,7 @@ pub mod warm; pub mod bits; pub mod form; pub mod hash; +pub mod lute; pub mod math; pub mod nock; pub mod text; diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs new file mode 100644 index 0000000..cafb2fa --- /dev/null +++ b/rust/ares/src/jets/lute.rs @@ -0,0 +1,106 @@ +/** ++ut jets (compiler backend and pretty-printer) + */ +use ares_macros::tas; +use crate::interpreter::{Context, interpret}; +use crate::jets::util::*; +use crate::jets::JetErr::*; +use crate::jets::Result; +use crate::noun::{Noun, D, T}; + +crate::gdb!(); + +/* +u3_noun +u3wfu_crop(u3_noun cor) +{ + u3_noun bat, sut, ref, van; + + if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, 0)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + u3_weak vet = u3r_at(u3qfu_van_vet, van); + c3_m fun_m = 141 + c3__crop + ((!!vet) << 8); + u3_noun key = u3z_key_3(fun_m, sut, ref, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); + return u3z_save(key, pro); + } + } +} +*/ + +pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { + let ref_ = slot(subject, 6)?; + let van = slot(subject, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let fun = (141 + tas!(b"crop")) + ((vet.as_atom()?.as_direct()?.data() as u64) << 8); + let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, subject, slot(subject, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + context.cache.insert(context.stack, &mut key, pro); + Ok(pro) + } + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::jets::util::test::{assert_jet, assert_jet_ubig, init_stack, A}; + use crate::mem::NockStack; + use crate::noun::{Noun, D, T}; + use ibig::ubig; + + fn atoms(s: &mut NockStack) -> (Noun, Noun, Noun, Noun, Noun) { + (atom_0(s), atom_24(s), atom_63(s), atom_96(s), atom_128(s)) + } + + fn atom_0(_stack: &mut NockStack) -> Noun { + D(0) + } + + fn atom_24(_stack: &mut NockStack) -> Noun { + D(0x876543) + } + + fn atom_63(_stack: &mut NockStack) -> Noun { + D(0x7fffffffffffffff) + } + + fn atom_96(stack: &mut NockStack) -> Noun { + A(stack, &ubig!(0xfaceb00c15deadbeef123456)) + } + + fn atom_128(stack: &mut NockStack) -> Noun { + A(stack, &ubig!(0xdeadbeef12345678fedcba9876543210)) + } + + #[test] + fn test_crop() { + let s = &mut init_stack(); + } +} From fa73b698e957dc2f7d0e13eb6f9b4fa7e30e37bd Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 19 Oct 2023 09:40:25 -0400 Subject: [PATCH 02/11] wip: `++crop:ut` --- rust/ares/src/jets/lute.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index cafb2fa..acfc5f5 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -46,7 +46,8 @@ pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? let vet = slot(van, 59)?; - let fun = (141 + tas!(b"crop")) + ((vet.as_atom()?.as_direct()?.data() as u64) << 8); + let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let fun = (141 + tas!(b"crop")) + (flag << 8); let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); let pro = context.cache.lookup(context.stack, &mut key); From 32ea7e95d0e620a05b2d6adde2781582a81e4aaf Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 19 Oct 2023 09:58:56 -0400 Subject: [PATCH 03/11] wip: `++{fine,fish,fuse}:ut` --- rust/ares/src/jets/lute.rs | 146 ++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 1 deletion(-) diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index acfc5f5..267f2d9 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -9,6 +9,151 @@ use crate::noun::{Noun, D, T}; crate::gdb!(); +/* +u3_noun +u3wfu_fuse(u3_noun cor) +{ + u3_noun bat, sut, ref, van; + + if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, 0)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + u3_weak vet = u3r_at(u3qfu_van_vet, van); + c3_m fun_m = 141 + c3__fuse + ((!!vet) << 8); + u3_noun key = u3z_key_3(fun_m, sut, ref, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); + return u3z_save(key, pro); + } + } +} +*/ +pub fn jet_fuse(context: &mut Context, subject: Noun) -> Result { + let ref_ = slot(subject, 6)?; + let van = slot(subject, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let fun = (141 + tas!(b"fuse")) + (flag << 8); + let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, subject, slot(subject, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + context.cache.insert(context.stack, &mut key, pro); + Ok(pro) + } + } + } + } +} + +/* +u3_noun +u3wfu_fish(u3_noun cor) +{ + u3_noun bat, sut, axe, van; + + if ( (c3n == u3r_mean(cor, u3x_sam, &axe, u3x_con, &van, 0)) + || (c3n == u3ud(axe)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + u3_weak vet = u3r_at(u3qfu_van_vet, van); + c3_m fun_m = 141 + c3__fish + ((!!vet) << 8); + u3_noun key = u3z_key_3(fun_m, sut, axe, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); + return u3z_save(key, pro); + } + } +} +*/ +pub fn jet_fish(context: &mut Context, subject: Noun) -> Result { + let axe = slot(subject, 6)?.as_atom()?; + let van = slot(subject, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let fun = (141 + tas!(b"fish")) + (flag << 8); + let mut key = T(context.stack, &[D(fun), sut, axe.as_noun(), bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, subject, slot(subject, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + context.cache.insert(context.stack, &mut key, pro); + Ok(pro) + } + } + } + } +} + +/* +u3_noun +u3qf_fine(u3_noun fuv, + u3_noun lup, + u3_noun mar) +{ + if ( (c3__void == lup) || (c3__void == mar) ) { + return c3__void; + } else { + return u3nq(c3__fine, + u3k(fuv), + u3k(lup), + u3k(mar)); + } +} +*/ +pub fn jet_fine(context: &mut Context, subject: Noun) -> Result { + let fuv = slot(subject, 12)?; + let lup = slot(subject, 26)?.as_direct()?; + let mar = slot(subject, 27)?.as_direct()?; + + if tas!(b"void") == lup.data() || tas!(b"void") == mar.data() { + Ok(D(tas!(b"void"))) + } else { + Ok(T(context.stack, &[D(tas!(b"fine")), fuv, lup.as_noun(), mar.as_noun()])) + } +} + /* u3_noun u3wfu_crop(u3_noun cor) @@ -38,7 +183,6 @@ u3wfu_crop(u3_noun cor) } } */ - pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { let ref_ = slot(subject, 6)?; let van = slot(subject, 7)?; From 9999d1f83739ce010f2052fe9e2d40cf758894b8 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 19 Oct 2023 10:53:24 -0400 Subject: [PATCH 04/11] wip: `++{rest,nest,mull,mint}:ut` jets --- rust/ares/src/jets/lute.rs | 265 ++++++++++++++++++++++++++++++++++++- 1 file changed, 264 insertions(+), 1 deletion(-) diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index 267f2d9..278e140 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -5,10 +5,273 @@ use crate::interpreter::{Context, interpret}; use crate::jets::util::*; use crate::jets::JetErr::*; use crate::jets::Result; -use crate::noun::{Noun, D, T}; +use crate::noun::{Noun, D, T, YES, NO}; crate::gdb!(); +/* +u3_noun +u3wfu_rest(u3_noun cor) +{ + u3_noun bat, sut, leg, van; + + if ( (c3n == u3r_mean(cor, u3x_sam, &leg, u3x_con, &van, 0)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + u3_weak vet = u3r_at(u3qfu_van_vet, van); + c3_m fun_m = 141 + c3__rest + ((!!vet) << 8); + u3_noun key = u3z_key_3(fun_m, sut, leg, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); + return u3z_save(key, pro); + } + } +} +*/ +pub fn jet_rest(context: &mut Context, subject: Noun) -> Result { + let leg = slot(subject, 6)?; + let van = slot(subject, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let fun = (141 + tas!(b"rest")) + (flag << 8); + let mut key = T(context.stack, &[D(fun), sut, leg, bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, subject, slot(subject, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + context.cache.insert(context.stack, &mut key, pro); + Ok(pro) + } + } + } + } +} + +/* +u3_noun +u3wfu_nest_dext(u3_noun dext_core) +{ + u3_noun nest_in_core, nest_core; + u3_noun bat, sut, ref, van, seg, reg, gil; + + if ( (u3_none == (nest_in_core = u3r_at(3, dext_core))) + || (c3n == u3r_mean(nest_in_core, u3x_sam_2, &seg, + u3x_sam_6, ®, + u3x_sam_7, &gil, + u3x_con, &nest_core, 0)) + || (c3n == u3r_mean(nest_core, u3x_sam_3, &ref, + u3x_con, &van, 0)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + u3_weak vet = u3r_at(u3qfu_van_vet, van); + c3_m fun_m = 141 + c3__dext + ((!!vet) << 8); + u3_noun key = u3z_key_3(fun_m, sut, ref, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(dext_core), u3k(u3x_at(u3x_bat, dext_core))); + + if ( ((c3y == pro) && (u3_nul == reg)) || + ((c3n == pro) && (u3_nul == seg)) ) + { + return u3z_save(key, pro); + } + else { + u3z(key); + return pro; + } + } + } +} +*/ +pub fn jet_nest(context: &mut Context, subject: Noun) -> Result { + let nest_in_core = slot(subject, 3)?; + let seg = slot(nest_in_core, 12)?; + let reg = slot(nest_in_core, 26)?; + // let gil = slot(nest_in_core, 27)?; + let nest_core = slot(nest_in_core, 7)?; + let ref_ = slot(nest_core, 13)?; + let van = slot(nest_core, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let fun = (141 + tas!(b"dext")) + (flag << 8); + let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, nest_in_core, slot(nest_in_core, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + if (unsafe { pro.raw_equals(YES) && reg.raw_equals(D(0)) } ) || + (unsafe { pro.raw_equals(NO) && seg.raw_equals(D(0)) } ) { + context.cache.insert(context.stack, &mut key, pro); + } + Ok(pro) + } + } + } + } +} + +/* +u3_noun +u3wfu_mull(u3_noun cor) +{ + u3_noun bat, sut, gol, dox, gen, van; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &gol, + u3x_sam_6, &dox, + u3x_sam_7, &gen, + u3x_con, &van, 0)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + u3_weak vet = u3r_at(u3qfu_van_vet, van); + c3_m fun_m = 141 + c3__mull + ((!!vet) << 8); + u3_noun key = u3z_key_5(fun_m, sut, gol, dox, gen, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); + return u3z_save(key, pro); + } + } +} +*/ +pub fn jet_mull(context: &mut Context, subject: Noun) -> Result { + let gol = slot(subject, 12)?; + let dox = slot(subject, 26)?; + let gen = slot(subject, 27)?; + let van = slot(subject, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let fun = (141 + tas!(b"mull")) + (flag << 8); + let mut key = T(context.stack, &[D(fun), sut, gol, dox, gen, bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, subject, slot(subject, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + context.cache.insert(context.stack, &mut key, pro); + Ok(pro) + } + } + } + } +} + +/* +u3_noun +u3wfu_mint(u3_noun cor) +{ + u3_noun bat, sut, gol, gen, van; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &gol, + u3x_sam_3, &gen, + u3x_con, &van, 0)) + || (u3_none == (bat = u3r_at(u3x_bat, van))) + || (u3_none == (sut = u3r_at(u3x_sam, van))) ) + { + return u3m_bail(c3__fail); + } + else { + c3_m fun_m = 141 + c3__mint; + u3_noun vet = u3r_at(u3qfu_van_vet, van); + u3_noun key = u3z_key_5(fun_m, vet, sut, gol, gen, bat); + u3_weak pro = u3z_find(key); + + if ( u3_none != pro ) { + u3z(key); + return pro; + } + else { + pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); + return u3z_save(key, pro); + } + } +} +*/ +pub fn jet_mint(context: &mut Context, subject: Noun) -> Result { + let gol = slot(subject, 12)?; + let gen = slot(subject, 13)?; + let van = slot(subject, 7)?; + let bat = slot(van , 2)?; + let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? + + let vet = slot(van, 59)?; + let fun = 141 + tas!(b"mint"); + let mut key = T(context.stack, &[D(fun), vet, sut, gol, gen, bat]); + let pro = context.cache.lookup(context.stack, &mut key); + + match pro { + Some(pro) => Ok(pro), + None => { + let res = interpret(context, subject, slot(subject, 2)?); + match res { + Err(_) => { + Err(Deterministic) + }, + Ok(pro) => { + context.cache.insert(context.stack, &mut key, pro); + Ok(pro) + } + } + } + } +} + /* u3_noun u3wfu_fuse(u3_noun cor) From e76f7007855f0cbf875b2db4f8df332be7aeb892 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Fri, 27 Oct 2023 01:03:07 -0400 Subject: [PATCH 05/11] Fixup mismatches and make idiomatic --- rust/ares/src/jets.rs | 6 + rust/ares/src/jets/lute.rs | 564 +++++++++---------------------------- rust/ares/src/noun.rs | 5 + 3 files changed, 145 insertions(+), 430 deletions(-) diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index 3430193..62893bd 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -52,6 +52,12 @@ impl From for JetErr { } } +impl From for JetErr { + fn from(e: Error) -> Self { + Self::Fail(e) + } +} + impl From for () { fn from(_: JetErr) -> Self {} } diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index 278e140..8bfc71a 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -1,514 +1,218 @@ /** ++ut jets (compiler backend and pretty-printer) */ -use ares_macros::tas; -use crate::interpreter::{Context, interpret}; +use crate::interpreter::{interpret, Context}; use crate::jets::util::*; -use crate::jets::JetErr::*; use crate::jets::Result; -use crate::noun::{Noun, D, T, YES, NO}; +use crate::noun::{Noun, D, NO, NONE, T, YES}; +use ares_macros::tas; crate::gdb!(); -/* -u3_noun -u3wfu_rest(u3_noun cor) -{ - u3_noun bat, sut, leg, van; - - if ( (c3n == u3r_mean(cor, u3x_sam, &leg, u3x_con, &van, 0)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - u3_weak vet = u3r_at(u3qfu_van_vet, van); - c3_m fun_m = 141 + c3__rest + ((!!vet) << 8); - u3_noun key = u3z_key_3(fun_m, sut, leg, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); - return u3z_save(key, pro); - } - } -} -*/ -pub fn jet_rest(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_rest(context: &mut Context, subject: Noun) -> Result { let leg = slot(subject, 6)?; let van = slot(subject, 7)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - let vet = slot(van, 59)?; - let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; - let fun = (141 + tas!(b"rest")) + (flag << 8); - let mut key = T(context.stack, &[D(fun), sut, leg, bat]); - let pro = context.cache.lookup(context.stack, &mut key); + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; - match pro { + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"rest") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, leg, bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), None => { - let res = interpret(context, subject, slot(subject, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - context.cache.insert(context.stack, &mut key, pro); - Ok(pro) - } - } + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) } } } -/* -u3_noun -u3wfu_nest_dext(u3_noun dext_core) -{ - u3_noun nest_in_core, nest_core; - u3_noun bat, sut, ref, van, seg, reg, gil; - - if ( (u3_none == (nest_in_core = u3r_at(3, dext_core))) - || (c3n == u3r_mean(nest_in_core, u3x_sam_2, &seg, - u3x_sam_6, ®, - u3x_sam_7, &gil, - u3x_con, &nest_core, 0)) - || (c3n == u3r_mean(nest_core, u3x_sam_3, &ref, - u3x_con, &van, 0)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - u3_weak vet = u3r_at(u3qfu_van_vet, van); - c3_m fun_m = 141 + c3__dext + ((!!vet) << 8); - u3_noun key = u3z_key_3(fun_m, sut, ref, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(dext_core), u3k(u3x_at(u3x_bat, dext_core))); - - if ( ((c3y == pro) && (u3_nul == reg)) || - ((c3n == pro) && (u3_nul == seg)) ) - { - return u3z_save(key, pro); - } - else { - u3z(key); - return pro; - } - } - } -} -*/ -pub fn jet_nest(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_nest(context: &mut Context, subject: Noun) -> Result { let nest_in_core = slot(subject, 3)?; + let seg = slot(nest_in_core, 12)?; let reg = slot(nest_in_core, 26)?; - // let gil = slot(nest_in_core, 27)?; let nest_core = slot(nest_in_core, 7)?; - let ref_ = slot(nest_core, 13)?; + + let rff = slot(nest_core, 13)?; let van = slot(nest_core, 7)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - let vet = slot(van, 59)?; - let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; + + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; let fun = (141 + tas!(b"dext")) + (flag << 8); - let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); - let pro = context.cache.lookup(context.stack, &mut key); + let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); - match pro { + match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), None => { - let res = interpret(context, nest_in_core, slot(nest_in_core, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - if (unsafe { pro.raw_equals(YES) && reg.raw_equals(D(0)) } ) || - (unsafe { pro.raw_equals(NO) && seg.raw_equals(D(0)) } ) { - context.cache.insert(context.stack, &mut key, pro); - } - Ok(pro) - } + let pro = interpret(context, subject, slot(subject, 2)?)?; + if unsafe { pro.raw_equals(YES) && reg.raw_equals(D(0)) } + || unsafe { pro.raw_equals(NO) && seg.raw_equals(D(0)) } + { + context.cache.insert(&mut context.stack, &mut key, pro); } + Ok(pro) } } } -/* -u3_noun -u3wfu_mull(u3_noun cor) -{ - u3_noun bat, sut, gol, dox, gen, van; - - if ( (c3n == u3r_mean(cor, u3x_sam_2, &gol, - u3x_sam_6, &dox, - u3x_sam_7, &gen, - u3x_con, &van, 0)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - u3_weak vet = u3r_at(u3qfu_van_vet, van); - c3_m fun_m = 141 + c3__mull + ((!!vet) << 8); - u3_noun key = u3z_key_5(fun_m, sut, gol, dox, gen, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); - return u3z_save(key, pro); - } - } -} -*/ -pub fn jet_mull(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result { let gol = slot(subject, 12)?; let dox = slot(subject, 26)?; let gen = slot(subject, 27)?; let van = slot(subject, 7)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - let vet = slot(van, 59)?; - let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; - let fun = (141 + tas!(b"mull")) + (flag << 8); - let mut key = T(context.stack, &[D(fun), sut, gol, dox, gen, bat]); - let pro = context.cache.lookup(context.stack, &mut key); + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; - match pro { + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"mull") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, gol, dox, gen, bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), None => { - let res = interpret(context, subject, slot(subject, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - context.cache.insert(context.stack, &mut key, pro); - Ok(pro) - } - } + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) } } } -/* -u3_noun -u3wfu_mint(u3_noun cor) -{ - u3_noun bat, sut, gol, gen, van; - - if ( (c3n == u3r_mean(cor, u3x_sam_2, &gol, - u3x_sam_3, &gen, - u3x_con, &van, 0)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - c3_m fun_m = 141 + c3__mint; - u3_noun vet = u3r_at(u3qfu_van_vet, van); - u3_noun key = u3z_key_5(fun_m, vet, sut, gol, gen, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); - return u3z_save(key, pro); - } - } -} -*/ -pub fn jet_mint(context: &mut Context, subject: Noun) -> Result { +pub fn jet_ut_mint(context: &mut Context, subject: Noun) -> Result { let gol = slot(subject, 12)?; let gen = slot(subject, 13)?; let van = slot(subject, 7)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - let vet = slot(van, 59)?; + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; + let fun = 141 + tas!(b"mint"); - let mut key = T(context.stack, &[D(fun), vet, sut, gol, gen, bat]); - let pro = context.cache.lookup(context.stack, &mut key); + let vet = slot(van, 59).map_or(NONE, |x| x); + let mut key = T(&mut context.stack, &[D(fun), vet, sut, gol, gen, bat]); - match pro { + match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), None => { - let res = interpret(context, subject, slot(subject, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - context.cache.insert(context.stack, &mut key, pro); - Ok(pro) - } - } + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) } } } -/* -u3_noun -u3wfu_fuse(u3_noun cor) -{ - u3_noun bat, sut, ref, van; - - if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, 0)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - u3_weak vet = u3r_at(u3qfu_van_vet, van); - c3_m fun_m = 141 + c3__fuse + ((!!vet) << 8); - u3_noun key = u3z_key_3(fun_m, sut, ref, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); - return u3z_save(key, pro); - } - } -} -*/ -pub fn jet_fuse(context: &mut Context, subject: Noun) -> Result { - let ref_ = slot(subject, 6)?; +pub fn jet_ut_fuse(context: &mut Context, subject: Noun) -> Result { + let rff = slot(subject, 6)?; let van = slot(subject, 7)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - let vet = slot(van, 59)?; - let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; - let fun = (141 + tas!(b"fuse")) + (flag << 8); - let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); - let pro = context.cache.lookup(context.stack, &mut key); + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; - match pro { + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"fuse") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), None => { - let res = interpret(context, subject, slot(subject, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - context.cache.insert(context.stack, &mut key, pro); - Ok(pro) - } - } + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) } } } -/* -u3_noun -u3wfu_fish(u3_noun cor) -{ - u3_noun bat, sut, axe, van; - - if ( (c3n == u3r_mean(cor, u3x_sam, &axe, u3x_con, &van, 0)) - || (c3n == u3ud(axe)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - u3_weak vet = u3r_at(u3qfu_van_vet, van); - c3_m fun_m = 141 + c3__fish + ((!!vet) << 8); - u3_noun key = u3z_key_3(fun_m, sut, axe, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); - return u3z_save(key, pro); - } - } -} -*/ pub fn jet_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)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - let vet = slot(van, 59)?; - let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; - let fun = (141 + tas!(b"fish")) + (flag << 8); - let mut key = T(context.stack, &[D(fun), sut, axe.as_noun(), bat]); - let pro = context.cache.lookup(context.stack, &mut key); + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; - match pro { - Some(pro) => Ok(pro), - None => { - let res = interpret(context, subject, slot(subject, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - context.cache.insert(context.stack, &mut key, pro); - Ok(pro) - } - } + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 } - } -} - -/* -u3_noun -u3qf_fine(u3_noun fuv, - u3_noun lup, - u3_noun mar) -{ - if ( (c3__void == lup) || (c3__void == mar) ) { - return c3__void; - } else { - return u3nq(c3__fine, - u3k(fuv), - u3k(lup), - u3k(mar)); - } -} -*/ -pub fn jet_fine(context: &mut Context, subject: Noun) -> Result { - let fuv = slot(subject, 12)?; - let lup = slot(subject, 26)?.as_direct()?; - let mar = slot(subject, 27)?.as_direct()?; - - if tas!(b"void") == lup.data() || tas!(b"void") == mar.data() { - Ok(D(tas!(b"void"))) } else { - Ok(T(context.stack, &[D(tas!(b"fine")), fuv, lup.as_noun(), mar.as_noun()])) - } -} + 1 + }; + let fun = 141 + tas!(b"fish") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, axe.as_noun(), bat]); -/* -u3_noun -u3wfu_crop(u3_noun cor) -{ - u3_noun bat, sut, ref, van; - - if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, 0)) - || (u3_none == (bat = u3r_at(u3x_bat, van))) - || (u3_none == (sut = u3r_at(u3x_sam, van))) ) - { - return u3m_bail(c3__fail); - } - else { - u3_weak vet = u3r_at(u3qfu_van_vet, van); - c3_m fun_m = 141 + c3__crop + ((!!vet) << 8); - u3_noun key = u3z_key_3(fun_m, sut, ref, bat); - u3_weak pro = u3z_find(key); - - if ( u3_none != pro ) { - u3z(key); - return pro; - } - else { - pro = u3n_nock_on(u3k(cor), u3k(u3x_at(u3x_bat, cor))); - return u3z_save(key, pro); - } - } -} -*/ -pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { - let ref_ = slot(subject, 6)?; - let van = slot(subject, 7)?; - let bat = slot(van , 2)?; - let sut = slot(van , 6)?; // why does vere bail:fail if any of these are none? - - let vet = slot(van, 59)?; - let flag = if unsafe { vet.raw_equals(D(0)) } { 0 } else { 1 }; - let fun = (141 + tas!(b"crop")) + (flag << 8); - let mut key = T(context.stack, &[D(fun), sut, ref_, bat]); - let pro = context.cache.lookup(context.stack, &mut key); - - match pro { + match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), None => { - let res = interpret(context, subject, slot(subject, 2)?); - match res { - Err(_) => { - Err(Deterministic) - }, - Ok(pro) => { - context.cache.insert(context.stack, &mut key, pro); - Ok(pro) - } - } + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) } } } -#[cfg(test)] -mod tests { - use super::*; - use crate::jets::util::test::{assert_jet, assert_jet_ubig, init_stack, A}; - use crate::mem::NockStack; - use crate::noun::{Noun, D, T}; - use ibig::ubig; +pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { + let rff = slot(subject, 6)?; + let van = slot(subject, 7)?; - fn atoms(s: &mut NockStack) -> (Noun, Noun, Noun, Noun, Noun) { - (atom_0(s), atom_24(s), atom_63(s), atom_96(s), atom_128(s)) - } + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; - fn atom_0(_stack: &mut NockStack) -> Noun { - D(0) - } + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"crop") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); - fn atom_24(_stack: &mut NockStack) -> Noun { - D(0x876543) - } - - fn atom_63(_stack: &mut NockStack) -> Noun { - D(0x7fffffffffffffff) - } - - fn atom_96(stack: &mut NockStack) -> Noun { - A(stack, &ubig!(0xfaceb00c15deadbeef123456)) - } - - fn atom_128(stack: &mut NockStack) -> Noun { - A(stack, &ubig!(0xdeadbeef12345678fedcba9876543210)) - } - - #[test] - fn test_crop() { - let s = &mut init_stack(); + match context.cache.lookup(&mut context.stack, &mut key) { + Some(pro) => Ok(pro), + None => { + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) + } } } diff --git a/rust/ares/src/noun.rs b/rust/ares/src/noun.rs index 232d391..1e9849c 100644 --- a/rust/ares/src/noun.rs +++ b/rust/ares/src/noun.rs @@ -39,6 +39,7 @@ const FORWARDING_MASK: u64 = CELL_MASK; /** Loobeans */ pub const YES: Noun = D(0); pub const NO: Noun = D(1); +pub const NONE: Noun = unsafe { DirectAtom::new_unchecked(u64::MAX).as_noun() }; #[cfg(feature = "check_acyclic")] #[macro_export] @@ -916,6 +917,10 @@ pub union Noun { } impl Noun { + pub fn is_none(self) -> bool { + unsafe { self.raw == u64::MAX } + } + pub fn is_direct(&self) -> bool { unsafe { is_direct_atom(self.raw) } } From 096208a612ba5794ef0db0f7179b644425ab0b4d Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Fri, 27 Oct 2023 06:11:19 +0100 Subject: [PATCH 06/11] Reorder jets --- rust/ares/src/jets/lute.rs | 240 ++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index 8bfc71a..ccf4393 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -8,8 +8,8 @@ use ares_macros::tas; crate::gdb!(); -pub fn jet_ut_rest(context: &mut Context, subject: Noun) -> Result { - let leg = slot(subject, 6)?; +pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { + let rff = slot(subject, 6)?; let van = slot(subject, 7)?; let bat = slot(van, 2)?; @@ -24,8 +24,120 @@ pub fn jet_ut_rest(context: &mut Context, subject: Noun) -> Result { } else { 1 }; - let fun = 141 + tas!(b"rest") + (flag << 8); - let mut key = T(&mut context.stack, &[D(fun), sut, leg, bat]); + let fun = 141 + tas!(b"crop") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { + Some(pro) => Ok(pro), + None => { + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) + } + } +} + +pub fn jet_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)?; + + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; + + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"fish") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, axe.as_noun(), bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { + Some(pro) => Ok(pro), + None => { + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) + } + } +} + +pub fn jet_ut_fuse(context: &mut Context, subject: Noun) -> Result { + let rff = slot(subject, 6)?; + let van = slot(subject, 7)?; + + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; + + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"fuse") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { + Some(pro) => Ok(pro), + None => { + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) + } + } +} + +pub fn jet_ut_mint(context: &mut Context, subject: Noun) -> Result { + let gol = slot(subject, 12)?; + let gen = slot(subject, 13)?; + let van = slot(subject, 7)?; + + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; + + let fun = 141 + tas!(b"mint"); + let vet = slot(van, 59).map_or(NONE, |x| x); + let mut key = T(&mut context.stack, &[D(fun), vet, sut, gol, gen, bat]); + + match context.cache.lookup(&mut context.stack, &mut key) { + Some(pro) => Ok(pro), + None => { + let pro = interpret(context, subject, slot(subject, 2)?)?; + context.cache.insert(&mut context.stack, &mut key, pro); + Ok(pro) + } + } +} + +pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result { + let gol = slot(subject, 12)?; + let dox = slot(subject, 26)?; + let gen = slot(subject, 27)?; + let van = slot(subject, 7)?; + + let bat = slot(van, 2)?; + let sut = slot(van, 6)?; + + let flag = if let Ok(noun) = slot(van, 59) { + if unsafe { noun.raw_equals(D(0)) } { + 0u64 + } else { + 1u64 + } + } else { + 1 + }; + let fun = 141 + tas!(b"mull") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, gol, dox, gen, bat]); match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), @@ -76,10 +188,8 @@ pub fn jet_ut_nest(context: &mut Context, subject: Noun) -> Result { } } -pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result { - let gol = slot(subject, 12)?; - let dox = slot(subject, 26)?; - let gen = slot(subject, 27)?; +pub fn jet_ut_rest(context: &mut Context, subject: Noun) -> Result { + let leg = slot(subject, 6)?; let van = slot(subject, 7)?; let bat = slot(van, 2)?; @@ -94,118 +204,8 @@ pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result { } else { 1 }; - let fun = 141 + tas!(b"mull") + (flag << 8); - let mut key = T(&mut context.stack, &[D(fun), sut, gol, dox, gen, bat]); - - match context.cache.lookup(&mut context.stack, &mut key) { - Some(pro) => Ok(pro), - None => { - let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); - Ok(pro) - } - } -} - -pub fn jet_ut_mint(context: &mut Context, subject: Noun) -> Result { - let gol = slot(subject, 12)?; - let gen = slot(subject, 13)?; - let van = slot(subject, 7)?; - - let bat = slot(van, 2)?; - let sut = slot(van, 6)?; - - let fun = 141 + tas!(b"mint"); - let vet = slot(van, 59).map_or(NONE, |x| x); - let mut key = T(&mut context.stack, &[D(fun), vet, sut, gol, gen, bat]); - - match context.cache.lookup(&mut context.stack, &mut key) { - Some(pro) => Ok(pro), - None => { - let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); - Ok(pro) - } - } -} - -pub fn jet_ut_fuse(context: &mut Context, subject: Noun) -> Result { - let rff = slot(subject, 6)?; - let van = slot(subject, 7)?; - - let bat = slot(van, 2)?; - let sut = slot(van, 6)?; - - let flag = if let Ok(noun) = slot(van, 59) { - if unsafe { noun.raw_equals(D(0)) } { - 0u64 - } else { - 1u64 - } - } else { - 1 - }; - let fun = 141 + tas!(b"fuse") + (flag << 8); - let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); - - match context.cache.lookup(&mut context.stack, &mut key) { - Some(pro) => Ok(pro), - None => { - let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); - Ok(pro) - } - } -} - -pub fn jet_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)?; - - let bat = slot(van, 2)?; - let sut = slot(van, 6)?; - - let flag = if let Ok(noun) = slot(van, 59) { - if unsafe { noun.raw_equals(D(0)) } { - 0u64 - } else { - 1u64 - } - } else { - 1 - }; - let fun = 141 + tas!(b"fish") + (flag << 8); - let mut key = T(&mut context.stack, &[D(fun), sut, axe.as_noun(), bat]); - - match context.cache.lookup(&mut context.stack, &mut key) { - Some(pro) => Ok(pro), - None => { - let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); - Ok(pro) - } - } -} - -pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { - let rff = slot(subject, 6)?; - let van = slot(subject, 7)?; - - let bat = slot(van, 2)?; - let sut = slot(van, 6)?; - - let flag = if let Ok(noun) = slot(van, 59) { - if unsafe { noun.raw_equals(D(0)) } { - 0u64 - } else { - 1u64 - } - } else { - 1 - }; - let fun = 141 + tas!(b"crop") + (flag << 8); - let mut key = T(&mut context.stack, &[D(fun), sut, rff, bat]); + let fun = 141 + tas!(b"rest") + (flag << 8); + let mut key = T(&mut context.stack, &[D(fun), sut, leg, bat]); match context.cache.lookup(&mut context.stack, &mut key) { Some(pro) => Ok(pro), From 9499b00590f8a7d09918654af0eae115fabf1742 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Fri, 27 Oct 2023 06:21:35 +0100 Subject: [PATCH 07/11] Fixup comment explaining scry failure behaviour --- rust/ares/src/jets/nock.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/rust/ares/src/jets/nock.rs b/rust/ares/src/jets/nock.rs index b0337c5..6f0f049 100644 --- a/rust/ares/src/jets/nock.rs +++ b/rust/ares/src/jets/nock.rs @@ -51,18 +51,19 @@ pub fn jet_mink(context: &mut Context, subject: Noun) -> Result { Err(error) => match error { Error::NonDeterministic(_) => Err(JetErr::Fail(error)), Error::ScryCrashed(trace) => { - // When we enter a +mink call, we record what the scry handler stack looked like on - // entry. Each scry pulls the scry handler off the top of the scry handler stack and - // and calls interpret() with the remainder of the scry handler stack. When a scry - // succeeds, it replaces the scry handler it used at the top of the stack. However, - // it never does so when it fails. Therefore, we can tell which particular - // virtualization instance failed if the scry handler stack at the time of failure - // is identical to the scry handler stack on entry to the +mink call. Therefore, - // when a virtual nock call returns ScryCrashed, mink compares the root of the scry - // handler stack currently in the context object with the one that was on the stack - // when the mink call was initiated. If they match, it's this mink call that crashed - // so convert the Error::ScryCrashed into a Error::Deterministic. Otherwise, pass - // the Error::ScryCrashed up to the senior virtualizer. + // When we enter a +mink call, we record the state of the scry handler stack at the + // time (i.e. the Noun representing (list scry)). Each scry will pop the head off of + // this scry handler stack and calls interpret(), using the rest of the scry handler + // stack in the event that it scries again recursively. When a scry succeeds, it + // replaces the scry handler that it used by pushing it back onto the top of the + // scry handler stack. However, it never does so when it fails. Therefore, we can + // tell which particular virtualization instance failed by comparing the scry + // handler stack at the time of failure (i.e. the scry handler stack in the context + // after a failed scry) with the scry handler stack at the time of the virtualization + // call. Thus, whenever a virtualized interpret() call fails with a + // Error::ScryCrashed, jet_mink() compares the two scry handler stack Nouns> If they + // are identical, jet_mink() bails with Error::Deterministic. Otherwise, it forwards + // the Error::ScryCrashed to the senior virtualization call. if unsafe { context.scry_stack.raw_equals(old_scry_stack) } { Err(JetErr::Fail(Error::Deterministic(trace))) } else { From 73623745791a943a7cc87f4c5d69a21721841fb7 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Fri, 27 Oct 2023 14:02:36 -0500 Subject: [PATCH 08/11] noun: We need a hack value for NONE until we figure out what to do about mint_ut --- rust/ares/src/noun.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ares/src/noun.rs b/rust/ares/src/noun.rs index 1e9849c..9d0c5da 100644 --- a/rust/ares/src/noun.rs +++ b/rust/ares/src/noun.rs @@ -39,7 +39,7 @@ const FORWARDING_MASK: u64 = CELL_MASK; /** Loobeans */ pub const YES: Noun = D(0); pub const NO: Noun = D(1); -pub const NONE: Noun = unsafe { DirectAtom::new_unchecked(u64::MAX).as_noun() }; +pub const NONE: Noun = unsafe { DirectAtom::new_unchecked(tas!(b"MORMAGIC").as_noun() }; #[cfg(feature = "check_acyclic")] #[macro_export] From 46275f51839f7532ed8265a5b44b8166596563e4 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Fri, 27 Oct 2023 14:04:56 -0500 Subject: [PATCH 09/11] noun: lost paren --- rust/ares/src/noun.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ares/src/noun.rs b/rust/ares/src/noun.rs index 9d0c5da..27994fa 100644 --- a/rust/ares/src/noun.rs +++ b/rust/ares/src/noun.rs @@ -39,7 +39,7 @@ const FORWARDING_MASK: u64 = CELL_MASK; /** Loobeans */ pub const YES: Noun = D(0); pub const NO: Noun = D(1); -pub const NONE: Noun = unsafe { DirectAtom::new_unchecked(tas!(b"MORMAGIC").as_noun() }; +pub const NONE: Noun = unsafe { DirectAtom::new_unchecked(tas!(b"MORMAGIC")).as_noun() }; #[cfg(feature = "check_acyclic")] #[macro_export] From c214118c2da61f2b41835ba769411514dd420e6e Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Wed, 15 Nov 2023 13:15:40 +0100 Subject: [PATCH 10/11] jets: fix cache assignment bug --- rust/ares/src/jets/lute.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index ccf4393..f282d8b 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -31,7 +31,7 @@ pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } } @@ -61,7 +61,7 @@ pub fn jet_fish(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } } @@ -90,7 +90,7 @@ pub fn jet_ut_fuse(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } } @@ -112,7 +112,7 @@ pub fn jet_ut_mint(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } } @@ -143,7 +143,7 @@ pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } } @@ -181,7 +181,7 @@ pub fn jet_ut_nest(context: &mut Context, subject: Noun) -> Result { if unsafe { pro.raw_equals(YES) && reg.raw_equals(D(0)) } || unsafe { pro.raw_equals(NO) && seg.raw_equals(D(0)) } { - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); } Ok(pro) } @@ -211,7 +211,7 @@ pub fn jet_ut_rest(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } } From af7398133a00b9ca2f4f370dca4824c1183dbb19 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Wed, 15 Nov 2023 06:23:24 -0600 Subject: [PATCH 11/11] jet_crop: fix doubled assignment to cache --- rust/ares/src/jets/lute.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ares/src/jets/lute.rs b/rust/ares/src/jets/lute.rs index f282d8b..966ff1d 100644 --- a/rust/ares/src/jets/lute.rs +++ b/rust/ares/src/jets/lute.rs @@ -31,7 +31,7 @@ pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { Some(pro) => Ok(pro), None => { let pro = interpret(context, subject, slot(subject, 2)?)?; - context.cache = context.cache = context.cache.insert(&mut context.stack, &mut key, pro); + context.cache = context.cache.insert(&mut context.stack, &mut key, pro); Ok(pro) } }