From 28e83ea1bd390502e0204e233b283f5ede9f86c5 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Tue, 16 Aug 2022 15:39:46 +0530 Subject: [PATCH 1/8] Parse tuples in the comprehension for --- src/lpython/parser/parser.yy | 18 +++++++++++------- src/lpython/parser/semantics.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index ae7c41cede..70f4aaa7bb 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -811,13 +811,12 @@ tuple_list ; id_list - : id_list "," id { $$ = $1; LIST_ADD($$, $3); } - | id { LIST_NEW($$); LIST_ADD($$, $1); } + : id_list "," id_item { $$ = $1; LIST_ADD($$, $3); } + | id_item { LIST_NEW($$); LIST_ADD($$, $1); } ; id_item - : id_list { $$ = ID_TUPLE_01($1, @$); } - | id_list "," { $$ = ID_TUPLE_03($1, @$); } + : id { $$ = $1; } | "(" id ")" { $$ = $2; } | "(" id_list "," ")" { $$ = ID_TUPLE_03($2, @$); } | "(" id_list "," id ")" { $$ = ID_TUPLE_01(TUPLE_($2, $4), @$); } @@ -840,9 +839,14 @@ primary ; comp_for - : KW_FOR id_item KW_IN expr { $$ = COMP_FOR_01($2, $4, @$); } - | KW_FOR id_item KW_IN expr KW_IF expr { - $$ = COMP_FOR_02($2, $4, $6, @$); } + : KW_FOR id_list KW_IN expr { + $$ = COMP_FOR_01(ID_TUPLE_01($2, @$), $4, @$); } + | KW_FOR id_list "," KW_IN expr { + $$ = COMP_FOR_01(ID_TUPLE_03($2, @$), $5, @$); } + | KW_FOR id_list KW_IN expr KW_IF expr { + $$ = COMP_FOR_02(ID_TUPLE_01($2, @$), $4, $6, @$); } + | KW_FOR id_list "," KW_IN expr KW_IF expr { + $$ = COMP_FOR_02(ID_TUPLE_03($2, @$), $5, $7, @$); } ; comp_for_items diff --git a/src/lpython/parser/semantics.h b/src/lpython/parser/semantics.h index f07e1a153f..cf0bb337ff 100644 --- a/src/lpython/parser/semantics.h +++ b/src/lpython/parser/semantics.h @@ -820,7 +820,7 @@ static inline ast_t* ID_TUPLE_02(Allocator &al, Location &l, Vec elts) { #define ID_TUPLE_01(elts, l) ID_TUPLE_02(p.m_a, l, elts) #define ID_TUPLE_03(elts, l) make_Tuple_t(p.m_a, l, \ EXPRS(SET_EXPR_CTX_02(SET_CTX_02(elts, Store), Store)), elts.size(), \ - expr_contextType::Store); + expr_contextType::Store) #define LIST_COMP_1(expr, generators, l) make_ListComp_t(p.m_a, l, \ EXPR(expr), generators.p, generators.n) From 07842a3f8ff03d2b1a28f8eb8c04da44b50a7d33 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Tue, 16 Aug 2022 15:53:59 +0530 Subject: [PATCH 2/8] Rename tuple_list to slice_items --- src/lpython/parser/parser.yy | 64 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 70f4aaa7bb..3fb593ce22 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -231,6 +231,7 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %type dict %type dict_list %type slice_item +%type slice_items %type slice_item_list %type with_statement %type with_as_items @@ -766,26 +767,6 @@ while_statement $$ = WHILE_02($2, $4, $7, @$); } ; -slice_item_list - : slice_item_list "," slice_item { $$ = $1; LIST_ADD($$, $3); } - | slice_item { LIST_NEW($$); LIST_ADD($$, $1); } - -slice_item - : ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } - | expr ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } - | ":" expr { $$ = SLICE_01(nullptr, $2, nullptr, @$); } - | expr ":" expr { $$ = SLICE_01( $1, $3, nullptr, @$); } - | ":" ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } - | ":" ":" expr { $$ = SLICE_01(nullptr, nullptr, $3, @$); } - | expr ":" ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } - | ":" expr ":" { $$ = SLICE_01(nullptr, $2, nullptr, @$); } - | expr ":" ":" expr { $$ = SLICE_01( $1, nullptr, $4, @$); } - | ":" expr ":" expr { $$ = SLICE_01(nullptr, $2, $4, @$); } - | expr ":" expr ":" { $$ = SLICE_01( $1, $3, nullptr, @$); } - | expr ":" expr ":" expr { $$ = SLICE_01( $1, $3, $5, @$); } - | expr { $$ = $1; } - ; - expr_list_opt : expr_list { $$ = $1; } | %empty { LIST_NEW($$); } @@ -806,10 +787,6 @@ dict_list | dict { LIST_NEW($$); LIST_ADD($$, $1); } ; -tuple_list - : slice_item_list comma_opt { $$ = TUPLE($1, @$); } - ; - id_list : id_list "," id_item { $$ = $1; LIST_ADD($$, $3); } | id_item { LIST_NEW($$); LIST_ADD($$, $1); } @@ -882,17 +859,42 @@ function_call | "(" expr ")" "(" call_arguement_list ")" { $$ = CALL_01($2, $5, @$); } ; +slice_item_list + : slice_item_list "," slice_items { $$ = $1; LIST_ADD($$, $3); } + | slice_items { LIST_NEW($$); LIST_ADD($$, $1); } + ; + +slice_items + : ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } + | expr ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } + | ":" expr { $$ = SLICE_01(nullptr, $2, nullptr, @$); } + | expr ":" expr { $$ = SLICE_01( $1, $3, nullptr, @$); } + | ":" ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } + | ":" ":" expr { $$ = SLICE_01(nullptr, nullptr, $3, @$); } + | expr ":" ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } + | ":" expr ":" { $$ = SLICE_01(nullptr, $2, nullptr, @$); } + | expr ":" ":" expr { $$ = SLICE_01( $1, nullptr, $4, @$); } + | ":" expr ":" expr { $$ = SLICE_01(nullptr, $2, $4, @$); } + | expr ":" expr ":" { $$ = SLICE_01( $1, $3, nullptr, @$); } + | expr ":" expr ":" expr { $$ = SLICE_01( $1, $3, $5, @$); } + | expr { $$ = $1; } + ; + +slice_item + : slice_item_list comma_opt { $$ = TUPLE($1, @$); } + ; + subscript - : primary "[" tuple_list "]" { $$ = SUBSCRIPT_01($1, $3, @$); } - | function_call "[" tuple_list "]" { $$ = SUBSCRIPT_01($1, $3, @$); } - | "[" expr_list_opt "]" "[" tuple_list "]" { + : primary "[" slice_item "]" { $$ = SUBSCRIPT_01($1, $3, @$); } + | function_call "[" slice_item "]" { $$ = SUBSCRIPT_01($1, $3, @$); } + | "[" expr_list_opt "]" "[" slice_item "]" { $$ = SUBSCRIPT_01(LIST($2, @$), $5, @$); } - | "{" expr_list "}" "[" tuple_list "]" { + | "{" expr_list "}" "[" slice_item "]" { $$ = SUBSCRIPT_01(SET($2, @$), $5, @$); } - | "(" expr ")" "[" tuple_list "]" { $$ = SUBSCRIPT_01($2, $5, @$); } - | "{" dict_list comma_opt "}" "[" tuple_list "]" { + | "(" expr ")" "[" slice_item "]" { $$ = SUBSCRIPT_01($2, $5, @$); } + | "{" dict_list comma_opt "}" "[" slice_item "]" { $$ = SUBSCRIPT_01(DICT_02($2, @$), $6, @$); } - | subscript "[" tuple_list "]" { $$ = SUBSCRIPT_01($1, $3, @$); } + | subscript "[" slice_item "]" { $$ = SUBSCRIPT_01($1, $3, @$); } ; string From b5ed3035381f1b768cfd069ebddcc596311bb1bf Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Tue, 16 Aug 2022 15:56:08 +0530 Subject: [PATCH 3/8] Parse tuples in the for statement --- src/lpython/parser/parser.yy | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 3fb593ce22..5189a482d6 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -536,18 +536,23 @@ if_statement for_target_list : expr %prec FOR { $$ = $1; } | expr_list "," expr %prec FOR { $$ = TUPLE_01(TUPLE_($1, $3), @$); } + | expr_list "," %prec FOR { $$ = TUPLE_03($1, @$); } + ; + +tuple_list + : expr { $$ = $1; } + | expr_list "," expr { $$ = TUPLE_01(TUPLE_($1, $3), @$); } + | expr_list "," { $$ = TUPLE_03($1, @$); } ; for_statement - : KW_FOR for_target_list KW_IN expr ":" body_stmts { + : KW_FOR for_target_list KW_IN tuple_list ":" body_stmts { $$ = FOR_01($2, $4, $6, @$); } - | KW_FOR for_target_list KW_IN expr "," ":" body_stmts { - $$ = FOR_01($2, TUPLE_03(A2LIST(p.m_a, $4), @$), $7, @$); } - | KW_FOR for_target_list KW_IN expr ":" body_stmts KW_ELSE ":" + | KW_FOR for_target_list KW_IN tuple_list ":" body_stmts KW_ELSE ":" body_stmts { $$ = FOR_02($2, $4, $6, $9, @$); } - | KW_FOR for_target_list KW_IN expr ":" type_comment TK_NEWLINE + | KW_FOR for_target_list KW_IN tuple_list ":" type_comment TK_NEWLINE statements { $$ = FOR_03($2, $4, $6, $8, @$); } - | KW_FOR for_target_list KW_IN expr ":" type_comment TK_NEWLINE + | KW_FOR for_target_list KW_IN tuple_list ":" type_comment TK_NEWLINE statements KW_ELSE ":" body_stmts { $$ = FOR_04($2, $4, $8, $11, $6, @$); } ; From 791d9905bb2ec3ddc11fb03ce26d95ec0821ec2c Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Tue, 16 Aug 2022 16:04:21 +0530 Subject: [PATCH 4/8] replace tuple_list for other statements --- src/lpython/parser/parser.yy | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 5189a482d6..948287a3af 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -410,20 +410,12 @@ assert_statement ; target_list - : target_list expr "=" { $$ = $1; LIST_ADD($$, $2); } - | expr "=" { LIST_NEW($$); LIST_ADD($$, $1); } - | target_list expr_list "," expr "=" { - $$ = $1; LIST_ADD($$, TUPLE_01(TUPLE_($2, $4), @$)); } - | expr_list "," expr "=" { - LIST_NEW($$); LIST_ADD($$, TUPLE_01(TUPLE_($1, $3), @$)); } - | target_list expr_list "," "=" { $$ = $1; LIST_ADD($$, TUPLE_03($2, @$)); } - | expr_list "," "=" { LIST_NEW($$); LIST_ADD($$, TUPLE_03($1, @$)); } + : target_list tuple_list "=" { $$ = $1; LIST_ADD($$, $2); } + | tuple_list "=" { LIST_NEW($$); LIST_ADD($$, $1); } ; assignment_statement - : target_list expr { $$ = ASSIGNMENT($1, $2, @$); } - | target_list expr_list "," expr { - $$ = ASSIGNMENT($1, TUPLE_01(TUPLE_($2, $4), @$), @$); } + : target_list tuple_list { $$ = ASSIGNMENT($1, $2, @$); } | target_list expr type_comment { $$ = ASSIGNMENT2($1, $2, $3, @$); } ; @@ -458,10 +450,7 @@ delete_statement return_statement : KW_RETURN { $$ = RETURN_01(@$); } - | KW_RETURN expr { $$ = RETURN_02($2, @$); } - | KW_RETURN expr_list "," expr { - $$ = RETURN_02(TUPLE_01(TUPLE_($2, $4), @$), @$); } - | KW_RETURN expr_list "," { $$ = RETURN_02(TUPLE_03($2, @$), @$); } + | KW_RETURN tuple_list { $$ = RETURN_02($2, @$); } ; module From 2693043b65ff444bc1580d05fbc82c18d6e3d66e Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Tue, 16 Aug 2022 19:35:48 +0530 Subject: [PATCH 5/8] Recognize embedded tuple in the comprehension --- src/lpython/parser/parser.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 948287a3af..8662e8e5fb 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -790,7 +790,7 @@ id_item : id { $$ = $1; } | "(" id ")" { $$ = $2; } | "(" id_list "," ")" { $$ = ID_TUPLE_03($2, @$); } - | "(" id_list "," id ")" { $$ = ID_TUPLE_01(TUPLE_($2, $4), @$); } + | "(" id_list "," id_item ")" { $$ = ID_TUPLE_01(TUPLE_($2, $4), @$); } ; keyword_item From b184e0b82f6a8ef040d02a0c2f4c824b097082b6 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Wed, 17 Aug 2022 15:44:30 +0530 Subject: [PATCH 6/8] Parse tuples in the expression statement --- src/lpython/parser/parser.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 8662e8e5fb..4763e65946 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -383,7 +383,7 @@ multi_line_statement ; expression_statment - : expr { $$ = EXPR_01($1, @$); } + : tuple_list { $$ = EXPR_01($1, @$); } ; pass_statement From 25cecf6309b7f428bf8bcc2b261b8ab7bb6d0052 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Thu, 18 Aug 2022 13:20:11 +0530 Subject: [PATCH 7/8] Parse Tuples in yield and await expression --- src/lpython/parser/parser.yy | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 4763e65946..cc5e78cc2d 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -282,8 +282,6 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %left "%" "//" "/" "@" "*" %precedence UNARY %right "**" -%precedence AWAIT -%precedence YIELD %precedence "." %start units @@ -384,6 +382,10 @@ multi_line_statement expression_statment : tuple_list { $$ = EXPR_01($1, @$); } + | KW_AWAIT tuple_list { $$ = EXPR_01(AWAIT($2, @$), @$); } + | KW_YIELD { $$ = EXPR_01(YIELD_01(@$), @$); } + | KW_YIELD tuple_list { $$ = EXPR_01(YIELD_02($2, @$), @$); } + | KW_YIELD_FROM tuple_list { $$ = EXPR_01(YIELD_03($2, @$), @$); } ; pass_statement @@ -972,10 +974,6 @@ expr | "{" "}" { $$ = DICT_01(@$); } | "{" dict_list comma_opt "}" { $$ = DICT_02($2, @$); } - | KW_AWAIT expr %prec AWAIT { $$ = AWAIT($2, @$); } - | KW_YIELD %prec YIELD { $$ = YIELD_01(@$); } - | KW_YIELD expr %prec YIELD { $$ = YIELD_02($2, @$); } - | KW_YIELD_FROM expr %prec YIELD { $$ = YIELD_03($2, @$); } | id ":=" expr { $$ = NAMEDEXPR($1, $3, @$); } | "*" expr { $$ = STARRED_ARG($2, @$); } From c0699a5a7ca1fdc5eaa3f26cc0c07c0ffd4e2493 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Thu, 18 Aug 2022 13:20:19 +0530 Subject: [PATCH 8/8] Add tests and Update refs. --- tests/parser/comprehension1.py | 4 ++++ tests/parser/for2.py | 5 +++++ tests/parser/statements1.py | 1 + tests/parser/tuple1.py | 6 +++--- tests/parser/yield.py | 3 +++ tests/reference/ast_new-comprehension1-69cf2af.json | 4 ++-- tests/reference/ast_new-comprehension1-69cf2af.stdout | 2 +- tests/reference/ast_new-for2-af08901.json | 4 ++-- tests/reference/ast_new-for2-af08901.stdout | 2 +- tests/reference/ast_new-statements1-e081093.json | 4 ++-- tests/reference/ast_new-statements1-e081093.stdout | 2 +- tests/reference/ast_new-tuple1-29c08af.json | 4 ++-- tests/reference/ast_new-tuple1-29c08af.stdout | 2 +- tests/reference/ast_new-yield-4c41668.json | 4 ++-- tests/reference/ast_new-yield-4c41668.stdout | 2 +- 15 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tests/parser/comprehension1.py b/tests/parser/comprehension1.py index 44b4c648f8..d318acd821 100644 --- a/tests/parser/comprehension1.py +++ b/tests/parser/comprehension1.py @@ -38,3 +38,7 @@ (string[i] for i in range(len(string)-1, -1, -1)) k = (j + k for j, k in range(10) if j > 0) + +(left + size + right for size, (left, right) in zip(array.shape, pad_width)) + +viter = ((i, j) for ((i, _), (j, _)) in zip(newargs[1:], args[1:])) diff --git a/tests/parser/for2.py b/tests/parser/for2.py index 453c951096..2c299bc9a1 100644 --- a/tests/parser/for2.py +++ b/tests/parser/for2.py @@ -50,3 +50,8 @@ async def test(): for a in (b, c): a**2; pass; async for a in range(5): print(a) + +for like_function in np.zeros_like, np.ones_like, np.empty_like: + pass +for a, in t: + pass diff --git a/tests/parser/statements1.py b/tests/parser/statements1.py index 816a222b57..847ee1edc8 100644 --- a/tests/parser/statements1.py +++ b/tests/parser/statements1.py @@ -20,6 +20,7 @@ (x, y, z) = t x, = t (x,) = t +obj = obj, x += 1 diff --git a/tests/parser/tuple1.py b/tests/parser/tuple1.py index f525524d3a..f354c59455 100644 --- a/tests/parser/tuple1.py +++ b/tests/parser/tuple1.py @@ -24,6 +24,6 @@ def test(): _promotion_table = { (int8, int8): int8 } -# TODO -# 1, 2, -# 1, 2 +x, y +x, y, +assert_(np.isnan(div)), 'dt: %s, rem: %s' % (dt, rem) diff --git a/tests/parser/yield.py b/tests/parser/yield.py index 1ec13e9b77..2881c65c58 100644 --- a/tests/parser/yield.py +++ b/tests/parser/yield.py @@ -15,6 +15,9 @@ def func(): for _ in x: yield + yield x, y + yield x, y, + def iterable1(): yield 1 yield 2 diff --git a/tests/reference/ast_new-comprehension1-69cf2af.json b/tests/reference/ast_new-comprehension1-69cf2af.json index b6ffcfe9cb..4582cfe620 100644 --- a/tests/reference/ast_new-comprehension1-69cf2af.json +++ b/tests/reference/ast_new-comprehension1-69cf2af.json @@ -2,11 +2,11 @@ "basename": "ast_new-comprehension1-69cf2af", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/comprehension1.py", - "infile_hash": "db1a35055ce4df698bffbd406fc34ab9fb183a91366f6289575b71d8", + "infile_hash": "86299dc3e7927f4d06bb55bce36c88a6833bb6e1801a3f1c758c6266", "outfile": null, "outfile_hash": null, "stdout": "ast_new-comprehension1-69cf2af.stdout", - "stdout_hash": "965115c1326ba5d293a5e01ecd8b5d83bbd4392a7ba1eea0f08ef82f", + "stdout_hash": "2215f7cfded5c53e72d9f7768eb71be7d0514402ad2ec993ed1b577e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-comprehension1-69cf2af.stdout b/tests/reference/ast_new-comprehension1-69cf2af.stdout index a6a08103cc..fae76fa945 100644 --- a/tests/reference/ast_new-comprehension1-69cf2af.stdout +++ b/tests/reference/ast_new-comprehension1-69cf2af.stdout @@ -1 +1 @@ -(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (Assign [(Name prm_tup Store)] (Call (Name tuple Load) [(GeneratorExp (Call (Name next Load) [(Name parameters Load)] []) [((Name _ Store) (Attribute (Name i Load) __parameters__ Load) [] 0)])] []) ()) (Assign [(Name args Store)] (Call (Attribute (ConstantStr ", " ()) join Load) [(GeneratorExp (Call (Name _to_str Load) [(Name i Load)] []) [((Name i Store) (Attribute (Name self Load) __args__ Load) [] 0)])] []) ()) (Assign [(Name rest Store)] (Call (Name tuple Load) [(GeneratorExp (Name i Load) [((Name i Store) (Call (Name range Load) [(Attribute (Name a Load) ndim Load)] []) [(Compare (Name i Load) NotIn [(Name axis Load)])] 0)])] []) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [(Compare (BinOp (Name element Load) Mod (ConstantInt 2 ())) Eq [(ConstantInt 0 ())])] 0)]) ()) (Expr (DictComp (Name x Load) (BinOp (Name x Load) Pow (ConstantInt 3 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (BinOp (BinOp (Name x Load) Pow (ConstantInt 3 ())) Mod (ConstantInt 4 ())) Eq [(ConstantInt 0 ())])] 0)])) (Assign [(Name square_dict Store)] (DictComp (Name num Load) (BinOp (Name num Load) Mult (Name num Load)) [((Name num Store) (Call (Name range Load) [(ConstantInt 1 ()) (ConstantInt 11 ())] []) [] 0)]) ()) (Expr (GeneratorExp (Subscript (Name string Load) (Name i Load) Load) [((Name i Store) (Call (Name range Load) [(BinOp (Call (Name len Load) [(Name string Load)] []) Sub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ()))] []) [] 0)])) (Assign [(Name k Store)] (GeneratorExp (BinOp (Name j Load) Add (Name k Load)) [((Tuple [(Name j Store) (Name k Store)] Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (Name j Load) Gt [(ConstantInt 0 ())])] 0)]) ())] []) +(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (Assign [(Name prm_tup Store)] (Call (Name tuple Load) [(GeneratorExp (Call (Name next Load) [(Name parameters Load)] []) [((Name _ Store) (Attribute (Name i Load) __parameters__ Load) [] 0)])] []) ()) (Assign [(Name args Store)] (Call (Attribute (ConstantStr ", " ()) join Load) [(GeneratorExp (Call (Name _to_str Load) [(Name i Load)] []) [((Name i Store) (Attribute (Name self Load) __args__ Load) [] 0)])] []) ()) (Assign [(Name rest Store)] (Call (Name tuple Load) [(GeneratorExp (Name i Load) [((Name i Store) (Call (Name range Load) [(Attribute (Name a Load) ndim Load)] []) [(Compare (Name i Load) NotIn [(Name axis Load)])] 0)])] []) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [(Compare (BinOp (Name element Load) Mod (ConstantInt 2 ())) Eq [(ConstantInt 0 ())])] 0)]) ()) (Expr (DictComp (Name x Load) (BinOp (Name x Load) Pow (ConstantInt 3 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (BinOp (BinOp (Name x Load) Pow (ConstantInt 3 ())) Mod (ConstantInt 4 ())) Eq [(ConstantInt 0 ())])] 0)])) (Assign [(Name square_dict Store)] (DictComp (Name num Load) (BinOp (Name num Load) Mult (Name num Load)) [((Name num Store) (Call (Name range Load) [(ConstantInt 1 ()) (ConstantInt 11 ())] []) [] 0)]) ()) (Expr (GeneratorExp (Subscript (Name string Load) (Name i Load) Load) [((Name i Store) (Call (Name range Load) [(BinOp (Call (Name len Load) [(Name string Load)] []) Sub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ()))] []) [] 0)])) (Assign [(Name k Store)] (GeneratorExp (BinOp (Name j Load) Add (Name k Load)) [((Tuple [(Name j Store) (Name k Store)] Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (Name j Load) Gt [(ConstantInt 0 ())])] 0)]) ()) (Expr (GeneratorExp (BinOp (BinOp (Name left Load) Add (Name size Load)) Add (Name right Load)) [((Tuple [(Name size Store) (Tuple [(Name left Store) (Name right Store)] Store)] Store) (Call (Name zip Load) [(Attribute (Name array Load) shape Load) (Name pad_width Load)] []) [] 0)])) (Assign [(Name viter Store)] (GeneratorExp (Tuple [(Name i Load) (Name j Load)] Load) [((Tuple [(Tuple [(Name i Store) (Name _ Store)] Store) (Tuple [(Name j Store) (Name _ Store)] Store)] Store) (Call (Name zip Load) [(Subscript (Name newargs Load) (Slice (ConstantInt 1 ()) () ()) Load) (Subscript (Name args Load) (Slice (ConstantInt 1 ()) () ()) Load)] []) [] 0)]) ())] []) diff --git a/tests/reference/ast_new-for2-af08901.json b/tests/reference/ast_new-for2-af08901.json index 030cf61d5f..a3e69a308d 100644 --- a/tests/reference/ast_new-for2-af08901.json +++ b/tests/reference/ast_new-for2-af08901.json @@ -2,11 +2,11 @@ "basename": "ast_new-for2-af08901", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/for2.py", - "infile_hash": "5b2063381273e132aae18d9ba76c775c5743c66592fd42046b030543", + "infile_hash": "32c45d5c5edc44504a3fa5d24c6c1660977d2ceceeef311ee5a37410", "outfile": null, "outfile_hash": null, "stdout": "ast_new-for2-af08901.stdout", - "stdout_hash": "a6ef674db9539591e9e5c0409f91b616ba70008d77b975d5074196fa", + "stdout_hash": "d8c03cf0ef7c1473ea457b1282da26a047e1b110c5fab6494cf434cd", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-for2-af08901.stdout b/tests/reference/ast_new-for2-af08901.stdout index c1ef48d2cf..a84b61557d 100644 --- a/tests/reference/ast_new-for2-af08901.stdout +++ b/tests/reference/ast_new-for2-af08901.stdout @@ -1 +1 @@ -(Module [(For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] "parallel") (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(If (Compare (ConstantInt 2 ()) Gt [(Name i Load)]) [(Pass)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (BoolOp And [(Compare (Name i Load) Eq [(ConstantInt 5 ())]) (Compare (Name i Load) Lt [(ConstantInt 10 ())])]) [(Assign [(Name i Store)] (ConstantInt 3 ()) ())] [])] [] ()) (For (Name i Store) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (For (Name item Store) (Name list1 Load) [(If (Compare (Name item Load) In [(Name list2 Load)]) [(Pass)] [])] [] ()) (If (BoolOp Or [(BoolOp And [(Compare (Name a Load) In [(Name list1 Load)]) (Compare (Name b Load) NotIn [(Name list2 Load)])]) (Compare (Name c Load) In [(Name list3 Load)])]) [(Pass)] []) (For (Name f Store) (Tuple [(Name a Load) (Name b Load) (Name c Load) (Name d Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFunctionDef test ([] [] [] [] [] [] []) [(AsyncFor (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFor (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ())] [] () ()) (For (Name a Store) (Tuple [(Name b Load) (Name c Load)] Load) [(Expr (BinOp (Name a Load) Pow (ConstantInt 2 ()))) (Pass)] [] ()) (AsyncFor (Name a Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Expr (Call (Name print Load) [(Name a Load)] []))] [] ())] []) +(Module [(For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] "parallel") (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(If (Compare (ConstantInt 2 ()) Gt [(Name i Load)]) [(Pass)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (BoolOp And [(Compare (Name i Load) Eq [(ConstantInt 5 ())]) (Compare (Name i Load) Lt [(ConstantInt 10 ())])]) [(Assign [(Name i Store)] (ConstantInt 3 ()) ())] [])] [] ()) (For (Name i Store) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (For (Name item Store) (Name list1 Load) [(If (Compare (Name item Load) In [(Name list2 Load)]) [(Pass)] [])] [] ()) (If (BoolOp Or [(BoolOp And [(Compare (Name a Load) In [(Name list1 Load)]) (Compare (Name b Load) NotIn [(Name list2 Load)])]) (Compare (Name c Load) In [(Name list3 Load)])]) [(Pass)] []) (For (Name f Store) (Tuple [(Name a Load) (Name b Load) (Name c Load) (Name d Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFunctionDef test ([] [] [] [] [] [] []) [(AsyncFor (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFor (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ())] [] () ()) (For (Name a Store) (Tuple [(Name b Load) (Name c Load)] Load) [(Expr (BinOp (Name a Load) Pow (ConstantInt 2 ()))) (Pass)] [] ()) (AsyncFor (Name a Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Expr (Call (Name print Load) [(Name a Load)] []))] [] ()) (For (Name like_function Store) (Tuple [(Attribute (Name np Load) zeros_like Load) (Attribute (Name np Load) ones_like Load) (Attribute (Name np Load) empty_like Load)] Load) [(Pass)] [] ()) (For (Tuple [(Name a Store)] Store) (Name t Load) [(Pass)] [] ())] []) diff --git a/tests/reference/ast_new-statements1-e081093.json b/tests/reference/ast_new-statements1-e081093.json index e5a178121d..d1a38d331b 100644 --- a/tests/reference/ast_new-statements1-e081093.json +++ b/tests/reference/ast_new-statements1-e081093.json @@ -2,11 +2,11 @@ "basename": "ast_new-statements1-e081093", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/statements1.py", - "infile_hash": "cec0db26e0950c7680ae773a867e0f6c1e6c1c6d8d782e42c0e6ee5c", + "infile_hash": "795f2671c2e282f01d1715deac8bdb342dbef6df5962ded5a3a045d1", "outfile": null, "outfile_hash": null, "stdout": "ast_new-statements1-e081093.stdout", - "stdout_hash": "0aec07bcf0f9f9c7ad8f3098d37a9d8a498af6adf0c9953499220991", + "stdout_hash": "8c0a1dd6e96f4b8ec7a5fd2996b0474d5d2e2f947b02e74658656067", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-statements1-e081093.stdout b/tests/reference/ast_new-statements1-e081093.stdout index e6bd22c585..3ddcf6e777 100644 --- a/tests/reference/ast_new-statements1-e081093.stdout +++ b/tests/reference/ast_new-statements1-e081093.stdout @@ -1 +1 @@ -(Module [(Pass) (Break) (Continue) (Raise () ()) (Raise (Call (Name NameError Load) [(ConstantStr "String" ())] []) ()) (Raise (Name RuntimeError Load) (Name exc Load)) (Assert (Compare (Call (Name len Load) [(Name marks Load)] []) NotEq [(ConstantInt 0 ())]) (ConstantStr "List is empty." ())) (Assert (Compare (Name x Load) Eq [(ConstantStr "String" ())]) ()) (Assign [(Name x Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Call (Name x Load) [] []) ()) (Assign [(Name x Store) (Name y Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Subscript (Name x Load) (Name i Load) Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (AugAssign (Name x Store) Add (ConstantInt 1 ())) (AnnAssign (Name x Store) (Name i64 Load) () 1) (AnnAssign (Name y Store) (Name i32 Load) (ConstantInt 1 ()) 1) (Delete [(Name x Del)]) (Delete [(Tuple [] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Name x Del) (Name y Del)]) (Delete [(Name x Del) (Name y Del)]) (Return ()) (Return (BinOp (Name a Load) Add (Name b Load))) (Return (Call (Name x Load) [(Name a Load)] [])) (Return (Tuple [] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Global [a]) (Global [a b]) (Nonlocal [a]) (Nonlocal [a b]) (Expr (ConstantInt 123 ())) (Expr (UnaryOp USub (ConstantInt 123 ()))) (Expr (UnaryOp USub (ConstantInt 291 ()))) (Expr (ConstantInt 6844 ())) (Expr (UnaryOp USub (ConstantInt 83 ()))) (Expr (ConstantInt 87 ())) (Expr (UnaryOp USub (ConstantInt 13 ()))) (Expr (ConstantInt 13 ())) (Expr (ConstantInt 32768 ())) (Expr (ConstantInt 12 ())) (Expr (ConstantInt 23440334322333 ())) (Expr (ConstantFloat 123.000000 ())) (Expr (ConstantFloat 123.450000 ())) (Expr (ConstantFloat 123400000000.000000 ())) (Expr (BinOp (ConstantInt 12 ()) Add (ConstantComplex 0.000000 3.000000 ()))) (Expr (BinOp (ConstantFloat 0.120000 ()) Add (ConstantComplex 0.000000 0.001000 ()))) (Expr (ConstantStr "String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (Subscript (ConstantStr "String String" ()) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (BinOp (ConstantStr "String " ()) Add (ConstantStr "String" ())) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String " ()) ()) (Expr (ConstantStr "String" ())) (Expr (ConstantBool .true. ())) (Expr (ConstantBool .false. ())) (Expr (BinOp (BinOp (Name x Load) Add (Name y Load)) Mult (Name z Load))) (Expr (BinOp (Name x Load) Sub (Name y Load))) (Expr (BinOp (Name x Load) Mult (Name y Load))) (Expr (BinOp (Name x Load) Div (Name y Load))) (Expr (BinOp (Name x Load) Mod (Name y Load))) (Expr (UnaryOp USub (Name y Load))) (Expr (UnaryOp UAdd (Name y Load))) (Expr (UnaryOp Invert (Name y Load))) (Expr (BinOp (Name x Load) Pow (Name y Load))) (Expr (BinOp (Name x Load) FloorDiv (Name y Load))) (Expr (BinOp (Name x Load) MatMult (Name y Load))) (Expr (BinOp (Name x Load) BitAnd (Name y Load))) (Expr (BinOp (Name x Load) BitOr (Name y Load))) (Expr (BinOp (Name x Load) BitXor (Name y Load))) (Expr (BinOp (Name x Load) LShift (Name y Load))) (Expr (BinOp (Name x Load) RShift (Name y Load))) (Expr (Compare (Name x Load) Eq [(Name y Load)])) (Expr (Compare (Name x Load) NotEq [(Name y Load)])) (Expr (Compare (Name x Load) Lt [(Name y Load)])) (Expr (Compare (Name x Load) LtE [(Name y Load)])) (Expr (Compare (Name x Load) Gt [(Name y Load)])) (Expr (Compare (Name x Load) GtE [(Name y Load)])) (Expr (Compare (ConstantStr "hello" ()) In [(Name x Load)])) (Expr (Compare (ConstantStr "a" ()) In [(Call (Attribute (Name a Load) func Load) [] [])])) (Expr (Compare (ConstantStr "lo" ()) In [(ConstantStr "hello" ())])) (Expr (Subscript (Attribute (Name a Load) b Load) (ConstantInt 1 ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (ConstantInt 1 ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) () ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () (UnaryOp USub (ConstantInt 1 ())) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () () ()) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (NamedExpr (Name y Store) (ConstantInt 0 ())) ()) (If (NamedExpr (Name a Store) (Call (Name ord Load) [(ConstantStr "3" ())] [])) [(Assign [(Name x Store)] (ConstantInt 1 ()) ())] []) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (AnnAssign (Name output Store) (Name bool Load) (Compare (Name x Load) Eq [(Name y Load)]) 1) (AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (Name x Load) Eq [(Name y Load)]) ()) (AnnAssign (Name output Store) (Name bool Load) (Compare (Name x Load) Gt [(Name y Load)]) 1) (AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (Name x Load) Gt [(Name y Load)]) ()) (AnnAssign (Name output Store) (Name bool Load) (Compare (List [(Name x Load)] Load) NotIn [(List [(Name y Load)] Load)]) 1) (AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (List [(Name x Load)] Load) NotIn [(List [(Name y Load)] Load)]) ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(Return (Compare (Name a Load) Gt [(Name b Load)]))] [] () ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(Return (Compare (List [(Name a Load)] Load) In [(List [(Name b Load)] Load)]))] [] () ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (List [(Name a Load)] Load) NotIn [(List [(Name b Load)] Load)]) ()) (Return (Name output Load))] [] () ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(Assign [(Name output Store)] (Compare (List [(Name a Load)] Load) NotIn [(List [(Name b Load)] Load)]) ()) (Return (Name output Load))] [] () ())] []) +(Module [(Pass) (Break) (Continue) (Raise () ()) (Raise (Call (Name NameError Load) [(ConstantStr "String" ())] []) ()) (Raise (Name RuntimeError Load) (Name exc Load)) (Assert (Compare (Call (Name len Load) [(Name marks Load)] []) NotEq [(ConstantInt 0 ())]) (ConstantStr "List is empty." ())) (Assert (Compare (Name x Load) Eq [(ConstantStr "String" ())]) ()) (Assign [(Name x Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Call (Name x Load) [] []) ()) (Assign [(Name x Store) (Name y Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Subscript (Name x Load) (Name i Load) Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (Assign [(Name obj Store)] (Tuple [(Name obj Load)] Load) ()) (AugAssign (Name x Store) Add (ConstantInt 1 ())) (AnnAssign (Name x Store) (Name i64 Load) () 1) (AnnAssign (Name y Store) (Name i32 Load) (ConstantInt 1 ()) 1) (Delete [(Name x Del)]) (Delete [(Tuple [] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Name x Del) (Name y Del)]) (Delete [(Name x Del) (Name y Del)]) (Return ()) (Return (BinOp (Name a Load) Add (Name b Load))) (Return (Call (Name x Load) [(Name a Load)] [])) (Return (Tuple [] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Global [a]) (Global [a b]) (Nonlocal [a]) (Nonlocal [a b]) (Expr (ConstantInt 123 ())) (Expr (UnaryOp USub (ConstantInt 123 ()))) (Expr (UnaryOp USub (ConstantInt 291 ()))) (Expr (ConstantInt 6844 ())) (Expr (UnaryOp USub (ConstantInt 83 ()))) (Expr (ConstantInt 87 ())) (Expr (UnaryOp USub (ConstantInt 13 ()))) (Expr (ConstantInt 13 ())) (Expr (ConstantInt 32768 ())) (Expr (ConstantInt 12 ())) (Expr (ConstantInt 23440334322333 ())) (Expr (ConstantFloat 123.000000 ())) (Expr (ConstantFloat 123.450000 ())) (Expr (ConstantFloat 123400000000.000000 ())) (Expr (BinOp (ConstantInt 12 ()) Add (ConstantComplex 0.000000 3.000000 ()))) (Expr (BinOp (ConstantFloat 0.120000 ()) Add (ConstantComplex 0.000000 0.001000 ()))) (Expr (ConstantStr "String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (Subscript (ConstantStr "String String" ()) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (BinOp (ConstantStr "String " ()) Add (ConstantStr "String" ())) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String " ()) ()) (Expr (ConstantStr "String" ())) (Expr (ConstantBool .true. ())) (Expr (ConstantBool .false. ())) (Expr (BinOp (BinOp (Name x Load) Add (Name y Load)) Mult (Name z Load))) (Expr (BinOp (Name x Load) Sub (Name y Load))) (Expr (BinOp (Name x Load) Mult (Name y Load))) (Expr (BinOp (Name x Load) Div (Name y Load))) (Expr (BinOp (Name x Load) Mod (Name y Load))) (Expr (UnaryOp USub (Name y Load))) (Expr (UnaryOp UAdd (Name y Load))) (Expr (UnaryOp Invert (Name y Load))) (Expr (BinOp (Name x Load) Pow (Name y Load))) (Expr (BinOp (Name x Load) FloorDiv (Name y Load))) (Expr (BinOp (Name x Load) MatMult (Name y Load))) (Expr (BinOp (Name x Load) BitAnd (Name y Load))) (Expr (BinOp (Name x Load) BitOr (Name y Load))) (Expr (BinOp (Name x Load) BitXor (Name y Load))) (Expr (BinOp (Name x Load) LShift (Name y Load))) (Expr (BinOp (Name x Load) RShift (Name y Load))) (Expr (Compare (Name x Load) Eq [(Name y Load)])) (Expr (Compare (Name x Load) NotEq [(Name y Load)])) (Expr (Compare (Name x Load) Lt [(Name y Load)])) (Expr (Compare (Name x Load) LtE [(Name y Load)])) (Expr (Compare (Name x Load) Gt [(Name y Load)])) (Expr (Compare (Name x Load) GtE [(Name y Load)])) (Expr (Compare (ConstantStr "hello" ()) In [(Name x Load)])) (Expr (Compare (ConstantStr "a" ()) In [(Call (Attribute (Name a Load) func Load) [] [])])) (Expr (Compare (ConstantStr "lo" ()) In [(ConstantStr "hello" ())])) (Expr (Subscript (Attribute (Name a Load) b Load) (ConstantInt 1 ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (ConstantInt 1 ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) () ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () (UnaryOp USub (ConstantInt 1 ())) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () () ()) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (NamedExpr (Name y Store) (ConstantInt 0 ())) ()) (If (NamedExpr (Name a Store) (Call (Name ord Load) [(ConstantStr "3" ())] [])) [(Assign [(Name x Store)] (ConstantInt 1 ()) ())] []) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (AnnAssign (Name output Store) (Name bool Load) (Compare (Name x Load) Eq [(Name y Load)]) 1) (AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (Name x Load) Eq [(Name y Load)]) ()) (AnnAssign (Name output Store) (Name bool Load) (Compare (Name x Load) Gt [(Name y Load)]) 1) (AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (Name x Load) Gt [(Name y Load)]) ()) (AnnAssign (Name output Store) (Name bool Load) (Compare (List [(Name x Load)] Load) NotIn [(List [(Name y Load)] Load)]) 1) (AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (List [(Name x Load)] Load) NotIn [(List [(Name y Load)] Load)]) ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(Return (Compare (Name a Load) Gt [(Name b Load)]))] [] () ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(Return (Compare (List [(Name a Load)] Load) In [(List [(Name b Load)] Load)]))] [] () ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(AnnAssign (Name output Store) (Name bool Load) () 1) (Assign [(Name output Store)] (Compare (List [(Name a Load)] Load) NotIn [(List [(Name b Load)] Load)]) ()) (Return (Name output Load))] [] () ()) (FunctionDef comparison_return ([] [(a () ()) (b () ())] [] [] [] [] []) [(Assign [(Name output Store)] (Compare (List [(Name a Load)] Load) NotIn [(List [(Name b Load)] Load)]) ()) (Return (Name output Load))] [] () ())] []) diff --git a/tests/reference/ast_new-tuple1-29c08af.json b/tests/reference/ast_new-tuple1-29c08af.json index e30ed57db2..1b06d0aad4 100644 --- a/tests/reference/ast_new-tuple1-29c08af.json +++ b/tests/reference/ast_new-tuple1-29c08af.json @@ -2,11 +2,11 @@ "basename": "ast_new-tuple1-29c08af", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/tuple1.py", - "infile_hash": "c6b5d261e80e336d87a78b4f378c30c43eb12b145c9ca6e731ce527c", + "infile_hash": "99f703a4ff107887b7e006cf2d69f4f53f2668af5a61c28ca25accac", "outfile": null, "outfile_hash": null, "stdout": "ast_new-tuple1-29c08af.stdout", - "stdout_hash": "32eba4e6e55f98c5125966bc8d1d0873d249f96d8f3a32afb27f1eeb", + "stdout_hash": "514f2eb7591d6f760233b111d9bbf6c4666de15bf8cc617012017c84", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-tuple1-29c08af.stdout b/tests/reference/ast_new-tuple1-29c08af.stdout index c2e9022138..2c393ca71e 100644 --- a/tests/reference/ast_new-tuple1-29c08af.stdout +++ b/tests/reference/ast_new-tuple1-29c08af.stdout @@ -1 +1 @@ -(Module [(Assign [(Name a Store)] (BinOp (Tuple [(ConstantInt 1 ())] Load) Add (ConstantInt 4 ())) ()) (Assign [(Name a Store)] (BinOp (BinOp (ConstantInt 3 ()) Mult (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) Add (ConstantInt 4 ())) ()) (Expr (Call (Name f Load) [(Tuple [(Name x Load) (Name y Load)] Load)] [])) (Expr (Call (Name f Load) [(Tuple [(Name x Load)] Load)] [])) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a4 Store)] (Tuple [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) (Tuple [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ())] Load)] Load) ()) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) (Expr (BinOp (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) Mult (ConstantInt 3 ()))) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(Name a Load) (Name b Load) (Name c Load)] Load))] [])) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(BinOp (ConstantInt 10 ()) Add (Name x Load)) (Name y Load) (BinOp (Name z Load) Add (ConstantInt 20 ()))] Load))] [])) (If (Compare (Attribute (Name sys Load) version_info Load) GtE [(Tuple [(ConstantInt 3 ()) (ConstantInt 9 ())] Load)]) [(Pass)] []) (Assign [(Name NDArray Store)] (Call (Name _GenericAlias Load) [(Attribute (Name np Load) ndarray Load) (Tuple [(Name Any Load) (Name _DType Load)] Load)] []) ()) (FunctionDef test ([] [] [] [] [] [] []) [(Pass)] [(Call (Attribute (Attribute (Name pytest Load) mark Load) parametrize Load) [(ConstantStr "shape" ()) (List [(ConstantInt 5 ()) (Tuple [(ConstantInt 3 ()) (ConstantInt 3 ()) (ConstantInt 3 ())] Load)] Load)] [])] () ()) (Assign [(Name _promotion_table Store)] (Dict [(Tuple [(Name int8 Load) (Name int8 Load)] Load)] [(Name int8 Load)]) ())] []) +(Module [(Assign [(Name a Store)] (BinOp (Tuple [(ConstantInt 1 ())] Load) Add (ConstantInt 4 ())) ()) (Assign [(Name a Store)] (BinOp (BinOp (ConstantInt 3 ()) Mult (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) Add (ConstantInt 4 ())) ()) (Expr (Call (Name f Load) [(Tuple [(Name x Load) (Name y Load)] Load)] [])) (Expr (Call (Name f Load) [(Tuple [(Name x Load)] Load)] [])) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a4 Store)] (Tuple [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) (Tuple [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ())] Load)] Load) ()) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) (Expr (BinOp (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) Mult (ConstantInt 3 ()))) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(Name a Load) (Name b Load) (Name c Load)] Load))] [])) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(BinOp (ConstantInt 10 ()) Add (Name x Load)) (Name y Load) (BinOp (Name z Load) Add (ConstantInt 20 ()))] Load))] [])) (If (Compare (Attribute (Name sys Load) version_info Load) GtE [(Tuple [(ConstantInt 3 ()) (ConstantInt 9 ())] Load)]) [(Pass)] []) (Assign [(Name NDArray Store)] (Call (Name _GenericAlias Load) [(Attribute (Name np Load) ndarray Load) (Tuple [(Name Any Load) (Name _DType Load)] Load)] []) ()) (FunctionDef test ([] [] [] [] [] [] []) [(Pass)] [(Call (Attribute (Attribute (Name pytest Load) mark Load) parametrize Load) [(ConstantStr "shape" ()) (List [(ConstantInt 5 ()) (Tuple [(ConstantInt 3 ()) (ConstantInt 3 ()) (ConstantInt 3 ())] Load)] Load)] [])] () ()) (Assign [(Name _promotion_table Store)] (Dict [(Tuple [(Name int8 Load) (Name int8 Load)] Load)] [(Name int8 Load)]) ()) (Expr (Tuple [(Name x Load) (Name y Load)] Load)) (Expr (Tuple [(Name x Load) (Name y Load)] Load)) (Expr (Tuple [(Call (Name assert_ Load) [(Call (Attribute (Name np Load) isnan Load) [(Name div Load)] [])] []) (BinOp (ConstantStr "dt: %s, rem: %s" ()) Mod (Tuple [(Name dt Load) (Name rem Load)] Load))] Load))] []) diff --git a/tests/reference/ast_new-yield-4c41668.json b/tests/reference/ast_new-yield-4c41668.json index ba586c15a7..5591dfc0a6 100644 --- a/tests/reference/ast_new-yield-4c41668.json +++ b/tests/reference/ast_new-yield-4c41668.json @@ -2,11 +2,11 @@ "basename": "ast_new-yield-4c41668", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/yield.py", - "infile_hash": "620c6ab803ffaaf334d2e79f025ab91d504dc3b1f7601da644cdb73f", + "infile_hash": "acf514c9231bf9a1b68a30074944574470af47dab7562be71ab99d3e", "outfile": null, "outfile_hash": null, "stdout": "ast_new-yield-4c41668.stdout", - "stdout_hash": "3912a1cdfb29cf132e43ecd8b5e524c14162440efe82ccd5116add76", + "stdout_hash": "27053c77574330eda52c32b802e24e5f9aeb17844245d8b92a42319d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-yield-4c41668.stdout b/tests/reference/ast_new-yield-4c41668.stdout index 057d1f65e8..8a00050613 100644 --- a/tests/reference/ast_new-yield-4c41668.stdout +++ b/tests/reference/ast_new-yield-4c41668.stdout @@ -1 +1 @@ -(Module [(FunctionDef func ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Subscript (Name list Load) (Name i32 Load) Load) () 1) (Assign [(Name x Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Name x Load) [(Expr (Yield (Name i Load)))] [] ()) (For (Name i Store) (Name x Load) [(Expr (Yield (Name i Load)))] [] ()) (For (Name i Store) (Name x Load) [(Expr (Yield (Tuple [] Load)))] [] ()) (For (Name _ Store) (Name x Load) [(Expr (Yield ()))] [] ())] [] () ()) (FunctionDef iterable1 ([] [] [] [] [] [] []) [(Expr (Yield (ConstantInt 1 ()))) (Expr (Yield (ConstantInt 2 ())))] [] () ()) (FunctionDef iterable2 ([] [] [] [] [] [] []) [(Expr (YieldFrom (Call (Name iterable1 Load) [] []))) (Expr (Yield (ConstantInt 3 ())))] [] () ()) (Assert (Compare (Call (Name list Load) [(Call (Name iterable2 Load) [] [])] []) Eq [(List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)]) ())] []) +(Module [(FunctionDef func ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Subscript (Name list Load) (Name i32 Load) Load) () 1) (Assign [(Name x Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Name x Load) [(Expr (Yield (Name i Load)))] [] ()) (For (Name i Store) (Name x Load) [(Expr (Yield (Name i Load)))] [] ()) (For (Name i Store) (Name x Load) [(Expr (Yield (Tuple [] Load)))] [] ()) (For (Name _ Store) (Name x Load) [(Expr (Yield ()))] [] ()) (Expr (Yield (Tuple [(Name x Load) (Name y Load)] Load))) (Expr (Yield (Tuple [(Name x Load) (Name y Load)] Load)))] [] () ()) (FunctionDef iterable1 ([] [] [] [] [] [] []) [(Expr (Yield (ConstantInt 1 ()))) (Expr (Yield (ConstantInt 2 ())))] [] () ()) (FunctionDef iterable2 ([] [] [] [] [] [] []) [(Expr (YieldFrom (Call (Name iterable1 Load) [] []))) (Expr (Yield (ConstantInt 3 ())))] [] () ()) (Assert (Compare (Call (Name list Load) [(Call (Name iterable2 Load) [] [])] []) Eq [(List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)]) ())] [])