From 88841b194dc86c9392a813f9b8b0cf16857acb93 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 21 Jul 2021 00:12:09 +0000 Subject: 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 --- builtins.c | 18 ++++++++++++++++++ parser.c | 4 ++-- 2 files changed, 20 insertions(+), 2 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; } diff --git a/parser.c b/parser.c index 0a37a75..773a0a2 100644 --- a/parser.c +++ b/parser.c @@ -74,8 +74,8 @@ parse(int fd, Biobuf *bio, int querymode) Term *result = prologtext(querymode); if(querymode && result){ - uvlong id = 1; - result = copyterm(result, &id); + result = copyterm(result, &clausenr); + clausenr++; } if(!bio) Bterm(parsein); -- cgit v1.2.3