forked from koniifer/ableos
fixed a significant bugus
This commit is contained in:
parent
605d20b20f
commit
33eea02670
|
@ -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 };
|
new := fn($Elem: type): Vec(Elem) return Vec(Elem).{ data: @bitcast(0), len: 0, cap: 0 };
|
||||||
|
|
||||||
deinit := fn($Elem: type, vec: ^Vec(Elem)): void {
|
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);
|
*vec = new(Elem);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
push := fn($Elem: type, vec: ^Vec(Elem), value: Elem): ^Elem {
|
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;
|
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;
|
vec.data = new_alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +302,9 @@ push := fn($Elem: type, vec: ^Vec(Elem), value: Elem): ^Elem {
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
vec := new(int);
|
vec := new(int);
|
||||||
push(int, &vec, 69);
|
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 {
|
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);
|
let size = self.tys.size_of(ret);
|
||||||
match size {
|
match size {
|
||||||
0 => Loc::default(),
|
0 => Loc::default(),
|
||||||
1..=8 => Loc::reg(1),
|
1..=8 => Loc::reg(1),
|
||||||
9..=16 => Loc::stack(self.ci.stack.allocate(size)),
|
9..=16 => Loc::stack(self.ci.stack.allocate(size)),
|
||||||
_ => {
|
_ => {
|
||||||
let stack = self.ci.stack.allocate(size);
|
let loc = ctx
|
||||||
self.stack_offset(1, STACK_PTR, Some(&stack), 0);
|
.loc
|
||||||
Loc::stack(stack)
|
.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
|
ret: 69
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
Loading…
Reference in a new issue