summaryrefslogtreecommitdiff
path: root/builtins.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-21 00:12:09 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-21 00:12:09 +0000
commit88841b194dc86c9392a813f9b8b0cf16857acb93 (patch)
tree18dd5e01b0ddc07b7318fd783885533450cf9f7b /builtins.c
parent085e3595450d6652b62350621b470b26ae67b6de (diff)
Always use a fresh clausenr for read teams, and make sure to update the clausenr in call/1, so cuts are local to that call
Diffstat (limited to 'builtins.c')
-rw-r--r--builtins.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/builtins.c b/builtins.c
index a037a23..e403541 100644
--- a/builtins.c
+++ b/builtins.c
@@ -229,6 +229,21 @@ canbecalled(Term *t)
return 1;
}
+void
+updateclausenr(Term *t, uvlong nr)
+{
+ /* Change the clause number on the term and its subterms, unless it is a variable */
+ if(t->tag == VariableTerm)
+ return;
+
+ t->clausenr = nr;
+ if(t->tag == CompoundTerm){
+ Term *child;
+ for(child = t->children; child != nil; child = child->next)
+ updateclausenr(child, nr);
+ }
+}
+
int
builtincall(Term *goal, Binding **bindings, Module *module)
{
@@ -238,6 +253,9 @@ builtincall(Term *goal, Binding **bindings, Module *module)
if(!canbecalled(callgoal))
Throw(typeerror(L"callable", callgoal));
+ updateclausenr(callgoal, clausenr);
+ clausenr++;
+
goalstack = addgoals(goalstack, callgoal, module);
return 1;
}