From: Bryan English Date: Sat, 31 Jan 2026 03:52:58 +0000 (-0500) Subject: generate instructions on doubles, not words X-Git-Url: https://rethought.computer/gitweb//gitweb//git?a=commitdiff_plain;h=f1afb35d4d5ea4930240bc1f287c0c9c2d38a697;p=sorel-lang.git generate instructions on doubles, not words --- diff --git a/rel-lang/relc/src/riscv_asm_codegen.rs b/rel-lang/relc/src/riscv_asm_codegen.rs index 4edfe4e..8999ef5 100644 --- a/rel-lang/relc/src/riscv_asm_codegen.rs +++ b/rel-lang/relc/src/riscv_asm_codegen.rs @@ -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));