-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathopcodestemps.py
44 lines (30 loc) · 1.05 KB
/
opcodestemps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ----------------------------------------------------------------------
# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel)
#
# This program is Free Software and is released under the terms of
# the GNU General License
# ----------------------------------------------------------------------
__all__ = "OpcodesTemps", "init"
class Counter:
"""Implements a counter each time it's invoked"""
def __init__(self, start: int = 0, step: int = 1):
self._count = start
self._step = step
def __call__(self) -> int:
result = self._count
self._count += self._step
return result
_COUNTER = Counter()
class OpcodesTemps:
"""Manages a table of Tn temporal values.
This should be a SINGLETON container
"""
def __init__(self, prefix: str = "t"):
self._prefix = prefix
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()