fixing inconststent context for function

This commit is contained in:
mlokr 2024-09-02 03:37:49 +02:00
parent a2c08b6ef6
commit 97c62e424a
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
2 changed files with 34 additions and 2 deletions

View file

@ -631,6 +631,7 @@ min := fn(a: int, b: int): int {
```hb
Point := struct {x: int, y: int}
Buffer := struct {}
Transform := Point
ColorBGRA := Point
line := fn(buffer: Buffer, p0: Point, p1: Point, color: ColorBGRA, thickness: int): void {
@ -658,8 +659,35 @@ line_high := fn(buffer: Buffer, p0: Point, p1: Point, color: ColorBGRA): void {
return
}
main := fn(): int {
line(.(), .(0, 0), .(0, 0), .(0, 0), 10)
screenidx := @use("screen.hb").screenidx
rect_line := fn(buffer: Buffer, pos: Point, tr: Transform, color: ColorBGRA, thickness: int): void {
t := 0
y := 0
x := 0
loop if t == thickness break else {
y = pos.y
x = pos.x
loop if y == pos.y + tr.x break else {
a := 1 + @inline(screenidx, 10)
a = 1 + @inline(screenidx, 2)
y += 1
}
t += 1
}
return
}
main := fn(): int {
line(.(), .(0, 0), .(0, 0), .(0, 0), 10)
rect_line(.(), .(0, 0), .(0, 0), .(0, 0), 10)
return
}
// in module: screen.hb
screenidx := fn(orange: int): int {
return orange
}
```

View file

@ -1538,8 +1538,12 @@ impl Codegen {
let loc = self.alloc_ret(sig.ret, ctx, true);
let prev_ret_reg = std::mem::replace(&mut self.ci.inline_ret_loc, loc);
let prev_file = std::mem::replace(&mut self.ci.file, fuc.file);
let prev_ret = std::mem::replace(&mut self.ci.ret, Some(sig.ret));
self.expr(body);
let loc = std::mem::replace(&mut self.ci.inline_ret_loc, prev_ret_reg);
self.ci.file = prev_file;
self.ci.ret = prev_ret;
if let Some(last_ret) = self.ci.ret_relocs.last()
&& last_ret.offset as usize + self.ci.snap.code == self.output.code.len() - 5