You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Binary file not shown.
BIN
test/bytecode_2.6_run/02_ifelse_lambda.pyc
Normal file
BIN
test/bytecode_2.6_run/02_ifelse_lambda.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_2.7_run/02_ifelse_lambda.pyc
Normal file
BIN
test/bytecode_2.7_run/02_ifelse_lambda.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.5_run/02_ifelse_lambda.pyc
Normal file
BIN
test/bytecode_3.5_run/02_ifelse_lambda.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.6_run/02_ifelse_lambda.pyc
Normal file
BIN
test/bytecode_3.6_run/02_ifelse_lambda.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.7/04_withas.pyc
Normal file
BIN
test/bytecode_3.7/04_withas.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.7/05_36lambda.pyc
Normal file
BIN
test/bytecode_3.7/05_36lambda.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.7/05_call_function_kw2.pyc
Normal file
BIN
test/bytecode_3.7/05_call_function_kw2.pyc
Normal file
Binary file not shown.
@@ -2,7 +2,8 @@
|
|||||||
# lambda's have to be more or less on a line
|
# lambda's have to be more or less on a line
|
||||||
|
|
||||||
f = lambda x: 1 if x<2 else 3
|
f = lambda x: 1 if x<2 else 3
|
||||||
f(5)
|
assert f(3) == 3
|
||||||
|
assert f(1) == 1
|
||||||
|
|
||||||
# If that wasn't enough ...
|
# If that wasn't enough ...
|
||||||
# Python will create dead code
|
# Python will create dead code
|
||||||
@@ -10,10 +11,18 @@ f(5)
|
|||||||
# not to include the else expression
|
# not to include the else expression
|
||||||
|
|
||||||
g = lambda: 1 if True else 3
|
g = lambda: 1 if True else 3
|
||||||
g()
|
assert g() == 1
|
||||||
|
|
||||||
h = lambda: 1 if False else 3
|
h = lambda: 1 if False else 3
|
||||||
h()
|
assert h() == 3
|
||||||
|
|
||||||
# From 2.7 test_builtin
|
# From 2.7 test_builtin
|
||||||
lambda c: 'a' <= c <= 'z', 'Hello World'
|
i = lambda c: 'a' <= c <= 'z', 'Hello World'
|
||||||
|
assert i[0]('a') == True
|
||||||
|
assert i[0]('A') == False
|
||||||
|
|
||||||
|
# Issue #170. Bug is needing an "conditional_not_lambda" grammar rule
|
||||||
|
# in addition the the "conditional_lambda" rule
|
||||||
|
j = lambda a: False if not a else True
|
||||||
|
assert j(True) == True
|
||||||
|
assert j(False) == False
|
||||||
|
@@ -75,8 +75,12 @@ class Python25Parser(Python26Parser):
|
|||||||
setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 setup_finally
|
setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 setup_finally
|
||||||
stmt ::= classdefdeco
|
stmt ::= classdefdeco
|
||||||
stmt ::= conditional_lambda
|
stmt ::= conditional_lambda
|
||||||
|
stmt ::= conditional_not_lambda
|
||||||
conditional_lambda ::= expr jmp_false_then expr return_if_lambda
|
conditional_lambda ::= expr jmp_false_then expr return_if_lambda
|
||||||
return_stmt_lambda LAMBDA_MARKER
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
conditional_not_lambda
|
||||||
|
::= expr jmp_true_then expr return_if_lambda
|
||||||
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
""")
|
""")
|
||||||
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
|
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
|
||||||
if self.version == 2.5:
|
if self.version == 2.5:
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2017 Rocky Bernstein
|
# Copyright (c) 2017-2018 Rocky Bernstein
|
||||||
"""
|
"""
|
||||||
spark grammar differences over Python2 for Python 2.6.
|
spark grammar differences over Python2 for Python 2.6.
|
||||||
"""
|
"""
|
||||||
@@ -289,8 +289,12 @@ class Python26Parser(Python2Parser):
|
|||||||
|
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
||||||
stmt ::= conditional_lambda
|
stmt ::= conditional_lambda
|
||||||
|
stmt ::= conditional_not_lambda
|
||||||
conditional_lambda ::= expr jmp_false_then expr return_if_lambda
|
conditional_lambda ::= expr jmp_false_then expr return_if_lambda
|
||||||
return_stmt_lambda LAMBDA_MARKER
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
conditional_not_lambda ::=
|
||||||
|
expr jmp_true_then expr return_if_lambda
|
||||||
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
|
||||||
# conditional_true are for conditions which always evaluate true
|
# conditional_true are for conditions which always evaluate true
|
||||||
# There is dead or non-optional remnants of the condition code though,
|
# There is dead or non-optional remnants of the condition code though,
|
||||||
|
@@ -158,8 +158,12 @@ class Python27Parser(Python2Parser):
|
|||||||
# Common with 2.6
|
# Common with 2.6
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM
|
return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM
|
||||||
stmt ::= conditional_lambda
|
stmt ::= conditional_lambda
|
||||||
|
stmt ::= conditional_not_lambda
|
||||||
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
||||||
return_stmt_lambda LAMBDA_MARKER
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
conditional_not_lambda
|
||||||
|
::= expr jmp_true expr return_if_lambda
|
||||||
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
|
||||||
kv3 ::= expr expr STORE_MAP
|
kv3 ::= expr expr STORE_MAP
|
||||||
"""
|
"""
|
||||||
|
@@ -334,6 +334,17 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
def p_stmt3(self, args):
|
def p_stmt3(self, args):
|
||||||
"""
|
"""
|
||||||
|
stmt ::= conditional_lambda
|
||||||
|
stmt ::= conditional_not_lambda
|
||||||
|
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
||||||
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
conditional_not_lambda
|
||||||
|
::= expr jmp_true expr return_if_lambda
|
||||||
|
return_stmt_lambda LAMBDA_MARKER
|
||||||
|
|
||||||
|
return_stmt_lambda ::= ret_expr RETURN_VALUE_LAMBDA
|
||||||
|
return_if_lambda ::= RETURN_END_IF_LAMBDA
|
||||||
|
|
||||||
stmt ::= return_closure
|
stmt ::= return_closure
|
||||||
return_closure ::= LOAD_CLOSURE RETURN_VALUE RETURN_LAST
|
return_closure ::= LOAD_CLOSURE RETURN_VALUE RETURN_LAST
|
||||||
|
|
||||||
@@ -584,8 +595,12 @@ class Python3Parser(PythonParser):
|
|||||||
assign2_pypy ::= expr expr store store
|
assign2_pypy ::= expr expr store store
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA
|
return_if_lambda ::= RETURN_END_IF_LAMBDA
|
||||||
stmt ::= conditional_lambda
|
stmt ::= conditional_lambda
|
||||||
|
stmt ::= conditional_not_lambda
|
||||||
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
||||||
return_lambda LAMBDA_MARKER
|
return_lambda LAMBDA_MARKER
|
||||||
|
conditional_not_lambda
|
||||||
|
::= expr jmp_true expr return_if_lambda
|
||||||
|
return_lambda LAMBDA_MARKER
|
||||||
""", nop_func)
|
""", nop_func)
|
||||||
|
|
||||||
n = len(tokens)
|
n = len(tokens)
|
||||||
|
@@ -36,13 +36,6 @@ class Python36Parser(Python35Parser):
|
|||||||
# 3.6 redoes how return_closure works. FIXME: Isolate to LOAD_CLOSURE
|
# 3.6 redoes how return_closure works. FIXME: Isolate to LOAD_CLOSURE
|
||||||
return_closure ::= LOAD_CLOSURE DUP_TOP STORE_NAME RETURN_VALUE RETURN_LAST
|
return_closure ::= LOAD_CLOSURE DUP_TOP STORE_NAME RETURN_VALUE RETURN_LAST
|
||||||
|
|
||||||
stmt ::= conditional_lambda
|
|
||||||
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
|
||||||
return_stmt_lambda LAMBDA_MARKER
|
|
||||||
return_stmt_lambda ::= ret_expr RETURN_VALUE_LAMBDA
|
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA
|
|
||||||
|
|
||||||
|
|
||||||
for_block ::= l_stmts_opt come_from_loops JUMP_BACK
|
for_block ::= l_stmts_opt come_from_loops JUMP_BACK
|
||||||
come_from_loops ::= COME_FROM_LOOP*
|
come_from_loops ::= COME_FROM_LOOP*
|
||||||
|
|
||||||
|
@@ -209,7 +209,12 @@ TABLE_DIRECT = {
|
|||||||
'ret_cond': ( '%p if %p else %p', (2, 27), (0, 27), (-1, 27) ),
|
'ret_cond': ( '%p if %p else %p', (2, 27), (0, 27), (-1, 27) ),
|
||||||
'conditionalnot': ( '%p if not %p else %p', (2, 27), (0, 22), (4, 27) ),
|
'conditionalnot': ( '%p if not %p else %p', (2, 27), (0, 22), (4, 27) ),
|
||||||
'ret_cond_not': ( '%p if not %p else %p', (2, 27), (0, 22), (-1, 27) ),
|
'ret_cond_not': ( '%p if not %p else %p', (2, 27), (0, 22), (-1, 27) ),
|
||||||
'conditional_lambda': ( '%c if %c else %c', 2, 0, 4),
|
'conditional_lambda':
|
||||||
|
( '%c if %c else %c',
|
||||||
|
(2, 'expr'), 0, 4 ),
|
||||||
|
'conditional_not_lambda':
|
||||||
|
( '%c if not %c else %c',
|
||||||
|
(2, 'expr'), 0, 4 ),
|
||||||
|
|
||||||
'compare_single': ( '%p %[-1]{pattr.replace("-", " ")} %p', (0, 19), (1, 19) ),
|
'compare_single': ( '%p %[-1]{pattr.replace("-", " ")} %p', (0, 19), (1, 19) ),
|
||||||
'compare_chained': ( '%p %p', (0, 29), (1, 30)),
|
'compare_chained': ( '%p %p', (0, 29), (1, 30)),
|
||||||
@@ -321,7 +326,7 @@ MAP = {
|
|||||||
# or https://docs.python.org/3/reference/expressions.html
|
# or https://docs.python.org/3/reference/expressions.html
|
||||||
# for a list.
|
# for a list.
|
||||||
|
|
||||||
# Things at the top of this list below with low-value precidence will
|
# Things at the top of this lnist below with low-value precidence will
|
||||||
# tend to have parenthesis around them. Things at the bottom
|
# tend to have parenthesis around them. Things at the bottom
|
||||||
# of the list will tend not to have parenthesis around them.
|
# of the list will tend not to have parenthesis around them.
|
||||||
PRECEDENCE = {
|
PRECEDENCE = {
|
||||||
@@ -362,15 +367,11 @@ PRECEDENCE = {
|
|||||||
'BINARY_RSHIFT': 12,
|
'BINARY_RSHIFT': 12,
|
||||||
|
|
||||||
'BINARY_AND': 14,
|
'BINARY_AND': 14,
|
||||||
|
|
||||||
'BINARY_XOR': 16,
|
'BINARY_XOR': 16,
|
||||||
|
|
||||||
'BINARY_OR': 18,
|
'BINARY_OR': 18,
|
||||||
|
|
||||||
'compare': 20,
|
'compare': 20,
|
||||||
|
|
||||||
'unary_not': 22,
|
'unary_not': 22,
|
||||||
|
|
||||||
'and': 24,
|
'and': 24,
|
||||||
'ret_and': 24,
|
'ret_and': 24,
|
||||||
|
|
||||||
@@ -379,11 +380,13 @@ PRECEDENCE = {
|
|||||||
|
|
||||||
'conditional': 28,
|
'conditional': 28,
|
||||||
'conditional_lamdba': 28,
|
'conditional_lamdba': 28,
|
||||||
|
'conditional_not_lamdba': 28,
|
||||||
'conditionalnot': 28,
|
'conditionalnot': 28,
|
||||||
'ret_cond': 28,
|
'ret_cond': 28,
|
||||||
'ret_cond_not': 28,
|
'ret_cond_not': 28,
|
||||||
|
|
||||||
'_mklambda': 30,
|
'_mklambda': 30,
|
||||||
|
|
||||||
'yield': 101,
|
'yield': 101,
|
||||||
'yield_from': 101
|
'yield_from': 101
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user