Skip to content

Commit c4d815f

Browse files
committed
don't use u64::MAX to halt
1 parent d95c8e8 commit c4d815f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

zenlang/src/vm/vm.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct VM {
2121
pub ret: Value,
2222
pub platform: Option<Box<dyn Platform>>,
2323
pub global_scope: Scope,
24+
pub halted: bool,
2425
pub(crate) bfas_stack_start: Vec<i64>,
2526
pub(crate) bfas_stack_end: Vec<i64>,
2627
}
@@ -38,6 +39,7 @@ impl VM {
3839
ret: Value::Null(),
3940
platform: None,
4041
global_scope: Scope::new(),
42+
halted: false,
4143
bfas_stack_start: Vec::new(),
4244
bfas_stack_end: Vec::new(),
4345
};
@@ -136,19 +138,19 @@ impl VM {
136138
}
137139

138140
pub fn step(&mut self) -> bool {
139-
if !self.error.is_empty() {
141+
if self.halted {
140142
return false;
141143
}
142144

143145
let module_index = self.pc.get_high() as usize;
144146
let opcode_index = self.pc.get_low();
145147
if module_index >= self.modules.len() {
146-
return false;
148+
self.halted = true;
147149
}
148150

149151
let opcodes = core::mem::take(&mut self.modules[module_index].opcodes);
150152
if opcode_index >= opcodes.len() as u32 {
151-
return false;
153+
self.halted = true;
152154
}
153155

154156
let opcode = &opcodes[opcode_index as usize];

zenlang/src/vm/vm_opcode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl VM {
378378
if !self.call_stack.is_empty() {
379379
self.pc = self.call_stack.pop().unwrap();
380380
} else {
381-
self.pc.set_high(u32::MAX);
381+
self.halted = true;
382382
}
383383
}
384384
}

0 commit comments

Comments
 (0)