diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2022-12-05 18:17:30 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2022-12-05 18:17:30 -0500 |
commit | 65d1112cffbe3a761c96b63c74ce0d704f64fb2d (patch) | |
tree | 2b363b41103a4f6554a368da35d82b947790f11b /tnslc | |
parent | cd34a562ce21381600799c390ba7e905e9dcf1e8 (diff) |
Include files
Diffstat (limited to 'tnslc')
-rw-r--r-- | tnslc/compile/compile.tnsl | 42 | ||||
-rw-r--r-- | tnslc/dummy.tnsl | 6 | ||||
-rw-r--r-- | tnslc/inc.tnsl | 1 | ||||
-rw-r--r-- | tnslc/paths.tnsl | 4 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 5 |
5 files changed, 45 insertions, 13 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl index 80c1456..1f9af2d 100644 --- a/tnslc/compile/compile.tnsl +++ b/tnslc/compile/compile.tnsl @@ -74,6 +74,7 @@ ;return -1 ;/ +# The commonly used registers in order /; reg_by_num(int r) [{}charp] /; if (r == 0) ;return "ax" @@ -143,6 +144,7 @@ ;return out ;/ +# Using the given offset (in bytes), return an asm value of form ".quad <offset>" /; construct_offset_value (int offset) [{}charp] ;{}charp out = ".quad " ;{}charp tmp = string_from_int(offset) @@ -293,6 +295,7 @@ ;/ ;/ +# Evaluate a value and return it to the register pointed at by reg /; eval_value (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}charp hsec, csec, dsec, int reg) /; if (token_is(cur, data, ";/")) ;return @@ -336,6 +339,10 @@ ;return "ax" ;/ +/; set_struct_value (~{}charp csec) + +;/ + /; set_value ({}charp from, to, int size, ~{}charp csec) /; if (is_common_reg(from)) ;from = get_reg(size, from) @@ -481,26 +488,43 @@ ;csec`.append('\n') ;/ -/; do_compile ({}charp file, ~{}Token data) - ;{}charp hsec = ".global main\n" - ;{}charp csec = ".text\n" - ;{}charp dsec = ".data\n" +/; compile_include (Path file_path, ~VTrack global, ~{}charp hsec, csec, dsec) + ;tnsl.io.File inc = file_path.open_r() + ;~{}Token data = parse.tokenize(inc) + ;inc.close() + ;compile_file(file_path, data, global, hsec, csec, dsec) +;/ - ;int j = len data` +/; compile_file (Path rel, ~{}Token data, ~VTrack global, ~{}charp hsec, csec, dsec) - ;VTrack global_scope = {{}, {}} + ;int j = len data` /; loop (int i = 0; i < j) [i++] /; if (string_equate(data`{i}.data`, "/;")) - ;compile_block(~i, data, ~global_scope, ~hsec, ~csec, ~dsec) + ;compile_block(~i, data, global, hsec, csec, dsec) ;; else if (string_equate(data`{i}.data`, ";")) - ;compile_global(~i, data, ~global_scope, ~hsec, ~csec, ~dsec) + ;compile_global(~i, data, global, hsec, csec, dsec) + ;; else if (string_equate(data`{i}.data`, ":")) + ;i = i + 2 + ;Path inc = rel.rel_file(unquote_string(data`{i}.data`)) + ;compile_include(inc, global, hsec, csec, dsec) ;; else ;break ;/ ;/ - ;tnsl.io.File out = tnsl.io.writeFile(file) +;/ + +/; do_compile ({}charp file_out, Path rel) + ;{}charp hsec = ".global main\n" + ;{}charp csec = ".text\n" + ;{}charp dsec = ".data\n" + + ;VTrack global_scope = {{}, {}} + + ;compile_include(rel, ~global_scope, ~hsec, ~csec, ~dsec) + + ;tnsl.io.File out = tnsl.io.writeFile(file_out) /; loop (int i = 0; i < len hsec) [i++] ;out.write(hsec{i}) diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl index c806022..1bfbee9 100644 --- a/tnslc/dummy.tnsl +++ b/tnslc/dummy.tnsl @@ -1,5 +1,9 @@ ;struct test { - int i, j, k, l + int8 i, j, k, l +} + +;struct test2 { + test a, b } /; _alloc (uint bytes) [~void] diff --git a/tnslc/inc.tnsl b/tnslc/inc.tnsl new file mode 100644 index 0000000..f9029f0 --- /dev/null +++ b/tnslc/inc.tnsl @@ -0,0 +1 @@ +:include "dummy.tnsl"
\ No newline at end of file diff --git a/tnslc/paths.tnsl b/tnslc/paths.tnsl index da0e782..c85da11 100644 --- a/tnslc/paths.tnsl +++ b/tnslc/paths.tnsl @@ -23,7 +23,9 @@ /; full_path [{}charp] ;{}charp out = join((self.dirs), '/') - ;out.append('/') + /; if (len (self.dirs) > 0) + ;out.append('/') + ;/ ;add_strings(~out, ~(self.file)) ;return out ;/ diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 1056dc5..129ef44 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -42,13 +42,14 @@ ;tnsl.io.print(len psrc`) ;tnsl.io.println(" tokens parsed.") - # ;tnslc.print_tokens(psrc) + ;tnslc.print_tokens(psrc) # ;tnslc.Node tree_node = tnslc.ast.make_tree(psrc, args{0}) + ;Path rel = path_from_str(file) ;file.append('.') ;file.append('S') - ;tnslc.do_compile(file, psrc) + ;tnslc.do_compile(file, rel) ;return 0 ;/ |