on master help sign in
initial optionification
bd361abiko
nock/src/interpreter.rs+58−60
@@ -1,4 +1,3 @@
1−use core::panic;
2use std::rc::Rc;
1use std::rc::Rc;
3
2
4use num_bigint::BigUint;
3use num_bigint::BigUint;
@@ -72,10 +71,10 @@ fn wut(ctx: &InterpreterContext, noun: Rc<Noun>) -> Rc<Noun> {
72 }
71 }
73}
72}
74
73
75−fn lus(noun: Rc<Noun>) -> Noun {
74+fn lus(noun: Rc<Noun>) -> Option<Noun> {
76 match (*noun).clone() {
75 match (*noun).clone() {
77− Noun::Cell { .. } => panic!(),
76+ Noun::Cell { .. } => None,
78− Noun::Atom(atm) => Noun::Atom(atm + 1u32),
77+ Noun::Atom(atm) => Some(Noun::Atom(atm + 1u32)),
79 }
78 }
80}
79}
81
80
@@ -87,37 +86,37 @@ fn tis(ctx: &InterpreterContext, lhs: Rc<Noun>, rhs: Rc<Noun>) -> Rc<Noun> {
87 }
86 }
88}
87}
89
88
90−fn fas(ctx: &InterpreterContext, addr: Atom, noun: Rc<Noun>) -> Rc<Noun> {
89+fn fas(ctx: &InterpreterContext, addr: Atom, noun: Rc<Noun>) -> Option<Rc<Noun>> {
91 let mut addr_iter = addr.iter_u32_digits();
90 let mut addr_iter = addr.iter_u32_digits();
92
91
93 match addr_iter.len() {
92 match addr_iter.len() {
94 0 => panic!(),
93 0 => panic!(),
95− 1 => fas_u32(addr_iter.next().unwrap(), noun),
94+ 1 => Some(fas_u32(addr_iter.next()?, noun)?),
96 _ => {
95 _ => {
97− let rest = fas(ctx, &addr >> 1, noun);
96+ let rest = fas(ctx, &addr >> 1, noun)?;
98− fas_u32(
97+ Some(fas_u32(
99 if (addr & &ctx.big_uints.one) == ctx.big_uints.one {
98 if (addr & &ctx.big_uints.one) == ctx.big_uints.one {
100 3
99 3
101 } else {
100 } else {
102 2
101 2
103 },
102 },
104 rest,
103 rest,
105− )
104+ )?)
106 }
105 }
107 }
106 }
108}
107}
109
108
110−fn fas_u32(addr: u32, noun: Rc<Noun>) -> Rc<Noun> {
109+fn fas_u32(addr: u32, noun: Rc<Noun>) -> Option<Rc<Noun>> {
111 match addr {
110 match addr {
112− 0 => panic!(),
111+ 0 => None,
113− 1 => noun,
112+ 1 => Some(noun),
114 n => match (*noun).clone() {
113 n => match (*noun).clone() {
115− Noun::Atom(_) => panic!(),
114+ Noun::Atom(_) => None,
116 Noun::Cell { p, q, .. } => match n {
115 Noun::Cell { p, q, .. } => match n {
117− 2 => p,
116+ 2 => Some(p),
118− 3 => q,
117+ 3 => Some(q),
119 _ => {
118 _ => {
120− let rest = fas_u32(n >> 1, cell(p, q));
119+ let rest = fas_u32(n >> 1, cell(p, q))?;
121 fas_u32(if (n & 1) == 1 { 3 } else { 2 }, rest)
120 fas_u32(if (n & 1) == 1 { 3 } else { 2 }, rest)
122 }
121 }
123 },
122 },
@@ -125,23 +124,28 @@ fn fas_u32(addr: u32, noun: Rc<Noun>) -> Rc<Noun> {
125 }
124 }
126}
125}
127
126
128−fn hax_u32(addr: u32, new_value: Rc<Noun>, target: Rc<Noun>) -> Rc<Noun> {
127+fn hax_u32(addr: u32, new_value: Rc<Noun>, target: Rc<Noun>) -> Option<Rc<Noun>> {
129 match addr {
128 match addr {
130− 0 => panic!(),
129+ 0 => None,
131− 1 => new_value,
130+ 1 => Some(new_value),
132 _ => hax_u32(
131 _ => hax_u32(
133 addr >> 1,
132 addr >> 1,
134 if (addr & 1) == 1 {
133 if (addr & 1) == 1 {
135− cell(fas_u32(addr - 1, target.clone()), new_value)
134+ cell(fas_u32(addr - 1, target.clone())?, new_value)
136 } else {
135 } else {
137− cell(new_value, fas_u32(addr + 1, target.clone()))
136+ cell(new_value, fas_u32(addr + 1, target.clone())?)
138 },
137 },
139 target,
138 target,
140 ),
139 ),
141 }
140 }
142}
141}
143
142
143+fn hax(
144−fn hax(ctx: &InterpreterContext, addr: Atom, new_value: Rc<Noun>, target: Rc<Noun>) -> Rc<Noun> {
144+ ctx: &InterpreterContext,
145+ addr: Atom,
146+ new_value: Rc<Noun>,
147+ target: Rc<Noun>,
148+) -> Option<Rc<Noun>> {
145 let mut addr_iter = addr.iter_u32_digits();
149 let mut addr_iter = addr.iter_u32_digits();
146
150
147 match addr_iter.len() {
151 match addr_iter.len() {
@@ -152,13 +156,13 @@ fn hax(ctx: &InterpreterContext, addr: Atom, new_value: Rc<Noun>, target: Rc<Nou
152 &addr >> 1u32,
156 &addr >> 1u32,
153 if (&addr & &ctx.big_uints.one) == ctx.big_uints.one {
157 if (&addr & &ctx.big_uints.one) == ctx.big_uints.one {
154 cell(
158 cell(
155− fas(ctx, addr - &ctx.big_uints.one, target.clone()),
159+ fas(ctx, addr - &ctx.big_uints.one, target.clone())?,
156 new_value,
160 new_value,
157 )
161 )
158 } else {
162 } else {
159 cell(
163 cell(
160 new_value,
164 new_value,
161− fas(ctx, addr + &ctx.big_uints.one, target.clone()),
165+ fas(ctx, addr + &ctx.big_uints.one, target.clone())?,
162 )
166 )
163 },
167 },
164 target,
168 target,
@@ -166,15 +170,18 @@ fn hax(ctx: &InterpreterContext, addr: Atom, new_value: Rc<Noun>, target: Rc<Nou
166 }
170 }
167}
171}
168
172
173+fn tar_u32(
169−fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>) -> Rc<Noun> {
174+ ctx: &InterpreterContext,
175+ subj: Rc<Noun>,
176+ op: u32,
177+ formula: Rc<Noun>,
178+) -> Option<Rc<Noun>> {
170 match op {
179 match op {
171 0 => {
180 0 => {
172− let Noun::Atom(b) = (*formula).clone() else {
181+ let b = formula.as_atom()?.clone();
173− panic!()
174− };
175 fas(ctx, b, subj)
182 fas(ctx, b, subj)
176 }
183 }
177− 1 => formula,
184+ 1 => Some(formula),
178 2 => {
185 2 => {
179 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
186 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
180 panic!()
187 panic!()
@@ -194,27 +201,23 @@ fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>)
194 println!("Evaluating jet {}", hash);
201 println!("Evaluating jet {}", hash);
195 f(ctx, sample)
202 f(ctx, sample)
196 }
203 }
197− None => tar(ctx, tar(ctx, subj.clone(), b), tar(ctx, subj, c)),
204+ None => tar(ctx, tar(ctx, subj.clone(), b)?, tar(ctx, subj, c)?),
198 }
205 }
199 }
206 }
200− _ => tar(ctx, tar(ctx, subj.clone(), b), tar(ctx, subj, c)),
207+ _ => tar(ctx, tar(ctx, subj.clone(), b)?, tar(ctx, subj, c)?),
201 }
208 }
202 }
209 }
203− 3 => wut(ctx, tar(ctx, subj, formula)),
210+ 3 => Some(wut(ctx, tar(ctx, subj, formula)?)),
204− 4 => Rc::new(lus(tar(ctx, subj, formula))),
211+ 4 => Some(Rc::new(lus(tar(ctx, subj, formula)?)?)),
205 5 => {
212 5 => {
206 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
213 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
207 panic!()
214 panic!()
208 };
215 };
209− tis(ctx, tar(ctx, subj.clone(), b), tar(ctx, subj, c))
216+ Some(tis(ctx, tar(ctx, subj.clone(), b)?, tar(ctx, subj, c)?))
210 }
217 }
211 6 => {
218 6 => {
212− let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
219+ let (b, c) = formula.as_cell()?;
213− panic!()
220+ let (c, d) = c.as_cell()?;
214− };
215− let Noun::Cell { p: c, q: d, .. } = (*c).clone() else {
216− panic!()
217− };
218
221
219 tar(
222 tar(
220 ctx,
223 ctx,
@@ -227,22 +230,22 @@ fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>)
227 ctx,
230 ctx,
228 ctx.nouns.two_three.clone(),
231 ctx.nouns.two_three.clone(),
229 0,
232 0,
230− tar_u32(ctx, subj, 4, cell(ctx.nouns.four.clone(), b)),
233+ tar_u32(ctx, subj, 4, cell(ctx.nouns.four.clone(), b))?,
231− ),
234+ )?,
232− ),
235+ )?,
233 )
236 )
234 }
237 }
235 7 => {
238 7 => {
236 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
239 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
237 panic!()
240 panic!()
238 };
241 };
239− tar(ctx, tar(ctx, subj, b), c)
242+ tar(ctx, tar(ctx, subj, b)?, c)
240 }
243 }
241 8 => {
244 8 => {
242 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
245 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
243 panic!()
246 panic!()
244 };
247 };
245− tar(ctx, cell(tar(ctx, subj.clone(), b), subj), c)
248+ tar(ctx, cell(tar(ctx, subj.clone(), b)?, subj), c)
246 }
249 }
247 9 => {
250 9 => {
248 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
251 let Noun::Cell { p: b, q: c, .. } = (*formula).clone() else {
@@ -250,7 +253,7 @@ fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>)
250 };
253 };
251 tar_u32(
254 tar_u32(
252 ctx,
255 ctx,
253− tar(ctx, subj, c),
256+ tar(ctx, subj, c)?,
254 2,
257 2,
255 cell(ctx.nouns.sig_one.clone(), cell(ctx.nouns.sig.clone(), b)),
258 cell(ctx.nouns.sig_one.clone(), cell(ctx.nouns.sig.clone(), b)),
256 )
259 )
@@ -266,7 +269,7 @@ fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>)
266 panic!()
269 panic!()
267 };
270 };
268
271
269− hax(ctx, b, tar(ctx, subj.clone(), c), tar(ctx, subj, d))
272+ hax(ctx, b, tar(ctx, subj.clone(), c)?, tar(ctx, subj, d)?)
270 }
273 }
271 11 => {
274 11 => {
272 let Noun::Cell { p: b, q: d, .. } = (*formula).clone() else {
275 let Noun::Cell { p: b, q: d, .. } = (*formula).clone() else {
@@ -276,7 +279,7 @@ fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>)
276 Noun::Atom(_) => tar(ctx, subj, d),
279 Noun::Atom(_) => tar(ctx, subj, d),
277 Noun::Cell { q: c, .. } => tar_u32(
280 Noun::Cell { q: c, .. } => tar_u32(
278 ctx,
281 ctx,
279− cell(tar(ctx, subj.clone(), c), tar(ctx, subj, d)),
282+ cell(tar(ctx, subj.clone(), c)?, tar(ctx, subj, d)?),
280 0,
283 0,
281 ctx.nouns.three.clone(),
284 ctx.nouns.three.clone(),
282 ),
285 ),
@@ -286,16 +289,11 @@ fn tar_u32(ctx: &InterpreterContext, subj: Rc<Noun>, op: u32, formula: Rc<Noun>)
286 }
289 }
287}
290}
288
291
289−pub fn tar(ctx: &InterpreterContext, subj: Rc<Noun>, formula: Rc<Noun>) -> Rc<Noun> {
292+pub fn tar(ctx: &InterpreterContext, subj: Rc<Noun>, formula: Rc<Noun>) -> Option<Rc<Noun>> {
290− let Noun::Cell {
291− p: op, q: formula, ..
293+ let (op, formula) = formula.as_cell()?;
292− } = (*formula).clone()
293− else {
294− panic!()
295− };
296− match (*op).clone() {
294+ match *op {
297− Noun::Cell { .. } => cell(tar(ctx, subj.clone(), op), tar(ctx, subj, formula)),
295+ Noun::Cell { .. } => Some(cell(tar(ctx, subj.clone(), op)?, tar(ctx, subj, formula)?)),
298− Noun::Atom(op) => {
296+ Noun::Atom(ref op) => {
299 let mut op_iter = op.iter_u32_digits();
297 let mut op_iter = op.iter_u32_digits();
300 let op = match op_iter.len() {
298 let op = match op_iter.len() {
301 0 => 0,
299 0 => 0,
@@ -307,7 +305,7 @@ pub fn tar(ctx: &InterpreterContext, subj: Rc<Noun>, formula: Rc<Noun>) -> Rc<No
307 }
305 }
308}
306}
309
307
310−pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Rc<Noun> {
308+pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Option<Rc<Noun>> {
311 tar(
309 tar(
312 ctx,
310 ctx,
313 gate,
311 gate,
@@ -321,7 +319,7 @@ pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Rc<Noun> {
321 )
319 )
322}
320}
323
321
324−pub fn slam(ctx: &InterpreterContext, gate: Rc<Noun>, sample: Rc<Noun>) -> Rc<Noun> {
322+pub fn slam(ctx: &InterpreterContext, gate: Rc<Noun>, sample: Rc<Noun>) -> Option<Rc<Noun>> {
325 let (battery, payload) = gate.as_cell().unwrap();
323 let (battery, payload) = gate.as_cell().unwrap();
326 let (_sample, context) = payload.as_cell().unwrap();
324 let (_sample, context) = payload.as_cell().unwrap();
327
325
nock/src/jets.rs+169−138
@@ -12,6 +12,16 @@ use crate::{
12 noun::{self, cell, Atom, Noun},
12 noun::{self, cell, Atom, Noun},
13};
13};
14
14
15+fn traverse_iter_option<T: Clone, I: Iterator<Item = Option<T>>>(xs: I) -> Option<Vec<T>> {
16+ let mut target: Vec<T> = Vec::new();
17+
18+ for x in xs {
19+ target.push(x.clone()?)
20+ }
21+
22+ Some(target)
23+}
24+
15pub type Jets = BTreeMap<noun::Hash, Jet>;
25pub type Jets = BTreeMap<noun::Hash, Jet>;
16
26
17pub fn generate_jets() -> Jets {
27pub fn generate_jets() -> Jets {
@@ -54,7 +64,7 @@ pub fn generate_jets() -> Jets {
54 (288515703007942177334798811660651439897, SNAG),
64 (288515703007942177334798811660651439897, SNAG),
55 (322006565952434408151902864454572452802, SNIP),
65 (322006565952434408151902864454572452802, SNIP),
56 (290837622185731774795798043954046795930, SNOC),
66 (290837622185731774795798043954046795930, SNOC),
57− (255402796382159268271460433298209603428, SORT),
67+ // (255402796382159268271460433298209603428, SORT),
58 (10111398404342329752608067595798409804, SPIN),
68 (10111398404342329752608067595798409804, SPIN),
59 (209194119090564757355985847956576215234, SPUN),
69 (209194119090564757355985847956576215234, SPUN),
60 (103985097318911737222583881947453560061, TURN),
70 (103985097318911737222583881947453560061, TURN),
@@ -86,35 +96,38 @@ pub fn generate_jets() -> Jets {
86 ])
96 ])
87}
97}
88
98
89−pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Rc<Noun>;
99+pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Option<Rc<Noun>>;
90
100
91−static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Rc<Noun> =
101+static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Option<Rc<Noun>> =
92 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
102 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
93− let (p, q) = n.as_cell().unwrap();
103+ let (p, q) = n.as_cell()?;
94− Rc::new(Noun::Atom(f(p.as_atom().unwrap(), q.as_atom().unwrap())))
104+ Some(Rc::new(Noun::Atom(f(p.as_atom()?, q.as_atom()?))))
95 };
105 };
96
106
97−static BINARY_ATOM_LOOB: fn(&InterpreterContext, Rc<Noun>, fn(&Atom, &Atom) -> bool) -> Rc<Noun> =
107+static BINARY_ATOM_LOOB: fn(
108+ &InterpreterContext,
109+ Rc<Noun>,
110+ fn(&Atom, &Atom) -> bool,
98− |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
111+) -> Option<Rc<Noun>> = |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
99− let (p, q) = n.as_cell().unwrap();
112+ let (p, q) = n.as_cell().unwrap();
100
113
101− if f(p.as_atom().unwrap(), q.as_atom().unwrap()) {
114+ if f(p.as_atom()?, q.as_atom()?) {
102− ctx.nouns.sig.clone()
115+ Some(ctx.nouns.sig.clone())
103− } else {
116+ } else {
104− ctx.nouns.one.clone()
117+ Some(ctx.nouns.one.clone())
105− }
118+ }
106− };
119+};
107
120
108−static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Rc<Noun> =
121+static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Option<Rc<Noun>> =
109 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
122 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
110 let (p, q) = n.as_cell().unwrap();
123 let (p, q) = n.as_cell().unwrap();
111
124
112 let (a, b) = f(p.as_atom().unwrap(), q.as_atom().unwrap());
125 let (a, b) = f(p.as_atom().unwrap(), q.as_atom().unwrap());
113− cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b)))
126+ Some(cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b))))
114 };
127 };
115
128
116static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
129static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
117−static DEC: Jet = |_ctx, n| Rc::new(Noun::Atom(n.as_atom().unwrap() - 1u32));
130+static DEC: Jet = |_ctx, n| Some(Rc::new(Noun::Atom(n.as_atom().unwrap() - 1u32)));
118static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
131static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
119static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
132static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
120static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
133static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -133,7 +146,7 @@ static CAP: Jet = |ctx, n| {
133 };
146 };
134 CAP_ATOM(ctx, n)
147 CAP_ATOM(ctx, n)
135};
148};
136−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Rc<Noun> = |ctx, n: Atom| {
149+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Option<Rc<Noun>> = |ctx, n: Atom| {
137 let mut n_iter = n.iter_u32_digits();
150 let mut n_iter = n.iter_u32_digits();
138
151
139 match n_iter.len() {
152 match n_iter.len() {
@@ -142,10 +155,10 @@ static CAP_ATOM: fn(&InterpreterContext, Atom) -> Rc<Noun> = |ctx, n: Atom| {
142 _ => CAP_ATOM(ctx, n >> 1),
155 _ => CAP_ATOM(ctx, n >> 1),
143 }
156 }
144};
157};
145−static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Rc<Noun> = |ctx, n| match n {
158+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Option<Rc<Noun>> = |ctx, n| match n {
146 0 | 1 => panic!(),
159 0 | 1 => panic!(),
147− 2 => ctx.nouns.two.clone(),
160+ 2 => Some(ctx.nouns.two.clone()),
148− 3 => ctx.nouns.three.clone(),
161+ 3 => Some(ctx.nouns.three.clone()),
149 n => CAP_U32(ctx, n >> 1),
162 n => CAP_U32(ctx, n >> 1),
150};
163};
151
164
@@ -153,7 +166,7 @@ static MAS: Jet = |ctx, n| {
153 let Noun::Atom(n) = (*n).clone() else {
166 let Noun::Atom(n) = (*n).clone() else {
154 panic!()
167 panic!()
155 };
168 };
156− Rc::new(Noun::Atom(MAS_ATOM(ctx, n)))
169+ Some(Rc::new(Noun::Atom(MAS_ATOM(ctx, n))))
157};
170};
158static MAS_ATOM: fn(&InterpreterContext, Atom) -> Atom = |ctx, n| {
171static MAS_ATOM: fn(&InterpreterContext, Atom) -> Atom = |ctx, n| {
159 let mut n_iter = n.iter_u32_digits();
172 let mut n_iter = n.iter_u32_digits();
@@ -182,7 +195,7 @@ static PEG: Jet = |ctx, n| {
182 panic!()
195 panic!()
183 };
196 };
184
197
185− Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())))
198+ Some(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone()))))
186};
199};
187static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Atom = |ctx, a, b| {
200static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Atom = |ctx, a, b| {
188 let mut b_iter = b.iter_u32_digits();
201 let mut b_iter = b.iter_u32_digits();
@@ -204,7 +217,7 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
204static FAND: Jet = |ctx, n| {
217static FAND: Jet = |ctx, n| {
205 let (nedl, hstk) = n.as_cell().unwrap();
218 let (nedl, hstk) = n.as_cell().unwrap();
206 if nedl.is_sig() || hstk.is_sig() {
219 if nedl.is_sig() || hstk.is_sig() {
207− return ctx.nouns.sig.clone();
220+ return Some(ctx.nouns.sig.clone());
208 }
221 }
209
222
210 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
223 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
@@ -228,13 +241,13 @@ static FAND: Jet = |ctx, n| {
228 inner_iter = iter.clone();
241 inner_iter = iter.clone();
229 }
242 }
230
243
231− Noun::list(result.iter().map(|a| Noun::from_u32(*a)))
244+ Some(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
232};
245};
233
246
234static FIND: Jet = |ctx, n| {
247static FIND: Jet = |ctx, n| {
235 let (nedl, hstk) = n.as_cell().unwrap();
248 let (nedl, hstk) = n.as_cell().unwrap();
236 if nedl.is_sig() || hstk.is_sig() {
249 if nedl.is_sig() || hstk.is_sig() {
237− return ctx.nouns.sig.clone();
250+ return Some(ctx.nouns.sig.clone());
238 }
251 }
239
252
240 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
253 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
@@ -250,18 +263,20 @@ static FIND: Jet = |ctx, n| {
250 .collect::<Vec<_>>()
263 .collect::<Vec<_>>()
251 == nedl
264 == nedl
252 {
265 {
253− return Rc::new(Noun::from_u32(i)).unit();
266+ return Some(Rc::new(Noun::from_u32(i)).unit());
254 }
267 }
255
268
256 inner_iter = iter.clone();
269 inner_iter = iter.clone();
257 }
270 }
258
271
259− return ctx.nouns.sig.clone();
272+ return Some(ctx.nouns.sig.clone());
260};
273};
261
274
262static FLOP: Jet = |ctx, n| {
275static FLOP: Jet = |ctx, n| {
276+ Some(
263− n.list_iter()
277+ n.list_iter()
264− .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail))
278+ .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail)),
279+ )
265};
280};
266
281
267static GULF: Jet = |_ctx, n| {
282static GULF: Jet = |_ctx, n| {
@@ -281,7 +296,7 @@ static GULF: Jet = |_ctx, n| {
281 from += 1u32;
296 from += 1u32;
282 }
297 }
283
298
284− Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone())))
299+ Some(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
285};
300};
286
301
287static INTO: Jet = |_ctx, n| {
302static INTO: Jet = |_ctx, n| {
@@ -291,11 +306,11 @@ static INTO: Jet = |_ctx, n| {
291 let mut b_iter = b.as_atom().unwrap().iter_u32_digits();
306 let mut b_iter = b.as_atom().unwrap().iter_u32_digits();
292
307
293 match b_iter.len() {
308 match b_iter.len() {
294− 0 => cell(c, a),
309+ 0 => Some(cell(c, a)),
295 1 => {
310 1 => {
296 let l = a.list_iter();
311 let l = a.list_iter();
297 let b = b_iter.next().unwrap() as usize;
312 let b = b_iter.next().unwrap() as usize;
298− Noun::list_refs(
313+ Some(Noun::list_refs(
299 l.clone()
314 l.clone()
300 .take(b)
315 .take(b)
301 .chain(once(c))
316 .chain(once(c))
@@ -303,79 +318,85 @@ static INTO: Jet = |_ctx, n| {
303 .collect::<Vec<_>>()
318 .collect::<Vec<_>>()
304 .iter()
319 .iter()
305 .map(|x| x.clone()),
320 .map(|x| x.clone()),
306− )
321+ ))
307 }
322 }
308− _ => Noun::list_refs(
323+ _ => Some(Noun::list_refs(
309 a.list_iter()
324 a.list_iter()
310 .chain(once(c))
325 .chain(once(c))
311 .collect::<Vec<_>>()
326 .collect::<Vec<_>>()
312 .iter()
327 .iter()
313 .map(|x| x.clone()),
328 .map(|x| x.clone()),
314− ),
329+ )),
315 }
330 }
316};
331};
317
332
318static JOIN: Jet = |_ctx, n| {
333static JOIN: Jet = |_ctx, n| {
319 let (sep, list) = n.as_cell().unwrap();
334 let (sep, list) = n.as_cell().unwrap();
320− Noun::list_refs(
335+ Some(Noun::list_refs(
321 list.list_iter()
336 list.list_iter()
322 .intersperse(sep)
337 .intersperse(sep)
323 .collect::<Vec<_>>()
338 .collect::<Vec<_>>()
324 .iter()
339 .iter()
325 .map(|x| x.clone()),
340 .map(|x| x.clone()),
326− )
341+ ))
327};
342};
328
343
344+static LENT: Jet = |_ctx, n| {
345+ Some(Rc::new(Noun::from_u32(
329−static LENT: Jet = |_ctx, n| Rc::new(Noun::from_u32(n.list_iter().fold(0u32, |l, _| l + 1)));
346+ n.list_iter().fold(0u32, |l, _| l + 1),
347+ )))
348+};
330
349
331static LEVY: Jet = |ctx, n| {
350static LEVY: Jet = |ctx, n| {
332 let (a, b) = n.as_cell().unwrap();
351 let (a, b) = n.as_cell().unwrap();
333− if a.list_iter()
352+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
334− .all(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
353+ .iter()
354+ .all(|x| x.is_y())
335 {
355 {
336− ctx.nouns.y.clone()
356+ Some(ctx.nouns.y.clone())
337 } else {
357 } else {
338− ctx.nouns.n.clone()
358+ Some(ctx.nouns.n.clone())
339 }
359 }
340};
360};
341
361
342static LIEN: Jet = |ctx, n| {
362static LIEN: Jet = |ctx, n| {
343 let (a, b) = n.as_cell().unwrap();
363 let (a, b) = n.as_cell().unwrap();
344− if a.list_iter()
364+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
345− .any(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
365+ .iter()
366+ .any(|x| x.is_y())
346 {
367 {
347− ctx.nouns.y.clone()
368+ Some(ctx.nouns.y.clone())
348 } else {
369 } else {
349− ctx.nouns.n.clone()
370+ Some(ctx.nouns.n.clone())
350 }
371 }
351};
372};
352
373
353static MURN: Jet = |ctx, n| {
374static MURN: Jet = |ctx, n| {
354 let (a, b) = n.as_cell().unwrap();
375 let (a, b) = n.as_cell().unwrap();
355
376
356− Noun::list_refs(
377+ Some(Noun::list_refs(
357 a.list_iter()
378 a.list_iter()
358− .filter_map(|n| slam(ctx, b.clone(), n).as_unit())
379+ .filter_map(|n| slam(ctx, b.clone(), n)?.as_unit())
359 .collect::<Vec<_>>()
380 .collect::<Vec<_>>()
360 .iter()
381 .iter()
361 .map(|x| x.clone()),
382 .map(|x| x.clone()),
362− )
383+ ))
363};
384};
364
385
365static REAP: Jet = |_ctx, n| {
386static REAP: Jet = |_ctx, n| {
366 let (a, b) = n.as_cell().unwrap();
387 let (a, b) = n.as_cell().unwrap();
367
388
368− Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize))
389+ Some(Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize)))
369};
390};
370
391
371−static REAR: Jet = |_ctx, n| n.list_iter().last().unwrap();
392+static REAR: Jet = |_ctx, n| n.list_iter().last();
372
393
373static REEL: Jet = |ctx, n| {
394static REEL: Jet = |ctx, n| {
374 let (list, gate) = n.as_cell().unwrap();
395 let (list, gate) = n.as_cell().unwrap();
375
396
376 list.list_iter().collect::<Vec<_>>().iter().rfold(
397 list.list_iter().collect::<Vec<_>>().iter().rfold(
377− gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
398+ Some(gate.clone().gate_sample()?.as_cell()?.1),
378− |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
399+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
379 )
400 )
380};
401};
381
402
@@ -383,58 +404,66 @@ static ROLL: Jet = |ctx, n| {
383 let (list, gate) = n.as_cell().unwrap();
404 let (list, gate) = n.as_cell().unwrap();
384
405
385 list.list_iter().fold(
406 list.list_iter().fold(
386− gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
407+ Some(gate.clone().gate_sample()?.as_cell()?.1),
387− |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
408+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
388 )
409 )
389};
410};
390
411
391static SCAG: Jet = |_ctx, n| {
412static SCAG: Jet = |_ctx, n| {
392 let (a, b) = n.as_cell().unwrap();
413 let (a, b) = n.as_cell().unwrap();
393
414
394− Noun::list_refs(
415+ Some(Noun::list_refs(
395 b.list_iter()
416 b.list_iter()
396 .take(a.as_u32().unwrap() as usize)
417 .take(a.as_u32().unwrap() as usize)
397 .collect::<Vec<_>>()
418 .collect::<Vec<_>>()
398 .iter()
419 .iter()
399 .map(|x| x.clone()),
420 .map(|x| x.clone()),
400− )
421+ ))
401};
422};
402
423
403static SKID: Jet = |ctx, n| {
424static SKID: Jet = |ctx, n| {
404 let (list, gate) = n.as_cell().unwrap();
425 let (list, gate) = n.as_cell().unwrap();
405
426
406− let (ys, ns): (Vec<Rc<Noun>>, _) = list
427+ let slammed_n = traverse_iter_option(
407− .list_iter()
428+ list.list_iter()
408− .partition(|n| slam(ctx, gate.clone(), n.clone()).is_y());
429+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
430+ )?;
431+ let (ys, ns): (Vec<_>, _) = slammed_n.iter().partition(|(l, _)| l.is_y());
409
432
410− cell(
433+ Some(cell(
411− Noun::list_refs(ys.iter().cloned()),
434+ Noun::list_refs(ys.iter().map(|(_, x)| x).cloned()),
412− Noun::list_refs(ns.iter().cloned()),
435+ Noun::list_refs(ns.iter().map(|(_, x)| x).cloned()),
413− )
436+ ))
414};
437};
415
438
416static SKIM: Jet = |ctx, n| {
439static SKIM: Jet = |ctx, n| {
417 let (list, gate) = n.as_cell().unwrap();
440 let (list, gate) = n.as_cell().unwrap();
418
441
419− Noun::list_refs(
442+ Some(Noun::list_refs(
443+ traverse_iter_option(
420− list.list_iter()
444+ list.list_iter()
421− .filter(|n| slam(ctx, gate.clone(), n.clone()).is_y())
445+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
422− .collect::<Vec<_>>()
446+ )?
423− .iter()
447+ .iter()
448+ .filter(|(l, _)| l.is_y())
449+ .map(|(_, x)| x)
424− .cloned(),
450+ .cloned(),
425− )
451+ ))
426};
452};
427
453
428static SKIP: Jet = |ctx, n| {
454static SKIP: Jet = |ctx, n| {
429 let (list, gate) = n.as_cell().unwrap();
455 let (list, gate) = n.as_cell().unwrap();
430
456
431− Noun::list_refs(
457+ Some(Noun::list_refs(
458+ traverse_iter_option(
432− list.list_iter()
459+ list.list_iter()
433− .filter(|n| slam(ctx, gate.clone(), n.clone()).is_n())
460+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
434− .collect::<Vec<_>>()
461+ )?
435− .iter()
462+ .iter()
463+ .filter(|(l, _)| l.is_y())
464+ .map(|(_, x)| x)
436− .cloned(),
465+ .cloned(),
437− )
466+ ))
438};
467};
439
468
440static SLAG: Jet = |ctx, n| {
469static SLAG: Jet = |ctx, n| {
@@ -443,26 +472,26 @@ static SLAG: Jet = |ctx, n| {
443 let mut a_iter = a.as_atom().unwrap().iter_u32_digits();
472 let mut a_iter = a.as_atom().unwrap().iter_u32_digits();
444
473
445 match a_iter.len() {
474 match a_iter.len() {
446− 0 => list,
475+ 0 => Some(list),
447− 1 => Noun::list_refs(
476+ 1 => Some(Noun::list_refs(
448 list.list_iter()
477 list.list_iter()
449 .skip(a_iter.next().unwrap() as usize)
478 .skip(a_iter.next().unwrap() as usize)
450 .collect::<Vec<_>>()
479 .collect::<Vec<_>>()
451 .iter()
480 .iter()
452 .cloned(),
481 .cloned(),
453− ),
482+ )),
454− _ => ctx.nouns.sig.clone(),
483+ _ => Some(ctx.nouns.sig.clone()),
455 }
484 }
456};
485};
457
486
458static SNAG: Jet = |_ctx, n| {
487static SNAG: Jet = |_ctx, n| {
459 let (a, list) = n.as_cell().unwrap();
488 let (a, list) = n.as_cell().unwrap();
460
489
461− list.list_iter().nth(a.as_u32().unwrap() as usize).unwrap()
490+ list.list_iter().nth(a.as_u32().unwrap() as usize)
462};
491};
463
492
464static SNIP: Jet = |_ctx, n| {
493static SNIP: Jet = |_ctx, n| {
465− Noun::list_refs(
494+ Some(Noun::list_refs(
466 n.list_iter()
495 n.list_iter()
467 .collect::<Vec<_>>()
496 .collect::<Vec<_>>()
468 .iter()
497 .iter()
@@ -470,38 +499,38 @@ static SNIP: Jet = |_ctx, n| {
470 .skip(1)
499 .skip(1)
471 .rev()
500 .rev()
472 .cloned(),
501 .cloned(),
473− )
502+ ))
474};
503};
475
504
476static SNOC: Jet = |_ctx, n| {
505static SNOC: Jet = |_ctx, n| {
477 let (list, b) = n.as_cell().unwrap();
506 let (list, b) = n.as_cell().unwrap();
478
507
479− Noun::list_refs(
508+ Some(Noun::list_refs(
480 list.list_iter()
509 list.list_iter()
481 .chain(once(b))
510 .chain(once(b))
482 .collect::<Vec<_>>()
511 .collect::<Vec<_>>()
483 .iter()
512 .iter()
484 .cloned(),
513 .cloned(),
485− )
514+ ))
486};
515};
487
516
488−static SORT: Jet = |ctx, n| {
517+// static SORT: Jet = |ctx, n| {
489− let (list, lth) = n.as_cell().unwrap();
518+// let (list, lth) = n.as_cell().unwrap();
490
519
491− let mut v: Vec<_> = list.list_iter().collect();
520+// let mut v: Vec<_> = list.list_iter().collect();
492
521
493− v.sort_by(|a, b| {
522+// v.sort_by(|a, b| {
494− if slam(ctx, lth.clone(), cell(a.clone(), b.clone())).is_y() {
523+// if slam(ctx, lth.clone(), cell(a.clone(), b.clone())) == ctx.nouns.some_y {
495− Ordering::Less
524+// Ordering::Less
496− } else if slam(ctx, lth.clone(), cell(b.clone(), a.clone())).is_y() {
525+// } else if slam(ctx, lth.clone(), cell(b.clone(), a.clone())) == ctx.nouns.some_y {
497− Ordering::Greater
526+// Ordering::Greater
498− } else {
527+// } else {
499− Ordering::Equal
528+// Ordering::Equal
500− }
529+// }
501− });
530+// });
502
531
503− Noun::list_refs(v.iter().cloned())
532+// Some(Noun::list_refs(v.iter().cloned()))
504−};
533+// };
505
534
506static SPIN: Jet = |ctx, n| {
535static SPIN: Jet = |ctx, n| {
507 let (list, b) = n.as_cell().unwrap();
536 let (list, b) = n.as_cell().unwrap();
@@ -510,12 +539,12 @@ static SPIN: Jet = |ctx, n| {
510 let mut res = Vec::new();
539 let mut res = Vec::new();
511
540
512 for n in list.list_iter() {
541 for n in list.list_iter() {
513− let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc)).as_cell().unwrap();
542+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell().unwrap();
514 acc = new_acc;
543 acc = new_acc;
515 res.push(el);
544 res.push(el);
516 }
545 }
517
546
518− cell(Noun::list_refs(res.iter().cloned()), acc)
547+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
519};
548};
520
549
521static SPUN: Jet = |ctx, n| {
550static SPUN: Jet = |ctx, n| {
@@ -525,51 +554,53 @@ static SPUN: Jet = |ctx, n| {
525 let mut acc = gate.clone().gate_sample().unwrap().as_cell().unwrap().1;
554 let mut acc = gate.clone().gate_sample().unwrap().as_cell().unwrap().1;
526
555
527 for n in list.list_iter() {
556 for n in list.list_iter() {
528− let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc)).as_cell().unwrap();
557+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell().unwrap();
529 acc = new_acc;
558 acc = new_acc;
530 res.push(el);
559 res.push(el);
531 }
560 }
532
561
533− cell(Noun::list_refs(res.iter().cloned()), acc)
562+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
534};
563};
535
564
536static TURN: Jet = |ctx, n| {
565static TURN: Jet = |ctx, n| {
537 let (list, gate) = n.as_cell().unwrap();
566 let (list, gate) = n.as_cell().unwrap();
538− Noun::list_refs(
567+ Some(Noun::list_refs(
539− list.list_iter()
540− .map(|x| slam(ctx, gate.clone(), x))
568+ traverse_iter_option(list.list_iter().map(|x| slam(ctx, gate.clone(), x)))?
541− .collect::<Vec<_>>()
542 .iter()
569 .iter()
543 .cloned(),
570 .cloned(),
544− )
571+ ))
545};
572};
546
573
547static WELD: Jet = |_ctx, n| {
574static WELD: Jet = |_ctx, n| {
548 let (a, b) = n.as_cell().unwrap();
575 let (a, b) = n.as_cell().unwrap();
549
576
550− Noun::list_refs(
577+ Some(Noun::list_refs(
551 a.list_iter()
578 a.list_iter()
552 .chain(b.list_iter())
579 .chain(b.list_iter())
553 .collect::<Vec<_>>()
580 .collect::<Vec<_>>()
554 .iter()
581 .iter()
555 .cloned(),
582 .cloned(),
556− )
583+ ))
557};
584};
558
585
559static WELP: Jet = WELD;
586static WELP: Jet = WELD;
560
587
561static ZING: Jet = |_ctx, n| {
588static ZING: Jet = |_ctx, n| {
562− Noun::list_refs(
589+ Some(Noun::list_refs(
563 n.list_iter()
590 n.list_iter()
564 .map(|l| l.list_iter())
591 .map(|l| l.list_iter())
565 .flatten()
592 .flatten()
566 .collect::<Vec<_>>()
593 .collect::<Vec<_>>()
567 .iter()
594 .iter()
568 .cloned(),
595 .cloned(),
569− )
596+ ))
570};
597};
571
598
599+static BEX: Jet = |ctx, n| {
600+ Some(Rc::new(Noun::Atom(
572−static BEX: Jet = |ctx, n| Rc::new(Noun::Atom(&ctx.big_uints.one << n.as_u32().unwrap()));
601+ &ctx.big_uints.one << n.as_u32().unwrap(),
602+ )))
603+};
573
604
574static END: Jet = |ctx, n| {
605static END: Jet = |ctx, n| {
575 let (a, b) = n.as_cell().unwrap();
606 let (a, b) = n.as_cell().unwrap();
@@ -579,7 +610,7 @@ static END: Jet = |ctx, n| {
579
610
580 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
611 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
581
612
582− Rc::new(Noun::Atom(mask & b.as_atom().unwrap()))
613+ Some(Rc::new(Noun::Atom(mask & b.as_atom().unwrap())))
583};
614};
584
615
585static CAN: Jet = |ctx, n| {
616static CAN: Jet = |ctx, n| {
@@ -599,7 +630,7 @@ static CAN: Jet = |ctx, n| {
599
630
600 (acc << bits) | (mask & q.as_atom().unwrap())
631 (acc << bits) | (mask & q.as_atom().unwrap())
601 });
632 });
602− Rc::new(Noun::Atom(atom))
633+ Some(Rc::new(Noun::Atom(atom)))
603};
634};
604
635
605static CAT: Jet = |_ctx, n| {
636static CAT: Jet = |_ctx, n| {
@@ -610,9 +641,9 @@ static CAT: Jet = |_ctx, n| {
610 let b = b.as_atom().unwrap();
641 let b = b.as_atom().unwrap();
611 let c = c.as_atom().unwrap();
642 let c = c.as_atom().unwrap();
612
643
613− Rc::new(Noun::Atom(
644+ Some(Rc::new(Noun::Atom(
614 (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
645 (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
615− ))
646+ )))
616};
647};
617
648
618static MET: Jet = |_ctx, n| {
649static MET: Jet = |_ctx, n| {
@@ -620,7 +651,7 @@ static MET: Jet = |_ctx, n| {
620 let b: Atom = b.as_atom().unwrap().clone();
651 let b: Atom = b.as_atom().unwrap().clone();
621 let bloq = bloq.as_u32().unwrap();
652 let bloq = bloq.as_u32().unwrap();
622
653
623− Rc::new(Noun::from_u32(met(bloq, b)))
654+ Some(Rc::new(Noun::from_u32(met(bloq, b))))
624};
655};
625
656
626fn met(bloq: u32, mut a: Atom) -> u32 {
657fn met(bloq: u32, mut a: Atom) -> u32 {
@@ -645,9 +676,9 @@ static CUT: Jet = |ctx, n| {
645
676
646 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
677 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
647
678
648− Rc::new(Noun::Atom(
679+ Some(Rc::new(Noun::Atom(
649 (d.as_atom().unwrap() >> (bits * b.as_u32().unwrap())) & mask,
680 (d.as_atom().unwrap() >> (bits * b.as_u32().unwrap())) & mask,
650− ))
681+ )))
651};
682};
652
683
653static FIL: Jet = |ctx, n| {
684static FIL: Jet = |ctx, n| {
@@ -666,7 +697,7 @@ static FIL: Jet = |ctx, n| {
666 target = (target << bits) | &src;
697 target = (target << bits) | &src;
667 }
698 }
668
699
669− Rc::new(Noun::Atom(target))
700+ Some(Rc::new(Noun::Atom(target)))
670};
701};
671
702
672static LSH: Jet = |_ctx, n| {
703static LSH: Jet = |_ctx, n| {
@@ -674,7 +705,7 @@ static LSH: Jet = |_ctx, n| {
674 let a = a.as_bite().unwrap();
705 let a = a.as_bite().unwrap();
675 let b = b.as_atom().unwrap();
706 let b = b.as_atom().unwrap();
676
707
677− Rc::new(Noun::Atom(b << a.bits()))
708+ Some(Rc::new(Noun::Atom(b << a.bits())))
678};
709};
679
710
680static RSH: Jet = |_ctx, n| {
711static RSH: Jet = |_ctx, n| {
@@ -682,7 +713,7 @@ static RSH: Jet = |_ctx, n| {
682 let a = a.as_bite().unwrap();
713 let a = a.as_bite().unwrap();
683 let b = b.as_atom().unwrap();
714 let b = b.as_atom().unwrap();
684
715
685− Rc::new(Noun::Atom(b >> a.bits()))
716+ Some(Rc::new(Noun::Atom(b >> a.bits())))
686};
717};
687
718
688static RAP: Jet = |ctx, n| {
719static RAP: Jet = |ctx, n| {
@@ -699,7 +730,7 @@ static RAP: Jet = |ctx, n| {
699 }
730 }
700 }
731 }
701
732
702− Rc::new(Noun::Atom(target))
733+ Some(Rc::new(Noun::Atom(target)))
703};
734};
704
735
705static REP: Jet = |ctx, n| {
736static REP: Jet = |ctx, n| {
@@ -715,7 +746,7 @@ static REP: Jet = |ctx, n| {
715 target = (target << bits) | (el.as_atom().unwrap() & &mask);
746 target = (target << bits) | (el.as_atom().unwrap() & &mask);
716 }
747 }
717
748
718− Rc::new(Noun::Atom(target))
749+ Some(Rc::new(Noun::Atom(target)))
719};
750};
720
751
721static REV: Jet = |ctx, n| {
752static REV: Jet = |ctx, n| {
@@ -735,7 +766,7 @@ static REV: Jet = |ctx, n| {
735 dat = dat >> bits;
766 dat = dat >> bits;
736 }
767 }
737
768
738− Rc::new(Noun::Atom(target))
769+ Some(Rc::new(Noun::Atom(target)))
739};
770};
740
771
741static RIP: Jet = |ctx, n| {
772static RIP: Jet = |ctx, n| {
@@ -753,7 +784,7 @@ static RIP: Jet = |ctx, n| {
753 b = b >> bits;
784 b = b >> bits;
754 }
785 }
755
786
756− Noun::list_refs(target.iter().cloned())
787+ Some(Noun::list_refs(target.iter().cloned()))
757};
788};
758
789
759static RUN: Jet = |ctx, n| {
790static RUN: Jet = |ctx, n| {
@@ -770,14 +801,14 @@ static RUN: Jet = |ctx, n| {
770
801
771 while b > ctx.big_uints.zero {
802 while b > ctx.big_uints.zero {
772 target = (target << bits)
803 target = (target << bits)
773− | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b))))
804+ | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?)
774 .as_atom()
805 .as_atom()
775 .unwrap()
806 .unwrap()
776 & &mask);
807 & &mask);
777 b = b >> bits;
808 b = b >> bits;
778 }
809 }
779
810
780− Rc::new(Noun::Atom(target))
811+ Some(Rc::new(Noun::Atom(target)))
781};
812};
782
813
783static RUT: Jet = |ctx, n| {
814static RUT: Jet = |ctx, n| {
@@ -794,7 +825,7 @@ static RUT: Jet = |ctx, n| {
794
825
795 while b > ctx.big_uints.zero {
826 while b > ctx.big_uints.zero {
796 target.push(
827 target.push(
797− (*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b))))
828+ (*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?)
798 .as_atom()
829 .as_atom()
799 .unwrap()
830 .unwrap()
800 & &mask,
831 & &mask,
@@ -802,7 +833,7 @@ static RUT: Jet = |ctx, n| {
802 b = b >> bits;
833 b = b >> bits;
803 }
834 }
804
835
805− Noun::list(target.iter().cloned().map(Noun::Atom))
836+ Some(Noun::list(target.iter().cloned().map(Noun::Atom)))
806};
837};
807
838
808static SEW: Jet = |ctx, n| {
839static SEW: Jet = |ctx, n| {
@@ -823,7 +854,7 @@ static SEW: Jet = |ctx, n| {
823
854
824 let target = (recipient ^ apendix) | (donor & mask);
855 let target = (recipient ^ apendix) | (donor & mask);
825
856
826− Rc::new(Noun::Atom(target))
857+ Some(Rc::new(Noun::Atom(target)))
827};
858};
828
859
829static SWP: Jet = |ctx, n| {
860static SWP: Jet = |ctx, n| {
@@ -840,7 +871,7 @@ static SWP: Jet = |ctx, n| {
840 source = source >> bits;
871 source = source >> bits;
841 }
872 }
842
873
843− Rc::new(Noun::Atom(target))
874+ Some(Rc::new(Noun::Atom(target)))
844};
875};
845
876
846static XEB: Jet = |_ctx, n| {
877static XEB: Jet = |_ctx, n| {
@@ -853,7 +884,7 @@ static XEB: Jet = |_ctx, n| {
853 c += 1;
884 c += 1;
854 }
885 }
855
886
856− Rc::new(Noun::from_u32(c))
887+ Some(Rc::new(Noun::from_u32(c)))
857};
888};
858
889
859static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
890static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
@@ -870,5 +901,5 @@ static NOT: Jet = |ctx, n| {
870
901
871 let target = c.as_atom().unwrap() ^ &mask;
902 let target = c.as_atom().unwrap() ^ &mask;
872
903
873− Rc::new(Noun::Atom(target))
904+ Some(Rc::new(Noun::Atom(target)))
874};
905};
nock/src/main.rs+1−1
@@ -13,7 +13,7 @@ fn main() {
13
13
14 let gate = cue_bytes(&jammed_input);
14 let gate = cue_bytes(&jammed_input);
15
15
16− let result = eval_gate(&generate_interpreter_context(), gate);
16+ let result = eval_gate(&generate_interpreter_context(), gate).unwrap();
17
17
18 println!("{result}");
18 println!("{result}");
19}
19}