Python 3.3 tolerance

This commit is contained in:
rocky
2022-04-25 07:53:36 -04:00
parent ee4d166e71
commit 0f525c142d
4 changed files with 17 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016, 2018-2021 by Rocky Bernstein
# Copyright (c) 2016, 2018-2022 by Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock
@@ -168,7 +168,7 @@ class Scanner(object):
opname="COLLECTION_START",
attr=collection_enum,
pattr=collection_type,
offset=f"{start_offset}_0",
offset="%s_0" % start_offset,
has_arg=True,
opc=self.opc,
has_extended_arg=False,
@@ -189,7 +189,7 @@ class Scanner(object):
)
new_tokens.append(
Token(
opname=f"BUILD_{collection_type}",
opname="BUILD_%s" % collection_type,
attr=t.attr,
pattr=t.pattr,
offset=t.offset,

View File

@@ -22,7 +22,6 @@ This sets up opcodes Python's 3.7 and calls a generalized
scanner routine for Python 3.
"""
from typing import Tuple
from uncompyle6.scanners.scanner37base import Scanner37Base
# bytecode verification, verify(), uses JUMP_OPs from here
@@ -44,7 +43,7 @@ class Scanner37(Scanner37Base):
def ingest(
self, co, classname=None, code_objects={}, show_asm=None
) -> Tuple[list, dict]:
):
"""
Create "tokens" the bytecode of an Python code object. Largely these
are the opcode name, but in some cases that has been modified to make parsing
@@ -78,7 +77,7 @@ class Scanner37(Scanner37Base):
else t.kind.split("_")[1]
)
new_tokens = self.bound_collection(
tokens, new_tokens, t, i, f"CONST_{collection_type}"
tokens, new_tokens, t, i, "CONST_%s" % collection_type
)
continue

View File

@@ -29,8 +29,6 @@ For example:
Finally we save token information.
"""
from typing import Any, Dict, List, Set
from xdis import iscode, instruction_size, Instruction
from xdis.bytecode import _get_const_info
@@ -534,17 +532,17 @@ class Scanner37Base(Scanner):
self.structs = [{"type": "root", "start": 0, "end": n - 1}]
# All loop entry points
self.loops: List[int] = []
self.loops = []
# Map fixed jumps to their real destination
self.fixed_jumps: Dict[int, int] = {}
self.fixed_jumps = {}
self.except_targets = {}
self.ignore_if: Set[int] = set()
self.ignore_if = set()
self.build_statement_indices()
# Containers filled by detect_control_flow()
self.not_continue: Set[int] = set()
self.return_end_ifs: Set[int] = set()
self.not_continue = set()
self.return_end_ifs = set()
self.setup_loop_targets = {} # target given setup_loop offset
self.setup_loops = {} # setup_loop offset given target
@@ -683,7 +681,7 @@ class Scanner37Base(Scanner):
slist += [codelen] * (codelen - len(slist))
def detect_control_flow(
self, offset: int, targets: Dict[Any, Any], inst_index: int
self, offset, targets, inst_index
):
"""
Detect type of block structures and their boundaries to fix optimized jumps
@@ -695,9 +693,9 @@ class Scanner37Base(Scanner):
op = inst.opcode
# Detect parent structure
parent: Dict[str, Any] = self.structs[0]
start: int = parent["start"]
end: int = parent["end"]
parent = self.structs[0]
start = parent["start"]
end = parent["end"]
# Pick inner-most parent for our offset
for struct in self.structs:
@@ -941,5 +939,5 @@ if __name__ == "__main__":
for t in tokens:
print(t)
else:
print(f"Need to be Python 3.7 to demo; I am version {version_tuple_to_str()}.")
print("Need to be Python 3.7 to demo; I am version %s." % version_tuple_to_str())
pass

View File

@@ -221,7 +221,7 @@ class NonterminalActions:
else:
# from trepan.api import debug; debug()
raise TypeError(
f"Internal Error: n_const_list expects dict, list set, or set; got {lastnodetype}"
"Internal Error: n_const_list expects dict, list set, or set; got %s" % lastnodetype
)
self.indent_more(INDENT_PER_LEVEL)
@@ -240,7 +240,7 @@ class NonterminalActions:
else:
if sep != "":
sep += " "
self.write(f"{sep} {repr(keys[i])}: {value}")
self.write("%s %s: %s" % (sep, repr(keys[i]), value))
sep = ","
else:
for elem in flat_elems: