From be43ea893018090044cd411bc5b50787b99087b8 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 15:51:57 +0200 Subject: feat: add reapts and loops --- eval.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 3f27fa2..2f79a5d 100644 --- a/eval.c +++ b/eval.c @@ -266,6 +266,23 @@ static enum RunStatus enable_if(struct Machine* machine, const struct Node* node return execute(machine, node->body); } +// runs the body count times. no index, no condition, no break. you wanted a loop +static enum RunStatus repeat(struct Machine* machine, const struct Node* node) +{ + int64_t count = 0; + if (evaluate_value(machine, node->first, &count)) + return RUN_FAILED; + + for (int64_t index = 0; index < count; index++) + { + enum RunStatus status = execute(machine, node->body); + if (status != RUN_DONE) + return status; + } + + return RUN_DONE; +} + static enum RunStatus static_assert_statement(struct Machine* machine, const struct Node* node) { bool truth = false; @@ -288,6 +305,7 @@ static enum RunStatus execute_one(struct Machine* machine, const struct Node* no case STMT_DECLARE: return declare(machine, node); case STMT_UNDECLARE: return undeclare(machine, node); case STMT_ENABLE_IF: return enable_if(machine, node); + case STMT_REPEAT: return repeat(machine, node); case STMT_EMIT: return emit(machine, node); case STMT_STATIC_ASSERT: return static_assert_statement(machine, node); default: break; -- cgit v1.3