aboutsummaryrefslogtreecommitdiff
path: root/repl.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-31 13:13:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-31 13:13:08 -0400
commitb6534ce34706d1a98584e5f916107d91da072346 (patch)
treedfb8578405cb0bf02fa573a344f0d0542e25599a /repl.c
parent56a44684faa9f91f5d5a794c3413ddd7dca93ca1 (diff)
Implement REPL 'while'
Diffstat (limited to 'repl.c')
-rw-r--r--repl.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/repl.c b/repl.c
index b458f08c..d6c8676f 100644
--- a/repl.c
+++ b/repl.c
@@ -299,6 +299,21 @@ void run(env_t *env, ast_t *ast)
}
break;
}
+ case While: {
+ auto while_ = Match(ast, While);
+ bool condition;
+ type_t *cond_t = get_type(env, while_->condition);
+ assert(cond_t->tag == BoolType);
+ for (;;) {
+ eval(env, while_->condition, &condition);
+ if (!condition) break;
+ run(env, while_->body);
+ }
+ break;
+ }
+ // case For: {
+ // auto for_ = Match(ast, For);
+ // }
default: {
eval(env, ast, NULL);
break;