on master help sign in
nock/src/jets.rs+66−1
since splitsnapshots
unifiedsplit
@@ -10,7 +10,7 @@ use std::{
10
10
11use crate::{
11use crate::{
12 interpreter::{slam_pulled_gate, InterpreterContext, TTanks, EMPTY_TANKS},
12 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},
14};
14};
15
15
16fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
16fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
@@ -112,6 +112,7 @@ pub fn generate_jets() -> Jets {
112 (299422828284010240628877806738195667652, DOR),
112 (299422828284010240628877806738195667652, DOR),
113 (166326796552601297695313176538120818632, GOR),
113 (166326796552601297695313176538120818632, GOR),
114 (7942398240152905363972500667649380756, MOR),
114 (7942398240152905363972500667649380756, MOR),
115+ (315687984998079865981003916817293521765, LOOK),
115 ])
116 ])
116}
117}
117
118
@@ -1095,6 +1096,18 @@ static GOR: Jet = |ctx, n| {
1095 }
1096 }
1096};
1097};
1097
1098
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+
1098static MOR: Jet = |ctx, n| {
1111static MOR: Jet = |ctx, n| {
1099 let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1112 let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1100 let c = Noun::from_u32(a.mug()).mug();
1113 let c = Noun::from_u32(a.mug()).mug();
@@ -1111,6 +1124,58 @@ static MOR: Jet = |ctx, n| {
1111 }
1124 }
1112};
1125};
1113
1126
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+
1114static JUST: DoubleJet = |ctx, n, m| {
1179static JUST: DoubleJet = |ctx, n, m| {
1115 let char = n.as_atom()?;
1180 let char = n.as_atom()?;
1116 let nail = m.as_nail()?;
1181 let nail = m.as_nail()?;
nock/src/noun.rs+6
@@ -305,6 +305,12 @@ pub trait AsNoun {
305 fn as_noun(self: &Self) -> Rc<Noun>;
305 fn as_noun(self: &Self) -> Rc<Noun>;
306}
306}
307
307
308+impl AsNoun for Atom {
309+ fn as_noun(self: &Self) -> Rc<Noun> {
310+ Rc::new(Noun::Atom(self.clone()))
311+ }
312+}
313+
308impl AsNoun for Noun {
314impl AsNoun for Noun {
309 fn as_noun(self: &Self) -> Rc<Noun> {
315 fn as_noun(self: &Self) -> Rc<Noun> {
310 Rc::new(self.clone())
316 Rc::new(self.clone())