Skip to content

Commit 445d4cc

Browse files
committed
refact: make actual use of binary functions operations
1 parent 6dc075d commit 445d4cc

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/arch/z80/visitor/translator.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from collections import namedtuple
2+
from collections.abc import Callable
3+
from typing import Any
24

35
import src.api.errmsg
46
import src.api.global_ as gl
@@ -145,8 +147,29 @@ def visit_BINARY(self, node):
145147
yield node.right
146148

147149
ins = {"PLUS": "add", "MINUS": "sub"}.get(node.operator, node.operator.lower())
148-
s = self.TSUFFIX(node.left.type_) # Operands type
149-
self.emit(ins + s, node.t, str(node.left.t), str(node.right.t))
150+
ins_t: dict[str, Callable[[TYPE | symbols.BASICTYPE, Any, Any, Any], None]] = {
151+
"add": self.ic_add,
152+
"sub": self.ic_sub,
153+
"mul": self.ic_mul,
154+
"div": self.ic_div,
155+
"or": self.ic_or,
156+
"xor": self.ic_xor,
157+
"and": self.ic_and,
158+
"eq": self.ic_eq,
159+
"ne": self.ic_ne,
160+
"gt": self.ic_gt,
161+
"lt": self.ic_lt,
162+
"le": self.ic_le,
163+
"ge": self.ic_ge,
164+
"band": self.ic_band,
165+
"bor": self.ic_bor,
166+
"bxor": self.ic_bxor,
167+
"shl": self.ic_shl,
168+
"shr": self.ic_shr,
169+
"pow": self.ic_pow,
170+
"mod": self.ic_mod,
171+
}
172+
ins_t[ins](node.left.type_, node.t, str(node.left.t), str(node.right.t))
150173

151174
def visit_TYPECAST(self, node):
152175
yield node.operand

0 commit comments

Comments
 (0)