diff --git a/hblang/README.md b/hblang/README.md index accb2596..6e94b311 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 2767978e..b83e1867 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 dc42dca6..c8b2e095 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 fd186824..82a34a59 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 00000000..2bd2ac21 --- /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(())