diff options
Diffstat (limited to 'crates/sloth_bytecode/src/lib.rs')
| -rw-r--r-- | crates/sloth_bytecode/src/lib.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/sloth_bytecode/src/lib.rs b/crates/sloth_bytecode/src/lib.rs index e499597..bf20068 100644 --- a/crates/sloth_bytecode/src/lib.rs +++ b/crates/sloth_bytecode/src/lib.rs @@ -18,12 +18,12 @@ pub enum Error { instructions! { Instruction; - 0x00 Constant [u64] "Push a constant value onto the stack", - 0x01 Load [u64] "Load a value from a variable", - 0x02 Push [u64] "Push a value to a variable", + 0x00 Constant [u32] "Push a constant value onto the stack", + 0x01 Load [u32] "Load a value from a variable", + 0x02 Push [u32] "Push a value to a variable", 0x10 Dup [] "Duplicate a value on the stack", - 0x11 Pop [] "Pop a value from the stack", + 0x11 Del [] "Delete a value from the stack", 0x20 Add [] "Add the last 2 values on the stack", 0x21 Sub [] "Subtract the last 2 values on the stack", @@ -31,8 +31,16 @@ instructions! { 0x23 Div [] "Divide the last 2 values on the stack", 0x24 Mod [] "Modulo the last 2 values on the stack", + 0x30 Eq [] "Check if the last 2 values on the stack are equal", + 0x31 Ne [] "Check if the last 2 values on the stack are not equal", + + 0x40 Jmp [u32] "Jump to a specific point in the program", + 0x41 JmpIf [u32] "Jump to a specific point in the program if true is on the stack", + + 0xE0 Hlt [] "Halt the program", + 0xE1 Exit [] "Exit the program", + 0xF0 VMReturn [] "[DEBUG] Pop value from stack and return it from the program", - 0xF1 VMExit [] "[DEBUG] Exit from the VM", } #[cfg(test)] @@ -44,8 +52,8 @@ mod tests { fn decompile_basic_instructions() { let code = [ // Load constant 0 - 0x00, 0, 0, 0, 0, 0, 0, 0, 0, - // Pop, Dup, Add, Sub, Mul, Div, Mod + 0x00, 0, 0, 0, 0, + // Pop, Del, Add, Sub, Mul, Div, Mod 0x10, 0x11, 0x20, 0x21, 0x22, 0x23, 0x24, ]; @@ -53,7 +61,7 @@ mod tests { assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Constant(0)); assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Dup); - assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Pop); + assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Del); assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Add); assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Sub); assert_eq!(Instruction::disassemble(&code, &mut offset), Instruction::Mul); |
