You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
BUILD_{MAP,TUPLE}_UNPACK & CALL_FUNCTION_EX_KW...
Bang on these in 3.6. Not totally succesfull right now. In fact a regression on one of the test cases
This commit is contained in:
BIN
test/bytecode_3.6/04_CALL_FUNCTION_VAR_KW.pyc-notyet
Normal file
BIN
test/bytecode_3.6/04_CALL_FUNCTION_VAR_KW.pyc-notyet
Normal file
Binary file not shown.
@@ -507,11 +507,13 @@ class Python3Parser(PythonParser):
|
|||||||
('pos_arg ' * args_pos) +
|
('pos_arg ' * args_pos) +
|
||||||
('kwarg ' * args_kw) + kw + token.type)
|
('kwarg ' * args_kw) + kw + token.type)
|
||||||
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
||||||
|
if self.version >= 3.6 and opname == 'CALL_FUNCTION_EX_KW':
|
||||||
rule = ('call_function ::= expr ' +
|
rule = 'call_function ::= expr build_tuple_unpack_with_call build_map_unpack_with_call CALL_FUNCTION_EX_KW_1'
|
||||||
('pos_arg ' * args_pos) +
|
else:
|
||||||
('kwarg ' * args_kw) +
|
rule = ('call_function ::= expr ' +
|
||||||
'expr ' * nak + token.type)
|
('pos_arg ' * args_pos) +
|
||||||
|
('kwarg ' * args_kw) +
|
||||||
|
'expr ' * nak + token.type)
|
||||||
|
|
||||||
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
||||||
if self.version >= 3.5:
|
if self.version >= 3.5:
|
||||||
@@ -610,9 +612,9 @@ class Python3Parser(PythonParser):
|
|||||||
assign2_pypy ::= expr expr designator designator
|
assign2_pypy ::= expr expr designator designator
|
||||||
""", nop_func)
|
""", nop_func)
|
||||||
continue
|
continue
|
||||||
elif opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
elif (opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||||
'CALL_FUNCTION_VAR_KW') \
|
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_EX_KW')
|
||||||
or opname.startswith('CALL_FUNCTION_KW'):
|
or opname.startswith('CALL_FUNCTION_KW')):
|
||||||
self.custom_classfunc_rule(opname, token, customize)
|
self.custom_classfunc_rule(opname, token, customize)
|
||||||
elif opname == 'LOAD_DICTCOMP':
|
elif opname == 'LOAD_DICTCOMP':
|
||||||
rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr "
|
rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr "
|
||||||
@@ -633,6 +635,18 @@ class Python3Parser(PythonParser):
|
|||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
rule = 'expr ::= build_list_unpack'
|
rule = 'expr ::= build_list_unpack'
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
|
elif opname.startswith('BUILD_TUPLE_UNPACK_WITH_CALL'):
|
||||||
|
v = token.attr
|
||||||
|
rule = ('build_tuple_unpack_with_call ::= ' + 'expr1024 ' * int(v//1024) +
|
||||||
|
'expr32 ' * int((v//32) % 32) +
|
||||||
|
'expr ' * (v % 32) + opname)
|
||||||
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
|
elif opname.startswith('BUILD_MAP_UNPACK_WITH_CALL'):
|
||||||
|
v = token.attr
|
||||||
|
rule = ('build_map_unpack_with_call ::= ' + 'expr1024 ' * int(v//1024) +
|
||||||
|
'expr32 ' * int((v//32) % 32) +
|
||||||
|
'expr ' * (v % 32) + opname)
|
||||||
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
|
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
|
||||||
v = token.attr
|
v = token.attr
|
||||||
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
|
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
|
||||||
@@ -642,7 +656,10 @@ class Python3Parser(PythonParser):
|
|||||||
if opname_base == 'BUILD_TUPLE':
|
if opname_base == 'BUILD_TUPLE':
|
||||||
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
|
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
|
rule = ('build_tuple ::= ' + 'expr1024 ' * int(v//1024) +
|
||||||
|
'expr32 ' * int((v//32) % 32) +
|
||||||
|
'expr ' * (v % 32) + opname)
|
||||||
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
elif opname == 'LOOKUP_METHOD':
|
elif opname == 'LOOKUP_METHOD':
|
||||||
# A PyPy speciality - DRY with parse2
|
# A PyPy speciality - DRY with parse2
|
||||||
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
|
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
|
||||||
|
@@ -25,12 +25,13 @@ class Python36Parser(Python35Parser):
|
|||||||
|
|
||||||
func_args36 ::= expr BUILD_TUPLE_0
|
func_args36 ::= expr BUILD_TUPLE_0
|
||||||
call_function ::= func_args36 unmapexpr CALL_FUNCTION_EX
|
call_function ::= func_args36 unmapexpr CALL_FUNCTION_EX
|
||||||
|
call_function ::= func_args36 build_map_unpack_with_call CALL_FUNCTION_EX_KW_1
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
|
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
|
||||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||||
|
|
||||||
call_function ::= expr expr CALL_FUNCTION_EX
|
call_function ::= expr expr CALL_FUNCTION_EX
|
||||||
call_function ::= expr expr expr CALL_FUNCTION_EX_KW
|
call_function ::= expr expr expr CALL_FUNCTION_EX_KW_1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_custom_rules(self, tokens, customize):
|
def add_custom_rules(self, tokens, customize):
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2016 by Rocky Bernstein
|
# Copyright (c) 2016-2017 by Rocky Bernstein
|
||||||
"""
|
"""
|
||||||
Python 3.6 bytecode scanner/deparser
|
Python 3.6 bytecode scanner/deparser
|
||||||
|
|
||||||
@@ -28,8 +28,12 @@ class Scanner36(Scanner3):
|
|||||||
if t.op == self.opc.CALL_FUNCTION_EX and t.attr & 1:
|
if t.op == self.opc.CALL_FUNCTION_EX and t.attr & 1:
|
||||||
t.type = 'CALL_FUNCTION_EX_KW'
|
t.type = 'CALL_FUNCTION_EX_KW'
|
||||||
pass
|
pass
|
||||||
if t.op == self.opc.CALL_FUNCTION_KW:
|
elif t.op == self.opc.CALL_FUNCTION_KW:
|
||||||
t.type = 'CALL_FUNCTION_KW_{t.attr}'.format(**locals())
|
t.type = 'CALL_FUNCTION_KW_{t.attr}'.format(**locals())
|
||||||
|
elif t.op == self.opc.BUILD_TUPLE_UNPACK_WITH_CALL:
|
||||||
|
t.type = 'BUILD_TUPLE_UNPACK_WITH_CALL_%d' % t.attr
|
||||||
|
elif t.op == self.opc.BUILD_MAP_UNPACK_WITH_CALL:
|
||||||
|
t.type = 'BUILD_MAP_UNPACK_WITH_CALL_%d' % t.attr
|
||||||
pass
|
pass
|
||||||
return tokens, customize
|
return tokens, customize
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user