@@ -2,15 +2,14 @@ use core::panic;
22use murmur3::murmur3_32;
33use num_integer::Integer;
44use std::{
5− borrow::Borrow,
65 collections::BTreeMap,
76 iter::{once, repeat_n, zip},
87 rc::Rc,
98};
109
1110use crate::{
12− interpreter::{slam_pulled_gate, InterpreterContext, TTanks, EMPTY_TANKS},
13− noun::{self, cell, AsNoun, Atom, Edge, Hair, Nail, Noun},
11+ interpreter::{slam_pulled_gate, InterpreterContext, Tanks},
12+ noun::{self, cell, Atom, Edge, Hair, Nail, Noun},
1413};
1514
1615fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
@@ -108,23 +107,18 @@ pub fn generate_jets() -> Jets {
108107 (124976064672625230427889101290245200507, TRIP),
109108 (4078279288073906183633157465551067635, MUK),
110109 (261900159748071234702685239353558471892, MUG),
111− (198191257620924788695943358402651905954, AOR),
112− (299422828284010240628877806738195667652, DOR),
113− (166326796552601297695313176538120818632, GOR),
114− (7942398240152905363972500667649380756, MOR),
115− (315687984998079865981003916817293521765, LOOK),
116110 ])
117111}
118112
119−pub type Jet = fn(ctx: &mut InterpreterContext, &Rc<Noun>) -> Result<Rc<Noun>, TTanks>;
113+pub type Jet = fn(ctx: &mut InterpreterContext, &Rc<Noun>) -> Result<Rc<Noun>, Tanks>;
120114pub type DoubleJet = fn(ctx: &mut InterpreterContext, &Rc<Noun>, &Rc<Noun>) -> Option<Rc<Noun>>;
121115
122−static BINARY_ATOM: fn(&Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Result<Rc<Noun>, TTanks> =
116+static BINARY_ATOM: fn(&Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Result<Rc<Noun>, Tanks> =
123117 |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
124− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
118+ let (p, q) = n.as_cell().ok_or(Tanks::new())?;
125119 Ok(Rc::new(Noun::Atom(f(
126− p.as_atom().ok_or(TTanks::new())?,
127− q.as_atom().ok_or(TTanks::new())?,
120+ p.as_atom().ok_or(Tanks::new())?,
121+ q.as_atom().ok_or(Tanks::new())?,
128122 ))))
129123 };
130124
@@ -132,13 +126,13 @@ static BINARY_ATOM_LOOB: fn(
132126 &InterpreterContext,
133127 &Rc<Noun>,
134128 fn(&Atom, &Atom) -> bool,
135−) -> Result<Rc<Noun>, TTanks> =
129+) -> Result<Rc<Noun>, Tanks> =
136130 |ctx: &InterpreterContext, n: &Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
137− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
131+ let (p, q) = n.as_cell().ok_or(Tanks::new())?;
138132
139133 if f(
140− p.as_atom().ok_or(TTanks::new())?,
141− q.as_atom().ok_or(TTanks::new())?,
134+ p.as_atom().ok_or(Tanks::new())?,
135+ q.as_atom().ok_or(Tanks::new())?,
142136 ) {
143137 Ok(ctx.nouns.sig.clone())
144138 } else {
@@ -149,22 +143,18 @@ static BINARY_ATOM_LOOB: fn(
149143static BINARY_ATOM_PAIR: fn(
150144 &Rc<Noun>,
151145 fn(&Atom, &Atom) -> (Atom, Atom),
152−) -> Result<Rc<Noun>, TTanks> = |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
153− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
146+) -> Result<Rc<Noun>, Tanks> = |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
147+ let (p, q) = n.as_cell().ok_or(Tanks::new())?;
154148
155149 let (a, b) = f(
156− p.as_atom().ok_or(TTanks::new())?,
157− q.as_atom().ok_or(TTanks::new())?,
150+ p.as_atom().ok_or(Tanks::new())?,
151+ q.as_atom().ok_or(Tanks::new())?,
158152 );
159153 Ok(cell(&Rc::new(Noun::Atom(a)), &Rc::new(Noun::Atom(b))))
160154};
161155
162156static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
163−static DEC: Jet = |_ctx, n| {
164− Ok(Rc::new(Noun::Atom(
165− n.as_atom().ok_or(TTanks::new())? - 1u32,
166− )))
167−};
157+static DEC: Jet = |_ctx, n| Ok(Rc::new(Noun::Atom(n.as_atom().ok_or(Tanks::new())? - 1u32)));
168158static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
169159static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
170160static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -178,30 +168,30 @@ static MUL: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a * b);
178168static SUB: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a - b);
179169
180170static CAP: Jet = |ctx, n| {
181− let n = n.as_atom().ok_or(TTanks::new())?;
171+ let n = n.as_atom().ok_or(Tanks::new())?;
182172 CAP_ATOM(ctx, n.clone())
183173};
184174
185−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, TTanks> = |ctx, n: Atom| {
175+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, Tanks> = |ctx, n: Atom| {
186176 let mut n_iter = n.iter_u32_digits();
187177
188178 match n_iter.len() {
189− 0 => Err(TTanks::new()),
179+ 0 => Err(Tanks::new()),
190180 1 => CAP_U32(ctx, n_iter.next().unwrap()),
191181 _ => CAP_ATOM(ctx, n >> 1),
192182 }
193183};
194−static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Result<Rc<Noun>, TTanks> = |ctx, n| match n {
195− 0 | 1 => Err(TTanks::new()),
184+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Result<Rc<Noun>, Tanks> = |ctx, n| match n {
185+ 0 | 1 => Err(Tanks::new()),
196186 2 => Ok(ctx.nouns.two.clone()),
197187 3 => Ok(ctx.nouns.three.clone()),
198188 n => CAP_U32(ctx, n >> 1),
199189};
200190
201191static MAS: Jet = |ctx, n| {
202− let n = n.as_atom().ok_or(TTanks::new())?;
192+ let n = n.as_atom().ok_or(Tanks::new())?;
203193 Ok(Rc::new(Noun::Atom(
204− MAS_ATOM(ctx, n.clone()).ok_or(TTanks::new())?,
194+ MAS_ATOM(ctx, n.clone()).ok_or(Tanks::new())?,
205195 )))
206196};
207197static MAS_ATOM: fn(&InterpreterContext, Atom) -> Option<Atom> = |ctx, n| {
@@ -223,22 +213,22 @@ static MAS_U32: fn(u32) -> u32 = |n| match n {
223213};
224214
225215static PEG: Jet = |ctx, n| {
226− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
216+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
227217
228− let a = a.as_atom().ok_or(TTanks::new())?;
229− let b = b.as_atom().ok_or(TTanks::new())?;
218+ let a = a.as_atom().ok_or(Tanks::new())?;
219+ let b = b.as_atom().ok_or(Tanks::new())?;
230220
231221 if *a == Atom::ZERO {
232− return Err(TTanks::new());
222+ return Err(Tanks::new());
233223 };
234224
235225 Ok(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())?)))
236226};
237−static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, TTanks> = |ctx, a, b| {
227+static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, Tanks> = |ctx, a, b| {
238228 let mut b_iter = b.iter_u32_digits();
239229
240230 match b_iter.len() {
241− 0 => Err(TTanks::new()),
231+ 0 => Err(Tanks::new()),
242232 1 => Ok(PEG_U32(a, b_iter.next().unwrap())),
243233 _ => Ok((&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1)? << 1)),
244234 }
@@ -252,7 +242,7 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
252242};
253243
254244static FAND: Jet = |ctx, n| {
255− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
245+ let (nedl, hstk) = n.as_cell().ok_or(Tanks::new())?;
256246 if nedl.is_sig() || hstk.is_sig() {
257247 return Ok(ctx.nouns.sig.clone());
258248 }
@@ -282,7 +272,7 @@ static FAND: Jet = |ctx, n| {
282272};
283273
284274static FIND: Jet = |ctx, n| {
285− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
275+ let (nedl, hstk) = n.as_cell().ok_or(Tanks::new())?;
286276 if nedl.is_sig() || hstk.is_sig() {
287277 return Ok(ctx.nouns.sig.clone());
288278 }
@@ -315,13 +305,13 @@ static FLOP: Jet = |ctx, n| {
315305};
316306
317307static GULF: Jet = |_ctx, n| {
318− let (from, to) = n.as_cell().ok_or(TTanks::new())?;
308+ let (from, to) = n.as_cell().ok_or(Tanks::new())?;
319309
320− let mut from = (*from.as_atom().ok_or(TTanks::new())?).clone();
321− let to = to.as_atom().ok_or(TTanks::new())?.clone();
310+ let mut from = (*from.as_atom().ok_or(Tanks::new())?).clone();
311+ let to = to.as_atom().ok_or(Tanks::new())?.clone();
322312
323313 if from > to {
324− return Err(TTanks::new());
314+ return Err(Tanks::new());
325315 }
326316
327317 let mut tmp = Vec::new();
@@ -335,10 +325,10 @@ static GULF: Jet = |_ctx, n| {
335325};
336326
337327static INTO: Jet = |_ctx, n| {
338− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
339− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
328+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
329+ let (b, c) = b.as_cell().ok_or(Tanks::new())?;
340330
341− let mut b_iter = b.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
331+ let mut b_iter = b.as_atom().ok_or(Tanks::new())?.iter_u32_digits();
342332
343333 match b_iter.len() {
344334 0 => Ok(cell(&c, &a)),
@@ -368,7 +358,7 @@ static INTO: Jet = |_ctx, n| {
368358};
369359
370360static JOIN: Jet = |_ctx, n| {
371− let (sep, list) = n.as_cell().ok_or(TTanks::new())?;
361+ let (sep, list) = n.as_cell().ok_or(Tanks::new())?;
372362 Ok(Noun::list_refs(
373363 list.list_iter()
374364 .intersperse(sep)
@@ -386,7 +376,7 @@ static LENT: Jet = |_ctx, n| {
386376};
387377
388378static LEVY: Jet = |ctx, n| {
389− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
379+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
390380 if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
391381 .iter()
392382 .all(|x| x.is_y())
@@ -398,7 +388,7 @@ static LEVY: Jet = |ctx, n| {
398388};
399389
400390static LIEN: Jet = |ctx, n| {
401− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
391+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
402392 if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
403393 .iter()
404394 .any(|x| x.is_y())
@@ -410,7 +400,7 @@ static LIEN: Jet = |ctx, n| {
410400};
411401
412402static MURN: Jet = |ctx, n| {
413− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
403+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
414404
415405 Ok(Noun::list_refs(
416406 traverse_iter_result(
@@ -423,7 +413,7 @@ static MURN: Jet = |ctx, n| {
423413};
424414
425415static REAP: Jet = |_ctx, n| {
426− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
416+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
427417
428418 Ok(Noun::list_refs(repeat_n(
429419 b.clone(),
@@ -431,17 +421,17 @@ static REAP: Jet = |_ctx, n| {
431421 )))
432422};
433423
434−static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(TTanks::new()).cloned();
424+static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(Tanks::new()).cloned();
435425
436426static REEL: Jet = |ctx, n| {
437− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
427+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
438428
439429 list.list_iter().collect::<Vec<_>>().iter().rfold(
440430 Ok(gate
441431 .gate_sample()
442− .ok_or(TTanks::new())?
432+ .ok_or(Tanks::new())?
443433 .as_cell()
444− .ok_or(TTanks::new())?
434+ .ok_or(Tanks::new())?
445435 .1
446436 .clone()),
447437 |acc, next| {
@@ -452,15 +442,15 @@ static REEL: Jet = |ctx, n| {
452442};
453443
454444static ROLL: Jet = |ctx, n| {
455− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
445+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
456446
457447 list.list_iter().fold(
458448 Ok(gate
459449 .clone()
460450 .gate_sample()
461− .ok_or(TTanks::new())?
451+ .ok_or(Tanks::new())?
462452 .as_cell()
463− .ok_or(TTanks::new())?
453+ .ok_or(Tanks::new())?
464454 .1
465455 .clone()),
466456 |acc, next| {
@@ -471,7 +461,7 @@ static ROLL: Jet = |ctx, n| {
471461};
472462
473463static SCAG: Jet = |_ctx, n| {
474− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
464+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
475465
476466 Ok(Noun::list_refs(
477467 b.list_iter()
@@ -484,7 +474,7 @@ static SCAG: Jet = |_ctx, n| {
484474};
485475
486476static SKID: Jet = |ctx, n| {
487− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
477+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
488478
489479 let slammed_n = traverse_iter_result(
490480 list.list_iter()
@@ -499,7 +489,7 @@ static SKID: Jet = |ctx, n| {
499489};
500490
501491static SKIM: Jet = |ctx, n| {
502− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
492+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
503493
504494 Ok(Noun::list_refs(
505495 traverse_iter_result(
@@ -513,7 +503,7 @@ static SKIM: Jet = |ctx, n| {
513503};
514504
515505static SKIP: Jet = |ctx, n| {
516− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
506+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
517507
518508 Ok(Noun::list_refs(
519509 traverse_iter_result(
@@ -527,9 +517,9 @@ static SKIP: Jet = |ctx, n| {
527517};
528518
529519static SLAG: Jet = |ctx, n| {
530− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
520+ let (a, list) = n.as_cell().ok_or(Tanks::new())?;
531521
532− let mut a_iter = a.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
522+ let mut a_iter = a.as_atom().ok_or(Tanks::new())?.iter_u32_digits();
533523
534524 match a_iter.len() {
535525 0 => Ok(list.clone()),
@@ -546,12 +536,12 @@ static SLAG: Jet = |ctx, n| {
546536};
547537
548538static SNAG: Jet = |_ctx, n| {
549− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
539+ let (a, list) = n.as_cell().ok_or(Tanks::new())?;
550540
551541 list.list_iter()
552542 .nth(a.as_u32().unwrap() as usize)
553543 .cloned()
554− .ok_or(TTanks::new())
544+ .ok_or(Tanks::new())
555545};
556546
557547static SNIP: Jet = |_ctx, n| {
@@ -568,7 +558,7 @@ static SNIP: Jet = |_ctx, n| {
568558};
569559
570560static SNOC: Jet = |_ctx, n| {
571− let (list, b) = n.as_cell().ok_or(TTanks::new())?;
561+ let (list, b) = n.as_cell().ok_or(Tanks::new())?;
572562
573563 Ok(Noun::list_refs(
574564 list.list_iter()
@@ -599,15 +589,15 @@ static SNOC: Jet = |_ctx, n| {
599589// };
600590
601591static SPIN: Jet = |ctx, n| {
602− let (list, b) = n.as_cell().ok_or(TTanks::new())?;
603− let (acc, gate) = b.as_cell().ok_or(TTanks::new())?;
592+ let (list, b) = n.as_cell().ok_or(Tanks::new())?;
593+ let (acc, gate) = b.as_cell().ok_or(Tanks::new())?;
604594
605595 let mut res = Vec::new();
606596 let mut acc = acc.clone();
607597
608598 for n in list.list_iter() {
609599 let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
610− let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
600+ let (el, new_acc) = foo.as_cell().ok_or(Tanks::new())?;
611601 acc = new_acc.clone();
612602 res.push(el.clone());
613603 }
@@ -616,20 +606,20 @@ static SPIN: Jet = |ctx, n| {
616606};
617607
618608static SPUN: Jet = |ctx, n| {
619− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
609+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
620610
621611 let mut res = Vec::new();
622612 let mut acc = gate
623613 .gate_sample()
624− .ok_or(TTanks::new())?
614+ .ok_or(Tanks::new())?
625615 .as_cell()
626− .ok_or(TTanks::new())?
616+ .ok_or(Tanks::new())?
627617 .1
628618 .clone();
629619
630620 for n in list.list_iter() {
631621 let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
632− let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
622+ let (el, new_acc) = foo.as_cell().ok_or(Tanks::new())?;
633623 acc = new_acc.clone();
634624 res.push(el.clone());
635625 }
@@ -638,7 +628,7 @@ static SPUN: Jet = |ctx, n| {
638628};
639629
640630static TURN: Jet = |ctx, n| {
641− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
631+ let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
642632 Ok(Noun::list_refs(
643633 traverse_iter_result(list.list_iter().map(|x| slam_pulled_gate(ctx, gate, x)))?
644634 .iter()
@@ -647,7 +637,7 @@ static TURN: Jet = |ctx, n| {
647637};
648638
649639static WELD: Jet = |_ctx, n| {
650− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
640+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
651641
652642 Ok(Noun::list_refs(
653643 a.list_iter()
@@ -680,20 +670,18 @@ static BEX: Jet = |ctx, n| {
680670};
681671
682672static END: Jet = |ctx, n| {
683− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
673+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
684674 let bite = a.as_bite();
685675
686676 let bits = bite.bits();
687677
688678 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
689679
690− Ok(Rc::new(Noun::Atom(
691− mask & b.as_atom().ok_or(TTanks::new())?,
692− )))
680+ Ok(Rc::new(Noun::Atom(mask & b.as_atom().ok_or(Tanks::new())?)))
693681};
694682
695683static CAN: Jet = |ctx, n| {
696− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
684+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
697685 let bloq = a.as_u32().unwrap();
698686 let bloq_ = 2u32.pow(bloq);
699687
@@ -708,16 +696,16 @@ static CAN: Jet = |ctx, n| {
708696 Some((acc? << bits) | (mask & q.as_atom()?))
709697 },
710698 );
711− Ok(Rc::new(Noun::Atom(atom.ok_or(TTanks::new())?)))
699+ Ok(Rc::new(Noun::Atom(atom.ok_or(Tanks::new())?)))
712700};
713701
714702static CAT: Jet = |_ctx, n| {
715− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
716− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
703+ let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
704+ let (b, c) = b.as_cell().ok_or(Tanks::new())?;
717705
718− let bloq = bloq.as_u32().ok_or(TTanks::new())?;
719− let b = b.as_atom().ok_or(TTanks::new())?;
720− let c = c.as_atom().ok_or(TTanks::new())?;
706+ let bloq = bloq.as_u32().ok_or(Tanks::new())?;
707+ let b = b.as_atom().ok_or(Tanks::new())?;
708+ let c = c.as_atom().ok_or(Tanks::new())?;
721709
722710 Ok(Rc::new(Noun::Atom(
723711 (c << (met(bloq, &b) * 2u32.pow(bloq))) | b,
@@ -725,8 +713,8 @@ static CAT: Jet = |_ctx, n| {
725713};
726714
727715static MET: Jet = |_ctx, n| {
728− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
729− let b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
716+ let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
717+ let b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
730718 let bloq = bloq.as_u32().unwrap();
731719
732720 Ok(Rc::new(Noun::from_u32(met(bloq, &b))))
@@ -737,28 +725,28 @@ fn met(bloq: u32, a: &Atom) -> u32 {
737725}
738726
739727static CUT: Jet = |ctx, n| {
740− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
741− let (b, d) = b.as_cell().ok_or(TTanks::new())?;
742− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
728+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
729+ let (b, d) = b.as_cell().ok_or(Tanks::new())?;
730+ let (b, c) = b.as_cell().ok_or(Tanks::new())?;
743731
744732 let bits = 2u32.pow(a.as_u32().unwrap());
745733
746734 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
747735
748736 Ok(Rc::new(Noun::Atom(
749− (d.as_atom().ok_or(TTanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
737+ (d.as_atom().ok_or(Tanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
750738 )))
751739};
752740
753741static FIL: Jet = |ctx, n| {
754− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
755− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
742+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
743+ let (b, c) = b.as_cell().ok_or(Tanks::new())?;
756744
757745 let bits = 2u32.pow(a.as_u32().unwrap());
758746
759747 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
760748
761− let src = c.as_atom().ok_or(TTanks::new())? & mask;
749+ let src = c.as_atom().ok_or(Tanks::new())? & mask;
762750
763751 let mut target = ctx.big_uints.zero.clone();
764752
@@ -770,30 +758,30 @@ static FIL: Jet = |ctx, n| {
770758};
771759
772760static LSH: Jet = |_ctx, n| {
773− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
761+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
774762 let a = a.as_bite();
775− let b = b.as_atom().ok_or(TTanks::new())?;
763+ let b = b.as_atom().ok_or(Tanks::new())?;
776764
777765 Ok(Rc::new(Noun::Atom(b << a.bits())))
778766};
779767
780768static RSH: Jet = |_ctx, n| {
781− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
769+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
782770 let a = a.as_bite();
783− let b = b.as_atom().ok_or(TTanks::new())?;
771+ let b = b.as_atom().ok_or(Tanks::new())?;
784772
785773 Ok(Rc::new(Noun::Atom(b >> a.bits())))
786774};
787775
788−pub static RAP: Jet = |ctx, n| {
789− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
776+static RAP: Jet = |ctx, n| {
777+ let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
790778 let bloq = bloq.as_u32().unwrap();
791779 let bits = 2u32.pow(bloq);
792780
793781 let mut target = ctx.big_uints.zero.clone();
794782
795783 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
796− let el = el.as_atom().ok_or(TTanks::new())?;
784+ let el = el.as_atom().ok_or(Tanks::new())?;
797785 if el != &ctx.big_uints.zero {
798786 target = (target << (bits * met(bloq, &el))) | el;
799787 }
@@ -803,7 +791,7 @@ pub static RAP: Jet = |ctx, n| {
803791};
804792
805793static REP: Jet = |ctx, n| {
806− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
794+ let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
807795 let bite = bite.as_bite();
808796
809797 let bits = bite.bits();
@@ -812,18 +800,18 @@ static REP: Jet = |ctx, n| {
812800 let mut target = ctx.big_uints.zero.clone();
813801
814802 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
815− target = (target << bits) | (el.as_atom().ok_or(TTanks::new())? & &mask);
803+ target = (target << bits) | (el.as_atom().ok_or(Tanks::new())? & &mask);
816804 }
817805
818806 Ok(Rc::new(Noun::Atom(target)))
819807};
820808
821809static REV: Jet = |ctx, n| {
822− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
823− let (len, dat) = b.as_cell().ok_or(TTanks::new())?;
810+ let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
811+ let (len, dat) = b.as_cell().ok_or(Tanks::new())?;
824812 let bloq = bloq.as_u32().unwrap();
825813 let len = len.as_u32().unwrap();
826− let mut dat: Atom = dat.as_atom().ok_or(TTanks::new())?.clone();
814+ let mut dat: Atom = dat.as_atom().ok_or(Tanks::new())?.clone();
827815
828816 let bits = 2u32.pow(bloq);
829817 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -839,9 +827,9 @@ static REV: Jet = |ctx, n| {
839827};
840828
841829static RIP: Jet = |ctx, n| {
842− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
830+ let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
843831 let bite = bite.as_bite();
844− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
832+ let mut b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
845833
846834 let bits = bite.bits();
847835 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -857,11 +845,11 @@ static RIP: Jet = |ctx, n| {
857845};
858846
859847static RUN: Jet = |ctx, n| {
860− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
861− let (b, gate) = b.as_cell().ok_or(TTanks::new())?;
848+ let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
849+ let (b, gate) = b.as_cell().ok_or(Tanks::new())?;
862850
863851 let bite = bite.as_bite();
864− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
852+ let mut b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
865853
866854 let bits = bite.bits();
867855 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -872,7 +860,7 @@ static RUN: Jet = |ctx, n| {
872860 target = (target << bits)
873861 | ((*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
874862 .as_atom()
875− .ok_or(TTanks::new())?
863+ .ok_or(Tanks::new())?
876864 & &mask);
877865 b = b >> bits;
878866 }
@@ -881,11 +869,11 @@ static RUN: Jet = |ctx, n| {
881869};
882870
883871static RUT: Jet = |ctx, n| {
884− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
885− let (b, gate) = b.as_cell().ok_or(TTanks::new())?;
872+ let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
873+ let (b, gate) = b.as_cell().ok_or(Tanks::new())?;
886874
887875 let bite = bite.as_bite();
888− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
876+ let mut b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
889877
890878 let bits = bite.bits();
891879 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -896,7 +884,7 @@ static RUT: Jet = |ctx, n| {
896884 target.push(
897885 (*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
898886 .as_atom()
899− .ok_or(TTanks::new())?
887+ .ok_or(Tanks::new())?
900888 & &mask,
901889 );
902890 b = b >> bits;
@@ -906,12 +894,12 @@ static RUT: Jet = |ctx, n| {
906894};
907895
908896static SEW: Jet = |ctx, n| {
909− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
910− let (b, recipient) = b.as_cell().ok_or(TTanks::new())?;
911− let (sew_start, c) = b.as_cell().ok_or(TTanks::new())?;
912− let (number_of_blocks, donor) = c.as_cell().ok_or(TTanks::new())?;
913− let recipient = recipient.as_atom().ok_or(TTanks::new())?;
914− let donor = donor.as_atom().ok_or(TTanks::new())?;
897+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
898+ let (b, recipient) = b.as_cell().ok_or(Tanks::new())?;
899+ let (sew_start, c) = b.as_cell().ok_or(Tanks::new())?;
900+ let (number_of_blocks, donor) = c.as_cell().ok_or(Tanks::new())?;
901+ let recipient = recipient.as_atom().ok_or(Tanks::new())?;
902+ let donor = donor.as_atom().ok_or(Tanks::new())?;
915903
916904 let bloq = a.as_u32().unwrap();
917905 let bits = 2u32.pow(bloq);
@@ -927,12 +915,12 @@ static SEW: Jet = |ctx, n| {
927915};
928916
929917static SWP: Jet = |ctx, n| {
930− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
918+ let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
931919 let bloq = bloq.as_u32().unwrap();
932920 let bits = 2u32.pow(bloq);
933921 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
934922
935− let mut source = b.as_atom().ok_or(TTanks::new())?.clone();
923+ let mut source = b.as_atom().ok_or(Tanks::new())?.clone();
936924 let mut target = ctx.big_uints.zero.clone();
937925
938926 while source > ctx.big_uints.zero {
@@ -944,7 +932,7 @@ static SWP: Jet = |ctx, n| {
944932};
945933
946934static XEB: Jet = |_ctx, n| {
947− let mut a = n.as_atom().ok_or(TTanks::new())?.clone();
935+ let mut a = n.as_atom().ok_or(Tanks::new())?.clone();
948936
949937 let mut c = 0;
950938
@@ -961,22 +949,22 @@ static DIS: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a & b);
961949static MIX: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a ^ b);
962950
963951static NOT: Jet = |ctx, n| {
964− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
965− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
952+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
953+ let (b, c) = b.as_cell().ok_or(Tanks::new())?;
966954
967955 let bloq = a.as_u32().unwrap();
968956 let bits = 2u32.pow(bloq);
969957 let mask = (&ctx.big_uints.one << (bits * b.as_u32().unwrap())) - &ctx.big_uints.one;
970958
971− let target = c.as_atom().ok_or(TTanks::new())? ^ &mask;
959+ let target = c.as_atom().ok_or(Tanks::new())? ^ &mask;
972960
973961 Ok(Rc::new(Noun::Atom(target)))
974962};
975963
976964static LAST: Jet = |_ctx, n| {
977− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
978− let a = a.as_hair().ok_or(TTanks::new())?;
979− let b = b.as_hair().ok_or(TTanks::new())?;
965+ let (a, b) = n.as_cell().ok_or(Tanks::new())?;
966+ let a = a.as_hair().ok_or(Tanks::new())?;
967+ let b = b.as_hair().ok_or(Tanks::new())?;
980968 Ok(Noun::from_hair(last(&a, &b)))
981969};
982970
@@ -997,185 +985,22 @@ fn last<'a>(a: &'a Hair, b: &'a Hair) -> &'a Hair {
997985}
998986
999987static TRIP: Jet = |_ctx, n| {
1000− let a = n.as_atom().ok_or(TTanks::new())?;
988+ let a = n.as_atom().ok_or(Tanks::new())?;
1001989 Ok(Noun::list(
1002990 a.to_bytes_le().iter().map(|b| Noun::from_u32(*b as u32)),
1003991 ))
1004992};
1005993
1006994static MUK: Jet = |_ctx, n| {
1007− let (seed, len) = n.as_cell().ok_or(TTanks::new())?;
1008− let (len, key) = len.as_cell().ok_or(TTanks::new())?;
1009− let seed = seed.as_u32().ok_or(TTanks::new())?;
1010− let len = len.as_u32().ok_or(TTanks::new())?;
1011− let key = key.as_atom().ok_or(TTanks::new())?;
995+ let (seed, len) = n.as_cell().ok_or(Tanks::new())?;
996+ let (len, key) = len.as_cell().ok_or(Tanks::new())?;
997+ let seed = seed.as_u32().ok_or(Tanks::new())?;
998+ let len = len.as_u32().ok_or(Tanks::new())?;
999+ let key = key.as_atom().ok_or(Tanks::new())?;
10121000
10131001 Ok(Rc::new(Noun::from_u32(muk(seed, len, key))))
10141002};
10151003
1016−static AOR: Jet = |ctx, n| {
1017− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1018−
1019− if a == b {
1020− Ok(ctx.nouns.y.clone())
1021− } else {
1022− match (a.borrow(), b.borrow()) {
1023− (Noun::Cell { .. }, Noun::Atom(_)) => Ok(ctx.nouns.n.clone()),
1024− (Noun::Cell { p: a_p, q: a_q, .. }, Noun::Cell { p: b_p, q: b_q, .. }) => {
1025− if a_p == b_p {
1026− AOR(ctx, &cell(a_q, b_q))
1027− } else {
1028− AOR(ctx, &cell(a_p, b_p))
1029− }
1030− }
1031− (Noun::Atom(_), Noun::Cell { .. }) => Ok(ctx.nouns.y.clone()),
1032− (Noun::Atom(a), Noun::Atom(b)) => {
1033− let a = a.to_bytes_le();
1034− let b = b.to_bytes_le();
1035−
1036− let mut i = 0;
1037− loop {
1038− let c = a.get(i).unwrap_or(&0);
1039− let d = b.get(i).unwrap_or(&0);
1040−
1041− if a[0] == b[0] {
1042− i += 1;
1043− } else {
1044− if c < d {
1045− return Ok(ctx.nouns.y.clone());
1046− } else {
1047− return Ok(ctx.nouns.n.clone());
1048− }
1049− }
1050− }
1051− }
1052− }
1053− }
1054−};
1055−
1056−static DOR: Jet = |ctx, n| {
1057− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1058−
1059− if a == b {
1060− Ok(ctx.nouns.y.clone())
1061− } else {
1062− match (a.borrow(), b.borrow()) {
1063− (Noun::Cell { .. }, Noun::Atom(_)) => Ok(ctx.nouns.n.clone()),
1064− (Noun::Cell { p: a_p, q: a_q, .. }, Noun::Cell { p: b_p, q: b_q, .. }) => {
1065− if a_p == b_p {
1066− DOR(ctx, &cell(a_q, b_q))
1067− } else {
1068− DOR(ctx, &cell(a_p, b_p))
1069− }
1070− }
1071− (Noun::Atom(_), Noun::Cell { .. }) => Ok(ctx.nouns.y.clone()),
1072− (Noun::Atom(a), Noun::Atom(b)) => {
1073− if a < b {
1074− Ok(ctx.nouns.y.clone())
1075− } else {
1076− Ok(ctx.nouns.n.clone())
1077− }
1078− }
1079− }
1080− }
1081−};
1082−
1083−static GOR: Jet = |ctx, n| {
1084− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1085− let c = a.mug();
1086− let d = b.mug();
1087−
1088− if c == d {
1089− DOR(ctx, n)
1090− } else {
1091− if c < d {
1092− Ok(ctx.nouns.y.clone())
1093− } else {
1094− Ok(ctx.nouns.n.clone())
1095− }
1096− }
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−
1111−static MOR: Jet = |ctx, n| {
1112− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1113− let c = Noun::from_u32(a.mug()).mug();
1114− let d = Noun::from_u32(b.mug()).mug();
1115−
1116− if c == d {
1117− DOR(ctx, n)
1118− } else {
1119− if c < d {
1120− Ok(ctx.nouns.y.clone())
1121− } else {
1122− Ok(ctx.nouns.n.clone())
1123− }
1124− }
1125−};
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−
11791004static JUST: DoubleJet = |ctx, n, m| {
11801005 let char = n.as_atom()?;
11811006 let nail = m.as_nail()?;