diff --git a/src/state.rs b/src/state.rs index 346eb0d..9658d66 100644 --- a/src/state.rs +++ b/src/state.rs @@ -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; } }, diff --git a/test_vectors/n_body_new_stuff.lua b/test_vectors/n_body_new_stuff.lua index d8556f3..e1fd105 100644 --- a/test_vectors/n_body_new_stuff.lua +++ b/test_vectors/n_body_new_stuff.lua @@ -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)