From b9032fd845e9425df4f0bdf93701edf503c14534 Mon Sep 17 00:00:00 2001 From: CircleShift Date: Wed, 3 Dec 2025 02:31:45 -0500 Subject: [tnslc] begin rework of scope --- tnslc/compile/function.tnsl | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tnslc/compile/function.tnsl') diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index 911b02c..a768596 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -70,7 +70,61 @@ struct Function { ;/ ;/ + /; _fqn (~Module parent) [~uint8] + utils.Vector out + + return out.as_cstr() + ;/ + + /; _build_scope(~Module parent, ~CompBuf cb) [Scope] + ~uint8 fqn = self._fqn(parent) + Scope out + out.init(parent, cb, fqn) + out.parent = NULL + _delete(fqn) + + # TODO: Write label to cb + # TODO: Push all saved vars and deal with parameters + # TODO: Add all params to the scope + + return out + ;/ + + /; _end_scope(~Scope scope, ~CompBuf cb) + # TODO: place jmp label + # TODO: pop all saved vars + # TODO: ret + + scope`.end() + ;/ + /; _compile (~Module parent, ~CompBuf cb) + # Sanity check + ~parse.Node _up = self._up + /; if (_up`.sub.count < 1) + ~Scope s = self._build_scope(parent, cb) + self._end_scope(s, cb) + return + ;/ + + # Skip past parameters and outputs + int i = 0 + ~parse.Node n = _up`.sub.get(i) + /; if (n`._type == parse.NTYPE_DLIST) + i++ + /; if (_up`.sub.count > 1) + n = _up`.sub.get(1) + ;/ + ;/ + + /; if (n`._type == parse.NTYPE_TLIST) + i++ + ;/ + + # Create scope and start compiling statements from here. + Scope fscope = self._build_scope(parent, cb) + fscope._compile_statements(_up, i) + self._end_scope(~fscope, cb) ;/ /; _print (int idt) -- cgit v1.2.3