Handle comprehensions inside a lambda

This commit is contained in:
rocky 2023-08-11 12:13:46 -04:00
parent 48a0a411b8
commit 20af515dda
7 changed files with 34 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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

View File

@ -37,11 +37,16 @@ class Python27Parser(Python2Parser):
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

View File

@ -74,9 +74,15 @@ class Python30Parser(Python31Parser):
# 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
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_LAMBDA LAMBDA_MARKER
list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST
list_comp ::= list_comp_header
@ -107,6 +113,10 @@ class Python30Parser(Python31Parser):
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

View File

@ -741,9 +741,13 @@ class Python37Parser(Python37BaseParser):
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
@ -757,8 +761,11 @@ class Python37Parser(Python37BaseParser):
""""
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