diff options
-rw-r--r-- | builtins.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -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; } |