You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Correct 3.6 FUNCTION_EX handling, somewhat
Some Python 2.4 compatibility snuck in but I suppose that is not so bad
This commit is contained in:
BIN
test/bytecode_3.5/04_call_function.pyc
Normal file
BIN
test/bytecode_3.5/04_call_function.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.6/04_call_function.pyc
Normal file
BIN
test/bytecode_3.6/04_call_function.pyc
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2015-2017 Rocky Bernstein
|
# Copyright (c) 2015-2018 Rocky Bernstein
|
||||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
# Copyright (c) 1999 John Aycock
|
# Copyright (c) 1999 John Aycock
|
||||||
@@ -15,8 +15,6 @@ If we succeed in creating a parse tree, then we have a Python program
|
|||||||
that a later phase can turn into a sequence of ASCII text.
|
that a later phase can turn into a sequence of ASCII text.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
||||||
from uncompyle6.parsers.astnode import AST
|
from uncompyle6.parsers.astnode import AST
|
||||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
@@ -523,7 +521,10 @@ class Python3Parser(PythonParser):
|
|||||||
"""Python 3.3 added a an addtional LOAD_CONST before MAKE_FUNCTION and
|
"""Python 3.3 added a an addtional LOAD_CONST before MAKE_FUNCTION and
|
||||||
this has an effect on many rules.
|
this has an effect on many rules.
|
||||||
"""
|
"""
|
||||||
new_rule = rule % (('LOAD_CONST ') * (1 if self.version >= 3.3 else 0))
|
if self.version >= 3.3:
|
||||||
|
new_rule = rule % (('LOAD_CONST ') * 1)
|
||||||
|
else:
|
||||||
|
new_rule = rule % (('LOAD_CONST ') * 0)
|
||||||
self.add_unique_rule(new_rule, opname, attr, customize)
|
self.add_unique_rule(new_rule, opname, attr, customize)
|
||||||
|
|
||||||
def customize_grammar_rules(self, tokens, customize):
|
def customize_grammar_rules(self, tokens, customize):
|
||||||
@@ -814,7 +815,10 @@ class Python3Parser(PythonParser):
|
|||||||
args_pos, args_kw, annotate_args = token.attr
|
args_pos, args_kw, annotate_args = token.attr
|
||||||
|
|
||||||
# FIXME: Fold test into add_make_function_rule
|
# FIXME: Fold test into add_make_function_rule
|
||||||
j = 1 if self.version < 3.3 else 2
|
if self.version < 3.3:
|
||||||
|
j = 1
|
||||||
|
else:
|
||||||
|
j = 2
|
||||||
if is_pypy or (i >= j and tokens[i-j] == 'LOAD_LAMBDA'):
|
if is_pypy or (i >= j and tokens[i-j] == 'LOAD_LAMBDA'):
|
||||||
rule_pat = ('mklambda ::= %sload_closure LOAD_LAMBDA %%s%s' %
|
rule_pat = ('mklambda ::= %sload_closure LOAD_LAMBDA %%s%s' %
|
||||||
('pos_arg '* args_pos, opname))
|
('pos_arg '* args_pos, opname))
|
||||||
|
@@ -158,8 +158,8 @@ class Python36Parser(Python35Parser):
|
|||||||
elif opname == 'CALL_FUNCTION_EX':
|
elif opname == 'CALL_FUNCTION_EX':
|
||||||
self.addRule("""
|
self.addRule("""
|
||||||
expr ::= call_ex
|
expr ::= call_ex
|
||||||
unpack_list ::= list
|
starred ::= expr
|
||||||
call_ex ::= expr unpack_list CALL_FUNCTION_EX
|
call_ex ::= expr starred CALL_FUNCTION_EX
|
||||||
""", nop_func)
|
""", nop_func)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@@ -533,8 +533,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
'fstring_single': ( "f'{%c%{conversion}}'", 0),
|
'fstring_single': ( "f'{%c%{conversion}}'", 0),
|
||||||
'fstring_multi': ( "f'%c'", 0),
|
'fstring_multi': ( "f'%c'", 0),
|
||||||
'func_args36': ( "%c(**", 0),
|
'func_args36': ( "%c(**", 0),
|
||||||
'try_except36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
|
'try_except36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
|
||||||
'unpack_list': ( '*%c', (0, 'list') ),
|
'unpack_list': ( '*%c', (0, 'list') ),
|
||||||
|
'starred': ( '*%c', (0, 'expr') ),
|
||||||
'call_ex' : (
|
'call_ex' : (
|
||||||
'%c(%c)',
|
'%c(%c)',
|
||||||
(0, 'expr'), 1),
|
(0, 'expr'), 1),
|
||||||
|
Reference in New Issue
Block a user