summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtins.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/builtins.c b/builtins.c
index 9aee573..a037a23 100644
--- a/builtins.c
+++ b/builtins.c
@@ -216,10 +216,29 @@ builtinfail(Term *goal, Binding **bindings, Module *module)
}
int
+canbecalled(Term *t)
+{
+ if(t->tag == VariableTerm || t->tag == AtomTerm)
+ return 1;
+ if(t->tag != CompoundTerm)
+ return 0;
+
+ if(t->arity == 2 && (runestrcmp(t->text, L",") == 0 || runestrcmp(t->text, L";") == 0))
+ return canbecalled(t->children) && canbecalled(t->children->next);
+ else
+ return 1;
+}
+
+int
builtincall(Term *goal, Binding **bindings, Module *module)
{
USED(bindings);
- goalstack = addgoals(goalstack, goal->children, module);
+ Term *callgoal = goal->children;
+
+ if(!canbecalled(callgoal))
+ Throw(typeerror(L"callable", callgoal));
+
+ goalstack = addgoals(goalstack, callgoal, module);
return 1;
}