diff --git a/C/cdmgr.c b/C/cdmgr.c index f0165550d..c14a69ab0 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -120,7 +120,7 @@ bool Yap_Consulting(USES_REGS1) { * assertz are supported for static predicates no database predicates are * supportted for fast predicates */ -1 + /** Look for a predicate with same functor as t, create a new one of it cannot find it. */ diff --git a/C/exec.c b/C/exec.c index de5cc31b0..cfba1c0c7 100755 --- a/C/exec.c +++ b/C/exec.c @@ -151,6 +151,49 @@ Term Yap_ExecuteCallMetaCall(Term g, Term mod) { return Yap_MkApplTerm(PredMetaCall->FunctorOfPred, 4, ts); } +PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) { + Term t0 = t; + +restart: + if (IsVarTerm(t)) { + Yap_Error(INSTANTIATION_ERROR, t0, pname); + return NULL; + } else if (IsAtomTerm(t)) { + PredEntry *ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod)); + return ap; + } else if (IsIntegerTerm(t) && tmod == IDB_MODULE) { + return Yap_FindLUIntKey(IntegerOfTerm(t)); + } else if (IsPairTerm(t)) { + t = Yap_MkApplTerm(FunctorCsult, 1, &t); + goto restart; + } else if (IsApplTerm(t)) { + Functor fun = FunctorOfTerm(t); + if (IsExtensionFunctor(fun)) { + Yap_Error(TYPE_ERROR_CALLABLE, Yap_TermToIndicator(t, tmod), pname); + return NULL; + } + if (fun == FunctorModule) { + Term tmod = ArgOfTerm(1, t); + if (IsVarTerm(tmod)) { + Yap_Error(INSTANTIATION_ERROR, t0, pname); + return NULL; + } + if (!IsAtomTerm(tmod)) { + Yap_Error(TYPE_ERROR_ATOM, t0, pname); + return NULL; + } + t = ArgOfTerm(2, t); + goto restart; + } + PredEntry *ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod)); + return ap; + } else { + Yap_Error(TYPE_ERROR_CALLABLE, t0, pname); + } + return NULL; +} + + Term Yap_TermToIndicator(Term t, Term mod) { CACHE_REGS // generate predicate indicator in this case @@ -183,12 +226,12 @@ Term Yap_PredicateToIndicator(PredEntry *pe) { ti[0] = MkAtomTerm(NameOfFunctor(pe->FunctorOfPred)); ti[1] = MkIntegerTerm(ArityOfFunctor(pe->FunctorOfPred)); } else { - ti[0] = t; + ti[0] = MkAtomTerm((Atom)(pe->FunctorOfPred)); ti[1] = MkIntTerm(0); } - t = Yap_MkApplTerm(FunctorSlash, 2, ti); - Term mod - if (mod != TermUser and mod!= TermProlog) { + Term t = Yap_MkApplTerm(FunctorSlash, 2, ti); + Term mod = pe->ModuleOfPred; + if (mod != TermUser && mod!= PROLOG_MODULE) { ti[0] = mod; ti[1] = t; return Yap_MkApplTerm(FunctorModule, 2, ti); @@ -301,7 +344,7 @@ restart: } else if (IsIntegerTerm(t) && tmod == IDB_MODULE) { return Yap_FindLUIntKey(IntegerOfTerm(t)); } else if (IsApplTerm(t)) { - Functor fun = pe->FunctorOfPred; + Functor fun = FunctorOfTerm(t); if (IsExtensionFunctor(fun)) { Yap_Error(TYPE_ERROR_CALLABLE, Yap_TermToIndicator(t, tmod), pname); return NULL; diff --git a/C/index.c b/C/index.c index 0ae420a6f..03e9d41b0 100755 --- a/C/index.c +++ b/C/index.c @@ -4152,7 +4152,7 @@ restart_index: } #if DEBUG if (GLOBAL_Option['i' - 'a' + 1]) { - Yap_DebugWritexozoIndicator(ap); + Yap_DebugWriteIndicator(ap); } #endif if ((labp = expand_index(&cint)) == NULL) { diff --git a/C/stack.c b/C/stack.c index d393cde7e..3418c0ef1 100644 --- a/C/stack.c +++ b/C/stack.c @@ -90,7 +90,7 @@ static PredEntry *get_pred(Term t, Term tmod, char *pname) { } else if (IsApplTerm(t)) { Functor fun = FunctorOfTerm(t); if (IsExtensionFunctor(fun)) { - Yap_Error(TYPE_ERROR_CALLABLE, Yap_PredicateIndicator(t, tmod), pname); + Yap_Error(TYPE_ERROR_CALLABLE, Yap_TermToIndicator(t, tmod), pname); return NULL; } if (fun == FunctorModule) { diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 076c88054..fe3a3789c 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -82,7 +82,7 @@ restart: Functor fun = FunctorOfTerm(t); if (IsExtensionFunctor(fun)) { throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, - Yap_PredicateIndicator(t, tmod), pname); + Yap_TermToIndicator(t, tmod), pname); } if (fun == FunctorModule) { tmod = ArgOfTerm(1, t);