@@ -1,39 +1,28 @@
11use core::panic;
2−use murmur3::murmur3_32;
32use num_integer::Integer;
43use std::{
5− borrow::Borrow,
4+ cmp::Ordering,
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, InterpreterContext},
12+ noun::{self, cell, Atom, Noun},
1413};
1514
16−fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
17− xs: I,
18−) -> Result<Vec<T>, E> {
15+fn traverse_iter_option<T: Clone, I: Iterator<Item = Option<T>>>(xs: I) -> Option<Vec<T>> {
1916 let mut target: Vec<T> = Vec::new();
2017
2118 for x in xs {
2219 target.push(x.clone()?)
2320 }
2421
25− Ok(target)
22+ Some(target)
2623}
2724
2825pub type Jets = BTreeMap<noun::Hash, Jet>;
29−pub type DoubleJets = BTreeMap<noun::Hash, DoubleJet>;
30−
31−pub fn generate_double_jets() -> DoubleJets {
32− BTreeMap::from([
33− (210326504639957723220404138306543145797, JUST),
34− // (255213039400865122956425872354360738044, STIR),
35− ])
36−}
3726
3827pub fn generate_jets() -> Jets {
3928 BTreeMap::from([
@@ -104,67 +93,41 @@ pub fn generate_jets() -> Jets {
10493 (311027486926441687148059942599447850754, DIS),
10594 (330927609077697663248483044495963838437, MIX),
10695 (39579736615539990724554083585557839000, NOT),
107− (3482046397915506566435874021936376320, LAST),
108− (124976064672625230427889101290245200507, TRIP),
109− (4078279288073906183633157465551067635, MUK),
110− (261900159748071234702685239353558471892, MUG),
111− (198191257620924788695943358402651905954, AOR),
112− (299422828284010240628877806738195667652, DOR),
113− (166326796552601297695313176538120818632, GOR),
114− (7942398240152905363972500667649380756, MOR),
115− (315687984998079865981003916817293521765, LOOK),
11696 ])
11797}
11898
119−pub type Jet = fn(ctx: &mut InterpreterContext, &Rc<Noun>) -> Result<Rc<Noun>, TTanks>;
120−pub type DoubleJet = fn(ctx: &mut InterpreterContext, &Rc<Noun>, &Rc<Noun>) -> Option<Rc<Noun>>;
99+pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Option<Rc<Noun>>;
121100
122−static BINARY_ATOM: fn(&Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Result<Rc<Noun>, TTanks> =
123− |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
124− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
125− Ok(Rc::new(Noun::Atom(f(
126− p.as_atom().ok_or(TTanks::new())?,
127− q.as_atom().ok_or(TTanks::new())?,
128− ))))
101+static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Option<Rc<Noun>> =
102+ |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
103+ let (p, q) = n.as_cell()?;
104+ Some(Rc::new(Noun::Atom(f(p.as_atom()?, q.as_atom()?))))
129105 };
130106
131107static BINARY_ATOM_LOOB: fn(
132108 &InterpreterContext,
133− &Rc<Noun>,
109+ Rc<Noun>,
134110 fn(&Atom, &Atom) -> bool,
135−) -> Result<Rc<Noun>, TTanks> =
136− |ctx: &InterpreterContext, n: &Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
137− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
138−
139− if f(
140− p.as_atom().ok_or(TTanks::new())?,
141− q.as_atom().ok_or(TTanks::new())?,
142− ) {
143− Ok(ctx.nouns.sig.clone())
144− } else {
145− Ok(ctx.nouns.one.clone())
146− }
147− };
111+) -> Option<Rc<Noun>> = |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
112+ let (p, q) = n.as_cell().unwrap();
148113
149−static BINARY_ATOM_PAIR: fn(
150− &Rc<Noun>,
151− 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())?;
154−
155− let (a, b) = f(
156− p.as_atom().ok_or(TTanks::new())?,
157− q.as_atom().ok_or(TTanks::new())?,
158− );
159− Ok(cell(&Rc::new(Noun::Atom(a)), &Rc::new(Noun::Atom(b))))
114+ if f(p.as_atom()?, q.as_atom()?) {
115+ Some(ctx.nouns.sig.clone())
116+ } else {
117+ Some(ctx.nouns.one.clone())
118+ }
160119};
161120
121+static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Option<Rc<Noun>> =
122+ |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
123+ let (p, q) = n.as_cell().unwrap();
124+
125+ let (a, b) = f(p.as_atom().unwrap(), q.as_atom().unwrap());
126+ Some(cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b))))
127+ };
128+
162129static 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−};
130+static DEC: Jet = |_ctx, n| Some(Rc::new(Noun::Atom(n.as_atom().unwrap() - 1u32)));
168131static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
169132static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
170133static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -178,42 +141,40 @@ static MUL: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a * b);
178141static SUB: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a - b);
179142
180143static CAP: Jet = |ctx, n| {
181− let n = n.as_atom().ok_or(TTanks::new())?;
182− CAP_ATOM(ctx, n.clone())
144+ let Noun::Atom(n) = (*n).clone() else {
145+ panic!()
146+ };
147+ CAP_ATOM(ctx, n)
183148};
184−
185−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, TTanks> = |ctx, n: Atom| {
149+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Option<Rc<Noun>> = |ctx, n: Atom| {
186150 let mut n_iter = n.iter_u32_digits();
187151
188152 match n_iter.len() {
189− 0 => Err(TTanks::new()),
153+ 0 => panic!(),
190154 1 => CAP_U32(ctx, n_iter.next().unwrap()),
191155 _ => CAP_ATOM(ctx, n >> 1),
192156 }
193157};
194−static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Result<Rc<Noun>, TTanks> = |ctx, n| match n {
195− 0 | 1 => Err(TTanks::new()),
196− 2 => Ok(ctx.nouns.two.clone()),
197− 3 => Ok(ctx.nouns.three.clone()),
158+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Option<Rc<Noun>> = |ctx, n| match n {
159+ 0 | 1 => panic!(),
160+ 2 => Some(ctx.nouns.two.clone()),
161+ 3 => Some(ctx.nouns.three.clone()),
198162 n => CAP_U32(ctx, n >> 1),
199163};
200164
201165static MAS: Jet = |ctx, n| {
202− let n = n.as_atom().ok_or(TTanks::new())?;
203− Ok(Rc::new(Noun::Atom(
204− MAS_ATOM(ctx, n.clone()).ok_or(TTanks::new())?,
205− )))
166+ let Noun::Atom(n) = (*n).clone() else {
167+ panic!()
168+ };
169+ Some(Rc::new(Noun::Atom(MAS_ATOM(ctx, n))))
206170};
207−static MAS_ATOM: fn(&InterpreterContext, Atom) -> Option<Atom> = |ctx, n| {
171+static MAS_ATOM: fn(&InterpreterContext, Atom) -> Atom = |ctx, n| {
208172 let mut n_iter = n.iter_u32_digits();
209173
210174 match n_iter.len() {
211− 0 => None,
212− 1 => match n_iter.next().unwrap() {
213− 1 => None,
214− x => Some(Atom::new(vec![MAS_U32(x)])),
215− },
216− _ => Some((&n & &ctx.big_uints.one) + (MAS_ATOM(ctx, &n >> 1)? << 1)),
175+ 0 => panic!(),
176+ 1 => Atom::new(vec![MAS_U32(n_iter.next().unwrap())]),
177+ _ => (&n & &ctx.big_uints.one) + (MAS_ATOM(ctx, &n >> 1) << 1),
217178 }
218179};
219180static MAS_U32: fn(u32) -> u32 = |n| match n {
@@ -223,24 +184,26 @@ static MAS_U32: fn(u32) -> u32 = |n| match n {
223184};
224185
225186static PEG: Jet = |ctx, n| {
226− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
187+ let Noun::Cell { p: a, q: b, .. } = (*n).clone() else {
188+ panic!()
189+ };
227190
228− let a = a.as_atom().ok_or(TTanks::new())?;
229− let b = b.as_atom().ok_or(TTanks::new())?;
191+ let a = a.as_atom().unwrap();
192+ let b = b.as_atom().unwrap();
230193
231194 if *a == Atom::ZERO {
232− return Err(TTanks::new());
195+ panic!()
233196 };
234197
235− Ok(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())?)))
198+ Some(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone()))))
236199};
237−static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, TTanks> = |ctx, a, b| {
200+static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Atom = |ctx, a, b| {
238201 let mut b_iter = b.iter_u32_digits();
239202
240203 match b_iter.len() {
241− 0 => Err(TTanks::new()),
242− 1 => Ok(PEG_U32(a, b_iter.next().unwrap())),
243− _ => Ok((&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1)? << 1)),
204+ 0 => panic!(),
205+ 1 => PEG_U32(a, b_iter.next().unwrap()),
206+ _ => (&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1) << 1),
244207 }
245208};
246209static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
@@ -252,12 +215,12 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
252215};
253216
254217static FAND: Jet = |ctx, n| {
255− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
218+ let (nedl, hstk) = n.as_cell().unwrap();
256219 if nedl.is_sig() || hstk.is_sig() {
257− return Ok(ctx.nouns.sig.clone());
220+ return Some(ctx.nouns.sig.clone());
258221 }
259222
260− let nedl: Vec<&Rc<Noun>> = nedl.list_iter().collect();
223+ let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
261224
262225 let mut result: Vec<u32> = Vec::new();
263226
@@ -278,16 +241,16 @@ static FAND: Jet = |ctx, n| {
278241 inner_iter = iter.clone();
279242 }
280243
281− Ok(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
244+ Some(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
282245};
283246
284247static FIND: Jet = |ctx, n| {
285− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
248+ let (nedl, hstk) = n.as_cell().unwrap();
286249 if nedl.is_sig() || hstk.is_sig() {
287− return Ok(ctx.nouns.sig.clone());
250+ return Some(ctx.nouns.sig.clone());
288251 }
289252
290− let nedl: Vec<&Rc<Noun>> = nedl.list_iter().collect();
253+ let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
291254
292255 let mut iter = zip(0.., hstk.list_iter());
293256
@@ -300,28 +263,30 @@ static FIND: Jet = |ctx, n| {
300263 .collect::<Vec<_>>()
301264 == nedl
302265 {
303− return Ok(Rc::new(Noun::from_u32(i)).unit());
266+ return Some(Rc::new(Noun::from_u32(i)).unit());
304267 }
305268
306269 inner_iter = iter.clone();
307270 }
308271
309− return Ok(ctx.nouns.sig.clone());
272+ return Some(ctx.nouns.sig.clone());
310273};
311274
312275static FLOP: Jet = |ctx, n| {
313− Ok(n.list_iter()
314− .fold(ctx.nouns.sig.clone(), |tail, head| cell(&head, &tail)))
276+ Some(
277+ n.list_iter()
278+ .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail)),
279+ )
315280};
316281
317282static GULF: Jet = |_ctx, n| {
318− let (from, to) = n.as_cell().ok_or(TTanks::new())?;
283+ let (from, to) = n.as_cell().unwrap();
319284
320− let mut from = (*from.as_atom().ok_or(TTanks::new())?).clone();
321− let to = to.as_atom().ok_or(TTanks::new())?.clone();
285+ let mut from = (*from.as_atom().unwrap()).clone();
286+ let to = to.as_atom().unwrap().clone();
322287
323288 if from > to {
324− return Err(TTanks::new());
289+ panic!()
325290 }
326291
327292 let mut tmp = Vec::new();
@@ -331,251 +296,220 @@ static GULF: Jet = |_ctx, n| {
331296 from += 1u32;
332297 }
333298
334− Ok(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
299+ Some(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
335300};
336301
337302static 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())?;
303+ let (a, b) = n.as_cell().unwrap();
304+ let (b, c) = b.as_cell().unwrap();
340305
341− let mut b_iter = b.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
306+ let mut b_iter = b.as_atom().unwrap().iter_u32_digits();
342307
343308 match b_iter.len() {
344− 0 => Ok(cell(&c, &a)),
309+ 0 => Some(cell(c, a)),
345310 1 => {
346311 let l = a.list_iter();
347312 let b = b_iter.next().unwrap() as usize;
348− Ok(Noun::list_refs(
313+ Some(Noun::list_refs(
349314 l.clone()
350315 .take(b)
351316 .chain(once(c))
352317 .chain(l.skip(b))
353318 .collect::<Vec<_>>()
354319 .iter()
355− .cloned()
356− .cloned(),
320+ .map(|x| x.clone()),
357321 ))
358322 }
359− _ => Ok(Noun::list_refs(
323+ _ => Some(Noun::list_refs(
360324 a.list_iter()
361325 .chain(once(c))
362326 .collect::<Vec<_>>()
363327 .iter()
364− .cloned()
365− .cloned(),
328+ .map(|x| x.clone()),
366329 )),
367330 }
368331};
369332
370333static JOIN: Jet = |_ctx, n| {
371− let (sep, list) = n.as_cell().ok_or(TTanks::new())?;
372− Ok(Noun::list_refs(
334+ let (sep, list) = n.as_cell().unwrap();
335+ Some(Noun::list_refs(
373336 list.list_iter()
374337 .intersperse(sep)
375338 .collect::<Vec<_>>()
376339 .iter()
377− .cloned()
378− .cloned(),
340+ .map(|x| x.clone()),
379341 ))
380342};
381343
382344static LENT: Jet = |_ctx, n| {
383− Ok(Rc::new(Noun::from_u32(
345+ Some(Rc::new(Noun::from_u32(
384346 n.list_iter().fold(0u32, |l, _| l + 1),
385347 )))
386348};
387349
388350static LEVY: Jet = |ctx, n| {
389− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
390− if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
351+ let (a, b) = n.as_cell().unwrap();
352+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
391353 .iter()
392354 .all(|x| x.is_y())
393355 {
394− Ok(ctx.nouns.y.clone())
356+ Some(ctx.nouns.y.clone())
395357 } else {
396− Ok(ctx.nouns.n.clone())
358+ Some(ctx.nouns.n.clone())
397359 }
398360};
399361
400362static LIEN: Jet = |ctx, n| {
401− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
402− if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
363+ let (a, b) = n.as_cell().unwrap();
364+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
403365 .iter()
404366 .any(|x| x.is_y())
405367 {
406− Ok(ctx.nouns.y.clone())
368+ Some(ctx.nouns.y.clone())
407369 } else {
408− Ok(ctx.nouns.n.clone())
370+ Some(ctx.nouns.n.clone())
409371 }
410372};
411373
412374static MURN: Jet = |ctx, n| {
413− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
375+ let (a, b) = n.as_cell().unwrap();
414376
415− Ok(Noun::list_refs(
416− traverse_iter_result(
417− a.list_iter()
418− .map(|n| Ok(slam_pulled_gate(ctx, b, n)?.as_unit().cloned())),
419− )?
420− .iter()
421− .filter_map(|x| x.clone()),
377+ Some(Noun::list_refs(
378+ a.list_iter()
379+ .filter_map(|n| slam(ctx, b.clone(), n)?.as_unit())
380+ .collect::<Vec<_>>()
381+ .iter()
382+ .map(|x| x.clone()),
422383 ))
423384};
424385
425386static REAP: Jet = |_ctx, n| {
426− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
387+ let (a, b) = n.as_cell().unwrap();
427388
428− Ok(Noun::list_refs(repeat_n(
429− b.clone(),
430− a.as_u32().unwrap() as usize,
431− )))
389+ Some(Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize)))
432390};
433391
434−static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(TTanks::new()).cloned();
392+static REAR: Jet = |_ctx, n| n.list_iter().last();
435393
436394static REEL: Jet = |ctx, n| {
437− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
395+ let (list, gate) = n.as_cell().unwrap();
438396
439397 list.list_iter().collect::<Vec<_>>().iter().rfold(
440− Ok(gate
441− .gate_sample()
442− .ok_or(TTanks::new())?
443− .as_cell()
444− .ok_or(TTanks::new())?
445− .1
446− .clone()),
447− |acc, next| {
448− let acc = acc?;
449− slam_pulled_gate(ctx, gate, &cell(&next, &acc))
450− },
398+ Some(gate.clone().gate_sample()?.as_cell()?.1),
399+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
451400 )
452401};
453402
454403static ROLL: Jet = |ctx, n| {
455− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
404+ let (list, gate) = n.as_cell().unwrap();
456405
457406 list.list_iter().fold(
458− Ok(gate
459− .clone()
460− .gate_sample()
461− .ok_or(TTanks::new())?
462− .as_cell()
463− .ok_or(TTanks::new())?
464− .1
465− .clone()),
466− |acc, next| {
467− let acc = acc?;
468− slam_pulled_gate(ctx, gate, &cell(&next, &acc))
469− },
407+ Some(gate.clone().gate_sample()?.as_cell()?.1),
408+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
470409 )
471410};
472411
473412static SCAG: Jet = |_ctx, n| {
474− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
413+ let (a, b) = n.as_cell().unwrap();
475414
476− Ok(Noun::list_refs(
415+ Some(Noun::list_refs(
477416 b.list_iter()
478417 .take(a.as_u32().unwrap() as usize)
479418 .collect::<Vec<_>>()
480419 .iter()
481− .cloned()
482− .cloned(),
420+ .map(|x| x.clone()),
483421 ))
484422};
485423
486424static SKID: Jet = |ctx, n| {
487− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
425+ let (list, gate) = n.as_cell().unwrap();
488426
489− let slammed_n = traverse_iter_result(
427+ let slammed_n = traverse_iter_option(
490428 list.list_iter()
491− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
429+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
492430 )?;
493431 let (ys, ns): (Vec<_>, _) = slammed_n.iter().partition(|(l, _)| l.is_y());
494432
495− Ok(cell(
496− &Noun::list_refs(ys.iter().map(|(_, x)| (*x).clone())),
497− &Noun::list_refs(ns.iter().map(|(_, x)| (*x).clone())),
433+ Some(cell(
434+ Noun::list_refs(ys.iter().map(|(_, x)| x).cloned()),
435+ Noun::list_refs(ns.iter().map(|(_, x)| x).cloned()),
498436 ))
499437};
500438
501439static SKIM: Jet = |ctx, n| {
502− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
440+ let (list, gate) = n.as_cell().unwrap();
503441
504− Ok(Noun::list_refs(
505− traverse_iter_result(
442+ Some(Noun::list_refs(
443+ traverse_iter_option(
506444 list.list_iter()
507− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
445+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
508446 )?
509447 .iter()
510448 .filter(|(l, _)| l.is_y())
511− .map(|(_, x)| (*x).clone()),
449+ .map(|(_, x)| x)
450+ .cloned(),
512451 ))
513452};
514453
515454static SKIP: Jet = |ctx, n| {
516− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
455+ let (list, gate) = n.as_cell().unwrap();
517456
518− Ok(Noun::list_refs(
519− traverse_iter_result(
457+ Some(Noun::list_refs(
458+ traverse_iter_option(
520459 list.list_iter()
521− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
460+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
522461 )?
523462 .iter()
524463 .filter(|(l, _)| l.is_y())
525− .map(|(_, x)| (*x).clone()),
464+ .map(|(_, x)| x)
465+ .cloned(),
526466 ))
527467};
528468
529469static SLAG: Jet = |ctx, n| {
530− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
470+ let (a, list) = n.as_cell().unwrap();
531471
532− let mut a_iter = a.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
472+ let mut a_iter = a.as_atom().unwrap().iter_u32_digits();
533473
534474 match a_iter.len() {
535− 0 => Ok(list.clone()),
536− 1 => Ok(Noun::list_refs(
475+ 0 => Some(list),
476+ 1 => Some(Noun::list_refs(
537477 list.list_iter()
538478 .skip(a_iter.next().unwrap() as usize)
539479 .collect::<Vec<_>>()
540480 .iter()
541− .cloned()
542481 .cloned(),
543482 )),
544− _ => Ok(ctx.nouns.sig.clone()),
483+ _ => Some(ctx.nouns.sig.clone()),
545484 }
546485};
547486
548487static SNAG: Jet = |_ctx, n| {
549− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
488+ let (a, list) = n.as_cell().unwrap();
550489
551− list.list_iter()
552− .nth(a.as_u32().unwrap() as usize)
553− .cloned()
554− .ok_or(TTanks::new())
490+ list.list_iter().nth(a.as_u32().unwrap() as usize)
555491};
556492
557493static SNIP: Jet = |_ctx, n| {
558− Ok(Noun::list_refs(
494+ Some(Noun::list_refs(
559495 n.list_iter()
560496 .collect::<Vec<_>>()
561497 .iter()
562498 .rev()
563499 .skip(1)
564500 .rev()
565− .cloned()
566501 .cloned(),
567502 ))
568503};
569504
570505static SNOC: Jet = |_ctx, n| {
571− let (list, b) = n.as_cell().ok_or(TTanks::new())?;
506+ let (list, b) = n.as_cell().unwrap();
572507
573− Ok(Noun::list_refs(
508+ Some(Noun::list_refs(
574509 list.list_iter()
575510 .chain(once(b))
576511 .collect::<Vec<_>>()
577512 .iter()
578− .cloned()
579513 .cloned(),
580514 ))
581515};
@@ -599,62 +533,52 @@ static SNOC: Jet = |_ctx, n| {
599533// };
600534
601535static 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())?;
536+ let (list, b) = n.as_cell().unwrap();
537+ let (mut acc, gate) = b.as_cell().unwrap();
604538
605539 let mut res = Vec::new();
606− let mut acc = acc.clone();
607540
608541 for n in list.list_iter() {
609− let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
610− let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
611− acc = new_acc.clone();
612− res.push(el.clone());
542+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell().unwrap();
543+ acc = new_acc;
544+ res.push(el);
613545 }
614546
615− Ok(cell(&Noun::list_refs(res.iter().cloned()), &acc))
547+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
616548};
617549
618550static SPUN: Jet = |ctx, n| {
619− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
551+ let (list, gate) = n.as_cell().unwrap();
620552
621553 let mut res = Vec::new();
622− let mut acc = gate
623− .gate_sample()
624− .ok_or(TTanks::new())?
625− .as_cell()
626− .ok_or(TTanks::new())?
627− .1
628− .clone();
554+ let mut acc = gate.clone().gate_sample().unwrap().as_cell().unwrap().1;
629555
630556 for n in list.list_iter() {
631− let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
632− let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
633− acc = new_acc.clone();
634− res.push(el.clone());
557+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell().unwrap();
558+ acc = new_acc;
559+ res.push(el);
635560 }
636561
637− Ok(cell(&Noun::list_refs(res.iter().cloned()), &acc))
562+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
638563};
639564
640565static TURN: Jet = |ctx, n| {
641− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
642− Ok(Noun::list_refs(
643− traverse_iter_result(list.list_iter().map(|x| slam_pulled_gate(ctx, gate, x)))?
566+ let (list, gate) = n.as_cell().unwrap();
567+ Some(Noun::list_refs(
568+ traverse_iter_option(list.list_iter().map(|x| slam(ctx, gate.clone(), x)))?
644569 .iter()
645570 .cloned(),
646571 ))
647572};
648573
649574static WELD: Jet = |_ctx, n| {
650− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
575+ let (a, b) = n.as_cell().unwrap();
651576
652− Ok(Noun::list_refs(
577+ Some(Noun::list_refs(
653578 a.list_iter()
654579 .chain(b.list_iter())
655580 .collect::<Vec<_>>()
656581 .iter()
657− .cloned()
658582 .cloned(),
659583 ))
660584};
@@ -662,103 +586,110 @@ static WELD: Jet = |_ctx, n| {
662586static WELP: Jet = WELD;
663587
664588static ZING: Jet = |_ctx, n| {
665− Ok(Noun::list_refs(
589+ Some(Noun::list_refs(
666590 n.list_iter()
667591 .map(|l| l.list_iter())
668592 .flatten()
669593 .collect::<Vec<_>>()
670594 .iter()
671− .cloned()
672595 .cloned(),
673596 ))
674597};
675598
676599static BEX: Jet = |ctx, n| {
677− Ok(Rc::new(Noun::Atom(
600+ Some(Rc::new(Noun::Atom(
678601 &ctx.big_uints.one << n.as_u32().unwrap(),
679602 )))
680603};
681604
682605static END: Jet = |ctx, n| {
683− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
684− let bite = a.as_bite();
606+ let (a, b) = n.as_cell().unwrap();
607+ let bite = a.as_bite().unwrap();
685608
686609 let bits = bite.bits();
687610
688611 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
689612
690− Ok(Rc::new(Noun::Atom(
691− mask & b.as_atom().ok_or(TTanks::new())?,
692− )))
613+ Some(Rc::new(Noun::Atom(mask & b.as_atom().unwrap())))
693614};
694615
695616static CAN: Jet = |ctx, n| {
696− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
617+ let (a, b) = n.as_cell().unwrap();
697618 let bloq = a.as_u32().unwrap();
698619 let bloq_ = 2u32.pow(bloq);
699620
700− let atom: Option<Atom> = b.list_iter().collect::<Vec<_>>().iter().rfold(
701− Some(ctx.big_uints.zero.clone()),
702− |acc, next| {
703− let (p, q) = next.as_cell()?;
704− let step = p.as_u32().unwrap();
705− let bits = bloq_ * step;
706− let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
707−
708− Some((acc? << bits) | (mask & q.as_atom()?))
709− },
710− );
711− Ok(Rc::new(Noun::Atom(atom.ok_or(TTanks::new())?)))
621+ let atom: Atom =
622+ b.list_iter()
623+ .collect::<Vec<_>>()
624+ .iter()
625+ .rfold(ctx.big_uints.zero.clone(), |acc, next| {
626+ let (p, q) = next.as_cell().unwrap();
627+ let step = p.as_u32().unwrap();
628+ let bits = bloq_ * step;
629+ let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
630+
631+ (acc << bits) | (mask & q.as_atom().unwrap())
632+ });
633+ Some(Rc::new(Noun::Atom(atom)))
712634};
713635
714636static 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())?;
637+ let (bloq, b) = n.as_cell().unwrap();
638+ let (b, c) = b.as_cell().unwrap();
717639
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())?;
640+ let bloq = bloq.as_u32().unwrap();
641+ let b = b.as_atom().unwrap();
642+ let c = c.as_atom().unwrap();
721643
722− Ok(Rc::new(Noun::Atom(
723− (c << (met(bloq, &b) * 2u32.pow(bloq))) | b,
644+ Some(Rc::new(Noun::Atom(
645+ (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
724646 )))
725647};
726648
727649static 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();
650+ let (bloq, b) = n.as_cell().unwrap();
651+ let b: Atom = b.as_atom().unwrap().clone();
730652 let bloq = bloq.as_u32().unwrap();
731653
732− Ok(Rc::new(Noun::from_u32(met(bloq, &b))))
654+ Some(Rc::new(Noun::from_u32(met(bloq, b))))
733655};
734656
735−fn met(bloq: u32, a: &Atom) -> u32 {
736− (a.bits() as u32).div_ceil(2u32.pow(bloq))
657+fn met(bloq: u32, mut a: Atom) -> u32 {
658+ let bits = 2u32.pow(bloq);
659+
660+ let mut c = 0;
661+
662+ while a > Atom::ZERO {
663+ a = a >> bits;
664+ c += 1;
665+ }
666+
667+ c
737668}
738669
739670static 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())?;
671+ let (a, b) = n.as_cell().unwrap();
672+ let (b, d) = b.as_cell().unwrap();
673+ let (b, c) = b.as_cell().unwrap();
743674
744675 let bits = 2u32.pow(a.as_u32().unwrap());
745676
746677 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
747678
748− Ok(Rc::new(Noun::Atom(
749− (d.as_atom().ok_or(TTanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
679+ Some(Rc::new(Noun::Atom(
680+ (d.as_atom().unwrap() >> (bits * b.as_u32().unwrap())) & mask,
750681 )))
751682};
752683
753684static 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())?;
685+ let (a, b) = n.as_cell().unwrap();
686+ let (b, c) = b.as_cell().unwrap();
756687
757688 let bits = 2u32.pow(a.as_u32().unwrap());
758689
759690 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
760691
761− let src = c.as_atom().ok_or(TTanks::new())? & mask;
692+ let src = c.as_atom().unwrap() & mask;
762693
763694 let mut target = ctx.big_uints.zero.clone();
764695
@@ -766,45 +697,45 @@ static FIL: Jet = |ctx, n| {
766697 target = (target << bits) | &src;
767698 }
768699
769− Ok(Rc::new(Noun::Atom(target)))
700+ Some(Rc::new(Noun::Atom(target)))
770701};
771702
772703static LSH: Jet = |_ctx, n| {
773− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
774− let a = a.as_bite();
775− let b = b.as_atom().ok_or(TTanks::new())?;
704+ let (a, b) = n.as_cell().unwrap();
705+ let a = a.as_bite().unwrap();
706+ let b = b.as_atom().unwrap();
776707
777− Ok(Rc::new(Noun::Atom(b << a.bits())))
708+ Some(Rc::new(Noun::Atom(b << a.bits())))
778709};
779710
780711static RSH: Jet = |_ctx, n| {
781− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
782− let a = a.as_bite();
783− let b = b.as_atom().ok_or(TTanks::new())?;
712+ let (a, b) = n.as_cell().unwrap();
713+ let a = a.as_bite().unwrap();
714+ let b = b.as_atom().unwrap();
784715
785− Ok(Rc::new(Noun::Atom(b >> a.bits())))
716+ Some(Rc::new(Noun::Atom(b >> a.bits())))
786717};
787718
788−pub static RAP: Jet = |ctx, n| {
789− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
719+static RAP: Jet = |ctx, n| {
720+ let (bloq, b) = n.as_cell().unwrap();
790721 let bloq = bloq.as_u32().unwrap();
791722 let bits = 2u32.pow(bloq);
792723
793724 let mut target = ctx.big_uints.zero.clone();
794725
795726 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
796− let el = el.as_atom().ok_or(TTanks::new())?;
727+ let el = el.as_atom().unwrap();
797728 if el != &ctx.big_uints.zero {
798− target = (target << (bits * met(bloq, &el))) | el;
729+ target = (target << (bits * met(bloq, el.clone()))) | el;
799730 }
800731 }
801732
802− Ok(Rc::new(Noun::Atom(target)))
733+ Some(Rc::new(Noun::Atom(target)))
803734};
804735
805736static REP: Jet = |ctx, n| {
806− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
807− let bite = bite.as_bite();
737+ let (bite, b) = n.as_cell().unwrap();
738+ let bite = bite.as_bite().unwrap();
808739
809740 let bits = bite.bits();
810741 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -812,18 +743,18 @@ static REP: Jet = |ctx, n| {
812743 let mut target = ctx.big_uints.zero.clone();
813744
814745 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
815− target = (target << bits) | (el.as_atom().ok_or(TTanks::new())? & &mask);
746+ target = (target << bits) | (el.as_atom().unwrap() & &mask);
816747 }
817748
818− Ok(Rc::new(Noun::Atom(target)))
749+ Some(Rc::new(Noun::Atom(target)))
819750};
820751
821752static 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())?;
753+ let (bloq, b) = n.as_cell().unwrap();
754+ let (len, dat) = b.as_cell().unwrap();
824755 let bloq = bloq.as_u32().unwrap();
825756 let len = len.as_u32().unwrap();
826− let mut dat: Atom = dat.as_atom().ok_or(TTanks::new())?.clone();
757+ let mut dat: Atom = dat.as_atom().unwrap().clone();
827758
828759 let bits = 2u32.pow(bloq);
829760 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -835,13 +766,13 @@ static REV: Jet = |ctx, n| {
835766 dat = dat >> bits;
836767 }
837768
838− Ok(Rc::new(Noun::Atom(target)))
769+ Some(Rc::new(Noun::Atom(target)))
839770};
840771
841772static RIP: Jet = |ctx, n| {
842− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
843− let bite = bite.as_bite();
844− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
773+ let (bite, b) = n.as_cell().unwrap();
774+ let bite = bite.as_bite().unwrap();
775+ let mut b: Atom = b.as_atom().unwrap().clone();
845776
846777 let bits = bite.bits();
847778 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -853,15 +784,15 @@ static RIP: Jet = |ctx, n| {
853784 b = b >> bits;
854785 }
855786
856− Ok(Noun::list_refs(target.iter().cloned()))
787+ Some(Noun::list_refs(target.iter().cloned()))
857788};
858789
859790static 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())?;
791+ let (bite, b) = n.as_cell().unwrap();
792+ let (b, gate) = b.as_cell().unwrap();
862793
863− let bite = bite.as_bite();
864− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
794+ let bite = bite.as_bite().unwrap();
795+ let mut b: Atom = b.as_atom().unwrap().clone();
865796
866797 let bits = bite.bits();
867798 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -870,22 +801,22 @@ static RUN: Jet = |ctx, n| {
870801
871802 while b > ctx.big_uints.zero {
872803 target = (target << bits)
873− | ((*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
804+ | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?)
874805 .as_atom()
875− .ok_or(TTanks::new())?
806+ .unwrap()
876807 & &mask);
877808 b = b >> bits;
878809 }
879810
880− Ok(Rc::new(Noun::Atom(target)))
811+ Some(Rc::new(Noun::Atom(target)))
881812};
882813
883814static 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())?;
815+ let (bite, b) = n.as_cell().unwrap();
816+ let (b, gate) = b.as_cell().unwrap();
886817
887− let bite = bite.as_bite();
888− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
818+ let bite = bite.as_bite().unwrap();
819+ let mut b: Atom = b.as_atom().unwrap().clone();
889820
890821 let bits = bite.bits();
891822 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -894,24 +825,24 @@ static RUT: Jet = |ctx, n| {
894825
895826 while b > ctx.big_uints.zero {
896827 target.push(
897− (*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
828+ (*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?)
898829 .as_atom()
899− .ok_or(TTanks::new())?
830+ .unwrap()
900831 & &mask,
901832 );
902833 b = b >> bits;
903834 }
904835
905− Ok(Noun::list(target.iter().cloned().map(Noun::Atom)))
836+ Some(Noun::list(target.iter().cloned().map(Noun::Atom)))
906837};
907838
908839static 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())?;
840+ let (a, b) = n.as_cell().unwrap();
841+ let (b, recipient) = b.as_cell().unwrap();
842+ let (sew_start, c) = b.as_cell().unwrap();
843+ let (number_of_blocks, donor) = c.as_cell().unwrap();
844+ let recipient = recipient.as_atom().unwrap();
845+ let donor = donor.as_atom().unwrap();
915846
916847 let bloq = a.as_u32().unwrap();
917848 let bits = 2u32.pow(bloq);
@@ -923,16 +854,16 @@ static SEW: Jet = |ctx, n| {
923854
924855 let target = (recipient ^ apendix) | (donor & mask);
925856
926− Ok(Rc::new(Noun::Atom(target)))
857+ Some(Rc::new(Noun::Atom(target)))
927858};
928859
929860static SWP: Jet = |ctx, n| {
930− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
861+ let (bloq, b) = n.as_cell().unwrap();
931862 let bloq = bloq.as_u32().unwrap();
932863 let bits = 2u32.pow(bloq);
933864 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
934865
935− let mut source = b.as_atom().ok_or(TTanks::new())?.clone();
866+ let mut source = b.as_atom().unwrap().clone();
936867 let mut target = ctx.big_uints.zero.clone();
937868
938869 while source > ctx.big_uints.zero {
@@ -940,11 +871,11 @@ static SWP: Jet = |ctx, n| {
940871 source = source >> bits;
941872 }
942873
943− Ok(Rc::new(Noun::Atom(target)))
874+ Some(Rc::new(Noun::Atom(target)))
944875};
945876
946877static XEB: Jet = |_ctx, n| {
947− let mut a = n.as_atom().ok_or(TTanks::new())?.clone();
878+ let mut a = n.as_atom().unwrap().clone();
948879
949880 let mut c = 0;
950881
@@ -953,7 +884,7 @@ static XEB: Jet = |_ctx, n| {
953884 c += 1;
954885 }
955886
956− Ok(Rc::new(Noun::from_u32(c)))
887+ Some(Rc::new(Noun::from_u32(c)))
957888};
958889
959890static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
@@ -961,310 +892,14 @@ static DIS: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a & b);
961892static MIX: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a ^ b);
962893
963894static 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())?;
895+ let (a, b) = n.as_cell().unwrap();
896+ let (b, c) = b.as_cell().unwrap();
966897
967898 let bloq = a.as_u32().unwrap();
968899 let bits = 2u32.pow(bloq);
969900 let mask = (&ctx.big_uints.one << (bits * b.as_u32().unwrap())) - &ctx.big_uints.one;
970901
971− let target = c.as_atom().ok_or(TTanks::new())? ^ &mask;
972−
973− Ok(Rc::new(Noun::Atom(target)))
974−};
902+ let target = c.as_atom().unwrap() ^ &mask;
975903
976−static 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())?;
980− Ok(Noun::from_hair(last(&a, &b)))
904+ Some(Rc::new(Noun::Atom(target)))
981905};
982−
983−fn last<'a>(a: &'a Hair, b: &'a Hair) -> &'a Hair {
984− if a.line == b.line {
985− if a.column > b.column {
986− a
987− } else {
988− b
989− }
990− } else {
991− if a.line > b.line {
992− a
993− } else {
994− b
995− }
996− }
997−}
998−
999−static TRIP: Jet = |_ctx, n| {
1000− let a = n.as_atom().ok_or(TTanks::new())?;
1001− Ok(Noun::list(
1002− a.to_bytes_le().iter().map(|b| Noun::from_u32(*b as u32)),
1003− ))
1004−};
1005−
1006−static 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())?;
1012−
1013− Ok(Rc::new(Noun::from_u32(muk(seed, len, key))))
1014−};
1015−
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−
1179−static JUST: DoubleJet = |ctx, n, m| {
1180− let char = n.as_atom()?;
1181− let nail = m.as_nail()?;
1182− if *nail.rest == ctx.nouns.sig {
1183− Some(fail(nail).as_noun())
1184− } else {
1185− let (i, _) = nail.rest.as_cell()?;
1186− let i = i.as_atom()?;
1187− if i == char {
1188− Some(next(nail)?.as_noun())
1189− } else {
1190− Some(fail(nail).as_noun())
1191− }
1192− }
1193−};
1194−
1195−// static STIR: DoubleJet = |ctx, n, m| {
1196−// let (rud, raq) = n.as_cell()?;
1197−// let (raq, fel) = raq.as_cell()?;
1198−// let tub = m.as_nail()?;
1199−
1200−// let mut lef = Vec::new();
1201−// let mut vex = slam(ctx, fel, tub)?.as;
1202−// if vex.
1203−// };
1204−
1205−fn next<'a>(nail: Nail<'a>) -> Option<Edge<'a>> {
1206− if **nail.rest == Noun::SIG {
1207− Some(fail(nail))
1208− } else {
1209− let (i, t) = nail.rest.as_cell()?;
1210− let zac = lust(i.as_atom()?.clone(), nail.hair);
1211− // cell(zac, cell(Rc::new(Noun::SIG), cell(i, cell(zac, t))))
1212− Some(Edge {
1213− hair: zac.clone(),
1214− result: Some((i, Nail { hair: zac, rest: t })),
1215− })
1216− }
1217−}
1218−
1219−fn lust(char: Atom, hair: Hair) -> Hair {
1220− if char == Atom::from_slice(&vec![10]) {
1221− Hair {
1222− line: hair.line + 1,
1223− column: 1,
1224− }
1225− } else {
1226− Hair {
1227− line: hair.line,
1228− column: hair.column + 1,
1229− }
1230− }
1231−}
1232−
1233−fn fail(nail: Nail) -> Edge {
1234− Edge {
1235− hair: nail.hair,
1236− result: None,
1237− }
1238−}
1239−
1240−const MUG: Jet = |__ctx, n| Ok(Rc::new(Noun::from_u32(n.mug())));
1241−
1242−pub fn mum(syd: u32, fal: u32, key: &Atom) -> u32 {
1243− let wyd = met(3, &key);
1244− let mut i = 0;
1245− loop {
1246− if i == 8 {
1247− break fal;
1248− } else {
1249− let haz = muk(syd, wyd, &key);
1250− let ham = (haz >> 31) ^ (haz & !(1 << 31));
1251− if ham == 0 {
1252− i += 1;
1253− continue;
1254− } else {
1255− break ham;
1256− }
1257− }
1258− }
1259−}
1260−
1261−fn muk(seed: u32, len: u32, key: &Atom) -> u32 {
1262− let key: Vec<_> = key
1263− .to_bytes_le()
1264− .iter()
1265− .take(len as usize)
1266− .cloned()
1267− .collect();
1268−
1269− murmur3_32(&mut &*key, seed).unwrap()
1270−}