You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
previous 2.7 class decorator bug fixed in 3.x
This commit is contained in:
BIN
test/bytecode_3.4/10_classdec.pyc
Normal file
BIN
test/bytecode_3.4/10_classdec.pyc
Normal file
Binary file not shown.
@@ -184,7 +184,6 @@ class Python3Parser(PythonParser):
|
|||||||
classdefdeco ::= classdefdeco1 designator
|
classdefdeco ::= classdefdeco1 designator
|
||||||
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
|
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
|
||||||
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
||||||
classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST CALL_FUNCTION_2
|
|
||||||
|
|
||||||
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
||||||
@@ -358,13 +357,13 @@ class Python3Parser(PythonParser):
|
|||||||
'''
|
'''
|
||||||
# Should the first rule be somehow folded into the 2nd one?
|
# Should the first rule be somehow folded into the 2nd one?
|
||||||
build_class ::= LOAD_BUILD_CLASS mkfunc
|
build_class ::= LOAD_BUILD_CLASS mkfunc
|
||||||
LOAD_CLASSNAME {expr}^n CALL_FUNCTION_n+2
|
LOAD_CLASSNAME {expr}^n-1 CALL_FUNCTION_n
|
||||||
LOAD_CONST CALL_FUNCTION_n
|
LOAD_CONST CALL_FUNCTION_n
|
||||||
build_class ::= LOAD_BUILD_CLASS mkfunc
|
build_class ::= LOAD_BUILD_CLASS mkfunc
|
||||||
expr
|
expr
|
||||||
call_function
|
call_function
|
||||||
CALL_FUNCTION_3
|
CALL_FUNCTION_3
|
||||||
'''
|
'''
|
||||||
# FIXME: I bet this can be simplified
|
# FIXME: I bet this can be simplified
|
||||||
# look for next MAKE_FUNCTION
|
# look for next MAKE_FUNCTION
|
||||||
for i in range(i+1, len(tokens)):
|
for i in range(i+1, len(tokens)):
|
||||||
@@ -401,7 +400,9 @@ class Python3Parser(PythonParser):
|
|||||||
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_n POP_TOP
|
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_n POP_TOP
|
||||||
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n POP_TOP
|
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n POP_TOP
|
||||||
call_function ::= expr {expr}^n CALL_FUNCTION_KW_n POP_TOP
|
call_function ::= expr {expr}^n CALL_FUNCTION_KW_n POP_TOP
|
||||||
"""
|
|
||||||
|
classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n
|
||||||
|
"""
|
||||||
# Low byte indicates number of positional paramters,
|
# Low byte indicates number of positional paramters,
|
||||||
# high byte number of positional parameters
|
# high byte number of positional parameters
|
||||||
args_pos = token.attr & 0xff
|
args_pos = token.attr & 0xff
|
||||||
@@ -413,6 +414,9 @@ class Python3Parser(PythonParser):
|
|||||||
+ ('kwarg ' * args_kw)
|
+ ('kwarg ' * args_kw)
|
||||||
+ 'expr ' * nak + token.type)
|
+ 'expr ' * nak + token.type)
|
||||||
self.add_unique_rule(rule, token.type, args_pos, customize)
|
self.add_unique_rule(rule, token.type, args_pos, customize)
|
||||||
|
rule = ('classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d'
|
||||||
|
% (('expr ' * (args_pos-1)), opname, args_pos))
|
||||||
|
self.add_unique_rule(rule, token.type, args_pos, customize)
|
||||||
|
|
||||||
def add_custom_rules(self, tokens, customize):
|
def add_custom_rules(self, tokens, customize):
|
||||||
"""
|
"""
|
||||||
@@ -553,7 +557,7 @@ class Python3Parser(PythonParser):
|
|||||||
'expr GET_ITER CALL_FUNCTION_1' %
|
'expr GET_ITER CALL_FUNCTION_1' %
|
||||||
('pos_arg ' * args_pos, opname),
|
('pos_arg ' * args_pos, opname),
|
||||||
opname, token.attr, customize)
|
opname, token.attr, customize)
|
||||||
if self.version >= 3.4:
|
if self.version >= 3.3:
|
||||||
rule1 = ('listcomp ::= %sload_closure LOAD_LISTCOMP LOAD_CONST %s expr '
|
rule1 = ('listcomp ::= %sload_closure LOAD_LISTCOMP LOAD_CONST %s expr '
|
||||||
'GET_ITER CALL_FUNCTION_1' % ('expr ' * args_pos, opname))
|
'GET_ITER CALL_FUNCTION_1' % ('expr ' * args_pos, opname))
|
||||||
rule2 = ('setcomp ::= %sload_closure LOAD_SETCOMP LOAD_CONST %s expr '
|
rule2 = ('setcomp ::= %sload_closure LOAD_SETCOMP LOAD_CONST %s expr '
|
||||||
|
@@ -34,6 +34,7 @@ import xdis.opcodes.opcode_33 as op3
|
|||||||
|
|
||||||
globals().update(op3.opmap)
|
globals().update(op3.opmap)
|
||||||
|
|
||||||
|
# POP_JUMP_IF is used by verify
|
||||||
POP_JUMP_TF = (POP_JUMP_IF_TRUE, POP_JUMP_IF_FALSE)
|
POP_JUMP_TF = (POP_JUMP_IF_TRUE, POP_JUMP_IF_FALSE)
|
||||||
|
|
||||||
import uncompyle6.scanner as scan
|
import uncompyle6.scanner as scan
|
||||||
@@ -56,7 +57,8 @@ class Scanner3(scan.Scanner):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
show_asm = self.show_asm if not show_asm else show_asm
|
show_asm = self.show_asm if not show_asm else show_asm
|
||||||
if self.show_asm in ('both', 'before'):
|
# show_asm = 'both'
|
||||||
|
if show_asm in ('both', 'before'):
|
||||||
bytecode = Bytecode(co, self.opc)
|
bytecode = Bytecode(co, self.opc)
|
||||||
for instr in bytecode.get_instructions(co):
|
for instr in bytecode.get_instructions(co):
|
||||||
print(instr._disassemble())
|
print(instr._disassemble())
|
||||||
|
Reference in New Issue
Block a user