on master help sign in
Added jet counting
3d2d317iko
nock/Cargo.lock+141−5
@@ -1,6 +1,6 @@
1# This file is automatically @generated by Cargo.
1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing.
2# It is not intended for manual editing.
3−version = 3
3+version = 4
4
4
5[[package]]
5[[package]]
6name = "anstream"
6name = "anstream"
@@ -63,6 +63,12 @@ version = "0.8.0"
63source = "registry+https://github.com/rust-lang/crates.io-index"
63source = "registry+https://github.com/rust-lang/crates.io-index"
64checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
64checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
65
65
66+[[package]]
67+name = "bitflags"
68+version = "2.6.0"
69+source = "registry+https://github.com/rust-lang/crates.io-index"
70+checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
71+
66[[package]]
72[[package]]
67name = "bitter"
73name = "bitter"
68version = "0.7.0"
74version = "0.7.0"
@@ -87,6 +93,12 @@ version = "3.16.0"
87source = "registry+https://github.com/rust-lang/crates.io-index"
93source = "registry+https://github.com/rust-lang/crates.io-index"
88checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
94checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
89
95
96+[[package]]
97+name = "bytecount"
98+version = "0.6.8"
99+source = "registry+https://github.com/rust-lang/crates.io-index"
100+checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
101+
90[[package]]
102[[package]]
91name = "cc"
103name = "cc"
92version = "1.1.31"
104version = "1.1.31"
@@ -102,6 +114,12 @@ version = "1.0.0"
102source = "registry+https://github.com/rust-lang/crates.io-index"
114source = "registry+https://github.com/rust-lang/crates.io-index"
103checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
115checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
104
116
117+[[package]]
118+name = "cfg_aliases"
119+version = "0.2.1"
120+source = "registry+https://github.com/rust-lang/crates.io-index"
121+checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
122+
105[[package]]
123[[package]]
106name = "clap"
124name = "clap"
107version = "4.5.20"
125version = "4.5.20"
@@ -130,10 +148,10 @@ version = "4.5.18"
130source = "registry+https://github.com/rust-lang/crates.io-index"
148source = "registry+https://github.com/rust-lang/crates.io-index"
131checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
149checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
132dependencies = [
150dependencies = [
133− "heck",
151+ "heck 0.5.0",
134 "proc-macro2",
152 "proc-macro2",
135 "quote",
153 "quote",
136− "syn",
154+ "syn 2.0.85",
137]
155]
138
156
139[[package]]
157[[package]]
@@ -158,6 +176,22 @@ dependencies = [
158 "windows-sys 0.48.0",
176 "windows-sys 0.48.0",
159]
177]
160
178
179+[[package]]
180+name = "ctrlc"
181+version = "3.4.5"
182+source = "registry+https://github.com/rust-lang/crates.io-index"
183+checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3"
184+dependencies = [
185+ "nix",
186+ "windows-sys 0.59.0",
187+]
188+
189+[[package]]
190+name = "fnv"
191+version = "1.0.7"
192+source = "registry+https://github.com/rust-lang/crates.io-index"
193+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
194+
161[[package]]
195[[package]]
162name = "fplist"
196name = "fplist"
163version = "0.2.1"
197version = "0.2.1"
@@ -170,6 +204,12 @@ version = "2.0.0"
170source = "registry+https://github.com/rust-lang/crates.io-index"
204source = "registry+https://github.com/rust-lang/crates.io-index"
171checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
205checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
172
206
207+[[package]]
208+name = "heck"
209+version = "0.4.1"
210+source = "registry+https://github.com/rust-lang/crates.io-index"
211+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
212+
173[[package]]
213[[package]]
174name = "heck"
214name = "heck"
175version = "0.5.0"
215version = "0.5.0"
@@ -215,6 +255,18 @@ version = "0.5.2"
215source = "registry+https://github.com/rust-lang/crates.io-index"
255source = "registry+https://github.com/rust-lang/crates.io-index"
216checksum = "9252111cf132ba0929b6f8e030cac2a24b507f3a4d6db6fb2896f27b354c714b"
256checksum = "9252111cf132ba0929b6f8e030cac2a24b507f3a4d6db6fb2896f27b354c714b"
217
257
258+[[package]]
259+name = "nix"
260+version = "0.29.0"
261+source = "registry+https://github.com/rust-lang/crates.io-index"
262+checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
263+dependencies = [
264+ "bitflags",
265+ "cfg-if",
266+ "cfg_aliases",
267+ "libc",
268+]
269+
218[[package]]
270[[package]]
219name = "nock"
271name = "nock"
220version = "0.1.0"
272version = "0.1.0"
@@ -223,13 +275,16 @@ dependencies = [
223 "bitter",
275 "bitter",
224 "bitvec",
276 "bitvec",
225 "clap",
277 "clap",
278+ "ctrlc",
226 "fplist",
279 "fplist",
280+ "lazy_static",
227 "murmur3",
281 "murmur3",
228 "num-bigint",
282 "num-bigint",
229 "num-integer",
283 "num-integer",
230 "num-traits",
284 "num-traits",
231 "spinoff",
285 "spinoff",
232 "stacker",
286 "stacker",
287+ "tabled",
233 "web-sys",
288 "web-sys",
234 "xxhash-rust",
289 "xxhash-rust",
235]
290]
@@ -268,12 +323,47 @@ version = "1.20.2"
268source = "registry+https://github.com/rust-lang/crates.io-index"
323source = "registry+https://github.com/rust-lang/crates.io-index"
269checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
324checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
270
325
326+[[package]]
327+name = "papergrid"
328+version = "0.12.0"
329+source = "registry+https://github.com/rust-lang/crates.io-index"
330+checksum = "c7419ad52a7de9b60d33e11085a0fe3df1fbd5926aa3f93d3dd53afbc9e86725"
331+dependencies = [
332+ "bytecount",
333+ "fnv",
334+ "unicode-width",
335+]
336+
271[[package]]
337[[package]]
272name = "paste"
338name = "paste"
273version = "1.0.15"
339version = "1.0.15"
274source = "registry+https://github.com/rust-lang/crates.io-index"
340source = "registry+https://github.com/rust-lang/crates.io-index"
275checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
341checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
276
342
343+[[package]]
344+name = "proc-macro-error"
345+version = "1.0.4"
346+source = "registry+https://github.com/rust-lang/crates.io-index"
347+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
348+dependencies = [
349+ "proc-macro-error-attr",
350+ "proc-macro2",
351+ "quote",
352+ "syn 1.0.109",
353+ "version_check",
354+]
355+
356+[[package]]
357+name = "proc-macro-error-attr"
358+version = "1.0.4"
359+source = "registry+https://github.com/rust-lang/crates.io-index"
360+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
361+dependencies = [
362+ "proc-macro2",
363+ "quote",
364+ "version_check",
365+]
366+
277[[package]]
367[[package]]
278name = "proc-macro2"
368name = "proc-macro2"
279version = "1.0.89"
369version = "1.0.89"
@@ -343,6 +433,17 @@ version = "0.11.1"
343source = "registry+https://github.com/rust-lang/crates.io-index"
433source = "registry+https://github.com/rust-lang/crates.io-index"
344checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
434checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
345
435
436+[[package]]
437+name = "syn"
438+version = "1.0.109"
439+source = "registry+https://github.com/rust-lang/crates.io-index"
440+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
441+dependencies = [
442+ "proc-macro2",
443+ "quote",
444+ "unicode-ident",
445+]
446+
346[[package]]
447[[package]]
347name = "syn"
448name = "syn"
348version = "2.0.85"
449version = "2.0.85"
@@ -354,6 +455,29 @@ dependencies = [
354 "unicode-ident",
455 "unicode-ident",
355]
456]
356
457
458+[[package]]
459+name = "tabled"
460+version = "0.16.0"
461+source = "registry+https://github.com/rust-lang/crates.io-index"
462+checksum = "77c9303ee60b9bedf722012ea29ae3711ba13a67c9b9ae28993838b63057cb1b"
463+dependencies = [
464+ "papergrid",
465+ "tabled_derive",
466+]
467+
468+[[package]]
469+name = "tabled_derive"
470+version = "0.8.0"
471+source = "registry+https://github.com/rust-lang/crates.io-index"
472+checksum = "bf0fb8bfdc709786c154e24a66777493fb63ae97e3036d914c8666774c477069"
473+dependencies = [
474+ "heck 0.4.1",
475+ "proc-macro-error",
476+ "proc-macro2",
477+ "quote",
478+ "syn 1.0.109",
479+]
480+
357[[package]]
481[[package]]
358name = "tap"
482name = "tap"
359version = "1.0.1"
483version = "1.0.1"
@@ -366,12 +490,24 @@ version = "1.0.13"
366source = "registry+https://github.com/rust-lang/crates.io-index"
490source = "registry+https://github.com/rust-lang/crates.io-index"
367checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
491checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
368
492
493+[[package]]
494+name = "unicode-width"
495+version = "0.1.11"
496+source = "registry+https://github.com/rust-lang/crates.io-index"
497+checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
498+
369[[package]]
499[[package]]
370name = "utf8parse"
500name = "utf8parse"
371version = "0.2.2"
501version = "0.2.2"
372source = "registry+https://github.com/rust-lang/crates.io-index"
502source = "registry+https://github.com/rust-lang/crates.io-index"
373checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
503checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
374
504
505+[[package]]
506+name = "version_check"
507+version = "0.9.5"
508+source = "registry+https://github.com/rust-lang/crates.io-index"
509+checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
510+
375[[package]]
511[[package]]
376name = "wasm-bindgen"
512name = "wasm-bindgen"
377version = "0.2.95"
513version = "0.2.95"
@@ -394,7 +530,7 @@ dependencies = [
394 "once_cell",
530 "once_cell",
395 "proc-macro2",
531 "proc-macro2",
396 "quote",
532 "quote",
397− "syn",
533+ "syn 2.0.85",
398 "wasm-bindgen-shared",
534 "wasm-bindgen-shared",
399]
535]
400
536
@@ -416,7 +552,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
416dependencies = [
552dependencies = [
417 "proc-macro2",
553 "proc-macro2",
418 "quote",
554 "quote",
419− "syn",
555+ "syn 2.0.85",
420 "wasm-bindgen-backend",
556 "wasm-bindgen-backend",
421 "wasm-bindgen-shared",
557 "wasm-bindgen-shared",
422]
558]
nock/Cargo.toml+7
@@ -17,6 +17,9 @@ stacker = "0.1.17"
17murmur3 = "0.5.2"
17murmur3 = "0.5.2"
18web-sys = "0.3.70"
18web-sys = "0.3.70"
19fplist = "0.2.1"
19fplist = "0.2.1"
20+ctrlc = "3.4.5"
21+lazy_static = "1.5.0"
22+tabled = "0.16.0"
20
23
21[dependencies.xxhash-rust]
24[dependencies.xxhash-rust]
22version = "0.8.5"
25version = "0.8.5"
@@ -26,6 +29,9 @@ features = ["xxh3"]
26# Tell `rustc` to optimize for small code size.
29# Tell `rustc` to optimize for small code size.
27opt-level = 3
30opt-level = 3
28
31
32+[features]
33+count-jets = []
34+
29[[bin]]
35[[bin]]
30name = "nock"
36name = "nock"
31path = "src/main.rs"
37path = "src/main.rs"
@@ -33,3 +39,4 @@ path = "src/main.rs"
33[[bin]]
39[[bin]]
34name = "hash-gate"
40name = "hash-gate"
35path = "src/hash-gate.rs"
41path = "src/hash-gate.rs"
42+
nock/src/interpreter.rs+36−2
@@ -1,15 +1,23 @@
1use core::str;
1use core::str;
2use std::borrow::Borrow;
2use std::borrow::Borrow;
3use std::collections::BTreeMap;
3use std::collections::BTreeMap;
4+use std::collections::HashMap;
4use std::rc::Rc;
5use std::rc::Rc;
6+use std::sync::Mutex;
5
7
6use fplist::cons;
8use fplist::cons;
7use fplist::PersistentList;
9use fplist::PersistentList;
10+use lazy_static::lazy_static;
8use num_bigint::BigUint;
11use num_bigint::BigUint;
9
12
10use crate::jets::*;
13use crate::jets::*;
11use crate::noun::*;
14use crate::noun::*;
12
15
16+// #[cfg(feature = "count-jets")]
17+lazy_static! {
18+ pub static ref JET_COUNTER: Mutex<HashMap<Atom, u32>> = Mutex::new(HashMap::new());
19+}
20+
13#[derive(Clone)]
21#[derive(Clone)]
14pub struct Nouns {
22pub struct Nouns {
15 pub y: Rc<Noun>,
23 pub y: Rc<Noun>,
@@ -308,7 +316,26 @@ fn tar_u32<'a>(
308 (ctx.slog)(&ram(ctx, tank.clone()).unwrap_or(String::new()));
316 (ctx.slog)(&ram(ctx, tank.clone()).unwrap_or(String::new()));
309 eval(ctx)
317 eval(ctx)
310 } else if *p == ctx.nouns.fast {
318 } else if *p == ctx.nouns.fast {
319+ if cfg!(feature = "count-jets") {
311− // eprintln!("{}", q.as_cell().unwrap().1.as_cell().unwrap().0);
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+ }
312 eval(ctx)
339 eval(ctx)
313 } else {
340 } else {
314 eval(ctx)
341 eval(ctx)
@@ -407,8 +434,15 @@ fn ram(ctx: &mut InterpreterContext, tank: Rc<Noun>) -> Option<String> {
407pub fn ram_ttanks(ctx: &mut InterpreterContext, tanks: TTanks) -> String {
434pub fn ram_ttanks(ctx: &mut InterpreterContext, tanks: TTanks) -> String {
408 let mut target = String::new();
435 let mut target = String::new();
409
436
437+ let mut first = true;
410− for tank in tanks.iter() {
438+ for tank in tanks.iter().collect::<Vec<_>>().iter().cloned().rev() {
439+ if !first {
440+ target.push('\n');
441+ }
442+
411 target.push_str(&*ram_ttank(ctx, tank.clone()));
443 target.push_str(&*ram_ttank(ctx, tank.clone()));
444+
445+ first = false;
412 }
446 }
413
447
414 target
448 target
nock/src/main.rs+33−1
@@ -1,6 +1,8 @@
1use clap::{command, error::Result, Parser, Subcommand};
1use clap::{command, error::Result, Parser, Subcommand};
2use core::str;
2use core::str;
3+use nock::interpreter::{
3−use nock::interpreter::{ram_ttanks, slam_pulled_gate, tar, InterpreterContext, TTanks};
4+ ram_ttanks, slam_pulled_gate, tar, InterpreterContext, TTanks, JET_COUNTER,
5+};
4use nock::{
6use nock::{
5 cue::cue_bytes,
7 cue::cue_bytes,
6 interpreter::{generate_interpreter_context, slam},
8 interpreter::{generate_interpreter_context, slam},
@@ -65,7 +67,33 @@ enum RunCommand {
65 },
67 },
66}
68}
67
69
70+fn print_jet_counter() {
71+ let counter = JET_COUNTER.lock().unwrap();
72+ let mut builder = tabled::builder::Builder::new();
73+ builder.push_record(vec!["jet", "number of calls"]);
74+ let mut counters = counter.iter().collect::<Vec<_>>();
75+ counters.sort_unstable_by_key(|x| x.1);
76+ for (key, count) in counters {
77+ let key = String::from_utf8(key.to_bytes_le()).unwrap();
78+ builder.push_record(vec![key, count.to_string()]);
79+ }
80+ println!(
81+ "\n{}",
82+ builder
83+ .build()
84+ .with(tabled::settings::style::Style::rounded())
85+ );
86+}
87+
68fn main() -> Result<(), std::io::Error> {
88fn main() -> Result<(), std::io::Error> {
89+ if cfg!(feature = "count-jets") {
90+ ctrlc::set_handler(|| {
91+ print_jet_counter();
92+ exit(1);
93+ })
94+ .unwrap();
95+ }
96+
69 let urbit = LazyCell::new(GENERATE_URBIT);
97 let urbit = LazyCell::new(GENERATE_URBIT);
70 let mut ctx = InterpreterContext {
98 let mut ctx = InterpreterContext {
71 // slog: |_| {},
99 // slog: |_| {},
@@ -145,6 +173,10 @@ fn main() -> Result<(), std::io::Error> {
145 }
173 }
146 }
174 }
147
175
176+ if cfg!(feature = "count-jets") {
177+ print_jet_counter()
178+ }
179+
148 Ok(())
180 Ok(())
149}
181}
150
182