-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.py
56 lines (43 loc) · 1.54 KB
/
variables.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
45
46
47
48
49
50
51
52
53
54
55
56
class Variable:
def __init__(self):
pass
def __init__(self, pid, memory_location):
self.pid = pid
self.is_initialized = False
self.memory_location = memory_location
self.is_shadowed = False
self.reference_to_iterator = None
class VariableOfArray(Variable):
def __init__(self, array, index):
self.array = array
self.index = index
class ArrayOfVariables(Variable):
def __init__(self, pid, memory_location, start, end):
if start > end:
raise IncorrectIndexRangeError
self.pid = pid
self.start = start
self.end = end
self.length = end - start + 1
self.is_initialized = True
self.memory_location = memory_location
self.variables = dict()
def at_index(self, index: int):
if not self.start <= index <= self.end:
raise IndexError
my_index = index-self.start
if my_index not in self.variables:
self.variables[my_index] = Variable(self.pid+"[" + str(my_index) + "]", self.memory_location+my_index)
self.variables[my_index].is_initialized = True
return self.variables[my_index]
class VariableIterator(Variable):
def __init__(self, pid, memory_location, start, end):
self.pid = pid
self.start = start
self.end = end
self.is_initialized = True
self.memory_location = memory_location
self.is_in_register = False
self.register_location = None
class IncorrectIndexRangeError(Exception):
pass