@@ -1,39 +1,18 @@
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> {
19− let mut target: Vec<T> = Vec::new();
20−
21− for x in xs {
22− target.push(x.clone()?)
23− }
24−
25− Ok(target)
26−}
27−
2815pub 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−}
3716
3817pub fn generate_jets() -> Jets {
3918 BTreeMap::from([
@@ -75,7 +54,7 @@ pub fn generate_jets() -> Jets {
7554 (288515703007942177334798811660651439897, SNAG),
7655 (322006565952434408151902864454572452802, SNIP),
7756 (290837622185731774795798043954046795930, SNOC),
78− // (255402796382159268271460433298209603428, SORT),
57+ (255402796382159268271460433298209603428, SORT),
7958 (10111398404342329752608067595798409804, SPIN),
8059 (209194119090564757355985847956576215234, SPUN),
8160 (103985097318911737222583881947453560061, TURN),
@@ -102,69 +81,43 @@ pub fn generate_jets() -> Jets {
10281 (315388312266248574424227833154020891850, XEB),
10382 (26880808488368366377851132561579207892, CON),
10483 (311027486926441687148059942599447850754, DIS),
105− (330927609077697663248483044495963838437, MIX),
106− (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),
11684 ])
11785}
11886
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>>;
87+pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Rc<Noun>;
12188
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− ))))
89+static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Rc<Noun> =
90+ |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
91+ let Noun::Cell { p, q, .. } = (*n).clone() else {
92+ panic!()
93+ };
94+ Rc::new(Noun::Atom(f(p.as_atom().unwrap(), q.as_atom().unwrap())))
12995 };
13096
131−static BINARY_ATOM_LOOB: fn(
132− &InterpreterContext,
133− &Rc<Noun>,
134− 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())
97+static BINARY_ATOM_LOOB: fn(&InterpreterContext, Rc<Noun>, fn(&Atom, &Atom) -> bool) -> Rc<Noun> =
98+ |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
99+ let Noun::Cell { p, q, .. } = (*n).clone() else {
100+ panic!()
101+ };
102+
103+ if f(p.as_atom().unwrap(), q.as_atom().unwrap()) {
104+ ctx.nouns.sig.clone()
144105 } else {
145− Ok(ctx.nouns.one.clone())
106+ ctx.nouns.one.clone()
146107 }
147108 };
148109
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))))
160−};
110+static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Rc<Noun> =
111+ |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
112+ let Noun::Cell { p, q, .. } = (*n).clone() else {
113+ panic!()
114+ };
115+ let (a, b) = f(p.as_atom().unwrap(), q.as_atom().unwrap());
116+ cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b)))
117+ };
161118
162119static 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−};
120+static DEC: Jet = |_ctx, n| Rc::new(Noun::Atom(n.as_atom().unwrap() - 1u32));
168121static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
169122static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
170123static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -178,42 +131,40 @@ static MUL: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a * b);
178131static SUB: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a - b);
179132
180133static CAP: Jet = |ctx, n| {
181− let n = n.as_atom().ok_or(TTanks::new())?;
182− CAP_ATOM(ctx, n.clone())
134+ let Noun::Atom(n) = (*n).clone() else {
135+ panic!()
136+ };
137+ CAP_ATOM(ctx, n)
183138};
184−
185−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, TTanks> = |ctx, n: Atom| {
139+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Rc<Noun> = |ctx, n: Atom| {
186140 let mut n_iter = n.iter_u32_digits();
187141
188142 match n_iter.len() {
189− 0 => Err(TTanks::new()),
143+ 0 => panic!(),
190144 1 => CAP_U32(ctx, n_iter.next().unwrap()),
191145 _ => CAP_ATOM(ctx, n >> 1),
192146 }
193147};
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()),
148+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Rc<Noun> = |ctx, n| match n {
149+ 0 | 1 => panic!(),
150+ 2 => ctx.nouns.two.clone(),
151+ 3 => ctx.nouns.three.clone(),
198152 n => CAP_U32(ctx, n >> 1),
199153};
200154
201155static 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− )))
156+ let Noun::Atom(n) = (*n).clone() else {
157+ panic!()
158+ };
159+ Rc::new(Noun::Atom(MAS_ATOM(ctx, n)))
206160};
207−static MAS_ATOM: fn(&InterpreterContext, Atom) -> Option<Atom> = |ctx, n| {
161+static MAS_ATOM: fn(&InterpreterContext, Atom) -> Atom = |ctx, n| {
208162 let mut n_iter = n.iter_u32_digits();
209163
210164 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)),
165+ 0 => panic!(),
166+ 1 => Atom::new(vec![MAS_U32(n_iter.next().unwrap())]),
167+ _ => (&n & &ctx.big_uints.one) + (MAS_ATOM(ctx, &n >> 1) << 1),
217168 }
218169};
219170static MAS_U32: fn(u32) -> u32 = |n| match n {
@@ -223,24 +174,26 @@ static MAS_U32: fn(u32) -> u32 = |n| match n {
223174};
224175
225176static PEG: Jet = |ctx, n| {
226− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
177+ let Noun::Cell { p: a, q: b, .. } = (*n).clone() else {
178+ panic!()
179+ };
227180
228− let a = a.as_atom().ok_or(TTanks::new())?;
229− let b = b.as_atom().ok_or(TTanks::new())?;
181+ let a = a.as_atom().unwrap();
182+ let b = b.as_atom().unwrap();
230183
231184 if *a == Atom::ZERO {
232− return Err(TTanks::new());
185+ panic!()
233186 };
234187
235− Ok(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())?)))
188+ Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())))
236189};
237−static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, TTanks> = |ctx, a, b| {
190+static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Atom = |ctx, a, b| {
238191 let mut b_iter = b.iter_u32_digits();
239192
240193 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)),
194+ 0 => panic!(),
195+ 1 => PEG_U32(a, b_iter.next().unwrap()),
196+ _ => (&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1) << 1),
244197 }
245198};
246199static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
@@ -252,12 +205,12 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
252205};
253206
254207static FAND: Jet = |ctx, n| {
255− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
208+ let (nedl, hstk) = n.as_cell().unwrap();
256209 if nedl.is_sig() || hstk.is_sig() {
257− return Ok(ctx.nouns.sig.clone());
210+ return ctx.nouns.sig.clone();
258211 }
259212
260− let nedl: Vec<&Rc<Noun>> = nedl.list_iter().collect();
213+ let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
261214
262215 let mut result: Vec<u32> = Vec::new();
263216
@@ -278,16 +231,16 @@ static FAND: Jet = |ctx, n| {
278231 inner_iter = iter.clone();
279232 }
280233
281− Ok(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
234+ Noun::list(result.iter().map(|a| Noun::from_u32(*a)))
282235};
283236
284237static FIND: Jet = |ctx, n| {
285− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
238+ let (nedl, hstk) = n.as_cell().unwrap();
286239 if nedl.is_sig() || hstk.is_sig() {
287− return Ok(ctx.nouns.sig.clone());
240+ return ctx.nouns.sig.clone();
288241 }
289242
290− let nedl: Vec<&Rc<Noun>> = nedl.list_iter().collect();
243+ let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
291244
292245 let mut iter = zip(0.., hstk.list_iter());
293246
@@ -300,28 +253,28 @@ static FIND: Jet = |ctx, n| {
300253 .collect::<Vec<_>>()
301254 == nedl
302255 {
303− return Ok(Rc::new(Noun::from_u32(i)).unit());
256+ return Rc::new(Noun::from_u32(i)).unit();
304257 }
305258
306259 inner_iter = iter.clone();
307260 }
308261
309− return Ok(ctx.nouns.sig.clone());
262+ return ctx.nouns.sig.clone();
310263};
311264
312265static FLOP: Jet = |ctx, n| {
313− Ok(n.list_iter()
314− .fold(ctx.nouns.sig.clone(), |tail, head| cell(&head, &tail)))
266+ n.list_iter()
267+ .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail))
315268};
316269
317270static GULF: Jet = |_ctx, n| {
318− let (from, to) = n.as_cell().ok_or(TTanks::new())?;
271+ let (from, to) = n.as_cell().unwrap();
319272
320− let mut from = (*from.as_atom().ok_or(TTanks::new())?).clone();
321− let to = to.as_atom().ok_or(TTanks::new())?.clone();
273+ let mut from = (*from.as_atom().unwrap()).clone();
274+ let to = to.as_atom().unwrap().clone();
322275
323276 if from > to {
324− return Err(TTanks::new());
277+ panic!()
325278 }
326279
327280 let mut tmp = Vec::new();
@@ -331,434 +284,384 @@ static GULF: Jet = |_ctx, n| {
331284 from += 1u32;
332285 }
333286
334− Ok(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
287+ Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone())))
335288};
336289
337290static 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())?;
291+ let (a, b) = n.as_cell().unwrap();
292+ let (b, c) = b.as_cell().unwrap();
340293
341− let mut b_iter = b.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
294+ let mut b_iter = b.as_atom().unwrap().iter_u32_digits();
342295
343296 match b_iter.len() {
344− 0 => Ok(cell(&c, &a)),
297+ 0 => cell(c, a),
345298 1 => {
346299 let l = a.list_iter();
347300 let b = b_iter.next().unwrap() as usize;
348− Ok(Noun::list_refs(
301+ Noun::list_refs(
349302 l.clone()
350303 .take(b)
351304 .chain(once(c))
352305 .chain(l.skip(b))
353306 .collect::<Vec<_>>()
354307 .iter()
355− .cloned()
356− .cloned(),
357− ))
308+ .map(|x| x.clone()),
309+ )
358310 }
359− _ => Ok(Noun::list_refs(
311+ _ => Noun::list_refs(
360312 a.list_iter()
361313 .chain(once(c))
362314 .collect::<Vec<_>>()
363315 .iter()
364− .cloned()
365− .cloned(),
366− )),
316+ .map(|x| x.clone()),
317+ ),
367318 }
368319};
369320
370321static JOIN: Jet = |_ctx, n| {
371− let (sep, list) = n.as_cell().ok_or(TTanks::new())?;
372− Ok(Noun::list_refs(
322+ let (sep, list) = n.as_cell().unwrap();
323+ Noun::list_refs(
373324 list.list_iter()
374325 .intersperse(sep)
375326 .collect::<Vec<_>>()
376327 .iter()
377− .cloned()
378− .cloned(),
379− ))
328+ .map(|x| x.clone()),
329+ )
380330};
381331
382−static LENT: Jet = |_ctx, n| {
383− Ok(Rc::new(Noun::from_u32(
384− n.list_iter().fold(0u32, |l, _| l + 1),
385− )))
386−};
332+static LENT: Jet = |_ctx, n| Rc::new(Noun::from_u32(n.list_iter().fold(0u32, |l, _| l + 1)));
387333
388334static 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)))?
391− .iter()
392− .all(|x| x.is_y())
335+ let (a, b) = n.as_cell().unwrap();
336+ if a.list_iter()
337+ .all(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
393338 {
394− Ok(ctx.nouns.y.clone())
339+ ctx.nouns.y.clone()
395340 } else {
396− Ok(ctx.nouns.n.clone())
341+ ctx.nouns.n.clone()
397342 }
398343};
399344
400345static 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)))?
403− .iter()
404− .any(|x| x.is_y())
346+ let (a, b) = n.as_cell().unwrap();
347+ if a.list_iter()
348+ .any(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
405349 {
406− Ok(ctx.nouns.y.clone())
350+ ctx.nouns.y.clone()
407351 } else {
408− Ok(ctx.nouns.n.clone())
352+ ctx.nouns.n.clone()
409353 }
410354};
411355
412356static MURN: Jet = |ctx, n| {
413− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
357+ let (a, b) = n.as_cell().unwrap();
414358
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()),
422− ))
359+ Noun::list_refs(
360+ a.list_iter()
361+ .filter_map(|n| slam(ctx, b.clone(), n).as_unit())
362+ .collect::<Vec<_>>()
363+ .iter()
364+ .map(|x| x.clone()),
365+ )
423366};
424367
425368static REAP: Jet = |_ctx, n| {
426− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
369+ let (a, b) = n.as_cell().unwrap();
427370
428− Ok(Noun::list_refs(repeat_n(
429− b.clone(),
430− a.as_u32().unwrap() as usize,
431− )))
371+ Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize))
432372};
433373
434−static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(TTanks::new()).cloned();
374+static REAR: Jet = |_ctx, n| n.list_iter().last().unwrap();
435375
436376static REEL: Jet = |ctx, n| {
437− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
377+ let (list, gate) = n.as_cell().unwrap();
438378
439379 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− },
380+ gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
381+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
451382 )
452383};
453384
454385static ROLL: Jet = |ctx, n| {
455− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
386+ let (list, gate) = n.as_cell().unwrap();
456387
457388 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− },
389+ gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
390+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
470391 )
471392};
472393
473394static SCAG: Jet = |_ctx, n| {
474− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
395+ let (a, b) = n.as_cell().unwrap();
475396
476− Ok(Noun::list_refs(
397+ Noun::list_refs(
477398 b.list_iter()
478399 .take(a.as_u32().unwrap() as usize)
479400 .collect::<Vec<_>>()
480401 .iter()
481− .cloned()
482− .cloned(),
483− ))
402+ .map(|x| x.clone()),
403+ )
484404};
485405
486406static SKID: Jet = |ctx, n| {
487− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
407+ let (list, gate) = n.as_cell().unwrap();
488408
489− let slammed_n = traverse_iter_result(
490− list.list_iter()
491− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
492− )?;
493− let (ys, ns): (Vec<_>, _) = slammed_n.iter().partition(|(l, _)| l.is_y());
409+ let (ys, ns): (Vec<Rc<Noun>>, _) = list
410+ .list_iter()
411+ .partition(|n| slam(ctx, gate.clone(), n.clone()).is_y());
494412
495− Ok(cell(
496− &Noun::list_refs(ys.iter().map(|(_, x)| (*x).clone())),
497− &Noun::list_refs(ns.iter().map(|(_, x)| (*x).clone())),
498− ))
413+ cell(
414+ Noun::list_refs(ys.iter().cloned()),
415+ Noun::list_refs(ns.iter().cloned()),
416+ )
499417};
500418
501419static SKIM: Jet = |ctx, n| {
502− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
420+ let (list, gate) = n.as_cell().unwrap();
503421
504− Ok(Noun::list_refs(
505− traverse_iter_result(
506− list.list_iter()
507− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
508− )?
509− .iter()
510− .filter(|(l, _)| l.is_y())
511− .map(|(_, x)| (*x).clone()),
512− ))
422+ Noun::list_refs(
423+ list.list_iter()
424+ .filter(|n| slam(ctx, gate.clone(), n.clone()).is_y())
425+ .collect::<Vec<_>>()
426+ .iter()
427+ .cloned(),
428+ )
513429};
514430
515431static SKIP: Jet = |ctx, n| {
516− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
432+ let (list, gate) = n.as_cell().unwrap();
517433
518− Ok(Noun::list_refs(
519− traverse_iter_result(
520− list.list_iter()
521− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
522− )?
523− .iter()
524− .filter(|(l, _)| l.is_y())
525− .map(|(_, x)| (*x).clone()),
526− ))
434+ Noun::list_refs(
435+ list.list_iter()
436+ .filter(|n| slam(ctx, gate.clone(), n.clone()).is_n())
437+ .collect::<Vec<_>>()
438+ .iter()
439+ .cloned(),
440+ )
527441};
528442
529443static SLAG: Jet = |ctx, n| {
530− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
444+ let (a, list) = n.as_cell().unwrap();
531445
532− let mut a_iter = a.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
446+ let mut a_iter = a.as_atom().unwrap().iter_u32_digits();
533447
534448 match a_iter.len() {
535− 0 => Ok(list.clone()),
536− 1 => Ok(Noun::list_refs(
449+ 0 => list,
450+ 1 => Noun::list_refs(
537451 list.list_iter()
538452 .skip(a_iter.next().unwrap() as usize)
539453 .collect::<Vec<_>>()
540454 .iter()
541− .cloned()
542455 .cloned(),
543− )),
544− _ => Ok(ctx.nouns.sig.clone()),
456+ ),
457+ _ => ctx.nouns.sig.clone(),
545458 }
546459};
547460
548461static SNAG: Jet = |_ctx, n| {
549− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
462+ let (a, list) = n.as_cell().unwrap();
550463
551− list.list_iter()
552− .nth(a.as_u32().unwrap() as usize)
553− .cloned()
554− .ok_or(TTanks::new())
464+ list.list_iter().nth(a.as_u32().unwrap() as usize).unwrap()
555465};
556466
557467static SNIP: Jet = |_ctx, n| {
558− Ok(Noun::list_refs(
468+ Noun::list_refs(
559469 n.list_iter()
560470 .collect::<Vec<_>>()
561471 .iter()
562472 .rev()
563473 .skip(1)
564474 .rev()
565− .cloned()
566475 .cloned(),
567− ))
476+ )
568477};
569478
570479static SNOC: Jet = |_ctx, n| {
571− let (list, b) = n.as_cell().ok_or(TTanks::new())?;
480+ let (list, b) = n.as_cell().unwrap();
572481
573− Ok(Noun::list_refs(
482+ Noun::list_refs(
574483 list.list_iter()
575484 .chain(once(b))
576485 .collect::<Vec<_>>()
577486 .iter()
578− .cloned()
579487 .cloned(),
580− ))
488+ )
581489};
582490
583−// static SORT: Jet = |ctx, n| {
584−// let (list, lth) = n.as_cell().unwrap();
491+static SORT: Jet = |ctx, n| {
492+ let (list, lth) = n.as_cell().unwrap();
585493
586−// let mut v: Vec<_> = list.list_iter().collect();
494+ let mut v: Vec<_> = list.list_iter().collect();
587495
588−// v.sort_by(|a, b| {
589−// if slam(ctx, lth.clone(), cell(a.clone(), b.clone())) == ctx.nouns.some_y {
590−// Ordering::Less
591−// } else if slam(ctx, lth.clone(), cell(b.clone(), a.clone())) == ctx.nouns.some_y {
592−// Ordering::Greater
593−// } else {
594−// Ordering::Equal
595−// }
596−// });
496+ v.sort_by(|a, b| {
497+ if slam(ctx, lth.clone(), cell(a.clone(), b.clone())).is_y() {
498+ Ordering::Less
499+ } else if slam(ctx, lth.clone(), cell(b.clone(), a.clone())).is_y() {
500+ Ordering::Greater
501+ } else {
502+ Ordering::Equal
503+ }
504+ });
597505
598−// Some(Noun::list_refs(v.iter().cloned()))
599−// };
506+ Noun::list_refs(v.iter().cloned())
507+};
600508
601509static 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())?;
510+ let (list, b) = n.as_cell().unwrap();
511+ let (mut acc, gate) = b.as_cell().unwrap();
604512
605513 let mut res = Vec::new();
606− let mut acc = acc.clone();
607514
608515 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());
516+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc)).as_cell().unwrap();
517+ acc = new_acc;
518+ res.push(el);
613519 }
614520
615− Ok(cell(&Noun::list_refs(res.iter().cloned()), &acc))
521+ cell(Noun::list_refs(res.iter().cloned()), acc)
616522};
617523
618524static SPUN: Jet = |ctx, n| {
619− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
525+ let (list, gate) = n.as_cell().unwrap();
620526
621527 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();
528+ let mut acc = gate.clone().gate_sample().unwrap().as_cell().unwrap().1;
629529
630530 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());
531+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc)).as_cell().unwrap();
532+ acc = new_acc;
533+ res.push(el);
635534 }
636535
637− Ok(cell(&Noun::list_refs(res.iter().cloned()), &acc))
536+ cell(Noun::list_refs(res.iter().cloned()), acc)
638537};
639538
640539static 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)))?
540+ let (list, gate) = n.as_cell().unwrap();
541+ Noun::list_refs(
542+ list.list_iter()
543+ .map(|x| slam(ctx, gate.clone(), x))
544+ .collect::<Vec<_>>()
644545 .iter()
645546 .cloned(),
646− ))
547+ )
647548};
648549
649550static WELD: Jet = |_ctx, n| {
650− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
551+ let (a, b) = n.as_cell().unwrap();
651552
652− Ok(Noun::list_refs(
553+ Noun::list_refs(
653554 a.list_iter()
654555 .chain(b.list_iter())
655556 .collect::<Vec<_>>()
656557 .iter()
657− .cloned()
658558 .cloned(),
659− ))
559+ )
660560};
661561
662562static WELP: Jet = WELD;
663563
664564static ZING: Jet = |_ctx, n| {
665− Ok(Noun::list_refs(
565+ Noun::list_refs(
666566 n.list_iter()
667567 .map(|l| l.list_iter())
668568 .flatten()
669569 .collect::<Vec<_>>()
670570 .iter()
671− .cloned()
672571 .cloned(),
673− ))
572+ )
674573};
675574
676−static BEX: Jet = |ctx, n| {
677− Ok(Rc::new(Noun::Atom(
678− &ctx.big_uints.one << n.as_u32().unwrap(),
679− )))
680−};
575+static BEX: Jet = |ctx, n| Rc::new(Noun::Atom(&ctx.big_uints.one << n.as_u32().unwrap()));
681576
682577static END: Jet = |ctx, n| {
683− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
684− let bite = a.as_bite();
578+ let (a, b) = n.as_cell().unwrap();
579+ let bite = a.as_bite().unwrap();
685580
686581 let bits = bite.bits();
687582
688583 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
689584
690− Ok(Rc::new(Noun::Atom(
691− mask & b.as_atom().ok_or(TTanks::new())?,
692− )))
585+ Rc::new(Noun::Atom(mask & b.as_atom().unwrap()))
693586};
694587
695588static CAN: Jet = |ctx, n| {
696− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
589+ let (a, b) = n.as_cell().unwrap();
697590 let bloq = a.as_u32().unwrap();
698591 let bloq_ = 2u32.pow(bloq);
699592
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())?)))
593+ let atom: Atom =
594+ b.list_iter()
595+ .collect::<Vec<_>>()
596+ .iter()
597+ .rfold(ctx.big_uints.zero.clone(), |acc, next| {
598+ let (p, q) = next.as_cell().unwrap();
599+ let step = p.as_u32().unwrap();
600+ let bits = bloq_ * step;
601+ let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
602+
603+ (acc << bits) | (mask & q.as_atom().unwrap())
604+ });
605+ Rc::new(Noun::Atom(atom))
712606};
713607
714608static 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())?;
609+ let (bloq, b) = n.as_cell().unwrap();
610+ let (b, c) = b.as_cell().unwrap();
717611
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())?;
612+ let bloq = bloq.as_u32().unwrap();
613+ let b = b.as_atom().unwrap();
614+ let c = c.as_atom().unwrap();
721615
722− Ok(Rc::new(Noun::Atom(
723− (c << (met(bloq, &b) * 2u32.pow(bloq))) | b,
724− )))
616+ Rc::new(Noun::Atom(
617+ (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
618+ ))
725619};
726620
727621static 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();
622+ let (bloq, b) = n.as_cell().unwrap();
623+ let b: Atom = b.as_atom().unwrap().clone();
730624 let bloq = bloq.as_u32().unwrap();
731625
732− Ok(Rc::new(Noun::from_u32(met(bloq, &b))))
626+ Rc::new(Noun::from_u32(met(bloq, b)))
733627};
734628
735−fn met(bloq: u32, a: &Atom) -> u32 {
736− (a.bits() as u32).div_ceil(2u32.pow(bloq))
629+fn met(bloq: u32, mut a: Atom) -> u32 {
630+ let bits = 2u32.pow(bloq);
631+
632+ let mut c = 0;
633+
634+ while a > Atom::ZERO {
635+ a = a >> bits;
636+ c += 1;
637+ }
638+
639+ c
737640}
738641
739642static 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())?;
643+ let (a, b) = n.as_cell().unwrap();
644+ let (b, d) = b.as_cell().unwrap();
645+ let (b, c) = b.as_cell().unwrap();
743646
744647 let bits = 2u32.pow(a.as_u32().unwrap());
745648
746649 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
747650
748− Ok(Rc::new(Noun::Atom(
749− (d.as_atom().ok_or(TTanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
750− )))
651+ Rc::new(Noun::Atom(
652+ (d.as_atom().unwrap() >> (bits * b.as_u32().unwrap())) & mask,
653+ ))
751654};
752655
753656static 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())?;
657+ let (a, b) = n.as_cell().unwrap();
658+ let (b, c) = b.as_cell().unwrap();
756659
757660 let bits = 2u32.pow(a.as_u32().unwrap());
758661
759662 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
760663
761− let src = c.as_atom().ok_or(TTanks::new())? & mask;
664+ let src = c.as_atom().unwrap() & mask;
762665
763666 let mut target = ctx.big_uints.zero.clone();
764667
@@ -766,45 +669,45 @@ static FIL: Jet = |ctx, n| {
766669 target = (target << bits) | &src;
767670 }
768671
769− Ok(Rc::new(Noun::Atom(target)))
672+ Rc::new(Noun::Atom(target))
770673};
771674
772675static 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())?;
676+ let (a, b) = n.as_cell().unwrap();
677+ let a = a.as_bite().unwrap();
678+ let b = b.as_atom().unwrap();
776679
777− Ok(Rc::new(Noun::Atom(b << a.bits())))
680+ Rc::new(Noun::Atom(b << a.bits()))
778681};
779682
780683static 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())?;
684+ let (a, b) = n.as_cell().unwrap();
685+ let a = a.as_bite().unwrap();
686+ let b = b.as_atom().unwrap();
784687
785− Ok(Rc::new(Noun::Atom(b >> a.bits())))
688+ Rc::new(Noun::Atom(b >> a.bits()))
786689};
787690
788−pub static RAP: Jet = |ctx, n| {
789− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
691+static RAP: Jet = |ctx, n| {
692+ let (bloq, b) = n.as_cell().unwrap();
790693 let bloq = bloq.as_u32().unwrap();
791694 let bits = 2u32.pow(bloq);
792695
793696 let mut target = ctx.big_uints.zero.clone();
794697
795698 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
796− let el = el.as_atom().ok_or(TTanks::new())?;
699+ let el = el.as_atom().unwrap();
797700 if el != &ctx.big_uints.zero {
798− target = (target << (bits * met(bloq, &el))) | el;
701+ target = (target << (bits * met(bloq, el.clone()))) | el;
799702 }
800703 }
801704
802− Ok(Rc::new(Noun::Atom(target)))
705+ Rc::new(Noun::Atom(target))
803706};
804707
805708static REP: Jet = |ctx, n| {
806− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
807− let bite = bite.as_bite();
709+ let (bite, b) = n.as_cell().unwrap();
710+ let bite = bite.as_bite().unwrap();
808711
809712 let bits = bite.bits();
810713 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -812,18 +715,18 @@ static REP: Jet = |ctx, n| {
812715 let mut target = ctx.big_uints.zero.clone();
813716
814717 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
815− target = (target << bits) | (el.as_atom().ok_or(TTanks::new())? & &mask);
718+ target = (target << bits) | (el.as_atom().unwrap() & &mask);
816719 }
817720
818− Ok(Rc::new(Noun::Atom(target)))
721+ Rc::new(Noun::Atom(target))
819722};
820723
821724static 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())?;
725+ let (bloq, b) = n.as_cell().unwrap();
726+ let (len, dat) = b.as_cell().unwrap();
824727 let bloq = bloq.as_u32().unwrap();
825728 let len = len.as_u32().unwrap();
826− let mut dat: Atom = dat.as_atom().ok_or(TTanks::new())?.clone();
729+ let mut dat: Atom = dat.as_atom().unwrap().clone();
827730
828731 let bits = 2u32.pow(bloq);
829732 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -835,13 +738,13 @@ static REV: Jet = |ctx, n| {
835738 dat = dat >> bits;
836739 }
837740
838− Ok(Rc::new(Noun::Atom(target)))
741+ Rc::new(Noun::Atom(target))
839742};
840743
841744static 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();
745+ let (bite, b) = n.as_cell().unwrap();
746+ let bite = bite.as_bite().unwrap();
747+ let mut b: Atom = b.as_atom().unwrap().clone();
845748
846749 let bits = bite.bits();
847750 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -853,15 +756,15 @@ static RIP: Jet = |ctx, n| {
853756 b = b >> bits;
854757 }
855758
856− Ok(Noun::list_refs(target.iter().cloned()))
759+ Noun::list_refs(target.iter().cloned())
857760};
858761
859762static 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())?;
763+ let (bite, b) = n.as_cell().unwrap();
764+ let (b, gate) = b.as_cell().unwrap();
862765
863− let bite = bite.as_bite();
864− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
766+ let bite = bite.as_bite().unwrap();
767+ let mut b: Atom = b.as_atom().unwrap().clone();
865768
866769 let bits = bite.bits();
867770 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -870,22 +773,22 @@ static RUN: Jet = |ctx, n| {
870773
871774 while b > ctx.big_uints.zero {
872775 target = (target << bits)
873− | ((*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
776+ | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b))))
874777 .as_atom()
875− .ok_or(TTanks::new())?
778+ .unwrap()
876779 & &mask);
877780 b = b >> bits;
878781 }
879782
880− Ok(Rc::new(Noun::Atom(target)))
783+ Rc::new(Noun::Atom(target))
881784};
882785
883786static 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())?;
787+ let (bite, b) = n.as_cell().unwrap();
788+ let (b, gate) = b.as_cell().unwrap();
886789
887− let bite = bite.as_bite();
888− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
790+ let bite = bite.as_bite().unwrap();
791+ let mut b: Atom = b.as_atom().unwrap().clone();
889792
890793 let bits = bite.bits();
891794 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -894,24 +797,24 @@ static RUT: Jet = |ctx, n| {
894797
895798 while b > ctx.big_uints.zero {
896799 target.push(
897− (*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
800+ (*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b))))
898801 .as_atom()
899− .ok_or(TTanks::new())?
802+ .unwrap()
900803 & &mask,
901804 );
902805 b = b >> bits;
903806 }
904807
905− Ok(Noun::list(target.iter().cloned().map(Noun::Atom)))
808+ Noun::list(target.iter().cloned().map(Noun::Atom))
906809};
907810
908811static 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())?;
812+ let (a, b) = n.as_cell().unwrap();
813+ let (b, recipient) = b.as_cell().unwrap();
814+ let (sew_start, c) = b.as_cell().unwrap();
815+ let (number_of_blocks, donor) = c.as_cell().unwrap();
816+ let recipient = recipient.as_atom().unwrap();
817+ let donor = donor.as_atom().unwrap();
915818
916819 let bloq = a.as_u32().unwrap();
917820 let bits = 2u32.pow(bloq);
@@ -923,16 +826,16 @@ static SEW: Jet = |ctx, n| {
923826
924827 let target = (recipient ^ apendix) | (donor & mask);
925828
926− Ok(Rc::new(Noun::Atom(target)))
829+ Rc::new(Noun::Atom(target))
927830};
928831
929832static SWP: Jet = |ctx, n| {
930− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
833+ let (bloq, b) = n.as_cell().unwrap();
931834 let bloq = bloq.as_u32().unwrap();
932835 let bits = 2u32.pow(bloq);
933836 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
934837
935− let mut source = b.as_atom().ok_or(TTanks::new())?.clone();
838+ let mut source = b.as_atom().unwrap().clone();
936839 let mut target = ctx.big_uints.zero.clone();
937840
938841 while source > ctx.big_uints.zero {
@@ -940,11 +843,11 @@ static SWP: Jet = |ctx, n| {
940843 source = source >> bits;
941844 }
942845
943− Ok(Rc::new(Noun::Atom(target)))
846+ Rc::new(Noun::Atom(target))
944847};
945848
946849static XEB: Jet = |_ctx, n| {
947− let mut a = n.as_atom().ok_or(TTanks::new())?.clone();
850+ let mut a = n.as_atom().unwrap().clone();
948851
949852 let mut c = 0;
950853
@@ -953,318 +856,8 @@ static XEB: Jet = |_ctx, n| {
953856 c += 1;
954857 }
955858
956− Ok(Rc::new(Noun::from_u32(c)))
859+ Rc::new(Noun::from_u32(c))
957860};
958861
959862static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
960863static DIS: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a & b);
961−static MIX: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a ^ b);
962−
963−static 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())?;
966−
967− let bloq = a.as_u32().unwrap();
968− let bits = 2u32.pow(bloq);
969− let mask = (&ctx.big_uints.one << (bits * b.as_u32().unwrap())) - &ctx.big_uints.one;
970−
971− let target = c.as_atom().ok_or(TTanks::new())? ^ &mask;
972−
973− Ok(Rc::new(Noun::Atom(target)))
974−};
975−
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)))
981−};
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−}