From 46ee3fc0efc60c3af47c92390d207ce843671b5b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 17 Mar 2024 15:59:06 -0400 Subject: Temporary fix for newlines between statements --- compile.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 2f2bc4e3..178a7794 100644 --- a/compile.c +++ b/compile.c @@ -520,6 +520,8 @@ CORD compile_statement(env_t *env, ast_t *ast) } case For: { auto for_ = Match(ast, For); + // TODO: optimize case for iterating over comprehensions so we don't need to create + // an intermediary array/table type_t *iter_t = get_type(env, for_->iter); env_t *body_scope = for_scope(env, ast); loop_ctx_t loop_ctx = (loop_ctx_t){ @@ -1290,7 +1292,13 @@ CORD compile(env_t *env, ast_t *ast) } case Comprehension: { - code_err(ast, "Comprehensions cannot be compiled as expressions"); + ast_t *base = Match(ast, Comprehension)->expr; + while (base->tag == Comprehension) + base = Match(ast, Comprehension)->expr; + if (base->tag == TableEntry) + return compile(env, WrapAST(ast, Table, .entries=new(ast_list_t, .ast=ast))); + else + return compile(env, WrapAST(ast, Array, .items=new(ast_list_t, .ast=ast))); } case Lambda: { auto lambda = Match(ast, Lambda); -- cgit v1.2.3