From af0ae49abe0c11d1b33b8830e379e412877d3ef5 Mon Sep 17 00:00:00 2001 From: Toni Date: Thu, 12 Feb 2026 14:10:42 +0100 Subject: [PATCH] consts in raylib.zr --- examples/raylib.zr | 20 ++++++++++++++------ src/parser.rs | 2 +- src/std/crypto.zr | 2 ++ src/std/std.zr | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/raylib.zr b/examples/raylib.zr index e56124d..4850485 100644 --- a/examples/raylib.zr +++ b/examples/raylib.zr @@ -9,6 +9,14 @@ extern CloseWindow extern DrawRectangle extern IsKeyDown +const KEY_W = 87 +const KEY_S = 83 +const KEY_A = 65 +const KEY_D = 68 + +const WHITE = 0xffffffff +const RED = 0xff0000ff + func main[] : i64 let x = 200 let y = 200 @@ -17,18 +25,18 @@ func main[] : i64 SetTargetFPS(60) while !WindowShouldClose() - if IsKeyDown(87) & 255 // W + if IsKeyDown(KEY_W) & 255 y = y - 10 - if IsKeyDown(83) & 255 // S + if IsKeyDown(KEY_S) & 255 y = y + 10 - if IsKeyDown(65) & 255 // A + if IsKeyDown(KEY_A) & 255 x = x - 10 - if IsKeyDown(68) & 255 // D + if IsKeyDown(KEY_D) & 255 x = x + 10 BeginDrawing() - ClearBackground(0xffffffff) - DrawRectangle(x, y, 100, 100, 0xff0000ff) + ClearBackground(WHITE) + DrawRectangle(x, y, 100, 100, RED) EndDrawing() CloseWindow() \ No newline at end of file diff --git a/src/parser.rs b/src/parser.rs index a7e2095..8135faa 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -86,7 +86,7 @@ pub enum Expr { }, } -// TODO: currently they are all just 8 byte values +// TODO: currently they are all just 64 bit values static TYPES: [&str; 7] = ["void", "u8", "i64", "str", "bool", "ptr", "array"]; pub struct Parser { diff --git a/src/std/crypto.zr b/src/std/crypto.zr index 6f4982d..5d97dd7 100644 --- a/src/std/crypto.zr +++ b/src/std/crypto.zr @@ -1,3 +1,5 @@ +// absolutely not production-ready + func crypto.rotl32[x: i64, r: i64] : i64 return ((x << r) | (x >> (32 - r))) & 0xffffffff diff --git a/src/std/std.zr b/src/std/std.zr index 2fd7c8c..f60ad93 100644 --- a/src/std/std.zr +++ b/src/std/std.zr @@ -6,7 +6,7 @@ extern gethostbyname func dbg.panic[msg: str] : void io.print("PANIC: ") io.println(msg) - 0/0 // crashes program which is kinda better since you get a gdb backtrace + (0 / 0) // crashes program which is kinda better since you get a gdb backtrace os.exit(1) func mem.alloc[x: i64] : ptr