]> rethought.computer Git - sorel-lang.git/commitdiff
finish arithmetic keep/c31ec01d1ad1593e98fa76efab112902aba7d639
authorBryan English <bryan@rethought.computer>
Mon, 19 Jan 2026 21:28:09 +0000 (16:28 -0500)
committerBryan English <bryan@rethought.computer>
Tue, 10 Feb 2026 04:08:54 +0000 (04:08 +0000)
hylo-lang/hylo-ir/src/lib.rs
hylo-lang/hyloc/src/ir.rs
hylo-lang/hyloc/src/riscv_asm_codegen.rs

index a8aba878df6c31af681fafe7c317509ab4a41cc9..e1db8f771061a3ff4527154e03711614c10d5381 100644 (file)
@@ -24,6 +24,7 @@ pub enum IR {
     SubtractU64,
     MultiplyU64,
     DivideU64,
+    ModU64,
     Equals,
     GreaterThan,
     BitwiseOr,
index c96ee9a842db4b6615c9da7f0836eda3a284bed2..643dc8b5eef4a589e5f217fc294d166bb511a983 100644 (file)
@@ -103,6 +103,7 @@ fn generate_internal(path: PathBuf, module: &Module, imported: &mut HashSet<Path
                         "-" => IR::SubtractU64,
                         "*" => IR::MultiplyU64,
                         "/" => IR::DivideU64,
+                        "%" => IR::ModU64,
                         "|" => IR::BitwiseOr,
                         "import" => IR::Import,
                         "sys0" => IR::Sys0,
index 3da147d07d0a94062e83f9102b46601d1011303d..53e88faf14017fd7cede1d5821a6ed31d2f792b8 100644 (file)
@@ -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");