diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/interpreter.rs | 24 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/opcodes.rs | 28 |
3 files changed, 43 insertions, 13 deletions
diff --git a/src/interpreter.rs b/src/interpreter.rs index ebddcf6..b93b05f 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -37,18 +37,18 @@ pub enum Output { } pub struct Interpreter { - memory: Vec<u8>, - stack: Vec<u8>, - mem_writeable: MemAddress, - mem_min: MemAddress, - heap: Vec<HeapChunk>, - - reg_program: MemAddress, - reg_stack: StackAddress, - reg_frame: StackAddress, - reg_strdec: MemAddress, - - output_mode: Output, + pub memory: Vec<u8>, + pub stack: Vec<u8>, + pub mem_writeable: MemAddress, + pub mem_min: MemAddress, + pub heap: Vec<HeapChunk>, + + pub reg_program: MemAddress, + pub reg_stack: StackAddress, + pub reg_frame: StackAddress, + pub reg_strdec: MemAddress, + + pub output_mode: Output, } impl Interpreter { diff --git a/src/main.rs b/src/main.rs index 7866a7a..4e97cd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,10 @@ mod interpreter; mod glk; mod instructions; -use interpreter::Interpreter; +mod opcodes; +use opcodes::OpCodes; +use interpreter::Interpreter; use std::{env, fs, process::exit}; const MAJOR_VERSION : u16 = 3; diff --git a/src/opcodes.rs b/src/opcodes.rs new file mode 100644 index 0000000..e8ef7fe --- /dev/null +++ b/src/opcodes.rs @@ -0,0 +1,28 @@ +use opcode_proc::generate_opcodes; + +generate_opcodes!( + pub enum OpCodes { + #[code(0x00)] + fn Nop() { + + }, + + #[code(0x10)] + fn Add(a: u32, b: u32) -> u32 { + a + b + }, + + #[code(0x11)] + fn Sub(a: u32, b: u32) -> u32 { + a - b + }, + + #[code(0x23)] + fn Jnz(&mut interpreter, comparison: u32, offset: u32) { + if comparison != 0 { + interpreter.reg_program += offset; + } + } + } +); + |