fix repeat stack discipline

This commit is contained in:
Scott Richmond 2025-06-23 17:37:46 -04:00
parent 6954857fdd
commit 49e46d045b
4 changed files with 11 additions and 5 deletions

View File

@ -494,7 +494,7 @@ 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 * [ ] This is in the service of getting turtle graphics working
* Other forms in the language need help: * Other forms in the language need help:
* [ ] repeat needs its stack discipline updated, it currently crashes the compiler * [ ] 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,5 +35,11 @@ let state = #{:position (0, 0), :heading 0, :pencolor :white}
& & (:background, _) -> state & & (:background, _) -> state
& } & }
box foos = []
repeat 4 {
update! (foos, append (_, :foo))
}
do foos > unbox > count

View File

@ -1242,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

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