Skip to content

Commit 00c1d43

Browse files
authored
Merge pull request #686 from boriel/bugfix/ic_representation
fix: IC representation
2 parents d7121f5 + 6bae216 commit 00c1d43

8 files changed

Lines changed: 57 additions & 10 deletions

File tree

src/api/opcodestemps.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
# vim: ts=4:et:sw=4:
43

54
# ----------------------------------------------------------------------
65
# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel)
@@ -9,6 +8,8 @@
98
# the GNU General License
109
# ----------------------------------------------------------------------
1110

11+
__all__ = "OpcodesTemps", "init"
12+
1213

1314
class Counter:
1415
"""Implements a counter each time it's invoked"""
@@ -38,3 +39,9 @@ def __init__(self, prefix: str = "t"):
3839
def new_t(self):
3940
"""Returns a new t-value name"""
4041
return f"{self._prefix}{_COUNTER()}"
42+
43+
44+
def init():
45+
"""Initializes the global container"""
46+
global _COUNTER
47+
_COUNTER = Counter()

src/arch/interface/quad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, instr: str, *args) -> None:
2222

2323
def __str__(self) -> str:
2424
"""String representation"""
25-
return f"({self.instr} {', '.join(x for x in self.args)})"
25+
return str(tuple(self))
2626

2727
def __len__(self) -> int:
2828
"""Returns the number of arguments + 1 (the instruction)"""

src/zxbc/zxbparser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# Global containers
2828
from src.api import errmsg
2929
from src.api import global_ as gl
30+
from src.api import opcodestemps
3031
from src.api.check import (
3132
check_and_make_label,
3233
check_class,
@@ -46,7 +47,6 @@
4647
from src.api.debug import __DEBUG__
4748
from src.api.errmsg import error, warning
4849
from src.api.global_ import LoopInfo
49-
from src.api.opcodestemps import OpcodesTemps
5050

5151
# Compiler API
5252
from src.api.symboltable.symboltable import SymbolTable
@@ -135,7 +135,8 @@ def init():
135135

136136
ast = None
137137
data_ast = None # Global Variables AST
138-
optemps = OpcodesTemps()
138+
opcodestemps.init()
139+
optemps = opcodestemps.OpcodesTemps()
139140

140141
gl.INITS.clear()
141142
del gl.FUNCTION_CALLS[:]
@@ -3436,4 +3437,4 @@ def p_error(p):
34363437

34373438
ast = None
34383439
data_ast = None # Global Variables AST
3439-
optemps = OpcodesTemps()
3440+
optemps = opcodestemps.OpcodesTemps()

tests/functional/test.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
reOPT = re.compile(r"^opt([0-9]+)_") # To detect -On tests
1717
reBIN = re.compile(r"^(?:.*/)?(tzx|tap)_.*") # To detect tzx / tap test
18+
reIC = re.compile(r"^.*_IC$") # To detect intermediate code tests
1819

1920
EXIT_CODE = 0
20-
FILTER = r"^(([ \t]*;)|(#[ \t]*line))"
21+
FILTER = r"^(([ \t]*;)|(#[ \t]*line))|^\('inline',[ \t]+'#[ \t]*line .*'\)"
2122
DEFAULT_ARCH = "zx48k" # Default testing architecture
2223

2324
# Global tests and failed counters
@@ -233,11 +234,16 @@ def _get_testbas_options(fname: str) -> tuple[list[str], str, str]:
233234
if match:
234235
options.append("-O" + match.groups()[0])
235236

236-
match = reBIN.match(getName(fname))
237-
if match and match.groups()[0].lower() in ("tzx", "tap"):
238-
ext = match.groups()[0].lower()
237+
match_bin = reBIN.match(getName(fname))
238+
match_ic = reIC.match(getName(fname))
239+
if match_bin and match_bin.groups()[0].lower() in ("tzx", "tap"):
240+
ext = match_bin.groups()[0].lower()
239241
tfname = os.path.join(TEMP_DIR, getName(fname) + os.extsep + ext)
240242
options.extend(["--%s" % ext, fname, "-o", tfname, "-a", "-B"] + prep)
243+
elif match_ic:
244+
ext = "ic"
245+
tfname = os.path.join(TEMP_DIR, "test" + getName(fname) + os.extsep + ext)
246+
options.extend(["-E", fname, "-o", tfname] + prep)
241247
else:
242248
ext = "asm"
243249
tfname = os.path.join(TEMP_DIR, "test" + getName(fname) + os.extsep + ext)
@@ -406,7 +412,12 @@ def testBAS(
406412
func = lambda: systemExec(syscmd)
407413

408414
with TempTestFile(func, tfname, keep_file=UPDATE):
409-
result: bool | None = is_same_file(okfile, tfname, filter_, is_binary=reBIN.match(fname) is not None)
415+
result: bool | None = is_same_file(
416+
okfile,
417+
tfname,
418+
filter_,
419+
is_binary=reBIN.match(fname) is not None,
420+
)
410421
if UPDATE:
411422
if not result: # File changed
412423
if os.path.exists(okfile):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
border 7
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
('fparamu8', '7')
2+
('call', '.core.BORDER', '0')
3+
('end', '0')
4+
('inline', ';; --- end of user code ---')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
function test(a as Float) as string
3+
if a then return "not zero"
4+
end function
5+
6+
test(0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
('paramf', '0.0')
2+
('call', '_test', '0')
3+
('call', '.core.__MEM_FREE', '0')
4+
('end', '0')
5+
('label', '_test')
6+
('enter', '0')
7+
('ploadf', 't3', '0')
8+
('jzerof', 't3', '.LABEL.__LABEL1')
9+
('retstr', '#.LABEL.__LABEL2', '_test__leave')
10+
('label', '.LABEL.__LABEL1')
11+
('inline', '#line 3 "func_call_IC.bas"')
12+
('inline', '\nld hl, 0\n')
13+
('inline', '#line 6 "func_call_IC.bas"')
14+
('label', '_test__leave')
15+
('leave', '6')
16+
('vard', '.LABEL.__LABEL2', "['0008', '6E', '6F', '74', '20', '7A', '65', '72', '6F']")
17+
('inline', ';; --- end of user code ---')

0 commit comments

Comments
 (0)