Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle comprehensions inside a lambda #470

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added test/bytecode_2.7_run/03_comprehension_in_lambda.pyc
Binary file not shown.
Binary file added test/bytecode_3.7_run/03_comprehension_in_lambda.pyc
Binary file not shown.
Binary file added test/bytecode_3.8_run/03_comprehension_in_lambda.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions test/simple_source/bug27+/03_comprehension_in_lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# RUNNABLE!
# From issue 469

"""This program is self-checking!"""

my_dict = (lambda variable0: {variable1: 123 for variable1 in variable0})([1, 2, 3])

assert my_dict[1] == 123

my_set = (lambda variable0: {variable1 for variable1 in variable0})([1, 2, 3])
assert 2 in my_set
5 changes: 5 additions & 0 deletions uncompyle6/parsers/parse27.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ def p_comprehension27(self, args):
dict_comp ::= LOAD_DICTCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1

stmt ::= dict_comp_func

dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER

set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER

comp_iter ::= comp_if_not
comp_if_not ::= expr jmp_true comp_iter
Expand Down
12 changes: 11 additions & 1 deletion uncompyle6/parsers/parse30.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ def p_30(self, args):

# Need to keep LOAD_FAST as index 1
set_comp_header ::= BUILD_SET_0 DUP_TOP STORE_FAST

set_comp_func ::= set_comp_header
LOAD_ARG FOR_ITER store comp_iter
JUMP_BACK COME_FROM POP_TOP JUMP_BACK
RETURN_VALUE RETURN_LAST
set_comp_func ::= set_comp_header
LOAD_ARG FOR_ITER store comp_iter
JUMP_BACK COME_FROM POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST
JUMP_BACK COME_FROM POP_TOP JUMP_BACK
RETURN_VALUE_LAMBDA LAMBDA_MARKER

list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST
list_comp ::= list_comp_header
Expand Down Expand Up @@ -107,6 +113,10 @@ def p_30(self, args):
DUP_TOP STORE_FAST
LOAD_ARG FOR_ITER store
dict_comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dict_comp_func ::= BUILD_MAP_0
DUP_TOP STORE_FAST
LOAD_ARG FOR_ITER store
dict_comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER

stmt ::= try_except30
try_except30 ::= SETUP_EXCEPT suite_stmts_opt
Expand Down
7 changes: 7 additions & 0 deletions uncompyle6/parsers/parse37.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,13 @@ def p_comprehension3(self, args):

set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER

set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER

comp_body ::= dict_comp_body
comp_body ::= set_comp_body
Expand All @@ -757,8 +761,11 @@ def p_dict_comp3(self, args):
""""
expr ::= dict_comp
stmt ::= dict_comp_func

dict_comp_func ::= BUILD_MAP_0 LOAD_ARG for_iter store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dict_comp_func ::= BUILD_MAP_0 LOAD_ARG for_iter store
comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER

comp_iter ::= comp_if
comp_iter ::= comp_if_not
Expand Down
Loading