fix dict pattern stack discipline

This commit is contained in:
Scott Richmond 2025-06-23 17:33:45 -04:00
parent f09caabfcb
commit 6954857fdd
5 changed files with 13 additions and 10 deletions

View File

@ -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 - I _think_ I just fixed this by fixing tail position tracking in collections
- [ ] test this - [ ] test this
* [ ] Dict patterns are giving me stack discipline grief. Why is stack discipline so hard? * [ ] 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

View File

@ -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) & let command = (:forward, 10)
@ -35,6 +35,5 @@
& & (:background, _) -> state & & (:background, _) -> state
& } & }
let foo = #{:a 1, :b 2, :c 3}
let #{a, b, ...c} = foo

View File

@ -724,6 +724,7 @@ impl<'a> Compiler<'a> {
}; };
self.emit_constant(Value::Keyword(key)); self.emit_constant(Value::Keyword(key));
self.emit_op(Op::DropDictEntry); self.emit_op(Op::DropDictEntry);
self.stack_depth -= 1;
} }
if let Some(splatt) = splattern { if let Some(splatt) = splattern {

View File

@ -112,8 +112,8 @@ pub fn run(src: &'static str) {
// in any event, the AST should live forever // in any event, the AST should live forever
let parsed: &'static Spanned<Ast> = Box::leak(Box::new(parse_result.unwrap())); let parsed: &'static Spanned<Ast> = Box::leak(Box::new(parse_result.unwrap()));
let prelude = prelude(); // let prelude = prelude();
// let prelude = imbl::HashMap::new(); let prelude = imbl::HashMap::new();
let mut validator = Validator::new(&parsed.0, &parsed.1, "user input", src, prelude.clone()); let mut validator = Validator::new(&parsed.0, &parsed.1, "user input", src, prelude.clone());
validator.validate(); validator.validate();

View File

@ -910,7 +910,7 @@ impl Vm {
for i in 0..arity as usize { for i in 0..arity as usize {
self.return_register[arity as usize - i - 1] = self.pop(); 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 // then pop everything back to the current stack frame
self.stack.truncate(self.frame.stack_base); self.stack.truncate(self.frame.stack_base);
@ -976,10 +976,10 @@ impl Vm {
// self.ip = self.frame.ip; // self.ip = self.frame.ip;
// // finally, throw the value on the stack // // finally, throw the value on the stack
self.push(value); self.push(value);
println!( // println!(
"=== returning to {} ===", // "=== returning to {} ===",
self.frame.function.as_fn().name() // self.frame.function.as_fn().name()
); // );
} }
Value::Partial(partial) => { Value::Partial(partial) => {
let last_arg = self.pop(); let last_arg = self.pop();