You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
continuing xdis refactor aftermath...
Both 2.7 bytecode broken from the refactor have now been reinstated, but two 3.5 and 3.6 bytecode have moved into the "todo" category.
This commit is contained in:
@@ -3,9 +3,14 @@
|
||||
ASSERT_OPS = frozenset(["LOAD_ASSERT", "RAISE_VARARGS_1"])
|
||||
def or_check(self, lhs, n, rule, ast, tokens, first, last):
|
||||
rhs = rule[1]
|
||||
if rhs in (("expr_jt", "expr"),
|
||||
("expr_jitop", "expr", "COME_FROM"),
|
||||
("expr_jit", "expr", "\\e_come_from_opt")):
|
||||
|
||||
# print("XXX", first, last, rule)
|
||||
# for t in range(first, last): print(tokens[t])
|
||||
# print("="*40)
|
||||
|
||||
if rhs[0:2] in (("expr_jt", "expr"),
|
||||
("expr_jitop", "expr"),
|
||||
("expr_jit", "expr")):
|
||||
if tokens[last] in ASSERT_OPS or tokens[last-1] in ASSERT_OPS:
|
||||
return True
|
||||
|
||||
@@ -22,28 +27,36 @@ def or_check(self, lhs, n, rule, ast, tokens, first, last):
|
||||
|
||||
first_offset = tokens[first].off2int()
|
||||
expr_jt = ast[0]
|
||||
|
||||
if expr_jt == "expr_jitop":
|
||||
jump_true = expr_jt[1]
|
||||
else:
|
||||
jump_true = expr_jt[1][0]
|
||||
|
||||
jmp_true_target = jump_true.attr
|
||||
jmp_true_target < first_offset
|
||||
|
||||
last_token = tokens[last]
|
||||
last_token_offset = last_token.off2int()
|
||||
|
||||
if jmp_true_target < first_offset:
|
||||
return False
|
||||
elif jmp_true_target < last_token_offset:
|
||||
return True
|
||||
|
||||
jmp_false = tokens[last]
|
||||
# If the jmp is backwards
|
||||
if jmp_false == "POP_JUMP_IF_FALSE":
|
||||
jmp_false_offset = jmp_false.off2int()
|
||||
if jmp_false.attr < jmp_false_offset:
|
||||
if last_token == "POP_JUMP_IF_FALSE":
|
||||
if last_token.attr < last_token_offset:
|
||||
# For a backwards loop, well compare to the instruction *after*
|
||||
# then POP_JUMP...
|
||||
jmp_false = tokens[last + 1]
|
||||
last_token = tokens[last + 1]
|
||||
return not (
|
||||
(jmp_false_offset <= jmp_true_target <= jmp_false_offset + 2)
|
||||
(last_token_offset <= jmp_true_target <= last_token_offset + 2)
|
||||
or jmp_true_target < tokens[first].off2int()
|
||||
)
|
||||
elif last_token == "JUMP_FORWARD" and expr_jt.kind != "expr_jitop":
|
||||
# "or" has to fall through to the next statement
|
||||
# FIXME: use instructions for all of this
|
||||
return True
|
||||
|
||||
|
||||
return False
|
||||
|
Reference in New Issue
Block a user