You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Work on MAKE_CLOSURE rules for Python 3.3
This commit is contained in:
BIN
test/bytecode_3.4/02_closure.pyc
Normal file
BIN
test/bytecode_3.4/02_closure.pyc
Normal file
Binary file not shown.
20
test/simple_source/def/02_closure.py
Normal file
20
test/simple_source/def/02_closure.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Tests
|
||||
# Python3:
|
||||
# funcdef ::= mkfunc designator
|
||||
# designator ::= STORE_DEREF
|
||||
# mkfunc ::= load_closure BUILD_TUPLE_1 LOAD_CONST LOAD_CONST MAKE_CLOSURE_0
|
||||
# load_closure ::= LOAD_CLOSURE
|
||||
#
|
||||
# Python2:
|
||||
|
||||
# funcdef ::= mkfunc designator
|
||||
# designator ::= STORE_DEREF
|
||||
# mkfunc ::= load_closure LOAD_CONST MAKE_CLOSURE_0
|
||||
# load_closure ::= LOAD_CLOSURE
|
||||
|
||||
|
||||
def bug():
|
||||
def convert(node):
|
||||
if node:
|
||||
return convert(node.left)
|
||||
return
|
@@ -817,4 +817,26 @@ class Python3Parser(PythonParser):
|
||||
rule = 'mkfunc ::= %s LOAD_CONST %s' % ('expr ' * token.attr, opname)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
pass
|
||||
elif opname.startswith('MAKE_CLOSURE'):
|
||||
self.add_unique_rule('mklambda ::= %s load_closure LOAD_LAMBDA %s' %
|
||||
('expr ' * token.attr, opname), opname, token.attr,
|
||||
customize)
|
||||
self.add_unique_rule('genexpr ::= %s load_closure LOAD_GENEXPR %s '
|
||||
'expr GET_ITER CALL_FUNCTION_1' %
|
||||
('expr ' * token.attr, opname),
|
||||
opname, token.attr, customize)
|
||||
self.add_unique_rule('setcomp ::= %s load_closure LOAD_SETCOMP %s expr '
|
||||
'GET_ITER CALL_FUNCTION_1' %
|
||||
('expr ' * token.attr, opname),
|
||||
opname, token.attr, customize)
|
||||
self.add_unique_rule('dictcomp ::= %s load_closure LOAD_DICTCOMP %s '
|
||||
'expr GET_ITER CALL_FUNCTION_1' %
|
||||
('expr '* token.attr, opname),
|
||||
opname, token.attr, customize)
|
||||
rule = ('mkfunc ::= %s load_closure BUILD_TUPLE_1 LOAD_CONST LOAD_CONST %s'
|
||||
% ('expr ' * token.attr, opname))
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = ('mkfunc ::= %s load_closure BUILD_TUPLE_1 LOAD_GENXPR LOAD_CONST %s'
|
||||
% ('expr ' * token.attr, opname))
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
return
|
||||
|
@@ -64,7 +64,7 @@ methods implement most of the below.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import inspect, sys, re
|
||||
import sys, re
|
||||
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.code import iscode
|
||||
@@ -921,22 +921,17 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
def n_mkfunc(self, node):
|
||||
|
||||
if self.version >= 3.0:
|
||||
if self.version >= 3.3:
|
||||
# LOAD_CONST code object ..
|
||||
# LOAD_CONST 'x0'
|
||||
# MAKE_FUNCTION ..
|
||||
if self.version >= 3.3:
|
||||
func_name = node[-2].pattr
|
||||
code_index = -3
|
||||
else:
|
||||
func_name = node[-2].attr.co_name
|
||||
code_index = -2
|
||||
pass
|
||||
code_index = -3
|
||||
else:
|
||||
# LOAD_CONST code object ..
|
||||
# MAKE_FUNCTION ..
|
||||
func_name = node[-2].attr.co_name
|
||||
code_index = -2
|
||||
code = node[code_index]
|
||||
func_name = code.attr.co_name
|
||||
self.write(func_name)
|
||||
|
||||
self.indentMore()
|
||||
@@ -1564,7 +1559,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
code._tokens = None; code._customize = None # save memory
|
||||
self.classes.pop(-1)
|
||||
|
||||
def gen_source(self, ast, name, customize, isLambda=0, returnNone=False):
|
||||
def gen_source(self, ast, name, customize, isLambda=False, returnNone=False):
|
||||
"""convert AST to source code"""
|
||||
|
||||
rn = self.return_none
|
||||
|
Reference in New Issue
Block a user