summaryrefslogtreecommitdiff
path: root/tnslc/vector.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-26 01:37:12 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-26 01:37:12 -0400
commit5ff4734f6b8fe64ac64ae55e1afa9d8ff8860ee4 (patch)
tree3f6efce2d88a87aaa15ee2caee29238b81211b73 /tnslc/vector.tnsl
parent8a89427dc5da5b0c728da49d34848ea4741dc35f (diff)
Hello world
Diffstat (limited to 'tnslc/vector.tnsl')
-rw-r--r--tnslc/vector.tnsl34
1 files changed, 34 insertions, 0 deletions
diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl
index 529e3a2..2175877 100644
--- a/tnslc/vector.tnsl
+++ b/tnslc/vector.tnsl
@@ -7,6 +7,7 @@ struct Vector {
}
uint VECTOR_MIN_ELEMENTS = 4
+uint VECTOR_MAX_GROW = 256
~void NULL = 0
~uint8 NUM_STR = "Num %d\n\0"
@@ -20,6 +21,11 @@ uint VECTOR_MIN_ELEMENTS = 4
self.data = _alloc(self.size * self._elsz)
;/
+ /; _grow (uint i)
+ self.size = self.size + i
+ self.data = _realloc(self.data, self.size * self._elsz)
+ ;/
+
/; get (uint index) [~void]
/; if (index !< self.count)
return NULL
@@ -28,6 +34,34 @@ uint VECTOR_MIN_ELEMENTS = 4
return self.data + index * self._elsz
;/
+ /; push (~void el)
+ /; if (self.size == self.count)
+ /; if (self.size < VECTOR_MAX_GROW)
+ self._grow(self.size)
+ ;; else
+ self._grow(VECTOR_MAX_GROW)
+ ;/
+ ;/
+
+ ~void start = self.data + self.count * self._elsz
+ /; loop (int i = 0; i < self._elsz) [i++]
+ ~void to = start + i
+ ~void from = el + i
+ to` = from`
+ ;/
+ self.count++
+ ;/
+
+ /; push_char (uint8 ch)
+ self.push(~ch)
+ ;/
+
+ /; push_cstr(~uint8 ch)
+ /; loop (ch` != 0) [ch++]
+ self.push(ch)
+ ;/
+ ;/
+
/; end
self.count = 0
self.size = 0