summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-17 02:37:39 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-17 02:37:39 -0400
commitd618ab0fb5e083dd9880f22b7bdc43be4a3c0327 (patch)
tree59548909be587a96b02f023e16dbf56b288c082e /tnslc
parent9385eaa149fae5d3c793f154611518342b7f3e9e (diff)
parentf80bb4fd79f27210b606966c421ff3104ad0c959 (diff)
Merge branch 'main' of git.cshift.net:CircleShift/ctc
Diffstat (limited to 'tnslc')
-rwxr-xr-xtnslc/build.sh9
-rw-r--r--tnslc/main.tnsl17
-rwxr-xr-xtnslc/tnslcbin0 -> 21440 bytes
-rw-r--r--tnslc/vector.tnsl87
4 files changed, 101 insertions, 12 deletions
diff --git a/tnslc/build.sh b/tnslc/build.sh
index b492dcd..a12ad5b 100755
--- a/tnslc/build.sh
+++ b/tnslc/build.sh
@@ -1,7 +1,8 @@
#!/bin/bash
-../ctc main.tnsl tnslc.asm
-nasm -f elf64 -o tnslc.o tnslc.asm
-gcc -o tnslc tnslc.o
-rm tnslc.asm tnslc.o
+mkdir -p out
+../ctc main.tnsl out/tnslc.asm
+nasm -f elf64 -o out/tnslc.o out/tnslc.asm
+gcc -o out/tnslc out/tnslc.o
+# rm tnslc.asm tnslc.o
diff --git a/tnslc/main.tnsl b/tnslc/main.tnsl
index 1abedb3..c7e8c95 100644
--- a/tnslc/main.tnsl
+++ b/tnslc/main.tnsl
@@ -1,14 +1,15 @@
:import "c_wrap_linux.tnsl"
+:import "vector.tnsl"
-~uint8 str_a = "Hello World\n\0"
-~uint8 str_b = "!\n\0"
+/; main [int]
-/; main (int argc, ~~uint8 argv) [int]
- _printf(str_a)
-
- /; if (argc > 2)
- _printf(str_b)
- ;/
+ Vector a
+ a.init(1)
+
+
+ a.end()
+
return 0
;/
+
diff --git a/tnslc/tnslc b/tnslc/tnslc
new file mode 100755
index 0000000..e8d4c46
--- /dev/null
+++ b/tnslc/tnslc
Binary files differ
diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl
new file mode 100644
index 0000000..9b89081
--- /dev/null
+++ b/tnslc/vector.tnsl
@@ -0,0 +1,87 @@
+# Define vector struct
+struct Vector {
+ ~void data,
+ int
+ size,
+ count,
+ _elsz
+}
+
+# Consts used in impl
+int VECT_DEFAULT_SIZE = 4
+int VECT_MAX_GROW = 128
+
+# Methods on the struct
+/; method Vector
+
+ # Initialize a new vector with elements
+ # 'elsz' bytes long
+ /; init (int elsz)
+ self.size = VECT_DEFAULT_SIZE
+ self._elsz = elsz
+ self.count = 0
+ self.data = _alloc(elsz * VECT_DEFAULT_SIZE)
+ ;/
+
+ # Grow the size of the vector by 'size' elements
+ /; _grow (int size)
+ /; if (size > VECT_MAX_GROW)
+ size = VECT_MAX_GROW
+ ;/
+
+ self.size = self.size + size
+ self.data = _realloc(self.data, self.size * self._elsz)
+ ;/
+
+ # Shrink the size of the vector by 'size' elements
+ /; _shrink (int size)
+ /; if (self.size - size < 0)
+ self.size = 1
+ ;; else
+ self.size = self.size - size
+ ;/
+
+ /; if (self.count < self.size)
+ self.count = self.size
+ ;/
+
+ self.data = _realloc(self.data, self.size * self._elsz)
+ ;/
+
+ # Push an element onto the end of the vector
+ /; push (~void data)
+ /; if (count == size - 1)
+ self._grow(self.size)
+ ;/
+
+ /; loop (int i = 0; i < self._elsz) [i++]
+ (self.data + i)` = (data + i)`
+ ;/
+
+ self.count++
+ ;/
+
+ # Pop an element off of the end of the vector
+ /; pop
+ self.count--
+
+ /; if (self.count < self.size / 2)
+ self._shrink(self.size / 3)
+ ;/
+ ;/
+
+ # Get a pointer to the start of an element in the vector
+ /; get (int index) [~void]
+ return self.data
+ ;/
+
+ # Free all memory associated with the vector
+ /; end
+ _delete(self.data)
+ self.size = 0
+ self._elsz = 0
+ self.count = 0
+ ;/
+
+;/
+