diff options
| author | CircleShift <kgunger12@gmail.com> | 2025-12-31 00:59:22 -0500 |
|---|---|---|
| committer | CircleShift <kgunger12@gmail.com> | 2025-12-31 00:59:22 -0500 |
| commit | b9f3f1731b2ccbef7547cfba61bc1cd697b00e61 (patch) | |
| tree | b19125e6515cac528aa93bcd46677cbd089fb39a /tnslc/compile | |
| parent | c998a37b330fdb4296007dffc579fe4909583ef7 (diff) | |
fix var loc generationorigin
Diffstat (limited to 'tnslc/compile')
| -rw-r--r-- | tnslc/compile/function.tnsl | 9 | ||||
| -rw-r--r-- | tnslc/compile/scope.tnsl | 44 | ||||
| -rw-r--r-- | tnslc/compile/var.tnsl | 6 |
3 files changed, 44 insertions, 15 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index 8b5b480..c47040f 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -235,11 +235,14 @@ struct Function { ;/ ;/ + /; _return (~Scope s, ~parse.Node n) + ;/ + # Should handle break, continue, and return /; _compile_flow_control (~Scope s, ~parse.Node n) /; if (utils.strcmp(n`.data, "return\0") == true) # Compute value and return - self._compile_value(s, n) + self._return(s, n) ;; else if (utils.strcmp(n`.data, "continue\0") == true) ~Scope lp = s`.closest_loop() /; if (lp == NULL) @@ -270,7 +273,9 @@ struct Function { ;/ # Should handle computing a value, delegate to other funcs when needed - /; _compile_value (~Scope s, ~parse.Node n) + /; _compile_value (~Scope s, ~parse.Node n) [Var] + Var out + return out ;/ /; _print (int idt) diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl index b7df075..191d433 100644 --- a/tnslc/compile/scope.tnsl +++ b/tnslc/compile/scope.tnsl @@ -77,10 +77,12 @@ struct Scope { ~Var v /; loop (int i = 0; i < self.vars.count) [i++] v = self.vars.get(i) - /; if (v`.loc > 0) + /; if (v`.loc > 1) out++ /; if (out > 16) - return 0 - 1 + out = 0 + out = out - 1 + return out ;/ ;/ ;/ @@ -89,7 +91,8 @@ struct Scope { ;/ /; _next_stack_slot [int] - int out = 0 - 56 + int out = 0 + out = out - 56 /; if (self.parent !== NULL) out = self.parent`._next_stack_slot() ;/ @@ -97,7 +100,7 @@ struct Scope { ~Var v /; loop (int i = 0; i < self.vars.count) [i++] v = self.vars.get(i) - /; if (v`.loc < 0) + /; if (v`.loc < 0 && v`.offset !== 0) out = out - v`.actual_size() ;/ ;/ @@ -160,14 +163,12 @@ struct Scope { /; precheck_stmt (~parse.Node n) ;/ - /; find_var (~uint8 name) [~Var] + /; _find_var (~uint8 name) [~Var] ~Var v /; loop (int i = 0; i < self.vars.count) [i++] v = self.vars.get(i) /; if (utils.strcmp(v`.name, name) == true) - /; if (v`.loc > 1 || v`.offset !== 0) - return v - ;/ + return v ;/ ;/ @@ -178,22 +179,39 @@ struct Scope { return NULL ;/ + /; find_var (~uint8 name) [~Var] + ~Var out = self._find_var(name) + + /; if (out == NULL) + return NULL + ;/ + + /; if (out`.loc > 1 || out`.offset !== 0) + return out + ;/ + + return NULL + ;/ + /; mk_set_var (~Var src) - ~Var v = self.find_var(src`.name) + ~Var v = self._find_var(src`.name) /; if (v == NULL) return ;/ + int tmp = 0 /; if (v`.loc == 1) - v`.loc = self._next_reg_slot() + int tmp = self._next_reg_slot() + v`.loc = tmp /; if (v`.loc + 1 == 0) - v`.offset = self._next_stack_slot() + tmp = self._next_stack_slot() + v`.offset = tmp ;/ ;; else if (v`.loc + 1 == 0) /; if (v`.offset == 0) - v`.loc = 0 - 1 - v`.offset = self._next_stack_slot() + tmp = self._next_stack_slot() + v`.offset = tmp ;/ ;/ diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index 3bf8b5e..a47e182 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -158,6 +158,12 @@ struct Var { ;/ _printf("\n\0") + _indent(idt + 1) + _print_num("loc: %d\n\0", self.loc) + + _indent(idt + 1) + _print_num("off: %d\n\0", self.offset) + _indent(idt) _printf("}\n\0") ;/ |