diff options
| author | Cody <cody@codyq.dev> | 2023-04-11 17:34:11 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-04-11 17:34:11 -0500 |
| commit | ee079d193b6644e65543c3fa02dbfcf7b4f2f9c6 (patch) | |
| tree | 80975f19a2fcbd909beee83f2000f3dcabac1d9a /crates/sloth_bytecode | |
| parent | 7451bdb02d54243eb299dde55f22d3b06ac5b2f2 (diff) | |
| download | sloth-ee079d193b6644e65543c3fa02dbfcf7b4f2f9c6.tar.gz | |
Hehehe
Diffstat (limited to 'crates/sloth_bytecode')
| -rw-r--r-- | crates/sloth_bytecode/macros/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/sloth_bytecode/src/lib.rs | 24 |
2 files changed, 17 insertions, 9 deletions
diff --git a/crates/sloth_bytecode/macros/src/lib.rs b/crates/sloth_bytecode/macros/src/lib.rs index 31f462f..1690c17 100644 --- a/crates/sloth_bytecode/macros/src/lib.rs +++ b/crates/sloth_bytecode/macros/src/lib.rs @@ -97,7 +97,7 @@ fn into_bytecode_parser(instruction: &DslInstructionInput) -> TokenStream { let mut chunks = Vec::new(); for byte in 0..bytes { - let shift_amount = size - (byte + 1) * bytes; + let shift_amount = size - (byte + 1) * 8; chunks.push(quote! { ((chunk[*offset + #byte] as #arg) << #shift_amount) }); 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); |
