Anonymous avatar Anonymous committed f6ef704

Added ctx to tuples and fixed for loop compilation from ast.

Comments (0)

Files changed (3)

 }
 
 ArExprNode *
-arana_ast_Tuple(AR_SIG, ArExprSeq *items)
+arana_ast_Tuple(AR_SIG, ArExprSeq *items, ArAstCtx ctx)
 {
-    AR_EXPR_NODE_INIT1(Tuple, items);
+    AR_EXPR_NODE_INIT2(Tuple, items, ctx);
 }
 
 ArExprNode *
         if (seq->free == 0) {                                           \
             seq = AR_REALLOCTE(seq, Ar##tp##Seq,                        \
                                sizeof(ArAstNode *)*(seq->count*2));     \
-            if (!seq) arana_out_of_memory(ps->AI, ps->CF);               \
+            if (!seq) arana_out_of_memory(ps->AI, ps->CF);              \
             seq->free = seq->count;                                     \
             seq->count *= 2;                                            \
         }                                                               \
         target = seq;                                                   \
     }
 
-#define AR_AST_MAYBE_TUPLE(target, seq) {                               \
+#define AR_AST_MAYBE_TUPLE(target, seq, ctx) {                          \
         if (seq->count == 1) {                                          \
             target = seq->items[0];                                     \
         } else {                                                        \
-            target = AR_AST(Tuple, seq);                                \
+            target = AR_AST(Tuple, seq, ctx);                           \
         }                                                               \
     }
 
 AR_API_FUNC(ArExprNode *) arana_ast_Subscript(AR_SIG, ArExprNode *expr,
                                               ArExprNode *index, ArAstCtx ctx);
 AR_API_FUNC(ArExprNode *) arana_ast_List(AR_SIG, ArExprSeq *items);
-AR_API_FUNC(ArExprNode *) arana_ast_Tuple(AR_SIG, ArExprSeq *items);
+AR_API_FUNC(ArExprNode *) arana_ast_Tuple(AR_SIG, ArExprSeq *items, ArAstCtx ctx);
 AR_API_FUNC(ArExprNode *) arana_ast_Interpolation(AR_SIG, ArExprSeq *items);
 AR_API_FUNC(ArExprNode *) arana_ast_Name(AR_SIG, const char *ident, ArAstCtx ctx);
 AR_API_FUNC(ArExprNode *) arana_ast_Literal(AR_SIG, AR value);
 %type small_stmts  { ArStmtSeq * }
 %type small_stmt   { ArStmtNode * }
 %type expr         { ArExprNode * }
+%type assexpr      { ArExprNode * }
 %type interp_items { ArExprSeq * }
 %type interp_item  { ArExprNode * }
 %type exprlist     { ArExprSeq * }
 
 statement(A) ::= IF expr(B) suite(C) ELSE suite(D). { A = AR_AST(If, B, C, D); }
 statement(A) ::= IF expr(B) suite(C).            { A = AR_AST(If, B, C, NULL); }
-statement(A) ::= FOR expr(B) IN expr(C) suite(D).  { A = AR_AST(For, B, C, D); }
+statement(A) ::= FOR assexpr(B) IN expr(C) suite(D).
+						   { A = AR_AST(For, B, C, D); }
 //statement(A) ::= DEF NAME(B) LPAREN arglist(C) RPAREN suite(D).
 //                               { A = AR_AST(def_stmt, AR_AS_CHARP(B), C, D); }
 statement(A) ::= small_stmts(B).                    { A = AR_AST(Compound, B); }
 
 small_stmt(A) ::= PASS.                          { A = AR_AST(Compound, NULL); }
 small_stmt(A) ::= exprlist(B).
-     { ArExprNode *tmp; AR_AST_MAYBE_TUPLE(tmp, B); A = AR_AST(ExprStmt, tmp); }
-small_stmt(A) ::= exprlist(B) COMMA. { A = AR_AST(ExprStmt, AR_AST(Tuple, B)); }
+                   { ArExprNode *tmp; AR_AST_MAYBE_TUPLE(tmp, B, AR_CTX_Load);
+                                                    A = AR_AST(ExprStmt, tmp); }
+small_stmt(A) ::= exprlist(B) COMMA.
+                        { A = AR_AST(ExprStmt, AR_AST(Tuple, B, AR_CTX_Load)); }
+
+// assignment expressions
+assexpr(A) ::= NAME(B).      { A = AR_AST(Name, AR_AS_CHARP(B), AR_CTX_Store); }
+assexpr(A) ::= expr(B) DOT NAME(C).
+                 { A = AR_AST(Attribute, B, AR_AST(Literal, C), AR_CTX_Store); }
+assexpr(A) ::= expr(B) DOT LBRACKET expr(C) RBRACKET.
+                                  { A = AR_AST(Attribute, B, C, AR_CTX_Store); }
+assexpr(A) ::= LPAREN RPAREN.         { A = AR_AST(Tuple, NULL, AR_CTX_Store); }
+assexpr(A) ::= LPAREN exprlist(B) RPAREN.
+                                     { AR_AST_MAYBE_TUPLE(A, B, AR_CTX_Store); }
+assexpr(A) ::= LPAREN exprlist(B) COMMA RPAREN.
+                                         { A = AR_AST(Tuple, B, AR_CTX_Store); }
 
 // simple expressions (literals and names)
 expr(A) ::= CONST(B).                                { A = AR_AST(Literal, B); }
                                    { A = AR_AST(Attribute, B, C, AR_CTX_Load); }
 
 // calls
-expr(A) ::= expr(B) LPAREN RPAREN. { A = AR_AST(Call, B, AR_AST(Tuple, NULL)); }
+expr(A) ::= expr(B) LPAREN RPAREN.
+                      { A = AR_AST(Call, B, AR_AST(Tuple, NULL, AR_CTX_Load)); }
 expr(A) ::= expr(B) LPAREN exprlist(C) RPAREN.
-                                      { A = AR_AST(Call, B, AR_AST(Tuple, C)); }
+                         { A = AR_AST(Call, B, AR_AST(Tuple, C, AR_CTX_Load)); }
 expr(A) ::= expr(B) LPAREN exprlist(C) COMMA RPAREN.
-                                      { A = AR_AST(Call, B, AR_AST(Tuple, C)); }
+                         { A = AR_AST(Call, B, AR_AST(Tuple, C, AR_CTX_Load)); }
 
 // tuple displays (or grouping)
-expr(A) ::= LPAREN RPAREN.                          { A = AR_AST(Tuple, NULL); }
-expr(A) ::= LPAREN exprlist(B) RPAREN.             { AR_AST_MAYBE_TUPLE(A, B); }
-expr(A) ::= LPAREN exprlist(B) COMMA RPAREN.           { A = AR_AST(Tuple, B); }
+expr(A) ::= LPAREN RPAREN.             { A = AR_AST(Tuple, NULL, AR_CTX_Load); }
+expr(A) ::= LPAREN exprlist(B) RPAREN.
+                                      { AR_AST_MAYBE_TUPLE(A, B, AR_CTX_Load); }
+expr(A) ::= LPAREN exprlist(B) COMMA RPAREN.
+                                          { A = AR_AST(Tuple, B, AR_CTX_Load); }
 
 // list displays
 expr(A) ::= LBRACKET RBRACKET.                       { A = AR_AST(List, NULL); }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.