diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2026-01-01 21:19:38 -0500 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2026-01-01 21:19:38 -0500 |
| commit | 8682fb7aad90f053375937fe391a65e7e269e2c1 (patch) | |
| tree | 1a8cd9cd6c8657a19b733f6db6873458102c6f5a /tnslc/compile/function.tnsl | |
| parent | b9f3f1731b2ccbef7547cfba61bc1cd697b00e61 (diff) | |
handle variable declarations
Diffstat (limited to 'tnslc/compile/function.tnsl')
| -rw-r--r-- | tnslc/compile/function.tnsl | 33 |
1 files changed, 31 insertions, 2 deletions
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 ;/ |