Skip to content

Commit 0c6ff06

Browse files
committed
refact: improve OptcodesTemp() code
1 parent 7679dff commit 0c6ff06

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

src/api/opcodestemps.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@
1010
# ----------------------------------------------------------------------
1111

1212

13-
class __Singleton(object):
14-
pass
13+
class Counter:
14+
""" Implements a counter each time it's invoked
15+
"""
16+
def __init__(self, start: int = 0, step: int = 1):
17+
self._count = start
18+
self._step = step
19+
20+
def __call__(self) -> int:
21+
result = self._count
22+
self._count += self._step
23+
24+
return result
1525

1626

17-
singleton = __Singleton()
18-
singleton.table = {}
19-
singleton.count = 0
27+
_COUNTER = Counter()
2028

2129

22-
class OpcodesTemps(object):
30+
class OpcodesTemps:
2331
""" Manages a table of Tn temporal values.
2432
This should be a SINGLETON container
2533
"""
26-
def __init__(self):
27-
self.data = singleton
34+
def __init__(self, prefix: str = "t"):
35+
self._prefix = prefix
2836

2937
def new_t(self):
3038
""" Returns a new t-value name
3139
"""
32-
self.data.count += 1
33-
return 't%i' % (self.data.count - 1)
40+
return f"{self._prefix}{_COUNTER()}"

0 commit comments

Comments
 (0)