Skip to content

Commit 6bae216

Browse files
committed
feat: make tests idempotent when using tN
tNs are generated with OpcodesTemps() and the COUNTER must be reset upon compiler initialization.
1 parent 6ffa4d2 commit 6bae216

2 files changed

Lines changed: 12 additions & 4 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/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()

0 commit comments

Comments
 (0)