Skip to content

Commit 3649f1b

Browse files
committed
run_until_halt
1 parent 5245738 commit 3649f1b

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

zenlang-cli/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ fn run_vm(vm: &mut vm::VM) {
1414
}
1515
//println!("{:?}", vm.modules);
1616

17-
loop {
18-
if !vm.step() {
19-
break;
20-
}
21-
}
17+
vm.run_until_halt();
18+
2219
if !vm.error.is_empty() {
2320
let mut pc = vm.pc;
2421
pc.sub_low(1);

zenlang/src/vm/vm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ impl VM {
167167
return None;
168168
}
169169

170+
pub fn run_until_halt(&mut self) {
171+
while !self.halted {
172+
self.step();
173+
}
174+
}
175+
170176
pub fn step(&mut self) -> bool {
171177
if self.halted {
172178
return false;

zenlang/tests/vm_stdlib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ fn expect_to_return(code: String, value: Value) {
2727
assert_eq!(e, "");
2828
}
2929

30-
loop {
31-
if !vm.step() {
32-
break;
33-
}
34-
}
30+
vm.run_until_halt();
3531

3632
println!("vm.ret: {:?}", vm.ret);
3733
assert_eq!(vm.error, "");
@@ -56,11 +52,7 @@ fn expect_to_return_obj(code: String, object: Object) {
5652
assert_eq!(e, "");
5753
}
5854

59-
loop {
60-
if !vm.step() {
61-
break;
62-
}
63-
}
55+
vm.run_until_halt();
6456

6557
println!("vm.ret: {}", vm.ret);
6658
assert_eq!(vm.error, "");

0 commit comments

Comments
 (0)