From 3af75072c6226932f7dae48c6fc34c4177e42c18 Mon Sep 17 00:00:00 2001 From: Kai Gunger Date: Fri, 17 Apr 2026 02:38:13 -0400 Subject: [tnslc] initial bin op comp --- tnslc/compile/function.tnsl | 56 ++++++++++++++++++++++++++++++++++++++++++--- tnslc/compile/scope.tnsl | 5 ++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index cd755cb..69b069d 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -440,7 +440,7 @@ struct Function { ;/ ;/ - /; _compile_func_call(~Scope s, ~parse.Node n, ~Function f) [Var] + /; _compile_call(~Scope s, ~parse.Node n, ~Function f) [Var] Var out return out ;/ @@ -500,12 +500,62 @@ struct Function { return out ;/ - /; _compile_bin (~Scope s, ~parse.Node n) [Var] - # TODO + /; _compile_chain(~Scope s, ~parse.Node n) [Var] Var out return out ;/ + /; _compile_bin (~Scope s, ~parse.Node n) [Var] + # TODO + /; if (utils.strcmp(n`.data, ".\0") == true) + return self._compile_chain(s, n) + ;/ + + ~parse.Node lhn = n`.sub.get(0) + ~parse.Node rhn = n`.sub.get(1) + + # If we are setting + /; if (utils.strcmp(n`.data, "=\0") == true) + Var rhs = self._compile_value(s, rhn) + # TODO: move rhs maybe if it is in rdi + Var lhs = self._compile_value(s, lhn) + lhs.set(s`.cb, ~rhs) + rhs.end() + return lhs + ;/ + + # Otherwise + Var lhs = self._compile_value(s, lhn) + /; if (s`.is_tmp(~lhs) == false) + Var tmp = s`.mk_tmp(~lhs) + tmp.set(s`.cb, ~lhs) + lhs.end() + lhs = tmp + ;/ + Var rhs = self._compile_value(s, rhn) + + /; if (utils.strcmp(n`.data, "*\0") == true) + lhs.mul(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "/\0") == true) + lhs.div(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "%\0") == true) + lhs.mod(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "+\0") == true) + lhs.add(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "-\0") == true) + lhs.sub(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "&\0") == true) + lhs.and(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "|\0") == true) + lhs.or(s`.cb, ~rhs) + ;; else if (utils.strcmp(n`.data, "^\0") == true) + lhs.xor(s`.cb, ~rhs) + ;/ + + rhs.end() + return lhs + ;/ + /; _compile_pre (~Scope s, ~parse.Node n, ~Var type_hint) [Var] Var out diff --git a/tnslc/compile/scope.tnsl b/tnslc/compile/scope.tnsl index 6faf596..a9cbef7 100644 --- a/tnslc/compile/scope.tnsl +++ b/tnslc/compile/scope.tnsl @@ -412,6 +412,11 @@ struct Scope { ;/ ;/ + # Returns true if the variable is in a temp spot + /; is_tmp (~Var v) [bool] + return false + ;/ + # # Sub scope # -- cgit v1.2.3