🐛 bug: fix OP_TEST ignoring `k`

I didn't know what `k` was a few days ago.
main
_ 2023-10-01 01:33:47 -05:00
parent a9820677e9
commit fb46ede3ca
2 changed files with 12 additions and 4 deletions

View File

@ -104,7 +104,7 @@ fn lw_string_format (l: &mut State, num_args: usize) -> usize {
assert_eq! (f_string, "%0.9f");
let num = l.reg (1).as_float ().unwrap ();
let output = format! ("{}", num);
let output = format! ("{:0.9}", num);
*l.reg_mut (0) = Value::from (output);
1
@ -683,6 +683,8 @@ impl <'a> State <'a> {
for i in (offset)..(offset - 1 + b) {
self.registers [i] = self.registers [i + 1 + a].take ();
}
self.top = popped_frame.register_offset - 1 + b - 1;
}
else {
// Return from the entire program
@ -690,8 +692,9 @@ impl <'a> State <'a> {
}
},
Instruction::Return0 => {
self.stack.pop ();
let popped_frame = self.stack.pop ().unwrap ();
next_pc = self.stack.last ().unwrap ().program_counter;
self.top = popped_frame.register_offset - 1 + 0;
},
Instruction::Return1 (a) => {
let a = usize::try_from (*a).unwrap ();
@ -715,6 +718,8 @@ impl <'a> State <'a> {
// Shift output register down
let offset = popped_frame.register_offset;
self.registers [offset - 1] = self.registers [offset + a].take ();
self.top = popped_frame.register_offset - 1 + 1;
},
Instruction::SetField (a, b, c, k_flag) => {
let value = if *k_flag {
@ -812,8 +817,8 @@ impl <'a> State <'a> {
// Skip the PC increment
return Ok (None);
},
Instruction::Test (a, _k) => {
if self.reg (*a).is_truthy() {
Instruction::Test (a, k) => {
if self.reg (*a).is_truthy() != *k {
next_pc += 1;
}
},

View File

@ -2,3 +2,6 @@ print ()
print ("asdf")
print (math.sqrt (16))
print (math.sqrt (16.0))
local N = tonumber (arg and arg [1]) or 1000
print (N)