summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2024-12-07 13:29:46 -0700
committerAshelyn Rose <git@ashen.earth>2024-12-07 13:29:46 -0700
commitfbbeed8c10dc9c9bdb34f946d5b844b537ebad7a (patch)
tree096b6387ed9a72c93cafb3e8052be51c78c52b11 /src
parent3e51fca06d097698add372c1052751b3b6313be3 (diff)
Proof of concept for macro opcode defs
Diffstat (limited to 'src')
-rw-r--r--src/interpreter.rs24
-rw-r--r--src/main.rs4
-rw-r--r--src/opcodes.rs28
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;
+            }
+        }
+    }
+);
+