Merge branch 'master' into python-3.3-to-3.5

This commit is contained in:
rocky
2021-11-21 14:10:57 -05:00
9 changed files with 98 additions and 19 deletions

View File

@@ -72,6 +72,9 @@ check-3.7: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.7-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-3.7 --syntax-verify $(COMPILE)
check-pypy37: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-pypy37 --verify-run
#: Run working tests from Python 3.8
check-3.8: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.8-run --verify-run
@@ -353,10 +356,14 @@ check-bytecode-pypy3.6: 7.1
#: PyPy 5.0.x with Python 3.6.9
check-bytecode-pypy3.6: 7.2 7.3
7.3 7.2:
7.2:
$(PYTHON) test_pythonlib.py --bytecode-pypy3.6-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-pypy3.6 --verify
7.3:
$(PYTHON) test_pythonlib.py --bytecode-pypy3.7 --verify-run
clean: clean-py-dis clean-dis clean-unverified

Binary file not shown.

View File

@@ -0,0 +1,10 @@
"""This program is self-checking!"""
def lcase(s):
return s.lower()
l = ["xyz", "ABC"]
l.sort(key=lcase)
assert l == ["ABC", "xyz"]

View File

@@ -48,6 +48,7 @@ TEST_VERSIONS = (
"pypy3.6-7.1.0",
"pypy3.6-7.1.1",
"pypy3.6-7.2.0",
"pypy3.8-7.3.7",
"native",
) + tuple(python_versions)
@@ -82,9 +83,10 @@ for vers in TEST_VERSIONS:
else:
if vers == "native":
short_vers = os.path.basename(sys.path[-1])
from xdis import PYTHON_VERSION
if PYTHON_VERSION > 3.0:
PYC = "*.cpython-%d.pyc" % int(PYTHON_VERSION * 10)
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE > (3, 0):
version = version_tuple_to_str(end=2)
PYC = f"*.cpython-{version}.pyc"
test_options[vers] = (sys.path[-1], PYC, short_vers)
else:
short_vers = vers[:3]

View File

@@ -116,6 +116,12 @@ for vers in (
pythonlib = os.path.join(pythonlib, "__pycache__")
test_options[key] = (os.path.join(lib_prefix, pythonlib), PYOC, pythonlib, vers)
vers = 3.7
bytecode = "bytecode_pypy%s_run" % vers
key = "bytecode-pypy37"
test_options[key] = (bytecode, PYC, bytecode, vers)
# -----

View File

@@ -17,6 +17,7 @@ Python 3.7 grammar for the spark Earley-algorithm parser.
"""
from __future__ import print_function
from uncompyle6.scanners.tok import Token
from uncompyle6.parser import PythonParserSingle, nop_func
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from uncompyle6.parsers.parse37base import Python37BaseParser

View File

@@ -523,15 +523,30 @@ class Python37BaseParser(PythonParser):
args_pos, args_kw = self.get_pos_kw(token)
# number of apply equiv arguments:
nak = (len(opname_base) - len("CALL_METHOD")) // 3
rule = (
"call ::= expr "
+ ("pos_arg " * args_pos)
+ ("kwarg " * args_kw)
+ "expr " * nak
+ opname
)
if opname == "CALL_METHOD_KW":
args_kw = token.attr
rules_str = """
expr ::= call_kw_pypy37
pypy_kw_keys ::= LOAD_CONST
"""
self.add_unique_doc_rules(rules_str, customize)
rule = (
"call_kw_pypy37 ::= expr "
+ ("expr " * args_kw)
+ " pypy_kw_keys "
+ opname
)
else:
args_pos, args_kw = self.get_pos_kw(token)
# number of apply equiv arguments:
nak = (len(opname_base) - len("CALL_METHOD")) // 3
rule = (
"call ::= expr "
+ ("expr " * args_pos)
+ ("kwarg " * args_kw)
+ "expr " * nak
+ opname
)
self.add_unique_rule(rule, opname, token.attr, customize)
elif opname == "CONTINUE":

View File

@@ -6,7 +6,7 @@ Does some additional massaging of xdis-disassembled instructions to
make things easier for decompilation.
"""
import decompyle3.scanners.scanner3y as scan
import decompyle3.scanners.scanner37 as scan
# bytecode verification, verify(), uses JUMP_OPS from here
from xdis.opcodes import opcode_37pypy as opc # is this right?
@@ -21,4 +21,5 @@ class ScannerPyPy37(scan.Scanner37):
scan.Scanner37.__init__(self, show_asm, is_pypy=True)
self.version = (3, 7)
self.opc = opc
self.is_pypy = True
return

View File

@@ -16,9 +16,9 @@
"""Isolate Python version-specific semantic actions here.
"""
from uncompyle6.semantics.consts import PRECEDENCE, TABLE_R, TABLE_DIRECT
from uncompyle6.parsers.treenode import SyntaxTree
from uncompyle6.semantics.consts import INDENT_PER_LEVEL, PRECEDENCE, TABLE_R, TABLE_DIRECT
from uncompyle6.semantics.helper import flatten_list
from uncompyle6.scanners.tok import Token
@@ -28,9 +28,10 @@ def customize_for_version(self, is_pypy, version):
# PyPy changes
#######################
TABLE_DIRECT.update({
'assert_pypy': ( '%|assert %c\n' , (1, 'assert_expr') ),
# This is as a result of an if transoration
'assert0_pypy': ( '%|assert %c\n' , (0, 'assert_expr') ),
"assert": ("%|assert %c\n", 0),
"assert_pypy": ( '%|assert %c\n' , (1, 'assert_expr') ),
# This is as a result of an if transformation
'assert0_pypy': ( '%|assert %c\n' , 0),
'assert_not_pypy': ( '%|assert not %c\n' , (1, 'assert_exp') ),
'assert2_not_pypy': ( '%|assert not %c, %c\n' , (1, 'assert_exp'),
@@ -42,6 +43,42 @@ def customize_for_version(self, is_pypy, version):
'assign3_pypy': ( '%|%c, %c, %c = %c, %c, %c\n', 5, 4, 3, 0, 1, 2 ),
'assign2_pypy': ( '%|%c, %c = %c, %c\n', 3, 2, 0, 1),
})
if version[:2] == (3, 7):
def n_call_kw_pypy37(node):
self.template_engine(("%p(", (0, 100)), node)
assert node[-1] == "CALL_METHOD_KW"
pypy_kw_keys = node[-2]
assert pypy_kw_keys == "pypy_kw_keys"
flat_elems = flatten_list(node[1:-2])
# FIXME zip pypy_kw_keys and elems
self.indent_more(INDENT_PER_LEVEL)
sep = ""
n = len(flat_elems)
kw_keys_tuple = pypy_kw_keys[0].attr
assert n == len(kw_keys_tuple)
for i in range(n):
elem = flat_elems[i]
assert elem == "expr"
line_number = self.line_number
value = self.traverse(elem)
if line_number != self.line_number:
sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
pass
self.write(sep)
self.write("%s=%s" % (kw_keys_tuple[i], value))
sep = ", "
pass
self.write(")")
self.prune()
self.n_call_kw_pypy37 = n_call_kw_pypy37
else:
########################
# Without PyPy