summaryrefslogtreecommitdiff
path: root/tnslc/compile/scope.tnsl
diff options
context:
space:
mode:
authorCircleShift <kgunger12@gmail.com>2025-12-31 00:59:22 -0500
committerCircleShift <kgunger12@gmail.com>2025-12-31 00:59:22 -0500
commitb9f3f1731b2ccbef7547cfba61bc1cd697b00e61 (patch)
treeb19125e6515cac528aa93bcd46677cbd089fb39a /tnslc/compile/scope.tnsl
parentc998a37b330fdb4296007dffc579fe4909583ef7 (diff)
fix var loc generationorigin
Diffstat (limited to 'tnslc/compile/scope.tnsl')
-rw-r--r--tnslc/compile/scope.tnsl44
1 files changed, 31 insertions, 13 deletions
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
;/
;/