diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-16 15:25:01 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-16 15:25:01 +0000 |
commit | 480de114963ecee700ece5b8793916726c04b9ab (patch) | |
tree | 9c1543307aef92c1c88289a4d07ad4dcbae6b38c /eval.c | |
parent | ee65a81ee5b0112ba4480619ca672c569fb28b45 (diff) |
Replace the C repl with one written in prolog :)
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 31 |
1 files changed, 4 insertions, 27 deletions
@@ -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; } |