fixing array bug, well actually more serious bug that somehow did not happen until now

This commit is contained in:
mlokr 2024-09-16 21:46:02 +02:00
parent faf068885a
commit 254d5ed962
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
5 changed files with 46 additions and 45 deletions

29
Cargo.lock generated
View file

@ -2,12 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" version = "0.1.0"
@ -21,7 +15,6 @@ name = "hblang"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"hbvm", "hbvm",
"regalloc2",
] ]
[[package]] [[package]]
@ -54,28 +47,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "regalloc2"
version = "0.10.2"
source = "git+https://github.com/jakubDoka/regalloc2.git#34d8424a0d74746d231a96239fdb32e3d5ec0245"
dependencies = [
"hashbrown",
"rustc-hash",
"smallvec",
]
[[package]]
name = "rustc-hash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "xtask" name = "xtask"
version = "0.1.0" version = "0.1.0"

View file

@ -9,4 +9,3 @@ path = "src/main.rs"
[dependencies] [dependencies]
hbvm = { path = "../hbvm", features = ["nightly"] } hbvm = { path = "../hbvm", features = ["nightly"] }
regalloc2 = { git = "https://github.com/jakubDoka/regalloc2.git" }

View file

@ -317,8 +317,12 @@ fib_iter := fn(n: int): int {
#### arrays #### arrays
```hb ```hb
main := fn(): int { main := fn(): int {
addr := @as(u16, 0x1FF)
msg := [u8].(0, 0, @as(u8, addr & 0xFF), @as(u8, addr >> 8 & 0xFF))
_force_stack := &msg
arr := [int].(1, 2, 4) arr := [int].(1, 2, 4)
return pass(&arr) return pass(&arr) + msg[3]
} }
pass := fn(arr: ^[int; 3]): int { pass := fn(arr: ^[int; 3]): int {

View file

@ -1677,7 +1677,11 @@ impl Codegen {
Some(match ctx.loc { Some(match ctx.loc {
Some(dest) => { Some(dest) => {
self.store_typed(value.loc, dest, value.ty); self.store_sized(
value.loc,
dest,
self.tys.size_of(ctx.ty.unwrap_or(value.ty)).min(self.tys.size_of(value.ty)),
);
Value { ty: value.ty, loc: Loc::ct(0) } Value { ty: value.ty, loc: Loc::ct(0) }
} }
None => value, None => value,

View file

@ -1,17 +1,40 @@
main: main:
ADDI64 r254, r254, -40d ADDI64 r254, r254, -68d
ST r31, r254, 24a, 16h ST r31, r254, 28a, 40h
LI64 r32, 1d LI64 r32, 511d
ST r32, r254, 0a, 8h LI64 r33, 0d
LI64 r32, 2d ST r33, r254, 24a, 1h
ST r32, r254, 8a, 8h LI64 r33, 0d
LI64 r32, 4d ST r33, r254, 25a, 1h
ST r32, r254, 16a, 8h CP r33, r32
ANDI r33, r33, 255d
ST r33, r254, 26a, 1h
SRUI16 r32, r32, 8b
ANDI r32, r32, 255d
ST r32, r254, 27a, 1h
CP r32, r0
LD r32, r254, 24a, 4h
ST r32, r254, 0a, 4h
ADDI64 r32, r254, 0d ADDI64 r32, r254, 0d
CP r2, r32 LI64 r33, 1d
ST r33, r254, 4a, 8h
LI64 r33, 2d
ST r33, r254, 12a, 8h
LI64 r33, 4d
ST r33, r254, 20a, 8h
ADDI64 r33, r254, 4d
CP r2, r33
JAL r31, r0, :pass JAL r31, r0, :pass
LD r31, r254, 24a, 16h CP r33, r1
ADDI64 r254, r254, 40d ADDI64 r34, r254, 0d
LI64 r35, 3d
ADD64 r34, r34, r35
CP r35, r0
LD r35, r34, 0a, 1h
SXT8 r35, r35
ADD64 r1, r33, r35
LD r31, r254, 28a, 40h
ADDI64 r254, r254, 68d
JALA r0, r31, 0a JALA r0, r31, 0a
pass: pass:
ADDI64 r254, r254, -40d ADDI64 r254, r254, -40d
@ -40,6 +63,6 @@ pass:
LD r31, r254, 0a, 40h LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d ADDI64 r254, r254, 40d
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 378 code size: 580
ret: 7 ret: 8
status: Ok(()) status: Ok(())