hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 15:47:03 +0200
committerhachem <im@hachem.wtf>2026-09-19 15:47:03 +0200
commit6d8b0392bb0c0df82285eec1b0f692113e66eb1a (patch)
treec08fde36b934b759b1255bac33dc69ae1adf7169 /eval.c
parente5cc80fb6a608aa1fbd0d6fabd1cf614a0fc004a (diff)
feat: enable_if
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index cb967c2..3f27fa2 100644
--- a/eval.c
+++ b/eval.c
@@ -254,6 +254,18 @@ static enum RunStatus emit(struct Machine* machine, const struct Node* node)
return RUN_DONE;
}
+static enum RunStatus enable_if(struct Machine* machine, const struct Node* node)
+{
+ bool truth = false;
+ if (evaluate_condition(machine, node->first, &truth))
+ return RUN_FAILED;
+
+ if (!truth)
+ return RUN_DONE;
+
+ return execute(machine, node->body);
+}
+
static enum RunStatus static_assert_statement(struct Machine* machine, const struct Node* node)
{
bool truth = false;
@@ -275,6 +287,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_EMIT: return emit(machine, node);
case STMT_STATIC_ASSERT: return static_assert_statement(machine, node);
default: break;