From 480de114963ecee700ece5b8793916726c04b9ab Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 16 Jul 2021 15:25:01 +0000 Subject: Replace the C repl with one written in prolog :) --- eval.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 13718ab..6fec2b6 100644 --- a/eval.c +++ b/eval.c @@ -11,33 +11,10 @@ Builtin findbuiltin(Term *); void addchoicepoints(Clause *, Term *, Goal *, Module *); int -evalquery(Term *query, Binding **resultbindings) +evalquery(Term *query) { - if(choicestack == nil){ - /* - The goal stack has the original query at the very bottom, protected by a catch frame where the ->goal field is nil. - This makes it so that we can continue until we hit the protective goal, at which point we have solved everything - and to get the result we can unify the original query with the one at the bottom of the stack, to get the bindings - applied. - */ - goalstack = gmalloc(sizeof(Goal)); - goalstack->goal = copyterm(query, nil); - goalstack->module = usermodule; - goalstack->catcher = nil; - goalstack->next = nil; - Goal *protector = gmalloc(sizeof(Goal)); - protector->goal = nil; - protector->module = usermodule; - protector->catcher = mkvariable(L"catch-var"); - protector->next = goalstack; - goalstack = protector; - - /* Now add the actual goals */ - goalstack = addgoals(goalstack, query, usermodule); - - }else{ - goto Backtrack; - } + Binding *replbindings = nil; + goalstack = addgoals(goalstack, query, usermodule); while(goalstack->goal != nil){ Term *goal = goalstack->goal; @@ -101,7 +78,7 @@ Backtrack: } } goalstack = goalstack->next; - unify(query, goalstack->goal, resultbindings); + unify(query, goalstack->goal, &replbindings); return 1; } -- cgit v1.2.3