summaryrefslogtreecommitdiff
path: root/tnslc/'
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/'')
-rw-r--r--tnslc/'165
1 files changed, 165 insertions, 0 deletions
diff --git a/tnslc/' b/tnslc/'
new file mode 100644
index 0000000..485e5d1
--- /dev/null
+++ b/tnslc/'
@@ -0,0 +1,165 @@
+
+struct Function {
+ ~uint8 name,
+ utils.Vector
+ inputs,
+ outputs,
+ ~parse.Node _up,
+}
+
+/; method Function
+ /; init (~parse.Node n)
+ self.name = utils.strcpy(n`.data)
+ self._up = n
+ Var v
+ self.inputs.init(len v)
+ 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)
+ ;/
+ ;/
+
+ /; _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)
+ _delete(fqn)
+
+ # TODO: Push all saved vars and deal with parameters
+ # TODO: Add all params to the scope
+
+ return out
+ ;/
+
+ /; _end_scope(~Scope scope, ~CompBuf cb)
+ ;/
+
+ /; _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(cb, _up, i)
+ self._end_scope(~fscope, cb)
+ ;/
+
+ /; _print (int idt)
+ _indent(idt)
+ _printf("{ Function : \0")
+ _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")
+ ;/
+
+ /; end
+ _delete(self.name)
+
+ ~Var v
+ /; loop (int i = 0; i < self.inputs.count) [i++]
+ v = self.inputs.get(i)
+ v`.end()
+ ;/
+ self.inputs.end()
+
+ /; loop (int i = 0; i < self.outputs.count) [i++]
+ v = self.outputs.get(i)
+ v`.end()
+ ;/
+ self.outputs.end()
+ ;/
+;/
+