summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-28 16:43:08 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-28 16:43:08 -0400
commit12f274a8523d99481106aff3a652d3b583f38551 (patch)
treea1b30a5239ffa8e7b3850f69ee16832c3a6529f4 /tnslc
parentf4da286b9ea4abae997e03cd0ce1f2e1ef534b7c (diff)
Vector updates
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/tnslc.tnsl20
-rw-r--r--tnslc/vector.tnsl72
2 files changed, 82 insertions, 10 deletions
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 8fb65c3..efc8922 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -17,6 +17,8 @@ usage:
\0"
+~uint8 split_test = "test/whatever/file.tnsl\0"
+
/; main (int argc, ~~uint8 argv) [int]
asm "mov r10, rdi"
asm "mov r11, rsi"
@@ -26,16 +28,18 @@ usage:
return 1
;/
- utils.File in, out
+ utils.Artifact art
+
+ art.init()
+ # art.push(split_test)
+ # _printf(art.strings{0})
- in.init(argv{1})
- /; if (argc < 3)
- out.init(argv{2})
- ;; else
- out.init(DEFAULT_FOUT)
- ;/
+ art.split_cstr(split_test, '/')
+ ~uint8 file = art.to_cstr('/')
+ _printf(file)
+ _delete(file)
- compile.generate(in, out)
+ art.end()
return 0
;/
diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl
index ea61d78..af0a665 100644
--- a/tnslc/vector.tnsl
+++ b/tnslc/vector.tnsl
@@ -21,6 +21,11 @@ uint VECTOR_MAX_GROW = 256
self.data = _alloc(self.size * self._elsz)
;/
+ /; from_cstr(~uint8 cstr)
+ self.init(1)
+ self.push_cstr(cstr)
+ ;/
+
/; _grow (uint i)
self.size = self.size + i
self.data = _realloc(self.data, self.size * self._elsz)
@@ -60,7 +65,6 @@ uint VECTOR_MAX_GROW = 256
/; loop (ch` !== 0) [ch++]
self.push(ch)
;/
- self.push(ch)
;/
/; as_cstr [~uint8]
@@ -92,7 +96,71 @@ struct Artifact {
/; init
self.size = VECTOR_MIN_ELEMENTS
self.count = 0
- self.strings = _alloc(self.size * 8)
+ self.strings = _alloc(len self.strings * self.size)
+ ;/
+
+ /; split_cstr (~uint8 str, uint8 split)
+ Vector track
+ track.init(1)
+
+ /; loop (str` !== 0) [str++]
+ /; if (str` == split)
+ self.push(track.as_cstr())
+ track.init(1)
+ ;; else
+ track.push(str)
+ ;/
+ ;/
+
+ self.push(track.as_cstr())
+ _print_num(NUM_STR, self.count)
+ ;/
+
+ /; _grow (uint i)
+ self.size = self.size + i
+ self.strings = _realloc(self.strings, len self.strings * self.size)
+ ;/
+
+ /; push (~uint8 str)
+ /; if (self.size == self.count + 1)
+ /; if (self.size < VECTOR_MAX_GROW)
+ self._grow(self.size)
+ ;; else
+ self._grow(VECTOR_MAX_GROW)
+ ;/
+ ;/
+
+ self.strings{self.count} = str
+ self.count++
+ ;/
+
+ /; get (uint index) [~uint8]
+ /; if (index !< self.count)
+ return NULL
+ ;/
+
+ return self.strings{index}
+ ;/
+
+ /; to_cstr (uint8 join) [~uint8]
+ Vector out
+ out.init(1)
+
+ /; loop (int i = 0; i < self.count) [i++]
+ out.push_cstr(self.get(i))
+ /; if (i < self.count - 1)
+ out.push(~join)
+ ;/
+ ;/
+
+ return out.as_cstr()
+ ;/
+
+ /; end
+ /; loop (int i = 0; i < self.count) [i++]
+ _delete(self.get(i))
+ ;/
+ _delete(self.strings)
;/
;/