From 5ff4734f6b8fe64ac64ae55e1afa9d8ff8860ee4 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 26 Mar 2024 01:37:12 -0400 Subject: Hello world --- tnslc/vector.tnsl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tnslc/vector.tnsl') 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 -- cgit v1.2.3