From 13135c7da60ccfb000f1fd5e106cf40b96fb6092 Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Fri, 31 May 2024 11:37:28 +0200 Subject: [PATCH] add vm -_- --- src/ir_compiler.rs | 1 + src/main.rs | 1 + src/vm.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/vm.rs diff --git a/src/ir_compiler.rs b/src/ir_compiler.rs index 1a06013..5afc851 100644 --- a/src/ir_compiler.rs +++ b/src/ir_compiler.rs @@ -110,6 +110,7 @@ impl<'syms> FnCompiler<'syms> { self.push(Op::Pop); } } + self.push(Op::Return); self.fns.push(Fn { ops: self.ops, data: self.data, diff --git a/src/main.rs b/src/main.rs index 77c0eeb..0c18c6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod parser; mod sym; mod token; mod util; +mod vm; fn main() { println!("Hello, world!"); diff --git a/src/vm.rs b/src/vm.rs new file mode 100644 index 0000000..adaca17 --- /dev/null +++ b/src/vm.rs @@ -0,0 +1,26 @@ +use crate::ir::Fn; + +enum Value { + I32(i32), + U32(u32), + StaticPtr(u32), + Fn(u32), +} + +struct Vm<'a> { + fns: &'a Vec, + call_stack: Vec<(u64, i32)>, + value_stack: Vec, +} + +impl<'a> Vm<'a> { + pub fn new(fns: &'a Vec) -> Self { + Self { + fns, + call_stack: Vec::new(), + value_stack: Vec::new(), + } + } + + pub fn run(&mut self, entry: u64) {} +}