diff --git a/include/pocketpy/compiler.h b/include/pocketpy/compiler.h index 42c3bc8b..ea7cf561 100644 --- a/include/pocketpy/compiler.h +++ b/include/pocketpy/compiler.h @@ -69,23 +69,7 @@ class Compiler { return expr; } - template - void _consume_comp(Expr_ expr){ - static_assert(std::is_base_of::value); - unique_ptr_128 ce = make_expr(); - ce->expr = std::move(expr); - ce->vars = EXPR_VARS(); - consume(TK("in")); - parse_expression(PREC_TERNARY + 1); - ce->iter = ctx()->s_expr.popx(); - match_newlines_repl(); - if(match(TK("if"))){ - parse_expression(PREC_TERNARY + 1); - ce->cond = ctx()->s_expr.popx(); - } - ctx()->s_expr.push(std::move(ce)); - match_newlines_repl(); - } + void consume_comp(unique_ptr_128 ce, Expr_ expr); void exprLiteral(); void exprLong(); diff --git a/src/compiler.cpp b/src/compiler.cpp index dd4fb3cd..c669e355 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -311,6 +311,21 @@ namespace pkpy{ ctx()->s_expr.push(std::move(g)); } + void Compiler::consume_comp(unique_ptr_128 ce, Expr_ expr){ + ce->expr = std::move(expr); + ce->vars = EXPR_VARS(); + consume(TK("in")); + parse_expression(PREC_TERNARY + 1); + ce->iter = ctx()->s_expr.popx(); + match_newlines_repl(); + if(match(TK("if"))){ + parse_expression(PREC_TERNARY + 1); + ce->cond = ctx()->s_expr.popx(); + } + ctx()->s_expr.push(std::move(ce)); + match_newlines_repl(); + } + void Compiler::exprList() { int line = prev().line; Expr_vector items; @@ -321,7 +336,7 @@ namespace pkpy{ items.push_back(ctx()->s_expr.popx()); match_newlines_repl(); if(items.size()==1 && match(TK("for"))){ - _consume_comp(std::move(items[0])); + consume_comp(make_expr(), std::move(items[0])); consume(TK("]")); return; } @@ -361,8 +376,8 @@ namespace pkpy{ } match_newlines_repl(); if(items.size()==1 && match(TK("for"))){ - if(parsing_dict) _consume_comp(std::move(items[0])); - else _consume_comp(std::move(items[0])); + if(parsing_dict) consume_comp(make_expr(), std::move(items[0])); + else consume_comp(make_expr(), std::move(items[0])); consume(TK("}")); return; }