hex literals

This commit is contained in:
2025-11-11 14:29:55 +01:00
parent 46045af4fa
commit 1e98d9d706
3 changed files with 43 additions and 18 deletions

View File

@@ -2,10 +2,10 @@
A very cool language
## Huh?
## Features
* Clean indentation-based syntax
* Compiles to x86_64 Assembly
* Almost works
* Sometimes works
* Has the pipe operator
## Syntax

View File

@@ -4,17 +4,39 @@ func main[] : I64
let rl: Ptr = c.dlopen("libraylib.so", 2)
let rl.InitWindow: Ptr = c.dlsym(rl, "InitWindow")
let rl.SetTargetFPS: Ptr = c.dlsym(rl, "SetTargetFPS")
let rl.WindowShouldClose: Ptr = c.dlsym(rl, "WindowShouldClose")
let rl.BeginDrawing: Ptr = c.dlsym(rl, "BeginDrawing")
let rl.EndDrawing: Ptr = c.dlsym(rl, "EndDrawing")
let rl.ClearBackground: Ptr = c.dlsym(rl, "ClearBackground")
let rl.CloseWindow: Ptr = c.dlsym(rl, "CloseWindow")
let rl.DrawRectangle: Ptr = c.dlsym(rl, "DrawRectangle")
let rl.IsKeyDown: Ptr = c.dlsym(rl, "IsKeyDown")
let rl.KEY_W: I64 = 87
let rl.KEY_S: I64 = 83
let rl.KEY_A: I64 = 65
let rl.KEY_D: I64 = 68
let x: I64 = 200
let y: I64 = 200
rl.InitWindow(800, 600, "Hello, World!")
rl.SetTargetFPS(60)
while !rl.WindowShouldClose()
if rl.IsKeyDown(rl.KEY_W) & 255
y = y - 10
if rl.IsKeyDown(rl.KEY_S) & 255
y = y + 10
if rl.IsKeyDown(rl.KEY_A) & 255
x = x - 10
if rl.IsKeyDown(rl.KEY_D) & 255
x = x + 10
rl.BeginDrawing()
rl.ClearBackground(4278190335) // 0xff0000ff
rl.ClearBackground(0xffffffff)
rl.DrawRectangle(x, y, 100, 100, 0xff0000ff)
rl.EndDrawing()
rl.CloseWindow()

View File

@@ -232,7 +232,7 @@ impl Tokenizer {
self.advance();
self.add_token(TokenType::String);
}
' ' | '\t' | '\r' => {}
' ' | '\r' => {}
'\n' => {
self.loc.line += 1;
self.loc.column = 1;
@@ -294,29 +294,31 @@ impl Tokenizer {
}
fn scan_number(&mut self) {
while self.peek().is_ascii_digit() {
self.advance();
}
if self.peek() == '.'
&& (self.current + 1 >= self.source.len())
&& self.source[self.current + 1].is_ascii_digit()
{
self.advance();
if self.match_char('x') {
while self.peek().is_ascii_hexdigit() {
self.advance();
}
} else {
while self.peek().is_ascii_digit() {
self.advance();
}
if self.peek() == '.'
&& self.current + 1 < self.source.len()
&& self.source[self.current + 1].is_ascii_digit()
{
self.advance();
while self.peek().is_ascii_digit() {
self.advance();
}
}
}
self.add_token(TokenType::Number);
}
fn scan_identifier(&mut self) {
while self.peek().is_alphanumeric()
|| self.peek() == '_'
|| self.peek() == '.'
|| self.peek() == '!'
{
while self.peek().is_alphanumeric() || self.peek() == '_' || self.peek() == '.' {
self.advance();
}
@@ -343,6 +345,7 @@ impl Tokenizer {
false
} else {
self.current += 1;
self.loc.column += 1;
true
}
}