summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-30 02:46:04 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-30 02:46:04 -0400
commit59aabd4ed77ff3ede1df368ad134c56a6f8787c0 (patch)
tree0dc74f277fa35eb7ec9d72cc793da094b18b4686 /tnslc
parenta282af0b8fd4102778d6d8781c29f1c0202e13ee (diff)
in_csv function
Diffstat (limited to 'tnslc')
-rwxr-xr-xtnslc/build.sh2
-rw-r--r--tnslc/compile/generator.tnsl10
-rw-r--r--tnslc/compile/tokenizer.tnsl53
-rw-r--r--tnslc/tnslc.tnsl28
-rw-r--r--tnslc/utils/iterator.tnsl28
-rw-r--r--tnslc/utils/utils.tnsl1
6 files changed, 113 insertions, 9 deletions
diff --git a/tnslc/build.sh b/tnslc/build.sh
index d86c9ae..95cca0e 100755
--- a/tnslc/build.sh
+++ b/tnslc/build.sh
@@ -9,5 +9,5 @@ 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
+gcc -s -o $BUILD_DIR/$filename $ARTIFACT_DIR/$filename.o
diff --git a/tnslc/compile/generator.tnsl b/tnslc/compile/generator.tnsl
index 239b0c3..5d71a05 100644
--- a/tnslc/compile/generator.tnsl
+++ b/tnslc/compile/generator.tnsl
@@ -1,3 +1,13 @@
/; generate (utils.File fin, fout)
+ ~uint8 fa = fin.path.to_cstr('/')
+ ~uint8 fb = fout.path.to_cstr('/')
+
+ _printf(fa)
+ _printf(newline)
+ _printf(fb)
+ _printf(newline)
+
+ _delete(fa)
+ _delete(fb)
;/
diff --git a/tnslc/compile/tokenizer.tnsl b/tnslc/compile/tokenizer.tnsl
index e69de29..428815f 100644
--- a/tnslc/compile/tokenizer.tnsl
+++ b/tnslc/compile/tokenizer.tnsl
@@ -0,0 +1,53 @@
+struct Token {
+ ~uint8 data,
+ int
+ _type,
+ line,
+ col
+}
+
+/; method Token
+ /; eq (Token tok) [bool]
+ return utils.strcmp(self.data, tok.data)
+ ;/
+
+ /; eq_str(~uint8 str) [bool]
+ return utils.strcmp(self.data, str)
+ ;/
+;/
+
+/; _is_space(uint8 char) [bool]
+ /; if (char == '\t' || char == '\n' || char == '\r' || char == ' ')
+ return true
+ ;/
+ return false
+;/
+
+/; _in_csv (~uint8 csv, ~uint8 str) [bool]
+ int along = 0
+
+ /; loop (csv` !== 0) [csv++]
+ /; if (csv` == ',')
+ /; if (along !< 0 && str{along} == 0)
+ return true
+ ;/
+ along = 0
+ ;; else if (along !< 0 && str{along} == csv`)
+ along++
+ ;; else
+ along = 0
+ along--
+ ;/
+ ;/
+
+ return along !< 0 && str{along} == 0
+;/
+
+/; tokenize(utils.File fin) [utils.Vector]
+ Token tok
+
+ utils.Vector out
+ out.init(len tok)
+
+ return out
+;/
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 852d22e..0123430 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -17,7 +17,8 @@ usage:
~uint8 char_str = "%c\0"
~uint8 newline = "\n\0"
-~uint8 scratch = "1234\0"
+~uint8 scratch = "asd,efg\0"
+~uint8 test = "asd\0"
/; main (int argc, ~~uint8 argv) [int]
asm "mov r10, rdi"
@@ -28,13 +29,24 @@ usage:
return 1
;/
- int i = utils.cstr_to_int(scratch)
- _print_num(utils.NUM_STR, 0 - i)
- i = 0 - i
- ~uint8 s = utils.int_to_str(i)
- _printf(s)
- _printf(newline)
- _delete(s)
+ /; if (compile._in_csv(scratch, test))
+ _printf(test)
+ _printf(newline)
+ ;/
+
+ utils.File fin, fout
+ fin.init(argv{1})
+
+ /; if (argc > 2)
+ fout.init(argv{2})
+ ;; else
+ fout.init(DEFAULT_FOUT)
+ ;/
+
+ compile.generate(fin, fout)
+
+ fin.end()
+ fout.end()
return 0
;/
diff --git a/tnslc/utils/iterator.tnsl b/tnslc/utils/iterator.tnsl
new file mode 100644
index 0000000..b38d71f
--- /dev/null
+++ b/tnslc/utils/iterator.tnsl
@@ -0,0 +1,28 @@
+struct Iterator {
+ ~Vector v,
+ int pos
+}
+
+/; method Iterator
+ /; init(~Vector v)
+ self.v = v
+ self.pos = 0
+ ;/
+
+ /; get [~void]
+ return self.v`.get(self.pos)
+ ;/
+
+ /; next
+ /; if (self.pos + 1 < self.v`.count)
+ self.pos++
+ ;/
+ ;/
+
+ /; prev
+ /; if (self.pos > 0)
+ self.pos--
+ ;/
+ ;/
+;/
+
diff --git a/tnslc/utils/utils.tnsl b/tnslc/utils/utils.tnsl
index aa7968a..fece1da 100644
--- a/tnslc/utils/utils.tnsl
+++ b/tnslc/utils/utils.tnsl
@@ -3,4 +3,5 @@
:import "vector.tnsl"
:import "file.tnsl"
:import "algo.tnsl"
+ :import "iterator.tnsl"
;/