diff options
| author | hachem <im@hachem.wtf> | 2026-09-19 15:51:57 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-19 15:51:57 +0200 |
| commit | be43ea893018090044cd411bc5b50787b99087b8 (patch) | |
| tree | 379af1300ee53afa0a7029835257f254aaccfce2 /eval.c | |
| parent | 6d8b0392bb0c0df82285eec1b0f692113e66eb1a (diff) | |
feat: add reapts and loops
Diffstat (limited to 'eval.c')
| -rw-r--r-- | eval.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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; |
