blueloveTH 2 anni fa
parent
commit
4d7b9d1c7c
2 ha cambiato i file con 8 aggiunte e 4 eliminazioni
  1. 7 4
      src/compiler.h
  2. 1 0
      src/expr.h

+ 7 - 4
src/compiler.h

@@ -359,21 +359,24 @@ private:
 
     // PASS
     void exprList() {
-        auto e = expr_prev_line<ListExpr>();
+        int line = prev().line;
+        std::vector<Expr_> items;
         do {
             match_newlines(mode()==REPL_MODE);
             if (curr().type == TK("]")) break;
             EXPR();
-            e->items.push_back(ctx()->s_expr.popx());
+            items.push_back(ctx()->s_expr.popx());
             match_newlines(mode()==REPL_MODE);
-            if(e->items.size()==1 && match(TK("for"))){
-                _consume_comp<ListCompExpr>(std::move(e->items[0]));
+            if(items.size()==1 && match(TK("for"))){
+                _consume_comp<ListCompExpr>(std::move(items[0]));
                 consume(TK("]"));
                 return;
             }
             match_newlines(mode()==REPL_MODE);
         } while (match(TK(",")));
         consume(TK("]"));
+        auto e = expr_prev_line<ListExpr>(std::move(items));
+        e->line = line;     // override line
         ctx()->s_expr.push(std::move(e));
     }
 

+ 1 - 0
src/expr.h

@@ -269,6 +269,7 @@ struct SliceExpr: Expr{
 
 struct SequenceExpr: Expr{
     std::vector<Expr_> items;
+    SequenceExpr(std::vector<Expr_>&& items): items(std::move(items)) {}
     virtual Opcode opcode() const = 0;
 
     void emit(CodeEmitContext* ctx) override {