ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

commit ec33dbc9e1d4a9753753c7f8977d944023c862e6
parent bda5a5b3262aa69d3a1d569cc7364b3a0ff92b5a
Author: citbl <citbl@citbl.org>
Date:   Sun, 16 Nov 2025 18:46:33 +1000

fix * mul broken

Diffstat:
M.zed/debug.json | 2+-
MTODO | 12+++++++-----
Msrc/lexer.c | 2+-
Atests/ex-div.ox | 4++++
Atests/ex-mul.ox | 4++++
Atests/ex-return-given-expr.ox | 9+++++++++
Atests/ex-return-given-int.ox | 8++++++++
Atests/ex-return-int.ox | 8++++++++
8 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/.zed/debug.json b/.zed/debug.json @@ -11,7 +11,7 @@ "cwd": "$ZED_WORKTREE_ROOT" }, "program": "$ZED_WORKTREE_ROOT/oxc", - "args": ["$ZED_WORKTREE_ROOT/tests/ex-print-minus-values.ox"], + "args": ["$ZED_WORKTREE_ROOT/tests/ex-mul.ox"], "request": "launch", "adapter": "CodeLLDB" } diff --git a/TODO b/TODO @@ -4,11 +4,13 @@ [x] conditionals (basic) [x] loops (basic) [x] handle for loop with `i = i + 1` and `i += 1` (see ex-for-simple2 and TODO NODE_BINARY_EXPR) -[/] printing `-5` crashes, I think parsing is wrong for `-`, sees as value 5 -[ ] print allow format or more than 1 arg -[ ] print anything else than a string -[ ] call another function from main, that prints something, handle return see todo -[ ] call another function that prints the passed argument +[x] printing `-5` crashes, I think parsing is wrong for `-`, sees as value 5 +[x] print allow more than 1 arg +[/] handle return values +[ ] print allow format +[x] print anything else than a string +[x] call another function from main, that prints something, +[x] call another function that prints the passed argument [ ] if without { } should be an error, e.g. `if(true) break;` doesn't work @later diff --git a/src/lexer.c b/src/lexer.c @@ -200,7 +200,7 @@ next_token(Lexer* lex) break; case '*': nudge(lex); - type = TOKEN_UNKNOWN; + type = TOKEN_STAR; break; case '+': nudge(lex); diff --git a/tests/ex-div.ox b/tests/ex-div.ox @@ -0,0 +1,4 @@ +void main() { + print("expecting 6:"); + print(12 / 2); +} diff --git a/tests/ex-mul.ox b/tests/ex-mul.ox @@ -0,0 +1,4 @@ +void main() { + print("expected 25"); + print(5 * 5); +} diff --git a/tests/ex-return-given-expr.ox b/tests/ex-return-given-expr.ox @@ -0,0 +1,9 @@ +int gimme(int ret_value) { + int ret = ret_value + 2; + return ret; +} + +void main() { + print("expected returned value of 10 = 12 + 2 - 4:"); + print(gimme(6 + 6) - 4); +} diff --git a/tests/ex-return-given-int.ox b/tests/ex-return-given-int.ox @@ -0,0 +1,8 @@ +int gimme(int ret_value) { + return ret_value; +} + +void main() { + print("expected returned value of 12:"); + print(gimme(12)); +} diff --git a/tests/ex-return-int.ox b/tests/ex-return-int.ox @@ -0,0 +1,8 @@ +int gimme5() { + return 5; +} + +void main() { + print("expected returned value of 5:"); + print(gimme5()); +}