From 1e1593298dc09c39ef1464d0eb9776a8229b4d03 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Mon, 26 May 2025 08:32:33 -0400 Subject: [PATCH] update repeat --- src/compiler.rs | 6 +++--- src/main.rs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 28b6e15..d8929d2 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -794,7 +794,7 @@ impl Compiler { self.emit_op(Op::ResetMatch); todo!(); } - // TODO: add stack-tracking to this + // TODO: add a check to make sure times >= 0 Repeat(times, body) => { self.visit(times); self.emit_op(Op::Truncate); @@ -805,7 +805,7 @@ impl Compiler { self.emit_op(Op::Decrement); let repeat_begin = self.len(); self.emit_op(Op::Duplicate); - self.stack_depth += 1; + // self.stack_depth += 1; self.emit_op(Op::JumpIfZero); self.emit_byte(0xff); // compile the body @@ -819,7 +819,7 @@ impl Compiler { self.emit_byte(repeat_end - repeat_begin); self.chunk.bytecode[repeat_begin + 2] = (repeat_end - repeat_begin - 2) as u8; // pop the counter - self.pop(); + // self.pop(); // self.emit_op(Op::Pop); // and emit nil self.emit_constant(Value::Nil); diff --git a/src/main.rs b/src/main.rs index c7f6466..1486892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,8 +74,9 @@ pub fn run(src: &'static str) { pub fn main() { env::set_var("RUST_BACKTRACE", "1"); let src = " -let #{a, :b #{c}} = #{:a 1, :b #{:c 3}} -[a, c] +repeat 4.8 { + true +} "; run(src); }