ox

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

commit a4527f8fdf4c864e58624e0e02cad82be7d98f3d
parent 70df24632c5c680d8a28573b70124bf8349b3ff6
Author: citbl <citbl@citbl.org>
Date:   Mon, 27 Oct 2025 22:35:18 +1000

infinite for loops and break tested

Diffstat:
MTODO | 2+-
Aex-for-advanced1.ox | 13+++++++++++++
Aex-for-advanced2.ox | 13+++++++++++++
Rex9.ox -> ex-for-simple3.ox | 0
Mex6.ox | 3++-
Dex7.ox | 9---------
Msrc/gen/gen.c | 2+-
7 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/TODO b/TODO @@ -9,12 +9,12 @@ [ ] 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 +[ ] if without { } should be an error, e.g. `if(true) break;` doesn't work @later [-] implement all or most of C's into libgccjit [-] ARC memory management, new keyword. - @cruft [x] redo arguments as list and not linked list, handle in parse and in gen (2 places in gen?) diff --git a/ex-for-advanced1.ox b/ex-for-advanced1.ox @@ -0,0 +1,13 @@ +// infinite loop break test + +void main() { + int a = 1; + for(;;) { + print("working"); + if (a == 1) { + break; + } + print("never get here"); + } + print("finished"); +} diff --git a/ex-for-advanced2.ox b/ex-for-advanced2.ox @@ -0,0 +1,13 @@ +// infinite loop break test + +void main() { + int a = 1; + for(;;) { + print("working"); + if (a++ == 5) { + break; + } + print("... not yet"); + } + print("finished"); +} diff --git a/ex9.ox b/ex-for-simple3.ox diff --git a/ex6.ox b/ex6.ox @@ -1,7 +1,8 @@ // simple loop int main() { - for (int a = 0; b < 10; c++) { + for (int a = 0; a < 10; a++) { + print(a); print("hi"); } } diff --git a/ex7.ox b/ex7.ox @@ -1,9 +0,0 @@ -// infinite loop break test - -int main() { - int a = 1; - for(;;) { - if (a == 1) break; - continue 7; // TODO fix this test to fail semantics - } -} diff --git a/src/gen/gen.c b/src/gen/gen.c @@ -629,7 +629,7 @@ build_for_statement(Gen* gen, Node* node) gen->curr_block = step_block; if (step) { build_statement(gen, step); } - gcc_jit_block_end_with_jump(step_block, loc, cond_block); + gcc_jit_block_end_with_jump(step_block, loc, cond != NULL ? cond_block : body_block); // resume after loop