diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2025-12-28 01:52:42 -0500 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2025-12-28 01:52:42 -0500 |
| commit | 75c5c7ccdf258d1f4731b02b6291ce55a04ea709 (patch) | |
| tree | 9037f5f4e5618536f5746d317d146f7f041a296d /tnslc | |
| parent | 7cd51a35921e7ed17fc3646bfd533695e35bebfd (diff) | |
pre-check funcs (stub)
Diffstat (limited to 'tnslc')
| -rw-r--r-- | tnslc/compile/function.tnsl | 51 | ||||
| -rw-r--r-- | tnslc/compile/scope.tnsl | 33 | ||||
| -rw-r--r-- | tnslc/compile/var.tnsl | 1 |
3 files changed, 76 insertions, 9 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index a30f383..5db1bd3 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -100,6 +100,31 @@ struct Function { ;/ ;/ + /; _compute_scope_vars(~Scope s) + + ~Var in + /; loop (int i = 0; i < self.inputs.count) [i++] + in = self.inputs.get(i) + s`.mk_aware(in) + ;/ + + int i = self._first_stmt_off() + /; if (i < 0) + return + ;/ + + ~parse.Node _up = self._up + ~parse.Node n + /; loop (i < _up`.sub.count) [i++] + n = _up`.sub.get(i) + /; if (n`._type == parse.NTYPE_DECL) + s`.mk_aware_node(n) + ;; else + s`.precheck_stmt(n) + ;/ + ;/ + ;/ + /; _build_func(~Module parent, ~CompBuf cb) [Scope] Scope out out.init(parent, cb, self.name) @@ -125,6 +150,8 @@ struct Function { cb`.add_c(" push r14\n\0") cb`.add_c(" push r15 ; scope init\n\n\0") + self._compute_scope_vars(~out) + # Add all params to the scope ~Var in /; loop (int i = 0; i < self.inputs.count) [i++] @@ -151,17 +178,14 @@ struct Function { scope`.end() ;/ - /; _compile (~Module parent, ~CompBuf cb) - # Sanity check + /; _first_stmt_off [int] + int i = 0 ~parse.Node _up = self._up + /; if (_up`.sub.count < 1) - ~Scope s = self._build_func(parent, cb) - self._end_func(s, cb) - return + return i - 1 ;/ - - # Skip past parameters and outputs - int i = 0 + ~parse.Node n = _up`.sub.get(i) /; if (n`._type == parse.NTYPE_DLIST) i++ @@ -173,13 +197,22 @@ struct Function { /; if (n`._type == parse.NTYPE_TLIST) i++ ;/ + + return i + ;/ + + /; _compile (~Module parent, ~CompBuf cb) + # Sanity check + int i = self._first_stmt_off() # Create scope Scope fscope = self._build_func(parent, cb) + /; if (i !< 0) + self._compile_statements(~fscope, i) + ;/ # Compile and then end scope - self._compile_statements(~fscope, i) self._end_func(~fscope, cb) ;/ diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl index 9079e60..b4fd4f3 100644 --- a/tnslc/compile/scope.tnsl +++ b/tnslc/compile/scope.tnsl @@ -105,6 +105,39 @@ struct Scope { return out ;/ + /; mk_aware (~Var v) + Var mk = v`.copy() + mk.offset = 0 + + /; if (mk.loc > 0) + mk.loc = 1 + ;/ + + self.vars.push(~mk) + ;/ + + /; mk_aware_node (~parse.Node n) + ;/ + + /; precheck_stmt (~parse.Node n) + ;/ + + /; 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) + return v + ;/ + ;/ + + /; if (self.parent !== NULL) + return self.parent`.find_var(name) + ;/ + + return NULL + ;/ + /; mk_set_var (~Var src) Var out = src`.copy() diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index cf12878..0dc0586 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -115,6 +115,7 @@ struct Var { out.init(self._tn, self._id) out._type = self._type out.loc = self.loc + out.offset = self.offset /; loop (int i = 0; i < self.ptrc.count) [i++] ~int32 p = self.ptrc.get(i) |