Skip to content

Commit 3fe7f8e

Browse files
committed
test: fix multi-arch testing
Also add test for mul8 and mul16
1 parent 9f2ac65 commit 3fe7f8e

8 files changed

Lines changed: 100 additions & 14 deletions

File tree

src/arch/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import importlib
66

77

8-
__all__ = ["zx48k", "zxnext"]
8+
__all__ = [
9+
"zx48k",
10+
"zxnext",
11+
]
912

1013
AVAILABLE_ARCHITECTURES = __all__
1114
target = None

src/arch/z80/backend/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,25 @@
128128
__all__ = [
129129
"tmp_label",
130130
"_fpop",
131+
"HI16",
132+
"INITS",
133+
"LO16",
131134
"LABEL_COUNTER",
132135
"MEMORY",
136+
"MEMINITS",
137+
"QUADS",
138+
"REQUIRES",
133139
"TMP_COUNTER",
134140
"TMP_STORAGES",
135-
"HI16",
136-
"LO16",
141+
"emit",
142+
"emit_end",
143+
"emit_start",
137144
]
138145

139146
# Default code ORG
140-
OPTIONS(Action.ADD, name="org", type=int, default=32768)
147+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="org", type=int, default=32768)
141148
# Default HEAP SIZE (Dynamic memory) in bytes
142-
OPTIONS(Action.ADD, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
149+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
143150

144151

145152
def init():
@@ -148,15 +155,15 @@ def init():
148155
common.init()
149156

150157
# Default code ORG
151-
OPTIONS(Action.ADD, name="org", type=int, default=32768)
158+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="org", type=int, default=32768)
152159
# Default HEAP SIZE (Dynamic memory) in bytes
153-
OPTIONS(Action.ADD, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
160+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
154161
# Labels for HEAP START (might not be used if not needed)
155-
OPTIONS(Action.ADD, name="heap_start_label", type=str, default=f"{NAMESPACE}.ZXBASIC_MEM_HEAP")
162+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_start_label", type=str, default=f"{NAMESPACE}.ZXBASIC_MEM_HEAP")
156163
# Labels for HEAP SIZE (might not be used if not needed)
157-
OPTIONS(Action.ADD, name="heap_size_label", type=str, default=f"{NAMESPACE}.ZXBASIC_HEAP_SIZE")
164+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_size_label", type=str, default=f"{NAMESPACE}.ZXBASIC_HEAP_SIZE")
158165
# Flag for headerless mode (No prologue / epilogue)
159-
OPTIONS(Action.ADD, name="headerless", type=bool, default=False, ignore_none=True)
166+
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="headerless", type=bool, default=False, ignore_none=True)
160167

161168
engine.main() # inits the optimizer
162169

src/arch/zx48k/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from src.arch.z80 import beep
66
from src.arch.z80.translator import * # noqa
7-
from src.arch.z80 import backend # noqa
7+
from src.arch.zx48k import backend # noqa
88
from src.arch.z80 import optimizer # noqa
99

1010

src/arch/zx48k/backend/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from src.api.config import OPTIONS
4+
from src.arch.z80 import backend
5+
6+
from src.arch.z80.backend import *
7+
8+
__all__ = [
9+
"tmp_label",
10+
"_fpop",
11+
"HI16",
12+
"INITS",
13+
"LO16",
14+
"LABEL_COUNTER",
15+
"MEMORY",
16+
"MEMINITS",
17+
"QUADS",
18+
"REQUIRES",
19+
"TMP_COUNTER",
20+
"TMP_STORAGES",
21+
"emit",
22+
"emit_end",
23+
"emit_start",
24+
]
25+
26+
27+
# ZXNext asm enabled by default for this arch
28+
OPTIONS.zxnext = False
29+
30+
31+
def init():
32+
# ZXNext asm enabled by default for this arch
33+
OPTIONS.zxnext = False
34+
35+
backend.init()

src/arch/zxnext/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from src.arch.z80 import beep
66
from src.arch.z80.translator import * # noqa
7-
from src.arch.z80 import backend # noqa
7+
from src.arch.zxnext import backend # noqa
88
from src.arch.z80 import optimizer # noqa
99

1010

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from src.api.config import OPTIONS
4+
from src.arch.z80 import backend
5+
6+
from src.arch.z80.backend import *
7+
8+
__all__ = [
9+
"tmp_label",
10+
"_fpop",
11+
"HI16",
12+
"INITS",
13+
"LO16",
14+
"LABEL_COUNTER",
15+
"MEMORY",
16+
"MEMINITS",
17+
"QUADS",
18+
"REQUIRES",
19+
"TMP_COUNTER",
20+
"TMP_STORAGES",
21+
"emit",
22+
"emit_end",
23+
"emit_start",
24+
]
25+
26+
27+
# ZXNext asm enabled by default for this arch
28+
OPTIONS.zxnext = True
29+
30+
31+
def init():
32+
# ZXNext asm enabled by default for this arch
33+
OPTIONS.zxnext = True
34+
35+
backend.init()

src/zxbc/zxbc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def main(args=None, emitter=None):
8787
options = parse_options(args)
8888
arch.set_target_arch(OPTIONS.architecture)
8989
backend = arch.target.backend
90+
backend.init() # Must reinitialize it again
91+
9092
args = [options.PROGRAM] # Strip out other options, because they're already set in the OPTIONS container
9193
input_filename = options.PROGRAM
9294

tests/functional/test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
EXIT_CODE = 0
2323
FILTER = r"^(([ \t]*;)|(#[ \t]*line))"
24+
DEFAULT_ARCH = "zx48k" # Default testing architecture
2425

2526
# Global tests and failed counters
2627
COUNTER = 0
@@ -226,6 +227,9 @@ def _get_testbas_options(fname: str):
226227
prep = ["-e", "/dev/null"] if CLOSE_STDERR else ["-e", STDERR]
227228
options = ["-O1"]
228229

230+
arch = os.path.dirname(fname).split(os.path.sep)[-1] or DEFAULT_ARCH
231+
options.extend(["--arch", arch])
232+
229233
match = reOPT.match(getName(fname))
230234
if match:
231235
options = ["-O" + match.groups()[0]]
@@ -595,7 +599,7 @@ def main(argv=None):
595599
parser.add_argument("-e", "--stderr", type=str, default=None, help="File for stderr messages")
596600
parser.add_argument("-S", "--use-shell", action="store_true", help="Use system shell for test instead of inline")
597601
parser.add_argument(
598-
"-O", "--option", action="append", help="Option to pass to compiler in a test " "(can be used many times)"
602+
"-O", "--option", action="append", help="Option to pass to compiler in a test (can be used many times)"
599603
)
600604
parser.add_argument(
601605
"-E",
@@ -625,7 +629,7 @@ def main(argv=None):
625629
TIMEOUT = 0 # disable timeout for Vim-dif
626630

627631
temp_dir_created = set_temp_dir(args.tmp_dir)
628-
files = {fname for pattern in args.FILES for fname in glob.glob(pattern, recursive=True)}
632+
files = sorted({fname for pattern in args.FILES for fname in glob.glob(pattern, recursive=True)})
629633

630634
if args.update:
631635
upgradeTest(files, args.update)

0 commit comments

Comments
 (0)