diff --git a/masm2c/op.py b/masm2c/op.py index 104bc2e..a89ff17 100644 --- a/masm2c/op.py +++ b/masm2c/op.py @@ -54,8 +54,8 @@ def getsize(self) -> int: def __str__(self) -> str: return str(self.__class__) - #@property - #def data(self): + def accept(self, visitor: "Cpp") -> str: + raise NotImplementedError() class var: @@ -1044,6 +1044,7 @@ def __init__(self, name: str) -> None: self.original_type = "" self.implemented = False self.size = 0 + self.value: Expression def gettype(self): return self.original_type @@ -1065,6 +1066,7 @@ def __init__(self, args: list[Union[str, Expression]]) -> None: self.original_type = "" self.implemented = False self.size = 0 + self.value: Expression def gettype(self): return self.original_type @@ -1087,6 +1089,7 @@ class _mov(baseop): def __init__(self, args: list[Expression]) -> None: super().__init__() self.children = args + self.syntetic = False def accept(self, visitor: "Cpp") -> str: return visitor._mov(*self.children) diff --git a/masm2c/proc.py b/masm2c/proc.py index a3537d4..46c327e 100644 --- a/masm2c/proc.py +++ b/masm2c/proc.py @@ -22,7 +22,7 @@ import logging import re -from typing import Any +from typing import Any, TYPE_CHECKING, ClassVar from lark import lark @@ -32,11 +32,14 @@ from . import op from .Token import Token +if TYPE_CHECKING: + from .cpp import Cpp + PTRDIR = "ptrdir" class Proc: - last_addr = 0xc000 + last_addr: ClassVar = 0xc000 def __init__(self, name: str, far: bool = False, line_number: int = 0, extern: bool = False, offset: int | None=0, real_offset: int | None=0, @@ -51,13 +54,13 @@ def __init__(self, name: str, far: bool = False, line_number: int = 0, extern: b self.name = name self.original_name = name - self.stmts = [] + self.stmts: list[baseop] = [] self.provided_labels = {name} self.line_number = line_number self.far = far self.used = False self.extern = extern - self.used_labels = set() + self.used_labels: set[str] = set() self.group = None self.segment = segment @@ -65,7 +68,7 @@ def __init__(self, name: str, far: bool = False, line_number: int = 0, extern: b Proc.last_addr += 4 self.real_offset, self.real_seg = real_offset, real_seg - def merge_two_procs(self, newname, other): + def merge_two_procs(self, newname: str, other: Proc): self.name, self.original_name = newname, newname self.stmts += other.stmts self.provided_labels |= other.provided_labels @@ -83,7 +86,7 @@ def optimize(self, keep_labels=None): # trivial simplifications - def create_instruction_object(self, instruction: Token, args: list[Any | Expression] | None=None) -> baseop: + def create_instruction_object(self, instruction: lark.Token, args: list[Any | Expression] | None=None) -> baseop: """:param instruction: the instruction name :param args: a list of strings, each string is an argument to the instruction :return: An object of type cl, which is a subclass of Instruction. @@ -96,14 +99,14 @@ def create_instruction_object(self, instruction: Token, args: list[Any | Express o.syntetic = False return o - def find_op_class(self, cmd: Token, args: list[Any | Expression]) -> Any: + def find_op_class(self, cmd: lark.Token, args: list[Any | Expression]) -> Any: try: cl = getattr(op, f"_{cmd.lower()}") except AttributeError: cl = self.find_op_common_class(cmd, args) return cl - def find_op_common_class(self, cmd: str, args: list[Any | Expression]) -> type[_instruction3 | _instruction2 | _instruction0 | _jump | _instruction1]: + def find_op_common_class(self, cmd: str, args: list[Any | Expression]) -> type[baseop]: logging.debug(cmd) try: cl = ( @@ -125,6 +128,7 @@ def create_equ_op(label: str, value: Expression, line_number: int) -> _equ: # T o = op._equ(label) if ptrdir := Token.find_tokens(value, PTRDIR): if isinstance(ptrdir[0], Token): + assert isinstance(ptrdir[0].children, str) o.original_type = ptrdir[0].children.lower() elif isinstance(ptrdir[0], str): o.original_type = ptrdir[0].lower()