🐛 bug: fix up printing to mostly match PUC Lua
The numbers are still off, since I didn't separate floats and ints yetmain
parent
7b1fb49775
commit
bc15781457
|
@ -58,7 +58,11 @@ pub fn parse_inst (buf: [u8; 4]) -> Option <Inst>
|
||||||
Some (match opcode {
|
Some (match opcode {
|
||||||
0x00 => Inst::Move (a, b),
|
0x00 => Inst::Move (a, b),
|
||||||
0x01 => Inst::LoadI (a, sbx),
|
0x01 => Inst::LoadI (a, sbx),
|
||||||
|
0x02 => Inst::LoadF (a, sbx),
|
||||||
0x03 => Inst::LoadK (a, bx),
|
0x03 => Inst::LoadK (a, bx),
|
||||||
|
0x05 => Inst::LoadFalse (a),
|
||||||
|
0x07 => Inst::LoadTrue (a),
|
||||||
|
0x08 => Inst::LoadNil (a),
|
||||||
0x09 => Inst::GetUpVal (a, b),
|
0x09 => Inst::GetUpVal (a, b),
|
||||||
0x0b => Inst::GetTabUp (a, b, c),
|
0x0b => Inst::GetTabUp (a, b, c),
|
||||||
0x0d => Inst::GetI (a, b, c),
|
0x0d => Inst::GetI (a, b, c),
|
||||||
|
|
|
@ -26,5 +26,5 @@ fn main () {
|
||||||
program_counter: 0,
|
program_counter: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
println! ("Returned: {:?}", vm.execute_chunk (&lua_file, &upvalues));
|
vm.execute_chunk (&lua_file, &upvalues);
|
||||||
}
|
}
|
||||||
|
|
24
src/state.rs
24
src/state.rs
|
@ -21,6 +21,9 @@ pub enum Instruction {
|
||||||
// Jump
|
// Jump
|
||||||
Jmp (i32),
|
Jmp (i32),
|
||||||
|
|
||||||
|
// Load F (Float?)
|
||||||
|
LoadF (u8, i32),
|
||||||
|
|
||||||
LoadFalse (u8),
|
LoadFalse (u8),
|
||||||
|
|
||||||
// Load Integer?
|
// Load Integer?
|
||||||
|
@ -29,6 +32,8 @@ pub enum Instruction {
|
||||||
// Load Constant
|
// Load Constant
|
||||||
LoadK (u8, i32),
|
LoadK (u8, i32),
|
||||||
|
|
||||||
|
LoadNil (u8),
|
||||||
|
|
||||||
LoadTrue (u8),
|
LoadTrue (u8),
|
||||||
|
|
||||||
// MetaMethod, Binary
|
// MetaMethod, Binary
|
||||||
|
@ -304,7 +309,16 @@ impl State {
|
||||||
// assert_eq! (*b, 2);
|
// assert_eq! (*b, 2);
|
||||||
assert_eq! (*c, 1);
|
assert_eq! (*c, 1);
|
||||||
|
|
||||||
println! ("{:?}", r.get (a + 1).unwrap ());
|
let value = r.get (a + 1).unwrap ();
|
||||||
|
let s = match value {
|
||||||
|
Value::Nil => println! ("nil"),
|
||||||
|
Value::Boolean (false) => println! ("false"),
|
||||||
|
Value::Boolean (true) => println! ("true"),
|
||||||
|
Value::Float (x) => println! ("{}", x),
|
||||||
|
Value::String (s) => println! ("{}", s),
|
||||||
|
_ => unimplemented! (),
|
||||||
|
};
|
||||||
|
|
||||||
r [a] = r [a + 1].take ();
|
r [a] = r [a + 1].take ();
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -389,6 +403,10 @@ impl State {
|
||||||
self.register_window_mut ()[a] = upvalues [b].clone ();
|
self.register_window_mut ()[a] = upvalues [b].clone ();
|
||||||
},
|
},
|
||||||
Instruction::Jmp (s_j) => next_pc += s_j,
|
Instruction::Jmp (s_j) => next_pc += s_j,
|
||||||
|
Instruction::LoadF (a, sbx) => {
|
||||||
|
let a = usize::try_from (*a).unwrap ();
|
||||||
|
self.register_window_mut ()[a] = Value::Float (*sbx as f64);
|
||||||
|
}
|
||||||
Instruction::LoadFalse (a) => {
|
Instruction::LoadFalse (a) => {
|
||||||
let a = usize::try_from (*a).unwrap ();
|
let a = usize::try_from (*a).unwrap ();
|
||||||
self.register_window_mut ()[a] = Value::Boolean (false);
|
self.register_window_mut ()[a] = Value::Boolean (false);
|
||||||
|
@ -404,6 +422,10 @@ impl State {
|
||||||
|
|
||||||
self.register_window_mut ()[a] = k [bx].clone ();
|
self.register_window_mut ()[a] = k [bx].clone ();
|
||||||
},
|
},
|
||||||
|
Instruction::LoadNil (a) => {
|
||||||
|
let a = usize::try_from (*a).unwrap ();
|
||||||
|
self.register_window_mut ()[a] = Value::Nil;
|
||||||
|
},
|
||||||
Instruction::LoadTrue (a) => {
|
Instruction::LoadTrue (a) => {
|
||||||
let a = usize::try_from (*a).unwrap ();
|
let a = usize::try_from (*a).unwrap ();
|
||||||
self.register_window_mut ()[a] = Value::Boolean (true);
|
self.register_window_mut ()[a] = Value::Boolean (true);
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
|
print (nil)
|
||||||
|
print (false)
|
||||||
|
print (true)
|
||||||
|
print (1993)
|
||||||
|
print (1993.0)
|
||||||
print "Hello."
|
print "Hello."
|
||||||
|
|
Loading…
Reference in New Issue