Compare commits

..

2 Commits

Author SHA1 Message Date
Scott Richmond
49e46d045b fix repeat stack discipline 2025-06-23 17:37:46 -04:00
Scott Richmond
6954857fdd fix dict pattern stack discipline 2025-06-23 17:33:45 -04:00
4 changed files with 18 additions and 9 deletions

View File

@ -494,5 +494,8 @@ Here's a list of things that need doing:
- I need this fixed for optimization reasons. - I need this fixed for optimization reasons.
- 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? * [x] 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

@ -35,6 +35,11 @@
& & (:background, _) -> state & & (:background, _) -> state
& } & }
let foo = #{:a 1, :b 2, :c 3} box foos = []
let #{a, b, ...c} = foo
repeat 4 {
update! (foos, append (_, :foo))
}
do foos > unbox > count

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 {
@ -1241,7 +1242,7 @@ impl<'a> Compiler<'a> {
// begin repeat // begin repeat
self.emit_op(Op::Decrement); self.emit_op(Op::Decrement);
let repeat_begin = self.len(); let repeat_begin = self.len();
self.emit_op(Op::Duplicate); self.duplicate();
let jiz_idx = self.stub_jump(Op::JumpIfZero); let jiz_idx = self.stub_jump(Op::JumpIfZero);
// compile the body // compile the body
self.visit(body); self.visit(body);

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();