@@ -1,23 +1,15 @@
11use core::str;
22use std::borrow::Borrow;
33use std::collections::BTreeMap;
4−use std::collections::HashMap;
54use std::rc::Rc;
6−use std::sync::Mutex;
75
86use fplist::cons;
97use fplist::PersistentList;
10−use lazy_static::lazy_static;
118use num_bigint::BigUint;
129
1310use crate::jets::*;
1411use crate::noun::*;
1512
16−// #[cfg(feature = "count-jets")]
17−lazy_static! {
18− pub static ref JET_COUNTER: Mutex<HashMap<Atom, u32>> = Mutex::new(HashMap::new());
19−}
20−
2113#[derive(Clone)]
2214pub struct Nouns {
2315 pub y: Rc<Noun>,
@@ -32,7 +24,6 @@ pub struct Nouns {
3224 pub memo: Rc<Noun>,
3325 pub mean: Rc<Noun>,
3426 pub slog: Rc<Noun>,
35− pub fast: Rc<Noun>,
3627}
3728
3829#[derive(Clone)]
@@ -74,7 +65,6 @@ pub fn generate_interpreter_context() -> InterpreterContext {
7465 let memo = Rc::new(Noun::from_bytes(b"memo"));
7566 let mean = Rc::new(Noun::from_bytes(b"mean"));
7667 let slog = Rc::new(Noun::from_bytes(b"slog"));
77− let fast = Rc::new(Noun::from_bytes(b"fast"));
7868 InterpreterContext {
7969 jets,
8070 double_jets,
@@ -91,7 +81,6 @@ pub fn generate_interpreter_context() -> InterpreterContext {
9181 memo,
9282 mean,
9383 slog,
94− fast,
9584 },
9685 big_uints,
9786 memo: BTreeMap::new(),
@@ -204,7 +193,7 @@ fn hax(
204193
205194fn tar_u32<'a>(
206195 ctx: &mut InterpreterContext,
207− subj: &'a Rc<Noun>,
196+ subj: Rc<Noun>,
208197 op: u32,
209198 formula: &'a Rc<Noun>,
210199) -> Result<Rc<Noun>, TTanks> {
@@ -227,16 +216,16 @@ fn tar_u32<'a>(
227216 match ctx.jets.get(&hash) {
228217 Some(f) => f(ctx, sample),
229218 None => {
230− let foo = tar(ctx, subj, &b)?;
219+ let foo = tar(ctx, subj.clone(), &b)?;
231220 let bar = tar(ctx, subj, &c)?;
232− tar(ctx, &foo, &bar)
221+ tar(ctx, foo, &bar)
233222 }
234223 }
235224 }
236225 _ => {
237− let foo = tar(ctx, subj, &b)?;
226+ let foo = tar(ctx, subj.clone(), &b)?;
238227 let bar = tar(ctx, subj, &c)?;
239− tar(ctx, &foo, &bar)
228+ tar(ctx, foo, &bar)
240229 }
241230 }
242231 }
@@ -247,7 +236,7 @@ fn tar_u32<'a>(
247236 4 => Ok(Rc::new(lus(&*tar(ctx, subj, &formula)?)?)),
248237 5 => {
249238 let (b, c) = formula.as_cell().ok_or(TTanks::new())?;
250− let foo = tar(ctx, subj, &b)?;
239+ let foo = tar(ctx, subj.clone(), &b)?;
251240 let bar = tar(ctx, subj, &c)?;
252241 Ok(tis(ctx, &foo, &bar).clone())
253242 }
@@ -255,29 +244,29 @@ fn tar_u32<'a>(
255244 let (b, c) = formula.as_cell().ok_or(TTanks::new())?;
256245 let (c, d) = c.as_cell().ok_or(TTanks::new())?;
257246
258− let bar = tar_u32(ctx, subj, 4, &cell(&ctx.nouns.four.clone(), &b))?;
247+ let bar = tar_u32(ctx, subj.clone(), 4, &cell(&ctx.nouns.four.clone(), &b))?;
259248
260− let foo = tar_u32(ctx, &ctx.nouns.two_three.clone(), 0, &bar)?;
261− let foo = tar_u32(ctx, &cell(&c, &d), 0, &foo)?;
249+ let foo = tar_u32(ctx, ctx.nouns.two_three.clone(), 0, &bar)?;
250+ let foo = tar_u32(ctx, cell(&c, &d), 0, &foo)?;
262251
263252 tar(ctx, subj, &foo)
264253 }
265254 7 => {
266255 let (b, c) = formula.as_cell().ok_or(TTanks::new())?;
267256 let foo = tar(ctx, subj, &b)?;
268− tar(ctx, &foo, &c)
257+ tar(ctx, foo, &c)
269258 }
270259 8 => {
271260 let (b, c) = formula.as_cell().ok_or(TTanks::new())?;
272− let foo = tar(ctx, subj, &b)?;
273− tar(ctx, &cell(&foo, &subj), &c)
261+ let foo = tar(ctx, subj.clone(), &b)?;
262+ tar(ctx, cell(&foo, &subj), &c)
274263 }
275264 9 => {
276265 let (b, c) = formula.as_cell().ok_or(TTanks::new())?;
277266 let foo = tar(ctx, subj, &c)?;
278267 tar_u32(
279268 ctx,
280− &foo,
269+ foo,
281270 2,
282271 &cell(&ctx.nouns.sig_one, &cell(&ctx.nouns.sig, &b)),
283272 )
@@ -287,7 +276,7 @@ fn tar_u32<'a>(
287276 let (b, c) = b.as_cell().ok_or(TTanks::new())?;
288277 let b = b.as_atom().ok_or(TTanks::new())?;
289278
290− let foo = tar(ctx, subj, &c)?;
279+ let foo = tar(ctx, subj.clone(), &c)?;
291280 let bar = tar(ctx, subj, &d)?;
292281 hax(ctx, b, &foo, &bar)
293282 }
@@ -296,7 +285,7 @@ fn tar_u32<'a>(
296285 match b.borrow() {
297286 Noun::Atom(_) => tar(ctx, subj, &d),
298287 Noun::Cell { p, q, .. } => {
299− let eval = |ctx: &mut InterpreterContext| tar(ctx, subj, &d);
288+ let eval = |ctx: &mut InterpreterContext| tar(ctx, subj.clone(), &d);
300289 if *p == ctx.nouns.memo {
301290 let hash = cell(&subj, &d).hash();
302291 match ctx.memo.get(&hash) {
@@ -310,33 +299,11 @@ fn tar_u32<'a>(
310299 } else if *p == ctx.nouns.mean {
311300 with_trace((subj.clone(), q.clone()), eval(ctx))
312301 } else if *p == ctx.nouns.slog {
313− let noun = tar(ctx, subj, &q)?;
302+ let noun = tar(ctx, subj.clone(), &q)?;
314303 let (_prio, tank) = noun.as_cell().ok_or(TTanks::new())?;
315304
316305 (ctx.slog)(&ram(ctx, tank.clone()).unwrap_or(String::new()));
317306 eval(ctx)
318− } else if *p == ctx.nouns.fast {
319− if cfg!(feature = "count-jets") {
320− let tag = q.as_cell().unwrap().1.as_cell().unwrap().0.as_atom();
321− match tag {
322− None => (),
323− Some(tag) => {
324− let mut counter = JET_COUNTER.lock().unwrap();
325− match counter.get(tag) {
326− None => {
327− counter.insert(tag.clone(), 1);
328− ()
329− }
330− Some(v) => {
331− let v = *v;
332− counter.insert(tag.clone(), v + 1);
333− ()
334− }
335− }
336− }
337− }
338− }
339− eval(ctx)
340307 } else {
341308 eval(ctx)
342309 }
@@ -434,15 +401,8 @@ fn ram(ctx: &mut InterpreterContext, tank: Rc<Noun>) -> Option<String> {
434401pub fn ram_ttanks(ctx: &mut InterpreterContext, tanks: TTanks) -> String {
435402 let mut target = String::new();
436403
437− let mut first = true;
438− for tank in tanks.iter().collect::<Vec<_>>().iter().cloned().rev() {
439− if !first {
440− target.push('\n');
441− }
442−
404+ for tank in tanks.iter() {
443405 target.push_str(&*ram_ttank(ctx, tank.clone()));
444−
445− first = false;
446406 }
447407
448408 target
@@ -451,7 +411,7 @@ pub fn ram_ttanks(ctx: &mut InterpreterContext, tanks: TTanks) -> String {
451411pub fn ram_ttank(ctx: &mut InterpreterContext, ttank: TTank) -> String {
452412 let (subj, q) = ttank;
453413
454− let tank = match tar(ctx, &subj, &q) {
414+ let tank = match tar(ctx, subj.clone(), &q) {
455415 Ok(gate) => match eval_pulled_gate(ctx, gate) {
456416 Ok(tank) => tank,
457417 Err(_) => {
@@ -484,13 +444,13 @@ pub const EMPTY_TANKS: TTanks = TTanks::new();
484444
485445pub fn tar<'a>(
486446 ctx: &mut InterpreterContext,
487− subj: &'a Rc<Noun>,
447+ subj: Rc<Noun>,
488448 formula: &'a Noun,
489449) -> Result<Rc<Noun>, TTanks> {
490450 let (op, formula) = formula.as_cell().ok_or(TTanks::new())?;
491451 match op.borrow() {
492452 Noun::Cell { .. } => {
493− let foo = tar(ctx, subj, &op)?;
453+ let foo = tar(ctx, subj.clone(), &op)?;
494454 let bar = tar(ctx, subj, &formula)?;
495455 Ok(cell(&foo, &bar))
496456 }
@@ -511,7 +471,7 @@ pub fn eval_gate(
511471 ctx: &mut InterpreterContext,
512472 gate_factory: &Rc<Noun>,
513473) -> Result<Rc<Noun>, TTanks> {
514− let pulled_gate = tar(ctx, &ctx.nouns.sig.clone(), &gate_factory)?;
474+ let pulled_gate = tar(ctx, ctx.nouns.sig.clone(), &gate_factory)?;
515475 eval_pulled_gate(ctx, pulled_gate)
516476}
517477
@@ -520,7 +480,7 @@ pub fn slam(
520480 gate_factory: &Rc<Noun>,
521481 sample: &Rc<Noun>,
522482) -> Result<Rc<Noun>, TTanks> {
523− let gate = tar(ctx, &ctx.nouns.sig.clone(), &gate_factory)?;
483+ let gate = tar(ctx, ctx.nouns.sig.clone(), &gate_factory)?;
524484
525485 eval_pulled_gate(ctx, replace_sample(&gate, sample)?)
526486}
@@ -530,7 +490,7 @@ pub fn slam(
530490pub fn eval_pulled_gate(ctx: &mut InterpreterContext, gate: Rc<Noun>) -> Result<Rc<Noun>, TTanks> {
531491 tar(
532492 ctx,
533− &gate,
493+ gate,
534494 &cell(
535495 &Rc::new(Noun::Atom(BigUint::new(vec![9]))),
536496 &cell(&ctx.nouns.two, &cell(&ctx.nouns.sig, &ctx.nouns.one)),