summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-25 21:56:52 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-25 21:56:52 -0400
commit12679f9be4bd3a924ca0859a7ad133178513bace (patch)
treed671fb3b5ce776474fc5eaf691805008e87b29a5 /tnslc
parent00f4940ff1c19f3659779b2db078b85f178cb5ab (diff)
Better tmp handling
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/main.tnsl21
-rw-r--r--tnslc/vector.tnsl10
2 files changed, 26 insertions, 5 deletions
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++