summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-14 00:31:03 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-14 00:31:03 +0000
commit07082593ab4abfbf9a3dd6729cb2e548ec303115 (patch)
treef6fa70b94a0bf263f2fa8af21b26aaae90e1965f /functions.c
parent454e026edc25b1d0f6b4f035d41b38a1e60e16e3 (diff)
Implement code for running operators (both monadic and dyadic).
Also implement ⍨ and ⍥ since they are very simple
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/functions.c b/functions.c
index db9fe01..636c195 100644
--- a/functions.c
+++ b/functions.c
@@ -116,6 +116,46 @@ fndyad dyadfunctiondefs[] = {
0, /* ⍕ */
};
+/* Runner function */
+Array *
+runfunc(Function f, Array *left, Array *right)
+{
+ if(f.type == FunctypeDfn){
+ Symtab *tmpsymtab = currentsymtab;
+ currentsymtab = newsymtab();
+
+ if(left){
+ Symbol *alpha = getsym(currentsymtab, L"⍺");
+ alpha->value.tag = ArrayTag;
+ alpha->value.array = left;
+ alpha->undefined = 0;
+ incref(left);
+ }
+
+ Symbol *omega = getsym(currentsymtab, L"⍵");
+ omega->value.tag = ArrayTag;
+ omega->value.array = right;
+ omega->undefined = 0;
+ incref(right);
+
+ Datum *dfnres = evalline(f.dfn);
+ freesymtab(currentsymtab);
+ currentsymtab = tmpsymtab;
+ return (*dfnres).array; /* TODO what if the evaluation failed */
+ }else if(f.type == FunctypePrim){
+ if(left)
+ return dyadfunctiondefs[f.code](left, right);
+ else
+ return monadfunctiondefs[f.code](right);
+ }else{
+ /* TODO assumes prim op, not dop */
+ if(f.operator.dyadic)
+ return dyadoperatordefs[f.operator.code](f.operator.left, f.operator.right, left, right);
+ else
+ return monadoperatordefs[f.operator.code](f.operator.left, left, right);
+ }
+}
+
/* Monadic functions */
Array *