From e5880b46165f0756f8d5589626ea936271df2732 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 30 Mar 2024 13:24:39 -0400 Subject: REPL 'if' --- repl.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/repl.c b/repl.c index b289ff39..815b1cdb 100644 --- a/repl.c +++ b/repl.c @@ -326,7 +326,6 @@ void run(env_t *env, ast_t *ast) } // UpdateAssign, // FunctionDef, - // Block, // For, While, If, When, // Skip, Stop, Pass, // Return, @@ -336,6 +335,19 @@ void run(env_t *env, ast_t *ast) // Use, // LinkerDirective, // InlineCCode, + case If: { + auto if_ = Match(ast, If); + bool condition; + type_t *cond_t = get_type(env, if_->condition); + assert(cond_t->tag == BoolType); + eval(env, if_->condition, &condition); + if (condition) { + run(env, if_->body); + } else if (if_->else_body) { + run(env, if_->else_body); + } + break; + } default: { eval(env, ast, NULL); break; -- cgit v1.2.3