summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/eval.c b/eval.c
index e50903f..1ff40ce 100644
--- a/eval.c
+++ b/eval.c
@@ -10,18 +10,19 @@ typedef Datum (*evalfn)(Datum, Datum);
Datum strand(Datum, Datum);
Datum monadfun(Datum, Datum);
+Datum dyadfun(Datum, Datum);
Datum lpar(Datum, Datum);
Datum rpar(Datum, Datum);
int bindingstrengths[12][12] = {
/* A F H MO DO AF ( ) { } [ ] */
- 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */
+ 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* H */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* MO */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DO */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* FA */
- 3, 3, 3, 3, 3, 3, 0, 4, 3, 3, 3, 3, /* ( */
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* AF */
+ 4, 4, 4, 4, 4, 4, 0, 5, 4, 4, 4, 4, /* ( */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ) */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* { */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* } */
@@ -31,12 +32,12 @@ int bindingstrengths[12][12] = {
evalfn evalfns[12][12] = {
/* A F H MO DO AF ( ) { } [ ] */
- strand, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */
+ strand, dyadfun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */
monadfun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* H */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* MO */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DO */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* FA */
+ monadfun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* AF */
lpar, lpar, lpar, lpar, lpar, 0, lpar, rpar, lpar, lpar, lpar, lpar, /* ( */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ) */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* { */
@@ -45,7 +46,6 @@ evalfn evalfns[12][12] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ] */
};
-
Datum *
eval(Datum *tokens, int *ntoks)
{
@@ -104,8 +104,23 @@ monadfun(Datum left, Datum right)
print("Monadic function application\n");
Datum result;
result.tag = ArrayTag;
+
/* TODO handle undefined functions here */
- result.array = monadfunctiondefs[left.code](right.array);
+ if(left.func.left)
+ result.array = dyadfunctiondefs[left.code](left.func.left, right.array);
+ else
+ result.array = monadfunctiondefs[left.code](right.array);
+ return result;
+}
+
+Datum
+dyadfun(Datum left, Datum right)
+{
+ print("Applying left argument to function\n");
+ Datum result;
+ result.tag = BoundFunctionTag,
+ result.func = right.func;
+ result.func.left = left.array;
return result;
}