on master help sign in
It no longer overflows the stack
commitd0b06e08420258e9fadc27aeaa8d28b4c107e1a9 authoriko <mail@iko.soy> dateFri 30 Aug 2024, 07:59 (2 years ago) parent2f823f0
3 files changed+18−27
nock/src/jets.rs+8−22 nock/src/main.rs+7−4 nock/src/noun.rs+3−1
nock/src/jets.rs+8−22
@@ -92,8 +92,8 @@ pub fn generate_jets() -> Jets {
9292 (311027486926441687148059942599447850754, DIS),
9393 (330927609077697663248483044495963838437, MIX),
9494 (39579736615539990724554083585557839000, NOT),
95− // (228256361381255837910155679973102107831, POSE),
9695 (3482046397915506566435874021936376320, LAST),
96+ (124976064672625230427889101290245200507, TRIP),
9797 ])
9898}
9999
@@ -886,27 +886,6 @@ static NOT: Jet = |ctx, n| {
886886 Some(Rc::new(Noun::Atom(target)))
887887};
888888
889−static POSE: Jet = |ctx, n| {
890− println!("runing pose");
891−
892− let (edge_noun, rule) = n.as_cell()?;
893− let edge = edge_noun.as_edge()?;
894−
895− match edge.result {
896− None => {
897− let roq = eval_gate(ctx, rule)?.as_edge()?;
898− Some(cell(
899− last(&edge.hair, &roq.hair).as_noun(),
900− Noun::from_unit(
901− roq.result
902− .map(|(result, nail)| cell(result, nail.as_noun())),
903− ),
904− ))
905− }
906− Some(_) => Some(edge_noun),
907− }
908−};
909−
910889static LAST: Jet = |_ctx, n| {
911890 let (a, b) = n.as_cell()?;
912891 let a = a.as_hair()?;
@@ -929,3 +908,10 @@ fn last<'a>(a: &'a Hair, b: &'a Hair) -> &'a Hair {
929908 }
930909 }
931910}
911+
912+static TRIP: Jet = |_ctx, n| {
913+ let a = n.as_atom()?;
914+ Some(Noun::list(
915+ a.to_bytes_le().iter().map(|b| Noun::from_u32(*b as u32)),
916+ ))
917+};
nock/src/main.rs+7−4
@@ -143,17 +143,20 @@ fn build(root: PathBuf, output: PathBuf) -> Result<(), std::io::Error> {
143143 let make_nock = include_bytes!("../res/make.nock");
144144 let make = cue_bytes(make_nock);
145145
146− let mut root = read_file(&root)?;
146+ let root = read_file(&root)?;
147147
148148 let hoon_hoon = include_bytes!("../res/hoon.hoon");
149149
150− root.extend_from_slice(b"=>\n");
151− root.extend_from_slice(hoon_hoon);
150+ let mut source = Vec::new();
151+
152+ source.extend_from_slice(b"=>\n");
153+ source.extend_from_slice(hoon_hoon);
154+ source.extend_from_slice(&root);
152155
153156 let slam_result = slam(
154157 &generate_interpreter_context(),
155158 make,
156− Rc::new(Noun::Atom(Atom::from_bytes_le(&root))),
159+ Rc::new(Noun::Atom(Atom::from_bytes_le(&source))),
157160 )
158161 .unwrap();
159162
nock/src/noun.rs+3−1
@@ -156,7 +156,9 @@ impl Noun {
156156 Noun::Cell { hash, p, q } => match hash.get() {
157157 Some(x) => x.clone(),
158158 None => {
159− let hash_value = hash_pair(p.clone(), q.clone());
159+ let hash_value = stacker::maybe_grow(32 * 1024, 1024 * 1024, || {
160+ hash_pair(p.clone(), q.clone())
161+ });
160162 hash.replace(Some(hash_value));
161163 hash_value
162164 }