From 562547d3c55c79f5ec92464718dab5b524c7ae83 Mon Sep 17 00:00:00 2001 From: CircleShift Date: Tue, 23 Dec 2025 01:45:55 -0500 Subject: slightly better var creation (not done) --- tnslc/compile/function.tnsl | 10 ++++++---- tnslc/compile/scope.tnsl | 21 +++++++++++---------- tnslc/compile/var.tnsl | 32 +++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index 682236b..0f885f8 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -20,7 +20,7 @@ struct Function { ~parse.Node tn = NULL ~parse.Node n int reg = 1 - int stack_down = 0 + int stack_up = 0 /; loop (int i = 0; i < dl`.sub.count) [i++] n = dl`.sub.get(i) /; if (n`._type == parse.NTYPE_TYPE) @@ -33,13 +33,14 @@ struct Function { Var p p.init(tn, n) p._resolve_type(parent) - /; if (p.is_reg_passed() == true && reg < 7) + # TODO: This is wrong + /; if (p.regable() == true && reg < 7) p.loc = reg reg++ ;; else p.loc = 0 - 1 - p.offset = 0 - stack_down - stack_down = stack_down - p.actual_size() + p.offset = stack_up + stack_up = stack_up + p.actual_size() ;/ self.inputs.push(~p) ;/ @@ -53,6 +54,7 @@ struct Function { /; loop (int i = 0; i < tl`.sub.count) [i++] n = tl`.sub.get(i) /; if (n`._type == parse.NTYPE_TYPE) + # TODO: also wrong Var r r.init(n, ~dummy) r._resolve_type(parent) diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl index 1afaeab..9079e60 100644 --- a/tnslc/compile/scope.tnsl +++ b/tnslc/compile/scope.tnsl @@ -64,13 +64,13 @@ struct Scope { # Make variables # - /; _next_reg_slot [uint] - uint out = 9 + /; _next_reg_slot [int] + int out = 11 /; if (self.parent !== NULL) out = self.parent`._next_reg_slot() ;/ - /; if (out == 0) + /; if (out < 0) return out ;/ @@ -80,7 +80,7 @@ struct Scope { /; if (v`.loc > 0) out++ /; if (out > 16) - return 0 + return 0 - 1 ;/ ;/ ;/ @@ -88,8 +88,8 @@ struct Scope { return out ;/ - /; _next_stack_slot [uint] - uint out = 0 + /; _next_stack_slot [int] + int out = 0 - 56 /; if (self.parent !== NULL) out = self.parent`._next_stack_slot() ;/ @@ -108,13 +108,14 @@ struct Scope { /; mk_set_var (~Var src) Var out = src`.copy() - /; if (src`.is_reg_passed() == true) + /; if (src`.regable() == true) out.loc = self._next_reg_slot() - /; if (out.loc == 0) - out.loc = self._next_stack_slot() + /; if (out.loc + 1 == 0) + out.offset = self._next_stack_slot() ;/ ;; else - out.loc = self._next_stack_slot() + out.loc = 0 - 1 + out.offset = self._next_stack_slot() ;/ ~int32 p = out.top_ptrc() diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index 12d0dab..ff417c2 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -173,11 +173,15 @@ struct Var { self.ptrc.push(~ptr) ;/ - /; is_reg_passed [bool] - /; if (self.ptrc.count > 0) - return true + /; regable [bool] + ~int p + /; loop (int i = 0; i < self.ptrc.count) [i++] + p = self.ptrc.get(i) + /; if (p` !== 0) + return true + ;/ ;/ - return false + return _is_primitive(self._type`.name) !== 0 ;/ /; actual_size [uint] @@ -326,7 +330,7 @@ struct Var { out.push_cstr("rel \0") str = utils.strcpy(self.name) ;; else if (self.loc < 0) - str = reg_string(7, 8) + str = reg_string(8, 8) ;; else str = reg_string(self.loc, self.actual_size()) ;/ @@ -336,12 +340,18 @@ struct Var { /; if (self.in_mem() == true) /; if (self.loc + 1 == 0) - int stk = 0 - stk = stk - self.loc - out.push_cstr(" + \0") - str = utils.int_to_str(stk) - out.push_cstr(str) - _delete(str) + int stk = 0 - self.offset + /; if (stk > 0) + out.push_cstr(" - \0") + str = utils.int_to_str(stk) + out.push_cstr(str) + _delete(str) + ;; else if (stk < 0) + out.push_cstr(" + \0") + str = utils.int_to_str(self.offset) + out.push_cstr(str) + _delete(str) + ;/ ;/ out.push_char(']') ;/ -- cgit v1.2.3