]> rethought.computer Git - sorel-lang.git/commitdiff
load different lengths keep/61b8f8c4f2f45eac679d5c9fd7d550b870803aeb
authorBryan English <bryan@rethought.computer>
Sat, 31 Jan 2026 03:52:58 +0000 (22:52 -0500)
committerBryan English <bryan@rethought.computer>
Tue, 10 Feb 2026 04:08:54 +0000 (04:08 +0000)
rel-lang/rel-ir/src/lib.rs
rel-lang/relc/src/ir.rs
rel-lang/relc/src/riscv_asm_codegen.rs

index 09b5d731b3bef8dbfb72921f2af552e1120fa971..bb2550215482177b4c34200686735d7eed860aba 100644 (file)
@@ -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
index ccff396b5265f4b06d79fdcc8bbe74e607cb93bd..23ca6ab02baa3f2b1f2c7c769f8864ba9b105091 100644 (file)
@@ -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,
index 14972aa8f1113ce1350e37e9d276ab158d029234..148423d7648d41996c49c9af857beaa6f6bcfe13 100644 (file)
@@ -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");