From 61b8f8c4f2f45eac679d5c9fd7d550b870803aeb Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 30 Jan 2026 22:52:58 -0500 Subject: [PATCH] load different lengths --- rel-lang/rel-ir/src/lib.rs | 3 +++ rel-lang/relc/src/ir.rs | 3 +++ rel-lang/relc/src/riscv_asm_codegen.rs | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/rel-lang/rel-ir/src/lib.rs b/rel-lang/rel-ir/src/lib.rs index 09b5d73..bb25502 100644 --- a/rel-lang/rel-ir/src/lib.rs +++ b/rel-lang/rel-ir/src/lib.rs @@ -12,6 +12,9 @@ pub enum IR { // These next ones should always be inlined, so they're in IR. Load, // @ ( addr -- x ) -- Fetch memory contents at addr + Load8, + Load16, + Load32, Store, // ! ( x addr -- ) -- Store x at addr // These ones might not be inlined, but should be built-in, so a compiler might diff --git a/rel-lang/relc/src/ir.rs b/rel-lang/relc/src/ir.rs index ccff396..23ca6ab 100644 --- a/rel-lang/relc/src/ir.rs +++ b/rel-lang/relc/src/ir.rs @@ -112,6 +112,9 @@ impl ImportTree { Token::Word(word) => { match *word { "@" => IR::Load, + "@:8" => IR::Load8, + "@:16" => IR::Load16, + "@:32" => IR::Load32, "!" => IR::Store, "dup" => IR::Dup, "swap" => IR::Swap, diff --git a/rel-lang/relc/src/riscv_asm_codegen.rs b/rel-lang/relc/src/riscv_asm_codegen.rs index 14972aa..148423d 100644 --- a/rel-lang/relc/src/riscv_asm_codegen.rs +++ b/rel-lang/relc/src/riscv_asm_codegen.rs @@ -163,7 +163,26 @@ impl<'a> CodeGen<'a> { self.line("ret"); } }, + IR::Load8 => { + self.label("# load 8"); + self.copy_top_stack_value_to("t0"); + self.line("lbu t0, 0(t0)"); // deref pointer in t0 to t0 + self.copy_to_top_of_stack("t0"); + }, + IR::Load16 => { + self.label("# load 16"); + self.copy_top_stack_value_to("t0"); + self.line("lhu t0, 0(t0)"); // deref pointer in t0 to t0 + self.copy_to_top_of_stack("t0"); + }, + IR::Load32 => { + self.label("# load 32"); + self.copy_top_stack_value_to("t0"); + self.line("lwu t0, 0(t0)"); // deref pointer in t0 to t0 + self.copy_to_top_of_stack("t0"); + }, IR::Load => { + self.label("# load 64"); self.copy_top_stack_value_to("t0"); self.line(format!("ld {}, 0({})", "t0", "t0")); // deref pointer int t0 to t0 self.copy_to_top_of_stack("t0"); -- 2.43.0