diff --git a/hblang/README.md b/hblang/README.md index 42ba7aa9..edc80df5 100644 --- a/hblang/README.md +++ b/hblang/README.md @@ -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 +} + ``` diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index a1f73cea..0f6e7f26 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -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