From bd45da99f861939246582a0dabb1b5d260e9f73b Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 13:17:20 -0500 Subject: [PATCH 01/31] jets: naive, non-cached `stir` implementation --- rust/ares/src/jets/hot.rs | 14 ++++++++++ rust/ares/src/jets/parse.rs | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index fb366f6..0186e97 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -440,6 +440,20 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_stag, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"stir"), + Left(b"fun"), + ], + 1, + jet_stir, + ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 0eb3c9b..f7a390c 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -225,6 +225,60 @@ pub fn jet_sfix(context: &mut Context, subject: Noun) -> Result { } } +pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { + context.stack.frame_push(0); + + let mut tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let rud = slot(van, 12)?; + let raq = slot(van, 26)?; + let fel = slot(van, 27)?; + + // +$ edge [p=hair q=(unit [p=* q=nail])] + let hair = T(&mut context.stack, &[D(1), D(1)]); + let mut par_u = T(&mut context.stack, &[hair, D(0)]); + + // initial accumulator (deconstructed) + let mut p_wag: Noun; + let mut puq_wag: Noun; + let quq_wag: Noun; + + // push incremental, succesful [fel] parse results onto stack + { + let mut vex = slam(context, fel, tub)?.as_cell()?; + let mut p_vex = vex.head(); + let mut q_vex = vex.tail(); + while !unsafe { q_vex.raw_equals(D(0)) } { + let puq_vex = q_vex.as_cell()?.head(); + let quq_vex = q_vex.as_cell()?.tail(); + + par_u = T(&mut context.stack, &[p_vex, puq_vex]); + unsafe { *(context.stack.push()) = par_u }; + + tub = quq_vex; + + vex = slam(context, fel, tub)?.as_cell()?; + p_vex = vex.head(); + q_vex = vex.tail(); + } + + p_wag = p_vex; + puq_wag = rud; + quq_wag = tub; + } + + // unwind the stack, folding parse results into [wag] by way of [raq] + while !context.stack.stack_is_empty() { + p_wag = util::last(p_wag, puq_wag)?; + let sam = T(&mut context.stack, &[par_u.as_cell()?.tail(), puq_wag]); + puq_wag = slam(context, raq, sam)?; + par_u = unsafe { *(context.stack.top()) }; + unsafe { context.stack.pop::(); }; + } + + Ok(T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag])) +} + // // Rule Builders // From 45eff27f624adbba2d78d88ab31dbb0a67b05a44 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 13:23:49 -0500 Subject: [PATCH 02/31] jets: `stack.frame_pop()` at end of `stir` --- rust/ares/src/jets/parse.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index f7a390c..d634cda 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -234,6 +234,7 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { let raq = slot(van, 26)?; let fel = slot(van, 27)?; + // XX should we use a struct for this? // +$ edge [p=hair q=(unit [p=* q=nail])] let hair = T(&mut context.stack, &[D(1), D(1)]); let mut par_u = T(&mut context.stack, &[hair, D(0)]); @@ -276,6 +277,8 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { unsafe { context.stack.pop::(); }; } + unsafe { context.stack.frame_pop(); }; + Ok(T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag])) } From 695a8787542b50ab6457fb18c89a0eb160b967fc Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 14:20:53 -0500 Subject: [PATCH 03/31] wip: push current `stir`, trying to fix bugs --- rust/ares/src/jets/parse.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index d634cda..6547203 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -225,6 +225,12 @@ pub fn jet_sfix(context: &mut Context, subject: Noun) -> Result { } } +#[derive(Copy, Clone)] +struct StirPair { + pub har: Noun, + pub res: Noun, +} + pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { context.stack.frame_push(0); @@ -234,10 +240,16 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { let raq = slot(van, 26)?; let fel = slot(van, 27)?; - // XX should we use a struct for this? + eprintln!("stir: got my nouns"); + // +$ edge [p=hair q=(unit [p=* q=nail])] let hair = T(&mut context.stack, &[D(1), D(1)]); - let mut par_u = T(&mut context.stack, &[hair, D(0)]); + let mut par_u = StirPair{ + har: hair, + res: D(0), + }; + + eprintln!("stir: prepared pair"); // initial accumulator (deconstructed) let mut p_wag: Noun; @@ -249,12 +261,14 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { let mut vex = slam(context, fel, tub)?.as_cell()?; let mut p_vex = vex.head(); let mut q_vex = vex.tail(); + eprintln!("stir: got vex"); while !unsafe { q_vex.raw_equals(D(0)) } { let puq_vex = q_vex.as_cell()?.head(); let quq_vex = q_vex.as_cell()?.tail(); - par_u = T(&mut context.stack, &[p_vex, puq_vex]); - unsafe { *(context.stack.push()) = par_u }; + par_u.har = p_vex; + par_u.res = puq_vex; + unsafe { *(context.stack.push::()) = par_u }; tub = quq_vex; @@ -262,6 +276,7 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { p_vex = vex.head(); q_vex = vex.tail(); } + eprintln!("stir: vex loop done"); p_wag = p_vex; puq_wag = rud; @@ -269,16 +284,20 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { } // unwind the stack, folding parse results into [wag] by way of [raq] + eprintln!("stir: unwinding stack"); while !context.stack.stack_is_empty() { p_wag = util::last(p_wag, puq_wag)?; - let sam = T(&mut context.stack, &[par_u.as_cell()?.tail(), puq_wag]); + let sam = T(&mut context.stack, &[par_u.res, puq_wag]); puq_wag = slam(context, raq, sam)?; - par_u = unsafe { *(context.stack.top()) }; - unsafe { context.stack.pop::(); }; + unsafe { context.stack.pop::(); }; + par_u = unsafe { *(context.stack.top::()) }; } + eprintln!("stir: unwind done"); + unsafe { context.stack.frame_pop(); }; + eprintln!("stir: done"); Ok(T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag])) } From d8e6db14ef7b49facbac23e0fa3058298b7a6e12 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 15:01:08 -0500 Subject: [PATCH 04/31] wip: formatting --- rust/ares/Cargo.toml | 4 +-- rust/ares/src/jets/parse.rs | 50 +++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index 27d1199..b3f4b07 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -12,9 +12,9 @@ edition = "2018" # Please keep these alphabetized [dependencies] ares_macros = { path = "../ares_macros" } -assert_no_alloc = "1.1.2" +# assert_no_alloc = "1.1.2" # use this when debugging requires allocation (e.g. eprintln) -# assert_no_alloc = {version="1.1.2", features=["warn_debug"]} +assert_no_alloc = {version="1.1.2", features=["warn_debug"]} bitvec = "1.0.0" criterion = "0.4" either = "1.9.0" diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 6547203..3e16ab8 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -244,7 +244,7 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { // +$ edge [p=hair q=(unit [p=* q=nail])] let hair = T(&mut context.stack, &[D(1), D(1)]); - let mut par_u = StirPair{ + let mut par_u = StirPair { har: hair, res: D(0), }; @@ -257,31 +257,29 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { let quq_wag: Noun; // push incremental, succesful [fel] parse results onto stack - { - let mut vex = slam(context, fel, tub)?.as_cell()?; - let mut p_vex = vex.head(); - let mut q_vex = vex.tail(); - eprintln!("stir: got vex"); - while !unsafe { q_vex.raw_equals(D(0)) } { - let puq_vex = q_vex.as_cell()?.head(); - let quq_vex = q_vex.as_cell()?.tail(); + let mut vex = slam(context, fel, tub)?.as_cell()?; + let mut p_vex = vex.head(); + let mut q_vex = vex.tail(); + eprintln!("stir: got vex"); + while !unsafe { q_vex.raw_equals(D(0)) } { + let puq_vex = q_vex.as_cell()?.head(); + let quq_vex = q_vex.as_cell()?.tail(); - par_u.har = p_vex; - par_u.res = puq_vex; - unsafe { *(context.stack.push::()) = par_u }; + par_u.har = p_vex; + par_u.res = puq_vex; + unsafe { *(context.stack.push::()) = par_u }; - tub = quq_vex; + tub = quq_vex; - vex = slam(context, fel, tub)?.as_cell()?; - p_vex = vex.head(); - q_vex = vex.tail(); - } - eprintln!("stir: vex loop done"); - - p_wag = p_vex; - puq_wag = rud; - quq_wag = tub; + vex = slam(context, fel, tub)?.as_cell()?; + p_vex = vex.head(); + q_vex = vex.tail(); } + eprintln!("stir: vex loop done"); + + p_wag = p_vex; + puq_wag = rud; + quq_wag = tub; // unwind the stack, folding parse results into [wag] by way of [raq] eprintln!("stir: unwinding stack"); @@ -289,13 +287,17 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { p_wag = util::last(p_wag, puq_wag)?; let sam = T(&mut context.stack, &[par_u.res, puq_wag]); puq_wag = slam(context, raq, sam)?; - unsafe { context.stack.pop::(); }; + unsafe { + context.stack.pop::(); + }; par_u = unsafe { *(context.stack.top::()) }; } eprintln!("stir: unwind done"); - unsafe { context.stack.frame_pop(); }; + unsafe { + context.stack.frame_pop(); + }; eprintln!("stir: done"); Ok(T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag])) From b982d79b185a27997ac23b3518f63d8407d19795 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 18:04:12 -0500 Subject: [PATCH 05/31] restore cargo --- rust/ares/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index b3f4b07..27d1199 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -12,9 +12,9 @@ edition = "2018" # Please keep these alphabetized [dependencies] ares_macros = { path = "../ares_macros" } -# assert_no_alloc = "1.1.2" +assert_no_alloc = "1.1.2" # use this when debugging requires allocation (e.g. eprintln) -assert_no_alloc = {version="1.1.2", features=["warn_debug"]} +# assert_no_alloc = {version="1.1.2", features=["warn_debug"]} bitvec = "1.0.0" criterion = "0.4" either = "1.9.0" From ecb626e227f6e0372ded55799467efb1bb9ed567 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 18:12:07 -0500 Subject: [PATCH 06/31] jets: broken `stir` i think? --- rust/ares/src/jets/.parse.rs.swp | Bin 0 -> 16384 bytes rust/ares/src/jets/parse.rs | 69 ++++++++++++++----------------- 2 files changed, 32 insertions(+), 37 deletions(-) create mode 100644 rust/ares/src/jets/.parse.rs.swp diff --git a/rust/ares/src/jets/.parse.rs.swp b/rust/ares/src/jets/.parse.rs.swp new file mode 100644 index 0000000000000000000000000000000000000000..62b8f0c89467e7149c4d9c17624bff560d95ceae GIT binary patch literal 16384 zcmeI3OKclO7{>>i04=oT(Q<*qv_RO6w(%p0?Ko;H)Jmua(o)ig6h+q9S*LF8wX?IE zCoL6HDoR0sKp=q-2S9Lua-axt04fd$IPf@f;)VoNLhTjW^8a>c&40(^nH{&7+`sD~p6f|7q+1zVopbHMeMaXhejBR^&pTvKk!9I5R;GS|5dQ^y1zrOuz&I#_17JUR1Uv|Kf*pW?AJ#GU z8F&-C0ZxIF;0Z7feBgo!kO1qzk82tG61)vgfhU0j_JW5&7w7<&Zei>q_yW8IPJnqZ z1k&J6uo0ZQ8L@-2;2H2Z*ahwdm)D>ka2C7(o(E-+0vw!Q&Dgu(b?_>91-uLnf-G1M zF5JY}ci;?oAG`$Sz%1Aewt)LV7dU?-W8Z@Jz-cfAM!>F?zJO`cy9ykaN01K=E9bgssdKKCTo&u-9Fvx+s z!Cl}2`oekeId~DA1k^uvgFj1LrK;_5f1)r`@%UCA9D9T;lAXOL03 zquj1ao6iL&l(GAWF>G|ze2f<57jsx-*aME!HP%SaR*DnMwySE=UnRUtj2QJA!+E#9D@&FzCt&!`#5SCNO| zQZ0cu>LJ@9TZ|cI(-t;fRz=NF;aj}uON&oH8C(lOG&PA|FEmqhf#2ebwmY<6dBGl* zZ(ij}$_I)Z4PHqb*YKugFoyz5PU0>PCnYC#YN z2@9cMlGVCrObW;18M-AD9~qGo8Kqx5Y?nNXXX6f16c-#s&EmarBVuVWrrT~rbQLLT z3x3g6f-o9>k(V8gUn&*GtG*rG-8>Jv>W;9hT3m&e=R;7?FE}q^wB}7_n>P<{XU8owjkPgZ*#?j#f3W_wLbDi7JQfbXf?v_gO5UVCDl2j;wl1E z5jwQo*~m#1ZaPJ`m>ek4jSS1fM-LGTLj?M+9wJo#Sayg&??%u0*AEe;dadzy3=z%2 zf<8Sf8!#~ZE-_?K9rOtdJRl?dV&6uKKGBQ5npYA-F!;yEsra`CU2y5|jwn1ms$Fs7 z)1qu#)o>hLT35Q||IExs4{Oc&%YR{5E85Q3)eLKi1WP11-%+m>D~|B$_>niV)PyKD z9iN>kS=F4kHd^l0Of*}-W?ns4JLA11> z*SgnQM+Ivow}FYg?dJ1pItneip?r5Y--F-QBTkyWN=EDdQLL>$0JQ$6Wjv+t@#a(T zD6qj0;DFZmPlHKN04Z<*Wj_WVs(Q{)T{>w6v;tZIt$QoYDb=WsrtHU_Ci zdg3tB*ouECKCv}5ikFdNlyhIXUZ;~*+h$QLZ5~BpRG1Ql6h1^)++5^eb8}T4%QQEg u?C;Cu(y2@~l}+P+@n%x(?HfsPv@DFB1ySP#EjJA637nd0@{zcg$^HPh!9zm; literal 0 HcmV?d00001 diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 3e16ab8..859b38d 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -225,6 +225,7 @@ pub fn jet_sfix(context: &mut Context, subject: Noun) -> Result { } } +// +$ edge [p=hair q=(unit [p=* q=nail])] #[derive(Copy, Clone)] struct StirPair { pub har: Noun, @@ -240,67 +241,61 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { let raq = slot(van, 26)?; let fel = slot(van, 27)?; - eprintln!("stir: got my nouns"); - - // +$ edge [p=hair q=(unit [p=* q=nail])] - let hair = T(&mut context.stack, &[D(1), D(1)]); - let mut par_u = StirPair { - har: hair, - res: D(0), - }; - - eprintln!("stir: prepared pair"); - // initial accumulator (deconstructed) let mut p_wag: Noun; let mut puq_wag: Noun; let quq_wag: Noun; // push incremental, succesful [fel] parse results onto stack - let mut vex = slam(context, fel, tub)?.as_cell()?; - let mut p_vex = vex.head(); - let mut q_vex = vex.tail(); - eprintln!("stir: got vex"); - while !unsafe { q_vex.raw_equals(D(0)) } { - let puq_vex = q_vex.as_cell()?.head(); - let quq_vex = q_vex.as_cell()?.tail(); + { + let mut vex = slam(context, fel, tub)?.as_cell()?; + let mut p_vex = vex.head(); + let mut q_vex = vex.tail(); + eprintln!("stir: got vex\r"); + let i = 0; + while unsafe { !q_vex.raw_equals(D(0)) } { + eprintln!("stir: starting vex loop {}\r", i); + let puq_vex = q_vex.as_cell()?.head(); - par_u.har = p_vex; - par_u.res = puq_vex; - unsafe { *(context.stack.push::()) = par_u }; + unsafe { + *(context.stack.push::()) = StirPair{ + har: p_vex, + res: puq_vex, + }; + }; - tub = quq_vex; + tub = q_vex.as_cell()?.tail(); - vex = slam(context, fel, tub)?.as_cell()?; - p_vex = vex.head(); - q_vex = vex.tail(); + vex = slam(context, fel, tub)?.as_cell()?; + p_vex = vex.head(); + q_vex = vex.tail(); + } + eprintln!("stir: vex loop done\r"); + + p_wag = p_vex; + puq_wag = rud; + quq_wag = tub; } - eprintln!("stir: vex loop done"); - - p_wag = p_vex; - puq_wag = rud; - quq_wag = tub; // unwind the stack, folding parse results into [wag] by way of [raq] - eprintln!("stir: unwinding stack"); + eprintln!("stir: unwinding stack\r"); while !context.stack.stack_is_empty() { - p_wag = util::last(p_wag, puq_wag)?; + let par_u = unsafe { *(context.stack.top::()) }; + p_wag = util::last(par_u.har, p_wag)?; let sam = T(&mut context.stack, &[par_u.res, puq_wag]); puq_wag = slam(context, raq, sam)?; unsafe { context.stack.pop::(); }; - par_u = unsafe { *(context.stack.top::()) }; } - eprintln!("stir: unwind done"); - + let mut res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); unsafe { + context.stack.preserve(&mut res); context.stack.frame_pop(); }; - eprintln!("stir: done"); - Ok(T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag])) + Ok(res) } // From 89506c4f1f0e17031d468eb331dd89c812aa845d Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 18:22:22 -0500 Subject: [PATCH 07/31] remove swp --- rust/ares/src/jets/.parse.rs.swp | Bin 16384 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 rust/ares/src/jets/.parse.rs.swp diff --git a/rust/ares/src/jets/.parse.rs.swp b/rust/ares/src/jets/.parse.rs.swp deleted file mode 100644 index 62b8f0c89467e7149c4d9c17624bff560d95ceae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3OKclO7{>>i04=oT(Q<*qv_RO6w(%p0?Ko;H)Jmua(o)ig6h+q9S*LF8wX?IE zCoL6HDoR0sKp=q-2S9Lua-axt04fd$IPf@f;)VoNLhTjW^8a>c&40(^nH{&7+`sD~p6f|7q+1zVopbHMeMaXhejBR^&pTvKk!9I5R;GS|5dQ^y1zrOuz&I#_17JUR1Uv|Kf*pW?AJ#GU z8F&-C0ZxIF;0Z7feBgo!kO1qzk82tG61)vgfhU0j_JW5&7w7<&Zei>q_yW8IPJnqZ z1k&J6uo0ZQ8L@-2;2H2Z*ahwdm)D>ka2C7(o(E-+0vw!Q&Dgu(b?_>91-uLnf-G1M zF5JY}ci;?oAG`$Sz%1Aewt)LV7dU?-W8Z@Jz-cfAM!>F?zJO`cy9ykaN01K=E9bgssdKKCTo&u-9Fvx+s z!Cl}2`oekeId~DA1k^uvgFj1LrK;_5f1)r`@%UCA9D9T;lAXOL03 zquj1ao6iL&l(GAWF>G|ze2f<57jsx-*aME!HP%SaR*DnMwySE=UnRUtj2QJA!+E#9D@&FzCt&!`#5SCNO| zQZ0cu>LJ@9TZ|cI(-t;fRz=NF;aj}uON&oH8C(lOG&PA|FEmqhf#2ebwmY<6dBGl* zZ(ij}$_I)Z4PHqb*YKugFoyz5PU0>PCnYC#YN z2@9cMlGVCrObW;18M-AD9~qGo8Kqx5Y?nNXXX6f16c-#s&EmarBVuVWrrT~rbQLLT z3x3g6f-o9>k(V8gUn&*GtG*rG-8>Jv>W;9hT3m&e=R;7?FE}q^wB}7_n>P<{XU8owjkPgZ*#?j#f3W_wLbDi7JQfbXf?v_gO5UVCDl2j;wl1E z5jwQo*~m#1ZaPJ`m>ek4jSS1fM-LGTLj?M+9wJo#Sayg&??%u0*AEe;dadzy3=z%2 zf<8Sf8!#~ZE-_?K9rOtdJRl?dV&6uKKGBQ5npYA-F!;yEsra`CU2y5|jwn1ms$Fs7 z)1qu#)o>hLT35Q||IExs4{Oc&%YR{5E85Q3)eLKi1WP11-%+m>D~|B$_>niV)PyKD z9iN>kS=F4kHd^l0Of*}-W?ns4JLA11> z*SgnQM+Ivow}FYg?dJ1pItneip?r5Y--F-QBTkyWN=EDdQLL>$0JQ$6Wjv+t@#a(T zD6qj0;DFZmPlHKN04Z<*Wj_WVs(Q{)T{>w6v;tZIt$QoYDb=WsrtHU_Ci zdg3tB*ouECKCv}5ikFdNlyhIXUZ;~*+h$QLZ5~BpRG1Ql6h1^)++5^eb8}T4%QQEg u?C;Cu(y2@~l}+P+@n%x(?HfsPv@DFB1ySP#EjJA637nd0@{zcg$^HPh!9zm; From 4312ecb95249280f1af20268077822c79137a27f Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 19:26:42 -0500 Subject: [PATCH 08/31] wip: x --- rust/ares/Cargo.toml | 4 ++-- rust/ares/src/interpreter.rs | 43 +++++++++++++++++++++++++++++++++++- rust/ares/src/jets/list.rs | 7 ++++-- rust/ares/src/jets/parse.rs | 12 +++++++--- rust/ares/src/main.rs | 8 +++---- rust/ares/src/serf.rs | 5 +++-- 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index 27d1199..b3f4b07 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -12,9 +12,9 @@ edition = "2018" # Please keep these alphabetized [dependencies] ares_macros = { path = "../ares_macros" } -assert_no_alloc = "1.1.2" +# assert_no_alloc = "1.1.2" # use this when debugging requires allocation (e.g. eprintln) -# assert_no_alloc = {version="1.1.2", features=["warn_debug"]} +assert_no_alloc = {version="1.1.2", features=["warn_debug"]} bitvec = "1.0.0" criterion = "0.4" either = "1.9.0" diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 2ebb752..484d39e 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -348,6 +348,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res push_formula(&mut context.stack, formula, true)?; loop { + assert_is_list(*(context.stack.local_noun_pointer(0)), "loop top"); let work: NockWork = *context.stack.top(); match work { NockWork::Done => { @@ -410,6 +411,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } else { // Axis invalid for input Noun + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 0"); break Err(Error::Deterministic(D(0))); } } @@ -419,6 +421,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } NockWork::Work2(mut vale) => { if (*terminator).load(Ordering::Relaxed) { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 2"); break Err(Error::NonDeterministic(D(0))); } @@ -489,6 +492,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } else { // Cannot increment (Nock 4) a cell + assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 4"); break Err(Error::Deterministic(D(0))); } } @@ -532,10 +536,12 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res push_formula(stack, cond.once, cond.tail)?; } else { // Test branch of Nock 6 must return 0 or 1 + assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 6"); break Err(Error::Deterministic(D(0))); } } else { // Test branch of Nock 6 must return a direct atom + assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 6.1"); break Err(Error::Deterministic(D(0))); } } @@ -592,6 +598,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }, NockWork::Work9(mut kale) => { if (*terminator).load(Ordering::Relaxed) { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 9"); break Err(Error::NonDeterministic(D(0))); } @@ -617,6 +624,10 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } Err(JetErr::Punt) => {} Err(err) => { + assert_is_list( + *(context.stack.local_noun_pointer(0)), + "WORK 9.1" + ); break Err(err.into()); } } @@ -663,6 +674,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } } else { // Axis into core must be atom + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 9.2"); break Err(Error::Deterministic(D(0))); } } @@ -708,6 +720,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { + assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 11D COMPHINT"); break Err(err); } } @@ -731,6 +744,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { + assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 11D COMPRES"); break Err(err); } } @@ -770,6 +784,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { + assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 11S COMP RES"); break Err(err); } } @@ -831,8 +846,10 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res Ok(noun) => match noun.as_either_atom_cell() { Left(atom) => { if atom.as_noun().raw_equals(D(0)) { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 SCRY BLOK"); break Err(Error::ScryBlocked(scry.path)); } else { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 SCRY CRASH"); break Err(Error::ScryCrashed(D(0))); } } @@ -842,6 +859,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res let hunk = T(stack, &[D(tas!(b"hunk")), scry.reff, scry.path]); mean_push(stack, hunk); + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 SCRY CRASH 2"); break Err(Error::ScryCrashed(D(0))); } Right(cell) => { @@ -853,18 +871,22 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }, Err(error) => match error { Error::Deterministic(trace) | Error::ScryCrashed(trace) => { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12.1"); break Err(Error::ScryCrashed(trace)); } Error::NonDeterministic(_) => { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12.2"); break Err(error); } Error::ScryBlocked(_) => { + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12.3"); break Err(Error::NonDeterministic(D(0))); } }, } } else { // No scry handler + assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 NO HANDLER"); break Err(Error::Deterministic(D(0))); } } @@ -875,7 +897,11 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res match nock { Ok(res) => Ok(res), - Err(err) => Err(exit(context, &snapshot, virtual_frame, err)), + Err(err) => { + let h = unsafe { *(context.stack.local_noun_pointer(0)) }; + assert_is_list(h, "FINAL MATCH"); + return Err(exit(context, &snapshot, virtual_frame, err)); + } } } @@ -1092,6 +1118,19 @@ fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> result::Res Ok(()) } +fn assert_is_list(mut noun: Noun, tag: &str) { + loop { + if let Ok(cell) = noun.as_cell() { + noun = cell.tail(); + } else { + if ! unsafe { noun.raw_equals(D(0)) } { + panic!("assertion failed: {} is not a list", tag); + break; + } + } + } +} + fn exit( context: &mut Context, snapshot: &ContextSnapshot, @@ -1107,6 +1146,8 @@ fn exit( Error::Deterministic(t) | Error::NonDeterministic(t) | Error::ScryCrashed(t) => { // Return $tang of traces let h = *(stack.local_noun_pointer(0)); + assert_is_list(h, "EXIT"); + // eprintln!("crashing with mean stack: {:?}", h); T(stack, &[h, t]) } }; diff --git a/rust/ares/src/jets/list.rs b/rust/ares/src/jets/list.rs index c281d35..7985701 100644 --- a/rust/ares/src/jets/list.rs +++ b/rust/ares/src/jets/list.rs @@ -73,12 +73,15 @@ pub mod util { let mut dest = &mut res as *mut Noun; while !list.raw_equals(D(0)) { - let pair = list.as_cell()?; + let pair = list.as_cell().expect("outer"); let mut sublist = pair.head(); list = pair.tail(); while !sublist.raw_equals(D(0)) { - let it = sublist.as_cell()?; + if sublist.is_atom() { + panic!("zing: sublist is atom: {:?}", sublist); + }; + let it = sublist.as_cell().expect("inner"); let i = it.head(); sublist = it.tail(); diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 859b38d..4662279 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -256,17 +256,23 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { while unsafe { !q_vex.raw_equals(D(0)) } { eprintln!("stir: starting vex loop {}\r", i); let puq_vex = q_vex.as_cell()?.head(); + let quq_vex = q_vex.as_cell()?.tail(); unsafe { - *(context.stack.push::()) = StirPair{ + *(context.stack.push::()) = StirPair { har: p_vex, res: puq_vex, }; }; - tub = q_vex.as_cell()?.tail(); + tub = quq_vex; - vex = slam(context, fel, tub)?.as_cell()?; + let slam_vex = slam(context, fel, tub); + if slam_vex.is_err() { + eprintln!("stir: slam vex failed\r"); + } + + vex = slam_vex?.as_cell()?; p_vex = vex.head(); q_vex = vex.tail(); } diff --git a/rust/ares/src/main.rs b/rust/ares/src/main.rs index cd6e189..244aff6 100644 --- a/rust/ares/src/main.rs +++ b/rust/ares/src/main.rs @@ -5,10 +5,10 @@ use std::io; fn main() -> io::Result<()> { // debug - // eprintln!("serf: pid {}", std::process::id()); - // if unsafe { libc::kill(std::process::id() as i32, libc::SIGSTOP) } != 0 { - // panic!("Could not stop ourselves."); - // }; + eprintln!("serf: pid {}", std::process::id()); + if unsafe { libc::kill(std::process::id() as i32, libc::SIGSTOP) } != 0 { + panic!("Could not stop ourselves."); + }; let filename = env::args().nth(1).expect("Must provide input filename"); diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 0ba34ea..518f33c 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -1,5 +1,4 @@ use crate::hamt::Hamt; -use crate::interpreter; use crate::interpreter::{inc, interpret, Error}; use crate::jets::cold::Cold; use crate::jets::hot::{Hot, HotEntry}; @@ -13,6 +12,7 @@ use crate::noun::{Atom, Cell, DirectAtom, Noun, Slots, D, T}; use crate::snapshot::double_jam::DoubleJam; use crate::snapshot::Snapshot; use crate::trace::*; +use crate::{interpreter, trace}; use ares_macros::tas; use signal_hook; use signal_hook::consts::SIGINT; @@ -307,7 +307,8 @@ fn peek(context: &mut Context, ovo: Noun) -> Noun { } fn goof(context: &mut Context, traces: Noun) -> Noun { - let trace = zing(&mut context.nock_context.stack, traces).unwrap(); + // eprintln!("serf: goof: traces: {}", traces); + let trace = zing(&mut context.nock_context.stack, traces).expect("serf: goof: zing failed"); let tone = Cell::new(&mut context.nock_context.stack, D(2), trace); let tang = mook(&mut context.nock_context, tone, false) .expect("serf: goof: +mook crashed on bail") From a44846a3fe8d66370963d7d9be52558e07d037fb Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 20:40:35 -0500 Subject: [PATCH 09/31] wip: `stir` needs to use `with_frame` --- rust/ares/Cargo.toml | 2 +- rust/ares/src/interpreter.rs | 71 ++++++++++++-------- rust/ares/src/jets/math.rs | 3 +- rust/ares/src/jets/parse.rs | 123 ++++++++++++++++++----------------- 4 files changed, 112 insertions(+), 87 deletions(-) diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index b3f4b07..2b4a709 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -40,7 +40,7 @@ name = "ares" path = "src/main.rs" [profile.dev] -opt-level = 3 +opt-level = 0 [profile.dev.package."*"] opt-level = 3 diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 484d39e..cdcd2a5 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -348,7 +348,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res push_formula(&mut context.stack, formula, true)?; loop { - assert_is_list(*(context.stack.local_noun_pointer(0)), "loop top"); + assert_is_list(*(context.stack.local_noun_pointer(0))); let work: NockWork = *context.stack.top(); match work { NockWork::Done => { @@ -411,7 +411,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } else { // Axis invalid for input Noun - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 0"); + eprintln!("WORK 0"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -421,7 +422,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } NockWork::Work2(mut vale) => { if (*terminator).load(Ordering::Relaxed) { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 2"); + eprintln!("WORK 2"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::NonDeterministic(D(0))); } @@ -492,7 +494,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } else { // Cannot increment (Nock 4) a cell - assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 4"); + eprintln!("TODO4 INC"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -536,12 +539,14 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res push_formula(stack, cond.once, cond.tail)?; } else { // Test branch of Nock 6 must return 0 or 1 - assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 6"); + eprintln!("TODO6 BRANCH"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } else { // Test branch of Nock 6 must return a direct atom - assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 6.1"); + eprintln!("TODO6 DIRECT"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -598,7 +603,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }, NockWork::Work9(mut kale) => { if (*terminator).load(Ordering::Relaxed) { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 9"); + eprintln!("WORK 9"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::NonDeterministic(D(0))); } @@ -616,6 +622,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res &mut res, &mut formula, ) { + assert_is_list(*(context.stack.local_noun_pointer(0))); match jet(context, res) { Ok(jet_res) => { res = jet_res; @@ -624,9 +631,10 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } Err(JetErr::Punt) => {} Err(err) => { + eprintln!("err: {:?}", err); + eprintln!("WORK 9.1"); assert_is_list( *(context.stack.local_noun_pointer(0)), - "WORK 9.1" ); break Err(err.into()); } @@ -674,7 +682,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } } else { // Axis into core must be atom - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 9.2"); + eprintln!("WORK 9.2"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -720,7 +729,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { - assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 11D COMPHINT"); + eprintln!("WORK 11D"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(err); } } @@ -744,7 +754,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { - assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 11D COMPRES"); + eprintln!("WORK 11D.1"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(err); } } @@ -784,7 +795,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { - assert_is_list(*(context.stack.local_noun_pointer(0)), "TODO 11S COMP RES"); + eprintln!("WORK 11S"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(err); } } @@ -846,10 +858,12 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res Ok(noun) => match noun.as_either_atom_cell() { Left(atom) => { if atom.as_noun().raw_equals(D(0)) { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 SCRY BLOK"); + eprintln!("WORK 12"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryBlocked(scry.path)); } else { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 SCRY CRASH"); + eprintln!("WORK 12.1"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryCrashed(D(0))); } } @@ -859,7 +873,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res let hunk = T(stack, &[D(tas!(b"hunk")), scry.reff, scry.path]); mean_push(stack, hunk); - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 SCRY CRASH 2"); + eprintln!("WORK 12.2"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryCrashed(D(0))); } Right(cell) => { @@ -871,22 +886,26 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }, Err(error) => match error { Error::Deterministic(trace) | Error::ScryCrashed(trace) => { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12.1"); + eprintln!("WORK 12.3"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryCrashed(trace)); } Error::NonDeterministic(_) => { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12.2"); + eprintln!("WORK 12.4"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(error); } Error::ScryBlocked(_) => { - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12.3"); + eprintln!("WORK 12.5"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::NonDeterministic(D(0))); } }, } } else { // No scry handler - assert_is_list(*(context.stack.local_noun_pointer(0)), "WORK 12 NO HANDLER"); + eprintln!("WORK 12.6"); + assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -899,7 +918,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res Ok(res) => Ok(res), Err(err) => { let h = unsafe { *(context.stack.local_noun_pointer(0)) }; - assert_is_list(h, "FINAL MATCH"); + eprintln!("MATCH ERR"); + assert_is_list(h); return Err(exit(context, &snapshot, virtual_frame, err)); } } @@ -1118,15 +1138,13 @@ fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> result::Res Ok(()) } -fn assert_is_list(mut noun: Noun, tag: &str) { +pub fn assert_is_list(mut noun: Noun) { loop { if let Ok(cell) = noun.as_cell() { noun = cell.tail(); } else { - if ! unsafe { noun.raw_equals(D(0)) } { - panic!("assertion failed: {} is not a list", tag); - break; - } + assert!(unsafe { noun.raw_equals(D(0)) }); + break; } } } @@ -1146,7 +1164,8 @@ fn exit( Error::Deterministic(t) | Error::NonDeterministic(t) | Error::ScryCrashed(t) => { // Return $tang of traces let h = *(stack.local_noun_pointer(0)); - assert_is_list(h, "EXIT"); + eprintln!("EXIT"); + assert_is_list(h); // eprintln!("crashing with mean stack: {:?}", h); T(stack, &[h, t]) } diff --git a/rust/ares/src/jets/math.rs b/rust/ares/src/jets/math.rs index f7b03be..15aa04f 100644 --- a/rust/ares/src/jets/math.rs +++ b/rust/ares/src/jets/math.rs @@ -12,7 +12,7 @@ * Another approach is use a global custom allocator. This is fairly involved, but it would allow * us to use any library without worrying whether it allocates. */ -use crate::interpreter::{Context, Error}; +use crate::interpreter::{assert_is_list, Context, Error}; use crate::jets::util::*; use crate::jets::{JetErr, Result}; use crate::noun::{Atom, DirectAtom, IndirectAtom, Noun, D, DIRECT_MAX, NO, T, YES}; @@ -115,6 +115,7 @@ pub fn jet_dvr(context: &mut Context, subject: Noun) -> Result { } pub fn jet_gte(context: &mut Context, subject: Noun) -> Result { + assert_is_list(unsafe { *(context.stack.local_noun_pointer(0)) }); let stack = &mut context.stack; let arg = slot(subject, 6)?; let a = slot(arg, 2)?.as_atom()?; diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 4662279..8236001 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -3,6 +3,7 @@ use crate::interpreter::Context; use crate::jets::util::{kick, slam, slot}; use crate::jets::Result; +use crate::mem::with_frame; use crate::noun::{Noun, D, T}; crate::gdb!(); @@ -233,75 +234,79 @@ struct StirPair { } pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { - context.stack.frame_push(0); + /** XX + * jet should use with_frame + * with_frame should require output to be Preserve and should unconditionally preserve output + * JetErr, interpreter::Error, and Result need Preserve instances + * then jet simply calls with_frame and no need to preserve in jet + */ + unsafe { + with_frame(0, || { + let mut tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let rud = slot(van, 12)?; + let raq = slot(van, 26)?; + let fel = slot(van, 27)?; - let mut tub = slot(subject, 6)?; - let van = slot(subject, 7)?; - let rud = slot(van, 12)?; - let raq = slot(van, 26)?; - let fel = slot(van, 27)?; + // initial accumulator (deconstructed) + let mut p_wag: Noun; + let mut puq_wag: Noun; + let quq_wag: Noun; - // initial accumulator (deconstructed) - let mut p_wag: Noun; - let mut puq_wag: Noun; - let quq_wag: Noun; + // push incremental, succesful [fel] parse results onto stack + { + let mut vex = slam(context, fel, tub)?.as_cell()?; + let mut p_vex = vex.head(); + let mut q_vex = vex.tail(); + eprintln!("stir: got vex\r"); + let i = 0; + while unsafe { !q_vex.raw_equals(D(0)) } { + eprintln!("stir: starting vex loop {}\r", i); + let puq_vex = q_vex.as_cell()?.head(); + let quq_vex = q_vex.as_cell()?.tail(); - // push incremental, succesful [fel] parse results onto stack - { - let mut vex = slam(context, fel, tub)?.as_cell()?; - let mut p_vex = vex.head(); - let mut q_vex = vex.tail(); - eprintln!("stir: got vex\r"); - let i = 0; - while unsafe { !q_vex.raw_equals(D(0)) } { - eprintln!("stir: starting vex loop {}\r", i); - let puq_vex = q_vex.as_cell()?.head(); - let quq_vex = q_vex.as_cell()?.tail(); + unsafe { + *(context.stack.push::()) = StirPair { + har: p_vex, + res: puq_vex, + }; + }; - unsafe { - *(context.stack.push::()) = StirPair { - har: p_vex, - res: puq_vex, - }; - }; + tub = quq_vex; - tub = quq_vex; + let slam_vex = slam(context, fel, tub); + if slam_vex.is_err() { + eprintln!("stir: slam vex failed\r"); + } - let slam_vex = slam(context, fel, tub); - if slam_vex.is_err() { - eprintln!("stir: slam vex failed\r"); + vex = slam_vex?.as_cell()?; + p_vex = vex.head(); + q_vex = vex.tail(); + } + eprintln!("stir: vex loop done\r"); + + p_wag = p_vex; + puq_wag = rud; + quq_wag = tub; } - vex = slam_vex?.as_cell()?; - p_vex = vex.head(); - q_vex = vex.tail(); - } - eprintln!("stir: vex loop done\r"); + // unwind the stack, folding parse results into [wag] by way of [raq] + eprintln!("stir: unwinding stack\r"); + while !context.stack.stack_is_empty() { + let par_u = unsafe { *(context.stack.top::()) }; + p_wag = util::last(par_u.har, p_wag)?; + let sam = T(&mut context.stack, &[par_u.res, puq_wag]); + puq_wag = slam(context, raq, sam)?; + unsafe { + context.stack.pop::(); + }; + } - p_wag = p_vex; - puq_wag = rud; - quq_wag = tub; + let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); + + Ok(res) + }) } - - // unwind the stack, folding parse results into [wag] by way of [raq] - eprintln!("stir: unwinding stack\r"); - while !context.stack.stack_is_empty() { - let par_u = unsafe { *(context.stack.top::()) }; - p_wag = util::last(par_u.har, p_wag)?; - let sam = T(&mut context.stack, &[par_u.res, puq_wag]); - puq_wag = slam(context, raq, sam)?; - unsafe { - context.stack.pop::(); - }; - } - - let mut res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); - unsafe { - context.stack.preserve(&mut res); - context.stack.frame_pop(); - }; - - Ok(res) } // From fd413bafe7ddeecea96c20e3a8a9e3212725b0bf Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 22:24:56 -0500 Subject: [PATCH 10/31] wip: `jet_stew` --- rust/ares/Cargo.toml | 6 +- rust/ares/src/jets/hot.rs | 20 +++- rust/ares/src/jets/parse.rs | 227 +++++++++++++++++++++++++----------- rust/ares/src/main.rs | 8 +- 4 files changed, 185 insertions(+), 76 deletions(-) diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index 2b4a709..27d1199 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -12,9 +12,9 @@ edition = "2018" # Please keep these alphabetized [dependencies] ares_macros = { path = "../ares_macros" } -# assert_no_alloc = "1.1.2" +assert_no_alloc = "1.1.2" # use this when debugging requires allocation (e.g. eprintln) -assert_no_alloc = {version="1.1.2", features=["warn_debug"]} +# assert_no_alloc = {version="1.1.2", features=["warn_debug"]} bitvec = "1.0.0" criterion = "0.4" either = "1.9.0" @@ -40,7 +40,7 @@ name = "ares" path = "src/main.rs" [profile.dev] -opt-level = 0 +opt-level = 3 [profile.dev.package."*"] opt-level = 3 diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 0186e97..7748968 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -440,6 +440,21 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_stag, ), // + // ( + // &[ + // K_139, + // Left(b"one"), + // Left(b"two"), + // Left(b"tri"), + // Left(b"qua"), + // Left(b"stir"), + // Left(b"fun"), + // ], + // 1, + // jet_stir, + // ), + // + // ( &[ K_139, @@ -447,13 +462,12 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ Left(b"two"), Left(b"tri"), Left(b"qua"), - Left(b"stir"), + Left(b"stew"), Left(b"fun"), ], 1, - jet_stir, + jet_stew, ), - // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 8236001..938258e 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,11 +1,14 @@ +use std::result; + /** Parsing jets */ -use crate::interpreter::Context; +use crate::interpreter::{Context, Error}; use crate::jets::util::{kick, slam, slot}; use crate::jets::Result; -use crate::mem::with_frame; use crate::noun::{Noun, D, T}; +use super::JetErr; + crate::gdb!(); // @@ -233,79 +236,171 @@ struct StirPair { pub res: Noun, } -pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { - /** XX - * jet should use with_frame - * with_frame should require output to be Preserve and should unconditionally preserve output - * JetErr, interpreter::Error, and Result need Preserve instances - * then jet simply calls with_frame and no need to preserve in jet - */ - unsafe { - with_frame(0, || { - let mut tub = slot(subject, 6)?; - let van = slot(subject, 7)?; - let rud = slot(van, 12)?; - let raq = slot(van, 26)?; - let fel = slot(van, 27)?; +// pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { + // XX + // jet should use with_frame + // with_frame should require output to be Preserve and should unconditionally preserve output + // JetErr, interpreter::Error, and Result need Preserve instances + // then jet simply calls with_frame and no need to preserve in jet + // unsafe { + // context.stack.with_frame(0, || { + // let mut tub = slot(subject, 6)?; + // let van = slot(subject, 7)?; + // let rud = slot(van, 12)?; + // let raq = slot(van, 26)?; + // let fel = slot(van, 27)?; - // initial accumulator (deconstructed) - let mut p_wag: Noun; - let mut puq_wag: Noun; - let quq_wag: Noun; + // // initial accumulator (deconstructed) + // let mut p_wag: Noun; + // let mut puq_wag: Noun; + // let quq_wag: Noun; - // push incremental, succesful [fel] parse results onto stack - { - let mut vex = slam(context, fel, tub)?.as_cell()?; - let mut p_vex = vex.head(); - let mut q_vex = vex.tail(); - eprintln!("stir: got vex\r"); - let i = 0; - while unsafe { !q_vex.raw_equals(D(0)) } { - eprintln!("stir: starting vex loop {}\r", i); - let puq_vex = q_vex.as_cell()?.head(); - let quq_vex = q_vex.as_cell()?.tail(); + // // push incremental, succesful [fel] parse results onto stack + // { + // let mut vex = slam(context, fel, tub)?.as_cell()?; + // let mut p_vex = vex.head(); + // let mut q_vex = vex.tail(); + // eprintln!("stir: got vex\r"); + // let i = 0; + // while unsafe { !q_vex.raw_equals(D(0)) } { + // eprintln!("stir: starting vex loop {}\r", i); + // let puq_vex = q_vex.as_cell()?.head(); + // let quq_vex = q_vex.as_cell()?.tail(); - unsafe { - *(context.stack.push::()) = StirPair { - har: p_vex, - res: puq_vex, - }; - }; + // unsafe { + // *(context.stack.push::()) = StirPair { + // har: p_vex, + // res: puq_vex, + // }; + // }; - tub = quq_vex; + // tub = quq_vex; - let slam_vex = slam(context, fel, tub); - if slam_vex.is_err() { - eprintln!("stir: slam vex failed\r"); + // let slam_vex = slam(context, fel, tub); + // if slam_vex.is_err() { + // eprintln!("stir: slam vex failed\r"); + // } + + // vex = slam_vex?.as_cell()?; + // p_vex = vex.head(); + // q_vex = vex.tail(); + // } + // eprintln!("stir: vex loop done\r"); + + // p_wag = p_vex; + // puq_wag = rud; + // quq_wag = tub; + // } + + // // unwind the stack, folding parse results into [wag] by way of [raq] + // eprintln!("stir: unwinding stack\r"); + // while !context.stack.stack_is_empty() { + // let par_u = unsafe { *(context.stack.top::()) }; + // p_wag = util::last(par_u.har, p_wag)?; + // let sam = T(&mut context.stack, &[par_u.res, puq_wag]); + // puq_wag = slam(context, raq, sam)?; + // unsafe { + // context.stack.pop::(); + // }; + // } + + // let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); + + // Ok(res) + // }) + // } +// } + +fn stew_wor(ort: Noun, wan: Noun) -> result::Result { + if !ort.as_atom()?.is_direct() { + return Err(JetErr::Fail(Error::Deterministic(D(0)))); + } + else { + if !wan.is_cell() { + if !wan.as_atom()?.is_direct() { + return Err(JetErr::Fail(Error::Deterministic(D(0)))); + } + else { + let ort_dat = ort.as_direct()?.data(); + let wan_dat = wan.as_direct()?.data(); + return Ok(ort_dat < wan_dat); + } + } + else { + let h_wan = wan.as_cell()?.head(); + + if !h_wan.as_atom()?.is_direct() { + return Err(JetErr::Fail(Error::Deterministic(D(0)))); + } + else { + let ort_dat = ort.as_direct()?.data(); + let h_wan_dat = h_wan.as_direct()?.data(); + return Ok(ort_dat < h_wan_dat); + } + } + } +} + +pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let con = slot(subject, 7)?; + let mut hel = slot(con, 2)?; + + let p_tub = tub.as_cell()?.head(); + let q_tub = tub.as_cell()?.tail(); + match q_tub.as_cell() { + Ok(a) => { + let iq_tub = a.head(); + if !iq_tub.as_atom()?.is_direct() { + return util::fail(context, p_tub); + } + else { + loop { + if !hel.is_cell() { + return util::fail(context, tub); } + else { + let n_hel = slot(hel, 2)?; + let l_hel = slot(hel, 6)?; + let r_hel = slot(hel, 7)?; + let pn_hel = n_hel.as_cell()?.head(); + let qn_hel = n_hel.as_cell()?.tail(); + let mut bit = false; - vex = slam_vex?.as_cell()?; - p_vex = vex.head(); - q_vex = vex.tail(); + if !pn_hel.is_cell() { + bit = true; + } + else { + let hpn_hel = pn_hel.as_cell()?.head(); + let tpn_hel = pn_hel.as_cell()?.tail(); + + if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { + return util::fail(context, tub); + } + else { + let iq_tub_dat = iq_tub.as_direct()?.data(); + let hpn_hel_dat = hpn_hel.as_direct()?.data(); + let tpn_hel_dat = tpn_hel.as_direct()?.data(); + bit = (iq_tub_dat >= hpn_hel_dat) && (iq_tub_dat <= tpn_hel_dat); + } + } + + if bit { + return slam(context, qn_hel, tub); + } + else { + if stew_wor(iq_tub, pn_hel)? { + hel = l_hel; + } + else { + hel = r_hel; + } + } + } } - eprintln!("stir: vex loop done\r"); - - p_wag = p_vex; - puq_wag = rud; - quq_wag = tub; } - - // unwind the stack, folding parse results into [wag] by way of [raq] - eprintln!("stir: unwinding stack\r"); - while !context.stack.stack_is_empty() { - let par_u = unsafe { *(context.stack.top::()) }; - p_wag = util::last(par_u.har, p_wag)?; - let sam = T(&mut context.stack, &[par_u.res, puq_wag]); - puq_wag = slam(context, raq, sam)?; - unsafe { - context.stack.pop::(); - }; - } - - let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); - - Ok(res) - }) + } + Err(e) => { return Err(JetErr::Fail(e.into())); } } } diff --git a/rust/ares/src/main.rs b/rust/ares/src/main.rs index 244aff6..cd6e189 100644 --- a/rust/ares/src/main.rs +++ b/rust/ares/src/main.rs @@ -5,10 +5,10 @@ use std::io; fn main() -> io::Result<()> { // debug - eprintln!("serf: pid {}", std::process::id()); - if unsafe { libc::kill(std::process::id() as i32, libc::SIGSTOP) } != 0 { - panic!("Could not stop ourselves."); - }; + // eprintln!("serf: pid {}", std::process::id()); + // if unsafe { libc::kill(std::process::id() as i32, libc::SIGSTOP) } != 0 { + // panic!("Could not stop ourselves."); + // }; let filename = env::args().nth(1).expect("Must provide input filename"); From fd12c44afcbdf32b3d4fe87431561dfb030309ad Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 7 Dec 2023 22:46:03 -0500 Subject: [PATCH 11/31] wip: 12/7 --- rust/ares/src/interpreter.rs | 57 --------- rust/ares/src/jets/math.rs | 3 +- rust/ares/src/jets/parse.rs | 226 +++++++++++++++++------------------ 3 files changed, 110 insertions(+), 176 deletions(-) diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index cdcd2a5..87e69c2 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -348,7 +348,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res push_formula(&mut context.stack, formula, true)?; loop { - assert_is_list(*(context.stack.local_noun_pointer(0))); let work: NockWork = *context.stack.top(); match work { NockWork::Done => { @@ -411,8 +410,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } else { // Axis invalid for input Noun - eprintln!("WORK 0"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -422,8 +419,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } NockWork::Work2(mut vale) => { if (*terminator).load(Ordering::Relaxed) { - eprintln!("WORK 2"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::NonDeterministic(D(0))); } @@ -494,8 +489,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } else { // Cannot increment (Nock 4) a cell - eprintln!("TODO4 INC"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -539,14 +532,10 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res push_formula(stack, cond.once, cond.tail)?; } else { // Test branch of Nock 6 must return 0 or 1 - eprintln!("TODO6 BRANCH"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } else { // Test branch of Nock 6 must return a direct atom - eprintln!("TODO6 DIRECT"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -603,8 +592,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }, NockWork::Work9(mut kale) => { if (*terminator).load(Ordering::Relaxed) { - eprintln!("WORK 9"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::NonDeterministic(D(0))); } @@ -622,7 +609,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res &mut res, &mut formula, ) { - assert_is_list(*(context.stack.local_noun_pointer(0))); match jet(context, res) { Ok(jet_res) => { res = jet_res; @@ -631,11 +617,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } Err(JetErr::Punt) => {} Err(err) => { - eprintln!("err: {:?}", err); - eprintln!("WORK 9.1"); - assert_is_list( - *(context.stack.local_noun_pointer(0)), - ); break Err(err.into()); } } @@ -682,8 +663,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res } } else { // Axis into core must be atom - eprintln!("WORK 9.2"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -729,8 +708,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { - eprintln!("WORK 11D"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(err); } } @@ -754,8 +731,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { - eprintln!("WORK 11D.1"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(err); } } @@ -795,8 +770,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res context.stack.pop::(); } Err(err) => { - eprintln!("WORK 11S"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(err); } } @@ -858,12 +831,8 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res Ok(noun) => match noun.as_either_atom_cell() { Left(atom) => { if atom.as_noun().raw_equals(D(0)) { - eprintln!("WORK 12"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryBlocked(scry.path)); } else { - eprintln!("WORK 12.1"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryCrashed(D(0))); } } @@ -873,8 +842,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res let hunk = T(stack, &[D(tas!(b"hunk")), scry.reff, scry.path]); mean_push(stack, hunk); - eprintln!("WORK 12.2"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryCrashed(D(0))); } Right(cell) => { @@ -886,26 +853,18 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }, Err(error) => match error { Error::Deterministic(trace) | Error::ScryCrashed(trace) => { - eprintln!("WORK 12.3"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::ScryCrashed(trace)); } Error::NonDeterministic(_) => { - eprintln!("WORK 12.4"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(error); } Error::ScryBlocked(_) => { - eprintln!("WORK 12.5"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::NonDeterministic(D(0))); } }, } } else { // No scry handler - eprintln!("WORK 12.6"); - assert_is_list(*(context.stack.local_noun_pointer(0))); break Err(Error::Deterministic(D(0))); } } @@ -918,8 +877,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res Ok(res) => Ok(res), Err(err) => { let h = unsafe { *(context.stack.local_noun_pointer(0)) }; - eprintln!("MATCH ERR"); - assert_is_list(h); return Err(exit(context, &snapshot, virtual_frame, err)); } } @@ -1138,17 +1095,6 @@ fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> result::Res Ok(()) } -pub fn assert_is_list(mut noun: Noun) { - loop { - if let Ok(cell) = noun.as_cell() { - noun = cell.tail(); - } else { - assert!(unsafe { noun.raw_equals(D(0)) }); - break; - } - } -} - fn exit( context: &mut Context, snapshot: &ContextSnapshot, @@ -1164,9 +1110,6 @@ fn exit( Error::Deterministic(t) | Error::NonDeterministic(t) | Error::ScryCrashed(t) => { // Return $tang of traces let h = *(stack.local_noun_pointer(0)); - eprintln!("EXIT"); - assert_is_list(h); - // eprintln!("crashing with mean stack: {:?}", h); T(stack, &[h, t]) } }; diff --git a/rust/ares/src/jets/math.rs b/rust/ares/src/jets/math.rs index 15aa04f..f7b03be 100644 --- a/rust/ares/src/jets/math.rs +++ b/rust/ares/src/jets/math.rs @@ -12,7 +12,7 @@ * Another approach is use a global custom allocator. This is fairly involved, but it would allow * us to use any library without worrying whether it allocates. */ -use crate::interpreter::{assert_is_list, Context, Error}; +use crate::interpreter::{Context, Error}; use crate::jets::util::*; use crate::jets::{JetErr, Result}; use crate::noun::{Atom, DirectAtom, IndirectAtom, Noun, D, DIRECT_MAX, NO, T, YES}; @@ -115,7 +115,6 @@ pub fn jet_dvr(context: &mut Context, subject: Noun) -> Result { } pub fn jet_gte(context: &mut Context, subject: Noun) -> Result { - assert_is_list(unsafe { *(context.stack.local_noun_pointer(0)) }); let stack = &mut context.stack; let arg = slot(subject, 6)?; let a = slot(arg, 2)?.as_atom()?; diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 938258e..1a903dd 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -237,102 +237,99 @@ struct StirPair { } // pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { - // XX - // jet should use with_frame - // with_frame should require output to be Preserve and should unconditionally preserve output - // JetErr, interpreter::Error, and Result need Preserve instances - // then jet simply calls with_frame and no need to preserve in jet - // unsafe { - // context.stack.with_frame(0, || { - // let mut tub = slot(subject, 6)?; - // let van = slot(subject, 7)?; - // let rud = slot(van, 12)?; - // let raq = slot(van, 26)?; - // let fel = slot(van, 27)?; +// XX +// jet should use with_frame +// with_frame should require output to be Preserve and should unconditionally preserve output +// JetErr, interpreter::Error, and Result need Preserve instances +// then jet simply calls with_frame and no need to preserve in jet +// unsafe { +// context.stack.with_frame(0, || { +// let mut tub = slot(subject, 6)?; +// let van = slot(subject, 7)?; +// let rud = slot(van, 12)?; +// let raq = slot(van, 26)?; +// let fel = slot(van, 27)?; - // // initial accumulator (deconstructed) - // let mut p_wag: Noun; - // let mut puq_wag: Noun; - // let quq_wag: Noun; +// // initial accumulator (deconstructed) +// let mut p_wag: Noun; +// let mut puq_wag: Noun; +// let quq_wag: Noun; - // // push incremental, succesful [fel] parse results onto stack - // { - // let mut vex = slam(context, fel, tub)?.as_cell()?; - // let mut p_vex = vex.head(); - // let mut q_vex = vex.tail(); - // eprintln!("stir: got vex\r"); - // let i = 0; - // while unsafe { !q_vex.raw_equals(D(0)) } { - // eprintln!("stir: starting vex loop {}\r", i); - // let puq_vex = q_vex.as_cell()?.head(); - // let quq_vex = q_vex.as_cell()?.tail(); +// // push incremental, succesful [fel] parse results onto stack +// { +// let mut vex = slam(context, fel, tub)?.as_cell()?; +// let mut p_vex = vex.head(); +// let mut q_vex = vex.tail(); +// eprintln!("stir: got vex\r"); +// let i = 0; +// while unsafe { !q_vex.raw_equals(D(0)) } { +// eprintln!("stir: starting vex loop {}\r", i); +// let puq_vex = q_vex.as_cell()?.head(); +// let quq_vex = q_vex.as_cell()?.tail(); - // unsafe { - // *(context.stack.push::()) = StirPair { - // har: p_vex, - // res: puq_vex, - // }; - // }; +// unsafe { +// *(context.stack.push::()) = StirPair { +// har: p_vex, +// res: puq_vex, +// }; +// }; - // tub = quq_vex; +// tub = quq_vex; - // let slam_vex = slam(context, fel, tub); - // if slam_vex.is_err() { - // eprintln!("stir: slam vex failed\r"); - // } +// let slam_vex = slam(context, fel, tub); +// if slam_vex.is_err() { +// eprintln!("stir: slam vex failed\r"); +// } - // vex = slam_vex?.as_cell()?; - // p_vex = vex.head(); - // q_vex = vex.tail(); - // } - // eprintln!("stir: vex loop done\r"); +// vex = slam_vex?.as_cell()?; +// p_vex = vex.head(); +// q_vex = vex.tail(); +// } +// eprintln!("stir: vex loop done\r"); - // p_wag = p_vex; - // puq_wag = rud; - // quq_wag = tub; - // } +// p_wag = p_vex; +// puq_wag = rud; +// quq_wag = tub; +// } - // // unwind the stack, folding parse results into [wag] by way of [raq] - // eprintln!("stir: unwinding stack\r"); - // while !context.stack.stack_is_empty() { - // let par_u = unsafe { *(context.stack.top::()) }; - // p_wag = util::last(par_u.har, p_wag)?; - // let sam = T(&mut context.stack, &[par_u.res, puq_wag]); - // puq_wag = slam(context, raq, sam)?; - // unsafe { - // context.stack.pop::(); - // }; - // } +// // unwind the stack, folding parse results into [wag] by way of [raq] +// eprintln!("stir: unwinding stack\r"); +// while !context.stack.stack_is_empty() { +// let par_u = unsafe { *(context.stack.top::()) }; +// p_wag = util::last(par_u.har, p_wag)?; +// let sam = T(&mut context.stack, &[par_u.res, puq_wag]); +// puq_wag = slam(context, raq, sam)?; +// unsafe { +// context.stack.pop::(); +// }; +// } - // let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); +// let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); - // Ok(res) - // }) - // } +// Ok(res) +// }) +// } // } fn stew_wor(ort: Noun, wan: Noun) -> result::Result { + eprintln!("stew_wor\r"); if !ort.as_atom()?.is_direct() { return Err(JetErr::Fail(Error::Deterministic(D(0)))); - } - else { + } else { if !wan.is_cell() { if !wan.as_atom()?.is_direct() { return Err(JetErr::Fail(Error::Deterministic(D(0)))); - } - else { + } else { let ort_dat = ort.as_direct()?.data(); let wan_dat = wan.as_direct()?.data(); return Ok(ort_dat < wan_dat); } - } - else { + } else { let h_wan = wan.as_cell()?.head(); if !h_wan.as_atom()?.is_direct() { return Err(JetErr::Fail(Error::Deterministic(D(0)))); - } - else { + } else { let ort_dat = ort.as_direct()?.data(); let h_wan_dat = h_wan.as_direct()?.data(); return Ok(ort_dat < h_wan_dat); @@ -342,65 +339,60 @@ fn stew_wor(ort: Noun, wan: Noun) -> result::Result { } pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { + eprintln!("jet_stew\r"); let tub = slot(subject, 6)?; let con = slot(subject, 7)?; let mut hel = slot(con, 2)?; - let p_tub = tub.as_cell()?.head(); let q_tub = tub.as_cell()?.tail(); - match q_tub.as_cell() { - Ok(a) => { - let iq_tub = a.head(); - if !iq_tub.as_atom()?.is_direct() { - return util::fail(context, p_tub); - } - else { - loop { - if !hel.is_cell() { - return util::fail(context, tub); + if !q_tub.is_cell() { + return util::fail(context, tub); + } else { + let iq_tub = q_tub.as_cell()?.head(); + if !iq_tub.as_atom()?.is_direct() { + return util::fail(context, tub); + } else { + loop { + if !hel.is_cell() { + return util::fail(context, tub); + } else { + let n_hel = slot(hel, 2)?; + let l_hel = slot(hel, 6)?; + let r_hel = slot(hel, 7)?; + let pn_hel = n_hel.as_cell()?.head(); + let qn_hel = n_hel.as_cell()?.tail(); + let bit; + + if !pn_hel.is_cell() { + let iq_tub_dat = iq_tub.as_direct()?.data(); + let pn_hel_dat = pn_hel.as_direct()?.data(); + bit = iq_tub_dat == pn_hel_dat; + } else { + let hpn_hel = pn_hel.as_cell()?.head(); + let tpn_hel = pn_hel.as_cell()?.tail(); + + if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { + return util::fail(context, tub); + } else { + let iq_tub_dat = iq_tub.as_direct()?.data(); + let hpn_hel_dat = hpn_hel.as_direct()?.data(); + let tpn_hel_dat = tpn_hel.as_direct()?.data(); + bit = (iq_tub_dat >= hpn_hel_dat) && (iq_tub_dat <= tpn_hel_dat); + } } - else { - let n_hel = slot(hel, 2)?; - let l_hel = slot(hel, 6)?; - let r_hel = slot(hel, 7)?; - let pn_hel = n_hel.as_cell()?.head(); - let qn_hel = n_hel.as_cell()?.tail(); - let mut bit = false; - if !pn_hel.is_cell() { - bit = true; - } - else { - let hpn_hel = pn_hel.as_cell()?.head(); - let tpn_hel = pn_hel.as_cell()?.tail(); - - if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { - return util::fail(context, tub); - } - else { - let iq_tub_dat = iq_tub.as_direct()?.data(); - let hpn_hel_dat = hpn_hel.as_direct()?.data(); - let tpn_hel_dat = tpn_hel.as_direct()?.data(); - bit = (iq_tub_dat >= hpn_hel_dat) && (iq_tub_dat <= tpn_hel_dat); - } - } - - if bit { - return slam(context, qn_hel, tub); - } - else { - if stew_wor(iq_tub, pn_hel)? { - hel = l_hel; - } - else { - hel = r_hel; - } + if bit { + return slam(context, qn_hel, tub); + } else { + if stew_wor(iq_tub, pn_hel)? { + hel = l_hel; + } else { + hel = r_hel; } } } } } - Err(e) => { return Err(JetErr::Fail(e.into())); } } } From ede1db4b187815eed7dfaa0b3ea0279feae6b08a Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Fri, 8 Dec 2023 12:47:42 -0600 Subject: [PATCH 12/31] jets: fix jet_stir --- rust/ares/src/jets/parse.rs | 123 +++++++++++++++++------------------- 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 1a903dd..e36cffe 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -236,80 +236,75 @@ struct StirPair { pub res: Noun, } -// pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { -// XX -// jet should use with_frame -// with_frame should require output to be Preserve and should unconditionally preserve output -// JetErr, interpreter::Error, and Result need Preserve instances -// then jet simply calls with_frame and no need to preserve in jet -// unsafe { -// context.stack.with_frame(0, || { -// let mut tub = slot(subject, 6)?; -// let van = slot(subject, 7)?; -// let rud = slot(van, 12)?; -// let raq = slot(van, 26)?; -// let fel = slot(van, 27)?; +pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { + unsafe { + context.with_stack_frame(0, |context| { + let mut tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let rud = slot(van, 12)?; + let raq = slot(van, 26)?; + let fel = slot(van, 27)?; -// // initial accumulator (deconstructed) -// let mut p_wag: Noun; -// let mut puq_wag: Noun; -// let quq_wag: Noun; + // initial accumulator (deconstructed) + let mut p_wag: Noun; + let mut puq_wag: Noun; + let quq_wag: Noun; -// // push incremental, succesful [fel] parse results onto stack -// { -// let mut vex = slam(context, fel, tub)?.as_cell()?; -// let mut p_vex = vex.head(); -// let mut q_vex = vex.tail(); -// eprintln!("stir: got vex\r"); -// let i = 0; -// while unsafe { !q_vex.raw_equals(D(0)) } { -// eprintln!("stir: starting vex loop {}\r", i); -// let puq_vex = q_vex.as_cell()?.head(); -// let quq_vex = q_vex.as_cell()?.tail(); + // push incremental, succesful [fel] parse results onto stack + { + let mut vex = slam(context, fel, tub)?.as_cell()?; + let mut p_vex = vex.head(); + let mut q_vex = vex.tail(); + eprintln!("stir: got vex\r"); + let i = 0; + while unsafe { !q_vex.raw_equals(D(0)) } { + eprintln!("stir: starting vex loop {}\r", i); + let puq_vex = q_vex.as_cell()?.head(); + let quq_vex = q_vex.as_cell()?.tail(); -// unsafe { -// *(context.stack.push::()) = StirPair { -// har: p_vex, -// res: puq_vex, -// }; -// }; + unsafe { + *(context.stack.push::()) = StirPair { + har: p_vex, + res: puq_vex, + }; + }; -// tub = quq_vex; + tub = quq_vex; -// let slam_vex = slam(context, fel, tub); -// if slam_vex.is_err() { -// eprintln!("stir: slam vex failed\r"); -// } + let slam_vex = slam(context, fel, tub); + if slam_vex.is_err() { + eprintln!("stir: slam vex failed\r"); + } -// vex = slam_vex?.as_cell()?; -// p_vex = vex.head(); -// q_vex = vex.tail(); -// } -// eprintln!("stir: vex loop done\r"); + vex = slam_vex?.as_cell()?; + p_vex = vex.head(); + q_vex = vex.tail(); + } + eprintln!("stir: vex loop done\r"); -// p_wag = p_vex; -// puq_wag = rud; -// quq_wag = tub; -// } + p_wag = p_vex; + puq_wag = rud; + quq_wag = tub; + } -// // unwind the stack, folding parse results into [wag] by way of [raq] -// eprintln!("stir: unwinding stack\r"); -// while !context.stack.stack_is_empty() { -// let par_u = unsafe { *(context.stack.top::()) }; -// p_wag = util::last(par_u.har, p_wag)?; -// let sam = T(&mut context.stack, &[par_u.res, puq_wag]); -// puq_wag = slam(context, raq, sam)?; -// unsafe { -// context.stack.pop::(); -// }; -// } + // unwind the stack, folding parse results into [wag] by way of [raq] + eprintln!("stir: unwinding stack\r"); + while !context.stack.stack_is_empty() { + let par_u = unsafe { *(context.stack.top::()) }; + p_wag = util::last(par_u.har, p_wag)?; + let sam = T(&mut context.stack, &[par_u.res, puq_wag]); + puq_wag = slam(context, raq, sam)?; + unsafe { + context.stack.pop::(); + }; + } -// let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); + let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); -// Ok(res) -// }) -// } -// } + Ok(res) + }) + } +} fn stew_wor(ort: Noun, wan: Noun) -> result::Result { eprintln!("stew_wor\r"); From 620a5b3ab2135571678300629d74cb7f51f898f2 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 8 Dec 2023 14:13:39 -0500 Subject: [PATCH 13/31] wip: immaculate conception --- rust/ares/src/interpreter.rs | 1 - rust/ares/src/jets/hot.rs | 34 +++++++++++++++++----------------- rust/ares/src/jets/parse.rs | 36 +++++++++++++++--------------------- rust/ares/src/serf.rs | 2 +- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 67dd162..6cad6eb 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -917,7 +917,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res match nock { Ok(res) => Ok(res), Err(err) => { - let h = unsafe { *(context.stack.local_noun_pointer(0)) }; return Err(exit(context, &snapshot, virtual_frame, err)); } } diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 7748968..9e3f08e 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -440,21 +440,6 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_stag, ), // - // ( - // &[ - // K_139, - // Left(b"one"), - // Left(b"two"), - // Left(b"tri"), - // Left(b"qua"), - // Left(b"stir"), - // Left(b"fun"), - // ], - // 1, - // jet_stir, - // ), - // - // ( &[ K_139, @@ -462,12 +447,27 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ Left(b"two"), Left(b"tri"), Left(b"qua"), - Left(b"stew"), + Left(b"stir"), Left(b"fun"), ], 1, - jet_stew, + jet_stir, ), + // + // ( + // &[ + // K_139, + // Left(b"one"), + // Left(b"two"), + // Left(b"tri"), + // Left(b"qua"), + // Left(b"stew"), + // Left(b"fun"), + // ], + // 1, + // jet_stew, + // ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index e36cffe..972d266 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -252,35 +252,27 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { // push incremental, succesful [fel] parse results onto stack { - let mut vex = slam(context, fel, tub)?.as_cell()?; + let vex = slam(context, fel, tub)?.as_cell()?; let mut p_vex = vex.head(); let mut q_vex = vex.tail(); - eprintln!("stir: got vex\r"); + eprintln!("stir: got vex\r\n"); let i = 0; - while unsafe { !q_vex.raw_equals(D(0)) } { - eprintln!("stir: starting vex loop {}\r", i); + while !q_vex.raw_equals(D(0)) { + eprintln!("stir: starting vex loop {}\r\n", i); let puq_vex = q_vex.as_cell()?.head(); let quq_vex = q_vex.as_cell()?.tail(); - unsafe { - *(context.stack.push::()) = StirPair { - har: p_vex, - res: puq_vex, - }; + *(context.stack.push::()) = StirPair { + har: p_vex, + res: puq_vex, }; tub = quq_vex; - let slam_vex = slam(context, fel, tub); - if slam_vex.is_err() { - eprintln!("stir: slam vex failed\r"); - } - - vex = slam_vex?.as_cell()?; + let vex = slam(context, fel, tub)?.as_cell()?; p_vex = vex.head(); q_vex = vex.tail(); } - eprintln!("stir: vex loop done\r"); p_wag = p_vex; puq_wag = rud; @@ -288,19 +280,21 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { } // unwind the stack, folding parse results into [wag] by way of [raq] - eprintln!("stir: unwinding stack\r"); + let mut j = 0; while !context.stack.stack_is_empty() { - let par_u = unsafe { *(context.stack.top::()) }; + eprintln!("stir: unwinding stack loop {}\r\n", j); + let par_u = *(context.stack.top::()); p_wag = util::last(par_u.har, p_wag)?; let sam = T(&mut context.stack, &[par_u.res, puq_wag]); puq_wag = slam(context, raq, sam)?; - unsafe { - context.stack.pop::(); - }; + context.stack.pop::(); + j += 1; } let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); + eprintln!("stir: done!\r\n"); + Ok(res) }) } diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 518f33c..d0fb425 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -12,7 +12,7 @@ use crate::noun::{Atom, Cell, DirectAtom, Noun, Slots, D, T}; use crate::snapshot::double_jam::DoubleJam; use crate::snapshot::Snapshot; use crate::trace::*; -use crate::{interpreter, trace}; +use crate::interpreter; use ares_macros::tas; use signal_hook; use signal_hook::consts::SIGINT; From 0094130918f6178bfea487bcde3cb2dd02a60478 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 8 Dec 2023 15:15:20 -0500 Subject: [PATCH 14/31] wip: stir works more but segfaults now --- rust/ares/src/jets/parse.rs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 972d266..6dc5c55 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -255,12 +255,9 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { let vex = slam(context, fel, tub)?.as_cell()?; let mut p_vex = vex.head(); let mut q_vex = vex.tail(); - eprintln!("stir: got vex\r\n"); - let i = 0; while !q_vex.raw_equals(D(0)) { - eprintln!("stir: starting vex loop {}\r\n", i); - let puq_vex = q_vex.as_cell()?.head(); - let quq_vex = q_vex.as_cell()?.tail(); + let puq_vex = slot(q_vex, 6)?; + let quq_vex = slot(q_vex, 7)?; *(context.stack.push::()) = StirPair { har: p_vex, @@ -280,28 +277,21 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { } // unwind the stack, folding parse results into [wag] by way of [raq] - let mut j = 0; while !context.stack.stack_is_empty() { - eprintln!("stir: unwinding stack loop {}\r\n", j); let par_u = *(context.stack.top::()); p_wag = util::last(par_u.har, p_wag)?; let sam = T(&mut context.stack, &[par_u.res, puq_wag]); puq_wag = slam(context, raq, sam)?; context.stack.pop::(); - j += 1; } let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); - - eprintln!("stir: done!\r\n"); - Ok(res) }) } } fn stew_wor(ort: Noun, wan: Noun) -> result::Result { - eprintln!("stew_wor\r"); if !ort.as_atom()?.is_direct() { return Err(JetErr::Fail(Error::Deterministic(D(0)))); } else { @@ -499,14 +489,14 @@ pub mod util { let zyl = zyc.as_cell()?; let nal = naz.as_cell()?; - let zyll = zyl.head().as_direct()?.data(); - let zylc = zyl.tail().as_direct()?.data(); - let nall = nal.head().as_direct()?.data(); - let nalc = nal.tail().as_direct()?.data(); + let p_zyc = zyl.head().as_direct()?.data(); + let q_zyc = zyl.tail().as_direct()?.data(); + let p_naz = nal.head().as_direct()?.data(); + let q_naz = nal.tail().as_direct()?.data(); - match zyll.cmp(&nall) { + match p_zyc.cmp(&p_naz) { Ordering::Equal => { - if zylc > nalc { + if q_zyc > q_naz { Ok(zyc) } else { Ok(naz) From dd13cba5dfb6b655f20498ad65f73b5532993c17 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sat, 9 Dec 2023 10:25:24 -0500 Subject: [PATCH 15/31] wip: debugging `stew` --- rust/ares/src/jets/hot.rs | 26 +++++++++++++------------- rust/ares/src/jets/parse.rs | 4 ++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 9e3f08e..d4dca14 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -454,19 +454,19 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_stir, ), // - // ( - // &[ - // K_139, - // Left(b"one"), - // Left(b"two"), - // Left(b"tri"), - // Left(b"qua"), - // Left(b"stew"), - // Left(b"fun"), - // ], - // 1, - // jet_stew, - // ), + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"stew"), + Left(b"fun"), + ], + 1, + jet_stew, + ), // ( &[ diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 6dc5c55..c730f6e 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -292,6 +292,7 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { } fn stew_wor(ort: Noun, wan: Noun) -> result::Result { + eprintln!("stew_wor\r"); if !ort.as_atom()?.is_direct() { return Err(JetErr::Fail(Error::Deterministic(D(0)))); } else { @@ -301,6 +302,7 @@ fn stew_wor(ort: Noun, wan: Noun) -> result::Result { } else { let ort_dat = ort.as_direct()?.data(); let wan_dat = wan.as_direct()?.data(); + eprintln!("stew wor: done\r"); return Ok(ort_dat < wan_dat); } } else { @@ -311,6 +313,7 @@ fn stew_wor(ort: Noun, wan: Noun) -> result::Result { } else { let ort_dat = ort.as_direct()?.data(); let h_wan_dat = h_wan.as_direct()?.data(); + eprintln!("stew wor: done\r"); return Ok(ort_dat < h_wan_dat); } } @@ -361,6 +364,7 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { } if bit { + eprintln!("jet_stew: bit slam\r"); return slam(context, qn_hel, tub); } else { if stew_wor(iq_tub, pn_hel)? { From 63ccabf1f1d544167fb59e83fab500b44e5e649e Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sat, 9 Dec 2023 16:27:09 -0500 Subject: [PATCH 16/31] wip: stew still broken --- rust/ares/src/jets/parse.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index c730f6e..69c8190 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -292,7 +292,6 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { } fn stew_wor(ort: Noun, wan: Noun) -> result::Result { - eprintln!("stew_wor\r"); if !ort.as_atom()?.is_direct() { return Err(JetErr::Fail(Error::Deterministic(D(0)))); } else { @@ -302,7 +301,7 @@ fn stew_wor(ort: Noun, wan: Noun) -> result::Result { } else { let ort_dat = ort.as_direct()?.data(); let wan_dat = wan.as_direct()?.data(); - eprintln!("stew wor: done\r"); + eprintln!("stew_wor: return {}\r", ort_dat < wan_dat); return Ok(ort_dat < wan_dat); } } else { @@ -313,7 +312,7 @@ fn stew_wor(ort: Noun, wan: Noun) -> result::Result { } else { let ort_dat = ort.as_direct()?.data(); let h_wan_dat = h_wan.as_direct()?.data(); - eprintln!("stew wor: done\r"); + eprintln!("stew_wor: return {}\r", ort_dat < h_wan_dat); return Ok(ort_dat < h_wan_dat); } } @@ -321,7 +320,7 @@ fn stew_wor(ort: Noun, wan: Noun) -> result::Result { } pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { - eprintln!("jet_stew\r"); + eprintln!("jet_stew: start\r"); let tub = slot(subject, 6)?; let con = slot(subject, 7)?; let mut hel = slot(con, 2)?; @@ -334,8 +333,10 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { if !iq_tub.as_atom()?.is_direct() { return util::fail(context, tub); } else { + let iq_tub_dat = iq_tub.as_direct()?.data(); loop { if !hel.is_cell() { + eprintln!("jet_stew: hel not cell\r"); return util::fail(context, tub); } else { let n_hel = slot(hel, 2)?; @@ -346,9 +347,9 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { let bit; if !pn_hel.is_cell() { - let iq_tub_dat = iq_tub.as_direct()?.data(); let pn_hel_dat = pn_hel.as_direct()?.data(); bit = iq_tub_dat == pn_hel_dat; + eprintln!("jet_stew: first bit to {}\r", bit); } else { let hpn_hel = pn_hel.as_cell()?.head(); let tpn_hel = pn_hel.as_cell()?.tail(); @@ -356,20 +357,23 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { return util::fail(context, tub); } else { - let iq_tub_dat = iq_tub.as_direct()?.data(); let hpn_hel_dat = hpn_hel.as_direct()?.data(); let tpn_hel_dat = tpn_hel.as_direct()?.data(); - bit = (iq_tub_dat >= hpn_hel_dat) && (iq_tub_dat <= tpn_hel_dat); + bit = iq_tub_dat >= hpn_hel_dat && iq_tub_dat <= tpn_hel_dat; + eprintln!("jet_stew: second bit to {}\r", bit); } } if bit { - eprintln!("jet_stew: bit slam\r"); + eprintln!("jet_stew: slam\r"); return slam(context, qn_hel, tub); } else { + eprintln!("jet_stew: stew_wor\r"); if stew_wor(iq_tub, pn_hel)? { + eprintln!("jet_stew: left\r"); hel = l_hel; } else { + eprintln!("jet_stew: right\r"); hel = r_hel; } } From df0790ef0bf91e0032828a1c3f7f877a293c94b8 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sat, 9 Dec 2023 21:38:08 -0500 Subject: [PATCH 17/31] wip: stew 12/9 --- rust/ares/src/jets/math.rs | 105 ++++++++++++++++++++---------------- rust/ares/src/jets/parse.rs | 64 +++++++++++----------- 2 files changed, 92 insertions(+), 77 deletions(-) diff --git a/rust/ares/src/jets/math.rs b/rust/ares/src/jets/math.rs index f7b03be..e8f46d3 100644 --- a/rust/ares/src/jets/math.rs +++ b/rust/ares/src/jets/math.rs @@ -120,21 +120,7 @@ pub fn jet_gte(context: &mut Context, subject: Noun) -> Result { let a = slot(arg, 2)?.as_atom()?; let b = slot(arg, 3)?.as_atom()?; - Ok(if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() >= b.data() { - YES - } else { - NO - } - } else if a.bit_size() > b.bit_size() { - YES - } else if a.bit_size() < b.bit_size() { - NO - } else if a.as_ubig(stack) >= b.as_ubig(stack) { - YES - } else { - NO - }) + Ok(if util::gte(stack, a, b) { YES } else { NO }) } pub fn jet_gth(context: &mut Context, subject: Noun) -> Result { @@ -143,21 +129,7 @@ pub fn jet_gth(context: &mut Context, subject: Noun) -> Result { let a = slot(arg, 2)?.as_atom()?; let b = slot(arg, 3)?.as_atom()?; - Ok(if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() > b.data() { - YES - } else { - NO - } - } else if a.bit_size() > b.bit_size() { - YES - } else if a.bit_size() < b.bit_size() { - NO - } else if a.as_ubig(stack) > b.as_ubig(stack) { - YES - } else { - NO - }) + Ok(if util::gth(stack, a, b) { YES } else { NO }) } pub fn jet_lte(context: &mut Context, subject: Noun) -> Result { @@ -166,21 +138,7 @@ pub fn jet_lte(context: &mut Context, subject: Noun) -> Result { let a = slot(arg, 2)?.as_atom()?; let b = slot(arg, 3)?.as_atom()?; - Ok(if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() <= b.data() { - YES - } else { - NO - } - } else if a.bit_size() < b.bit_size() { - YES - } else if a.bit_size() > b.bit_size() { - NO - } else if a.as_ubig(stack) <= b.as_ubig(stack) { - YES - } else { - NO - }) + Ok(if util::lte(stack, a, b) { YES } else { NO }) } pub fn jet_lth(context: &mut Context, subject: Noun) -> Result { @@ -307,6 +265,25 @@ pub mod util { } } + /// Greater than + pub fn gth(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { + if a.data() > b.data() { + true + } else { + false + } + } else if a.bit_size() > b.bit_size() { + true + } else if a.bit_size() < b.bit_size() { + false + } else if a.as_ubig(stack) > b.as_ubig(stack) { + true + } else { + false + } + } + /// Less than pub fn lth(stack: &mut NockStack, a: Atom, b: Atom) -> Noun { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { @@ -326,6 +303,44 @@ pub mod util { } } + /// Less than or equal to + pub fn lte(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { + if a.data() <= b.data() { + true + } else { + false + } + } else if a.bit_size() < b.bit_size() { + true + } else if a.bit_size() > b.bit_size() { + false + } else if a.as_ubig(stack) <= b.as_ubig(stack) { + true + } else { + false + } + } + + /// Greater than or equal to + pub fn gte(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { + if a.data() >= b.data() { + true + } else { + false + } + } else if a.bit_size() > b.bit_size() { + true + } else if a.bit_size() < b.bit_size() { + false + } else if a.as_ubig(stack) >= b.as_ubig(stack) { + true + } else { + false + } + } + /// Subtraction pub fn sub(stack: &mut NockStack, a: Atom, b: Atom) -> Result { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 69c8190..4ce8567 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -2,12 +2,16 @@ use std::result; /** Parsing jets */ +use either::{Left, Right}; use crate::interpreter::{Context, Error}; +use crate::jets::math::util::{gte, lte}; use crate::jets::util::{kick, slam, slot}; use crate::jets::Result; -use crate::noun::{Noun, D, T}; +use crate::mem::NockStack; +use crate::noun::{Noun, D, T, YES}; use super::JetErr; +use super::math::util::lth; crate::gdb!(); @@ -291,29 +295,26 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { } } -fn stew_wor(ort: Noun, wan: Noun) -> result::Result { - if !ort.as_atom()?.is_direct() { - return Err(JetErr::Fail(Error::Deterministic(D(0)))); - } else { - if !wan.is_cell() { - if !wan.as_atom()?.is_direct() { - return Err(JetErr::Fail(Error::Deterministic(D(0)))); - } else { - let ort_dat = ort.as_direct()?.data(); - let wan_dat = wan.as_direct()?.data(); - eprintln!("stew_wor: return {}\r", ort_dat < wan_dat); - return Ok(ort_dat < wan_dat); +fn stew_wor(stack: &mut NockStack, ort: Noun, wan: Noun) -> Result { + match ort.as_either_atom_cell() { + Left(ort_atom) => { + match wan.as_either_atom_cell() { + Left(wan_atom) => { + Ok(lth(stack, ort_atom, wan_atom)) + } + Right(wan_cell) => { + Ok(lth(stack, ort_atom, wan_cell.head().as_atom()?)) + } } - } else { - let h_wan = wan.as_cell()?.head(); - - if !h_wan.as_atom()?.is_direct() { - return Err(JetErr::Fail(Error::Deterministic(D(0)))); - } else { - let ort_dat = ort.as_direct()?.data(); - let h_wan_dat = h_wan.as_direct()?.data(); - eprintln!("stew_wor: return {}\r", ort_dat < h_wan_dat); - return Ok(ort_dat < h_wan_dat); + } + Right(ort_cell) => { + match wan.as_either_atom_cell() { + Left(wan_atom) => { + Ok(lth(stack, ort_cell.tail().as_atom()?, wan_atom)) + } + Right(wan_cell) => { + Ok(lth(stack, ort_cell.tail().as_atom()?, wan_cell.head().as_atom()?)) + } } } } @@ -326,16 +327,15 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { let mut hel = slot(con, 2)?; let q_tub = tub.as_cell()?.tail(); - if !q_tub.is_cell() { + if unsafe { q_tub.raw_equals(D(0)) } { return util::fail(context, tub); } else { let iq_tub = q_tub.as_cell()?.head(); if !iq_tub.as_atom()?.is_direct() { return util::fail(context, tub); } else { - let iq_tub_dat = iq_tub.as_direct()?.data(); loop { - if !hel.is_cell() { + if unsafe { hel.raw_equals(D(0)) } { eprintln!("jet_stew: hel not cell\r"); return util::fail(context, tub); } else { @@ -347,8 +347,7 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { let bit; if !pn_hel.is_cell() { - let pn_hel_dat = pn_hel.as_direct()?.data(); - bit = iq_tub_dat == pn_hel_dat; + bit = unsafe { iq_tub.raw_equals(pn_hel) }; eprintln!("jet_stew: first bit to {}\r", bit); } else { let hpn_hel = pn_hel.as_cell()?.head(); @@ -357,9 +356,10 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { return util::fail(context, tub); } else { - let hpn_hel_dat = hpn_hel.as_direct()?.data(); - let tpn_hel_dat = tpn_hel.as_direct()?.data(); - bit = iq_tub_dat >= hpn_hel_dat && iq_tub_dat <= tpn_hel_dat; + let iq_tub_atom = iq_tub.as_atom()?; + let hpn_hel_atom = hpn_hel.as_atom()?; + let tpn_hel_atom = tpn_hel.as_atom()?; + bit = gte(&mut context.stack, iq_tub_atom, hpn_hel_atom) && lte(&mut context.stack, iq_tub_atom, tpn_hel_atom); eprintln!("jet_stew: second bit to {}\r", bit); } } @@ -369,7 +369,7 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { return slam(context, qn_hel, tub); } else { eprintln!("jet_stew: stew_wor\r"); - if stew_wor(iq_tub, pn_hel)? { + if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { eprintln!("jet_stew: left\r"); hel = l_hel; } else { From 20593a91a476080e71b68ddca0a6ad58d6e62087 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sun, 10 Dec 2023 07:27:10 -0500 Subject: [PATCH 18/31] jets: `stew` --- rust/ares/src/jets/parse.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 4ce8567..1ffcab7 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -321,23 +321,22 @@ fn stew_wor(stack: &mut NockStack, ort: Noun, wan: Noun) -> Result { } pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { - eprintln!("jet_stew: start\r"); let tub = slot(subject, 6)?; let con = slot(subject, 7)?; let mut hel = slot(con, 2)?; + let p_tub = tub.as_cell()?.head(); let q_tub = tub.as_cell()?.tail(); if unsafe { q_tub.raw_equals(D(0)) } { - return util::fail(context, tub); + return util::fail(context, p_tub); } else { let iq_tub = q_tub.as_cell()?.head(); if !iq_tub.as_atom()?.is_direct() { - return util::fail(context, tub); + return util::fail(context, p_tub); } else { loop { if unsafe { hel.raw_equals(D(0)) } { - eprintln!("jet_stew: hel not cell\r"); - return util::fail(context, tub); + return util::fail(context, p_tub); } else { let n_hel = slot(hel, 2)?; let l_hel = slot(hel, 6)?; @@ -347,33 +346,29 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { let bit; if !pn_hel.is_cell() { - bit = unsafe { iq_tub.raw_equals(pn_hel) }; - eprintln!("jet_stew: first bit to {}\r", bit); + bit = iq_tub.as_direct()?.data() == pn_hel.as_direct()?.data(); } else { let hpn_hel = pn_hel.as_cell()?.head(); let tpn_hel = pn_hel.as_cell()?.tail(); if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { - return util::fail(context, tub); + return util::fail(context, p_tub); } else { let iq_tub_atom = iq_tub.as_atom()?; let hpn_hel_atom = hpn_hel.as_atom()?; let tpn_hel_atom = tpn_hel.as_atom()?; bit = gte(&mut context.stack, iq_tub_atom, hpn_hel_atom) && lte(&mut context.stack, iq_tub_atom, tpn_hel_atom); - eprintln!("jet_stew: second bit to {}\r", bit); } } if bit { - eprintln!("jet_stew: slam\r"); return slam(context, qn_hel, tub); } else { - eprintln!("jet_stew: stew_wor\r"); if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { - eprintln!("jet_stew: left\r"); + if unsafe { l_hel.raw_equals(D(0)) } { + } hel = l_hel; } else { - eprintln!("jet_stew: right\r"); hel = r_hel; } } From 4e0b0a89294d460cc79894aec6b9c7d6cccc2679 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sun, 10 Dec 2023 07:37:01 -0500 Subject: [PATCH 19/31] jets: `shim` --- rust/ares/src/jets/hot.rs | 14 ++++++++++++++ rust/ares/src/jets/parse.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index d4dca14..a2ae849 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -426,6 +426,20 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_mask, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"shim"), + Left(b"fun"), + ], + 1, + jet_shim, + ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 1ffcab7..800197e 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -378,6 +378,35 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { } } +pub fn jet_shim(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let zep = slot(van, 6)?; + + let p_tub = tub.as_cell()?.head(); + let q_tub = tub.as_cell()?.tail(); + + if unsafe { q_tub.raw_equals(D(0)) } { + return util::fail(context, p_tub); + } + else { + let p_zep = zep.as_cell()?.head(); + let q_zep = zep.as_cell()?.tail(); + let iq_tub = q_tub.as_cell()?.head(); + + let p_zep_dat = p_zep.as_direct()?.data(); + let q_zep_dat = q_zep.as_direct()?.data(); + let iq_tub_dat = iq_tub.as_direct()?.data(); + + if (iq_tub_dat >= p_zep_dat) && (iq_tub_dat <= q_zep_dat) { + return util::next(context, tub); + } + else { + return util::fail(context, p_tub); + } + } +} + // // Rule Builders // From e209c1f0bded3a147f6c4ea6c4919d06a92570d6 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sun, 10 Dec 2023 07:43:28 -0500 Subject: [PATCH 20/31] jets: `plug` --- rust/ares/src/jets/hot.rs | 13 +++++++++++++ rust/ares/src/jets/parse.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index a2ae849..6e120dd 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -344,6 +344,19 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_pfix, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"plug"), + ], + 1, + jet_plug, + ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 800197e..f1b2ec5 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -185,6 +185,40 @@ pub fn jet_pfix(context: &mut Context, subject: Noun) -> Result { Ok(T(&mut context.stack, &[arg, q_yit])) } +pub fn jet_plug(context: &mut Context, subject: Noun) -> Result { + let vex = slot(subject, 12)?; + let sab = slot(subject, 13)?; + + let p_vex = vex.as_cell()?.head(); + let q_vex = vex.as_cell()?.tail(); + + if unsafe { q_vex.raw_equals(D(0)) } { + Ok(vex) + } + else { + let uq_vex = q_vex.as_cell()?.tail().as_cell()?; + let puq_vex = uq_vex.head(); + let quq_vex = uq_vex.tail(); + + let yit = slam(context, sab, quq_vex)?.as_cell()?; + let p_yit = yit.head(); + let q_yit = yit.tail(); + + let yur = util::last(p_vex, p_yit)?; + + if unsafe { q_yit.raw_equals(D(0)) } { + Ok(T(&mut context.stack, &[yur, D(0)])) + } else { + let uq_yit = q_yit.as_cell()?.tail().as_cell()?; + let puq_yit = uq_yit.head(); + let quq_yit = uq_yit.tail(); + + let inner = T(&mut context.stack, &[puq_vex, puq_yit]); + Ok(T(&mut context.stack, &[yur, D(0), inner, quq_yit])) + } + } +} + pub fn jet_pose(context: &mut Context, subject: Noun) -> Result { let vex = slot(subject, 12)?.as_cell()?; let sab = slot(subject, 13)?; From 1543664377061186ad7763bbdaf44e790f6a913d Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sun, 10 Dec 2023 07:47:50 -0500 Subject: [PATCH 21/31] jets: `cold` --- rust/ares/src/jets/hot.rs | 14 ++++++++++++++ rust/ares/src/jets/parse.rs | 25 +++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 6e120dd..acae939 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -303,6 +303,20 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_bend, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"cold"), + Left(b"fun"), + ], + 1, + jet_cold, + ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index f1b2ec5..e868179 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,16 +1,13 @@ -use std::result; - /** Parsing jets */ use either::{Left, Right}; -use crate::interpreter::{Context, Error}; +use crate::interpreter::Context; use crate::jets::math::util::{gte, lte}; use crate::jets::util::{kick, slam, slot}; use crate::jets::Result; use crate::mem::NockStack; use crate::noun::{Noun, D, T, YES}; -use super::JetErr; use super::math::util::lth; crate::gdb!(); @@ -74,6 +71,26 @@ pub fn jet_bend(context: &mut Context, subject: Noun) -> Result { } } +pub fn jet_cold(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let cus = slot(van, 12)?; + let sef = slot(van, 13)?; + + let vex = slam(context, sef, tub)?.as_cell()?; + let p_vex = vex.head(); + let q_vex = vex.tail(); + + if unsafe { q_vex.raw_equals(D(0)) } { + Ok(vex.as_noun()) + } else { + let uq_vex = q_vex.as_cell()?.tail().as_cell()?; + let quq_vex = uq_vex.tail(); + + Ok(T(&mut context.stack, &[p_vex, D(0), cus, quq_vex])) + } +} + pub fn jet_comp(context: &mut Context, subject: Noun) -> Result { let sam = slot(subject, 6)?; let vex = slot(sam, 2)?.as_cell()?; From 6b17f11ebe7756eff8ccab9bfacba5d368e72545 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sun, 10 Dec 2023 08:12:33 -0500 Subject: [PATCH 22/31] jets: `cook` --- rust/ares/src/jets/hot.rs | 14 ++++++++++++++ rust/ares/src/jets/parse.rs | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index acae939..ea0beb4 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -331,6 +331,20 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_comp, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"cook"), + Left(b"fun"), + ], + 1, + jet_cook, + ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index e868179..f608b74 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -128,6 +128,28 @@ pub fn jet_comp(context: &mut Context, subject: Noun) -> Result { } } +pub fn jet_cook(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let poq = slot(van, 12)?; + let sef = slot(van, 13)?; + + let vex = slam(context, sef, tub)?.as_cell()?; + let p_vex = vex.head(); + let q_vex = vex.tail(); + + if unsafe { q_vex.raw_equals(D(0)) } { + Ok(vex.as_noun()) + } else { + let uq_vex = q_vex.as_cell()?.tail().as_cell()?; + let puq_vex = uq_vex.head(); + let quq_vex = uq_vex.tail(); + + let wag = slam(context, poq, puq_vex)?; + Ok(T(&mut context.stack, &[p_vex, D(0), wag, quq_vex])) + } +} + pub fn jet_glue(context: &mut Context, subject: Noun) -> Result { let sam = slot(subject, 6)?; let vex = slot(sam, 2)?.as_cell()?; From e1e79bbef486a8e985364f67e2af0ecb72f4d9cc Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Tue, 19 Dec 2023 14:51:21 -0300 Subject: [PATCH 23/31] jets: cargo fmt + lint --- rust/ares/src/interpreter.rs | 4 +- rust/ares/src/jets/math.rs | 30 ++------- rust/ares/src/jets/parse.rs | 124 ++++++++++++++++------------------- rust/ares/src/serf.rs | 2 +- 4 files changed, 63 insertions(+), 97 deletions(-) diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index af54984..bf406af 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -919,9 +919,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res match nock { Ok(res) => Ok(res), - Err(err) => { - return Err(exit(context, &snapshot, virtual_frame, err)); - } + Err(err) => Err(exit(context, &snapshot, virtual_frame, err)), } } diff --git a/rust/ares/src/jets/math.rs b/rust/ares/src/jets/math.rs index e8f46d3..b63cb66 100644 --- a/rust/ares/src/jets/math.rs +++ b/rust/ares/src/jets/math.rs @@ -268,19 +268,13 @@ pub mod util { /// Greater than pub fn gth(stack: &mut NockStack, a: Atom, b: Atom) -> bool { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() > b.data() { - true - } else { - false - } + a.data() > b.data() } else if a.bit_size() > b.bit_size() { true } else if a.bit_size() < b.bit_size() { false - } else if a.as_ubig(stack) > b.as_ubig(stack) { - true } else { - false + a.as_ubig(stack) > b.as_ubig(stack) } } @@ -306,38 +300,26 @@ pub mod util { /// Less than or equal to pub fn lte(stack: &mut NockStack, a: Atom, b: Atom) -> bool { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() <= b.data() { - true - } else { - false - } + a.data() <= b.data() } else if a.bit_size() < b.bit_size() { true } else if a.bit_size() > b.bit_size() { false - } else if a.as_ubig(stack) <= b.as_ubig(stack) { - true } else { - false + a.as_ubig(stack) <= b.as_ubig(stack) } } /// Greater than or equal to pub fn gte(stack: &mut NockStack, a: Atom, b: Atom) -> bool { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() >= b.data() { - true - } else { - false - } + a.data() >= b.data() } else if a.bit_size() > b.bit_size() { true } else if a.bit_size() < b.bit_size() { false - } else if a.as_ubig(stack) >= b.as_ubig(stack) { - true } else { - false + a.as_ubig(stack) >= b.as_ubig(stack) } } diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index f608b74..2fc28d6 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,12 +1,12 @@ /** Parsing jets */ -use either::{Left, Right}; use crate::interpreter::Context; use crate::jets::math::util::{gte, lte}; use crate::jets::util::{kick, slam, slot}; use crate::jets::Result; use crate::mem::NockStack; use crate::noun::{Noun, D, T, YES}; +use either::{Left, Right}; use super::math::util::lth; @@ -233,8 +233,7 @@ pub fn jet_plug(context: &mut Context, subject: Noun) -> Result { if unsafe { q_vex.raw_equals(D(0)) } { Ok(vex) - } - else { + } else { let uq_vex = q_vex.as_cell()?.tail().as_cell()?; let puq_vex = uq_vex.head(); let quq_vex = uq_vex.tail(); @@ -370,26 +369,18 @@ pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { fn stew_wor(stack: &mut NockStack, ort: Noun, wan: Noun) -> Result { match ort.as_either_atom_cell() { - Left(ort_atom) => { - match wan.as_either_atom_cell() { - Left(wan_atom) => { - Ok(lth(stack, ort_atom, wan_atom)) - } - Right(wan_cell) => { - Ok(lth(stack, ort_atom, wan_cell.head().as_atom()?)) - } - } - } - Right(ort_cell) => { - match wan.as_either_atom_cell() { - Left(wan_atom) => { - Ok(lth(stack, ort_cell.tail().as_atom()?, wan_atom)) - } - Right(wan_cell) => { - Ok(lth(stack, ort_cell.tail().as_atom()?, wan_cell.head().as_atom()?)) - } - } - } + Left(ort_atom) => match wan.as_either_atom_cell() { + Left(wan_atom) => Ok(lth(stack, ort_atom, wan_atom)), + Right(wan_cell) => Ok(lth(stack, ort_atom, wan_cell.head().as_atom()?)), + }, + Right(ort_cell) => match wan.as_either_atom_cell() { + Left(wan_atom) => Ok(lth(stack, ort_cell.tail().as_atom()?, wan_atom)), + Right(wan_cell) => Ok(lth( + stack, + ort_cell.tail().as_atom()?, + wan_cell.head().as_atom()?, + )), + }, } } @@ -402,51 +393,48 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { let q_tub = tub.as_cell()?.tail(); if unsafe { q_tub.raw_equals(D(0)) } { return util::fail(context, p_tub); - } else { - let iq_tub = q_tub.as_cell()?.head(); - if !iq_tub.as_atom()?.is_direct() { + } + + let iq_tub = q_tub.as_cell()?.head(); + if !iq_tub.as_atom()?.is_direct() { + return util::fail(context, p_tub); + } + + loop { + if unsafe { hel.raw_equals(D(0)) } { return util::fail(context, p_tub); } else { - loop { - if unsafe { hel.raw_equals(D(0)) } { + let n_hel = slot(hel, 2)?; + let l_hel = slot(hel, 6)?; + let r_hel = slot(hel, 7)?; + let pn_hel = n_hel.as_cell()?.head(); + let qn_hel = n_hel.as_cell()?.tail(); + let bit; + + if !pn_hel.is_cell() { + bit = iq_tub.as_direct()?.data() == pn_hel.as_direct()?.data(); + } else { + let hpn_hel = pn_hel.as_cell()?.head(); + let tpn_hel = pn_hel.as_cell()?.tail(); + + if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { return util::fail(context, p_tub); } else { - let n_hel = slot(hel, 2)?; - let l_hel = slot(hel, 6)?; - let r_hel = slot(hel, 7)?; - let pn_hel = n_hel.as_cell()?.head(); - let qn_hel = n_hel.as_cell()?.tail(); - let bit; - - if !pn_hel.is_cell() { - bit = iq_tub.as_direct()?.data() == pn_hel.as_direct()?.data(); - } else { - let hpn_hel = pn_hel.as_cell()?.head(); - let tpn_hel = pn_hel.as_cell()?.tail(); - - if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { - return util::fail(context, p_tub); - } else { - let iq_tub_atom = iq_tub.as_atom()?; - let hpn_hel_atom = hpn_hel.as_atom()?; - let tpn_hel_atom = tpn_hel.as_atom()?; - bit = gte(&mut context.stack, iq_tub_atom, hpn_hel_atom) && lte(&mut context.stack, iq_tub_atom, tpn_hel_atom); - } - } - - if bit { - return slam(context, qn_hel, tub); - } else { - if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { - if unsafe { l_hel.raw_equals(D(0)) } { - } - hel = l_hel; - } else { - hel = r_hel; - } - } + let iq_tub_atom = iq_tub.as_atom()?; + let hpn_hel_atom = hpn_hel.as_atom()?; + let tpn_hel_atom = tpn_hel.as_atom()?; + bit = gte(&mut context.stack, iq_tub_atom, hpn_hel_atom) + && lte(&mut context.stack, iq_tub_atom, tpn_hel_atom); } } + + if bit { + return slam(context, qn_hel, tub); + } else if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { + hel = l_hel; + } else { + hel = r_hel; + } } } } @@ -460,9 +448,8 @@ pub fn jet_shim(context: &mut Context, subject: Noun) -> Result { let q_tub = tub.as_cell()?.tail(); if unsafe { q_tub.raw_equals(D(0)) } { - return util::fail(context, p_tub); - } - else { + util::fail(context, p_tub) + } else { let p_zep = zep.as_cell()?.head(); let q_zep = zep.as_cell()?.tail(); let iq_tub = q_tub.as_cell()?.head(); @@ -472,10 +459,9 @@ pub fn jet_shim(context: &mut Context, subject: Noun) -> Result { let iq_tub_dat = iq_tub.as_direct()?.data(); if (iq_tub_dat >= p_zep_dat) && (iq_tub_dat <= q_zep_dat) { - return util::next(context, tub); - } - else { - return util::fail(context, p_tub); + util::next(context, tub) + } else { + util::fail(context, p_tub) } } } diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 3787edd..4c14824 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -1,4 +1,5 @@ use crate::hamt::Hamt; +use crate::interpreter; use crate::interpreter::{inc, interpret, Error}; use crate::jets::cold::Cold; use crate::jets::hot::{Hot, HotEntry}; @@ -10,7 +11,6 @@ use crate::mug::*; use crate::newt::Newt; use crate::noun::{Atom, Cell, DirectAtom, Noun, Slots, D, T}; use crate::trace::*; -use crate::interpreter; use ares_macros::tas; use signal_hook; use signal_hook::consts::SIGINT; From 5bc00a175b5e29b046f2e3b5964fb827363c31d8 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Tue, 19 Dec 2023 16:44:51 -0300 Subject: [PATCH 24/31] jets: boolean helpers for comparator jets --- rust/ares/src/jets/math.rs | 90 ++++++++++++++++++++++++------------- rust/ares/src/jets/parse.rs | 8 ++-- 2 files changed, 63 insertions(+), 35 deletions(-) diff --git a/rust/ares/src/jets/math.rs b/rust/ares/src/jets/math.rs index b63cb66..ba7a45b 100644 --- a/rust/ares/src/jets/math.rs +++ b/rust/ares/src/jets/math.rs @@ -15,7 +15,7 @@ use crate::interpreter::{Context, Error}; use crate::jets::util::*; use crate::jets::{JetErr, Result}; -use crate::noun::{Atom, DirectAtom, IndirectAtom, Noun, D, DIRECT_MAX, NO, T, YES}; +use crate::noun::{Atom, DirectAtom, IndirectAtom, Noun, D, DIRECT_MAX, T}; use either::{Left, Right}; use ibig::ops::DivRem; use ibig::UBig; @@ -120,7 +120,7 @@ pub fn jet_gte(context: &mut Context, subject: Noun) -> Result { let a = slot(arg, 2)?.as_atom()?; let b = slot(arg, 3)?.as_atom()?; - Ok(if util::gte(stack, a, b) { YES } else { NO }) + Ok(util::gte(stack, a, b)) } pub fn jet_gth(context: &mut Context, subject: Noun) -> Result { @@ -129,7 +129,7 @@ pub fn jet_gth(context: &mut Context, subject: Noun) -> Result { let a = slot(arg, 2)?.as_atom()?; let b = slot(arg, 3)?.as_atom()?; - Ok(if util::gth(stack, a, b) { YES } else { NO }) + Ok(util::gth(stack, a, b)) } pub fn jet_lte(context: &mut Context, subject: Noun) -> Result { @@ -138,7 +138,7 @@ pub fn jet_lte(context: &mut Context, subject: Noun) -> Result { let a = slot(arg, 2)?.as_atom()?; let b = slot(arg, 3)?.as_atom()?; - Ok(if util::lte(stack, a, b) { YES } else { NO }) + Ok(util::lte(stack, a, b)) } pub fn jet_lth(context: &mut Context, subject: Noun) -> Result { @@ -265,8 +265,30 @@ pub mod util { } } - /// Greater than - pub fn gth(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + /// Greater than or equal to (boolean) + pub fn gte_b(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { + a.data() >= b.data() + } else if a.bit_size() > b.bit_size() { + true + } else if a.bit_size() < b.bit_size() { + false + } else { + a.as_ubig(stack) >= b.as_ubig(stack) + } + } + + /// Greater than or equal to + pub fn gte(stack: &mut NockStack, a: Atom, b: Atom) -> Noun { + if gte_b(stack, a, b) { + YES + } else { + NO + } + } + + /// Greater than (boolean) + pub fn gth_b(stack: &mut NockStack, a: Atom, b: Atom) -> bool { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { a.data() > b.data() } else if a.bit_size() > b.bit_size() { @@ -278,27 +300,17 @@ pub mod util { } } - /// Less than - pub fn lth(stack: &mut NockStack, a: Atom, b: Atom) -> Noun { - if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - if a.data() < b.data() { - YES - } else { - NO - } - } else if a.bit_size() < b.bit_size() { - YES - } else if a.bit_size() > b.bit_size() { - NO - } else if a.as_ubig(stack) < b.as_ubig(stack) { + /// Greater than + pub fn gth(stack: &mut NockStack, a: Atom, b: Atom) -> Noun { + if gth_b(stack, a, b) { YES } else { NO } } - /// Less than or equal to - pub fn lte(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + /// Less than or equal to (boolean) + pub fn lte_b(stack: &mut NockStack, a: Atom, b: Atom) -> bool { if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { a.data() <= b.data() } else if a.bit_size() < b.bit_size() { @@ -310,16 +322,34 @@ pub mod util { } } - /// Greater than or equal to - pub fn gte(stack: &mut NockStack, a: Atom, b: Atom) -> bool { - if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { - a.data() >= b.data() - } else if a.bit_size() > b.bit_size() { - true - } else if a.bit_size() < b.bit_size() { - false + /// Less than or equal to + pub fn lte(stack: &mut NockStack, a: Atom, b: Atom) -> Noun { + if lte_b(stack, a, b) { + YES } else { - a.as_ubig(stack) >= b.as_ubig(stack) + NO + } + } + + /// Less than (boolean) + pub fn lth_b(stack: &mut NockStack, a: Atom, b: Atom) -> bool { + if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) { + a.data() < b.data() + } else if a.bit_size() > b.bit_size() { + false + } else if a.bit_size() < b.bit_size() { + true + } else { + a.as_ubig(stack) < b.as_ubig(stack) + } + } + + /// Less than + pub fn lth(stack: &mut NockStack, a: Atom, b: Atom) -> Noun { + if lth_b(stack, a, b) { + YES + } else { + NO } } diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 2fc28d6..169b7c7 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,15 +1,13 @@ /** Parsing jets */ use crate::interpreter::Context; -use crate::jets::math::util::{gte, lte}; +use crate::jets::math::util::{gte_b, lte_b, lth}; use crate::jets::util::{kick, slam, slot}; use crate::jets::Result; use crate::mem::NockStack; use crate::noun::{Noun, D, T, YES}; use either::{Left, Right}; -use super::math::util::lth; - crate::gdb!(); // @@ -423,8 +421,8 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { let iq_tub_atom = iq_tub.as_atom()?; let hpn_hel_atom = hpn_hel.as_atom()?; let tpn_hel_atom = tpn_hel.as_atom()?; - bit = gte(&mut context.stack, iq_tub_atom, hpn_hel_atom) - && lte(&mut context.stack, iq_tub_atom, tpn_hel_atom); + bit = gte_b(&mut context.stack, iq_tub_atom, hpn_hel_atom) + && lte_b(&mut context.stack, iq_tub_atom, tpn_hel_atom); } } From d2a5c5aaeb1e7da92da96f352f2e845fc14e5ac7 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Tue, 19 Dec 2023 16:47:31 -0300 Subject: [PATCH 25/31] serf: remove debug eprintln --- rust/ares/src/serf.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 4c14824..f511d35 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -303,7 +303,6 @@ fn peek(context: &mut Context, ovo: Noun) -> Noun { } fn goof(context: &mut Context, traces: Noun) -> Noun { - // eprintln!("serf: goof: traces: {}", traces); let trace = zing(&mut context.nock_context.stack, traces).expect("serf: goof: zing failed"); let tone = Cell::new(&mut context.nock_context.stack, D(2), trace); let tang = mook(&mut context.nock_context, tone, false) From 485ee1085848543f21ffa78031abb78f96e08cb5 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Tue, 19 Dec 2023 16:49:33 -0300 Subject: [PATCH 26/31] jets: remove +zing debug code --- rust/ares/src/jets/list.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rust/ares/src/jets/list.rs b/rust/ares/src/jets/list.rs index 7985701..2a00279 100644 --- a/rust/ares/src/jets/list.rs +++ b/rust/ares/src/jets/list.rs @@ -73,15 +73,13 @@ pub mod util { let mut dest = &mut res as *mut Noun; while !list.raw_equals(D(0)) { - let pair = list.as_cell().expect("outer"); + let pair = list.as_cell()?; let mut sublist = pair.head(); list = pair.tail(); while !sublist.raw_equals(D(0)) { - if sublist.is_atom() { - panic!("zing: sublist is atom: {:?}", sublist); - }; - let it = sublist.as_cell().expect("inner"); + if sublist.is_atom()?; + let it = sublist.as_cell()?; let i = it.head(); sublist = it.tail(); From a30e020d178e72bc95209daf86dbd21a72c8d431 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Tue, 19 Dec 2023 16:50:16 -0300 Subject: [PATCH 27/31] jets: remove more +zing debug code --- rust/ares/src/jets/list.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/ares/src/jets/list.rs b/rust/ares/src/jets/list.rs index 2a00279..c281d35 100644 --- a/rust/ares/src/jets/list.rs +++ b/rust/ares/src/jets/list.rs @@ -78,7 +78,6 @@ pub mod util { list = pair.tail(); while !sublist.raw_equals(D(0)) { - if sublist.is_atom()?; let it = sublist.as_cell()?; let i = it.head(); sublist = it.tail(); From ef6045e249ade5e4b0ae9113f48150890e321ad3 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Wed, 20 Dec 2023 17:01:05 -0300 Subject: [PATCH 28/31] jets: keep jet order consistent with Arvo --- rust/ares/src/jets/hot.rs | 64 +++--- rust/ares/src/jets/parse.rs | 422 ++++++++++++++++++------------------ 2 files changed, 244 insertions(+), 242 deletions(-) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 1e43786..71ba179 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -303,20 +303,6 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_bend, ), // - ( - &[ - K_139, - Left(b"one"), - Left(b"two"), - Left(b"tri"), - Left(b"qua"), - Left(b"cold"), - Left(b"fun"), - ], - 1, - jet_cold, - ), - // ( &[ K_139, @@ -331,20 +317,6 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_comp, ), // - ( - &[ - K_139, - Left(b"one"), - Left(b"two"), - Left(b"tri"), - Left(b"qua"), - Left(b"cook"), - Left(b"fun"), - ], - 1, - jet_cook, - ), - // ( &[ K_139, @@ -411,6 +383,34 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_sfix, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"cold"), + Left(b"fun"), + ], + 1, + jet_cold, + ), + // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"cook"), + Left(b"fun"), + ], + 1, + jet_cook, + ), + // ( &[ K_139, @@ -502,11 +502,11 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ Left(b"two"), Left(b"tri"), Left(b"qua"), - Left(b"stir"), + Left(b"stew"), Left(b"fun"), ], 1, - jet_stir, + jet_stew, ), // ( @@ -516,11 +516,11 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ Left(b"two"), Left(b"tri"), Left(b"qua"), - Left(b"stew"), + Left(b"stir"), Left(b"fun"), ], 1, - jet_stew, + jet_stir, ), // ( diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 169b7c7..b936f8d 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,9 +1,9 @@ /** Parsing jets */ -use crate::interpreter::Context; +use crate::interpreter::{Context, Error}; use crate::jets::math::util::{gte_b, lte_b, lth}; use crate::jets::util::{kick, slam, slot}; -use crate::jets::Result; +use crate::jets::{JetErr, Result}; use crate::mem::NockStack; use crate::noun::{Noun, D, T, YES}; use either::{Left, Right}; @@ -69,26 +69,6 @@ pub fn jet_bend(context: &mut Context, subject: Noun) -> Result { } } -pub fn jet_cold(context: &mut Context, subject: Noun) -> Result { - let tub = slot(subject, 6)?; - let van = slot(subject, 7)?; - let cus = slot(van, 12)?; - let sef = slot(van, 13)?; - - let vex = slam(context, sef, tub)?.as_cell()?; - let p_vex = vex.head(); - let q_vex = vex.tail(); - - if unsafe { q_vex.raw_equals(D(0)) } { - Ok(vex.as_noun()) - } else { - let uq_vex = q_vex.as_cell()?.tail().as_cell()?; - let quq_vex = uq_vex.tail(); - - Ok(T(&mut context.stack, &[p_vex, D(0), cus, quq_vex])) - } -} - pub fn jet_comp(context: &mut Context, subject: Noun) -> Result { let sam = slot(subject, 6)?; let vex = slot(sam, 2)?.as_cell()?; @@ -126,28 +106,6 @@ pub fn jet_comp(context: &mut Context, subject: Noun) -> Result { } } -pub fn jet_cook(context: &mut Context, subject: Noun) -> Result { - let tub = slot(subject, 6)?; - let van = slot(subject, 7)?; - let poq = slot(van, 12)?; - let sef = slot(van, 13)?; - - let vex = slam(context, sef, tub)?.as_cell()?; - let p_vex = vex.head(); - let q_vex = vex.tail(); - - if unsafe { q_vex.raw_equals(D(0)) } { - Ok(vex.as_noun()) - } else { - let uq_vex = q_vex.as_cell()?.tail().as_cell()?; - let puq_vex = uq_vex.head(); - let quq_vex = uq_vex.tail(); - - let wag = slam(context, poq, puq_vex)?; - Ok(T(&mut context.stack, &[p_vex, D(0), wag, quq_vex])) - } -} - pub fn jet_glue(context: &mut Context, subject: Noun) -> Result { let sam = slot(subject, 6)?; let vex = slot(sam, 2)?.as_cell()?; @@ -223,14 +181,13 @@ pub fn jet_pfix(context: &mut Context, subject: Noun) -> Result { } pub fn jet_plug(context: &mut Context, subject: Noun) -> Result { - let vex = slot(subject, 12)?; + let vex = slot(subject, 12)?.as_cell()?; let sab = slot(subject, 13)?; - - let p_vex = vex.as_cell()?.head(); - let q_vex = vex.as_cell()?.tail(); + let p_vex = vex.head(); + let q_vex = vex.tail(); if unsafe { q_vex.raw_equals(D(0)) } { - Ok(vex) + Ok(vex.as_noun()) } else { let uq_vex = q_vex.as_cell()?.tail().as_cell()?; let puq_vex = uq_vex.head(); @@ -303,171 +260,53 @@ pub fn jet_sfix(context: &mut Context, subject: Noun) -> Result { } } -// +$ edge [p=hair q=(unit [p=* q=nail])] -#[derive(Copy, Clone)] -struct StirPair { - pub har: Noun, - pub res: Noun, -} - -pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { - unsafe { - context.with_stack_frame(0, |context| { - let mut tub = slot(subject, 6)?; - let van = slot(subject, 7)?; - let rud = slot(van, 12)?; - let raq = slot(van, 26)?; - let fel = slot(van, 27)?; - - // initial accumulator (deconstructed) - let mut p_wag: Noun; - let mut puq_wag: Noun; - let quq_wag: Noun; - - // push incremental, succesful [fel] parse results onto stack - { - let vex = slam(context, fel, tub)?.as_cell()?; - let mut p_vex = vex.head(); - let mut q_vex = vex.tail(); - while !q_vex.raw_equals(D(0)) { - let puq_vex = slot(q_vex, 6)?; - let quq_vex = slot(q_vex, 7)?; - - *(context.stack.push::()) = StirPair { - har: p_vex, - res: puq_vex, - }; - - tub = quq_vex; - - let vex = slam(context, fel, tub)?.as_cell()?; - p_vex = vex.head(); - q_vex = vex.tail(); - } - - p_wag = p_vex; - puq_wag = rud; - quq_wag = tub; - } - - // unwind the stack, folding parse results into [wag] by way of [raq] - while !context.stack.stack_is_empty() { - let par_u = *(context.stack.top::()); - p_wag = util::last(par_u.har, p_wag)?; - let sam = T(&mut context.stack, &[par_u.res, puq_wag]); - puq_wag = slam(context, raq, sam)?; - context.stack.pop::(); - } - - let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); - Ok(res) - }) - } -} - -fn stew_wor(stack: &mut NockStack, ort: Noun, wan: Noun) -> Result { - match ort.as_either_atom_cell() { - Left(ort_atom) => match wan.as_either_atom_cell() { - Left(wan_atom) => Ok(lth(stack, ort_atom, wan_atom)), - Right(wan_cell) => Ok(lth(stack, ort_atom, wan_cell.head().as_atom()?)), - }, - Right(ort_cell) => match wan.as_either_atom_cell() { - Left(wan_atom) => Ok(lth(stack, ort_cell.tail().as_atom()?, wan_atom)), - Right(wan_cell) => Ok(lth( - stack, - ort_cell.tail().as_atom()?, - wan_cell.head().as_atom()?, - )), - }, - } -} - -pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { - let tub = slot(subject, 6)?; - let con = slot(subject, 7)?; - let mut hel = slot(con, 2)?; - - let p_tub = tub.as_cell()?.head(); - let q_tub = tub.as_cell()?.tail(); - if unsafe { q_tub.raw_equals(D(0)) } { - return util::fail(context, p_tub); - } - - let iq_tub = q_tub.as_cell()?.head(); - if !iq_tub.as_atom()?.is_direct() { - return util::fail(context, p_tub); - } - - loop { - if unsafe { hel.raw_equals(D(0)) } { - return util::fail(context, p_tub); - } else { - let n_hel = slot(hel, 2)?; - let l_hel = slot(hel, 6)?; - let r_hel = slot(hel, 7)?; - let pn_hel = n_hel.as_cell()?.head(); - let qn_hel = n_hel.as_cell()?.tail(); - let bit; - - if !pn_hel.is_cell() { - bit = iq_tub.as_direct()?.data() == pn_hel.as_direct()?.data(); - } else { - let hpn_hel = pn_hel.as_cell()?.head(); - let tpn_hel = pn_hel.as_cell()?.tail(); - - if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { - return util::fail(context, p_tub); - } else { - let iq_tub_atom = iq_tub.as_atom()?; - let hpn_hel_atom = hpn_hel.as_atom()?; - let tpn_hel_atom = tpn_hel.as_atom()?; - bit = gte_b(&mut context.stack, iq_tub_atom, hpn_hel_atom) - && lte_b(&mut context.stack, iq_tub_atom, tpn_hel_atom); - } - } - - if bit { - return slam(context, qn_hel, tub); - } else if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { - hel = l_hel; - } else { - hel = r_hel; - } - } - } -} - -pub fn jet_shim(context: &mut Context, subject: Noun) -> Result { - let tub = slot(subject, 6)?; - let van = slot(subject, 7)?; - let zep = slot(van, 6)?; - - let p_tub = tub.as_cell()?.head(); - let q_tub = tub.as_cell()?.tail(); - - if unsafe { q_tub.raw_equals(D(0)) } { - util::fail(context, p_tub) - } else { - let p_zep = zep.as_cell()?.head(); - let q_zep = zep.as_cell()?.tail(); - let iq_tub = q_tub.as_cell()?.head(); - - let p_zep_dat = p_zep.as_direct()?.data(); - let q_zep_dat = q_zep.as_direct()?.data(); - let iq_tub_dat = iq_tub.as_direct()?.data(); - - if (iq_tub_dat >= p_zep_dat) && (iq_tub_dat <= q_zep_dat) { - util::next(context, tub) - } else { - util::fail(context, p_tub) - } - } -} - // // Rule Builders // + +pub fn jet_cold(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let cus = slot(van, 12)?; + let sef = slot(van, 13)?; + + let vex = slam(context, sef, tub)?.as_cell()?; + let p_vex = vex.head(); + let q_vex = vex.tail(); + + if unsafe { q_vex.raw_equals(D(0)) } { + Ok(vex.as_noun()) + } else { + let quq_vex = q_vex.as_cell()?.tail().as_cell()?.tail(); + + Ok(T(&mut context.stack, &[p_vex, D(0), cus, quq_vex])) + } +} + +pub fn jet_cook(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let poq = slot(van, 12)?; + let sef = slot(van, 13)?; + + let vex = slam(context, sef, tub)?.as_cell()?; + let p_vex = vex.head(); + let q_vex = vex.tail(); + + if unsafe { q_vex.raw_equals(D(0)) } { + Ok(vex.as_noun()) + } else { + let uq_vex = q_vex.as_cell()?.tail().as_cell()?; + let puq_vex = uq_vex.head(); + let quq_vex = uq_vex.tail(); + + let wag = slam(context, poq, puq_vex)?; + Ok(T(&mut context.stack, &[p_vex, D(0), wag, quq_vex])) + } +} + + pub fn jet_easy(context: &mut Context, subject: Noun) -> Result { let tub = slot(subject, 6)?; let van = slot(subject, 7)?; @@ -546,6 +385,35 @@ pub fn jet_mask(context: &mut Context, subject: Noun) -> Result { util::fail(context, p_tub) } +pub fn jet_shim(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?.as_cell()?; + let van = slot(subject, 7)?; + let zep = slot(van, 6)?.as_cell()?; + + let p_tub = tub.head(); + let q_tub = tub.tail(); + + if unsafe { q_tub.raw_equals(D(0)) } { + util::fail(context, p_tub) + } else { + let p_zep = zep.head(); + let q_zep = zep.tail(); + let iq_tub = q_tub.as_cell()?.head(); + + if let (Some(p_zep_d), Some(q_zep_d), Some(iq_tub_d)) = + (p_zep.direct(), q_zep.direct(), iq_tub.direct()) + { + if (iq_tub_d.data() >= p_zep_d.data()) && (iq_tub_d.data() <= q_zep_d.data()) { + util::next(context, tub.as_noun()) + } else { + util::fail(context, p_tub) + } + } else { + Err(JetErr::Fail(Error::NonDeterministic(D(0)))) + } + } +} + pub fn jet_stag(context: &mut Context, subject: Noun) -> Result { let tub = slot(subject, 6)?; let van = slot(subject, 7)?; @@ -568,6 +436,140 @@ pub fn jet_stag(context: &mut Context, subject: Noun) -> Result { } } +fn stew_wor(stack: &mut NockStack, ort: Noun, wan: Noun) -> Result { + match ort.as_either_atom_cell() { + Left(ort_atom) => match wan.as_either_atom_cell() { + Left(wan_atom) => Ok(lth(stack, ort_atom, wan_atom)), + Right(wan_cell) => Ok(lth(stack, ort_atom, wan_cell.head().as_atom()?)), + }, + Right(ort_cell) => match wan.as_either_atom_cell() { + Left(wan_atom) => Ok(lth(stack, ort_cell.tail().as_atom()?, wan_atom)), + Right(wan_cell) => Ok(lth( + stack, + ort_cell.tail().as_atom()?, + wan_cell.head().as_atom()?, + )), + }, + } +} + +pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { + let tub = slot(subject, 6)?; + let con = slot(subject, 7)?; + let mut hel = slot(con, 2)?; + + let p_tub = tub.as_cell()?.head(); + let q_tub = tub.as_cell()?.tail(); + if unsafe { q_tub.raw_equals(D(0)) } { + return util::fail(context, p_tub); + } + + let iq_tub = q_tub.as_cell()?.head(); + if !iq_tub.as_atom()?.is_direct() { + return util::fail(context, p_tub); + } + + loop { + if unsafe { hel.raw_equals(D(0)) } { + return util::fail(context, p_tub); + } else { + let n_hel = slot(hel, 2)?; + let l_hel = slot(hel, 6)?; + let r_hel = slot(hel, 7)?; + let pn_hel = n_hel.as_cell()?.head(); + let qn_hel = n_hel.as_cell()?.tail(); + let bit; + + if !pn_hel.is_cell() { + bit = iq_tub.as_direct()?.data() == pn_hel.as_direct()?.data(); + } else { + let hpn_hel = pn_hel.as_cell()?.head(); + let tpn_hel = pn_hel.as_cell()?.tail(); + + if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { + return util::fail(context, p_tub); + } else { + let iq_tub_atom = iq_tub.as_atom()?; + let hpn_hel_atom = hpn_hel.as_atom()?; + let tpn_hel_atom = tpn_hel.as_atom()?; + bit = gte_b(&mut context.stack, iq_tub_atom, hpn_hel_atom) + && lte_b(&mut context.stack, iq_tub_atom, tpn_hel_atom); + } + } + + if bit { + return slam(context, qn_hel, tub); + } else if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { + hel = l_hel; + } else { + hel = r_hel; + } + } + } +} + +// +$ edge [p=hair q=(unit [p=* q=nail])] +#[derive(Copy, Clone)] +struct StirPair { + pub har: Noun, + pub res: Noun, +} + +pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { + unsafe { + context.with_stack_frame(0, |context| { + let mut tub = slot(subject, 6)?; + let van = slot(subject, 7)?; + let rud = slot(van, 12)?; + let raq = slot(van, 26)?; + let fel = slot(van, 27)?; + + // initial accumulator (deconstructed) + let mut p_wag: Noun; + let mut puq_wag: Noun; + let quq_wag: Noun; + + // push incremental, succesful [fel] parse results onto stack + { + let vex = slam(context, fel, tub)?.as_cell()?; + let mut p_vex = vex.head(); + let mut q_vex = vex.tail(); + while !q_vex.raw_equals(D(0)) { + let puq_vex = slot(q_vex, 6)?; + let quq_vex = slot(q_vex, 7)?; + + *(context.stack.push::()) = StirPair { + har: p_vex, + res: puq_vex, + }; + + tub = quq_vex; + + let vex = slam(context, fel, tub)?.as_cell()?; + p_vex = vex.head(); + q_vex = vex.tail(); + } + + p_wag = p_vex; + puq_wag = rud; + quq_wag = tub; + } + + // unwind the stack, folding parse results into [wag] by way of [raq] + while !context.stack.stack_is_empty() { + let par_u = *(context.stack.top::()); + p_wag = util::last(par_u.har, p_wag)?; + let sam = T(&mut context.stack, &[par_u.res, puq_wag]); + puq_wag = slam(context, raq, sam)?; + context.stack.pop::(); + } + + let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]); + Ok(res) + }) + } +} + pub mod util { use crate::interpreter::{inc, Context}; use crate::jets::Result; From 9a00b9a798a094bb50d57f89394d6307747f697f Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Wed, 20 Dec 2023 18:46:36 -0300 Subject: [PATCH 29/31] jets: +stew changes --- rust/ares/src/jets/parse.rs | 96 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index b936f8d..b7330ff 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,11 +1,10 @@ /** Parsing jets */ use crate::interpreter::{Context, Error}; -use crate::jets::math::util::{gte_b, lte_b, lth}; +use crate::jets::math::util::{gte_b, lte_b, lth_b}; use crate::jets::util::{kick, slam, slot}; use crate::jets::{JetErr, Result}; -use crate::mem::NockStack; -use crate::noun::{Noun, D, T, YES}; +use crate::noun::{Noun, D, T}; use either::{Left, Right}; crate::gdb!(); @@ -264,7 +263,6 @@ pub fn jet_sfix(context: &mut Context, subject: Noun) -> Result { // Rule Builders // - pub fn jet_cold(context: &mut Context, subject: Noun) -> Result { let tub = slot(subject, 6)?; let van = slot(subject, 7)?; @@ -306,7 +304,6 @@ pub fn jet_cook(context: &mut Context, subject: Noun) -> Result { } } - pub fn jet_easy(context: &mut Context, subject: Noun) -> Result { let tub = slot(subject, 6)?; let van = slot(subject, 7)?; @@ -436,73 +433,72 @@ pub fn jet_stag(context: &mut Context, subject: Noun) -> Result { } } -fn stew_wor(stack: &mut NockStack, ort: Noun, wan: Noun) -> Result { - match ort.as_either_atom_cell() { - Left(ort_atom) => match wan.as_either_atom_cell() { - Left(wan_atom) => Ok(lth(stack, ort_atom, wan_atom)), - Right(wan_cell) => Ok(lth(stack, ort_atom, wan_cell.head().as_atom()?)), - }, - Right(ort_cell) => match wan.as_either_atom_cell() { - Left(wan_atom) => Ok(lth(stack, ort_cell.tail().as_atom()?, wan_atom)), - Right(wan_cell) => Ok(lth( - stack, - ort_cell.tail().as_atom()?, - wan_cell.head().as_atom()?, - )), - }, - } -} - pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { - let tub = slot(subject, 6)?; + let tub = slot(subject, 6)?.as_cell()?; let con = slot(subject, 7)?; let mut hel = slot(con, 2)?; - let p_tub = tub.as_cell()?.head(); - let q_tub = tub.as_cell()?.tail(); + let p_tub = tub.head(); + let q_tub = tub.tail(); if unsafe { q_tub.raw_equals(D(0)) } { return util::fail(context, p_tub); } - let iq_tub = q_tub.as_cell()?.head(); - if !iq_tub.as_atom()?.is_direct() { - return util::fail(context, p_tub); + let iq_tub = q_tub.as_cell()?.head().as_atom()?; + if !iq_tub.is_direct() { + // Character cannot be encoded using 8 bytes = computibilty error + return Err(JetErr::Fail(Error::NonDeterministic(D(0)))); } loop { if unsafe { hel.raw_equals(D(0)) } { return util::fail(context, p_tub); } else { - let n_hel = slot(hel, 2)?; + let n_hel = slot(hel, 2)?.as_cell()?; let l_hel = slot(hel, 6)?; let r_hel = slot(hel, 7)?; - let pn_hel = n_hel.as_cell()?.head(); - let qn_hel = n_hel.as_cell()?.tail(); - let bit; + let pn_hel = n_hel.head(); + let qn_hel = n_hel.tail(); - if !pn_hel.is_cell() { - bit = iq_tub.as_direct()?.data() == pn_hel.as_direct()?.data(); - } else { - let hpn_hel = pn_hel.as_cell()?.head(); - let tpn_hel = pn_hel.as_cell()?.tail(); + let bit = match pn_hel.as_either_atom_cell() { + Left(atom) => match atom.as_either() { + Left(direct) => iq_tub.as_direct()?.data() == direct.data(), + Right(_) => { + // Character cannot be encoded using 8 bytes = computibilty error + return Err(JetErr::Fail(Error::NonDeterministic(D(0)))); + } + }, + Right(cell) => { + let hpn_hel = cell.head().as_atom()?; + let tpn_hel = cell.tail().as_atom()?; - if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() { - return util::fail(context, p_tub); - } else { - let iq_tub_atom = iq_tub.as_atom()?; - let hpn_hel_atom = hpn_hel.as_atom()?; - let tpn_hel_atom = tpn_hel.as_atom()?; - bit = gte_b(&mut context.stack, iq_tub_atom, hpn_hel_atom) - && lte_b(&mut context.stack, iq_tub_atom, tpn_hel_atom); + match (hpn_hel.as_either(), tpn_hel.as_either()) { + (Left(_), Left(_)) => { + gte_b(&mut context.stack, iq_tub, hpn_hel) + && lte_b(&mut context.stack, iq_tub, tpn_hel) + } + _ => { + // XX: Fixes jet mismatch in Vere + // Character cannot be encoded using 8 bytes = computibilty error + return Err(JetErr::Fail(Error::NonDeterministic(D(0)))); + } + } } - } + }; if bit { - return slam(context, qn_hel, tub); - } else if unsafe { stew_wor(&mut context.stack, iq_tub, pn_hel)?.raw_equals(YES) } { - hel = l_hel; + return slam(context, qn_hel, tub.as_noun()); } else { - hel = r_hel; + let wor = match pn_hel.as_either_atom_cell() { + Left(atom) => atom, + Right(cell) => cell.head().as_atom()?, + }; + + if lth_b(&mut context.stack, iq_tub, wor) { + hel = l_hel; + } else { + hel = r_hel; + } } } } From 084167defec22681b36350bdfef82ede932e9cdb Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Wed, 20 Dec 2023 19:01:47 -0300 Subject: [PATCH 30/31] jets: add comments for StirPair --- rust/ares/src/jets/parse.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index b7330ff..cece8c2 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -507,8 +507,8 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { // +$ edge [p=hair q=(unit [p=* q=nail])] #[derive(Copy, Clone)] struct StirPair { - pub har: Noun, - pub res: Noun, + pub har: Noun, // p.edge + pub res: Noun, // p.u.q.edge } pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { From 976e4dfbbcff123a1f5775da91e5e3a7dfdf5513 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Wed, 20 Dec 2023 19:05:41 -0300 Subject: [PATCH 31/31] jets: lint --- rust/ares/src/jets/parse.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index cece8c2..a5a8da4 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -507,8 +507,8 @@ pub fn jet_stew(context: &mut Context, subject: Noun) -> Result { // +$ edge [p=hair q=(unit [p=* q=nail])] #[derive(Copy, Clone)] struct StirPair { - pub har: Noun, // p.edge - pub res: Noun, // p.u.q.edge + pub har: Noun, // p.edge + pub res: Noun, // p.u.q.edge } pub fn jet_stir(context: &mut Context, subject: Noun) -> Result {