From b6534ce34706d1a98584e5f916107d91da072346 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 31 Mar 2024 13:13:08 -0400 Subject: Implement REPL 'while' --- repl.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'repl.c') 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; -- cgit v1.2.3