Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#686 from boriel/bugfix/ic_representation
Browse files Browse the repository at this point in the history
fix: IC representation
  • Loading branch information
boriel committed Oct 19, 2023
2 parents d7121f5 + 6bae216 commit 00c1d43
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/api/opcodestemps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vim: ts=4:et:sw=4:

# ----------------------------------------------------------------------
# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel)
Expand All @@ -9,6 +8,8 @@
# the GNU General License
# ----------------------------------------------------------------------

__all__ = "OpcodesTemps", "init"


class Counter:
"""Implements a counter each time it's invoked"""
Expand Down Expand Up @@ -38,3 +39,9 @@ def __init__(self, prefix: str = "t"):
def new_t(self):
"""Returns a new t-value name"""
return f"{self._prefix}{_COUNTER()}"


def init():
"""Initializes the global container"""
global _COUNTER
_COUNTER = Counter()
2 changes: 1 addition & 1 deletion src/arch/interface/quad.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, instr: str, *args) -> None:

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

def __len__(self) -> int:
"""Returns the number of arguments + 1 (the instruction)"""
Expand Down
7 changes: 4 additions & 3 deletions src/zxbc/zxbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# Global containers
from src.api import errmsg
from src.api import global_ as gl
from src.api import opcodestemps
from src.api.check import (
check_and_make_label,
check_class,
Expand All @@ -46,7 +47,6 @@
from src.api.debug import __DEBUG__
from src.api.errmsg import error, warning
from src.api.global_ import LoopInfo
from src.api.opcodestemps import OpcodesTemps

# Compiler API
from src.api.symboltable.symboltable import SymbolTable
Expand Down Expand Up @@ -135,7 +135,8 @@ def init():

ast = None
data_ast = None # Global Variables AST
optemps = OpcodesTemps()
opcodestemps.init()
optemps = opcodestemps.OpcodesTemps()

gl.INITS.clear()
del gl.FUNCTION_CALLS[:]
Expand Down Expand Up @@ -3436,4 +3437,4 @@ def p_error(p):

ast = None
data_ast = None # Global Variables AST
optemps = OpcodesTemps()
optemps = opcodestemps.OpcodesTemps()
21 changes: 16 additions & 5 deletions tests/functional/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

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

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

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

match = reBIN.match(getName(fname))
if match and match.groups()[0].lower() in ("tzx", "tap"):
ext = match.groups()[0].lower()
match_bin = reBIN.match(getName(fname))
match_ic = reIC.match(getName(fname))
if match_bin and match_bin.groups()[0].lower() in ("tzx", "tap"):
ext = match_bin.groups()[0].lower()
tfname = os.path.join(TEMP_DIR, getName(fname) + os.extsep + ext)
options.extend(["--%s" % ext, fname, "-o", tfname, "-a", "-B"] + prep)
elif match_ic:
ext = "ic"
tfname = os.path.join(TEMP_DIR, "test" + getName(fname) + os.extsep + ext)
options.extend(["-E", fname, "-o", tfname] + prep)
else:
ext = "asm"
tfname = os.path.join(TEMP_DIR, "test" + getName(fname) + os.extsep + ext)
Expand Down Expand Up @@ -406,7 +412,12 @@ def testBAS(
func = lambda: systemExec(syscmd)

with TempTestFile(func, tfname, keep_file=UPDATE):
result: bool | None = is_same_file(okfile, tfname, filter_, is_binary=reBIN.match(fname) is not None)
result: bool | None = is_same_file(
okfile,
tfname,
filter_,
is_binary=reBIN.match(fname) is not None,
)
if UPDATE:
if not result: # File changed
if os.path.exists(okfile):
Expand Down
1 change: 1 addition & 0 deletions tests/functional/zx48k/border00_IC.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
border 7
4 changes: 4 additions & 0 deletions tests/functional/zx48k/border00_IC.ic
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
('fparamu8', '7')
('call', '.core.BORDER', '0')
('end', '0')
('inline', ';; --- end of user code ---')
6 changes: 6 additions & 0 deletions tests/functional/zx48k/func_call_IC.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

function test(a as Float) as string
if a then return "not zero"
end function

test(0)
17 changes: 17 additions & 0 deletions tests/functional/zx48k/func_call_IC.ic
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
('paramf', '0.0')
('call', '_test', '0')
('call', '.core.__MEM_FREE', '0')
('end', '0')
('label', '_test')
('enter', '0')
('ploadf', 't3', '0')
('jzerof', 't3', '.LABEL.__LABEL1')
('retstr', '#.LABEL.__LABEL2', '_test__leave')
('label', '.LABEL.__LABEL1')
('inline', '#line 3 "func_call_IC.bas"')
('inline', '\nld hl, 0\n')
('inline', '#line 6 "func_call_IC.bas"')
('label', '_test__leave')
('leave', '6')
('vard', '.LABEL.__LABEL2', "['0008', '6E', '6F', '74', '20', '7A', '65', '72', '6F']")
('inline', ';; --- end of user code ---')

0 comments on commit 00c1d43

Please sign in to comment.