on master help sign in
Added look jet
commit9e1204fc4856703e88b682eb35c4f9d1f8aaee81 authoriko <mail@iko.soy> dateSat 16 Nov 2024, 18:41 (2 years ago) parent3d2d317
2 files changed+72−1
unifiedsplit
nock/src/jets.rs+66−1 nock/src/noun.rs+6
nock/src/jets.rs+66−1
@@ -10,7 +10,7 @@ use std::{
1010
1111use crate::{
1212 interpreter::{slam_pulled_gate, InterpreterContext, TTanks, EMPTY_TANKS},
13− noun::{self, cell, Atom, Edge, Hair, Nail, Noun},
13+ noun::{self, cell, AsNoun, Atom, Edge, Hair, Nail, Noun},
1414};
1515
1616fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
@@ -112,6 +112,7 @@ pub fn generate_jets() -> Jets {
112112 (299422828284010240628877806738195667652, DOR),
113113 (166326796552601297695313176538120818632, GOR),
114114 (7942398240152905363972500667649380756, MOR),
115+ (315687984998079865981003916817293521765, LOOK),
115116 ])
116117}
117118
@@ -1095,6 +1096,18 @@ static GOR: Jet = |ctx, n| {
10951096 }
10961097};
10971098
1099+static GOR_PAIR: fn(&mut InterpreterContext, &Rc<Noun>, &Rc<Noun>) -> Result<bool, TTanks> =
1100+ |ctx, a, b| {
1101+ let c = a.mug();
1102+ let d = b.mug();
1103+
1104+ if c == d {
1105+ Ok(DOR(ctx, &(a.clone(), b.clone()).as_noun())? == ctx.nouns.y)
1106+ } else {
1107+ Ok(c < d)
1108+ }
1109+ };
1110+
10981111static MOR: Jet = |ctx, n| {
10991112 let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
11001113 let c = Noun::from_u32(a.mug()).mug();
@@ -1111,6 +1124,58 @@ static MOR: Jet = |ctx, n| {
11111124 }
11121125};
11131126
1127+static LOOK: Jet = |ctx, n| {
1128+ let (cog, dab) = n.as_cell().ok_or(EMPTY_TANKS)?;
1129+ LOOK_PAIR(ctx, Atom::new(vec![1]), cog, dab)
1130+};
1131+
1132+static LOOK_PAIR: fn(
1133+ &mut InterpreterContext,
1134+ Atom,
1135+ &Rc<Noun>,
1136+ &Rc<Noun>,
1137+) -> Result<Rc<Noun>, TTanks> = |ctx, axe, cog, dab| {
1138+ if dab.is_sig() {
1139+ Ok(ctx.nouns.sig.clone())
1140+ } else {
1141+ let (node, b, c) = dab.tuple_3().ok_or(EMPTY_TANKS)?;
1142+ let l = b;
1143+ let r = c;
1144+ let (p, q) = node.as_cell().ok_or(EMPTY_TANKS)?;
1145+ if b.is_sig() && c.is_sig() {
1146+ if cog == p {
1147+ Ok((ctx.nouns.sig.clone(), Noun::Atom(axe), q.clone()).as_noun())
1148+ } else {
1149+ Ok(ctx.nouns.sig.clone())
1150+ }
1151+ } else if b.is_sig() {
1152+ if cog == p {
1153+ Ok((ctx.nouns.sig.clone(), PEG_U32(&axe, 2), q.clone()).as_noun())
1154+ } else if GOR_PAIR(ctx, cog, p)? {
1155+ Ok(ctx.nouns.sig.clone())
1156+ } else {
1157+ LOOK_PAIR(ctx, PEG_U32(&axe, 3), cog, r)
1158+ }
1159+ } else if c.is_sig() {
1160+ if cog == p {
1161+ Ok((ctx.nouns.sig.clone(), PEG_U32(&axe, 2), q.clone()).as_noun())
1162+ } else if GOR_PAIR(ctx, cog, p)? {
1163+ LOOK_PAIR(ctx, PEG_U32(&axe, 3), cog, l)
1164+ } else {
1165+ Ok(ctx.nouns.sig.clone())
1166+ }
1167+ } else {
1168+ if cog == p {
1169+ Ok((ctx.nouns.sig.clone(), PEG_U32(&axe, 2), q.clone()).as_noun())
1170+ } else if GOR_PAIR(ctx, cog, p)? {
1171+ LOOK_PAIR(ctx, PEG_U32(&axe, 6), cog, l)
1172+ } else {
1173+ LOOK_PAIR(ctx, PEG_U32(&axe, 7), cog, r)
1174+ }
1175+ }
1176+ }
1177+};
1178+
11141179static JUST: DoubleJet = |ctx, n, m| {
11151180 let char = n.as_atom()?;
11161181 let nail = m.as_nail()?;
nock/src/noun.rs+6
@@ -305,6 +305,12 @@ pub trait AsNoun {
305305 fn as_noun(self: &Self) -> Rc<Noun>;
306306}
307307
308+impl AsNoun for Atom {
309+ fn as_noun(self: &Self) -> Rc<Noun> {
310+ Rc::new(Noun::Atom(self.clone()))
311+ }
312+}
313+
308314impl AsNoun for Noun {
309315 fn as_noun(self: &Self) -> Rc<Noun> {
310316 Rc::new(self.clone())