diff options
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 40 |
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 * |