diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2026-07-11 14:43:40 -0400 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2026-07-11 14:43:40 -0400 |
| commit | a27736576d56e14e9dc534004284d9a4a9356369 (patch) | |
| tree | cdb9aa7368b763fcb806dfc77d048aa7ea12e037 | |
| parent | bc52debb9566d4c4cbdb398837c3244e53b81e75 (diff) | |
[tnslc] bootstrap compiler
| -rw-r--r-- | tnslc/compile/function.tnsl | 52 | ||||
| -rw-r--r-- | tnslc/compile/scope.tnsl | 7 | ||||
| -rw-r--r-- | tnslc/compile/var.tnsl | 18 |
3 files changed, 46 insertions, 31 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index d87c207..c88654a 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -1076,7 +1076,8 @@ struct Function { /; if (utils.strcmp(post`.data, "(\0") == true) _printf("TODO: tnslc does not yet support calling variables\n\0") ;; else if (utils.strcmp(post`.data, "`\0") == true) - Var tmp = v`.de_ref() + Var tmp + tmp = v`.de_ref() v`.end() self._set_var_ptr(v, ~tmp) ;; else if (utils.strcmp(post`.data, "{\0") == true) @@ -1094,7 +1095,8 @@ struct Function { v`.ptr_push(pp) ;/ - Var tmp = s`.mk_tmp(v) + Var tmp + tmp = s`.mk_tmp(v) tmp.set(s`.cb, v) v`.end() /; if (is_ref == true) @@ -1107,18 +1109,19 @@ struct Function { # Compute index Var idx = self._compile_value(s, post) - /; if (idx.loc == 6) + /; if (idx.loc == 1) ~CompBuf buf = s`.cb - buf`.add_c(" mov rax, rdi ; idx\n\0") - idx.loc = 1 + buf`.add_c(" mov rdi, rax ; idx\n\0") + idx.loc = 6 ;; else if (idx.loc == 5) ~CompBuf buf = s`.cb - buf`.add_c(" mov rax, rsi ; idx\n\0") - idx.loc = 1 + buf`.add_c(" mov rdi, rsi ; idx\n\0") + idx.loc = 6 ;/ # Take index and set result - Var tmp = v`.index(s`.cb, ~idx, 6) + Var tmp + tmp = v`.index(s`.cb, ~idx, 1) # Clear tmp /; if (s`.is_tmp(v) == true) @@ -1133,7 +1136,8 @@ struct Function { Var copy = v`.copy() copy.strip_refs() # Make tmp var - Var tmp = s`.mk_tmp(~copy) + Var tmp + tmp = s`.mk_tmp(~copy) copy.end() # Set the new tmp to the value of the old tmp.set(s`.cb, v) @@ -1146,7 +1150,8 @@ struct Function { Var copy = v`.copy() copy.strip_refs() # Make tmp var - Var tmp = s`.mk_tmp(~copy) + Var tmp + tmp = s`.mk_tmp(~copy) copy.end() # Set the new tmp to the value of the old tmp.set(s`.cb, v) @@ -1486,7 +1491,8 @@ struct Function { lhs.ptr_push(ptr) ;/ - Var tmp = s`.mk_tmp(~lhs) + Var tmp + tmp = s`.mk_tmp(~lhs) tmp.set(s`.cb, ~lhs) lhs.end() @@ -1516,7 +1522,8 @@ struct Function { # Mov lhs to a register bool is_ref = lhs.is_ref() /; if (lhs.loc < 1 || is_ref == true) - Var tmp = lhs.copy() + Var tmp + tmp = lhs.copy() tmp.strip_refs() tmp.loc = 3 tmp.offset = 0 @@ -1576,7 +1583,8 @@ struct Function { lhs.ptr_push(ptr) ;/ - Var tmp = s`.mk_tmp(~lhs) + Var tmp + tmp = s`.mk_tmp(~lhs) tmp.set(s`.cb, ~lhs) lhs.end() @@ -1604,7 +1612,8 @@ struct Function { # Mov lhs to a register bool is_ref = lhs.is_ref() /; if (lhs.loc < 1 || is_ref == true) - Var tmp = lhs.copy() + Var tmp + tmp = lhs.copy() tmp.strip_refs() tmp.loc = 3 tmp.offset = 0 @@ -1671,7 +1680,8 @@ struct Function { lhs.ptr_push(ptr) ;/ - Var tmp = s`.mk_tmp(~lhs) + Var tmp + tmp = s`.mk_tmp(~lhs) tmp.set(s`.cb, ~lhs) lhs.end() @@ -1701,7 +1711,8 @@ struct Function { /; if (s`.is_tmp(~lhs) == false) Var copy = lhs.copy() copy.strip_refs() - Var tmp = s`.mk_tmp(~copy) + Var tmp + tmp = s`.mk_tmp(~copy) copy.end() tmp.set(s`.cb, ~lhs) @@ -1712,7 +1723,8 @@ struct Function { /; if (lhs.is_ref() == true) Var copy = lhs.copy() copy.strip_refs() - Var tmp = s`.mk_tmp(~copy) + Var tmp + tmp = s`.mk_tmp(~copy) copy.end() tmp.set(s`.cb, ~lhs) @@ -1759,7 +1771,8 @@ struct Function { out.not(s`.cb) ;; else if (utils.strcmp(n`.data, "~\0") == true) ~parse.Node sub = n`.sub.get(0) - Var tmp = self._compile_value(s, sub) + Var tmp + tmp = self._compile_value(s, sub) out = tmp.take_ptr(s`.cb, 5) tmp.end() ;; else if (utils.strcmp(n`.data, "--\0") == true) @@ -1779,7 +1792,8 @@ struct Function { f_scope.cb = ~f_buff ~parse.Node sub = n`.sub.get(0) - Var tmp = self._compile_value(~f_scope, sub) + Var tmp + tmp = self._compile_value(~f_scope, sub) # Generate the length ~Struct t = self._find_literal_type(s, "uint\0") diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl index 96d30fd..6271a35 100644 --- a/tnslc/compile/scope.tnsl +++ b/tnslc/compile/scope.tnsl @@ -271,7 +271,7 @@ struct Scope { ;/ /; if (self.parent !== NULL) - return self.parent`.find_var(name) + return self.parent`._find_var(name) ;/ return NULL @@ -293,6 +293,7 @@ struct Scope { _printf("\" but it doesn't look like it's been initialized yet!\n\0") _print_num(" Loc: %d\n\0", out`.loc) _print_num(" Offset: %d\n\0", out`.offset) + out`._print(0) return NULL ;/ @@ -305,7 +306,7 @@ struct Scope { int tmp = 0 /; if (v`.loc == 1) - int tmp = self._next_reg_slot() + tmp = self._next_reg_slot() v`.loc = tmp /; if (v`.loc + 1 == 0) tmp = self._next_stack_slot() @@ -359,7 +360,7 @@ struct Scope { int tmp = 0 /; if (v.regable() == true) - int tmp = self._next_tmp_slot() + tmp = self._next_tmp_slot() v.loc = tmp /; if (v.loc + 1 == 0) tmp = self._next_stack_slot() diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index d12a85c..8590bc7 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -484,11 +484,11 @@ struct Var { # Static compilation # ###################### - /; _static_compile_arr(~parse.Node n, ~utils.Vector out, int depth) [~uint8] + /; _static_compile_arr (~parse.Node n, ~utils.Vector out, int depth) [~uint8] return utils.strcpy("TODO ; Static compile array\0") ;/ - /; _static_compile_ptr(~parse.Node n, ~utils.Vector out, int depth) [~uint8] + /; _static_compile_ptr (~parse.Node n, ~utils.Vector out, int depth) [~uint8] /; if (n`._type == parse.NTYPE_VALUE) n = n`.sub.get(0) @@ -575,7 +575,7 @@ struct Var { return utils.strcpy("TODO ; Static compile struct\0") ;/ - /; _static_comp_prim_r_dot(~parse.Node n) [Var] + /; _static_comp_prim_r_dot (~parse.Node n) [Var] # Has to do: # Variable dot chain mod # Variable dot chain struct @@ -585,7 +585,7 @@ struct Var { return out ;/ - /; _static_comp_prim_r_bin(~parse.Node n) [Var] + /; _static_comp_prim_r_bin (~parse.Node n) [Var] /; if (n`.data{0} == '.') return self._static_comp_prim_r_dot(n) ;/ @@ -626,14 +626,14 @@ struct Var { return a ;/ - /; _static_comp_prim_r_pre(~parse.Node n) [Var] + /; _static_comp_prim_r_pre (~parse.Node n) [Var] _printf("TODO: _static_comp_prim_r_pre\n\0") Var out out._init(self._type) return out ;/ - /; _static_comp_prim_r_post(~parse.Node n) [Var] + /; _static_comp_prim_r_post (~parse.Node n) [Var] # Has to do: # deref of variables # array index @@ -643,7 +643,7 @@ struct Var { return out ;/ - /; _static_comp_prim_r_id(~parse.Node n) [Var] + /; _static_comp_prim_r_id (~parse.Node n) [Var] # Has to do: # Get variable and static comp ~uint8 name = n`.data @@ -720,7 +720,7 @@ struct Var { return out ;/ - /; _static_comp_prim_r(~parse.Node n) [Var] + /; _static_comp_prim_r (~parse.Node n) [Var] /; if (n`._type == parse.NTYPE_VALUE) n = n`.sub.get(0) return self._static_comp_prim_r(n) @@ -765,7 +765,7 @@ struct Var { return out ;/ - /; _static_compile_prim(~parse.Node n) [~uint8] + /; _static_compile_prim (~parse.Node n) [~uint8] Var vout = self._static_comp_prim_r(n) utils.Vector out |