ox

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

commit f41b35e364522e0b9aa87619da3333a985b834a4
parent b122311a62711c6b94802af4f578a176f8075463
Author: citbl <citbl@citbl.org>
Date:   Sun, 16 Nov 2025 19:59:59 +1000

handle single statement if conditions

Diffstat:
Msrc/gen/gen.c | 4++++
Mtests/ex-if-no-parens.ox | 15+++++++--------
2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/gen/gen.c b/src/gen/gen.c @@ -1050,6 +1050,10 @@ build_bool_value(Gen* gen, Node* node) static bool build_block(Gen* gen, Node* body) { + // TODO if there is no block ({ ... }), we presume there is only 1 statement. + // This might not always be valid, func declaration do require a block {}, but there might be cases... + if (body->data.block.len == 0) { return build_statement(gen, body); } + for (size_t i = 0; i < body->data.block.len; i++) { if (gen->curr_block == NULL) return true; bool ended = build_statement(gen, body->data.block.stmts[i]); diff --git a/tests/ex-if-no-parens.ox b/tests/ex-if-no-parens.ox @@ -1,11 +1,10 @@ void main() { - + print("we should print something:"); int i = 5; - - if (i > 5) { print("oops1"); } else { print("start"); } - if (i < 5) print("oops1"); - print("okay"); - if (i == 5) {print("this should work");} - if (i == 5) print("yay"); - print("huh? no yay?"); + if(i == 5) print("eureka!"); + print("ended block"); + if(i == 5) { + print("1"); + print("2"); + } }