From fbbeed8c10dc9c9bdb34f946d5b844b537ebad7a Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Sat, 7 Dec 2024 13:29:46 -0700 Subject: Proof of concept for macro opcode defs --- src/interpreter.rs | 24 ++++++++++++------------ src/main.rs | 4 +++- src/opcodes.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 src/opcodes.rs (limited to 'src') 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, - stack: Vec, - mem_writeable: MemAddress, - mem_min: MemAddress, - heap: Vec, - - reg_program: MemAddress, - reg_stack: StackAddress, - reg_frame: StackAddress, - reg_strdec: MemAddress, - - output_mode: Output, + pub memory: Vec, + pub stack: Vec, + pub mem_writeable: MemAddress, + pub mem_min: MemAddress, + pub heap: Vec, + + 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; + } + } + } +); + -- cgit 1.4.1