Skip to content

Commit 1566b7a

Browse files
committed
refact: remove unused code
Also add type "str" for internal usage.
1 parent 4f389e9 commit 1566b7a

3 files changed

Lines changed: 5 additions & 35 deletions

File tree

src/arch/z80/backend/common.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from src.api import global_, tmp_labels
88
from src.api.config import OPTIONS, OptimizationStrategy
99
from src.api.exception import TempAlreadyFreedError
10-
1110
from .runtime import LABEL_REQUIRED_MODULES, NAMESPACE, RUNTIME_LABELS
1211
from .runtime import Labels as RuntimeLabel
1312

@@ -34,6 +33,7 @@ class DataType(StrEnum):
3433
i32 = "i32"
3534
f16 = "f16"
3635
f = "f"
36+
str = "str"
3737

3838

3939
# Handy constants, to not having to type long names :-)
@@ -46,7 +46,7 @@ class DataType(StrEnum):
4646
I32_t: Final[DataType] = DataType.i32
4747
F16_t: Final[DataType] = DataType.f16
4848
F_t: Final[DataType] = DataType.f
49-
49+
STR_t: Final[DataType] = DataType.str
5050

5151
# Internal data types definition, with its size in bytes, or -1 if it is variable (string)
5252
# Compound types are only arrays, and have the t
@@ -297,32 +297,6 @@ def get_bytes_size(elements: list[str]) -> int:
297297
return len(get_bytes(elements))
298298

299299

300-
def to_bool(stype: DataType) -> list[str]:
301-
"""Returns the instruction sequence for converting the number given number (in the stack)
302-
to boolean (just 0 (False) or non-zero (True))."""
303-
304-
if stype in (U8_t, I8_t):
305-
return []
306-
307-
if stype in (U16_t, I16_t):
308-
return [
309-
"ld a, h" "or l",
310-
]
311-
312-
if stype in (U32_t, I32_t, F16_t):
313-
return ["ld a, h" "or l" "or d", "or e,"]
314-
315-
if stype == F_t:
316-
return [
317-
"or b",
318-
"or c",
319-
"or d",
320-
"or e",
321-
]
322-
323-
raise NotImplementedError(f"type conversion from {stype} to bool is undefined")
324-
325-
326300
def normalize_boolean() -> list[str]:
327301
if OPTIONS.opt_strategy == OptimizationStrategy.Size:
328302
return [runtime_call(RuntimeLabel.NORMALIZE_BOOLEAN)]

src/arch/z80/backend/generic.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from src.api.config import OPTIONS
88
from src.api.fp import immediate_float
99
from src.api.tmp_labels import tmp_label
10-
1110
from . import common, exception
12-
from ._8bit import Bits8
1311
from ._16bit import Bits16
1412
from ._32bit import Bits32
13+
from ._8bit import Bits8
1514
from ._f16 import Fixed16
1615
from ._float import Float
1716
from .common import (
@@ -24,7 +23,6 @@
2423
get_bytes_size,
2524
new_ASMID,
2625
runtime_call,
27-
to_bool,
2826
to_byte,
2927
to_fixed,
3028
to_float,
@@ -365,8 +363,6 @@ def _cast(ins: Quad):
365363
output.extend(to_fixed(tA))
366364
elif tB == "f":
367365
output.extend(to_float(tA))
368-
elif tB == "bool":
369-
output.extend(to_bool(tA))
370366
else:
371367
raise exception.GenericError("Internal error: invalid typecast from %s to %s" % (tA, tB))
372368

src/arch/z80/visitor/translator_inst_visitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from src.api.debug import __DEBUG__
33
from src.arch.interface.quad import Quad
44
from src.arch.z80.backend import Backend
5-
from src.arch.z80.backend.common import BOOL_t, F16_t, F_t, I8_t, I16_t, I32_t, U8_t, U16_t, U32_t
5+
from src.arch.z80.backend.common import BOOL_t, F16_t, F_t, I8_t, I16_t, I32_t, U8_t, U16_t, U32_t, STR_t
66
from src.ast import NodeVisitor
77
from src.symbols import sym as symbols
88

@@ -30,7 +30,7 @@ def TSUFFIX(type_: TYPE | symbols.TYPEREF | symbols.BASICTYPE) -> str:
3030
TYPE.ulong: U32_t,
3131
TYPE.fixed: F16_t,
3232
TYPE.float: F_t,
33-
TYPE.string: "str",
33+
TYPE.string: STR_t,
3434
TYPE.boolean: BOOL_t,
3535
}
3636

0 commit comments

Comments
 (0)