diff options
-rw-r--r-- | tnslc/parse/ast.tnsl | 8 | ||||
-rw-r--r-- | tnslc/parse/parse.tnsl | 1 | ||||
-rw-r--r-- | tnslc/parse/tokenizer.tnsl | 1 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 4 | ||||
-rw-r--r-- | tnslc/utils/c_wrap_linux.tnsl | 38 | ||||
-rw-r--r-- | tnslc/utils/file.tnsl | 21 |
6 files changed, 53 insertions, 20 deletions
diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl index cdd0ae2..49c2f0f 100644 --- a/tnslc/parse/ast.tnsl +++ b/tnslc/parse/ast.tnsl @@ -9,7 +9,6 @@ uint16 NTYPE_POST_OP = 6 uint16 NTYPE_FUNCTION = 7 uint16 NTYPE_METHOD = 8 - struct Node { uint16 _type, ~uint8 data, @@ -107,11 +106,10 @@ struct Node { _ast_file(~_import, mod) _import.end() - ;; else - first = produce_next_token(fin, tmp) - tmp.end() - tmp = first ;/ + first = produce_next_token(fin, tmp) + tmp.end() + tmp = first ;/ fin`.close() diff --git a/tnslc/parse/parse.tnsl b/tnslc/parse/parse.tnsl index c225cf9..f6664d1 100644 --- a/tnslc/parse/parse.tnsl +++ b/tnslc/parse/parse.tnsl @@ -2,3 +2,4 @@ :import "tokenizer.tnsl" :import "ast.tnsl" ;/ + diff --git a/tnslc/parse/tokenizer.tnsl b/tnslc/parse/tokenizer.tnsl index c2ef091..d78fa40 100644 --- a/tnslc/parse/tokenizer.tnsl +++ b/tnslc/parse/tokenizer.tnsl @@ -373,6 +373,7 @@ uint MAX_MULTI = 3 com.end() ;/ ;/ + fin`.close() return out ;/ diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 2df15a3..7ce0c97 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -39,6 +39,10 @@ usage: parse.print_ast(~n) n.end() + # utils.Vector v = parse.gen_token_list(~fin) + # parse.print_token_list(~v) + # parse.end_token_list(~v) + fin.end() fout.end() diff --git a/tnslc/utils/c_wrap_linux.tnsl b/tnslc/utils/c_wrap_linux.tnsl index 62c3962..70b50f0 100644 --- a/tnslc/utils/c_wrap_linux.tnsl +++ b/tnslc/utils/c_wrap_linux.tnsl @@ -1,5 +1,5 @@ # Must be included at the top of the file -asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" +asm "extern malloc, realloc, free, printf, open, close, read, write, lseek, perror" {}uint8 _alert = "Alert!\n\0" {}uint8 _dec = "%d\n\0" @@ -119,8 +119,8 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" # Create file for writing (overwrite) -/; _create_file (~void name) [~void] - ~void out +/; _create_file (~void name) [int] + int out asm "mov rax, rsp" asm "xor rdx, rdx" @@ -143,8 +143,8 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" ;/ # Open file for reading or writing (no overwrite) -/; _open_file (~void name) [~void] - ~void out +/; _open_file (~void name) [int] + int out asm "mov rax, rsp" asm "xor rdx, rdx" @@ -166,7 +166,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" return out ;/ -/; _close_file (~void handle) +/; _close_file (int handle) asm "mov rax, rsp" asm "xor rdx, rdx" @@ -180,7 +180,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" asm "call close wrt ..plt" ;/ -/; _read_byte (~void handle, ~uint8 byte) [int] +/; _read_byte (int handle, ~uint8 byte) [int] int out asm "mov rax, rsp" @@ -202,7 +202,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" return out ;/ -/; _fseek (~void handle, uint pos) [int] +/; _fseek (int handle, uint pos) [int] int out # align stack @@ -226,7 +226,7 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" return out ;/ -/; _write_byte (~void handle, ~uint8 byte) [int] +/; _write_byte (int handle, ~uint8 byte) [int] int out asm "mov rax, rsp" @@ -247,6 +247,26 @@ asm "extern malloc, realloc, free, printf, open, close, read, write, lseek" return out ;/ +/; _perror (~void str) + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # setup call by clearing most values + asm "mov rdi, r10" + asm "xor rsi, rsi" + asm "xor rax, rax" + + # do call + asm "call perror wrt ..plt" + + # there's no more to do 'cause printf returns nothing +;/ + /; print_alert _printf(~_alert{0}) ;/ diff --git a/tnslc/utils/file.tnsl b/tnslc/utils/file.tnsl index 1d8a1e9..f6a0643 100644 --- a/tnslc/utils/file.tnsl +++ b/tnslc/utils/file.tnsl @@ -1,6 +1,6 @@ struct File { Artifact path, - ~void handle, + int32 handle, uint pos, bool at_end } @@ -13,7 +13,8 @@ struct File { /; init (~uint8 str) self.path.init() self.path.split_cstr(str, '/') - self.handle = NULL + self.handle = 0 + self.handle-- self.at_end = false self.pos = 0 ;/ @@ -43,16 +44,18 @@ struct File { ;/ /; end - self.path.end() /; if (self.handle + 1 !== 0) _close_file(self.handle) - self.handle = NULL + self.handle = 0 + self.handle-- ;/ + self.path.end() ;/ /; open ~uint8 p = self.path.to_cstr('/') self.handle = _open_file(p) + /; if (self.handle + 1 == 0) self.at_end = true ;/ @@ -71,7 +74,8 @@ struct File { /; close /; if (self.handle + 1 !== 0) _close_file(self.handle) - self.handle = NULL + self.handle = 0 + self.handle-- self.at_end = false ;/ ;/ @@ -84,10 +88,15 @@ struct File { uint8 out int bytes = _read_byte(self.handle, ~out) self.pos = self.pos + 1 - + /; if (bytes == 0) self.at_end = true return 0 + ;; else if (bytes !== 1) + _perror("Error reading from file\0") + _print_num("FD: %ld\n\0", self.handle) + self.at_end = true + return 0 ;/ return out |