update repeat
This commit is contained in:
parent
04c96c9edb
commit
1e1593298d
|
@ -794,7 +794,7 @@ impl Compiler {
|
||||||
self.emit_op(Op::ResetMatch);
|
self.emit_op(Op::ResetMatch);
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
// TODO: add stack-tracking to this
|
// TODO: add a check to make sure times >= 0
|
||||||
Repeat(times, body) => {
|
Repeat(times, body) => {
|
||||||
self.visit(times);
|
self.visit(times);
|
||||||
self.emit_op(Op::Truncate);
|
self.emit_op(Op::Truncate);
|
||||||
|
@ -805,7 +805,7 @@ impl Compiler {
|
||||||
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.emit_op(Op::Duplicate);
|
||||||
self.stack_depth += 1;
|
// self.stack_depth += 1;
|
||||||
self.emit_op(Op::JumpIfZero);
|
self.emit_op(Op::JumpIfZero);
|
||||||
self.emit_byte(0xff);
|
self.emit_byte(0xff);
|
||||||
// compile the body
|
// compile the body
|
||||||
|
@ -819,7 +819,7 @@ impl Compiler {
|
||||||
self.emit_byte(repeat_end - repeat_begin);
|
self.emit_byte(repeat_end - repeat_begin);
|
||||||
self.chunk.bytecode[repeat_begin + 2] = (repeat_end - repeat_begin - 2) as u8;
|
self.chunk.bytecode[repeat_begin + 2] = (repeat_end - repeat_begin - 2) as u8;
|
||||||
// pop the counter
|
// pop the counter
|
||||||
self.pop();
|
// self.pop();
|
||||||
// self.emit_op(Op::Pop);
|
// self.emit_op(Op::Pop);
|
||||||
// and emit nil
|
// and emit nil
|
||||||
self.emit_constant(Value::Nil);
|
self.emit_constant(Value::Nil);
|
||||||
|
|
|
@ -74,8 +74,9 @@ pub fn run(src: &'static str) {
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
env::set_var("RUST_BACKTRACE", "1");
|
env::set_var("RUST_BACKTRACE", "1");
|
||||||
let src = "
|
let src = "
|
||||||
let #{a, :b #{c}} = #{:a 1, :b #{:c 3}}
|
repeat 4.8 {
|
||||||
[a, c]
|
true
|
||||||
|
}
|
||||||
";
|
";
|
||||||
run(src);
|
run(src);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user