Bytecode 1.x fixes

This commit is contained in:
rocky
2022-04-30 14:05:44 -04:00
parent eba0d37d0f
commit 9aba1cc3af
6 changed files with 53 additions and 19 deletions

BIN
test/bytecode_1.0/os.pyc Normal file

Binary file not shown.

Binary file not shown.

BIN
test/bytecode_1.0/stat.pyc Normal file

Binary file not shown.

View File

@@ -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]

View File

@@ -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)})

View 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)
),
}
)