@@ -47,8 +47,8 @@ pub fn generate_interpreter_context() -> InterpreterContext {
47 let two = Rc::new(Noun::Atom(big_uints.two.clone()));
47 let two = Rc::new(Noun::Atom(big_uints.two.clone()));
48 let three = Rc::new(Noun::Atom(big_uints.three.clone()));
48 let three = Rc::new(Noun::Atom(big_uints.three.clone()));
49 let four = Rc::new(Noun::Atom(big_uints.four.clone()));
49 let four = Rc::new(Noun::Atom(big_uints.four.clone()));
50− let sig_one = cell(sig.clone(), one.clone());
50+ let sig_one = cell(&sig, &one);
51− let two_three = cell(two.clone(), three.clone());
51+ let two_three = cell(&two, &three);
52 InterpreterContext {
52 InterpreterContext {
54 double_jets,
54 double_jets,
@@ -67,21 +67,21 @@ pub fn generate_interpreter_context() -> InterpreterContext {
70−fn wut(ctx: &InterpreterContext, noun: Rc<Noun>) -> Rc<Noun> {
70+fn wut(ctx: &InterpreterContext, noun: &Noun) -> Rc<Noun> {
71− match *noun {
71+ match noun {
72 Noun::Cell { .. } => ctx.nouns.sig.clone(),
72 Noun::Cell { .. } => ctx.nouns.sig.clone(),
73 Noun::Atom(_) => ctx.nouns.one.clone(),
73 Noun::Atom(_) => ctx.nouns.one.clone(),
77−fn lus(noun: Rc<Noun>) -> Option<Noun> {
77+fn lus(noun: &Noun) -> Option<Noun> {
78 match (*noun).clone() {
78 match (*noun).clone() {
79 Noun::Cell { .. } => None,
79 Noun::Cell { .. } => None,
80 Noun::Atom(atm) => Some(Noun::Atom(atm + 1u32)),
80 Noun::Atom(atm) => Some(Noun::Atom(atm + 1u32)),
84−fn tis(ctx: &InterpreterContext, lhs: Rc<Noun>, rhs: Rc<Noun>) -> Rc<Noun> {
84+fn tis(ctx: &InterpreterContext, lhs: &Noun, rhs: &Noun) -> Rc<Noun> {
85 if lhs == rhs {
85 if lhs == rhs {
86 ctx.nouns.sig.clone()
86 ctx.nouns.sig.clone()
@@ -89,14 +89,14 @@ fn tis(ctx: &InterpreterContext, lhs: Rc<Noun>, rhs: Rc<Noun>) -> Rc<Noun> {
92−fn fas(ctx: &InterpreterContext, addr: Atom, noun: &Noun) -> Option<Rc<Noun>> {
92+fn fas(ctx: &InterpreterContext, addr: &Atom, noun: &Noun) -> Option<Rc<Noun>> {
93 let mut addr_iter = addr.iter_u32_digits();
93 let mut addr_iter = addr.iter_u32_digits();
95 match addr_iter.len() {
95 match addr_iter.len() {
96 0 => None,
96 0 => None,
97 1 => Some(fas_u32(addr_iter.next()?, noun)?),
97 1 => Some(fas_u32(addr_iter.next()?, noun)?),
99− let rest = fas(ctx, &addr >> 1, noun)?;
99+ let rest = fas(ctx, &(addr >> 1u8), noun)?;
100 Some(fas_u32(
100 Some(fas_u32(
101 if (addr & &ctx.big_uints.one) == ctx.big_uints.one {
101 if (addr & &ctx.big_uints.one) == ctx.big_uints.one {
@@ -119,7 +119,7 @@ fn fas_u32(addr: u32, noun: &Noun) -> Option<Rc<Noun>> {
119 2 => Some(p.clone()),
119 2 => Some(p.clone()),
120 3 => Some(q.clone()),
120 3 => Some(q.clone()),
122− let rest = fas_u32(n >> 1, &naked_cell(p.clone(), q.clone()))?;
122+ let rest = fas_u32(n >> 1, &naked_cell(&p, &q))?;
123 fas_u32(if (n & 1) == 1 { 3 } else { 2 }, &rest)
123 fas_u32(if (n & 1) == 1 { 3 } else { 2 }, &rest)
@@ -134,9 +134,11 @@ fn hax_u32(addr: u32, new_value: Rc<Noun>, target: Rc<Noun>) -> Option<Rc<Noun>>
134 _ => hax_u32(
134 _ => hax_u32(
135 addr >> 1,
135 addr >> 1,
136 if (addr & 1) == 1 {
136 if (addr & 1) == 1 {
137− cell(fas_u32(addr - 1, &target)?, new_value)
137+ let foo = fas_u32(addr - 1, &target)?;
138+ cell(&foo, &new_value)
139− cell(new_value, fas_u32(addr + 1, &target)?)
140+ let foo = fas_u32(addr + 1, &target)?;
141+ cell(&new_value, &foo)
@@ -158,9 +160,11 @@ fn hax(
159 &addr >> 1u32,
161 &addr >> 1u32,
160 if (&addr & &ctx.big_uints.one) == ctx.big_uints.one {
162 if (&addr & &ctx.big_uints.one) == ctx.big_uints.one {
161− cell(fas(ctx, addr - &ctx.big_uints.one, &target)?, new_value)
163+ let foo = fas(ctx, &(addr - &ctx.big_uints.one), &target)?;
164+ cell(&foo, &new_value)
163− cell(new_value, fas(ctx, addr + &ctx.big_uints.one, &target)?)
166+ let foo = fas(ctx, &(addr + &ctx.big_uints.one), &target)?;
167+ cell(&new_value, &foo)
@@ -171,7 +175,7 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
171 match op {
175 match op {
173 let b = formula.as_atom()?.clone();
177 let b = formula.as_atom()?.clone();
174− fas(ctx, b, subj)
178+ fas(ctx, &b, subj)
176 1 => Some(formula),
180 1 => Some(formula),
@@ -181,7 +185,7 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
181 Noun::Cell { p, q, .. }
185 Noun::Cell { p, q, .. }
182 if *p == Noun::SIG
186 if *p == Noun::SIG
183 && q == ctx.nouns.two
187 && q == ctx.nouns.two
184− && b == cell(Rc::new(Noun::SIG), ctx.nouns.one.clone()) =>
188+ && b == cell(&Noun::SIG, &ctx.nouns.one) =>
186 // This means we are about the evaluate a gate at the head of the current subject.
190 // This means we are about the evaluate a gate at the head of the current subject.
187 let (hash, sample) = subj.hash_gate();
191 let (hash, sample) = subj.hash_gate();
@@ -208,12 +212,19 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
216+ let foo = tar(ctx, subj, &formula)?;
211− 3 => Some(wut(ctx, tar(ctx, subj, &formula)?)),
217+ Some(wut(ctx, &foo))
220+ let foo = tar(ctx, subj, &formula)?;
212− 4 => Some(Rc::new(lus(tar(ctx, subj, &formula)?)?)),
221+ Some(Rc::new(lus(&foo)?))
214 let (b, c) = formula.as_cell()?;
224 let (b, c) = formula.as_cell()?;
215 let foo = tar(ctx, &subj, &b)?;
225 let foo = tar(ctx, &subj, &b)?;
216− Some(tis(ctx, foo, tar(ctx, subj, &c)?))
226+ let bar = tar(ctx, subj, &c)?;
227+ Some(tis(ctx, &foo, &bar))
219 let (b, c) = formula.as_cell()?;
230 let (b, c) = formula.as_cell()?;
@@ -221,13 +232,13 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
222 let foo = tar_u32(
233 let foo = tar_u32(
224− &cell(c, d),
235+ &cell(&c, &d),
228 &ctx.nouns.two_three,
239 &ctx.nouns.two_three,
230− tar_u32(ctx, subj, 4, cell(ctx.nouns.four.clone(), b))?,
241+ tar_u32(ctx, subj, 4, cell(&ctx.nouns.four, &b))?,
@@ -240,7 +251,8 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
242 let (b, c) = formula.as_cell()?;
253 let (b, c) = formula.as_cell()?;
243− tar(ctx, &cell(tar(ctx, &subj, &b)?, Rc::new(subj.clone())), &c)
254+ let foo = tar(ctx, &subj, &b)?;
255+ tar(ctx, &cell(&foo, subj), &c)
246 let (b, c) = formula.as_cell()?;
258 let (b, c) = formula.as_cell()?;
@@ -249,7 +261,7 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
252− cell(ctx.nouns.sig_one.clone(), cell(ctx.nouns.sig.clone(), b)),
264+ cell(&ctx.nouns.sig_one, &cell(&ctx.nouns.sig, &b)),
@@ -264,12 +276,11 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
264 // println!("{b}");
276 // println!("{b}");
265 match (*b).clone() {
277 match (*b).clone() {
266 Noun::Atom(_) => tar(ctx, subj, &d),
278 Noun::Atom(_) => tar(ctx, subj, &d),
267− Noun::Cell { q: c, .. } => tar_u32(
279+ Noun::Cell { q: c, .. } => {
268− ctx,
280+ let foo = tar(ctx, subj, &c)?;
269− &cell(tar(ctx, subj, &c)?, tar(ctx, subj, &d)?),
281+ let bar = tar(ctx, subj, &d)?;
271− ctx.nouns.three.clone(),
282+ tar_u32(ctx, &cell(&foo, &bar), 0, ctx.nouns.three.clone())
275 _ => None,
286 _ => None,
@@ -279,7 +290,11 @@ fn tar_u32(ctx: &InterpreterContext, subj: &Noun, op: u32, formula: Rc<Noun>) ->
279pub fn tar(ctx: &InterpreterContext, subj: &Noun, formula: &Noun) -> Option<Rc<Noun>> {
290pub fn tar(ctx: &InterpreterContext, subj: &Noun, formula: &Noun) -> Option<Rc<Noun>> {
280 let (op, formula) = formula.as_cell()?;
291 let (op, formula) = formula.as_cell()?;
281 match *op {
292 match *op {
293+ Noun::Cell { .. } => {
294+ let foo = tar(ctx, subj, &op)?;
282− Noun::Cell { .. } => Some(cell(tar(ctx, subj, &op)?, tar(ctx, subj, &formula)?)),
295+ let bar = tar(ctx, subj, &formula)?;
296+ Some(cell(&foo, &bar))
283 Noun::Atom(ref op) => {
298 Noun::Atom(ref op) => {
284 let mut op_iter = op.iter_u32_digits();
299 let mut op_iter = op.iter_u32_digits();
285 let op = match op_iter.len() {
300 let op = match op_iter.len() {
@@ -298,11 +313,8 @@ pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Option<Rc<Noun>> {
301− Rc::new(Noun::Atom(BigUint::new(vec![9]))),
316+ &Noun::Atom(BigUint::new(vec![9])),
303− ctx.nouns.two.clone(),
304− cell(ctx.nouns.sig.clone(), ctx.nouns.one.clone()),
317+ &cell(&ctx.nouns.two, &cell(&ctx.nouns.sig, &ctx.nouns.one)),
@@ -311,5 +323,5 @@ pub fn slam(ctx: &InterpreterContext, gate: Rc<Noun>, sample: Rc<Noun>) -> Optio
311 let (battery, payload) = gate.as_cell()?;
323 let (battery, payload) = gate.as_cell()?;
312 let (_sample, context) = payload.as_cell()?;
324 let (_sample, context) = payload.as_cell()?;
314− eval_gate(ctx, cell(battery, cell(sample, context)))
326+ eval_gate(ctx, cell(&battery, &cell(&sample, &context)))