@@ -1,39 +1,27 @@
1use core::panic;
1use core::panic;
2−use murmur3::murmur3_32;
3use num_integer::Integer;
2use num_integer::Integer;
6 collections::BTreeMap,
4 collections::BTreeMap,
7 iter::{once, repeat_n, zip},
5 iter::{once, repeat_n, zip},
11use crate::{
9use crate::{
12− interpreter::{slam_pulled_gate, InterpreterContext, TTanks, EMPTY_TANKS},
10+ interpreter::{slam, InterpreterContext},
13− noun::{self, cell, AsNoun, Atom, Edge, Hair, Nail, Noun},
11+ noun::{self, cell, Atom, Noun},
16−fn traverse_iter_result<E: Clone, T: Clone, I: Iterator<Item = Result<T, E>>>(
14+fn traverse_iter_option<T: Clone, I: Iterator<Item = Option<T>>>(xs: I) -> Option<Vec<T>> {
18−) -> Result<Vec<T>, E> {
19 let mut target: Vec<T> = Vec::new();
15 let mut target: Vec<T> = Vec::new();
21 for x in xs {
17 for x in xs {
22 target.push(x.clone()?)
18 target.push(x.clone()?)
25− Ok(target)
21+ Some(target)
28pub type Jets = BTreeMap<noun::Hash, Jet>;
24pub type Jets = BTreeMap<noun::Hash, Jet>;
29−pub type DoubleJets = BTreeMap<noun::Hash, DoubleJet>;
31−pub fn generate_double_jets() -> DoubleJets {
33− (210326504639957723220404138306543145797, JUST),
34− // (255213039400865122956425872354360738044, STIR),
38pub fn generate_jets() -> Jets {
26pub fn generate_jets() -> Jets {
39 BTreeMap::from([
27 BTreeMap::from([
@@ -104,67 +92,41 @@ pub fn generate_jets() -> Jets {
104 (311027486926441687148059942599447850754, DIS),
92 (311027486926441687148059942599447850754, DIS),
105 (330927609077697663248483044495963838437, MIX),
93 (330927609077697663248483044495963838437, MIX),
106 (39579736615539990724554083585557839000, NOT),
94 (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),
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>>;
98+pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Option<Rc<Noun>>;
122−static BINARY_ATOM: fn(&Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Result<Rc<Noun>, TTanks> =
100+static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Option<Rc<Noun>> =
123− |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
101+ |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
124− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
102+ let (p, q) = n.as_cell()?;
125− Ok(Rc::new(Noun::Atom(f(
103+ Some(Rc::new(Noun::Atom(f(p.as_atom()?, q.as_atom()?))))
126− p.as_atom().ok_or(TTanks::new())?,
127− q.as_atom().ok_or(TTanks::new())?,
131static BINARY_ATOM_LOOB: fn(
106static BINARY_ATOM_LOOB: fn(
132 &InterpreterContext,
107 &InterpreterContext,
133− &Rc<Noun>,
108+ Rc<Noun>,
134 fn(&Atom, &Atom) -> bool,
109 fn(&Atom, &Atom) -> bool,
135−) -> Result<Rc<Noun>, TTanks> =
136− |ctx: &InterpreterContext, n: &Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
110+) -> Option<Rc<Noun>> = |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
137− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
111+ let (p, q) = n.as_cell()?;
140− p.as_atom().ok_or(TTanks::new())?,
141− q.as_atom().ok_or(TTanks::new())?,
143− Ok(ctx.nouns.sig.clone())
145− Ok(ctx.nouns.one.clone())
149−static BINARY_ATOM_PAIR: fn(
113+ if f(p.as_atom()?, q.as_atom()?) {
150− &Rc<Noun>,
114+ Some(ctx.nouns.sig.clone())
151− fn(&Atom, &Atom) -> (Atom, Atom),
115+ } else {
152−) -> Result<Rc<Noun>, TTanks> = |n: &Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
116+ Some(ctx.nouns.one.clone())
153− let (p, q) = n.as_cell().ok_or(TTanks::new())?;
117+ }
156− p.as_atom().ok_or(TTanks::new())?,
157− q.as_atom().ok_or(TTanks::new())?,
159− Ok(cell(&Rc::new(Noun::Atom(a)), &Rc::new(Noun::Atom(b))))
120+static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Option<Rc<Noun>> =
121+ |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
122+ let (p, q) = n.as_cell()?;
124+ let (a, b) = f(p.as_atom()?, q.as_atom()?);
125+ Some(cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b))))
162static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
128static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
163−static DEC: Jet = |_ctx, n| {
129+static DEC: Jet = |_ctx, n| Some(Rc::new(Noun::Atom(n.as_atom()? - 1u32)));
164− Ok(Rc::new(Noun::Atom(
165− n.as_atom().ok_or(TTanks::new())? - 1u32,
168static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
130static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
169static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
131static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
170static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
132static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -178,31 +140,29 @@ static MUL: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a * b);
178static SUB: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a - b);
140static SUB: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a - b);
180static CAP: Jet = |ctx, n| {
142static CAP: Jet = |ctx, n| {
181− let n = n.as_atom().ok_or(TTanks::new())?;
143+ let n = n.as_atom()?;
182 CAP_ATOM(ctx, n.clone())
144 CAP_ATOM(ctx, n.clone())
185−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Result<Rc<Noun>, TTanks> = |ctx, n: Atom| {
147+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Option<Rc<Noun>> = |ctx, n: Atom| {
186 let mut n_iter = n.iter_u32_digits();
148 let mut n_iter = n.iter_u32_digits();
188 match n_iter.len() {
150 match n_iter.len() {
189− 0 => Err(TTanks::new()),
151+ 0 => None,
190 1 => CAP_U32(ctx, n_iter.next().unwrap()),
152 1 => CAP_U32(ctx, n_iter.next().unwrap()),
191 _ => CAP_ATOM(ctx, n >> 1),
153 _ => CAP_ATOM(ctx, n >> 1),
194−static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Result<Rc<Noun>, TTanks> = |ctx, n| match n {
156+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Option<Rc<Noun>> = |ctx, n| match n {
195− 0 | 1 => Err(TTanks::new()),
157+ 0 | 1 => None,
196− 2 => Ok(ctx.nouns.two.clone()),
158+ 2 => Some(ctx.nouns.two.clone()),
197− 3 => Ok(ctx.nouns.three.clone()),
159+ 3 => Some(ctx.nouns.three.clone()),
198 n => CAP_U32(ctx, n >> 1),
160 n => CAP_U32(ctx, n >> 1),
201static MAS: Jet = |ctx, n| {
163static MAS: Jet = |ctx, n| {
202− let n = n.as_atom().ok_or(TTanks::new())?;
164+ let n = n.as_atom()?;
203− Ok(Rc::new(Noun::Atom(
165+ Some(Rc::new(Noun::Atom(MAS_ATOM(ctx, n.clone())?)))
204− MAS_ATOM(ctx, n.clone()).ok_or(TTanks::new())?,
207static MAS_ATOM: fn(&InterpreterContext, Atom) -> Option<Atom> = |ctx, n| {
167static MAS_ATOM: fn(&InterpreterContext, Atom) -> Option<Atom> = |ctx, n| {
208 let mut n_iter = n.iter_u32_digits();
168 let mut n_iter = n.iter_u32_digits();
@@ -223,24 +183,24 @@ static MAS_U32: fn(u32) -> u32 = |n| match n {
225static PEG: Jet = |ctx, n| {
185static PEG: Jet = |ctx, n| {
226− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
186+ let (a, b) = n.as_cell()?;
228− let a = a.as_atom().ok_or(TTanks::new())?;
188+ let a = a.as_atom()?;
229− let b = b.as_atom().ok_or(TTanks::new())?;
189+ let b = b.as_atom()?;
231 if *a == Atom::ZERO {
191 if *a == Atom::ZERO {
232− return Err(TTanks::new());
192+ return None;
235− Ok(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())?)))
195+ Some(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())?)))
237−static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Result<Atom, TTanks> = |ctx, a, b| {
197+static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Option<Atom> = |ctx, a, b| {
238 let mut b_iter = b.iter_u32_digits();
198 let mut b_iter = b.iter_u32_digits();
240 match b_iter.len() {
200 match b_iter.len() {
241− 0 => Err(TTanks::new()),
201+ 0 => None,
242− 1 => Ok(PEG_U32(a, b_iter.next().unwrap())),
202+ 1 => Some(PEG_U32(a, b_iter.next().unwrap())),
243− _ => Ok((&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1)? << 1)),
203+ _ => Some((&b & &ctx.big_uints.one) + (PEG_ATOM(ctx, a, b >> 1)? << 1)),
246static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
206static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
@@ -252,12 +212,12 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
254static FAND: Jet = |ctx, n| {
214static FAND: Jet = |ctx, n| {
255− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
215+ let (nedl, hstk) = n.as_cell()?;
256 if nedl.is_sig() || hstk.is_sig() {
216 if nedl.is_sig() || hstk.is_sig() {
257− return Ok(ctx.nouns.sig.clone());
217+ return Some(ctx.nouns.sig.clone());
260− let nedl: Vec<&Rc<Noun>> = nedl.list_iter().collect();
220+ let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
262 let mut result: Vec<u32> = Vec::new();
222 let mut result: Vec<u32> = Vec::new();
@@ -278,16 +238,16 @@ static FAND: Jet = |ctx, n| {
278 inner_iter = iter.clone();
238 inner_iter = iter.clone();
281− Ok(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
241+ Some(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
284static FIND: Jet = |ctx, n| {
244static FIND: Jet = |ctx, n| {
285− let (nedl, hstk) = n.as_cell().ok_or(TTanks::new())?;
245+ let (nedl, hstk) = n.as_cell()?;
286 if nedl.is_sig() || hstk.is_sig() {
246 if nedl.is_sig() || hstk.is_sig() {
287− return Ok(ctx.nouns.sig.clone());
247+ return Some(ctx.nouns.sig.clone());
290− let nedl: Vec<&Rc<Noun>> = nedl.list_iter().collect();
250+ let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
292 let mut iter = zip(0.., hstk.list_iter());
252 let mut iter = zip(0.., hstk.list_iter());
@@ -300,28 +260,30 @@ static FIND: Jet = |ctx, n| {
300 .collect::<Vec<_>>()
260 .collect::<Vec<_>>()
303− return Ok(Rc::new(Noun::from_u32(i)).unit());
263+ return Some(Rc::new(Noun::from_u32(i)).unit());
306 inner_iter = iter.clone();
266 inner_iter = iter.clone();
309− return Ok(ctx.nouns.sig.clone());
269+ return Some(ctx.nouns.sig.clone());
312static FLOP: Jet = |ctx, n| {
272static FLOP: Jet = |ctx, n| {
313− Ok(n.list_iter()
274+ n.list_iter()
314− .fold(ctx.nouns.sig.clone(), |tail, head| cell(&head, &tail)))
275+ .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail)),
317static GULF: Jet = |_ctx, n| {
279static GULF: Jet = |_ctx, n| {
318− let (from, to) = n.as_cell().ok_or(TTanks::new())?;
280+ let (from, to) = n.as_cell()?;
320− let mut from = (*from.as_atom().ok_or(TTanks::new())?).clone();
282+ let mut from = (*from.as_atom()?).clone();
321− let to = to.as_atom().ok_or(TTanks::new())?.clone();
283+ let to = to.as_atom()?.clone();
323 if from > to {
285 if from > to {
324− return Err(TTanks::new());
286+ return None;
327 let mut tmp = Vec::new();
289 let mut tmp = Vec::new();
@@ -331,251 +293,220 @@ static GULF: Jet = |_ctx, n| {
331 from += 1u32;
293 from += 1u32;
334− Ok(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
296+ Some(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
337static INTO: Jet = |_ctx, n| {
299static INTO: Jet = |_ctx, n| {
338− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
300+ let (a, b) = n.as_cell()?;
339− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
301+ let (b, c) = b.as_cell()?;
341− let mut b_iter = b.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
303+ let mut b_iter = b.as_atom()?.iter_u32_digits();
343 match b_iter.len() {
305 match b_iter.len() {
344− 0 => Ok(cell(&c, &a)),
306+ 0 => Some(cell(c, a)),
346 let l = a.list_iter();
308 let l = a.list_iter();
347 let b = b_iter.next().unwrap() as usize;
309 let b = b_iter.next().unwrap() as usize;
348− Ok(Noun::list_refs(
310+ Some(Noun::list_refs(
349 l.clone()
311 l.clone()
351 .chain(once(c))
313 .chain(once(c))
352 .chain(l.skip(b))
314 .chain(l.skip(b))
353 .collect::<Vec<_>>()
315 .collect::<Vec<_>>()
355− .cloned()
317+ .map(|x| x.clone()),
359− _ => Ok(Noun::list_refs(
320+ _ => Some(Noun::list_refs(
360 a.list_iter()
321 a.list_iter()
361 .chain(once(c))
322 .chain(once(c))
362 .collect::<Vec<_>>()
323 .collect::<Vec<_>>()
364− .cloned()
325+ .map(|x| x.clone()),
370static JOIN: Jet = |_ctx, n| {
330static JOIN: Jet = |_ctx, n| {
371− let (sep, list) = n.as_cell().ok_or(TTanks::new())?;
331+ let (sep, list) = n.as_cell()?;
372− Ok(Noun::list_refs(
332+ Some(Noun::list_refs(
373 list.list_iter()
333 list.list_iter()
374 .intersperse(sep)
334 .intersperse(sep)
375 .collect::<Vec<_>>()
335 .collect::<Vec<_>>()
378 .cloned(),
337 .cloned(),
382static LENT: Jet = |_ctx, n| {
341static LENT: Jet = |_ctx, n| {
383− Ok(Rc::new(Noun::from_u32(
342+ Some(Rc::new(Noun::from_u32(
384 n.list_iter().fold(0u32, |l, _| l + 1),
343 n.list_iter().fold(0u32, |l, _| l + 1),
388static LEVY: Jet = |ctx, n| {
347static LEVY: Jet = |ctx, n| {
389− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
348+ let (a, b) = n.as_cell()?;
390− if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
349+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
392 .all(|x| x.is_y())
351 .all(|x| x.is_y())
394− Ok(ctx.nouns.y.clone())
353+ Some(ctx.nouns.y.clone())
396− Ok(ctx.nouns.n.clone())
355+ Some(ctx.nouns.n.clone())
400static LIEN: Jet = |ctx, n| {
359static LIEN: Jet = |ctx, n| {
401− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
360+ let (a, b) = n.as_cell()?;
402− if traverse_iter_result(a.list_iter().map(|n| slam_pulled_gate(ctx, b, n)))?
361+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
404 .any(|x| x.is_y())
363 .any(|x| x.is_y())
406− Ok(ctx.nouns.y.clone())
365+ Some(ctx.nouns.y.clone())
408− Ok(ctx.nouns.n.clone())
367+ Some(ctx.nouns.n.clone())
412static MURN: Jet = |ctx, n| {
371static MURN: Jet = |ctx, n| {
413− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
372+ let (a, b) = n.as_cell()?;
415− Ok(Noun::list_refs(
374+ Some(Noun::list_refs(
416− traverse_iter_result(
417− a.list_iter()
375+ a.list_iter()
418− .map(|n| Ok(slam_pulled_gate(ctx, b, n)?.as_unit().cloned())),
376+ .filter_map(|n| slam(ctx, b.clone(), n)?.as_unit())
419− )?
377+ .collect::<Vec<_>>()
421− .filter_map(|x| x.clone()),
379+ .map(|x| x.clone()),
425static REAP: Jet = |_ctx, n| {
383static REAP: Jet = |_ctx, n| {
426− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
384+ let (a, b) = n.as_cell()?;
428− Ok(Noun::list_refs(repeat_n(
386+ Some(Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize)))
430− a.as_u32().unwrap() as usize,
434−static REAR: Jet = |_ctx, n| n.list_iter().last().ok_or(TTanks::new()).cloned();
389+static REAR: Jet = |_ctx, n| n.list_iter().last();
436static REEL: Jet = |ctx, n| {
391static REEL: Jet = |ctx, n| {
437− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
392+ let (list, gate) = n.as_cell()?;
439 list.list_iter().collect::<Vec<_>>().iter().rfold(
394 list.list_iter().collect::<Vec<_>>().iter().rfold(
441− .gate_sample()
395+ Some(gate.clone().gate_sample()?.as_cell()?.1),
442− .ok_or(TTanks::new())?
444− .ok_or(TTanks::new())?
449− slam_pulled_gate(ctx, gate, &cell(&next, &acc))
396+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
454static ROLL: Jet = |ctx, n| {
400static ROLL: Jet = |ctx, n| {
455− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
401+ let (list, gate) = n.as_cell()?;
457 list.list_iter().fold(
403 list.list_iter().fold(
460− .gate_sample()
404+ Some(gate.clone().gate_sample()?.as_cell()?.1),
461− .ok_or(TTanks::new())?
463− .ok_or(TTanks::new())?
468− slam_pulled_gate(ctx, gate, &cell(&next, &acc))
405+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
473static SCAG: Jet = |_ctx, n| {
409static SCAG: Jet = |_ctx, n| {
474− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
410+ let (a, b) = n.as_cell()?;
476− Ok(Noun::list_refs(
412+ Some(Noun::list_refs(
477 b.list_iter()
413 b.list_iter()
478 .take(a.as_u32().unwrap() as usize)
414 .take(a.as_u32().unwrap() as usize)
479 .collect::<Vec<_>>()
415 .collect::<Vec<_>>()
481− .cloned()
417+ .map(|x| x.clone()),
486static SKID: Jet = |ctx, n| {
421static SKID: Jet = |ctx, n| {
487− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
422+ let (list, gate) = n.as_cell()?;
489− let slammed_n = traverse_iter_result(
424+ let slammed_n = traverse_iter_option(
490 list.list_iter()
425 list.list_iter()
491− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
426+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
493 let (ys, ns): (Vec<_>, _) = slammed_n.iter().partition(|(l, _)| l.is_y());
428 let (ys, ns): (Vec<_>, _) = slammed_n.iter().partition(|(l, _)| l.is_y());
495− Ok(cell(
430+ Some(cell(
496− &Noun::list_refs(ys.iter().map(|(_, x)| (*x).clone())),
431+ Noun::list_refs(ys.iter().map(|(_, x)| x).cloned()),
497− &Noun::list_refs(ns.iter().map(|(_, x)| (*x).clone())),
432+ Noun::list_refs(ns.iter().map(|(_, x)| x).cloned()),
501static SKIM: Jet = |ctx, n| {
436static SKIM: Jet = |ctx, n| {
502− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
437+ let (list, gate) = n.as_cell()?;
504− Ok(Noun::list_refs(
439+ Some(Noun::list_refs(
505− traverse_iter_result(
440+ traverse_iter_option(
506 list.list_iter()
441 list.list_iter()
507− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
442+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
510 .filter(|(l, _)| l.is_y())
445 .filter(|(l, _)| l.is_y())
511− .map(|(_, x)| (*x).clone()),
446+ .map(|(_, x)| x)
515static SKIP: Jet = |ctx, n| {
451static SKIP: Jet = |ctx, n| {
516− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
452+ let (list, gate) = n.as_cell()?;
518− Ok(Noun::list_refs(
454+ Some(Noun::list_refs(
519− traverse_iter_result(
455+ traverse_iter_option(
520 list.list_iter()
456 list.list_iter()
521− .map(|n| Ok((slam_pulled_gate(ctx, gate, n)?, n))),
457+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
524 .filter(|(l, _)| l.is_y())
460 .filter(|(l, _)| l.is_y())
525− .map(|(_, x)| (*x).clone()),
461+ .map(|(_, x)| x)
529static SLAG: Jet = |ctx, n| {
466static SLAG: Jet = |ctx, n| {
530− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
467+ let (a, list) = n.as_cell()?;
532− let mut a_iter = a.as_atom().ok_or(TTanks::new())?.iter_u32_digits();
469+ let mut a_iter = a.as_atom()?.iter_u32_digits();
534 match a_iter.len() {
471 match a_iter.len() {
535− 0 => Ok(list.clone()),
472+ 0 => Some(list),
536− 1 => Ok(Noun::list_refs(
473+ 1 => Some(Noun::list_refs(
537 list.list_iter()
474 list.list_iter()
538 .skip(a_iter.next().unwrap() as usize)
475 .skip(a_iter.next().unwrap() as usize)
539 .collect::<Vec<_>>()
476 .collect::<Vec<_>>()
542 .cloned(),
478 .cloned(),
544− _ => Ok(ctx.nouns.sig.clone()),
480+ _ => Some(ctx.nouns.sig.clone()),
548static SNAG: Jet = |_ctx, n| {
484static SNAG: Jet = |_ctx, n| {
549− let (a, list) = n.as_cell().ok_or(TTanks::new())?;
485+ let (a, list) = n.as_cell()?;
552− .nth(a.as_u32().unwrap() as usize)
487+ list.list_iter().nth(a.as_u32().unwrap() as usize)
554− .ok_or(TTanks::new())
557static SNIP: Jet = |_ctx, n| {
490static SNIP: Jet = |_ctx, n| {
558− Ok(Noun::list_refs(
491+ Some(Noun::list_refs(
559 n.list_iter()
492 n.list_iter()
560 .collect::<Vec<_>>()
493 .collect::<Vec<_>>()
566 .cloned(),
498 .cloned(),
570static SNOC: Jet = |_ctx, n| {
502static SNOC: Jet = |_ctx, n| {
571− let (list, b) = n.as_cell().ok_or(TTanks::new())?;
503+ let (list, b) = n.as_cell()?;
573− Ok(Noun::list_refs(
505+ Some(Noun::list_refs(
574 list.list_iter()
506 list.list_iter()
575 .chain(once(b))
507 .chain(once(b))
576 .collect::<Vec<_>>()
508 .collect::<Vec<_>>()
579 .cloned(),
510 .cloned(),
@@ -599,62 +530,52 @@ static SNOC: Jet = |_ctx, n| {
601static SPIN: Jet = |ctx, n| {
532static SPIN: Jet = |ctx, n| {
602− let (list, b) = n.as_cell().ok_or(TTanks::new())?;
533+ let (list, b) = n.as_cell()?;
603− let (acc, gate) = b.as_cell().ok_or(TTanks::new())?;
534+ let (mut acc, gate) = b.as_cell()?;
605 let mut res = Vec::new();
536 let mut res = Vec::new();
606− let mut acc = acc.clone();
608 for n in list.list_iter() {
538 for n in list.list_iter() {
609− let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
539+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell()?;
610− let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
611− acc = new_acc.clone();
540+ acc = new_acc;
612− res.push(el.clone());
541+ res.push(el);
615− Ok(cell(&Noun::list_refs(res.iter().cloned()), &acc))
544+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
618static SPUN: Jet = |ctx, n| {
547static SPUN: Jet = |ctx, n| {
619− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
548+ let (list, gate) = n.as_cell()?;
621 let mut res = Vec::new();
550 let mut res = Vec::new();
622− let mut acc = gate
551+ let mut acc = gate.clone().gate_sample()?.as_cell()?.1;
624− .ok_or(TTanks::new())?
626− .ok_or(TTanks::new())?
630 for n in list.list_iter() {
553 for n in list.list_iter() {
631− let foo = slam_pulled_gate(ctx, gate, &cell(&n, &acc))?;
554+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell()?;
632− let (el, new_acc) = foo.as_cell().ok_or(TTanks::new())?;
633− acc = new_acc.clone();
555+ acc = new_acc;
634− res.push(el.clone());
556+ res.push(el);
637− Ok(cell(&Noun::list_refs(res.iter().cloned()), &acc))
559+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
640static TURN: Jet = |ctx, n| {
562static TURN: Jet = |ctx, n| {
641− let (list, gate) = n.as_cell().ok_or(TTanks::new())?;
563+ let (list, gate) = n.as_cell()?;
642− Ok(Noun::list_refs(
564+ Some(Noun::list_refs(
643− traverse_iter_result(list.list_iter().map(|x| slam_pulled_gate(ctx, gate, x)))?
565+ traverse_iter_option(list.list_iter().map(|x| slam(ctx, gate.clone(), x)))?
645 .cloned(),
567 .cloned(),
649static WELD: Jet = |_ctx, n| {
571static WELD: Jet = |_ctx, n| {
650− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
572+ let (a, b) = n.as_cell()?;
652− Ok(Noun::list_refs(
574+ Some(Noun::list_refs(
653 a.list_iter()
575 a.list_iter()
654 .chain(b.list_iter())
576 .chain(b.list_iter())
655 .collect::<Vec<_>>()
577 .collect::<Vec<_>>()
658 .cloned(),
579 .cloned(),
@@ -662,38 +583,35 @@ static WELD: Jet = |_ctx, n| {
662static WELP: Jet = WELD;
583static WELP: Jet = WELD;
664static ZING: Jet = |_ctx, n| {
585static ZING: Jet = |_ctx, n| {
665− Ok(Noun::list_refs(
586+ Some(Noun::list_refs(
666 n.list_iter()
587 n.list_iter()
667 .map(|l| l.list_iter())
588 .map(|l| l.list_iter())
668 .flatten()
589 .flatten()
669 .collect::<Vec<_>>()
590 .collect::<Vec<_>>()
672 .cloned(),
592 .cloned(),
676static BEX: Jet = |ctx, n| {
596static BEX: Jet = |ctx, n| {
677− Ok(Rc::new(Noun::Atom(
597+ Some(Rc::new(Noun::Atom(
678 &ctx.big_uints.one << n.as_u32().unwrap(),
598 &ctx.big_uints.one << n.as_u32().unwrap(),
682static END: Jet = |ctx, n| {
602static END: Jet = |ctx, n| {
683− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
603+ let (a, b) = n.as_cell()?;
684 let bite = a.as_bite();
604 let bite = a.as_bite();
686 let bits = bite.bits();
606 let bits = bite.bits();
688 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
608 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
690− Ok(Rc::new(Noun::Atom(
610+ Some(Rc::new(Noun::Atom(mask & b.as_atom()?)))
691− mask & b.as_atom().ok_or(TTanks::new())?,
695static CAN: Jet = |ctx, n| {
613static CAN: Jet = |ctx, n| {
696− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
614+ let (a, b) = n.as_cell()?;
697 let bloq = a.as_u32().unwrap();
615 let bloq = a.as_u32().unwrap();
698 let bloq_ = 2u32.pow(bloq);
616 let bloq_ = 2u32.pow(bloq);
@@ -708,57 +626,66 @@ static CAN: Jet = |ctx, n| {
708 Some((acc? << bits) | (mask & q.as_atom()?))
626 Some((acc? << bits) | (mask & q.as_atom()?))
711− Ok(Rc::new(Noun::Atom(atom.ok_or(TTanks::new())?)))
629+ Some(Rc::new(Noun::Atom(atom?)))
714static CAT: Jet = |_ctx, n| {
632static CAT: Jet = |_ctx, n| {
715− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
633+ let (bloq, b) = n.as_cell()?;
716− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
634+ let (b, c) = b.as_cell()?;
718− let bloq = bloq.as_u32().ok_or(TTanks::new())?;
636+ let bloq = bloq.as_u32()?;
719− let b = b.as_atom().ok_or(TTanks::new())?;
637+ let b = b.as_atom()?;
720− let c = c.as_atom().ok_or(TTanks::new())?;
638+ let c = c.as_atom()?;
722− Ok(Rc::new(Noun::Atom(
640+ Some(Rc::new(Noun::Atom(
723− (c << (met(bloq, &b) * 2u32.pow(bloq))) | b,
641+ (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
727static MET: Jet = |_ctx, n| {
645static MET: Jet = |_ctx, n| {
728− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
646+ let (bloq, b) = n.as_cell()?;
729− let b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
647+ let b: Atom = b.as_atom()?.clone();
730 let bloq = bloq.as_u32().unwrap();
648 let bloq = bloq.as_u32().unwrap();
732− Ok(Rc::new(Noun::from_u32(met(bloq, &b))))
650+ Some(Rc::new(Noun::from_u32(met(bloq, b))))
735−fn met(bloq: u32, a: &Atom) -> u32 {
653+fn met(bloq: u32, mut a: Atom) -> u32 {
736− (a.bits() as u32).div_ceil(2u32.pow(bloq))
654+ let bits = 2u32.pow(bloq);
658+ while a > Atom::ZERO {
739static CUT: Jet = |ctx, n| {
666static CUT: Jet = |ctx, n| {
740− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
667+ let (a, b) = n.as_cell()?;
741− let (b, d) = b.as_cell().ok_or(TTanks::new())?;
668+ let (b, d) = b.as_cell()?;
742− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
669+ let (b, c) = b.as_cell()?;
744 let bits = 2u32.pow(a.as_u32().unwrap());
671 let bits = 2u32.pow(a.as_u32().unwrap());
746 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
673 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
748− Ok(Rc::new(Noun::Atom(
675+ Some(Rc::new(Noun::Atom(
749− (d.as_atom().ok_or(TTanks::new())? >> (bits * b.as_u32().unwrap())) & mask,
676+ (d.as_atom()? >> (bits * b.as_u32().unwrap())) & mask,
753static FIL: Jet = |ctx, n| {
680static FIL: Jet = |ctx, n| {
754− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
681+ let (a, b) = n.as_cell()?;
755− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
682+ let (b, c) = b.as_cell()?;
757 let bits = 2u32.pow(a.as_u32().unwrap());
684 let bits = 2u32.pow(a.as_u32().unwrap());
759 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
686 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
761− let src = c.as_atom().ok_or(TTanks::new())? & mask;
688+ let src = c.as_atom()? & mask;
763 let mut target = ctx.big_uints.zero.clone();
690 let mut target = ctx.big_uints.zero.clone();
@@ -766,44 +693,44 @@ static FIL: Jet = |ctx, n| {
766 target = (target << bits) | &src;
693 target = (target << bits) | &src;
769− Ok(Rc::new(Noun::Atom(target)))
696+ Some(Rc::new(Noun::Atom(target)))
772static LSH: Jet = |_ctx, n| {
699static LSH: Jet = |_ctx, n| {
773− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
700+ let (a, b) = n.as_cell()?;
774 let a = a.as_bite();
701 let a = a.as_bite();
775− let b = b.as_atom().ok_or(TTanks::new())?;
702+ let b = b.as_atom()?;
777− Ok(Rc::new(Noun::Atom(b << a.bits())))
704+ Some(Rc::new(Noun::Atom(b << a.bits())))
780static RSH: Jet = |_ctx, n| {
707static RSH: Jet = |_ctx, n| {
781− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
708+ let (a, b) = n.as_cell()?;
782 let a = a.as_bite();
709 let a = a.as_bite();
783− let b = b.as_atom().ok_or(TTanks::new())?;
710+ let b = b.as_atom()?;
785− Ok(Rc::new(Noun::Atom(b >> a.bits())))
712+ Some(Rc::new(Noun::Atom(b >> a.bits())))
788−pub static RAP: Jet = |ctx, n| {
715+static RAP: Jet = |ctx, n| {
789− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
716+ let (bloq, b) = n.as_cell()?;
790 let bloq = bloq.as_u32().unwrap();
717 let bloq = bloq.as_u32().unwrap();
791 let bits = 2u32.pow(bloq);
718 let bits = 2u32.pow(bloq);
793 let mut target = ctx.big_uints.zero.clone();
720 let mut target = ctx.big_uints.zero.clone();
795 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
722 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
796− let el = el.as_atom().ok_or(TTanks::new())?;
723+ let el = el.as_atom()?;
797 if el != &ctx.big_uints.zero {
724 if el != &ctx.big_uints.zero {
798− target = (target << (bits * met(bloq, &el))) | el;
725+ target = (target << (bits * met(bloq, el.clone()))) | el;
802− Ok(Rc::new(Noun::Atom(target)))
729+ Some(Rc::new(Noun::Atom(target)))
805static REP: Jet = |ctx, n| {
732static REP: Jet = |ctx, n| {
806− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
733+ let (bite, b) = n.as_cell()?;
807 let bite = bite.as_bite();
734 let bite = bite.as_bite();
809 let bits = bite.bits();
736 let bits = bite.bits();
@@ -812,18 +739,18 @@ static REP: Jet = |ctx, n| {
812 let mut target = ctx.big_uints.zero.clone();
739 let mut target = ctx.big_uints.zero.clone();
814 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
741 for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
815− target = (target << bits) | (el.as_atom().ok_or(TTanks::new())? & &mask);
742+ target = (target << bits) | (el.as_atom()? & &mask);
818− Ok(Rc::new(Noun::Atom(target)))
745+ Some(Rc::new(Noun::Atom(target)))
821static REV: Jet = |ctx, n| {
748static REV: Jet = |ctx, n| {
822− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
749+ let (bloq, b) = n.as_cell()?;
823− let (len, dat) = b.as_cell().ok_or(TTanks::new())?;
750+ let (len, dat) = b.as_cell()?;
824 let bloq = bloq.as_u32().unwrap();
751 let bloq = bloq.as_u32().unwrap();
825 let len = len.as_u32().unwrap();
752 let len = len.as_u32().unwrap();
826− let mut dat: Atom = dat.as_atom().ok_or(TTanks::new())?.clone();
753+ let mut dat: Atom = dat.as_atom()?.clone();
828 let bits = 2u32.pow(bloq);
755 let bits = 2u32.pow(bloq);
829 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
756 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -835,13 +762,13 @@ static REV: Jet = |ctx, n| {
835 dat = dat >> bits;
762 dat = dat >> bits;
838− Ok(Rc::new(Noun::Atom(target)))
765+ Some(Rc::new(Noun::Atom(target)))
841static RIP: Jet = |ctx, n| {
768static RIP: Jet = |ctx, n| {
842− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
769+ let (bite, b) = n.as_cell()?;
843 let bite = bite.as_bite();
770 let bite = bite.as_bite();
844− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
771+ let mut b: Atom = b.as_atom()?.clone();
846 let bits = bite.bits();
773 let bits = bite.bits();
847 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
774 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -853,15 +780,15 @@ static RIP: Jet = |ctx, n| {
853 b = b >> bits;
780 b = b >> bits;
856− Ok(Noun::list_refs(target.iter().cloned()))
783+ Some(Noun::list_refs(target.iter().cloned()))
859static RUN: Jet = |ctx, n| {
786static RUN: Jet = |ctx, n| {
860− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
787+ let (bite, b) = n.as_cell()?;
861− let (b, gate) = b.as_cell().ok_or(TTanks::new())?;
788+ let (b, gate) = b.as_cell()?;
863 let bite = bite.as_bite();
790 let bite = bite.as_bite();
864− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
791+ let mut b: Atom = b.as_atom()?.clone();
866 let bits = bite.bits();
793 let bits = bite.bits();
867 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
794 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -870,22 +797,19 @@ static RUN: Jet = |ctx, n| {
871 while b > ctx.big_uints.zero {
798 while b > ctx.big_uints.zero {
872 target = (target << bits)
799 target = (target << bits)
873− | ((*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
800+ | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?).as_atom()? & &mask);
875− .ok_or(TTanks::new())?
877 b = b >> bits;
801 b = b >> bits;
880− Ok(Rc::new(Noun::Atom(target)))
804+ Some(Rc::new(Noun::Atom(target)))
883static RUT: Jet = |ctx, n| {
807static RUT: Jet = |ctx, n| {
884− let (bite, b) = n.as_cell().ok_or(TTanks::new())?;
808+ let (bite, b) = n.as_cell()?;
885− let (b, gate) = b.as_cell().ok_or(TTanks::new())?;
809+ let (b, gate) = b.as_cell()?;
887 let bite = bite.as_bite();
811 let bite = bite.as_bite();
888− let mut b: Atom = b.as_atom().ok_or(TTanks::new())?.clone();
812+ let mut b: Atom = b.as_atom()?.clone();
890 let bits = bite.bits();
814 let bits = bite.bits();
891 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
815 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
@@ -893,25 +817,21 @@ static RUT: Jet = |ctx, n| {
893 let mut target = Vec::new();
817 let mut target = Vec::new();
895 while b > ctx.big_uints.zero {
819 while b > ctx.big_uints.zero {
896− target.push(
820+ target
897− (*slam_pulled_gate(ctx, gate, &Rc::new(Noun::Atom(&mask & &b)))?)
821+ .push((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?).as_atom()? & &mask);
899− .ok_or(TTanks::new())?
902 b = b >> bits;
822 b = b >> bits;
905− Ok(Noun::list(target.iter().cloned().map(Noun::Atom)))
825+ Some(Noun::list(target.iter().cloned().map(Noun::Atom)))
908static SEW: Jet = |ctx, n| {
828static SEW: Jet = |ctx, n| {
909− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
829+ let (a, b) = n.as_cell()?;
910− let (b, recipient) = b.as_cell().ok_or(TTanks::new())?;
830+ let (b, recipient) = b.as_cell()?;
911− let (sew_start, c) = b.as_cell().ok_or(TTanks::new())?;
831+ let (sew_start, c) = b.as_cell()?;
912− let (number_of_blocks, donor) = c.as_cell().ok_or(TTanks::new())?;
832+ let (number_of_blocks, donor) = c.as_cell()?;
913− let recipient = recipient.as_atom().ok_or(TTanks::new())?;
833+ let recipient = recipient.as_atom()?;
914− let donor = donor.as_atom().ok_or(TTanks::new())?;
834+ let donor = donor.as_atom()?;
916 let bloq = a.as_u32().unwrap();
836 let bloq = a.as_u32().unwrap();
917 let bits = 2u32.pow(bloq);
837 let bits = 2u32.pow(bloq);
@@ -923,16 +843,16 @@ static SEW: Jet = |ctx, n| {
924 let target = (recipient ^ apendix) | (donor & mask);
844 let target = (recipient ^ apendix) | (donor & mask);
926− Ok(Rc::new(Noun::Atom(target)))
846+ Some(Rc::new(Noun::Atom(target)))
929static SWP: Jet = |ctx, n| {
849static SWP: Jet = |ctx, n| {
930− let (bloq, b) = n.as_cell().ok_or(TTanks::new())?;
850+ let (bloq, b) = n.as_cell()?;
931 let bloq = bloq.as_u32().unwrap();
851 let bloq = bloq.as_u32().unwrap();
932 let bits = 2u32.pow(bloq);
852 let bits = 2u32.pow(bloq);
933 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
853 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
935− let mut source = b.as_atom().ok_or(TTanks::new())?.clone();
855+ let mut source = b.as_atom()?.clone();
936 let mut target = ctx.big_uints.zero.clone();
856 let mut target = ctx.big_uints.zero.clone();
938 while source > ctx.big_uints.zero {
858 while source > ctx.big_uints.zero {
@@ -940,11 +860,11 @@ static SWP: Jet = |ctx, n| {
940 source = source >> bits;
860 source = source >> bits;
943− Ok(Rc::new(Noun::Atom(target)))
863+ Some(Rc::new(Noun::Atom(target)))
946static XEB: Jet = |_ctx, n| {
866static XEB: Jet = |_ctx, n| {
947− let mut a = n.as_atom().ok_or(TTanks::new())?.clone();
867+ let mut a = n.as_atom()?.clone();
949 let mut c = 0;
869 let mut c = 0;
@@ -953,7 +873,7 @@ static XEB: Jet = |_ctx, n| {
956− Ok(Rc::new(Noun::from_u32(c)))
876+ Some(Rc::new(Noun::from_u32(c)))
959static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
879static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
@@ -961,310 +881,14 @@ static DIS: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a & b);
961static MIX: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a ^ b);
881static MIX: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a ^ b);
963static NOT: Jet = |ctx, n| {
883static NOT: Jet = |ctx, n| {
964− let (a, b) = n.as_cell().ok_or(TTanks::new())?;
884+ let (a, b) = n.as_cell()?;
965− let (b, c) = b.as_cell().ok_or(TTanks::new())?;
885+ let (b, c) = b.as_cell()?;
967 let bloq = a.as_u32().unwrap();
887 let bloq = a.as_u32().unwrap();
968 let bits = 2u32.pow(bloq);
888 let bits = 2u32.pow(bloq);
969 let mask = (&ctx.big_uints.one << (bits * b.as_u32().unwrap())) - &ctx.big_uints.one;
889 let mask = (&ctx.big_uints.one << (bits * b.as_u32().unwrap())) - &ctx.big_uints.one;
971− let target = c.as_atom().ok_or(TTanks::new())? ^ &mask;
891+ let target = c.as_atom()? ^ &mask;
973− Ok(Rc::new(Noun::Atom(target)))
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)))
983−fn last<'a>(a: &'a Hair, b: &'a Hair) -> &'a Hair {
984− if a.line == b.line {
985− if a.column > b.column {
991− if a.line > b.line {
999−static TRIP: Jet = |_ctx, n| {
1000− let a = n.as_atom().ok_or(TTanks::new())?;
1002− a.to_bytes_le().iter().map(|b| Noun::from_u32(*b as u32)),
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())?;
1013− Ok(Rc::new(Noun::from_u32(muk(seed, len, key))))
1016−static AOR: Jet = |ctx, n| {
1017− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1020− Ok(ctx.nouns.y.clone())
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, .. }) => {
1026− AOR(ctx, &cell(a_q, b_q))
1028− AOR(ctx, &cell(a_p, b_p))
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();
1038− let c = a.get(i).unwrap_or(&0);
1039− let d = b.get(i).unwrap_or(&0);
1045− return Ok(ctx.nouns.y.clone());
1047− return Ok(ctx.nouns.n.clone());
1056−static DOR: Jet = |ctx, n| {
1057− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1060− Ok(ctx.nouns.y.clone())
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, .. }) => {
1066− DOR(ctx, &cell(a_q, b_q))
1068− DOR(ctx, &cell(a_p, b_p))
1071− (Noun::Atom(_), Noun::Cell { .. }) => Ok(ctx.nouns.y.clone()),
1072− (Noun::Atom(a), Noun::Atom(b)) => {
1074− Ok(ctx.nouns.y.clone())
1076− Ok(ctx.nouns.n.clone())
1083−static GOR: Jet = |ctx, n| {
1084− let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1092− Ok(ctx.nouns.y.clone())
1094− Ok(ctx.nouns.n.clone())
1099−static GOR_PAIR: fn(&mut InterpreterContext, &Rc<Noun>, &Rc<Noun>) -> Result<bool, TTanks> =
1105− Ok(DOR(ctx, &(a.clone(), b.clone()).as_noun())? == ctx.nouns.y)
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();
1120− Ok(ctx.nouns.y.clone())
1122− Ok(ctx.nouns.n.clone())
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)
1132−static LOOK_PAIR: fn(
1133− &mut InterpreterContext,
1137−) -> Result<Rc<Noun>, TTanks> = |ctx, axe, cog, dab| {
1139− Ok(ctx.nouns.sig.clone())
1141− let (node, b, c) = dab.tuple_3().ok_or(EMPTY_TANKS)?;
1144− let (p, q) = node.as_cell().ok_or(EMPTY_TANKS)?;
1145− if b.is_sig() && c.is_sig() {
1147− Ok((ctx.nouns.sig.clone(), Noun::Atom(axe), q.clone()).as_noun())
1149− Ok(ctx.nouns.sig.clone())
1151− } else if b.is_sig() {
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())
1157− LOOK_PAIR(ctx, PEG_U32(&axe, 3), cog, r)
1159− } else if c.is_sig() {
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)
1165− Ok(ctx.nouns.sig.clone())
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)
1173− LOOK_PAIR(ctx, PEG_U32(&axe, 7), cog, r)
1179−static JUST: DoubleJet = |ctx, n, m| {
893+ Some(Rc::new(Noun::Atom(target)))
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())
1185− let (i, _) = nail.rest.as_cell()?;
1186− let i = i.as_atom()?;
1188− Some(next(nail)?.as_noun())
1190− Some(fail(nail).as_noun())
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()?;
1200−// let mut lef = Vec::new();
1201−// let mut vex = slam(ctx, fel, tub)?.as;
1205−fn next<'a>(nail: Nail<'a>) -> Option<Edge<'a>> {
1206− if **nail.rest == Noun::SIG {
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))))
1214− result: Some((i, Nail { hair: zac, rest: t })),
1219−fn lust(char: Atom, hair: Hair) -> Hair {
1220− if char == Atom::from_slice(&vec![10]) {
1222− line: hair.line + 1,
1228− column: hair.column + 1,
1233−fn fail(nail: Nail) -> Edge {
1240−const MUG: Jet = |__ctx, n| Ok(Rc::new(Noun::from_u32(n.mug())));
1242−pub fn mum(syd: u32, fal: u32, key: &Atom) -> u32 {
1243− let wyd = met(3, &key);
1249− let haz = muk(syd, wyd, &key);
1250− let ham = (haz >> 31) ^ (haz & !(1 << 31));
1261−fn muk(seed: u32, len: u32, key: &Atom) -> u32 {
1262− let key: Vec<_> = key
1265− .take(len as usize)
1269− murmur3_32(&mut &*key, seed).unwrap()