aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-17 15:59:06 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-17 15:59:06 -0400
commit46ee3fc0efc60c3af47c92390d207ce843671b5b (patch)
treeca8804edb1f610463b9e237ae7d1a4d8fbec54f7 /compile.c
parentccba8abf731fc9b796cfaee2776cddd516e8775d (diff)
Temporary fix for newlines between statements
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c10
1 files changed, 9 insertions, 1 deletions
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);