You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Sync a little with decompyle3
This commit is contained in:
42
test/simple_source/bug37/02_and_or.py
Normal file
42
test/simple_source/bug37/02_and_or.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# from 3.7 decompyle3/pytest/validate.py
|
||||||
|
# 3.7 changes changes "and" to use JUMP_IF_FALSE_OR_POP instead of
|
||||||
|
# POP_JUMP_IF_FALSE
|
||||||
|
|
||||||
|
# RUNNABLE!
|
||||||
|
def are_instructions_equal(a, b, c, d):
|
||||||
|
return a and (b or c) and d
|
||||||
|
|
||||||
|
for a, b, c, d, expect in (
|
||||||
|
(True, True, False, True, True),
|
||||||
|
(True, False, True, True, True),
|
||||||
|
(False, False, True, True, False),
|
||||||
|
(True, False, True, False, False),
|
||||||
|
):
|
||||||
|
assert are_instructions_equal(a, b, c, d) == expect
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME: figure out how to fix properly, and test.
|
||||||
|
# from 3.7 decompyle3/semantics/pysource.py
|
||||||
|
|
||||||
|
# Bug *is* miscompiling to
|
||||||
|
# if a:
|
||||||
|
# if b or c:
|
||||||
|
# d = 1
|
||||||
|
# else:
|
||||||
|
# d = 2
|
||||||
|
|
||||||
|
def n_alias(a, b, c, d=3):
|
||||||
|
if a and b or c:
|
||||||
|
d = 1
|
||||||
|
else:
|
||||||
|
d = 2
|
||||||
|
return d
|
||||||
|
|
||||||
|
for a, b, c, expect in (
|
||||||
|
(True, True, False, 1),
|
||||||
|
(True, False, True, 1),
|
||||||
|
# (True, False, False, 2), # miscompiles
|
||||||
|
# (False, False, True, 1), # miscompiles
|
||||||
|
(False, False, False, 2),
|
||||||
|
):
|
||||||
|
assert n_alias(a, b, c) == expect, f"{a}, {b}, {c}, {expect}"
|
25
test/simple_source/bug37/03_jump_to_jump.py
Normal file
25
test/simple_source/bug37/03_jump_to_jump.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# From uncompyle6/verify.py
|
||||||
|
# Bug was POP_JUMP offset to short so we have a POP_JUMP
|
||||||
|
# to a JUMP_ABSOULTE and this messes up reduction rule checking.
|
||||||
|
|
||||||
|
def cmp_code_objects(member, a, tokens1, tokens2, verify, f):
|
||||||
|
for member in members:
|
||||||
|
while a:
|
||||||
|
# Increase the bytecode length of the while statement
|
||||||
|
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
|
||||||
|
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
|
||||||
|
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
|
||||||
|
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
|
||||||
|
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
|
||||||
|
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
|
||||||
|
x = 49; x = 50; x = 51; x = 52; x = 53;
|
||||||
|
if tokens1:
|
||||||
|
if tokens2:
|
||||||
|
continue
|
||||||
|
elif f:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
a = 2
|
||||||
|
|
||||||
|
i1 += 1
|
||||||
|
x = 54 # comment this out and we're good
|
@@ -70,4 +70,6 @@ def customize_for_version37(self, version):
|
|||||||
'testfalse_not_or': ( "not %c or %c",
|
'testfalse_not_or': ( "not %c or %c",
|
||||||
(0, "expr"),
|
(0, "expr"),
|
||||||
(2, "expr") ),
|
(2, "expr") ),
|
||||||
|
'testfalse_not_and': ( "not (%c)", 0 ),
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@@ -243,9 +243,7 @@ class TreeTransform(GenericASTTraversal, object):
|
|||||||
)
|
)
|
||||||
node[3] = elifelse_stmt
|
node[3] = elifelse_stmt
|
||||||
else:
|
else:
|
||||||
elif_stmt = SyntaxTree(
|
elif_stmt = SyntaxTree("elifstmt", [n[0], n[else_suite_index]])
|
||||||
"elifstmt", [n[0], n[else_suite_index]]
|
|
||||||
)
|
|
||||||
node[3] = elif_stmt
|
node[3] = elif_stmt
|
||||||
|
|
||||||
node.transformed_by = "n_ifelsestmt"
|
node.transformed_by = "n_ifelsestmt"
|
||||||
@@ -260,11 +258,11 @@ class TreeTransform(GenericASTTraversal, object):
|
|||||||
|
|
||||||
def n_list_for(self, list_for_node):
|
def n_list_for(self, list_for_node):
|
||||||
expr = list_for_node[0]
|
expr = list_for_node[0]
|
||||||
if (expr == "expr" and expr[0] == "get_iter"):
|
if expr == "expr" and expr[0] == "get_iter":
|
||||||
# Remove extraneous get_iter() inside the "for" of a comprehension
|
# Remove extraneous get_iter() inside the "for" of a comprehension
|
||||||
assert expr[0][0] == "expr"
|
assert expr[0][0] == "expr"
|
||||||
list_for_node[0] = expr[0][0]
|
list_for_node[0] = expr[0][0]
|
||||||
list_for_node.transformed_by="n_list_for",
|
list_for_node.transformed_by = ("n_list_for",)
|
||||||
return list_for_node
|
return list_for_node
|
||||||
|
|
||||||
def traverse(self, node, is_lambda=False):
|
def traverse(self, node, is_lambda=False):
|
||||||
|
Reference in New Issue
Block a user