Skip to content

Commit c58e6ef

Browse files
authored
Merge pull request rocky#471 from rocky/add-ending_return
Simpilfy grammar via ending_return
2 parents b3ddf95 + c0957d9 commit c58e6ef

File tree

7 files changed

+22
-38
lines changed

7 files changed

+22
-38
lines changed
File renamed without changes.

uncompyle6/parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ def p_stmt(self, args):
304304
c_stmts ::= lastc_stmt
305305
c_stmts ::= continues
306306
307+
ending_return ::= RETURN_VALUE RETURN_LAST
308+
ending_return ::= RETURN_VALUE_LAMBDA LAMBDA_MARKER
309+
307310
lastc_stmt ::= iflaststmt
308311
lastc_stmt ::= forelselaststmt
309312
lastc_stmt ::= ifelsestmtc

uncompyle6/parsers/parse27.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ def p_comprehension27(self, args):
3939
stmt ::= dict_comp_func
4040
4141
dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
42-
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
43-
dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
44-
comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
42+
comp_iter JUMP_BACK ending_return
4543
4644
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
47-
JUMP_BACK RETURN_VALUE RETURN_LAST
48-
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
49-
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
45+
JUMP_BACK ending_return
5046
5147
comp_iter ::= comp_if_not
5248
comp_if_not ::= expr jmp_true comp_iter

uncompyle6/parsers/parse3.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,13 @@ def p_comprehension3(self, args):
7979
8080
stmt ::= set_comp_func
8181
82+
# TODO this can be simplified
8283
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
83-
JUMP_BACK RETURN_VALUE RETURN_LAST
84-
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
85-
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
86-
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
87-
JUMP_BACK RETURN_VALUE RETURN_LAST
84+
JUMP_BACK ending_return
8885
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
89-
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
90-
91-
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
92-
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
86+
JUMP_BACK ending_return
9387
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
94-
COME_FROM JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
88+
COME_FROM JUMP_BACK ending_return
9589
9690
comp_body ::= dict_comp_body
9791
comp_body ::= set_comp_body

uncompyle6/parsers/parse30.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,8 @@ def p_30(self, args):
7777
7878
set_comp_func ::= set_comp_header
7979
LOAD_ARG FOR_ITER store comp_iter
80-
JUMP_BACK
80+
JUMP_BACK ending_return
8181
RETURN_VALUE RETURN_LAST
82-
set_comp_func ::= set_comp_header
83-
LOAD_ARG FOR_ITER store comp_iter
84-
JUMP_BACK
85-
RETURN_VALUE_LAMBDA LAMBDA_MARKER
8682
8783
list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST
8884
list_comp ::= list_comp_header
@@ -112,11 +108,7 @@ def p_30(self, args):
112108
dict_comp_func ::= BUILD_MAP_0
113109
DUP_TOP STORE_FAST
114110
LOAD_ARG FOR_ITER store
115-
dict_comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
116-
dict_comp_func ::= BUILD_MAP_0
117-
DUP_TOP STORE_FAST
118-
LOAD_ARG FOR_ITER store
119-
dict_comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
111+
dict_comp_iter JUMP_BACK ending_return
120112
121113
stmt ::= try_except30
122114
try_except30 ::= SETUP_EXCEPT suite_stmts_opt

uncompyle6/parsers/parse37.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def p_stmt(self, args):
6262
c_stmts ::= lastc_stmt
6363
c_stmts ::= continues
6464
65+
ending_return ::= RETURN_VALUE RETURN_LAST
66+
ending_return ::= RETURN_VALUE_LAMBDA LAMBDA_MARKER
67+
6568
lastc_stmt ::= iflaststmt
6669
lastc_stmt ::= forelselaststmt
6770
lastc_stmt ::= ifelsestmtc
@@ -739,15 +742,11 @@ def p_comprehension3(self, args):
739742
740743
stmt ::= set_comp_func
741744
745+
# TODO: simplify this
742746
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
743-
JUMP_BACK RETURN_VALUE RETURN_LAST
747+
JUMP_BACK ending_return
744748
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
745-
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
746-
747-
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
748-
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
749-
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
750-
COME_FROM JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
749+
COME_FROM JUMP_BACK ending_return
751750
752751
comp_body ::= dict_comp_body
753752
comp_body ::= set_comp_body
@@ -763,9 +762,7 @@ def p_dict_comp3(self, args):
763762
stmt ::= dict_comp_func
764763
765764
dict_comp_func ::= BUILD_MAP_0 LOAD_ARG for_iter store
766-
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
767-
dict_comp_func ::= BUILD_MAP_0 LOAD_ARG for_iter store
768-
comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
765+
comp_iter JUMP_BACK ending_return
769766
770767
comp_iter ::= comp_if
771768
comp_iter ::= comp_if_not

uncompyle6/parsers/parse38.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def p_38_stmt(self, args):
121121
for38 ::= expr get_for_iter store for_block
122122
123123
forelsestmt38 ::= expr get_for_iter store for_block POP_BLOCK else_suite
124-
forelsestmt38 ::= expr get_for_iter store for_block JUMP_BACK _come_froms else_suite
124+
forelsestmt38 ::= expr get_for_iter store for_block JUMP_BACK _come_froms
125+
else_suite
125126
126127
forelselaststmt38 ::= expr get_for_iter store for_block POP_BLOCK else_suitec
127128
forelselaststmtl38 ::= expr get_for_iter store for_block POP_BLOCK else_suitel
@@ -130,7 +131,8 @@ def p_38_stmt(self, args):
130131
except_return_value ::= POP_BLOCK return
131132
except_return_value ::= expr POP_BLOCK RETURN_VALUE
132133
133-
whilestmt38 ::= _come_froms testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
134+
whilestmt38 ::= _come_froms testexpr l_stmts_opt COME_FROM JUMP_BACK
135+
POP_BLOCK
134136
whilestmt38 ::= _come_froms testexpr l_stmts_opt JUMP_BACK POP_BLOCK
135137
whilestmt38 ::= _come_froms testexpr l_stmts_opt JUMP_BACK come_froms
136138
whilestmt38 ::= _come_froms testexpr returns POP_BLOCK

0 commit comments

Comments
 (0)