From 8682fb7aad90f053375937fe391a65e7e269e2c1 Mon Sep 17 00:00:00 2001 From: Kai Gunger Date: Thu, 1 Jan 2026 21:19:38 -0500 Subject: handle variable declarations --- tnslc/compile/function.tnsl | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'tnslc/compile/function.tnsl') diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index c47040f..c9ab985 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -231,6 +231,8 @@ struct Function { s`.cb`.add_c(" \0") s`.cb`.add_c(n`.data) s`.cb`.add_c(" ; User defined asm\n\0") + ;; else if (n`._type == parse.NTYPE_DECL) + self._compile_decl(s, n) ;/ ;/ ;/ @@ -272,9 +274,36 @@ struct Function { ;/ ;/ + # Should handle variable declarations + /; _compile_decl(~Scope s, ~parse.Node n) + ~parse.Node sub + /; loop (int i = 0; i < n`.sub.count) [i++] + sub = n`.sub.get(i) + /; if (sub`._type == parse.NTYPE_ID) + ~Var v = s`._find_var(sub`.data) + + /; if (v == NULL) + _printf("Failed to find variable '\0") + _printf(sub`.data) + _printf("'\n\0") + return + ;/ + + /; if (sub`.sub.count > 0) + sub = sub`.sub.get(0) + Var val = self._compile_value(s, sub, v) + s`.mk_set_var(~val) + val.end() + ;; else + s`.mk_var(v) + ;/ + ;/ + ;/ + ;/ + # Should handle computing a value, delegate to other funcs when needed - /; _compile_value (~Scope s, ~parse.Node n) [Var] - Var out + /; _compile_value (~Scope s, ~parse.Node n, ~Var type_hint) [Var] + Var out = type_hint`.copy() return out ;/ -- cgit v1.2.3