From 99a2bf854128909de4e3f0c5c28428d638ab8c63 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Mon, 9 Feb 2026 22:57:20 -0500 Subject: [PATCH] remove unused interpreter --- rel-lang/Cargo.lock | 32 ----- rel-lang/Cargo.toml | 3 +- rel-lang/sorel-interpret/Cargo.toml | 9 -- rel-lang/sorel-interpret/src/lib.rs | 205 ---------------------------- rel-lang/sorelc/Cargo.toml | 1 - rel-lang/sorelc/src/main.rs | 4 - 6 files changed, 1 insertion(+), 253 deletions(-) delete mode 100644 rel-lang/sorel-interpret/Cargo.toml delete mode 100644 rel-lang/sorel-interpret/src/lib.rs diff --git a/rel-lang/Cargo.lock b/rel-lang/Cargo.lock index 4280816..47524a9 100644 --- a/rel-lang/Cargo.lock +++ b/rel-lang/Cargo.lock @@ -67,7 +67,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", - "serde_derive", ] [[package]] @@ -90,17 +89,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_repr" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "serde_yaml" version = "0.9.34+deprecated" @@ -114,15 +102,6 @@ dependencies = [ "unsafe-libyaml", ] -[[package]] -name = "sorel-interpret" -version = "0.1.0" -dependencies = [ - "anyhow", - "sorel-ir", - "syscalls", -] - [[package]] name = "sorel-ir" version = "0.1.0" @@ -137,7 +116,6 @@ name = "sorelc" version = "0.1.0" dependencies = [ "anyhow", - "sorel-interpret", "sorel-ir", ] @@ -152,16 +130,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syscalls" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90db46b5b4962319605d435986c775ea45a0ad2561c09e1d5372b89afeb49cf4" -dependencies = [ - "serde", - "serde_repr", -] - [[package]] name = "unicode-ident" version = "1.0.22" diff --git a/rel-lang/Cargo.toml b/rel-lang/Cargo.toml index 19da6a8..fae2a78 100644 --- a/rel-lang/Cargo.toml +++ b/rel-lang/Cargo.toml @@ -1,9 +1,8 @@ [workspace] resolver = "3" -members = ["sorel-ir","sorelc", "sorel-interpret"] +members = ["sorel-ir","sorelc"] [workspace.dependencies] sorel-ir = { path = "./sorel-ir", version = "0.1.0" } -sorel-interpret = { path = "./sorel-interpret", version = "0.1.0" } diff --git a/rel-lang/sorel-interpret/Cargo.toml b/rel-lang/sorel-interpret/Cargo.toml deleted file mode 100644 index 6afe8a9..0000000 --- a/rel-lang/sorel-interpret/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "sorel-interpret" -version = "0.1.0" -edition = "2024" - -[dependencies] -anyhow = "1.0.100" -sorel-ir = { workspace = true } -syscalls = "0.7.0" diff --git a/rel-lang/sorel-interpret/src/lib.rs b/rel-lang/sorel-interpret/src/lib.rs deleted file mode 100644 index b637594..0000000 --- a/rel-lang/sorel-interpret/src/lib.rs +++ /dev/null @@ -1,205 +0,0 @@ -use sorel_ir::*; - -use std::collections::HashMap; - -use syscalls::*; -use anyhow::{Result, anyhow}; - -pub struct Interpreter<'a> { - module: &'a IRObject, - data_stack: Vec, - instruction_pointer: usize, - return_stack: Vec, - labels: HashMap, - strings: HashMap, -} - -impl<'a> Interpreter<'a> { - pub fn new(ir_mod: &'a IRObject) -> Result { - let mut index = 0; - let mut labels = HashMap::new(); - for token in ir_mod.text.iter() { - if let IR::Label(name) = token { - labels.insert(name.clone(), index); - } - index += 1; - } - let instruction_pointer = *labels.get("main").ok_or(anyhow!("no main word found!"))?; - - let mut strings = HashMap::new(); - ir_mod.data.iter().for_each(|s| { - match s { - IR::StringDef(label, string) => { - strings.insert(label.clone(), string.clone()); - }, - _ => {} - } - }); - - Ok(Self { - module: ir_mod, - data_stack: vec![], - instruction_pointer, - return_stack: vec![], - labels, - strings - }) - } - - fn process_syscall_result(&mut self, result: Result) { - match result { - Ok(result) => { - self.data_stack.push(result as u64); - self.data_stack.push(0); - } - Err(err) => { - self.data_stack.push(0); - self.data_stack.push(err.into_raw() as u64); - } - } - } - - fn ds_pop(&mut self) -> Result { - self.data_stack.pop().ok_or(anyhow!("popping from empty data stack")) - } - - pub fn run(&mut self) -> Result<()> { - let mut looking_for_endif = false; - loop { - if looking_for_endif { - match &self.module.text[self.instruction_pointer] { - IR::EndIf => { - looking_for_endif = false; - }, - IR::Else => { - looking_for_endif = false; - } - _ => {} - } - } else { - match &self.module.text[self.instruction_pointer] { - IR::Label(_) => {}, - IR::Call(name) => { - self.return_stack.push(self.instruction_pointer); - self.instruction_pointer = *self.labels.get(name).ok_or(anyhow!("calling undefined word `{}`", name))?; - }, - IR::Ret => { - if self.return_stack.len() == 0 { - return Ok(()); - } - self.instruction_pointer = self.return_stack.pop().ok_or(anyhow!("returning from top level"))?; - }, - IR::StackPush(num) => { - self.data_stack.push(*num); - }, - IR::AddU64 => { - let a = self.ds_pop()?; - let b = self.ds_pop()?; - self.data_stack.push(a + b); - }, - IR::SubtractU64 => { - let b = self.ds_pop()?; - let a = self.ds_pop()?; - self.data_stack.push(a - b); - }, - IR::Dup => { - self.data_stack.push(*self.data_stack.last().ok_or(anyhow!("empty data stack"))?); - }, - IR::Swap => { - let a = self.ds_pop()?; - let b = self.ds_pop()?; - self.data_stack.push(a); - self.data_stack.push(b); - }, - IR::Drop => { - self.data_stack.pop(); - }, - IR::Equals => { - let a = self.ds_pop()?; - let b = self.ds_pop()?; - self.data_stack.push(if a == b { - 0 - } else { - -1 as i64 as u64 - }); - }, - IR::GreaterThan => { - let b = self.ds_pop()?; - let a = self.ds_pop()?; - self.data_stack.push(if a > b { - 0 - } else { - -1 as i64 as u64 - }); - - }, - IR::BitwiseOr => { - let b = self.ds_pop()?; - let a = self.ds_pop()?; - self.data_stack.push(a | b); - } - IR::If => { - if self.ds_pop()? != 0 { - looking_for_endif = true; - } - }, - IR::EndIf => {}, - IR::Sys0 => { - let call_num = Sysno::from(self.ds_pop()? as i32); - self.process_syscall_result(unsafe { syscall!(call_num) }); - }, - IR::Sys1 => { - let call_num = Sysno::from(self.ds_pop()? as i32); - let a1 = self.ds_pop()?; - self.process_syscall_result(unsafe { syscall!(call_num, a1) }); - }, - IR::Sys2 => { - let call_num = Sysno::from(self.ds_pop()? as i32); - let a2 = self.ds_pop()?; - let a1 = self.ds_pop()?; - self.process_syscall_result(unsafe { syscall!(call_num, a1, a2) }); - }, - IR::Sys3 => { - let call_num = Sysno::from(self.ds_pop()? as i32); - let a3 = self.ds_pop()?; - let a2 = self.ds_pop()?; - let a1 = self.ds_pop()?; - self.process_syscall_result(unsafe { syscall!(call_num, a1, a2, a3) }); - }, - IR::Sys4 => { - let call_num = Sysno::from(self.ds_pop()? as i32); - let a4 = self.ds_pop()?; - let a3 = self.ds_pop()?; - let a2 = self.ds_pop()?; - let a1 = self.ds_pop()?; - self.process_syscall_result(unsafe { syscall!(call_num, a1, a2, a3, a4) }); - }, - IR::Sys5 => { - let call_num = Sysno::from(self.ds_pop()? as i32); - let a5 = self.ds_pop()?; - let a4 = self.ds_pop()?; - let a3 = self.ds_pop()?; - let a2 = self.ds_pop()?; - let a1 = self.ds_pop()?; - self.process_syscall_result(unsafe { syscall!(call_num, a1, a2, a3, a4, a5) }); - }, - IR::Sys6 => { - println!("stack: {:?}", self.data_stack); - let call_num = Sysno::from(self.ds_pop()? as i32); - let a6 = self.ds_pop()?; - let a5 = self.ds_pop()?; - let a4 = self.ds_pop()?; - let a3 = self.ds_pop()?; - let a2 = self.ds_pop()?; - let a1 = self.ds_pop()?; - self.process_syscall_result(unsafe { syscall!(call_num, a1, a2, a3, a4, a5, a6) }); - }, - _ => { - println!("Instruction not implemented."); - }, - } - } - self.instruction_pointer += 1; - } - } -} diff --git a/rel-lang/sorelc/Cargo.toml b/rel-lang/sorelc/Cargo.toml index dc3b9bc..7859ecf 100644 --- a/rel-lang/sorelc/Cargo.toml +++ b/rel-lang/sorelc/Cargo.toml @@ -5,5 +5,4 @@ edition = "2024" [dependencies] sorel-ir = { workspace = true } -sorel-interpret = { workspace = true } anyhow = "1.0.100" diff --git a/rel-lang/sorelc/src/main.rs b/rel-lang/sorelc/src/main.rs index 89f1d7a..724df84 100644 --- a/rel-lang/sorelc/src/main.rs +++ b/rel-lang/sorelc/src/main.rs @@ -3,8 +3,6 @@ mod parser; mod ir; mod riscv_asm_codegen; -use sorel_interpret::Interpreter; - use anyhow::Result; use std::fs::File; @@ -14,8 +12,6 @@ use std::path::PathBuf; fn main() -> Result<()> { let filename = std::env::args().nth(1).expect("must provide a file to compile"); let module = ir::compile(&filename)?; - // let mut interp = Interpreter::new(&module)?; - // interp.run()?; let mut generator = riscv_asm_codegen::CodeGen::new(&module, 4096); let mut asm_path = PathBuf::from(filename); asm_path.set_extension("asm"); -- 2.43.0