From 12679f9be4bd3a924ca0859a7ad133178513bace Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 25 Mar 2024 21:56:52 -0400 Subject: Better tmp handling --- tnslc/main.tnsl | 21 ++++++++++++++++++--- tnslc/vector.tnsl | 10 ++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'tnslc') diff --git a/tnslc/main.tnsl b/tnslc/main.tnsl index c7e8c95..cf2e8ac 100644 --- a/tnslc/main.tnsl +++ b/tnslc/main.tnsl @@ -1,15 +1,30 @@ :import "c_wrap_linux.tnsl" :import "vector.tnsl" -/; main [int] +/; push_char(Vector` a, uint8 c) + a.push(~c) +;/ +/; main [int] Vector a a.init(1) - + push_char(~a, 'h') + push_char(~a, 'e') + push_char(~a, 'l') + push_char(~a, 'l') + push_char(~a, 'o') + push_char(~a, ' ') + push_char(~a, 'w') + push_char(~a, 'o') + push_char(~a, 'r') + push_char(~a, 'l') + push_char(~a, 'd') + push_char(~a, '\n') + push_char(~a, 0) + _printf(a.data) a.end() - return 0 ;/ diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl index 9b89081..e5f58eb 100644 --- a/tnslc/vector.tnsl +++ b/tnslc/vector.tnsl @@ -11,6 +11,8 @@ struct Vector { int VECT_DEFAULT_SIZE = 4 int VECT_MAX_GROW = 128 +~uint8 PUSH_STR = "Push %d\n\0" + # Methods on the struct /; method Vector @@ -50,12 +52,16 @@ int VECT_MAX_GROW = 128 # Push an element onto the end of the vector /; push (~void data) - /; if (count == size - 1) + /; if (self.count == self.size - 1) self._grow(self.size) ;/ + + int offset = self._elsz * self.count /; loop (int i = 0; i < self._elsz) [i++] - (self.data + i)` = (data + i)` + ~uint8 to = self.data + offset + i + ~uint8 from = data + i + to` = from` ;/ self.count++ -- cgit v1.2.3