From 6954857fddb2c4bc9da31a74754c421277b68552 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Mon, 23 Jun 2025 17:33:45 -0400 Subject: [PATCH] fix dict pattern stack discipline --- may_2025_thoughts.md | 3 +++ sandbox.ld | 5 ++--- src/compiler.rs | 1 + src/main.rs | 4 ++-- src/vm.rs | 10 +++++----- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/may_2025_thoughts.md b/may_2025_thoughts.md index 3d008c4..1458860 100644 --- a/may_2025_thoughts.md +++ b/may_2025_thoughts.md @@ -495,4 +495,7 @@ Here's a list of things that need doing: - I _think_ I just fixed this by fixing tail position tracking in collections - [ ] test this * [ ] Dict patterns are giving me stack discipline grief. Why is stack discipline so hard? +* [ ] This is in the service of getting turtle graphics working +* Other forms in the language need help: + * [ ] repeat needs its stack discipline updated, it currently crashes the compiler diff --git a/sandbox.ld b/sandbox.ld index fd745a2..3c9996a 100644 --- a/sandbox.ld +++ b/sandbox.ld @@ -1,4 +1,4 @@ -& let state = #{:position (0, 0), :heading 0, :pencolor :white} +let state = #{:position (0, 0), :heading 0, :pencolor :white} & let command = (:forward, 10) @@ -35,6 +35,5 @@ & & (:background, _) -> state & } -let foo = #{:a 1, :b 2, :c 3} -let #{a, b, ...c} = foo + diff --git a/src/compiler.rs b/src/compiler.rs index 0ca91bc..657f9f4 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -724,6 +724,7 @@ impl<'a> Compiler<'a> { }; self.emit_constant(Value::Keyword(key)); self.emit_op(Op::DropDictEntry); + self.stack_depth -= 1; } if let Some(splatt) = splattern { diff --git a/src/main.rs b/src/main.rs index 70eb87e..52d8542 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,8 +112,8 @@ pub fn run(src: &'static str) { // in any event, the AST should live forever let parsed: &'static Spanned = Box::leak(Box::new(parse_result.unwrap())); - let prelude = prelude(); - // let prelude = imbl::HashMap::new(); + // let prelude = prelude(); + let prelude = imbl::HashMap::new(); let mut validator = Validator::new(&parsed.0, &parsed.1, "user input", src, prelude.clone()); validator.validate(); diff --git a/src/vm.rs b/src/vm.rs index b442d0a..d6dd717 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -910,7 +910,7 @@ impl Vm { for i in 0..arity as usize { self.return_register[arity as usize - i - 1] = self.pop(); } - self.print_stack(); + // self.print_stack(); // then pop everything back to the current stack frame self.stack.truncate(self.frame.stack_base); @@ -976,10 +976,10 @@ impl Vm { // self.ip = self.frame.ip; // // finally, throw the value on the stack self.push(value); - println!( - "=== returning to {} ===", - self.frame.function.as_fn().name() - ); + // println!( + // "=== returning to {} ===", + // self.frame.function.as_fn().name() + // ); } Value::Partial(partial) => { let last_arg = self.pop();