@@ -2,14 +2,15 @@ use core::panic;
22use murmur3::murmur3_32;
33use num_integer::Integer;
44use std::{
5+ borrow::Borrow,
56 collections::BTreeMap,
67 iter::{once, repeat_n, zip},
78 rc::Rc,
89};
910
1011use crate::{
11− interpreter::{slam_pulled_gate, InterpreterContext, Tanks},
12− noun::{self, cell, Atom, Edge, Hair, Nail, Noun},
12+ interpreter::{slam_pulled_gate, InterpreterContext, TTanks, EMPTY_TANKS},
13+ noun::{self, cell, AsNoun, Atom, Edge, Hair, Nail, Noun},
1314};
1415
1516fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
@@ -107,18 +108,23 @@ pub fn generate_jets() -> Jets {
107108 (124976064672625230427889101290245200507, TRIP),
108109 (4078279288073906183633157465551067635, MUK),
109110 (261900159748071234702685239353558471892, MUG),
111+ (198191257620924788695943358402651905954, AOR),
112+ (299422828284010240628877806738195667652, DOR),
113+ (166326796552601297695313176538120818632, GOR),
114+ (7942398240152905363972500667649380756, MOR),
115+ (315687984998079865981003916817293521765, LOOK),
110116 ])
111117}
112118
113−pub type Jet = fn(ctx: &mut InterpreterContext, &Rc<Noun>) -> Result<Rc<Noun>, Tanks>;
119+pub type Jet = fn(ctx: &mut InterpreterContext, &Rc<Noun>) -> Result<Rc<Noun>, TTanks>;
114120pub type DoubleJet = fn(ctx: &mut InterpreterContext, &Rc<Noun>, &Rc<Noun>) -> Option<Rc<Noun>>;
115121
116−static BINARY_ATOM: fn(&Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Result<Rc<Noun>, Tanks> =
122+static BINARY_ATOM: fn(&Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Result<Rc<Noun>, TTanks> =
117123 |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
118− let (p, q) = n.as_cell().ok_or(Tanks::new())?;
124+ let (p, q) = n.as_cell().ok_or(TTanks::new())?;
119125 Ok(Rc::new(Noun::Atom(f(
120− p.as_atom().ok_or(Tanks::new())?,
121− q.as_atom().ok_or(Tanks::new())?,
126+ p.as_atom().ok_or(TTanks::new())?,
127+ q.as_atom().ok_or(TTanks::new())?,
122128 ))))
123129 };
124130
@@ -126,13 +132,13 @@ static BINARY_ATOM_LOOB: fn(
126132 &InterpreterContext,
127133 &Rc<Noun>,
128134 fn(&Atom, &Atom) -> bool,
129−) -> Result<Rc<Noun>, Tanks> =
135+) -> Result<Rc<Noun>, TTanks> =
130136 |ctx: &InterpreterContext, n: &Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
131− let (p, q) = n.as_cell().ok_or(Tanks::new())?;
137+ let (p, q) = n.as_cell().ok_or(TTanks::new())?;
132138
133139 if f(
134− p.as_atom().ok_or(Tanks::new())?,
135− q.as_atom().ok_or(Tanks::new())?,
140+ p.as_atom().ok_or(TTanks::new())?,
141+ q.as_atom().ok_or(TTanks::new())?,
136142 ) {
137143 Ok(ctx.nouns.sig.clone())
138144 } else {
@@ -143,18 +149,22 @@ static BINARY_ATOM_LOOB: fn(
143149static BINARY_ATOM_PAIR: fn(
144150 &Rc<Noun>,
145151 fn(&Atom, &Atom) -> (Atom, Atom),
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())?;
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())?;
148154
149155 let (a, b) = f(
150− p.as_atom().ok_or(Tanks::new())?,
151− q.as_atom().ok_or(Tanks::new())?,
156+ p.as_atom().ok_or(TTanks::new())?,
157+ q.as_atom().ok_or(TTanks::new())?,
152158 );
153159 Ok(cell(&Rc::new(Noun::Atom(a)), &Rc::new(Noun::Atom(b))))
154160};
155161
156162static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
157−static DEC: Jet = |_ctx, n| Ok(Rc::new(Noun::Atom(n.as_atom().ok_or(Tanks::new())? - 1u32)));
163+static DEC: Jet = |_ctx, n| {
164+ Ok(Rc::new(Noun::Atom(
165+ n.as_atom().ok_or(TTanks::new())? - 1u32,
166+ )))
167+};
158168static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
159169static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
160170static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -168,30 +178,30 @@ static MUL: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a * b);
168178static SUB: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a - b);
169179
170180static CAP: Jet = |ctx, n| {
171− let n = n.as_atom().ok_or(Tanks::new())?;
181+ let n = n.as_atom().ok_or(TTanks::new())?;
172182 CAP_ATOM(ctx, n.clone())
173183};
174184
175−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, Tanks> = |ctx, n: Atom| {
185+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, TTanks> = |ctx, n: Atom| {
176186 let mut n_iter = n.iter_u32_digits();
177187
178188 match n_iter.len() {
179− 0 => Err(Tanks::new()),
189+ 0 => Err(TTanks::new()),
180190 1 => CAP_U32(ctx, n_iter.next().unwrap()),
181191 _ => CAP_ATOM(ctx, n >> 1),
182192 }
183193};
184−static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Result<Rc<Noun>, Tanks> = |ctx, n| match n {
185− 0 | 1 => Err(Tanks::new()),
194+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Result<Rc<Noun>, TTanks> = |ctx, n| match n {
195+ 0 | 1 => Err(TTanks::new()),
186196 2 => Ok(ctx.nouns.two.clone()),
187197 3 => Ok(ctx.nouns.three.clone()),
188198 n => CAP_U32(ctx, n >> 1),
189199};
190200
191201static MAS: Jet = |ctx, n| {
192− let n = n.as_atom().ok_or(Tanks::new())?;
202+ let n = n.as_atom().ok_or(TTanks::new())?;
193203 Ok(Rc::new(Noun::Atom(
194− MAS_ATOM(ctx, n.clone()).ok_or(Tanks::new())?,
204+ MAS_ATOM(ctx, n.clone()).ok_or(TTanks::new())?,
195205 )))
196206};
197207static MAS_ATOM: fn(&InterpreterContext, Atom) -> Option<Atom> = |ctx, n| {
@@ -213,22 +223,22 @@ static MAS_U32: fn(u32) -> u32 = |n| match n {
213223};
214224
215225static PEG: Jet = |ctx, n| {
216− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
226+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
217227
218− let a = a.as_atom().ok_or(Tanks::new())?;
219− let b = b.as_atom().ok_or(Tanks::new())?;
228+ let a = a.as_atom().ok_or(TTanks::new())?;
229+ let b = b.as_atom().ok_or(TTanks::new())?;
220230
221231 if *a == Atom::ZERO {
222− return Err(Tanks::new());
232+ return Err(TTanks::new());
223233 };
224234
225235 Ok(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())?)))
226236};
227−static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, Tanks> = |ctx, a, b| {
237+static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, TTanks> = |ctx, a, b| {
228238 let mut b_iter = b.iter_u32_digits();
229239
230240 match b_iter.len() {
231− 0 => Err(Tanks::new()),
241+ 0 => Err(TTanks::new()),
232242 1 => Ok(PEG_U32(a, b_iter.next().unwrap())),
233243 _ => Ok((&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1)? << 1)),
234244 }
@@ -242,7 +252,7 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
242252};
243253
244254static FAND: Jet = |ctx, n| {
245− let (nedl, hstk) = n.as_cell().ok_or(Tanks::new())?;
255+ let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
246256 if nedl.is_sig() || hstk.is_sig() {
247257 return Ok(ctx.nouns.sig.clone());
248258 }
@@ -272,7 +282,7 @@ static FAND: Jet = |ctx, n| {
272282};
273283
274284static FIND: Jet = |ctx, n| {
275− let (nedl, hstk) = n.as_cell().ok_or(Tanks::new())?;
285+ let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
276286 if nedl.is_sig() || hstk.is_sig() {
277287 return Ok(ctx.nouns.sig.clone());
278288 }
@@ -305,13 +315,13 @@ static FLOP: Jet = |ctx, n| {
305315};
306316
307317static GULF: Jet = |_ctx, n| {
308− let (from, to) = n.as_cell().ok_or(Tanks::new())?;
318+ let (from, to) = n.as_cell().ok_or(TTanks::new())?;
309319
310− let mut from = (*from.as_atom().ok_or(Tanks::new())?).clone();
311− let to = to.as_atom().ok_or(Tanks::new())?.clone();
320+ let mut from = (*from.as_atom().ok_or(TTanks::new())?).clone();
321+ let to = to.as_atom().ok_or(TTanks::new())?.clone();
312322
313323 if from > to {
314− return Err(Tanks::new());
324+ return Err(TTanks::new());
315325 }
316326
317327 let mut tmp = Vec::new();
@@ -325,10 +335,10 @@ static GULF: Jet = |_ctx, n| {
325335};
326336
327337static INTO: Jet = |_ctx, n| {
328− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
329− let (b, c) = b.as_cell().ok_or(Tanks::new())?;
338+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
339+ let (b, c) = b.as_cell().ok_or(TTanks::new())?;
330340
331− let mut b_iter = b.as_atom().ok_or(Tanks::new())?.iter_u32_digits();
341+ let mut b_iter = b.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
332342
333343 match b_iter.len() {
334344 0 => Ok(cell(&c, &a)),
@@ -358,7 +368,7 @@ static INTO: Jet = |_ctx, n| {
358368};
359369
360370static JOIN: Jet = |_ctx, n| {
361− let (sep, list) = n.as_cell().ok_or(Tanks::new())?;
371+ let (sep, list) = n.as_cell().ok_or(TTanks::new())?;
362372 Ok(Noun::list_refs(
363373 list.list_iter()
364374 .intersperse(sep)
@@ -376,7 +386,7 @@ static LENT: Jet = |_ctx, n| {
376386};
377387
378388static LEVY: Jet = |ctx, n| {
379− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
389+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
380390 if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
381391 .iter()
382392 .all(|x| x.is_y())
@@ -388,7 +398,7 @@ static LEVY: Jet = |ctx, n| {
388398};
389399
390400static LIEN: Jet = |ctx, n| {
391− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
401+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
392402 if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
393403 .iter()
394404 .any(|x| x.is_y())
@@ -400,7 +410,7 @@ static LIEN: Jet = |ctx, n| {
400410};
401411
402412static MURN: Jet = |ctx, n| {
403− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
413+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
404414
405415 Ok(Noun::list_refs(
406416 traverse_iter_result(
@@ -413,7 +423,7 @@ static MURN: Jet = |ctx, n| {
413423};
414424
415425static REAP: Jet = |_ctx, n| {
416− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
426+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
417427
418428 Ok(Noun::list_refs(repeat_n(
419429 b.clone(),
@@ -421,17 +431,17 @@ static REAP: Jet = |_ctx, n| {
421431 )))
422432};
423433
424−static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(Tanks::new()).cloned();
434+static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(TTanks::new()).cloned();
425435
426436static REEL: Jet = |ctx, n| {
427− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
437+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
428438
429439 list.list_iter().collect::<Vec<_>>().iter().rfold(
430440 Ok(gate
431441 .gate_sample()
432− .ok_or(Tanks::new())?
442+ .ok_or(TTanks::new())?
433443 .as_cell()
434− .ok_or(Tanks::new())?
444+ .ok_or(TTanks::new())?
435445 .1
436446 .clone()),
437447 |acc, next| {
@@ -442,15 +452,15 @@ static REEL: Jet = |ctx, n| {
442452};
443453
444454static ROLL: Jet = |ctx, n| {
445− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
455+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
446456
447457 list.list_iter().fold(
448458 Ok(gate
449459 .clone()
450460 .gate_sample()
451− .ok_or(Tanks::new())?
461+ .ok_or(TTanks::new())?
452462 .as_cell()
453− .ok_or(Tanks::new())?
463+ .ok_or(TTanks::new())?
454464 .1
455465 .clone()),
456466 |acc, next| {
@@ -461,7 +471,7 @@ static ROLL: Jet = |ctx, n| {
461471};
462472
463473static SCAG: Jet = |_ctx, n| {
464− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
474+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
465475
466476 Ok(Noun::list_refs(
467477 b.list_iter()
@@ -474,7 +484,7 @@ static SCAG: Jet = |_ctx, n| {
474484};
475485
476486static SKID: Jet = |ctx, n| {
477− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
487+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
478488
479489 let slammed_n = traverse_iter_result(
480490 list.list_iter()
@@ -489,7 +499,7 @@ static SKID: Jet = |ctx, n| {
489499};
490500
491501static SKIM: Jet = |ctx, n| {
492− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
502+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
493503
494504 Ok(Noun::list_refs(
495505 traverse_iter_result(
@@ -503,7 +513,7 @@ static SKIM: Jet = |ctx, n| {
503513};
504514
505515static SKIP: Jet = |ctx, n| {
506− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
516+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
507517
508518 Ok(Noun::list_refs(
509519 traverse_iter_result(
@@ -517,9 +527,9 @@ static SKIP: Jet = |ctx, n| {
517527};
518528
519529static SLAG: Jet = |ctx, n| {
520− let (a, list) = n.as_cell().ok_or(Tanks::new())?;
530+ let (a, list) = n.as_cell().ok_or(TTanks::new())?;
521531
522− let mut a_iter = a.as_atom().ok_or(Tanks::new())?.iter_u32_digits();
532+ let mut a_iter = a.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
523533
524534 match a_iter.len() {
525535 0 => Ok(list.clone()),
@@ -536,12 +546,12 @@ static SLAG: Jet = |ctx, n| {
536546};
537547
538548static SNAG: Jet = |_ctx, n| {
539− let (a, list) = n.as_cell().ok_or(Tanks::new())?;
549+ let (a, list) = n.as_cell().ok_or(TTanks::new())?;
540550
541551 list.list_iter()
542552 .nth(a.as_u32().unwrap() as usize)
543553 .cloned()
544− .ok_or(Tanks::new())
554+ .ok_or(TTanks::new())
545555};
546556
547557static SNIP: Jet = |_ctx, n| {
@@ -558,7 +568,7 @@ static SNIP: Jet = |_ctx, n| {
558568};
559569
560570static SNOC: Jet = |_ctx, n| {
561− let (list, b) = n.as_cell().ok_or(Tanks::new())?;
571+ let (list, b) = n.as_cell().ok_or(TTanks::new())?;
562572
563573 Ok(Noun::list_refs(
564574 list.list_iter()
@@ -589,15 +599,15 @@ static SNOC: Jet = |_ctx, n| {
589599// };
590600
591601static SPIN: Jet = |ctx, n| {
592− let (list, b) = n.as_cell().ok_or(Tanks::new())?;
593− let (acc, gate) = b.as_cell().ok_or(Tanks::new())?;
602+ let (list, b) = n.as_cell().ok_or(TTanks::new())?;
603+ let (acc, gate) = b.as_cell().ok_or(TTanks::new())?;
594604
595605 let mut res = Vec::new();
596606 let mut acc = acc.clone();
597607
598608 for n in list.list_iter() {
599609 let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
600− let (el, new_acc) = foo.as_cell().ok_or(Tanks::new())?;
610+ let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
601611 acc = new_acc.clone();
602612 res.push(el.clone());
603613 }
@@ -606,20 +616,20 @@ static SPIN: Jet = |ctx, n| {
606616};
607617
608618static SPUN: Jet = |ctx, n| {
609− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
619+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
610620
611621 let mut res = Vec::new();
612622 let mut acc = gate
613623 .gate_sample()
614− .ok_or(Tanks::new())?
624+ .ok_or(TTanks::new())?
615625 .as_cell()
616− .ok_or(Tanks::new())?
626+ .ok_or(TTanks::new())?
617627 .1
618628 .clone();
619629
620630 for n in list.list_iter() {
621631 let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
622− let (el, new_acc) = foo.as_cell().ok_or(Tanks::new())?;
632+ let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
623633 acc = new_acc.clone();
624634 res.push(el.clone());
625635 }
@@ -628,7 +638,7 @@ static SPUN: Jet = |ctx, n| {
628638};
629639
630640static TURN: Jet = |ctx, n| {
631− let (list, gate) = n.as_cell().ok_or(Tanks::new())?;
641+ let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
632642 Ok(Noun::list_refs(
633643 traverse_iter_result(list.list_iter().map(|x| slam_pulled_gate(ctx, gate, x)))?
634644 .iter()
@@ -637,7 +647,7 @@ static TURN: Jet = |ctx, n| {
637647};
638648
639649static WELD: Jet = |_ctx, n| {
640− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
650+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
641651
642652 Ok(Noun::list_refs(
643653 a.list_iter()
@@ -670,18 +680,20 @@ static BEX: Jet = |ctx, n| {
670680};
671681
672682static END: Jet = |ctx, n| {
673− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
683+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
674684 let bite = a.as_bite();
675685
676686 let bits = bite.bits();
677687
678688 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
679689
680− Ok(Rc::new(Noun::Atom(mask & b.as_atom().ok_or(Tanks::new())?)))
690+ Ok(Rc::new(Noun::Atom(
691+ mask & b.as_atom().ok_or(TTanks::new())?,
692+ )))
681693};
682694
683695static CAN: Jet = |ctx, n| {
684− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
696+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
685697 let bloq = a.as_u32().unwrap();
686698 let bloq_ = 2u32.pow(bloq);
687699
@@ -696,16 +708,16 @@ static CAN: Jet = |ctx, n| {
696708 Some((acc? << bits) | (mask & q.as_atom()?))
697709 },
698710 );
699− Ok(Rc::new(Noun::Atom(atom.ok_or(Tanks::new())?)))
711+ Ok(Rc::new(Noun::Atom(atom.ok_or(TTanks::new())?)))
700712};
701713
702714static CAT: Jet = |_ctx, n| {
703− let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
704− let (b, c) = b.as_cell().ok_or(Tanks::new())?;
715+ let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
716+ let (b, c) = b.as_cell().ok_or(TTanks::new())?;
705717
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())?;
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())?;
709721
710722 Ok(Rc::new(Noun::Atom(
711723 (c << (met(bloq, &b) * 2u32.pow(bloq))) | b,
@@ -713,8 +725,8 @@ static CAT: Jet = |_ctx, n| {
713725};
714726
715727static MET: Jet = |_ctx, n| {
716− let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
717− let b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
728+ let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
729+ let b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
718730 let bloq = bloq.as_u32().unwrap();
719731
720732 Ok(Rc::new(Noun::from_u32(met(bloq, &b))))
@@ -725,28 +737,28 @@ fn met(bloq: u32, a: &Atom) -> u32 {
725737}
726738
727739static CUT: Jet = |ctx, n| {
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())?;
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())?;
731743
732744 let bits = 2u32.pow(a.as_u32().unwrap());
733745
734746 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
735747
736748 Ok(Rc::new(Noun::Atom(
737− (d.as_atom().ok_or(Tanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
749+ (d.as_atom().ok_or(TTanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
738750 )))
739751};
740752
741753static FIL: Jet = |ctx, n| {
742− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
743− let (b, c) = b.as_cell().ok_or(Tanks::new())?;
754+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
755+ let (b, c) = b.as_cell().ok_or(TTanks::new())?;
744756
745757 let bits = 2u32.pow(a.as_u32().unwrap());
746758
747759 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
748760
749− let src = c.as_atom().ok_or(Tanks::new())? & mask;
761+ let src = c.as_atom().ok_or(TTanks::new())? & mask;
750762
751763 let mut target = ctx.big_uints.zero.clone();
752764
@@ -758,30 +770,30 @@ static FIL: Jet = |ctx, n| {
758770};
759771
760772static LSH: Jet = |_ctx, n| {
761− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
773+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
762774 let a = a.as_bite();
763− let b = b.as_atom().ok_or(Tanks::new())?;
775+ let b = b.as_atom().ok_or(TTanks::new())?;
764776
765777 Ok(Rc::new(Noun::Atom(b << a.bits())))
766778};
767779
768780static RSH: Jet = |_ctx, n| {
769− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
781+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
770782 let a = a.as_bite();
771− let b = b.as_atom().ok_or(Tanks::new())?;
783+ let b = b.as_atom().ok_or(TTanks::new())?;
772784
773785 Ok(Rc::new(Noun::Atom(b >> a.bits())))
774786};
775787
776−static RAP: Jet = |ctx, n| {
777− let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
788+pub static RAP: Jet = |ctx, n| {
789+ let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
778790 let bloq = bloq.as_u32().unwrap();
779791 let bits = 2u32.pow(bloq);
780792
781793 let mut target = ctx.big_uints.zero.clone();
782794
783795 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
784− let el = el.as_atom().ok_or(Tanks::new())?;
796+ let el = el.as_atom().ok_or(TTanks::new())?;
785797 if el != &ctx.big_uints.zero {
786798 target = (target << (bits * met(bloq, &el))) | el;
787799 }
@@ -791,7 +803,7 @@ static RAP: Jet = |ctx, n| {
791803};
792804
793805static REP: Jet = |ctx, n| {
794− let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
806+ let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
795807 let bite = bite.as_bite();
796808
797809 let bits = bite.bits();
@@ -800,18 +812,18 @@ static REP: Jet = |ctx, n| {
800812 let mut target = ctx.big_uints.zero.clone();
801813
802814 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
803− target = (target << bits) | (el.as_atom().ok_or(Tanks::new())? & &mask);
815+ target = (target << bits) | (el.as_atom().ok_or(TTanks::new())? & &mask);
804816 }
805817
806818 Ok(Rc::new(Noun::Atom(target)))
807819};
808820
809821static REV: Jet = |ctx, n| {
810− let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
811− let (len, dat) = b.as_cell().ok_or(Tanks::new())?;
822+ let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
823+ let (len, dat) = b.as_cell().ok_or(TTanks::new())?;
812824 let bloq = bloq.as_u32().unwrap();
813825 let len = len.as_u32().unwrap();
814− let mut dat: Atom = dat.as_atom().ok_or(Tanks::new())?.clone();
826+ let mut dat: Atom = dat.as_atom().ok_or(TTanks::new())?.clone();
815827
816828 let bits = 2u32.pow(bloq);
817829 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -827,9 +839,9 @@ static REV: Jet = |ctx, n| {
827839};
828840
829841static RIP: Jet = |ctx, n| {
830− let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
842+ let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
831843 let bite = bite.as_bite();
832− let mut b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
844+ let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
833845
834846 let bits = bite.bits();
835847 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -845,11 +857,11 @@ static RIP: Jet = |ctx, n| {
845857};
846858
847859static RUN: Jet = |ctx, n| {
848− let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
849− let (b, gate) = b.as_cell().ok_or(Tanks::new())?;
860+ let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
861+ let (b, gate) = b.as_cell().ok_or(TTanks::new())?;
850862
851863 let bite = bite.as_bite();
852− let mut b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
864+ let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
853865
854866 let bits = bite.bits();
855867 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -860,7 +872,7 @@ static RUN: Jet = |ctx, n| {
860872 target = (target << bits)
861873 | ((*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
862874 .as_atom()
863− .ok_or(Tanks::new())?
875+ .ok_or(TTanks::new())?
864876 & &mask);
865877 b = b >> bits;
866878 }
@@ -869,11 +881,11 @@ static RUN: Jet = |ctx, n| {
869881};
870882
871883static RUT: Jet = |ctx, n| {
872− let (bite, b) = n.as_cell().ok_or(Tanks::new())?;
873− let (b, gate) = b.as_cell().ok_or(Tanks::new())?;
884+ let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
885+ let (b, gate) = b.as_cell().ok_or(TTanks::new())?;
874886
875887 let bite = bite.as_bite();
876− let mut b: Atom = b.as_atom().ok_or(Tanks::new())?.clone();
888+ let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
877889
878890 let bits = bite.bits();
879891 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -884,7 +896,7 @@ static RUT: Jet = |ctx, n| {
884896 target.push(
885897 (*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
886898 .as_atom()
887− .ok_or(Tanks::new())?
899+ .ok_or(TTanks::new())?
888900 & &mask,
889901 );
890902 b = b >> bits;
@@ -894,12 +906,12 @@ static RUT: Jet = |ctx, n| {
894906};
895907
896908static SEW: Jet = |ctx, n| {
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())?;
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())?;
903915
904916 let bloq = a.as_u32().unwrap();
905917 let bits = 2u32.pow(bloq);
@@ -915,12 +927,12 @@ static SEW: Jet = |ctx, n| {
915927};
916928
917929static SWP: Jet = |ctx, n| {
918− let (bloq, b) = n.as_cell().ok_or(Tanks::new())?;
930+ let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
919931 let bloq = bloq.as_u32().unwrap();
920932 let bits = 2u32.pow(bloq);
921933 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
922934
923− let mut source = b.as_atom().ok_or(Tanks::new())?.clone();
935+ let mut source = b.as_atom().ok_or(TTanks::new())?.clone();
924936 let mut target = ctx.big_uints.zero.clone();
925937
926938 while source > ctx.big_uints.zero {
@@ -932,7 +944,7 @@ static SWP: Jet = |ctx, n| {
932944};
933945
934946static XEB: Jet = |_ctx, n| {
935− let mut a = n.as_atom().ok_or(Tanks::new())?.clone();
947+ let mut a = n.as_atom().ok_or(TTanks::new())?.clone();
936948
937949 let mut c = 0;
938950
@@ -949,22 +961,22 @@ static DIS: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a & b);
949961static MIX: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a ^ b);
950962
951963static NOT: Jet = |ctx, n| {
952− let (a, b) = n.as_cell().ok_or(Tanks::new())?;
953− let (b, c) = b.as_cell().ok_or(Tanks::new())?;
964+ let (a, b) = n.as_cell().ok_or(TTanks::new())?;
965+ let (b, c) = b.as_cell().ok_or(TTanks::new())?;
954966
955967 let bloq = a.as_u32().unwrap();
956968 let bits = 2u32.pow(bloq);
957969 let mask = (&ctx.big_uints.one << (bits * b.as_u32().unwrap())) - &ctx.big_uints.one;
958970
959− let target = c.as_atom().ok_or(Tanks::new())? ^ &mask;
971+ let target = c.as_atom().ok_or(TTanks::new())? ^ &mask;
960972
961973 Ok(Rc::new(Noun::Atom(target)))
962974};
963975
964976static LAST: Jet = |_ctx, n| {
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())?;
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())?;
968980 Ok(Noun::from_hair(last(&a, &b)))
969981};
970982
@@ -985,22 +997,185 @@ fn last<'a>(a: &'a Hair, b: &'a Hair) -> &'a Hair {
985997}
986998
987999static TRIP: Jet = |_ctx, n| {
988− let a = n.as_atom().ok_or(Tanks::new())?;
1000+ let a = n.as_atom().ok_or(TTanks::new())?;
9891001 Ok(Noun::list(
9901002 a.to_bytes_le().iter().map(|b| Noun::from_u32(*b as u32)),
9911003 ))
9921004};
9931005
9941006static MUK: Jet = |_ctx, n| {
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())?;
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())?;
10001012
10011013 Ok(Rc::new(Noun::from_u32(muk(seed, len, key))))
10021014};
10031015
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+
10041179static JUST: DoubleJet = |ctx, n, m| {
10051180 let char = n.as_atom()?;
10061181 let nail = m.as_nail()?;