summaryrefslogtreecommitdiff
path: root/tnslc/compile/function.tnsl
diff options
context:
space:
mode:
authorCircleShift <kgunger12@gmail.com>2025-12-03 02:31:45 -0500
committerCircleShift <kgunger12@gmail.com>2025-12-03 02:31:45 -0500
commitb9032fd845e9425df4f0bdf93701edf503c14534 (patch)
treea38fdfcdcd5f693584f6f650188aedebdc52ebe6 /tnslc/compile/function.tnsl
parentc06f8eb6a30a74a589537fc4d77be1c334edae72 (diff)
[tnslc] begin rework of scope
Diffstat (limited to 'tnslc/compile/function.tnsl')
-rw-r--r--tnslc/compile/function.tnsl54
1 files changed, 54 insertions, 0 deletions
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)