hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 15:51:57 +0200
committerhachem <im@hachem.wtf>2026-09-19 15:51:57 +0200
commitbe43ea893018090044cd411bc5b50787b99087b8 (patch)
tree379af1300ee53afa0a7029835257f254aaccfce2 /eval.c
parent6d8b0392bb0c0df82285eec1b0f692113e66eb1a (diff)
feat: add reapts and loops
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c18
1 files changed, 18 insertions, 0 deletions
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;