shithub: pprolog

Download patch

ref: 88841b194dc86c9392a813f9b8b0cf16857acb93
parent: 085e3595450d6652b62350621b470b26ae67b6de
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Tue Jul 20 20:12:09 EDT 2021

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

--- a/builtins.c
+++ b/builtins.c
@@ -229,6 +229,21 @@
 		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)
 {
@@ -237,6 +252,9 @@
 
 	if(!canbecalled(callgoal))
 		Throw(typeerror(L"callable", callgoal));
+
+	updateclausenr(callgoal, clausenr);
+	clausenr++;
 
 	goalstack = addgoals(goalstack, callgoal, module);
 	return 1;
--- a/parser.c
+++ b/parser.c
@@ -74,8 +74,8 @@
 
 	Term *result = prologtext(querymode);
 	if(querymode && result){
-		uvlong id = 1;
-		result = copyterm(result, &id);
+		result = copyterm(result, &clausenr);
+		clausenr++;
 	}
 	if(!bio)
 		Bterm(parsein);