Skip to content

Commit cb3f7c1

Browse files
committed
Update array implementation
Arrays now have 2 new properties, namely: * data_label which, if the array is not dynamic, will return the label of the memory address where the array element data resides. * data_ptr_label, which is a pointer (for any array, dynamic or static) to the data element area. Accessing the first is slightly faster but only allowed in static global arrays, accessing the latter always works and is more versatile. Dynamic arrays are currently not implemented, but this scheme now allows them! The var symbol now returns the data_label when requiring its 't' (tree static value) symbol. The arrayaccess symbol now returns only the offset of the element.
1 parent c85b037 commit cb3f7c1

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

symbols/arrayaccess.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from api.errmsg import warning
1515
from api.check import is_number
1616
from api.check import is_const
17-
from api.constants import TYPE
1817

1918
from .call import SymbolCALL
2019
from .number import SymbolNUMBER as NUMBER
@@ -91,7 +90,7 @@ def offset(self):
9190
break
9291

9392
if offset is not None:
94-
offset = TYPE.size(gl.SIZE_TYPE) + TYPE.size(gl.BOUND_TYPE) * len(self.arglist) + offset * self.type_.size
93+
offset *= self.type_.size
9594

9695
return offset
9796

symbols/var.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def t(self):
110110
return str(self.default_value)
111111

112112
if self.scope == SCOPE.global_:
113-
return self.mangled
113+
if self.class_ == CLASS.array:
114+
return self.data_label
115+
else:
116+
return self.mangled
114117

115118
if self.type_ is None or not self.type_.is_dynamic:
116119
return self._t

symbols/vararray.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ def size(self):
4848
def memsize(self):
4949
""" Total array cell + indexes size
5050
"""
51-
return self.size + 1 + TYPE.size(gl.BOUND_TYPE) * len(self.bounds)
51+
return 2 * TYPE.size(gl.PTR_TYPE)
52+
53+
@property
54+
def data_label(self):
55+
return '{}.{}'.format(self.mangled, gl.ARRAY_DATA_PREFIX)
56+
57+
@property
58+
def data_ptr_label(self):
59+
return '{}.{}'.format(self.data_label, '__PTR__')

0 commit comments

Comments
 (0)