From 07082593ab4abfbf9a3dd6729cb2e548ec303115 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 14 Jan 2022 00:31:03 +0000 Subject: =?UTF-8?q?Implement=20code=20for=20running=20operators=20(both=20?= =?UTF-8?q?monadic=20and=20dyadic).=20Also=20implement=20=E2=8D=A8=20and?= =?UTF-8?q?=20=E2=8D=A5=20since=20they=20are=20very=20simple?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'functions.c') 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 * -- cgit v1.2.3