diff --git a/Cargo.lock b/Cargo.lock index af27ea7..ecdb7f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" 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]] name = "hblang" 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 = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" 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 = [ "hbbytecode", ] diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index d4959f2..c441068 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -141,7 +141,7 @@ Surface := struct { } 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 { @inline(put_line_low, self, p1, p0, color) } else { diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 495f53a..9e0866a 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -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} 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)) } @@ -35,5 +36,6 @@ $delete_buffer := fn(buffer_id: uint): void { } 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)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/dt.hb b/sysdata/libraries/stn/src/dt.hb index 160d537..543205a 100644 --- a/sysdata/libraries/stn/src/dt.hb +++ b/sysdata/libraries/stn/src/dt.hb @@ -1,5 +1,5 @@ .{string} := @use("../../stn/src/lib.hb") get := fn($Expr: type, query: ^u8): Expr { - return @eca(3, 5, query, @inline(string.length, query)) + return @eca(3, 5, query, string.length(query)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index 9391917..90b68b7 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -12,6 +12,7 @@ dt := @use("dt.hb") process := @use("process.hb") sleep := @use("sleep.hb") +// todo: replace with comptime message (for zero cost) panic := fn(message: ?^u8): never { log.error("Error: Panic Called, Message:\0") if message == null { @@ -20,4 +21,28 @@ panic := fn(message: ?^u8): never { log.error(message) } 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 } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index d8a9b0e..a234256 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -1,53 +1,60 @@ +.{unsigned_int, signed_int, integer, float, float_bytes} := @use("stn") + $PI := 3.14159265358979323846264338327950288 $LN_2 := 0.693147180559945309417232121458176568 $E := 2.71828182845904523536028747135266250 -$abs := fn($Expr: type, x: Expr): Expr { - if Expr == uint | Expr == u8 | Expr == u16 | Expr == u32 { - return (x ^ x >> @sizeof(Expr) - 1) - (x >> @sizeof(Expr) - 1) - } else if Expr == int | Expr == i8 | Expr == i16 | Expr == i32 { - return x * (1 - 2 * @intcast(@as(u8, @bitcast(x < 0)))) - } else if Expr == f32 | Expr == f64 { - return x * (1.0 - 2.0 * @floatcast(@itf(@intcast(@as(u8, @bitcast(x < 0)))))) +$abs := fn($T: type, x: T): T { + if integer(T) { + return (x ^ x >> @sizeof(T) * 8 - 1) - (x >> @sizeof(T) * 8 - 1) + } else if float(T) { + return @bitcast(@as(float_bytes(T), @bitcast(x)) & (1 << @sizeof(T) * 8) - 1) } } -$min := fn($Expr: type, a: Expr, b: Expr): Expr { - if Expr == uint | Expr == u8 | Expr == u16 | Expr == u32 { - return b + (a - b & a - b >> @sizeof(Expr) - 1) - } else if Expr == int | Expr == i8 | Expr == i16 | Expr == i32 { - return @intcast(@as(u8, @bitcast(a > b))) * b + @intcast(@as(u8, @bitcast(a <= b))) * a - } else if Expr == f32 | Expr == f64 { - return @floatcast(@itf(@intcast(@as(u8, @bitcast(a > b))))) * b + @floatcast(@itf(@intcast(@as(u8, @bitcast(a <= b))))) * a +// todo: better float min, max +$min := fn($T: type, a: T, b: T): T { + if integer(T) { + return b + (a - b & a - b >> @sizeof(T) * 8 - 1) + } else if float(T) { + return @itf(a > b) * b + @itf(a <= b) * a } } -$max := fn($Expr: type, a: Expr, b: Expr): Expr { - if Expr == uint | Expr == u8 | Expr == u16 | Expr == u32 { - return a - (a - b & a - b >> @sizeof(Expr) - 1) - } else if Expr == int | Expr == i8 | Expr == i16 | Expr == i32 { - return @intcast(@as(u8, @bitcast(a > b))) * a + @intcast(@as(u8, @bitcast(a <= b))) * b - } else if Expr == f32 | Expr == f64 { - return @floatcast(@itf(@intcast(@as(u8, @bitcast(a > b))))) * a + @floatcast(@itf(@intcast(@as(u8, @bitcast(a <= b))))) * b +$max := fn($T: type, a: T, b: T): T { + if integer(T) { + return a - (a - b & a - b >> @sizeof(T) - 1) + } else if float(T) { + return @itf(a > b) * a + @itf(a <= b) * b } } -$sign := fn($Expr: type, x: Expr): i8 { - return @bitcast(x > 0) - @bitcast(x < 0) +$sign := fn($T: type, x: T): i8 { + if signed_int(T) { + return @intcast(x >> @sizeof(T) * 8 - 1) | x != 0 + } else if float(T) { + sign_bit := @as(float_bytes(T), @bitcast(x)) >> @sizeof(T) * 8 - 1 + return (1 - 2 * @intcast(sign_bit)) * (x != 0) + } + return 1 } -$log := fn($Expr: type, base: uint, x: Expr): uint { - if Expr == uint | Expr == u8 | Expr == u16 | Expr == u32 | Expr == int | Expr == i8 | Expr == i16 | Expr == i32 { +log := fn($T: type, base: T, x: T): T { + if integer(T) { result := 0 loop if x < base break else { x /= base result += 1 } return result + } else if float(T) { + return ln(T, x) / ln(T, base) } } $lerp := fn($T: type, v0: T, v1: T, t: T): T { - return (1 - t) * v0 + t * v1 + if float(T) { + return v0 + t * (v1 - v0) + } } -Vec2 := fn($Expr: type): type { - return struct {x: Expr, y: Expr} +Vec2 := fn($T: type): type { + return struct {x: T, y: T} } /* source: @@ -55,11 +62,11 @@ Vec2 := fn($Expr: type): type { SIN_TABLE := [f32].(0.0, 0.02454122852291229, 0.04906767432741801, 0.07356456359966743, 0.0980171403295606, 0.1224106751992162, 0.1467304744553617, 0.1709618887603012, 0.1950903220161282, 0.2191012401568698, 0.2429801799032639, 0.2667127574748984, 0.2902846772544623, 0.3136817403988915, 0.3368898533922201, 0.3598950365349881, 0.3826834323650898, 0.4052413140049899, 0.4275550934302821, 0.4496113296546065, 0.4713967368259976, 0.492898192229784, 0.5141027441932217, 0.5349976198870972, 0.5555702330196022, 0.5758081914178453, 0.5956993044924334, 0.6152315905806268, 0.6343932841636455, 0.6531728429537768, 0.6715589548470183, 0.6895405447370668, 0.7071067811865475, 0.7242470829514669, 0.7409511253549591, 0.7572088465064845, 0.773010453362737, 0.7883464276266062, 0.8032075314806448, 0.8175848131515837, 0.8314696123025452, 0.844853565249707, 0.8577286100002721, 0.8700869911087113, 0.8819212643483549, 0.8932243011955153, 0.9039892931234433, 0.9142097557035307, 0.9238795325112867, 0.9329927988347388, 0.9415440651830208, 0.9495281805930367, 0.9569403357322089, 0.9637760657954398, 0.970031253194544, 0.9757021300385286, 0.9807852804032304, 0.9852776423889412, 0.989176509964781, 0.99247953459871, 0.9951847266721968, 0.9972904566786902, 0.9987954562051724, 0.9996988186962042, 1.0, 0.9996988186962042, 0.9987954562051724, 0.9972904566786902, 0.9951847266721969, 0.99247953459871, 0.989176509964781, 0.9852776423889412, 0.9807852804032304, 0.9757021300385286, 0.970031253194544, 0.9637760657954398, 0.9569403357322089, 0.9495281805930367, 0.9415440651830208, 0.9329927988347388, 0.9238795325112867, 0.9142097557035307, 0.9039892931234434, 0.8932243011955152, 0.881921264348355, 0.8700869911087115, 0.8577286100002721, 0.8448535652497072, 0.8314696123025455, 0.8175848131515837, 0.8032075314806449, 0.7883464276266063, 0.7730104533627371, 0.7572088465064847, 0.740951125354959, 0.7242470829514669, 0.7071067811865476, 0.6895405447370671, 0.6715589548470186, 0.6531728429537766, 0.6343932841636455, 0.6152315905806269, 0.5956993044924335, 0.5758081914178454, 0.5555702330196022, 0.5349976198870972, 0.5141027441932218, 0.4928981922297841, 0.4713967368259979, 0.4496113296546069, 0.427555093430282, 0.4052413140049899, 0.3826834323650899, 0.3598950365349883, 0.3368898533922203, 0.3136817403988914, 0.2902846772544624, 0.2667127574748985, 0.2429801799032641, 0.21910124015687, 0.1950903220161286, 0.1709618887603012, 0.1467304744553618, 0.1224106751992163, 0.09801714032956083, 0.07356456359966773, 0.04906767432741797, 0.02454122852291233, 0.0, -0.02454122852291208, -0.04906767432741772, -0.0735645635996675, -0.09801714032956059, -0.1224106751992161, -0.1467304744553616, -0.170961888760301, -0.1950903220161284, -0.2191012401568698, -0.2429801799032638, -0.2667127574748983, -0.2902846772544621, -0.3136817403988912, -0.3368898533922201, -0.3598950365349881, -0.3826834323650897, -0.4052413140049897, -0.4275550934302818, -0.4496113296546067, -0.4713967368259976, -0.4928981922297839, -0.5141027441932216, -0.5349976198870969, -0.555570233019602, -0.5758081914178453, -0.5956993044924332, -0.6152315905806267, -0.6343932841636453, -0.6531728429537765, -0.6715589548470184, -0.6895405447370668, -0.7071067811865475, -0.7242470829514668, -0.7409511253549589, -0.7572088465064842, -0.7730104533627367, -0.7883464276266059, -0.8032075314806451, -0.8175848131515838, -0.8314696123025452, -0.844853565249707, -0.857728610000272, -0.8700869911087113, -0.8819212643483549, -0.8932243011955152, -0.9039892931234431, -0.9142097557035305, -0.9238795325112865, -0.932992798834739, -0.9415440651830208, -0.9495281805930367, -0.9569403357322088, -0.9637760657954398, -0.970031253194544, -0.9757021300385285, -0.9807852804032303, -0.9852776423889411, -0.9891765099647809, -0.9924795345987101, -0.9951847266721969, -0.9972904566786902, -0.9987954562051724, -0.9996988186962042, -1.0, -0.9996988186962042, -0.9987954562051724, -0.9972904566786902, -0.9951847266721969, -0.9924795345987101, -0.9891765099647809, -0.9852776423889412, -0.9807852804032304, -0.9757021300385286, -0.970031253194544, -0.96377606579544, -0.9569403357322089, -0.9495281805930368, -0.9415440651830209, -0.9329927988347391, -0.9238795325112866, -0.9142097557035306, -0.9039892931234433, -0.8932243011955153, -0.881921264348355, -0.8700869911087115, -0.8577286100002722, -0.8448535652497072, -0.8314696123025455, -0.817584813151584, -0.8032075314806453, -0.7883464276266061, -0.7730104533627369, -0.7572088465064846, -0.7409511253549591, -0.724247082951467, -0.7071067811865477, -0.6895405447370672, -0.6715589548470187, -0.6531728429537771, -0.6343932841636459, -0.6152315905806274, -0.5956993044924332, -0.5758081914178452, -0.5555702330196022, -0.5349976198870973, -0.5141027441932219, -0.4928981922297843, -0.4713967368259979, -0.449611329654607, -0.4275550934302825, -0.4052413140049904, -0.3826834323650904, -0.359895036534988, -0.33688985339222, -0.3136817403988915, -0.2902846772544625, -0.2667127574748986, -0.2429801799032642, -0.2191012401568702, -0.1950903220161287, -0.1709618887603018, -0.1467304744553624, -0.122410675199216, -0.09801714032956051, -0.07356456359966741, -0.04906767432741809, -0.02454122852291245) TAN_TABLE := [f32].(0.0, 0.01227246237956628, 0.02454862210892544, 0.03683218099484564, 0.04912684976946725, 0.06143635258159376, 0.07376443152244928, 0.08611485119762791, 0.09849140335716425, 0.110897911595913, 0.1233382361367387, 0.1358162787093877, 0.1483359875383474, 0.1609013624534892, 0.1735164601378558, 0.1861853995275837, 0.198912367379658, 0.2117016240239833, 0.2245575093171293, 0.2374844488160702, 0.2504869601913055, 0.263569659899918, 0.2767372701404143, 0.2899946261126061, 0.3033466836073424, 0.3167985269526038, 0.330355377344334, 0.3440226015924263, 0.3578057213145241, 0.3717104226127435, 0.3857425662711212, 0.3999081985145372, 0.414213562373095, 0.4286651096994995, 0.4432695138908643, 0.4580336833706724, 0.4729647758913199, 0.4880702137228629, 0.5033576997992942, 0.5188352348999757, 0.5345111359507916, 0.5503940555372639, 0.566493002730344, 0.5828173653349761, 0.5993769336819237, 0.616181926094866, 0.6332430161775691, 0.6505713620801533, 0.6681786379192989, 0.6860770675448629, 0.7042794608650442, 0.7227992529642059, 0.7416505462720354, 0.7608481560702512, 0.7804076596539435, 0.8003454494993202, 0.8206787908286602, 0.8414258840072547, 0.8626059322567399, 0.8842392152253498, 0.906347169019147, 0.9289524733703675, 0.9520791467009252, 0.9757526499323765, 0.9999999999999999, 1.024849894150227, 1.05033284623986, 1.076481336415266, 1.103329975733476, 1.130915687498827, 1.159277907333434, 1.188458804282966, 1.218503525587976, 1.249460468133579, 1.281381580036554, 1.31432269635108, 1.34834391348672, 1.383510007652874, 1.419890903494092, 1.457562200087105, 1.496605762665489, 1.537110389861882, 1.579172567960209, 1.622897325693455, 1.668399205583507, 1.715803370795664, 1.765246870094191, 1.816880087892402, 1.870868411789389, 1.927394156630064, 1.986658792343365, 2.04888553303075, 2.11432235754864, 2.183245547884151, 2.255963851929159, 2.33282340310135, 2.414213562373095, 2.500573890994256, 2.592402517738071, 2.690266237279613, 2.794812772490477, 2.906785761665535, 3.027043204317773, 3.156580333940787, 3.296558208938321, 3.448339762033025, 3.613535681307428, 3.7940634000883, 3.992223783770083, 4.210802033502797, 4.453202224414411, 4.723629327882301, 5.027339492125846, 5.370990435003726, 5.763142005118804, 6.21498777108904, 6.741452405414988, 7.362887641324242, 8.107785803676903, 9.017302360424724, 10.15317038760884, 11.61239886143525, 13.55666924235242, 16.27700795993539, 20.35546762498714, 27.15017066569958, 40.73548387208334, 81.48324020654604, 1633123935319537.0, -81.48324020654685, -40.73548387208354, -27.15017066569967, -20.35546762498719, -16.27700795993542, -13.55666924235244, -11.61239886143527, -10.15317038760886, -9.017302360424734, -8.10778580367691, -7.362887641324249, -6.741452405414994, -6.214987771089044, -5.763142005118809, -5.37099043500373, -5.02733949212585, -4.723629327882303, -4.453202224414413, -4.2108020335028, -3.992223783770084, -3.794063400088302, -3.61353568130743, -3.448339762033026, -3.296558208938323, -3.156580333940789, -3.027043204317775, -2.906785761665536, -2.794812772490478, -2.690266237279614, -2.592402517738072, -2.500573890994257, -2.414213562373095, -2.332823403101351, -2.25596385192916, -2.183245547884153, -2.114322357548642, -2.048885533030752, -1.986658792343365, -1.927394156630064, -1.870868411789389, -1.816880087892402, -1.765246870094192, -1.715803370795664, -1.668399205583508, -1.622897325693455, -1.57917256796021, -1.537110389861883, -1.49660576266549, -1.457562200087105, -1.419890903494092, -1.383510007652874, -1.34834391348672, -1.31432269635108, -1.281381580036555, -1.249460468133579, -1.218503525587977, -1.188458804282967, -1.159277907333435, -1.130915687498827, -1.103329975733476, -1.076481336415266, -1.05033284623986, -1.024849894150228, -1.0, -0.9757526499323768, -0.9520791467009256, -0.9289524733703679, -0.9063471690191476, -0.8842392152253504, -0.8626059322567398, -0.8414258840072547, -0.8206787908286604, -0.8003454494993202, -0.7804076596539438, -0.7608481560702515, -0.7416505462720356, -0.7227992529642062, -0.7042794608650446, -0.6860770675448633, -0.6681786379192988, -0.6505713620801532, -0.6332430161775691, -0.6161819260948661, -0.5993769336819238, -0.5828173653349762, -0.5664930027303442, -0.5503940555372643, -0.5345111359507919, -0.5188352348999761, -0.5033576997992947, -0.4880702137228627, -0.4729647758913199, -0.4580336833706724, -0.4432695138908644, -0.4286651096994996, -0.4142135623730952, -0.3999081985145373, -0.3857425662711215, -0.3717104226127437, -0.3578057213145244, -0.3440226015924267, -0.3303553773443338, -0.3167985269526037, -0.3033466836073424, -0.2899946261126062, -0.2767372701404144, -0.2635696598999182, -0.2504869601913056, -0.2374844488160704, -0.2245575093171296, -0.2117016240239837, -0.1989123673796584, -0.1861853995275837, -0.1735164601378557, -0.1609013624534892, -0.1483359875383475, -0.1358162787093878, -0.1233382361367388, -0.1108979115959132, -0.09849140335716448, -0.08611485119762818, -0.0737644315224496, -0.06143635258159368, -0.04912684976946721, -0.03683218099484564, -0.02454862210892548, -0.01227246237956636) -$TABLE_SIZE := @as(i32, @sizeof(@TypeOf(SIN_TABLE)) / @sizeof(f32)) +$TABLE_SIZE := @sizeof(@TypeOf(SIN_TABLE)) / @sizeof(f32) sin := fn(theta: f32): f32 { si := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) - d := theta - @floatcast(@itf(si)) * 2.0 * PI / @floatcast(@itf(TABLE_SIZE)) + d := theta - @itf(si) * 2.0 * PI / TABLE_SIZE ci := si + TABLE_SIZE / 4 & TABLE_SIZE - 1 si &= TABLE_SIZE - 1 return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d @@ -67,7 +74,7 @@ sin := fn(theta: f32): f32 { cos := fn(theta: f32): f32 { ci := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) - d := theta - @floatcast(@itf(ci)) * 2.0 * PI / @floatcast(@itf(TABLE_SIZE)) + d := theta - @itf(ci) * 2.0 * PI / TABLE_SIZE si := ci + TABLE_SIZE / 4 & TABLE_SIZE - 1 ci &= TABLE_SIZE - 1 return SIN_TABLE[@bitcast(si)] - (SIN_TABLE[@bitcast(ci)] + 0.5 * SIN_TABLE[@bitcast(si)] * d) * d @@ -75,20 +82,20 @@ cos := fn(theta: f32): f32 { tan := fn(theta: f32): f32 { a := @fti(theta * @itf(TABLE_SIZE) / PI) - d := theta - @floatcast(@itf(a)) * PI / @itf(TABLE_SIZE) + d := theta - @itf(a) * PI / TABLE_SIZE d = d + 1.0 / 3.0 * d * d * d a &= TABLE_SIZE - 1 return (TAN_TABLE[@bitcast(a)] + d) / (1.0 - TAN_TABLE[@bitcast(a)] * d) } exp := fn($T: type, x: T): T { - if T == f64 | T == f32 { + if float(T) { result := @as(T, 1.0) term := @as(T, 1.0) n := @as(int, 1) loop if n == 20 break else { - term = term * x / @floatcast(@itf(n)) + term = term * x / @itf(n) result += term if abs(T, term) < 0.0000000001 break @@ -100,7 +107,7 @@ exp := fn($T: type, x: T): T { } ln := fn($T: type, x: T): T { - if T == f64 | T == f32 { + if float(T) { if x <= 0.0 return -100000000000000000000000.0 if x == 1.0 return 0.0 if x == E return 1.0 diff --git a/sysdata/libraries/stn/src/sleep.hb b/sysdata/libraries/stn/src/sleep.hb index 5aeaf14..3beec5e 100644 --- a/sysdata/libraries/stn/src/sleep.hb +++ b/sysdata/libraries/stn/src/sleep.hb @@ -1,7 +1,7 @@ -subscribe_to_interrupt := fn(interrupt_number: u8): bool { +$subscribe_to_interrupt := fn(interrupt_number: u8): bool { return false } // 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) } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/mandelbrot.hb b/sysdata/programs/render_example/src/examples/mandelbrot.hb index fa11b61..8180097 100644 --- a/sysdata/programs/render_example/src/examples/mandelbrot.hb +++ b/sysdata/programs/render_example/src/examples/mandelbrot.hb @@ -22,6 +22,11 @@ palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_G $LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color) 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) window := @as(?sunset.Window, null) if USE_SUNSET { @@ -66,15 +71,15 @@ example := fn(): void { if iteration < MAX_ITERATION { log_zn := math.ln(f64, x * x + y * y) / 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) normalised := smoothed - @itf(smoothed_int) colour0 := palette[@bitcast(smoothed_int) % LEN_PALETTE] colour1 := palette[@bitcast(smoothed_int + 1) % LEN_PALETTE] colour := render.Color.{ - r: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.r)), @itf(@intcast(colour1.r)), normalised))), - g: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.g)), @itf(@intcast(colour1.g)), normalised))), - b: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.b)), @itf(@intcast(colour1.b)), normalised))), + r: @intcast(@fti(math.lerp(f64, @itf(colour0.r), @itf(colour1.r), normalised))), + g: @intcast(@fti(math.lerp(f64, @itf(colour0.g), @itf(colour1.g), normalised))), + b: @intcast(@fti(math.lerp(f64, @itf(colour0.b), @itf(colour1.b), normalised))), a: 0, } screen.put_pixel(.(px, py), colour) @@ -82,8 +87,8 @@ example := fn(): void { px += 1 } py += 1 - } - if USE_SUNSET loop { - _ = sunset.client.send_frame(window) + if USE_SUNSET { + _ = sunset.client.send_frame(window) + } } } \ No newline at end of file