From 3bfdbd26958e3b8193500dd5fad8dcd58c5a8457 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 31 Aug 2023 01:00:44 -0400 Subject: Updates to include new c_wrap --- tnslc/c_wrap.tnsl | 283 --------------------------------------------- tnslc/c_wrap_linux.tnsl | 226 ++++++++++++++++++++++++++++++++++++ tnslc/c_wrap_windows.tnsl | 284 ++++++++++++++++++++++++++++++++++++++++++++++ tnslc/copy.tnsl | 9 +- tnslc/hello.tnsl | 12 +- tnslc/logging.tnsl | 1 + tnslc/path.tnsl | 0 tnslc/run.sh | 15 +++ tnslc/simple.tnsl | 47 ++++---- tnslc/tnslc_wrapped.tnsl | 31 +---- tnslc/tokenizer.tnsl | 13 ++- tnslc/vector_test.tnsl | 12 +- 12 files changed, 573 insertions(+), 360 deletions(-) delete mode 100644 tnslc/c_wrap.tnsl create mode 100644 tnslc/c_wrap_linux.tnsl create mode 100644 tnslc/c_wrap_windows.tnsl delete mode 100644 tnslc/path.tnsl (limited to 'tnslc') diff --git a/tnslc/c_wrap.tnsl b/tnslc/c_wrap.tnsl deleted file mode 100644 index ac516da..0000000 --- a/tnslc/c_wrap.tnsl +++ /dev/null @@ -1,283 +0,0 @@ -# Must be included at the top of the file -asm "extern malloc" -asm "extern realloc" -asm "extern free" - -asm "extern printf" - -asm "extern CreateFileA" -asm "extern ReadFile" -asm "extern WriteFile" -asm "extern CloseHandle" - -{}uint8 _alert = "Alert!\n\0" -{}uint8 _dec = "%d\n\0" -{}uint8 _ptr = "%p\n\0" - -/; _alloc (uint size) [~void] - ~void out - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - asm "sub rsp, 32" - - # Mov size into proper register, and set all extras to zero - asm "mov rcx, r8" - asm "mov rdx, 0" - asm "mov r8, 0" - asm "mov r9, 0" - - asm "call malloc" - # Set out to the returned value - # (The compiler assignes spaces sequentially, and we have a uint in r8) - asm "mov r9, rax" - return out -;/ - -/; _realloc (~void ptr, uint new_size) [~void] - ~void out - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - asm "sub rsp, 32" - - # Mov ptr and new size into proper registers, and set all extras to zero - asm "mov rcx, r8" - asm "mov rdx, r9" - asm "mov r8, 0" - asm "mov r9, 0" - # Do call - asm "call realloc" - # 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" - return out -;/ - -/; _delete (~void ptr) - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - asm "sub rsp, 32" - - # setup call by clearing most values - asm "mov rcx, r8" - asm "mov rdx, 0" - asm "mov r8, 0" - asm "mov r9, 0" - # do call - asm "call free" - # there's no more to do 'cause free returns nothing -;/ - -/; _printf (~void str) - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - asm "push qword 0" - asm "push qword 0" - asm "push qword 0" - asm "push qword 0" - - # setup call by clearing most values - asm "mov rcx, r8" - asm "mov rdx, 0" - asm "mov r8, 0" - asm "mov r9, 0" - # do call - asm "call printf" - # there's no more to do 'cause printf returns nothing -;/ - -/; _print_num (~void str, int num) - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - asm "push qword 0" - asm "push qword 0" - asm "push qword 0" - asm "push qword 0" - - # setup call by clearing most values - asm "mov rcx, r8" - asm "mov rdx, r9" - asm "mov rdi, 0" - asm "mov rsi, 0" - asm "mov r8, 0" - asm "mov r9, 0" - # do call - asm "call printf" - # there's no more to do 'cause printf returns nothing -;/ - - -# Create file for writing (overwrite) -/; _create_file (~void name) [~void] - ~void out - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - - asm "mov rcx, r8" # lpFileName - asm "mov rdx, 1" # dwDesiredAccess - asm "shl rdx, 28" # (GENERIC_READ 1 << 31 | GENERIC_WRITE 1 << 30) - asm "mov r8, 3" # dwShareMode - asm "mov r9, 0" # lpSecurityAttributes - - asm "push qword 0" # hTemplateFile - asm "push qword 128" # dwFlagsAndAttributes (NORMAL_FILE = 128) - asm "push qword 2" # dwCreationDisposition (CREATE_ALWAYS = 2) - - # Shadow space - asm "push r9" - asm "push r8" - asm "push rdx" - asm "push rcx" - - # Do call - asm "call CreateFileA" - - # Set out to the returned value - # (The compiler assignes spaces sequentially. We have a ptr in r8) - asm "mov r9, rax" - - return out -;/ - -# Open file for reading or writing (no overwrite) -/; _open_file (~void name) [~void] - ~void out - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - - asm "mov rcx, r8" # lpFileName - asm "mov rdx, 1" # dwDesiredAccess - asm "shl rdx, 28" # (GENERIC_READ 1 << 31 | GENERIC_WRITE 1 << 30) - asm "mov r8, 3" # dwShareMode - asm "mov r9, 0" # lpSecurityAttributes - - asm "push qword 0" # hTemplateFile - asm "push qword 128" # dwFlagsAndAttributes (NORMAL_FILE = 128) - asm "push qword 3" # dwCreationDisposition (OPEN_EXISTING = 3) - - # Shadow space - asm "push r9" - asm "push r8" - asm "push rdx" - asm "push rcx" - - # Do call - asm "call CreateFileA" - - # 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" - - return out -;/ - -/; _close_file (~void handle) - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - - asm "mov rcx, r8" # handle - asm "mov rdx, 0" - asm "mov r8, 0" - asm "mov r9, 0" - - # Shadow space - asm "push r9" - asm "push r8" - asm "push rdx" - asm "push rcx" - - asm "call CloseHandle" - - asm "add rsp, 32" -;/ - -/; _read_byte (~void handle, ~uint8 byte, ~int read) [bool] - int out - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - - asm "mov rcx, r8" # handle - asm "mov rdx, r9" # buffer - asm "mov r8, 1" # one byte - asm "mov r9, r10" # read bytes buffer - asm "push qword 0" - - # Shadow space - asm "push r9" - asm "push r8" - asm "push rdx" - asm "push rcx" - - asm "call ReadFile" - - asm "mov r11, rax" - - return out -;/ - -/; _write_byte (~void handle, ~uint8 byte) [int] - int out - - asm "mov rax, rsp" - asm "xor rdx, rdx" - asm "mov rcx, 32" - asm "div rcx" - asm "sub rsp, rdx" - - asm "mov rcx, r8" # handle - asm "mov rdx, r9" # buffer - asm "mov r8, 1" # one byte - asm "mov r9, 0" - asm "push qword 0" - - # Shadow space - asm "push r9" - asm "push r8" - asm "push rdx" - asm "push rcx" - - asm "call WriteFile" - - asm "mov r10, rax" - - return out -;/ - -/; print_alert - _printf(~_alert{0}) -;/ diff --git a/tnslc/c_wrap_linux.tnsl b/tnslc/c_wrap_linux.tnsl new file mode 100644 index 0000000..31037db --- /dev/null +++ b/tnslc/c_wrap_linux.tnsl @@ -0,0 +1,226 @@ +# Must be included at the top of the file +asm "extern malloc, realloc, free, printf, open, close, read, write" + +{}uint8 _alert = "Alert!\n\0" +{}uint8 _dec = "%d\n\0" +{}uint8 _ptr = "%p\n\0" + +/; _alloc (uint size) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # Mov size into proper register, and set all extras to zero + asm "mov rdi, r8" + asm "mov rsi, 0" + asm "xor rax, rax" + + # Do call + 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" + + return out +;/ + +/; _realloc (~void ptr, uint new_size) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + 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 "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" + + return out +;/ + +/; _delete (~void ptr) + + 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, r8" + asm "mov rsi, 0" + asm "xor rax, rax" + + # do call + asm "call free wrt ..plt" + + # there's no more to do 'cause free returns nothing +;/ + +/; _printf (~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, r8" + asm "xor rsi, rsi" + asm "xor rax, rax" + + # do call + asm "call printf wrt ..plt" + + # there's no more to do 'cause printf returns nothing +;/ + +/; _print_num (~void str, int num) + + 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, r8" + asm "mov rsi, r9" + asm "xor rax, rax" + + # do call + asm "call printf wrt ..plt" + + # there's no more to do 'cause printf returns nothing +;/ + + +# Create file for writing (overwrite) +/; _create_file (~void name) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # Do call + asm "mov rdi, r8" + 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" + + return out +;/ + +# Open file for reading or writing (no overwrite) +/; _open_file (~void name) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # Do syscall + asm "mov rdi, r8" + 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" + + return out +;/ + +/; _close_file (~void handle) + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # Do syscall + asm "mov rdi, r8" + asm "call close wrt ..plt" +;/ + +/; _read_byte (~void handle, ~uint8 byte) [int] + int out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # Do syscall + asm "mov rdi, r8" # handle + asm "mov rsi, r9" # buffer + asm "mov rdx, 1" # one byte + asm "call read wrt ..plt" + + # return number of bytes read + asm "mov r10, rax" + + return out +;/ + +/; _write_byte (~void handle, ~uint8 byte) [int] + int out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 16" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 128" + + # Do syscall + asm "mov rdi, r8" # handle + asm "mov rsi, r9" # buffer + asm "mov rdx, 1" # one byte + asm "call write wrt ..plt" + + asm "mov r10, rax" + + return out +;/ + +/; print_alert + _printf(~_alert{0}) +;/ diff --git a/tnslc/c_wrap_windows.tnsl b/tnslc/c_wrap_windows.tnsl new file mode 100644 index 0000000..577ca25 --- /dev/null +++ b/tnslc/c_wrap_windows.tnsl @@ -0,0 +1,284 @@ +# Must be included at the top of the file +asm "extern malloc" +asm "extern realloc" +asm "extern free" + +asm "extern printf" + +asm "extern CreateFileA" +asm "extern ReadFile" +asm "extern WriteFile" +asm "extern CloseHandle" + +{}uint8 _alert = "Alert!\n\0" +{}uint8 _dec = "%d\n\0" +{}uint8 _ptr = "%p\n\0" + +/; _alloc (uint size) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 32" + + # Mov size into proper register, and set all extras to zero + asm "mov rcx, r8" + asm "mov rdx, 0" + asm "mov r8, 0" + asm "mov r9, 0" + + asm "call malloc" + # Set out to the returned value + # (The compiler assignes spaces sequentially, and we have a uint in r8) + asm "mov r9, rax" + return out +;/ + +/; _realloc (~void ptr, uint new_size) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 32" + + # Mov ptr and new size into proper registers, and set all extras to zero + asm "mov rcx, r8" + asm "mov rdx, r9" + asm "mov r8, 0" + asm "mov r9, 0" + # Do call + asm "call realloc" + # 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" + return out +;/ + +/; _delete (~void ptr) + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + asm "sub rsp, 32" + + # setup call by clearing most values + asm "mov rcx, r8" + asm "mov rdx, 0" + asm "mov r8, 0" + asm "mov r9, 0" + # do call + asm "call free" + # there's no more to do 'cause free returns nothing +;/ + +/; _printf (~void str) + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + asm "push qword 0" + asm "push qword 0" + asm "push qword 0" + asm "push qword 0" + + # setup call by clearing most values + asm "mov rcx, r8" + asm "mov rdx, 0" + asm "mov r8, 0" + asm "mov r9, 0" + # do call + asm "call printf" + # there's no more to do 'cause printf returns nothing +;/ + +/; _print_num (~void str, int num) + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + asm "push qword 0" + asm "push qword 0" + asm "push qword 0" + asm "push qword 0" + + # setup call by clearing most values + asm "mov rcx, r8" + asm "mov rdx, r9" + asm "mov rdi, 0" + asm "mov rsi, 0" + asm "mov r8, 0" + asm "mov r9, 0" + # do call + asm "call printf" + # there's no more to do 'cause printf returns nothing +;/ + + +# Create file for writing (overwrite) +/; _create_file (~void name) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + + asm "mov rcx, r8" # lpFileName + asm "mov rdx, 1" # dwDesiredAccess + asm "shl rdx, 28" # (GENERIC_READ 1 << 31 | GENERIC_WRITE 1 << 30) + asm "mov r8, 3" # dwShareMode + asm "mov r9, 0" # lpSecurityAttributes + + asm "push qword 0" # hTemplateFile + asm "push qword 128" # dwFlagsAndAttributes (NORMAL_FILE = 128) + asm "push qword 2" # dwCreationDisposition (CREATE_ALWAYS = 2) + + # Shadow space + asm "push r9" + asm "push r8" + asm "push rdx" + asm "push rcx" + + # Do call + asm "call CreateFileA" + + # Set out to the returned value + # (The compiler assignes spaces sequentially. We have a ptr in r8) + asm "mov r9, rax" + + return out +;/ + +# Open file for reading or writing (no overwrite) +/; _open_file (~void name) [~void] + ~void out + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + + asm "mov rcx, r8" # lpFileName + asm "mov rdx, 1" # dwDesiredAccess + asm "shl rdx, 28" # (GENERIC_READ 1 << 31 | GENERIC_WRITE 1 << 30) + asm "mov r8, 3" # dwShareMode + asm "mov r9, 0" # lpSecurityAttributes + + asm "push qword 0" # hTemplateFile + asm "push qword 128" # dwFlagsAndAttributes (NORMAL_FILE = 128) + asm "push qword 3" # dwCreationDisposition (OPEN_EXISTING = 3) + + # Shadow space + asm "push r9" + asm "push r8" + asm "push rdx" + asm "push rcx" + + # Do call + asm "call CreateFileA" + + # 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" + + return out +;/ + +/; _close_file (~void handle) + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + + asm "mov rcx, r8" # handle + asm "mov rdx, 0" + asm "mov r8, 0" + asm "mov r9, 0" + + # Shadow space + asm "push r9" + asm "push r8" + asm "push rdx" + asm "push rcx" + + asm "call CloseHandle" + + asm "add rsp, 32" +;/ + +/; _read_byte (~void handle, ~uint8 byte) [int] + ~int out + int i = 0 + out = ~i + + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + + asm "mov rcx, r8" # handle + asm "mov rdx, r9" # buffer + asm "mov r8, 1" # one byte + asm "mov r9, r10" # read bytes buffer + asm "push qword 0" + + # Shadow space + asm "push r9" + asm "push r8" + asm "push rdx" + asm "push rcx" + + asm "call ReadFile" + + return out` +;/ + +/; _write_byte (~void handle, ~uint8 byte) [int] + ~int out + int i = 0 + out = ~i + + asm "mov rax, rsp" + asm "xor rdx, rdx" + asm "mov rcx, 32" + asm "div rcx" + asm "sub rsp, rdx" + + asm "mov rcx, r8" # handle + asm "mov rdx, r9" # buffer + asm "mov r8, 1" # one byte + asm "mov r9, 0" + asm "push qword 0" + + # Shadow space + asm "push r9" + asm "push r8" + asm "push rdx" + asm "push rcx" + + asm "call WriteFile" + + return out` +;/ + +/; print_alert + _printf(~_alert{0}) +;/ diff --git a/tnslc/copy.tnsl b/tnslc/copy.tnsl index 636a773..0050d1a 100644 --- a/tnslc/copy.tnsl +++ b/tnslc/copy.tnsl @@ -1,4 +1,4 @@ -:include "c_wrap.tnsl" +:include "c_wrap_linux.tnsl" # :include "utils.tnsl" @@ -7,8 +7,8 @@ # Proof of concept copy program /; main (int argc, ~~uint8 argv) [int] - asm "mov r8, rcx" - asm "mov r9, rdx" + asm "mov r8, rdi" + asm "mov r9, rsi" /; if (argc < 3) _printf(~wrong_args{0}) @@ -23,9 +23,8 @@ uint8 buf = 0 int read_count = 0 - int tries = 0 /; loop - _read_byte(read_handle, ~buf, ~read_count) + read_count = _read_byte(read_handle, ~buf) /; if (read_count == 0) break ;/ diff --git a/tnslc/hello.tnsl b/tnslc/hello.tnsl index a2bdc68..6a6313a 100644 --- a/tnslc/hello.tnsl +++ b/tnslc/hello.tnsl @@ -1,4 +1,4 @@ -:include "c_wrap.tnsl" +:include "c_wrap_linux.tnsl" {}uint8 star = "*\0" {}uint8 space = " \0" @@ -19,15 +19,15 @@ /; main (int argc, ~~uint8 argv) [int] # On windows, the first two arguments are passed in RCX and RDX, so we need to # update their positions here or else tnsl will have garbage values in r8 and r9 - asm "mov r8, rcx" - asm "mov r9, rdx" + # asm "mov r8, rcx" + # asm "mov r9, rdx" # If on linux, you would use rdi and rsi instead of rcx and rdx, respectively # simply comment out the bove asm, and uncomment the below lines - # asm "mov r8, rdi" - # asm "mov r9, rsi" + asm "mov r8, rdi" + asm "mov r9, rsi" print_triangle(argc) return 0 -;/ \ No newline at end of file +;/ diff --git a/tnslc/logging.tnsl b/tnslc/logging.tnsl index 238f3be..2de326a 100644 --- a/tnslc/logging.tnsl +++ b/tnslc/logging.tnsl @@ -72,3 +72,4 @@ int log_mode = 1 _print_num(~_dec{0}, i) _printf(~_log_nl{0}) ;/ + diff --git a/tnslc/path.tnsl b/tnslc/path.tnsl deleted file mode 100644 index e69de29..0000000 diff --git a/tnslc/run.sh b/tnslc/run.sh index c1b19e5..9957e15 100755 --- a/tnslc/run.sh +++ b/tnslc/run.sh @@ -1,3 +1,18 @@ #!/bin/bash +BUILD_DIR="./build" +ARTIFACTS_DIR="$BUILD_DIR/artifacts" + +if [ ! -d $BUILD_DIR ]; then + mkdir $BUILD_DIR +fi + +if [ ! -d $ARTIFACTS_DIR ]; then + mkdir $ARTIFACTS_DIR +fi + ../tint -in tnslc.tnsl -flags "$1" +mv -f "$1.asm" "$ARTIFACTS_DIR/$1.asm" +nasm -f elf64 -o "$ARTIFACTS_DIR/$1.o" "$ARTIFACTS_DIR/$1.asm" +clang -o "./build/${1%.*}" "$ARTIFACTS_DIR/$1.o" + diff --git a/tnslc/simple.tnsl b/tnslc/simple.tnsl index 90ee758..75b91bd 100644 --- a/tnslc/simple.tnsl +++ b/tnslc/simple.tnsl @@ -1,36 +1,29 @@ # No longer simple -:include "c_wrap.tnsl" +:include "c_wrap_linux.tnsl" -enum LOL [int] { - A = 1, - B = 2, - C = 4 -} - -struct Lolbert { - int a, b, c, +{}uint8 str = "Hello copy!\n\0" - ~uint8 stuff +struct Copier { + ~uint8 h8r } -/; lolbert1 (~Lolbert l, uint8 check) [bool] - return l`.a == check -;/ +/; method Copier + /; copy [Copier] + Copier out + out.h8r = self.h8r + return out + ;/ -/; main [int] - Lolbert lol - lol.a = 1 - lol.b = 4 - lol.c = 3 - lol.stuff = _alloc(2) - lol.stuff{0} = 2 - lol.stuff{1} = 1 +;/ - /; if (lolbert1(~lol, lol.stuff{1}) && lolbert1(~lol, lol.stuff{0})) - _delete(lol.stuff) - return lol.a + lol.b - ;/ - _delete(lol.stuff) +/; main + Copier a + a.h8r = ~str{0} + ~Copier b + b = ~a + Copier c = b`.copy() + _printf(c.h8r) return 0 -;/ \ No newline at end of file +;/ + diff --git a/tnslc/tnslc_wrapped.tnsl b/tnslc/tnslc_wrapped.tnsl index e82581a..5bffcb8 100644 --- a/tnslc/tnslc_wrapped.tnsl +++ b/tnslc/tnslc_wrapped.tnsl @@ -1,34 +1,11 @@ -:include "c_wrap.tnsl" +:include "c_wrap_linux.tnsl" :include "logging.tnsl" -:include "vector.tnsl" :include "utils.tnsl" +:include "vector.tnsl" :include "tokenizer.tnsl" :include "compiler.tnsl" -{}uint8 m_usage = "Usage: tnslc [file to compile] [output asm]\n\0" - /; main (int argc, ~~uint8 argv) [int] - asm "mov r8, rcx" - asm "mov r9, rdx" - - /; if (argc < 3) - _printf(~m_usage{0}) - return 1 - ;/ - - Path in - Path out - - in.start(argv{0}) - out.start(argv{0}) - - in.relative_file(argv{1}) - out.relative_file(argv{2}) - - compile(in, out) - - in._del() - out._del() - - return 0 + + return 0 ;/ diff --git a/tnslc/tokenizer.tnsl b/tnslc/tokenizer.tnsl index 09509f8..7a15ade 100644 --- a/tnslc/tokenizer.tnsl +++ b/tnslc/tokenizer.tnsl @@ -193,7 +193,7 @@ struct Token { uint8 buf = 0 int read_count = 0 /; loop - _read_byte(file_in, ~buf, ~read_count) + read_count = _read_byte(file_in, ~buf) /; if (buf == '\n' || read_count == 0) break ;/ @@ -209,7 +209,7 @@ struct Token { read_count = 0 /; loop - _read_byte(file_in, ~buf, ~read_count) + read_count = _read_byte(file_in, ~buf) /; if (read_count == 0) break @@ -217,10 +217,11 @@ struct Token { /; if (buf == '\\') tmp.append(buf) - read_count = 0 - _read_byte(file_in, ~buf, ~read_count) + read_count = _read_byte(file_in, ~buf) column`++ - tmp.append(buf) + /; if (read_count !== 0) + tmp.append(buf) + ;/ ;; else if (buf == first) tmp.append(buf) break @@ -261,7 +262,7 @@ struct Token { # Read loop. /; loop [column++] - _read_byte(file_in, ~buf, ~read_count) + read_count = _read_byte(file_in, ~buf) /; if (read_count == 0) break ;/ diff --git a/tnslc/vector_test.tnsl b/tnslc/vector_test.tnsl index c74ddf9..5606d80 100644 --- a/tnslc/vector_test.tnsl +++ b/tnslc/vector_test.tnsl @@ -1,16 +1,16 @@ -:include "c_wrap.tnsl" +:include "c_wrap_linux.tnsl" :include "vector.tnsl" /; main (int argc, ~~uint argv) [int] # On windows, the first two arguments are passed in RCX and RDX, so we need to # update their positions here or else tnsl will have garbage values in r8 and r9 - asm "mov r8, rcx" - asm "mov r9, rdx" + # asm "mov r8, rcx" + # asm "mov r9, rdx" # If on linux, you would use rdi and rsi instead of rcx and rdx, respectively # simply comment out the bove asm, and uncomment the below lines - # asm "mov r8, rdi" - # asm "mov r9, rsi" + asm "mov r8, rdi" + asm "mov r9, rsi" Vector vec vec.start(1) @@ -33,4 +33,4 @@ vec._del() return 0 -;/ \ No newline at end of file +;/ -- cgit v1.2.3