This commit is contained in:
koniifer 2024-12-16 13:22:03 +00:00
parent 6e3fea0713
commit 5eff0facb1
8 changed files with 88 additions and 49 deletions

6
Cargo.lock generated
View file

@ -213,12 +213,12 @@ dependencies = [
[[package]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8138d6664fb6983b10192f5a982a8bf5ec327287" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a1e692eac73fbf44f1fbf816832aaae0ea8f04d7"
[[package]] [[package]]
name = "hblang" name = "hblang"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8138d6664fb6983b10192f5a982a8bf5ec327287" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a1e692eac73fbf44f1fbf816832aaae0ea8f04d7"
dependencies = [ dependencies = [
"hashbrown", "hashbrown",
"hbbytecode", "hbbytecode",
@ -229,7 +229,7 @@ dependencies = [
[[package]] [[package]]
name = "hbvm" name = "hbvm"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8138d6664fb6983b10192f5a982a8bf5ec327287" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a1e692eac73fbf44f1fbf816832aaae0ea8f04d7"
dependencies = [ dependencies = [
"hbbytecode", "hbbytecode",
] ]

View file

@ -141,7 +141,7 @@ Surface := struct {
} }
put_line := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void { put_line := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
if math.abs(uint, p1.y - p0.y) < math.abs(uint, p1.x - p0.x) { if math.abs(int, @bitcast(p1.y - p0.y)) < math.abs(int, @bitcast(p1.x - p0.x)) {
if p0.x > p1.x { if p0.x > p1.x {
@inline(put_line_low, self, p1, p0, color) @inline(put_line_low, self, p1, p0, color)
} else { } else {

View file

@ -23,6 +23,7 @@ $write_length := fn(length: uint, msg: ^u8, buffer_id: uint): void {
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint} BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
create := fn(msg: ^u8): uint { create := fn(msg: ^u8): uint {
// for some reason not inlining here breaks things
return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
} }
@ -35,5 +36,6 @@ $delete_buffer := fn(buffer_id: uint): void {
} }
search := fn(msg: ^u8): uint { search := fn(msg: ^u8): uint {
// for some reason not inlining here breaks things
return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
} }

View file

@ -1,5 +1,5 @@
.{string} := @use("../../stn/src/lib.hb") .{string} := @use("../../stn/src/lib.hb")
get := fn($Expr: type, query: ^u8): Expr { get := fn($Expr: type, query: ^u8): Expr {
return @eca(3, 5, query, @inline(string.length, query)) return @eca(3, 5, query, string.length(query))
} }

View file

@ -12,6 +12,7 @@ dt := @use("dt.hb")
process := @use("process.hb") process := @use("process.hb")
sleep := @use("sleep.hb") sleep := @use("sleep.hb")
// todo: replace with comptime message (for zero cost)
panic := fn(message: ?^u8): never { panic := fn(message: ?^u8): never {
log.error("Error: Panic Called, Message:\0") log.error("Error: Panic Called, Message:\0")
if message == null { if message == null {
@ -21,3 +22,27 @@ panic := fn(message: ?^u8): never {
} }
die die
} }
$unsigned_int := fn($T: type): bool {
return T == uint | T == u8 | T == u16 | T == u32
}
$signed_int := fn($T: type): bool {
return T == int | T == i8 | T == i16 | T == i32
}
$integer := fn($T: type): bool {
return unsigned_int(T) | signed_int(T)
}
$float := fn($T: type): bool {
return T == f32 | T == f64
}
$primitive := fn($T: type): bool {
return integer(T) | float(T) | T == bool
}
$float_bytes := fn($T: type): type {
if T == f64 return uint else if T == f32 return u32
}

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
subscribe_to_interrupt := fn(interrupt_number: u8): bool { $subscribe_to_interrupt := fn(interrupt_number: u8): bool {
return false return false
} }
// Pauses execution until the interrupt occures // Pauses execution until the interrupt occures
sleep_until_interrupt := fn(interrupt_number: u8): void { $sleep_until_interrupt := fn(interrupt_number: u8): void {
@eca(6, interrupt_number) @eca(6, interrupt_number)
} }

View file

@ -22,6 +22,11 @@ palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_G
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color) $LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
example := fn(): void { example := fn(): void {
z := math.log(f32, 10.0, 100.0)
z2 := math.sign(f32, 10.0)
z = math.min(f32, 10.0, 100.0)
z = math.max(f32, 10.0, 100.0)
screen := @as(render.Surface, idk) screen := @as(render.Surface, idk)
window := @as(?sunset.Window, null) window := @as(?sunset.Window, null)
if USE_SUNSET { if USE_SUNSET {
@ -66,15 +71,15 @@ example := fn(): void {
if iteration < MAX_ITERATION { if iteration < MAX_ITERATION {
log_zn := math.ln(f64, x * x + y * y) / 2 log_zn := math.ln(f64, x * x + y * y) / 2
nu := math.ln(f64, log_zn / math.LN_2) / math.LN_2 nu := math.ln(f64, log_zn / math.LN_2) / math.LN_2
smoothed := @itf(@bitcast(iteration + 1)) - nu smoothed := @as(f64, @itf(@bitcast(iteration + 1))) - nu
smoothed_int := @fti(smoothed) smoothed_int := @fti(smoothed)
normalised := smoothed - @itf(smoothed_int) normalised := smoothed - @itf(smoothed_int)
colour0 := palette[@bitcast(smoothed_int) % LEN_PALETTE] colour0 := palette[@bitcast(smoothed_int) % LEN_PALETTE]
colour1 := palette[@bitcast(smoothed_int + 1) % LEN_PALETTE] colour1 := palette[@bitcast(smoothed_int + 1) % LEN_PALETTE]
colour := render.Color.{ colour := render.Color.{
r: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.r)), @itf(@intcast(colour1.r)), normalised))), r: @intcast(@fti(math.lerp(f64, @itf(colour0.r), @itf(colour1.r), normalised))),
g: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.g)), @itf(@intcast(colour1.g)), normalised))), g: @intcast(@fti(math.lerp(f64, @itf(colour0.g), @itf(colour1.g), normalised))),
b: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.b)), @itf(@intcast(colour1.b)), normalised))), b: @intcast(@fti(math.lerp(f64, @itf(colour0.b), @itf(colour1.b), normalised))),
a: 0, a: 0,
} }
screen.put_pixel(.(px, py), colour) screen.put_pixel(.(px, py), colour)
@ -82,8 +87,8 @@ example := fn(): void {
px += 1 px += 1
} }
py += 1 py += 1
} if USE_SUNSET {
if USE_SUNSET loop { _ = sunset.client.send_frame(window)
_ = sunset.client.send_frame(window) }
} }
} }