summaryrefslogtreecommitdiff
path: root/tnslc/test.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-08-29 14:55:11 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-08-29 14:55:11 -0400
commit2f5551c7c9c60f7e8e45b4826df9890cfa28d3d9 (patch)
treedb1699c6f81b2ecbbabfc2613d0b2f62d5e94271 /tnslc/test.tnsl
parent6dfceefbd4ad724dbad6e2e779395f4899ac6f0c (diff)
[tnslc] Framework for func helper
Diffstat (limited to 'tnslc/test.tnsl')
-rw-r--r--tnslc/test.tnsl208
1 files changed, 12 insertions, 196 deletions
diff --git a/tnslc/test.tnsl b/tnslc/test.tnsl
index d00d698..0d54258 100644
--- a/tnslc/test.tnsl
+++ b/tnslc/test.tnsl
@@ -1,201 +1,17 @@
-struct Vector {
- ~void data,
- uint
- count,
- size,
- _elsz
-}
-
-uint VECTOR_MIN_ELEMENTS = 4
-uint VECTOR_MAX_GROW = 256
-
-~uint8 NUM_STR = "Num %d\n\0"
-
-/; method Vector
-
- /; init (uint elsz)
- self._elsz = elsz
- self.size = VECTOR_MIN_ELEMENTS
- self.count = 0
- 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)
- ;/
-
- /; get (uint index) [~void]
- /; if (index !< self.count)
- return NULL
- ;/
-
- return self.data + index * self._elsz
- ;/
-
- /; push (~void el)
- /; if (self.size == self.count + 1)
- /; 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++]
- ~uint8 to = start + i
- ~uint8 from = el + i
- to` = from`
- ;/
- self.count++
- ;/
-
- /; _shrink(uint i)
- /; if (i !< self.size)
- self.size = 1
- ;; else
- self.size = self.size - i
- ;/
-
- self.data = _realloc(self.data, self.size * self._elsz)
- ;/
-
- /; pop
- self.count--
-
- /; if (self.count < self.size / 2)
- self._shrink(self.size / 3)
- ;/
- ;/
-
- /; push_char (uint8 ch)
- self.push(~ch)
- ;/
-
- /; push_cstr(~uint8 ch)
- /; loop (ch` !== 0) [ch++]
- self.push(ch)
- ;/
- ;/
-
- /; as_cstr [~uint8]
- ~uint8 z = self.data + self.count
- z` = 0
- return self.data
- ;/
-
- /; end
- self.count = 0
- self.size = 0
- self._elsz = 0
- _delete(self.data)
- ;/
-;/
-
-# Artifacts
-
-struct Artifact {
- ~~uint8 strings,
- uint
- size,
- count
+struct Fin {
+ ~void fd,
+ int state
}
-/; method Artifact
-
- /; init
- self.size = VECTOR_MIN_ELEMENTS
- self.count = 0
- 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())
- ;/
-
- /; _grow (uint i)
- self.size = self.size + i
- self.strings = _realloc(self.strings, self.size * len self.strings)
- ;/
-
- /; 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++
- ;/
-
- /; _shrink(uint i)
- /; if (i !< self.size)
- self.size = 1
- ;; else
- self.size = self.size - i
- ;/
-
- self.strings = _realloc(self.strings, self.size * len self.strings)
- ;/
-
- /; pop
- _delete(self.get(self.count - 1))
- self.count--
-
- /; if (self.count < self.size / 2)
- self._shrink(self.size / 3)
- ;/
- ;/
-
- /; 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)
- ;/
+/; main (int argc, {}{}uint8 argv) [int]
+ uint8 a = 1
+ ~uint8 b = ~a
+ Fin c
+ ~Fin d = ~c
+ b` = 2
+ c.state = a
+ d`.state = 0
+ return c.state
;/