From 97db10e0074a7d7cd560ccf750c3effd748239e6 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 26 Mar 2024 01:22:23 -0400 Subject: fix linux cwrap --- tnslc/c_wrap_linux.tnsl | 44 ++++++++++++++++++++++---------------------- tnslc/compile/compile.tnsl | 5 +++++ tnslc/compile/generator.tnsl | 0 tnslc/compile/lexer.tnsl | 0 tnslc/compile/tokenizer.tnsl | 0 tnslc/file.tnsl | 0 tnslc/tnslc.tnsl | 12 ++++++++++++ tnslc/vector.tnsl | 38 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 tnslc/compile/compile.tnsl create mode 100644 tnslc/compile/generator.tnsl create mode 100644 tnslc/compile/lexer.tnsl create mode 100644 tnslc/compile/tokenizer.tnsl create mode 100644 tnslc/file.tnsl create mode 100644 tnslc/vector.tnsl (limited to 'tnslc') diff --git a/tnslc/c_wrap_linux.tnsl b/tnslc/c_wrap_linux.tnsl index 31037db..4e7768a 100644 --- a/tnslc/c_wrap_linux.tnsl +++ b/tnslc/c_wrap_linux.tnsl @@ -16,7 +16,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Mov size into proper register, and set all extras to zero - asm "mov rdi, r8" + asm "mov rdi, r10" asm "mov rsi, 0" asm "xor rax, rax" @@ -24,8 +24,8 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "call malloc wrt ..plt" # Set out to the returned value - # (The compiler assignes spaces sequentially, and we have a uint in r8) - asm "mov r9, rax" + # (The compiler assignes spaces sequentially, and we have a uint in r10) + asm "mov r11, rax" return out ;/ @@ -41,16 +41,16 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Mov ptr and new size into proper registers, and set all extras to zero - asm "mov rdi, r8" - asm "mov rsi, r9" + asm "mov rdi, r10" + asm "mov rsi, r11" asm "xor rax, rax" # Do call asm "call realloc wrt ..plt" # Set out to the returned value - # (The compiler assignes spaces sequentially. We have a ptr in r8, and a uint in r9) - asm "mov r10, rax" + # (The compiler assignes spaces sequentially. We have a ptr in r10, and a uint in r11) + asm "mov r12, rax" return out ;/ @@ -65,7 +65,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # setup call by clearing most values - asm "mov rdi, r8" + asm "mov rdi, r10" asm "mov rsi, 0" asm "xor rax, rax" @@ -85,7 +85,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # setup call by clearing most values - asm "mov rdi, r8" + asm "mov rdi, r10" asm "xor rsi, rsi" asm "xor rax, rax" @@ -105,8 +105,8 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # setup call by clearing most values - asm "mov rdi, r8" - asm "mov rsi, r9" + asm "mov rdi, r10" + asm "mov rsi, r11" asm "xor rax, rax" # do call @@ -128,14 +128,14 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Do call - asm "mov rdi, r8" + asm "mov rdi, r10" asm "mov rsi, 0q1102" asm "mov rdx, 0q700" asm "call open wrt ..plt" # Set out to the returned value # (The compiler assignes spaces sequentially. We have a ptr in r8) - asm "mov r9, rax" + asm "mov r11, rax" return out ;/ @@ -152,14 +152,14 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Do syscall - asm "mov rdi, r8" + asm "mov rdi, r10" asm "mov rsi, 2" asm "mov rdx, 0q700" asm "call open wrt ..plt" # Set out to the returned value # (The compiler assignes spaces sequentially. We have a ptr in r8, and a uint in r9) - asm "mov r9, rax" + asm "mov r11, rax" return out ;/ @@ -174,7 +174,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Do syscall - asm "mov rdi, r8" + asm "mov rdi, r10" asm "call close wrt ..plt" ;/ @@ -189,13 +189,13 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Do syscall - asm "mov rdi, r8" # handle - asm "mov rsi, r9" # buffer + asm "mov rdi, r10" # handle + asm "mov rsi, r11" # buffer asm "mov rdx, 1" # one byte asm "call read wrt ..plt" # return number of bytes read - asm "mov r10, rax" + asm "mov r12, rax" return out ;/ @@ -211,12 +211,12 @@ asm "extern malloc, realloc, free, printf, open, close, read, write" asm "sub rsp, 128" # Do syscall - asm "mov rdi, r8" # handle - asm "mov rsi, r9" # buffer + asm "mov rdi, r10" # handle + asm "mov rsi, r11" # buffer asm "mov rdx, 1" # one byte asm "call write wrt ..plt" - asm "mov r10, rax" + asm "mov r12, rax" return out ;/ diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl new file mode 100644 index 0000000..157969e --- /dev/null +++ b/tnslc/compile/compile.tnsl @@ -0,0 +1,5 @@ +/; module compile + :import "tokenizer.tnsl" + :import "lexer.tnsl" + :import "generator.tnsl" +;/ diff --git a/tnslc/compile/generator.tnsl b/tnslc/compile/generator.tnsl new file mode 100644 index 0000000..e69de29 diff --git a/tnslc/compile/lexer.tnsl b/tnslc/compile/lexer.tnsl new file mode 100644 index 0000000..e69de29 diff --git a/tnslc/compile/tokenizer.tnsl b/tnslc/compile/tokenizer.tnsl new file mode 100644 index 0000000..e69de29 diff --git a/tnslc/file.tnsl b/tnslc/file.tnsl new file mode 100644 index 0000000..e69de29 diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 993771b..56623b7 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -1,6 +1,18 @@ :import "c_wrap_linux.tnsl" +/; module utils + :import "vector.tnsl" + :import "file.tnsl" +;/ + +:import "compile/compile.tnsl" + /; main [int] + utils.Vector vec + + vec.init(1) + vec.end() + return 0 ;/ diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl new file mode 100644 index 0000000..529e3a2 --- /dev/null +++ b/tnslc/vector.tnsl @@ -0,0 +1,38 @@ +struct Vector { + ~void data, + uint + count, + size, + _elsz +} + +uint VECTOR_MIN_ELEMENTS = 4 +~void NULL = 0 + +~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) + ;/ + + /; get (uint index) [~void] + /; if (index !< self.count) + return NULL + ;/ + + return self.data + index * self._elsz + ;/ + + /; end + self.count = 0 + self.size = 0 + self._elsz = 0 + _delete(self.data) + ;/ +;/ + -- cgit v1.2.3