summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 15:25:01 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 15:25:01 +0000
commit480de114963ecee700ece5b8793916726c04b9ab (patch)
tree9c1543307aef92c1c88289a4d07ad4dcbae6b38c /eval.c
parentee65a81ee5b0112ba4480619ca672c569fb28b45 (diff)
Replace the C repl with one written in prolog :)
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c31
1 files changed, 4 insertions, 27 deletions
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;
}