diff options
-rw-r--r-- | tnslc/c_wrap.tnsl | 10 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 92 |
2 files changed, 47 insertions, 55 deletions
diff --git a/tnslc/c_wrap.tnsl b/tnslc/c_wrap.tnsl index d1004bb..93ea3e4 100644 --- a/tnslc/c_wrap.tnsl +++ b/tnslc/c_wrap.tnsl @@ -1,3 +1,7 @@ +asm "extern malloc" +asm "extern realloc" +asm "extern free" + /; _alloc (uint size) [~void] ~void out # Mov size into proper register, and set all extras to zero @@ -8,7 +12,7 @@ asm "mov r8, 0" asm "mov r9, 0" asm "mov r10, 0" - asm "call malloc wrt ..got" + 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" @@ -26,7 +30,7 @@ asm "mov r9, 0" asm "mov r10, 0" # Do call - asm "call realloc wrt ..got" + 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" @@ -43,7 +47,7 @@ asm "mov r9, 0" asm "mov r10, 0" # do call - asm "call free wrt ..got" + asm "call free" # there's no more to do 'cause free returns nothing ;/ diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 582afbd..06fc6dc 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -380,7 +380,6 @@ /; method Type /; sprint [{}uint8] - ;log_debug("Sprinting Type") ;{}uint8 out = string_join( {"{ ", int_to_string(self.s), ", ", self.name, ", ", self.mod_name, ", { "}, "") ;{}{}uint8 pch = {} /; loop (int i = 0; i < len(self.ptr_chain)) [i++] @@ -633,14 +632,11 @@ /; loop (pc > 1) [pc = len (out.data_type.ptr_chain)] /; if (out.data_type.ptr_chain{pc - 1} == PTYPE.REFERENCE) - ;log_debug("Stripping") ;out.strip_one(data) ;; else - ;log_debug("Breaking") ;break ;/ ;/ - ;log_debug("Strip complete") ;return out ;/ @@ -943,7 +939,6 @@ ;/ ;struct Scope { - {}int level, int num, c, ~Scope parent, {}uint8 name, @@ -952,27 +947,17 @@ /; method Scope /; is_cf [bool] - ;{}{}uint8 split = string_split(self.name, '_') - /; if (len split == 0) + /;if (len(self.name) < 1) ;return false ;/ - /; if (split{0}{0} == '#') - /; loop (int i = 1; i < len split; i++) - /; if (len split{i} > 0) - /; if (split{i}{0} < '0' || split{i}{0} > '9') - ;return false - ;/ - ;; else - ;return false - ;/ - ;/ - ;return true - ;/ - ;return false + ;return self.name{0} == '#' ;/ /; cf_type ({}uint8 cf) [bool] ;{}{}uint8 split = string_split(self.name, '_') + /; if (len split !> 1) + ;return false + ;/ ;return string_equate(split{0}, string_add("#", cf)) ;/ @@ -980,7 +965,6 @@ ;{}uint8 out = "" /; if (self.is_cf()) ;out = self.parent`.full_label() - ;out.append('_') ;/ ;out = string_add(out, self.name) ;return out @@ -989,14 +973,13 @@ /; get_size [int] ;int out = 0 /; loop (int i = 0; i < len (self.vars)) [i++] - ;out = out + self.vars{i}.s + ;out = out + self.vars{i}.norm_size() ;/ ;return out ;/ /; next_register [int] ;int out = 8 - /; if (self.is_cf()) ;out = self.parent`.next_register() ;/ @@ -1019,7 +1002,7 @@ /; loop (int i = 0; i < len (self.vars)) [i++] /; if (self.vars{i}.loc_type == LOCATION.STACK) - ;out = out + self.vars{i}.s + ;out = out + self.vars{i}.norm_size() ;/ ;/ @@ -1029,12 +1012,12 @@ /; get_full_stack [int] ;int out = 0 /; if (self.is_cf()) - ;out = self.parent`.get_stack() + ;out = self.parent`.get_full_stack() ;/ /; loop (int i = 0; i < len (self.vars)) [i++] /; if (self.vars{i}.loc_type == LOCATION.STACK) - ;out = out + self.vars{i}.s + ;out = out + self.vars{i}.norm_size() ;/ ;/ @@ -1043,6 +1026,7 @@ /; next_loc (Type t) [int] /; if (is_primitive(t.name) !< 0 || len (t.ptr_chain) > 0) + ;log_debug("Next reg") ;return self.next_register() ;/ ;return -1 @@ -1090,16 +1074,11 @@ /; new_sub_cf ({}uint8 cf) [Scope] ;cf = string_add("#", cf) - ;{}int s = self.level - ;s.append(self.num) + ;cf.append('_') + ;cf = string_add(cf, int_to_string(self.num)) ;self.num++ - /; loop (int i = 0; i < len (s)) [i++] - ;cf.append('_') - ;cf = string_add(cf, int_to_string(s{i})) - ;/ - - ;return {s, 0, 0, ~self, cf, {}} + ;return {0, 0, ~self, cf, {}} ;/ /; get_continue (uint i) [{}uint8] @@ -1124,6 +1103,7 @@ /; new_var (Type t, {}uint8 name, ~CompData out) ;Variable new = {name, t, 0, 0} + ;log_debug(string_add("Creating new variable ", new.sprint())) /; if (self.next_loc(t) !< 0) ;new.loc_type = LOCATION.REGISTER ;new.location = self.next_loc(t) @@ -1208,7 +1188,7 @@ /; if (self.is_cf()) ;return self.parent`.next_const() ;/ - ;{}uint8 out = string_add(self.name, string_add("_#const_", int_to_string(self.c))) + ;{}uint8 out = string_add(self.name, string_add("#const_", int_to_string(self.c))) ;self.c++ ;return out ;/ @@ -1893,7 +1873,7 @@ ;refer.location = 2 ;/ - ;log_debug(wk.sprint()) + ;log_debug(string_add("Eval dot initial val: ", wk.sprint())) ;refer.data_type.ptr_chain.append(PTYPE.REFERENCE) /; if (tok`{start}.cmp(".")) @@ -1904,9 +1884,6 @@ ;refer = wk.deref(out) ;/ ;start++ - - ;tnsl.io.println(refer.name) - ;tnsl.io.println(refer.data_type) /; loop (start < max) [start++] /; if (tok`{start}.cmp("`")) @@ -2018,7 +1995,7 @@ ;/ ;log_debug(string_join( { - "_eval_value called with following type info:", t.name, int_to_string(t.s) + "_eval_value called with following type info:", t.sprint() }, " ")) ;Variable wk = {"#wk", t, 1, LOCATION.REGISTER} @@ -2095,6 +2072,7 @@ /; loop (tok`{cur`}.type_is(TOKEN.DEFWORD)) ;scope`.new_var(t, tok`{cur`}.data, out) ;eval_value(tok, cur, out, current, scope, t, false) + /; if (tok`{cur`}.cmp(",")) ;cur` = next_non_nl(tok, cur` + 1) ;/ @@ -2129,7 +2107,7 @@ ;/ /; compile_block (~{}Token tok, ~int cur, ~Module current, ~CompData out) - ;Scope root = {{}, 0, 0, 0, "", {}} + ;Scope root = {0, 0, 0, "", {}} ;int max = find_closing(tok, cur) ;bool r = false, m = false, returned = false ;Type ret = NO_TYPE @@ -2184,7 +2162,7 @@ /; loop (cur` = next_non_nl(tok, cur` + 1); cur` < max && !returned) [cur` = next_non_nl(tok, cur` + 1)] /; if (tok`{cur`}.cmp("/;") || tok`{cur`}.cmp(";;")) - ;tnsl.io.println("block") + ;tnsl.io.println("Block block") /; if (m) ;compile_block(tok, cur, current, out) ;; else @@ -2220,10 +2198,10 @@ ;tnsl.io.println(tok`{cur`}.data) ;/ ;; else if (is_definition(tok, cur, current)) - ;tnsl.io.println("def") + ;log_debug("Block def") ;eval_def(tok, cur, out, current, ~root) ;; else - ;tnsl.io.println("val") + ;log_debug("Block val") ;eval_value(tok, cur, out, current, ~root, NO_TYPE, false) ;/ ;/ @@ -2303,20 +2281,20 @@ ;/ ;continue ;; else if (tok`{cur`}.cmp("/;") || tok`{cur`}.cmp(";;")) - ;tnsl.io.print("block") + ;log_debug("Mod block") /; if (tok`{cur` + 1}.cmp("export") || tok`{cur` + 1}.cmp("module")) ;module_pass_two(tok, cur, current, out, f) ;; else ;compile_block(tok, cur, current, out) ;/ ;; else if (tok`{cur`}.cmp("struct")) - ;tnsl.io.print("struct") + ;log_debug("Mod struct") ;skip_struct(tok, cur) ;; else if (tok`{cur`}.cmp("enum")) - ;tnsl.io.print("enum") + ;log_debug("Mod enum") ;compile_enum(tok, cur, current, out) ;; else if (is_definition(tok, cur, current)) - ;tnsl.io.print("def") + ;log_debug("Mod def") ;compile_file_def(tok, cur, current, out) ;; else if (!(tok`{cur`}.cmp("\n"))) ;tnsl.io.println("Failed to recognize file-level statement") @@ -2408,21 +2386,31 @@ ;/ ;continue ;; else if (tok{i}.cmp("/;") || tok{i}.cmp(";;")) - ;tnsl.io.print("block") + ;log_debug("Root block") /; if (tok{i + 1}.cmp("export") || tok{i + 1}.cmp("module")) ;module_pass_two(~tok, ~i, current, ~out, f) ;; else ;compile_block(~tok, ~i, current, ~out) ;/ ;; else if (tok{i}.cmp("struct")) - ;tnsl.io.print("struct") + ;log_debug("File struct") ;skip_struct(~tok, ~i) ;; else if (tok{i}.cmp("enum")) - ;tnsl.io.print("enum") + ;log_debug("File enum") ;compile_enum(~tok, ~i, current, ~out) ;; else if (is_definition(~tok, ~i, current)) - ;tnsl.io.print("def") + ;log_debug("File def") ;compile_file_def(~tok, ~i, current, ~out) + ;; else if (tok{i}.cmp("asm")) + ;log_debug("File asm") + /; if (len (out.csec) == 0 && len (out.dsec) == 0) + ;out.hsec = string_add(out.hsec, unquote_str(tok{i + 1}.data)) + ;out.hsec.append('\n') + ;; else + ;out.dsec = string_add(out.dsec, unquote_str(tok{i + 1}.data)) + ;out.dsec.append('\n') + ;/ + ;i++ ;; else if (!(tok{i}.cmp("\n"))) ;tnsl.io.println("Failed to recognize file-level statement") ;tok{i}.print() |