You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Bytecode 1.x fixes
This commit is contained in:
BIN
test/bytecode_1.0/os.pyc
Normal file
BIN
test/bytecode_1.0/os.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_1.0/posixpath.pyc
Normal file
BIN
test/bytecode_1.0/posixpath.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_1.0/stat.pyc
Normal file
BIN
test/bytecode_1.0/stat.pyc
Normal file
Binary file not shown.
@@ -24,7 +24,6 @@ use in deparsing.
|
||||
|
||||
import sys
|
||||
import uncompyle6.scanners.scanner2 as scan
|
||||
from uncompyle6.scanner import L65536
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_26
|
||||
@@ -228,7 +227,9 @@ class Scanner26(scan.Scanner2):
|
||||
elif op in self.opc.JABS_OPS:
|
||||
pattr = repr(oparg)
|
||||
elif op in self.opc.LOCAL_OPS:
|
||||
if oparg in varnames:
|
||||
if self.version < (1, 5):
|
||||
pattr = names[oparg]
|
||||
else:
|
||||
pattr = varnames[oparg]
|
||||
elif op in self.opc.COMPARE_OPS:
|
||||
pattr = self.opc.cmp_op[oparg]
|
||||
|
@@ -193,24 +193,27 @@ def customize_for_version(self, is_pypy, version):
|
||||
self.prune()
|
||||
|
||||
self.n_iftrue_stmt24 = n_iftrue_stmt24
|
||||
elif version <= (1, 4):
|
||||
TABLE_DIRECT.update(
|
||||
{
|
||||
"call": (
|
||||
"%p(%P)",
|
||||
(0, "expr", 100), (1,-1,", ")
|
||||
),
|
||||
"print_expr_stmt": (
|
||||
("%|print %c,\n", 0)
|
||||
),
|
||||
}
|
||||
)
|
||||
elif version < (1, 4):
|
||||
from uncompyle6.semantics.customize14 import customize_for_version14
|
||||
customize_for_version14(self, version)
|
||||
|
||||
# FIXME: figure out how to handle LOAD_FAST
|
||||
# it uses code.names
|
||||
# def n_LOAD_FAST(node):
|
||||
# pass
|
||||
# self.n_LOAD_FAST = n_LOAD_FAST
|
||||
def n_call(node):
|
||||
expr = node[0]
|
||||
assert expr == "expr"
|
||||
params = node[1]
|
||||
if params == "tuple":
|
||||
self.template_engine(("%p(", (0, NO_PARENTHESIS_EVER)), expr)
|
||||
sep = ""
|
||||
for param in params[:-1]:
|
||||
self.write(sep)
|
||||
self.preorder(param)
|
||||
sep = ", "
|
||||
self.write(")")
|
||||
else:
|
||||
self.template_engine(("%p(%P)",
|
||||
(0, "expr", 100), (1,-1,", ", NO_PARENTHESIS_EVER)), node)
|
||||
self.prune()
|
||||
self.n_call = n_call
|
||||
|
||||
else: # 1.0 <= version <= 2.3:
|
||||
TABLE_DIRECT.update({"if1_stmt": ("%|if 1\n%+%c%-", 5)})
|
||||
|
30
uncompyle6/semantics/customize14.py
Normal file
30
uncompyle6/semantics/customize14.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) 2022 by Rocky Bernstein
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""Isolate Python 1.4- version-specific semantic actions here.
|
||||
"""
|
||||
|
||||
from uncompyle6.semantics.consts import TABLE_DIRECT
|
||||
|
||||
#######################
|
||||
# Python 1.4- Changes #
|
||||
#######################
|
||||
def customize_for_version14(self, version):
|
||||
TABLE_DIRECT.update(
|
||||
{
|
||||
"print_expr_stmt": (
|
||||
("%|print %c\n", 0)
|
||||
),
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user