Skip to content
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.10
rev: v0.9.4
hooks:
# Run the linter.
- id: ruff
Expand Down
569 changes: 278 additions & 291 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ ignore = [
"RUF005",
"RUF012",
"RUF013",
"RUF021",
"RUF022", # isort sorting style is not alphabetical and seems not natural either (despite the doc)
"UP008",
"UP015", # KEEP: redundant-open-modes
"UP024",
Expand Down
20 changes: 10 additions & 10 deletions src/api/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
from src.symbols.symbol_ import Symbol
from src.symbols.type_ import Type

__all__ = [
"check_type",
"check_is_declared_explicit",
__all__ = (
"check_and_make_label",
"check_type_is_explicit",
"check_call_arguments",
"check_is_declared_explicit",
"check_pending_calls",
"check_pending_labels",
"is_number",
"check_type",
"check_type_is_explicit",
"common_type",
"is_const",
"is_static",
"is_string",
"is_numeric",
"is_dynamic",
"is_null",
"is_number",
"is_numeric",
"is_static",
"is_string",
"is_unsigned",
"common_type",
]
)


# ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/api/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .config import OPTIONS

__all__ = ["__DEBUG__", "__LINE__", "__FILE__"]
__all__ = "__DEBUG__", "__FILE__", "__LINE__"

# --------------------- END OF GLOBAL FLAGS ---------------------

Expand Down
8 changes: 7 additions & 1 deletion src/api/errmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
from src.api.constants import CLASS

# Exports only these functions. Others
__all__ = ["error", "is_valid_warning_code", "warning", "warning_not_used", "register_warning"]
__all__ = (
"error",
"is_valid_warning_code",
"register_warning",
"warning",
"warning_not_used",
)


WARNING_PREFIX: str = "" # will be prepended to warning messages
Expand Down
8 changes: 4 additions & 4 deletions src/api/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

__all__ = [
"Error",
"InvalidOperatorError",
"InvalidLoopError",
"InvalidCONSTexpr",
"InvalidBuiltinFunctionError",
"InternalError",
"InvalidBuiltinFunctionError",
"InvalidCONSTexpr",
"InvalidLoopError",
"InvalidOperatorError",
"TempAlreadyFreedError",
]

Expand Down
7 changes: 6 additions & 1 deletion src/api/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

from src.api.exception import Error

__all__: Final[tuple[str, ...]] = "Option", "Options", "ANYTYPE", "Action"
__all__: Final[tuple[str, ...]] = (
"ANYTYPE",
"Action",
"Option",
"Options",
)


class ANYTYPE:
Expand Down
22 changes: 10 additions & 12 deletions src/api/symboltable/symboltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,10 @@ def declare_variable(self, id_: str, lineno: int, type_, default_value=None, cla
if entry_.scope == SCOPE.parameter:
syntax_error(
lineno,
f"Variable '{id_}' already declared as a parameter " f"at {entry_.filename}:{entry_.lineno}",
f"Variable '{id_}' already declared as a parameter at {entry_.filename}:{entry_.lineno}",
)
else:
syntax_error(lineno, f"Variable '{id_}' already declared at " f"{entry_.filename}:{entry_.lineno}")
syntax_error(lineno, f"Variable '{id_}' already declared at {entry_.filename}:{entry_.lineno}")
return None

if not self.check_class(id_, class_, lineno, scope=self.current_scope):
Expand Down Expand Up @@ -525,7 +525,7 @@ def declare_variable(self, id_: str, lineno: int, type_, default_value=None, cla
if entry.type_ != type_:
if not type_.implicit and entry.type_ is not None:
syntax_error(
lineno, "'%s' suffix is for type '%s' but it was " "declared as '%s'" % (id_, entry.type_, type_)
lineno, "'%s' suffix is for type '%s' but it was declared as '%s'" % (id_, entry.type_, type_)
)
return None

Expand Down Expand Up @@ -575,10 +575,10 @@ def declare_const(self, id_: str, lineno: int, type_, default_value):
if entry.scope == SCOPE.parameter:
syntax_error(
lineno,
"Constant '%s' already declared as a parameter " "at %s:%i" % (id_, entry.filename, entry.lineno),
"Constant '%s' already declared as a parameter at %s:%i" % (id_, entry.filename, entry.lineno),
)
else:
syntax_error(lineno, "Constant '%s' already declared at " "%s:%i" % (id_, entry.filename, entry.lineno))
syntax_error(lineno, "Constant '%s' already declared at %s:%i" % (id_, entry.filename, entry.lineno))
return None

entry = self.declare_variable(id_, lineno, type_, default_value, class_=CLASS.const)
Expand All @@ -600,7 +600,7 @@ def declare_label(self, id_: str, lineno: int) -> symbols.ID | None:
entry = self.get_entry(id_)
if entry is not None and entry.declared:
if entry.is_line_number:
syntax_error(lineno, "Duplicated line number '%s'. " "Previous was at %i" % (entry.name, entry.lineno))
syntax_error(lineno, "Duplicated line number '%s'. Previous was at %i" % (entry.name, entry.lineno))
else:
syntax_error(lineno, "Label '%s' already declared at line %i" % (id_, entry.lineno))
return None
Expand Down Expand Up @@ -680,23 +680,21 @@ def declare_array(self, id_: str, lineno: int, type_, bounds, default_value=None
if not entry.declared:
if entry.callable:
syntax_error(
lineno, "Array '%s' must be declared before use. " "First used at line %i" % (id_, entry.lineno)
lineno, "Array '%s' must be declared before use. First used at line %i" % (id_, entry.lineno)
)
return None
else:
if entry.scope == SCOPE.parameter:
syntax_error(
lineno, "variable '%s' already declared as a " "parameter at line %i" % (id_, entry.lineno)
)
syntax_error(lineno, "variable '%s' already declared as a parameter at line %i" % (id_, entry.lineno))
else:
syntax_error(lineno, "variable '%s' already declared at " "line %i" % (id_, entry.lineno))
syntax_error(lineno, "variable '%s' already declared at line %i" % (id_, entry.lineno))
return None

if entry.type_ != self.basic_types[TYPE.unknown] and entry.type_ != type_:
if not type_.implicit:
syntax_error(
lineno,
"Array suffix for '%s' is for type '%s' " "but declared as '%s'" % (entry.name, entry.type_, type_),
"Array suffix for '%s' is for type '%s' but declared as '%s'" % (entry.name, entry.type_, type_),
)
return None

Expand Down
4 changes: 2 additions & 2 deletions src/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from src.api import constants, errmsg, global_

__all__ = (
"chdir",
"first",
"flatten_list",
"open_file",
"read_txt_file",
"sanitize_filename",
"timeout",
"first",
"chdir",
)

__doc__ = """Utils module contains many helpers for several task,
Expand Down
3 changes: 1 addition & 2 deletions src/arch/z80/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from .visitor.translator import Translator
from .visitor.var_translator import VarTranslator

__all__ = "beep", "FunctionTranslator", "Translator", "VarTranslator"

__all__ = "FunctionTranslator", "Translator", "VarTranslator", "beep"

# -----------------------------------------
# Arch initialization setup
Expand Down
8 changes: 4 additions & 4 deletions src/arch/z80/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
from .main import Backend

__all__ = (
"Backend",
"Bits8",
"Bits16",
"Float",
"INITS",
"HI16",
"ICInfo",
"INITS",
"LO16",
"MAIN_LABEL",
"MEMINITS",
"REQUIRES",
"START_LABEL",
"TMP_COUNTER",
"TMP_STORAGES",
"Backend",
"engine",
"ICInfo",
"Bits8",
)
2 changes: 1 addition & 1 deletion src/arch/z80/optimizer/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Asm:
"""Defines an asm instruction"""

__slots__ = "inst", "oper", "asm", "cond", "output", "_bytes", "_max_tstates", "is_label"
__slots__ = "_bytes", "_max_tstates", "asm", "cond", "inst", "is_label", "oper", "output"

_operands_cache: dict[str, list[str]] = {}

Expand Down
2 changes: 1 addition & 1 deletion src/arch/z80/optimizer/cpustate.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def set(self, r: str, val: int | str | None) -> None:
if is_unknown8(val):
val = f"{new_tmp_val()}{HL_SEP}{val}"
assert is_num or is_unknown16(val) or is_label(val), (
f"val '{val}' is neither a number, nor a label" " nor an unknown16"
f"val '{val}' is neither a number, nor a label nor an unknown16"
)

self.regs[r] = val
Expand Down
50 changes: 25 additions & 25 deletions src/arch/z80/optimizer/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@
__all__ = (
"ALL_REGS",
"END_PROGRAM_LABEL",
"HI16",
"HI16_val",
"LO16",
"LO16_val",
"dict_intersection",
"get_H_from_unknown_value",
"get_L_from_unknown_value",
"get_orig_label_from_unknown16",
"idx_args",
"init",
"new_tmp_val",
"new_tmp_val16",
"new_tmp_val16_from_label",
"is_8bit_idx_register",
"is_8bit_normal_register",
"is_8bit_oper_register",
"is_16bit_composed_register",
"is_16bit_idx_register",
"is_16bit_normal_register",
"is_16bit_oper_register",
"is_label",
"is_mem_access",
"is_number",
"is_register",
"is_unknown",
"is_unknown8",
"is_unknown16",
"get_orig_label_from_unknown16",
"get_L_from_unknown_value",
"get_H_from_unknown_value",
"is_mem_access",
"is_number",
"is_label",
"valnum",
"to_int",
"new_tmp_val",
"new_tmp_val16",
"new_tmp_val16_from_label",
"simplify_arg",
"simplify_asm_args",
"is_register",
"is_8bit_normal_register",
"is_8bit_idx_register",
"is_8bit_oper_register",
"is_16bit_normal_register",
"is_16bit_idx_register",
"is_16bit_composed_register",
"is_16bit_oper_register",
"LO16",
"HI16",
"single_registers",
"idx_args",
"LO16_val",
"HI16_val",
"dict_intersection",
"to_int",
"valnum",
)


Expand Down
2 changes: 1 addition & 1 deletion src/arch/z80/optimizer/memcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MemCell:
the instruction.
"""

__slots__ = "addr", "__instr", "__dict__"
__slots__ = "__dict__", "__instr", "addr"
__instr: Asm

def __init__(self, instr: str, addr: int):
Expand Down
2 changes: 1 addition & 1 deletion src/arch/z80/peephole/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Evaluator:
+ (addition or concatenation for strings)
"""

__slots__ = "str_", "expression"
__slots__ = "expression", "str_"

def __init__(self, expression):
"""Initializes the object parsing the expression and preparing it for its (later)
Expand Down
4 changes: 2 additions & 2 deletions src/arch/z80/peephole/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BasicLinePattern:
$1 a pattern variable
"""

__slots__ = "line", "vars", "re_pattern", "re", "output"
__slots__ = "line", "output", "re", "re_pattern", "vars"

@staticmethod
def sanitize(pattern):
Expand Down Expand Up @@ -68,7 +68,7 @@ class LinePattern(BasicLinePattern):
If it matched, the vars_ dictionary will be updated with unified vars.
"""

__slots__ = "line", "vars", "re_pattern", "re", "output"
__slots__ = "line", "output", "re", "re_pattern", "vars"

def match(self, line: str, vars_: dict[str, str]) -> bool:
match = self.re.match(line)
Expand Down
8 changes: 4 additions & 4 deletions src/arch/zx48k/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
)
from src.arch.zx48k import backend # noqa

__all__ = [
"beep",
"VarTranslator",
__all__ = (
"FunctionTranslator",
"Translator",
]
"VarTranslator",
"beep",
)


# -----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/arch/zx48k/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from src.arch.z80.backend import Backend as Z80Backend

__all__ = (
"Float",
"HI16",
"INITS",
"LO16",
Expand All @@ -21,6 +20,7 @@
"TMP_COUNTER",
"TMP_STORAGES",
"Backend",
"Float",
)


Expand Down
7 changes: 6 additions & 1 deletion src/arch/zxnext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
optimizer, # noqa
)

__all__ = "beep", "VarTranslator", "FunctionTranslator", "Translator"
__all__ = (
"FunctionTranslator",
"Translator",
"VarTranslator",
"beep",
)


# -----------------------------------------
Expand Down
Loading