From c06f8eb6a30a74a589537fc4d77be1c334edae72 Mon Sep 17 00:00:00 2001 From: Kai Gunger Date: Tue, 2 Dec 2025 23:19:53 -0500 Subject: [tnslc] resolve types for structs and functions --- tnslc/compile/function.tnsl | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tnslc/compile/function.tnsl') diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index b0a1d00..911b02c 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -16,7 +16,58 @@ struct Function { self.outputs.init(len v) ;/ + /; _resolve_dlist (~Module parent, ~parse.Node dl) + ~parse.Node tn = NULL + ~parse.Node n + /; loop (int i = 0; i < dl`.sub.count) [i++] + n = dl`.sub.get(i) + /; if (n`._type == parse.NTYPE_TYPE) + tn = n + ;; else if (n`._type == parse.NTYPE_ID) + /; if (tn == NULL) + _printf("Identifier declared in parameter list before any type was found!\n\0") + return + ;/ + Var p + p.init(tn, n) + p._resolve_type(parent) + self.inputs.push(~p) + ;/ + ;/ + ;/ + + /; _resolve_tlist (~Module parent, ~parse.Node tl) + ~parse.Node n + parse.Node dummy + dummy.data = "### OUTPUT ###\0" + /; loop (int i = 0; i < tl`.sub.count) [i++] + n = tl`.sub.get(i) + /; if (n`._type == parse.NTYPE_TYPE) + Var r + r.init(n, ~dummy) + r._resolve_type(parent) + self.outputs.push(~r) + ;/ + ;/ + ;/ + /; _resolve_type (~Module parent) + ~parse.Node _up = self._up + /; if (_up`.sub.count < 1) + return + ;/ + + ~parse.Node lst = _up`.sub.get(0) + /; if (lst`._type == parse.NTYPE_DLIST) + self._resolve_dlist(parent, lst) + /; if (_up`.sub.count > 1) + lst = _up`.sub.get(1) + ;/ + ;/ + + /; if (lst`._type == parse.NTYPE_TLIST) + self._resolve_tlist(parent, lst) + ;/ ;/ /; _compile (~Module parent, ~CompBuf cb) @@ -28,6 +79,21 @@ struct Function { _printf(self.name) _printf("\n\0") + _indent(idt) + _printf(" inputs:\n\0") + ~Var prtv + /; loop (int i = 0; i < self.inputs.count) [i++] + prtv = self.inputs.get(i) + prtv`._print(idt + 1) + ;/ + + _indent(idt) + _printf(" outputs:\n\0") + /; loop (int i = 0; i < self.outputs.count) [i++] + prtv = self.outputs.get(i) + prtv`._print(idt + 1) + ;/ + _indent(idt) _printf("}\n\0") ;/ -- cgit v1.2.3