diff options
-rw-r--r-- | libtnsl/asm/asm.tnsl | 3 | ||||
-rw-r--r-- | libtnsl/asm/x86.tnsl | 6 | ||||
-rw-r--r-- | tnslc/ast/list.tnsl | 52 | ||||
-rw-r--r-- | tnslc/ast/tree.tnsl | 3 | ||||
-rw-r--r-- | tnslc/compile/arch/common.tnsl | 7 | ||||
-rw-r--r-- | tnslc/compile/comp.tnsl | 3 | ||||
-rw-r--r-- | tnslc/compile/compile.tnsl | 9 | ||||
-rw-r--r-- | tnslc/compile/format/format.tnsl | 2 | ||||
-rw-r--r-- | tnslc/compile/format/iex.tnsl | 0 | ||||
-rw-r--r-- | tnslc/compile/format/out.tnsl | 0 | ||||
-rw-r--r-- | tnslc/copy.tnsl | 30 | ||||
-rw-r--r-- | tnslc/dummy.tnsl | 6 | ||||
-rw-r--r-- | tnslc/flags/defaults.tnsl | 24 | ||||
-rw-r--r-- | tnslc/flags/flags.tnsl | 32 | ||||
-rw-r--r-- | tnslc/parse/token.tnsl | 26 | ||||
-rw-r--r-- | tnslc/parse/tokenizer.tnsl | 8 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 6 |
17 files changed, 192 insertions, 25 deletions
diff --git a/libtnsl/asm/asm.tnsl b/libtnsl/asm/asm.tnsl index d0da9a6..de525f5 100644 --- a/libtnsl/asm/asm.tnsl +++ b/libtnsl/asm/asm.tnsl @@ -26,4 +26,7 @@ the selected ISA/OS combo. #; module asm + + :include "asm/x86.tnsl" + ;/
\ No newline at end of file diff --git a/libtnsl/asm/x86.tnsl b/libtnsl/asm/x86.tnsl new file mode 100644 index 0000000..b010a76 --- /dev/null +++ b/libtnsl/asm/x86.tnsl @@ -0,0 +1,6 @@ +/; raw inline syscall (int i) + ; asm " + mov eax, {i} + int 80h + " +;/ diff --git a/tnslc/ast/list.tnsl b/tnslc/ast/list.tnsl index a5849a3..b9d8080 100644 --- a/tnslc/ast/list.tnsl +++ b/tnslc/ast/list.tnsl @@ -16,8 +16,60 @@ /; tree_list_value [{}Node] ;{}Node out = {} + ;return out +;/ + +/; tree_list_type [{}Node] + ;{}Node out = {} + ;return out +;/ + +/; tree_list_statement (~{}Token tok, ~int cur) [{}Node] + ;{}Node out = {} + + /; loop (cur` < len tok`) [cur` = cur` + 1] + ;Node stmt = tree_statement(tok, cur) + ;append(out, stmt) + ;Token tmp = tok`{cur`} + /; if (string_equate(tmp.data, "]") || string_equate(tmp.data, ")")) + ;cur` = cur` + 1 + ;break + ;; else if (string_equate(tmp.data, ";") == false) + ;create_panic("Unexpected token in list of statements") + ;/ + ;/ + ;return out +;/ + +/; tree_list_params (~{}Token tok, ~int cur) [{}Node] + ;{}Node out = {} + + /; if (string_equate(tok`{cur`}.data, ")")) + ;return out + ;/ + + /; if (type_then_name(tok, cur) == false) + ;create_panic("Parameter list must start with a type and name combo.") + ;/ + + /; loop (cur` < len tok`) [cur` = cur` + 1] + ;Node tmp + /; if (type_then_name(tok, cur)) + ;tmp = tree_type(tok, cur) + ;append(out, tmp) + ;/ + + ;tmp = tree_value(tok, cur) + + /; if (string_equate(tok`{cur`}.data, ")")) + ;cur` = cur` + 1 + ;break + ;; else if (string_equate(tok`{cur`}.data, ",") == false) + ;create_panic("A value in a list of params must be followed with a comma") + ;/ + ;/ ;return out ;/ diff --git a/tnslc/ast/tree.tnsl b/tnslc/ast/tree.tnsl index fe6baab..db901de 100644 --- a/tnslc/ast/tree.tnsl +++ b/tnslc/ast/tree.tnsl @@ -15,8 +15,7 @@ #/ /; make_null_node [Node] - ;{}charp null_str = "" - ;Token null_tok = {0, 0, 0, ~null_str} + ;Token null_tok = {0, 0, 0, ~CNULL} ;{}Node sub = {} ;return {null_tok, ~sub} ;/ diff --git a/tnslc/compile/arch/common.tnsl b/tnslc/compile/arch/common.tnsl index cba0d9f..1ff1c89 100644 --- a/tnslc/compile/arch/common.tnsl +++ b/tnslc/compile/arch/common.tnsl @@ -14,4 +14,9 @@ EXPRESS OR IMPLIED #/ -; struct instruction {}
\ No newline at end of file +# Instructions are always stored in big-endian format internally. +# The settings for the isa/compiler dictate weather the instruction +# data will be reversed when the sections are being written. +; struct instruction { + {}uint8 data +}
\ No newline at end of file diff --git a/tnslc/compile/comp.tnsl b/tnslc/compile/comp.tnsl new file mode 100644 index 0000000..18ca4b5 --- /dev/null +++ b/tnslc/compile/comp.tnsl @@ -0,0 +1,3 @@ +/; do_compile ({}charp file, ast.Node data, Settings settings) + +;/
\ No newline at end of file diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl index 263dc59..2787eba 100644 --- a/tnslc/compile/compile.tnsl +++ b/tnslc/compile/compile.tnsl @@ -15,7 +15,12 @@ #/ /; module compile - :include "compile/arch/arch.tnsl" + # :include "compile/arch/arch.tnsl" :include "compile/format/format.tnsl" - + # :include "compile/comp.tnsl" +;/ + + +/; do_compile ({}charp file, ast.Node data, Settings settings) + ;/ diff --git a/tnslc/compile/format/format.tnsl b/tnslc/compile/format/format.tnsl index 2d4ed4b..14831b5 100644 --- a/tnslc/compile/format/format.tnsl +++ b/tnslc/compile/format/format.tnsl @@ -15,6 +15,6 @@ #/ /; module format - :include "compile/format/out.tnsl" + # :include "compile/format/out.tnsl" :include "compile/format/elf.tnsl" ;/
\ No newline at end of file diff --git a/tnslc/compile/format/iex.tnsl b/tnslc/compile/format/iex.tnsl deleted file mode 100644 index e69de29..0000000 --- a/tnslc/compile/format/iex.tnsl +++ /dev/null diff --git a/tnslc/compile/format/out.tnsl b/tnslc/compile/format/out.tnsl deleted file mode 100644 index e69de29..0000000 --- a/tnslc/compile/format/out.tnsl +++ /dev/null diff --git a/tnslc/copy.tnsl b/tnslc/copy.tnsl new file mode 100644 index 0000000..953a7c8 --- /dev/null +++ b/tnslc/copy.tnsl @@ -0,0 +1,30 @@ +/# + Proof of concept that the language can copy any file. + + For testing with executibles to make sure that the language's current state + would be able to produce one from data alone. + + Seems to work. +#/ + +/; main ({}{}charp args) [int] + /; if (len args < 2) + ;tnsl.io.println("Usage: copy [file to copy] [path to copy to]") + ;return 1 + ;/ + + ;tnsl.io.File in = tnsl.io.readFile(args{0}) + ;tnsl.io.File out = tnsl.io.writeFile(args{1}) + + /; loop (int chk = in.read(); chk !< 0) [chk = in.read()] + ;uint8 write = chk + ;out.write(write) + ;/ + + ;tnsl.io.println("Copy complete.") + + ;in.close() + ;out.close() + + ;return 0 +;/ diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl index ebc9c3f..2aa55a7 100644 --- a/tnslc/dummy.tnsl +++ b/tnslc/dummy.tnsl @@ -1 +1,5 @@ -;int a = 0
\ No newline at end of file +;int a = 0x11 + +/; main + ;tnsl.io.println(a) +;/ diff --git a/tnslc/flags/defaults.tnsl b/tnslc/flags/defaults.tnsl new file mode 100644 index 0000000..2164e20 --- /dev/null +++ b/tnslc/flags/defaults.tnsl @@ -0,0 +1,24 @@ +/## + Copyright 2021 Kyle Gunger + + This file is licensed under the CDDL 1.0 (the License) + and may only be used in accordance with the License. + You should have received a copy of the License with this + software/source code. If you did not, a copy can be found + at the following URL: + + https://opensource.org/licenses/CDDL-1.0 + + THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO + WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE + EXPRESS OR IMPLIED +#/ + +/# defaults.tnsl + # This file provides the default settings for the compiler + # if the user has not provided flags which overrides them. +#/ + +/; get_defaults [Settings] + +;/
\ No newline at end of file diff --git a/tnslc/flags/flags.tnsl b/tnslc/flags/flags.tnsl index bc5d43f..1dbbaf4 100644 --- a/tnslc/flags/flags.tnsl +++ b/tnslc/flags/flags.tnsl @@ -14,3 +14,35 @@ EXPRESS OR IMPLIED #/ +/; module flags + :include "flags/defaults.tnsl" +;/ + +;enum ISA [uint] { + X86 = 0, + X64 = 1, + ARM = 2, + ARM64 = 3, + RISCV = 4 +} + +;enum FORMATS [uint] { + ELF = 0 + PE = 1 +} + +;struct Settings { + + # ISA settings + uint isa, + bool littleEndian, + + # Output format settings + uint format +} + +/; parse_flags () [Settings] + ;Settings out = flags.get_defaults() + + ;return out +;/ diff --git a/tnslc/parse/token.tnsl b/tnslc/parse/token.tnsl index 92748d8..e7d64e7 100644 --- a/tnslc/parse/token.tnsl +++ b/tnslc/parse/token.tnsl @@ -32,16 +32,13 @@ "abi" } -;const {}{}charp KEYTYPES = { - "bool", - "char", - "charp", - +;{}{}charp KEYTYPES = { "int8", "int16", "int32", "int64", "int", + "uint8", "uint16", "uint32", @@ -52,6 +49,7 @@ "float64", "float", + "bool", "void", "type" } @@ -60,7 +58,6 @@ "struct", "interface", "enum", - "is", "extends", "loop", @@ -83,8 +80,6 @@ "method", "override", - "self", - "super", "operator", "raw", @@ -93,6 +88,9 @@ "virtual", "delete", + "alloc", + "salloc", + "realloc", "module", "export" @@ -101,7 +99,11 @@ ;{}{}charp LITERALS = { "true", "false", - "null" + + "null", + + "self", + "super" } ;{}charp RESERVED = "`~!#%^&*()-=+[]{}|;:,.<>/" @@ -169,7 +171,11 @@ # Increment and De-increment "++", - "--" + "--", + + "is", + "len", + "size" } ;int MAX_MRESERVED = 3 diff --git a/tnslc/parse/tokenizer.tnsl b/tnslc/parse/tokenizer.tnsl index 3a66e24..7a1f085 100644 --- a/tnslc/parse/tokenizer.tnsl +++ b/tnslc/parse/tokenizer.tnsl @@ -14,11 +14,11 @@ EXPRESS OR IMPLIED #/ -/; is_float (~{}charp dat) [bool] +/; is_float (~{}uint8 dat) [bool] ;return is_numeric_literal(dat) && is_in_string(dat, '.') ;/ -/; break_token ({}charp dat, charp c) [bool] +/; break_token ({}uint8 dat, uint8 c) [bool] /; if (len dat == 0) ;return false @@ -74,7 +74,7 @@ /; tokenize (tnsl.io.File fstr) [~{}Token] ;{}Token out = {} - ;{}charp tdat = {} + ;{}uint8 tdat = {} ;bool comment = false ;int line = 1, col = 1 @@ -84,7 +84,7 @@ ;tdat = {} ;comment = true ;; else if (len tdat > 0) - ;{}charp tmp = tdat + ;{}uint8 tmp = tdat ;Token ttk = {get_token_type(~tmp), line, col, ~tmp} ;out.append(ttk) ;tdat = {} diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 21dbb45..1120745 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -19,14 +19,12 @@ /; export module tnslc :include "parse/parse.tnsl" :include "ast/ast.tnsl" + :include "compile/compile.tnsl" ;/ -/; test - -;/ - /; main ({}{}charp args) [int] + /; if (len args < 1) ;tnsl.io.println("Usage: tnslc [File to compile] <path to libtnsl>") ;return 1 |