forked from AbleOS/holey-bytes
fixed a significant bugus
This commit is contained in:
parent
76b3f9ff4b
commit
c85437e4e8
|
@ -261,8 +261,9 @@ Vec := fn($Elem: type): type {
|
|||
new := fn($Elem: type): Vec(Elem) return Vec(Elem).{ data: @bitcast(0), len: 0, cap: 0 };
|
||||
|
||||
deinit := fn($Elem: type, vec: ^Vec(Elem)): void {
|
||||
free(@bitcast(vec.data), vec.len * @sizeof(Elem), @alignof(Elem));
|
||||
free(@bitcast(vec.data), vec.cap * @sizeof(Elem), @alignof(Elem));
|
||||
*vec = new(Elem);
|
||||
return;
|
||||
}
|
||||
|
||||
push := fn($Elem: type, vec: ^Vec(Elem), value: Elem): ^Elem {
|
||||
|
@ -286,7 +287,9 @@ push := fn($Elem: type, vec: ^Vec(Elem), value: Elem): ^Elem {
|
|||
dst_cursor += 1;
|
||||
}
|
||||
|
||||
free(@bitcast(vec.data), vec.len * @sizeof(Elem), @alignof(Elem));
|
||||
if vec.len != 0 {
|
||||
free(@bitcast(vec.data), vec.len * @sizeof(Elem), @alignof(Elem));
|
||||
}
|
||||
vec.data = new_alloc;
|
||||
}
|
||||
|
||||
|
@ -299,7 +302,9 @@ push := fn($Elem: type, vec: ^Vec(Elem), value: Elem): ^Elem {
|
|||
main := fn(): int {
|
||||
vec := new(int);
|
||||
push(int, &vec, 69);
|
||||
return *vec.data;
|
||||
res := *vec.data;
|
||||
deinit(int, &vec);
|
||||
return res;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -2292,19 +2292,23 @@ impl Codegen {
|
|||
}
|
||||
|
||||
fn alloc_ret(&mut self, ret: ty::Id, ctx: Ctx) -> Loc {
|
||||
if let Some(loc) = ctx.loc {
|
||||
return loc;
|
||||
}
|
||||
|
||||
let size = self.tys.size_of(ret);
|
||||
match size {
|
||||
0 => Loc::default(),
|
||||
1..=8 => Loc::reg(1),
|
||||
9..=16 => Loc::stack(self.ci.stack.allocate(size)),
|
||||
_ => {
|
||||
let stack = self.ci.stack.allocate(size);
|
||||
self.stack_offset(1, STACK_PTR, Some(&stack), 0);
|
||||
Loc::stack(stack)
|
||||
let loc = ctx
|
||||
.loc
|
||||
.unwrap_or_else(|| Loc::stack(self.ci.stack.allocate(size)));
|
||||
let Loc::Rt {
|
||||
reg, stack, offset, ..
|
||||
} = &loc
|
||||
else {
|
||||
todo!("old man with the beard looks at the sky scared");
|
||||
};
|
||||
self.stack_offset(1, reg.get(), stack.as_ref(), *offset);
|
||||
loc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
code size: 1302
|
||||
code size: 1503
|
||||
ret: 69
|
||||
status: Ok(())
|
||||
|
|
Loading…
Reference in a new issue