From c8867502df27f516b0d46b1a254f0da572bdadb6 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 16 Jul 2021 20:22:40 +0000 Subject: Handle the 'unknown' prolog flag correctly --- eval.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 6fec2b6..f957553 100644 --- a/eval.c +++ b/eval.c @@ -40,8 +40,32 @@ evalquery(Term *query) }else{ Predicate *pred = findpredicate(module->predicates, goal); if(pred == nil){ - print("No predicate matches: %S:%S\n", module->name, prettyprint(goal, 0, 0, 0, nil)); - goto Backtrack; + Rune *name; + int arity; + Term *replacement = nil; + Term *procedure; + Term *pi; + if(goal->tag == CompoundTerm){ + name = goal->text; + arity = goal->arity; + }else{ + name = prettyprint(goal, 0, 0, 0, nil); + arity = 0; + } + switch(flagunknown){ + case UnknownError: + procedure = mkatom(name); + procedure->next = mkinteger(arity); + pi = mkcompound(L"/", 2, procedure); + replacement = existenceerror(L"procedure", pi); + break; + case UnknownWarning: + print("Warning: no such predicate in module %S: %S/%d\n", module->name, name, arity); + case UnknownFail: + replacement = mkatom(L"fail"); + } + goalstack = addgoals(goalstack, replacement, module); + continue; } /* Find a clause where the head unifies with the goal */ -- cgit v1.2.3