]> rethought.computer Git - sorel-lang.git/commitdiff
generate instructions on doubles, not words keep/f1afb35d4d5ea4930240bc1f287c0c9c2d38a697
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/relc/src/riscv_asm_codegen.rs

index 4edfe4e75b3af5473fd0627cbd2277eda265cdff..8999ef580e7e9e7c6b9c60ea43fc178be41177b4 100644 (file)
@@ -64,9 +64,9 @@ impl<'a> CodeGen<'a> {
         self.lines.push(line.to_string());
     }
 
-    asm_macro!(copy_top_stack_value_to, "lw   {}, 0(s2)", &str);
-    asm_macro!(copy_offset_stack_value_to, "lw   {}, {}*8(s2)", &str, isize);
-    asm_macro!(copy_to_top_of_stack, "sw {}, 0(s2)", &str);
+    asm_macro!(copy_top_stack_value_to, "ld   {}, 0(s2)", &str);
+    asm_macro!(copy_offset_stack_value_to, "ld   {}, {}*8(s2)", &str, isize);
+    asm_macro!(copy_to_top_of_stack, "sd {}, 0(s2)", &str);
     asm_macro!(move_stack_ptr_by_cells, "addi s2, s2, {}*8", isize);
 
     fn pop_to(&mut self, reg: &str) {
@@ -142,7 +142,7 @@ impl<'a> CodeGen<'a> {
                         self.label(format!("{}:", name));
                     }
                     self.line("addi sp, sp, -16 # allocate 16 bytes on stack"); // allocate 16 bytes on stack
-                    self.line("sw ra, 8(sp) # store return address on stack");   // store return address on stack
+                    self.line("sd ra, 8(sp) # store return address on stack");   // store return address on stack
                 },
                 IR::Call(name) => {
                     self.label(format!("# call {}", name));
@@ -156,21 +156,19 @@ impl<'a> CodeGen<'a> {
                         self.line("mv a0, x0");
                         self.line("ecall");
                     } else {
-                        self.line("lw ra, 8(sp)");  // load return address from stack
+                        self.line("ld ra, 8(sp)");  // load return address from stack
                         self.line("addi sp, sp, 16"); // restore stack pointer
                         self.line("ret");
                     }
                 },
                 IR::Load => {
                     self.copy_top_stack_value_to("t0");
-                    self.line(format!("lw   {}, 0({})", "t0", "t0")); // deref pointer int t0 to t0
+                    self.line(format!("ld   {}, 0({})", "t0", "t0")); // deref pointer int t0 to t0
                     self.copy_to_top_of_stack("t0");
                 },
                 IR::Store => { // ( x addr -- )
-                    self.copy_top_stack_value_to("t1");
-                    self.copy_offset_stack_value_to("t0", 1);
-                    self.line("sw t0, 0(t1)");                // store x at addr 
-                    self.move_stack_ptr_by_cells(2);
+                    self.pop_some_to("t0 t1");
+                    self.line("sd t0, 0(t1)");                // store x at addr 
                 },
                 IR::StackPush(num) => {
                     self.label(format!("# stackpush {}", num));