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/tnslc.tnsl | 17 +++++++++++++++++ tnslc/vector.tnsl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 56623b7..f9b26c7 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -11,6 +11,23 @@ utils.Vector vec vec.init(1) + + vec.push_char('h') + vec.push_char('e') + vec.push_char('l') + vec.push_char('l') + vec.push_char('o') + vec.push_char(' ') + vec.push_char('w') + vec.push_char('o') + vec.push_char('r') + vec.push_char('l') + vec.push_char('d') + vec.push_char('\n') + vec.push_char(0) + + _printf(vec.data) + vec.end() return 0 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