From 948cfe891a1234f52057db56f7cb1ea088de5ade Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 26 Mar 2024 14:39:54 -0400 Subject: vector bugfix --- .gitignore | 1 + tnslc/build.sh | 13 +++++++++++++ tnslc/file.tnsl | 2 +- tnslc/run.sh | 13 ------------- tnslc/tnslc.tnsl | 3 +-- tnslc/vector.tnsl | 31 ++++++++++++++++++++++++++++--- 6 files changed, 44 insertions(+), 19 deletions(-) create mode 100755 tnslc/build.sh delete mode 100755 tnslc/run.sh diff --git a/.gitignore b/.gitignore index a5ec8be..16231e5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ *.exe **/build/ +**/out/ ctc diff --git a/tnslc/build.sh b/tnslc/build.sh new file mode 100755 index 0000000..d86c9ae --- /dev/null +++ b/tnslc/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +BUILD_DIR=./out +ARTIFACT_DIR=$BUILD_DIR/artifacts + +mkdir -p $BUILD_DIR +mkdir -p $ARTIFACT_DIR +filename=tnslc.tnsl +filename="${filename%.*}" +./ctc $filename.tnsl $ARTIFACT_DIR/$filename.asm +nasm -f elf64 -o $ARTIFACT_DIR/$filename.o $ARTIFACT_DIR/$filename.asm +gcc -o $BUILD_DIR/$filename $ARTIFACT_DIR/$filename.o + diff --git a/tnslc/file.tnsl b/tnslc/file.tnsl index 0b24aea..e17ec70 100644 --- a/tnslc/file.tnsl +++ b/tnslc/file.tnsl @@ -1,5 +1,5 @@ struct File { - int i + } /; method File diff --git a/tnslc/run.sh b/tnslc/run.sh deleted file mode 100755 index 904e281..0000000 --- a/tnslc/run.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -BUILD_DIR=./build -ARTIFACT_DIR=$BUILD_DIR/artifacts - -mkdir -p $BUILD_DIR -mkdir -p $ARTIFACT_DIR -filename=tnslc.tnsl -filename="${filename%.*}" -./ctc $filename.tnsl $ARTIFACT_DIR/$filename.asm -nasm -f elf64 -o $ARTIFACT_DIR/$filename.o $ARTIFACT_DIR/$filename.asm -gcc -o $BUILD_DIR/$filename $ARTIFACT_DIR/$filename.o - diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 6269ef2..8fb65c3 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -13,9 +13,8 @@ TNSLC v1.0.0 (C) 2024 CircleShift usage: - tnslc [options] (file in) [file out] + tnslc (file in) [file out] - -h print this help text \0" /; main (int argc, ~~uint8 argv) [int] diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl index c8450ac..ea61d78 100644 --- a/tnslc/vector.tnsl +++ b/tnslc/vector.tnsl @@ -35,7 +35,7 @@ uint VECTOR_MAX_GROW = 256 ;/ /; push (~void el) - /; if (self.size == self.count) + /; if (self.size == self.count + 1) /; if (self.size < VECTOR_MAX_GROW) self._grow(self.size) ;; else @@ -45,8 +45,8 @@ uint VECTOR_MAX_GROW = 256 ~void start = self.data + self.count * self._elsz /; loop (int i = 0; i < self._elsz) [i++] - ~void to = start + i - ~void from = el + i + ~uint8 to = start + i + ~uint8 from = el + i to` = from` ;/ self.count++ @@ -63,6 +63,12 @@ uint VECTOR_MAX_GROW = 256 self.push(ch) ;/ + /; as_cstr [~uint8] + ~uint8 z = self.data + self.count + z` = 0 + return self.data + ;/ + /; end self.count = 0 self.size = 0 @@ -71,3 +77,22 @@ uint VECTOR_MAX_GROW = 256 ;/ ;/ + +# Artifacts + +struct Artifact { + ~~uint8 strings, + uint + size, + count +} + +/; method Artifact + + /; init + self.size = VECTOR_MIN_ELEMENTS + self.count = 0 + self.strings = _alloc(self.size * 8) + ;/ +;/ + -- cgit v1.2.3