From ce4b937bda2d33a6f92a428eedec8707a87f6761 Mon Sep 17 00:00:00 2001 From: mlokr Date: Wed, 4 Sep 2024 18:48:25 +0200 Subject: [PATCH] updating tests and fixing bug --- hblang/README.md | 2 +- hblang/src/codegen.rs | 4 ++-- hblang/tests/codegen_tests_arrays.txt | 6 +++--- hblang/tests/codegen_tests_c_strings.txt | 5 +++-- hblang/tests/codegen_tests_some_generic_code.txt | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 hblang/tests/codegen_tests_some_generic_code.txt diff --git a/hblang/README.md b/hblang/README.md index accb259..6e94b31 100644 --- a/hblang/README.md +++ b/hblang/README.md @@ -733,7 +733,7 @@ some_func := fn($Elem: type): void { } main := fn(): void { - some_func(0) + some_func(u8) return } ``` diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 2767978..b83e186 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -1740,12 +1740,12 @@ impl Codegen { } } ty::Kind::Slice(arr) => { - let arr = &self.tys.arrays[arr as usize]; + let arr = self.tys.arrays[arr as usize]; let item_size = self.tys.size_of(arr.ty); for (i, value) in fields.iter().enumerate() { let loc = loc.as_ref().offset(i as u32 * item_size); let value = - self.expr_ctx(value, Ctx::default().with_loc(loc).with_ty(ty))?; + self.expr_ctx(value, Ctx::default().with_loc(loc).with_ty(arr.ty))?; self.ci.free_loc(value.loc); } } diff --git a/hblang/tests/codegen_tests_arrays.txt b/hblang/tests/codegen_tests_arrays.txt index dc42dca..c8b2e09 100644 --- a/hblang/tests/codegen_tests_arrays.txt +++ b/hblang/tests/codegen_tests_arrays.txt @@ -2,11 +2,11 @@ main: ADDI64 r254, r254, -72d ST r31, r254, 48a, 24h LI64 r32, 1d - ST r32, r254, 0a, 24h + ST r32, r254, 0a, 8h LI64 r32, 2d - ST r32, r254, 8a, 24h + ST r32, r254, 8a, 8h LI64 r32, 4d - ST r32, r254, 16a, 24h + ST r32, r254, 16a, 8h ADDI64 r32, r254, 0d ADDI64 r33, r254, 24d BMC r32, r33, 24h diff --git a/hblang/tests/codegen_tests_c_strings.txt b/hblang/tests/codegen_tests_c_strings.txt index fd18682..82a34a5 100644 --- a/hblang/tests/codegen_tests_c_strings.txt +++ b/hblang/tests/codegen_tests_c_strings.txt @@ -1,11 +1,12 @@ main: ADDI64 r254, r254, -24d ST r31, r254, 0a, 24h - LRA r32, r0, :string + LRA r32, r0, :abāļž + 56789 CP r2, r32 JAL r31, r0, :str_len CP r32, r1 - LRA r33, r0, :string + LRA r33, r0, :fff CP r2, r33 JAL r31, r0, :str_len CP r33, r1 diff --git a/hblang/tests/codegen_tests_some_generic_code.txt b/hblang/tests/codegen_tests_some_generic_code.txt new file mode 100644 index 0000000..2bd2ac2 --- /dev/null +++ b/hblang/tests/codegen_tests_some_generic_code.txt @@ -0,0 +1,16 @@ +main: + ADDI64 r254, r254, -8d + ST r31, r254, 0a, 8h + JAL r31, r0, :some_func + LD r31, r254, 0a, 8h + ADDI64 r254, r254, 8d + JALA r0, r31, 0a +some_func: + ADDI64 r254, r254, -8d + ST r31, r254, 0a, 8h + LD r31, r254, 0a, 8h + ADDI64 r254, r254, 8d + JALA r0, r31, 0a +code size: 133 +ret: 0 +status: Ok(())