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/compile/function.tnsl | |
| parent | 7cd51a35921e7ed17fc3646bfd533695e35bebfd (diff) | |
pre-check funcs (stub)
Diffstat (limited to 'tnslc/compile/function.tnsl')
| -rw-r--r-- | tnslc/compile/function.tnsl | 51 |
1 files changed, 42 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) ;/ |