From: Bryan English Date: Mon, 19 Jan 2026 21:28:09 +0000 (-0500) Subject: finish arithmetic X-Git-Url: https://rethought.computer/gitweb//gitweb//git?a=commitdiff_plain;h=c31ec01d1ad1593e98fa76efab112902aba7d639;p=sorel-lang.git finish arithmetic --- diff --git a/hylo-lang/hylo-ir/src/lib.rs b/hylo-lang/hylo-ir/src/lib.rs index a8aba87..e1db8f7 100644 --- a/hylo-lang/hylo-ir/src/lib.rs +++ b/hylo-lang/hylo-ir/src/lib.rs @@ -24,6 +24,7 @@ pub enum IR { SubtractU64, MultiplyU64, DivideU64, + ModU64, Equals, GreaterThan, BitwiseOr, diff --git a/hylo-lang/hyloc/src/ir.rs b/hylo-lang/hyloc/src/ir.rs index c96ee9a..643dc8b 100644 --- a/hylo-lang/hyloc/src/ir.rs +++ b/hylo-lang/hyloc/src/ir.rs @@ -103,6 +103,7 @@ fn generate_internal(path: PathBuf, module: &Module, imported: &mut HashSet IR::SubtractU64, "*" => IR::MultiplyU64, "/" => IR::DivideU64, + "%" => IR::ModU64, "|" => IR::BitwiseOr, "import" => IR::Import, "sys0" => IR::Sys0, diff --git a/hylo-lang/hyloc/src/riscv_asm_codegen.rs b/hylo-lang/hyloc/src/riscv_asm_codegen.rs index 3da147d..53e88fa 100644 --- a/hylo-lang/hyloc/src/riscv_asm_codegen.rs +++ b/hylo-lang/hyloc/src/riscv_asm_codegen.rs @@ -171,6 +171,24 @@ impl<'a> CodeGen<'a> { self.line("sub t0, t0, t1"); self.push_from("t0"); }, + IR::MultiplyU64 => { + self.pop_to("t1"); + self.pop_to("t0"); + self.line("mul t0, t0, t1"); + self.push_from("t0"); + }, + IR::DivideU64 => { + self.pop_to("t1"); + self.pop_to("t0"); + self.line("div t0, t0, t1"); + self.push_from("t0"); + }, + IR::ModU64 => { + self.pop_to("t1"); + self.pop_to("t0"); + self.line("rem t0, t0, t1"); + self.push_from("t0"); + }, IR::Dup => { self.copy_top_stack_value_to("t0"); self.push_from("t0");