Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Upgrade: 3.9 - 3.12 #28

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Build Python wheels
uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311'
python-versions: 'cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion explorerscript/antlr/ExplorerScriptLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class ExplorerScriptLexer(Lexer):
SKIP_ = 91
UNKNOWN_CHAR = 92

channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ]

modeNames = [ "DEFAULT_MODE" ]

Expand Down
27 changes: 13 additions & 14 deletions explorerscript/antlr/ExplorerScriptParser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated from ExplorerScript.g4 by ANTLR 4.11.1
# encoding: utf-8
from antlr4 import *
from io import StringIO
import sys
Expand Down Expand Up @@ -535,7 +534,7 @@ def start(self):
self.state = 136
self._errHandler.sync(self)
_la = self._input.LA(1)
while (((_la - 24)) & ~0x3f) == 0 and ((1 << (_la - 24)) & 6597069766657) != 0:
while ((_la - 24) & ~0x3f) == 0 and ((1 << (_la - 24)) & 6597069766657) != 0:
self.state = 134
self._errHandler.sync(self)
token = self._input.LA(1)
Expand Down Expand Up @@ -1178,7 +1177,7 @@ def macro_call(self):
self.state = 195
self._errHandler.sync(self)
_la = self._input.LA(1)
if (((_la - 63)) & ~0x3f) == 0 and ((1 << (_la - 63)) & 33566209) != 0:
if ((_la - 63) & ~0x3f) == 0 and ((1 << (_la - 63)) & 33566209) != 0:
self.state = 194
self.arglist()

Expand Down Expand Up @@ -1444,7 +1443,7 @@ def if_block(self):
self.state = 229
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 226
self.stmt()
self.state = 231
Expand Down Expand Up @@ -1585,7 +1584,7 @@ def elseif_block(self):
self.state = 260
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 257
self.stmt()
self.state = 262
Expand Down Expand Up @@ -1660,7 +1659,7 @@ def else_block(self):
self.state = 270
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 267
self.stmt()
self.state = 272
Expand Down Expand Up @@ -2364,7 +2363,7 @@ def single_case_block(self):
self.state = 343
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 340
self.stmt()
self.state = 345
Expand Down Expand Up @@ -2450,7 +2449,7 @@ def default(self):
self.state = 354
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 351
self.stmt()
self.state = 356
Expand Down Expand Up @@ -3161,7 +3160,7 @@ def forever_block(self):
self.state = 413
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 410
self.stmt()
self.state = 415
Expand Down Expand Up @@ -3265,7 +3264,7 @@ def for_block(self):
self.state = 429
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 426
self.stmt()
self.state = 431
Expand Down Expand Up @@ -3367,7 +3366,7 @@ def while_block(self):
self.state = 445
self._errHandler.sync(self)
_la = self._input.LA(1)
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
while ((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0:
self.state = 442
self.stmt()
self.state = 447
Expand Down Expand Up @@ -4574,7 +4573,7 @@ def integer_like(self):
self.enterOuterAlt(localctx, 1)
self.state = 536
_la = self._input.LA(1)
if not((((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 11) != 0):
if not(((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 11) != 0):
self._errHandler.recoverInline(self)
else:
self._errHandler.reportMatch(self)
Expand Down Expand Up @@ -4642,7 +4641,7 @@ def operation(self):
self.state = 541
self._errHandler.sync(self)
_la = self._input.LA(1)
if (((_la - 63)) & ~0x3f) == 0 and ((1 << (_la - 63)) & 33566209) != 0:
if ((_la - 63) & ~0x3f) == 0 and ((1 << (_la - 63)) & 33566209) != 0:
self.state = 540
self.arglist()

Expand Down Expand Up @@ -4724,7 +4723,7 @@ def func_suite(self):
self.state = 549
self._errHandler.sync(self)
_la = self._input.LA(1)
if not (((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or (((_la - 73)) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0):
if not (((_la) & ~0x3f) == 0 and ((1 << _la) & 2249618519826104320) != 0 or ((_la - 73) & ~0x3f) == 0 and ((1 << (_la - 73)) & 16399) != 0):
break

pass
Expand Down
2 changes: 1 addition & 1 deletion explorerscript/antlr/SsbScriptLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class SsbScriptLexer(Lexer):
SKIP_ = 33
UNKNOWN_CHAR = 34

channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ]

modeNames = [ "DEFAULT_MODE" ]

Expand Down
1 change: 0 additions & 1 deletion explorerscript/antlr/SsbScriptParser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated from SsbScript.g4 by ANTLR 4.11.1
# encoding: utf-8
from antlr4 import *
from io import StringIO
import sys
Expand Down
4 changes: 2 additions & 2 deletions explorerscript/cli/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from explorerscript.util import open_utf8


def build_ops(ops: List[SsbOperation]):
def build_ops(ops: list[SsbOperation]):
out_ops = []
for op in ops:
out_op = {"opcode": op.op_code.name, "params": []}
Expand Down Expand Up @@ -71,7 +71,7 @@ def build_ops(ops: List[SsbOperation]):


def build_routines_json(
routine_infos: List[SsbRoutineInfo], named_coroutines: List[str], routine_ops: List[List[SsbOperation]]
routine_infos: list[SsbRoutineInfo], named_coroutines: list[str], routine_ops: list[list[SsbOperation]]
):
routines = []
for info, name, ops in zip(routine_infos, named_coroutines, routine_ops):
Expand Down
4 changes: 2 additions & 2 deletions explorerscript/cli/decompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def parse_pos_mark_arg(arg_str):
return exps_int(arg_str_arr[0]), 2


def read_ops(ops: List[dict]) -> List[SsbOperation]:
def read_ops(ops: list[dict]) -> list[SsbOperation]:
out_ops = []

for op in ops:
Expand Down Expand Up @@ -88,7 +88,7 @@ def read_ops(ops: List[dict]) -> List[SsbOperation]:
return out_ops


def read_routines(routines: List[dict]) -> Tuple[List[SsbRoutineInfo], List[SsbCoroutine], List[List[SsbOperation]]]:
def read_routines(routines: list[dict]) -> tuple[list[SsbRoutineInfo], list[SsbCoroutine], list[list[SsbOperation]]]:
routine_infos = []
named_coroutines = []
routine_ops = []
Expand Down
24 changes: 12 additions & 12 deletions explorerscript/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class MacroEndSsbLabel(SsbLabel):


class ExplorerScriptMacro:
def __init__(self, name: str, variables: List[str],
blueprints: List[SsbOperation], source_map: SourceMap):
def __init__(self, name: str, variables: list[str],
blueprints: list[SsbOperation], source_map: SourceMap):
"""
A model for a ExplorerScript macro. Contains the processed (= all sub-macros are already fully processed)
opcodes by the MacroVisitor and some metadata.
Expand All @@ -53,10 +53,10 @@ def __init__(self, name: str, variables: List[str],
self.name: str = name

# The names of the variables, in order of definition in the header.
self.variables: List[str] = variables
self.variables: list[str] = variables

# The Ssb operations that act as a blueprint for this macro
self.blueprints: List[SsbOperation] = blueprints
self.blueprints: list[SsbOperation] = blueprints

# The absolute path to the ExplorerScript source file that this macro is in.
# May be not set, if this macro is not in a physical file.
Expand All @@ -71,8 +71,8 @@ def __init__(self, name: str, variables: List[str],
# This is useful for source maps, to know where the macro file lies relative to the original compiled file.
self.included__relative_path: Optional[str] = None

def build(self, op_idx_counter: Counter, lbl_idx_counter: Counter, parameters: Dict[str, SsbOpParam],
smb: SourceMapBuilder) -> List[SsbOperation]:
def build(self, op_idx_counter: Counter, lbl_idx_counter: Counter, parameters: dict[str, SsbOpParam],
smb: SourceMapBuilder) -> list[SsbOperation]:
"""
Returns new built opcodes for this macro. SsbOpConstants in the blueprints, that have the names of variables,
are replaced with the values from the parameter dict. The keys for the dict are the names of the variables,
Expand All @@ -91,7 +91,7 @@ def build(self, op_idx_counter: Counter, lbl_idx_counter: Counter, parameters: D

# Add the macro start label if we are processed later as a sub-macro, so that the parent macro can push
# our ops to the callstack.
out_ops: List[SsbOperation] = [MacroStartSsbLabel(
out_ops: list[SsbOperation] = [MacroStartSsbLabel(
lbl_idx_counter(), -1, len_real_ops_in_blueprints, parameter_mapping, f"Macro call {self.name} start label."
)]

Expand All @@ -101,7 +101,7 @@ def build(self, op_idx_counter: Counter, lbl_idx_counter: Counter, parameters: D
)

# Maps blueprint label ids to new actual labels
new_labels: Dict[int, SsbLabel] = {}
new_labels: dict[int, SsbLabel] = {}

for blueprint_op in self.blueprints:
# If this a start / end of a macro, update the macro callstack
Expand Down Expand Up @@ -154,7 +154,7 @@ def build(self, op_idx_counter: Counter, lbl_idx_counter: Counter, parameters: D
return out_ops

def _build_op(self, op_idx_counter: Counter, blueprint_op: SsbOperation,
smb: SourceMapBuilder, params: Dict[str, SsbOpParam]):
smb: SourceMapBuilder, params: dict[str, SsbOpParam]):
new_op_idx = op_idx_counter()
# Maybe this op was also included through a macro, if so just relay the macro source map entry
potential_macro_sm_entry = self.source_map.get_op_line_and_col__macros(blueprint_op.offset)
Expand Down Expand Up @@ -182,7 +182,7 @@ def _build_op(self, op_idx_counter: Counter, blueprint_op: SsbOperation,
new_op_idx, blueprint_op.op_code, self._process_parameters(blueprint_op.params, params)
)

def _process_parameters(self, original_params: List[SsbOpParam], macro_params: Dict[str, SsbOpParam]) -> List[SsbOpParam]:
def _process_parameters(self, original_params: list[SsbOpParam], macro_params: dict[str, SsbOpParam]) -> list[SsbOpParam]:
"""
Returns a copy of original_params,
where SsbOpConstants that match keys of macro_params are
Expand All @@ -200,10 +200,10 @@ def _process_parameters(self, original_params: List[SsbOpParam], macro_params: D
new_params.append(p)
return new_params

def _create_parameter_mapping(self, parameters: Dict[str, SsbOpParam]):
def _create_parameter_mapping(self, parameters: dict[str, SsbOpParam]):
return {x: str(y) for x, y in parameters.items()}

def _replace_in_param_mapping(self, parameter_mapping: Dict[str, Tuple[int, str]], our_parameters: Dict[str, SsbOpParam]):
def _replace_in_param_mapping(self, parameter_mapping: dict[str, tuple[int, str]], our_parameters: dict[str, SsbOpParam]):
our_parameters = self._create_parameter_mapping(our_parameters)
new_dict = {}
for p_name, p_value in parameter_mapping.items():
Expand Down
38 changes: 18 additions & 20 deletions explorerscript/source_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#
import json
import logging
from typing import Dict, Tuple, List, Union, Optional, Iterable
from typing import Dict, Tuple, List, Union, Optional
from collections.abc import Iterable
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -123,8 +124,8 @@ def deserialize(cls, data_list) -> 'SourceMapping':
class MacroSourceMapping(SourceMapping):
def __init__(self, relpath_included_file: str, macro_name: str,
line_number: int, column: int,
called_in: Optional[Tuple[str, int, int]],
return_addr: Optional[int], parameter_mapping: Dict[str, Union[int, str]]):
called_in: Optional[tuple[str, int, int]],
return_addr: Optional[int], parameter_mapping: dict[str, Union[int, str]]):
super().__init__(line_number, column)
self.relpath_included_file = relpath_included_file
self.macro_name = macro_name
Expand Down Expand Up @@ -173,10 +174,10 @@ class SourceMap:
"""
def __init__(
self,
mappings: Dict[int, SourceMapping],
position_marks: List[SourceMapPositionMark],
mappings_macros: Dict[int, MacroSourceMapping],
position_marks_macro: List[Tuple[Optional[str], str, SourceMapPositionMark]]
mappings: dict[int, SourceMapping],
position_marks: list[SourceMapPositionMark],
mappings_macros: dict[int, MacroSourceMapping],
position_marks_macro: list[tuple[Optional[str], str, SourceMapPositionMark]]
):
"""
mappings: Actual main source mappings:
Expand Down Expand Up @@ -210,25 +211,22 @@ def get_op_line_and_col__macros(self, op_offset: int) -> Optional[MacroSourceMap
if op_offset in self._mappings_macros:
return self._mappings_macros[op_offset]

def get_position_marks__direct(self) -> List[SourceMapPositionMark]:
def get_position_marks__direct(self) -> list[SourceMapPositionMark]:
return self._position_marks

def get_position_marks__macros(self) -> List[Tuple[Optional[str], str, SourceMapPositionMark]]:
def get_position_marks__macros(self) -> list[tuple[Optional[str], str, SourceMapPositionMark]]:
return self._position_marks_macro

def __iter__(self) -> Iterable[Tuple[int, MacroSourceMapping]]:
def __iter__(self) -> Iterable[tuple[int, MacroSourceMapping]]:
"""
Iterates over all source map entries, including the macro entries.
If it's a macro entry, macro_name is a string.
"""
for opcode_offset, entry in self._mappings.items():
yield opcode_offset, entry
for opcode_offset, entry in self._mappings_macros.items():
yield opcode_offset, entry
yield from self._mappings.items()
yield from self._mappings_macros.items()

def collect_mappings__macros(self) -> Iterable[Tuple[int, MacroSourceMapping]]:
for opcode_offset, entry in self._mappings_macros.items():
yield opcode_offset, entry
def collect_mappings__macros(self) -> Iterable[tuple[int, MacroSourceMapping]]:
yield from self._mappings_macros.items()

def __eq__(self, other):
if not isinstance(other, SourceMap):
Expand Down Expand Up @@ -262,7 +260,7 @@ def deserialize(cls, json_str: str) -> 'SourceMap':
def create_empty(cls):
return cls({}, [], {}, [])

def rewrite_offsets(self, new_mapping: Dict[int, int]):
def rewrite_offsets(self, new_mapping: dict[int, int]):
"""
Replace all opcode offsets (in mappings, macrco mappings, macro return addresses) with new
offsets. The parameter is a dict mapping old offsets to new offsets.
Expand Down Expand Up @@ -293,7 +291,7 @@ def __init__(self):
self._mappings_macros = {}
self._pos_marks_macros = []
self._next_macro_called_in: Optional[SourceMapping] = None
self._macro_context__stack: List[Tuple[int, Dict[str, Union[int, str]]]] = []
self._macro_context__stack: list[tuple[int, dict[str, Union[int, str]]]] = []
#logger.debug("<%d>: Init.", id(self))

def add_opcode(self, op_offset, line_number, column):
Expand All @@ -304,7 +302,7 @@ def add_position_mark(self, position_mark: SourceMapPositionMark):
self._pos_marks.append(position_mark)
#logger.debug("<%d>: Adding PositionMark: %s", id(self), position_mark)

def macro_context__push(self, opcode_to_jump_to: int, parameter_mapping: Dict[str, Union[int, str]]):
def macro_context__push(self, opcode_to_jump_to: int, parameter_mapping: dict[str, Union[int, str]]):
"""
Push a new macro return address and parameter mapping to the stack, all added macro ops will
use what's on the top of the stack.
Expand Down
2 changes: 1 addition & 1 deletion explorerscript/source_map_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, source_code: str, source_map: SourceMap, apply_for_macro_call
self.source_code = source_code
self._source_map = source_map
# A dict of a list of strings to insert at given lines
self._inserts: Dict[int, List[str]] = {}
self._inserts: dict[int, list[str]] = {}

# Opcodes
for opcode_offset, mapping in self._source_map:
Expand Down
Loading