2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
2016-01-03 01:26:09 +00:00
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: cdmgr.c *
|
|
|
|
* comments: Code manager *
|
|
|
|
* *
|
|
|
|
* Last rev: $Date: 2008-07-22 23:34:44 $,$Author: vsc $ 8
|
|
|
|
*************************************************************************/
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef SCCS
|
2015-10-22 00:53:26 +01:00
|
|
|
static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98";
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "clause.h"
|
2017-02-20 15:28:46 +00:00
|
|
|
#include "YapEval.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "tracer.h"
|
2016-03-29 01:55:12 +01:00
|
|
|
#include "yapio.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
#include "or.macros.h"
|
2015-10-22 00:53:26 +01:00
|
|
|
#endif /* YAPOR */
|
2006-03-20 19:51:44 +00:00
|
|
|
#ifdef TABLING
|
|
|
|
#include "tab.macros.h"
|
|
|
|
#endif /* TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2016-03-29 01:55:12 +01:00
|
|
|
#include <assert.h>
|
2015-08-07 22:57:53 +01:00
|
|
|
#include <heapgc.h>
|
2015-09-29 23:08:10 +01:00
|
|
|
#include <iopreds.h>
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2013-04-25 23:15:04 +01:00
|
|
|
static void retract_all(PredEntry *, int);
|
|
|
|
static void add_first_static(PredEntry *, yamop *, int);
|
|
|
|
static void add_first_dynamic(PredEntry *, yamop *, int);
|
|
|
|
static void asserta_stat_clause(PredEntry *, yamop *, int);
|
|
|
|
static void asserta_dynam_clause(PredEntry *, yamop *);
|
|
|
|
static void assertz_stat_clause(PredEntry *, yamop *, int);
|
|
|
|
static void assertz_dynam_clause(PredEntry *, yamop *);
|
2015-10-22 00:53:26 +01:00
|
|
|
static void expand_consult(void);
|
|
|
|
static int not_was_reconsulted(PredEntry *, Term, int);
|
|
|
|
static int RemoveIndexation(PredEntry *);
|
|
|
|
static Int p_number_of_clauses(USES_REGS1);
|
|
|
|
static Int p_compile(USES_REGS1);
|
|
|
|
static Int p_purge_clauses(USES_REGS1);
|
|
|
|
static Int p_setspy(USES_REGS1);
|
|
|
|
static Int p_rmspy(USES_REGS1);
|
|
|
|
static Int p_startconsult(USES_REGS1);
|
|
|
|
static Int p_showconslultlev(USES_REGS1);
|
|
|
|
static Int p_endconsult(USES_REGS1);
|
|
|
|
static Int p_undefined(USES_REGS1);
|
|
|
|
static Int p_new_multifile(USES_REGS1);
|
|
|
|
static Int p_is_multifile(USES_REGS1);
|
|
|
|
static Int p_optimizer_on(USES_REGS1);
|
|
|
|
static Int p_optimizer_off(USES_REGS1);
|
|
|
|
static Int p_is_dynamic(USES_REGS1);
|
|
|
|
static Int p_kill_dynamic(USES_REGS1);
|
|
|
|
static Int p_is_profiled(USES_REGS1);
|
|
|
|
static Int p_profile_info(USES_REGS1);
|
|
|
|
static Int p_profile_reset(USES_REGS1);
|
|
|
|
static Int p_is_call_counted(USES_REGS1);
|
|
|
|
static Int p_call_count_info(USES_REGS1);
|
|
|
|
static Int p_call_count_set(USES_REGS1);
|
|
|
|
static Int p_call_count_reset(USES_REGS1);
|
|
|
|
static void kill_first_log_iblock(LogUpdIndex *, LogUpdIndex *, PredEntry *);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define PredArity(p) (p->ArityOfPE)
|
2015-10-22 00:53:26 +01:00
|
|
|
#define TRYCODE(G, F, N) ((N) < 5 ? (op_numbers)((int)F + (N)*3) : G)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void InitConsultStack(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_ConsultLow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj) *
|
|
|
|
InitialConsultCapacity);
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_ConsultLow == NULL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "No Heap Space in InitCodes");
|
2010-03-21 22:12:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultCapacity = InitialConsultCapacity;
|
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp =
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_ConsultLow + LOCAL_ConsultCapacity;
|
2010-03-21 22:12:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_ResetConsultStack(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_FreeCodeSpace((char *)LOCAL_ConsultLow);
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp = LOCAL_ConsultLow = NULL;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultCapacity = InitialConsultCapacity;
|
2010-03-21 22:12:42 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
ADDING AND REMOVE INFO TO A PROCEDURE
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have three kinds of predicates: dynamic DynamicPredFlag
|
|
|
|
* static CompiledPredFlag fast FastPredFlag all the
|
|
|
|
* database predicates are supported for dynamic predicates only abolish and
|
|
|
|
* assertz are supported for static predicates no database predicates are
|
2015-04-13 13:28:17 +01:00
|
|
|
* supportted for fast predicates
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) {
|
2007-11-26 23:43:10 +00:00
|
|
|
Term t0 = t;
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
restart:
|
2007-11-26 23:43:10 +00:00
|
|
|
if (IsVarTerm(t)) {
|
2015-01-18 01:32:13 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t0, pname);
|
2007-11-26 23:43:10 +00:00
|
|
|
return NULL;
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
return RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod));
|
2008-09-15 04:30:09 +01:00
|
|
|
} else if (IsIntegerTerm(t) && tmod == IDB_MODULE) {
|
|
|
|
return Yap_FindLUIntKey(IntegerOfTerm(t));
|
2017-02-26 20:34:17 +00:00
|
|
|
} else if (IsPairTerm(t)) {
|
|
|
|
t = Yap_MkApplTerm(FunctorCsult, 1, &t);
|
|
|
|
goto restart;
|
2007-11-26 23:43:10 +00:00
|
|
|
} else if (IsApplTerm(t)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor fun = FunctorOfTerm(t);
|
2009-11-18 13:13:16 +00:00
|
|
|
if (IsExtensionFunctor(fun)) {
|
2015-01-18 01:32:13 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE, Yap_PredicateIndicator(t, tmod), pname);
|
2015-04-13 13:28:17 +01:00
|
|
|
return NULL;
|
2009-11-18 13:13:16 +00:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
if (fun == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1, t);
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t0, pname);
|
|
|
|
return NULL;
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!IsAtomTerm(tmod)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t0, pname);
|
|
|
|
return NULL;
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
t = ArgOfTerm(2, t);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
return RepPredProp(Yap_GetPredPropByFunc(fun, tmod));
|
2016-08-02 17:34:58 +01:00
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE, t0, pname);
|
|
|
|
}
|
|
|
|
return NULL;
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 05:15:11 +01:00
|
|
|
/** Look for a predicate with same functor as t,
|
|
|
|
create a new one of it cannot find it.
|
|
|
|
*/
|
|
|
|
static PredEntry *new_pred(Term t, Term tmod, char *pname) {
|
|
|
|
Term t0 = t;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t0, pname);
|
|
|
|
return NULL;
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
return RepPredProp(PredPropByAtom(AtomOfTerm(t), tmod));
|
|
|
|
} else if (IsIntegerTerm(t) && tmod == IDB_MODULE) {
|
|
|
|
return Yap_FindLUIntKey(IntegerOfTerm(t));
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
if (IsExtensionFunctor(fun)) {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE, Yap_PredicateIndicator(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;
|
|
|
|
}
|
|
|
|
return RepPredProp(PredPropByFunc(fun, tmod));
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
Mega Clauses
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
******************************************************************/
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
#define OrArgAdjust(P)
|
|
|
|
#define TabEntryAdjust(P)
|
2008-08-29 17:27:11 +01:00
|
|
|
#define DoubleInCodeAdjust(D)
|
|
|
|
#define IntegerInCodeAdjust(D)
|
2015-10-22 00:53:26 +01:00
|
|
|
#define IntegerAdjust(D) (D)
|
2005-01-04 02:50:23 +00:00
|
|
|
#define PtoPredAdjust(X) (X)
|
|
|
|
#define PtoOpAdjust(X) (X)
|
2006-10-10 15:08:17 +01:00
|
|
|
#define PtoLUClauseAdjust(P) (P)
|
2006-11-27 17:42:03 +00:00
|
|
|
#define PtoLUIndexAdjust(P) (P)
|
2005-01-04 02:50:23 +00:00
|
|
|
#define XAdjust(X) (X)
|
|
|
|
#define YAdjust(X) (X)
|
|
|
|
#define AtomTermAdjust(X) (X)
|
|
|
|
#define CellPtoHeapAdjust(X) (X)
|
|
|
|
#define FuncAdjust(X) (X)
|
|
|
|
#define CodeAddrAdjust(X) (X)
|
2008-04-01 09:42:46 +01:00
|
|
|
#define CodeComposedTermAdjust(X) (X)
|
2008-08-29 17:27:11 +01:00
|
|
|
#define ConstantAdjust(X) (X)
|
|
|
|
#define ArityAdjust(X) (X)
|
|
|
|
#define OpcodeAdjust(X) (X)
|
|
|
|
#define ModuleAdjust(X) (X)
|
|
|
|
#define ExternalFunctionAdjust(X) (X)
|
2015-10-22 00:53:26 +01:00
|
|
|
#define AdjustSwitchTable(X, Y, Z)
|
|
|
|
#define DBGroundTermAdjust(X) (X)
|
|
|
|
#define rehash(A, B, C)
|
2010-12-16 20:39:53 +00:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Term BlobTermInCodeAdjust(Term t) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2005-01-04 02:50:23 +00:00
|
|
|
#if TAGS_FAST_OPS
|
2015-10-22 00:53:26 +01:00
|
|
|
return t - LOCAL_ClDiff;
|
2005-01-04 02:50:23 +00:00
|
|
|
#else
|
2015-10-22 00:53:26 +01:00
|
|
|
return t + LOCAL_ClDiff;
|
2005-01-04 02:50:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Term ConstantTermAdjust(Term t) {
|
2008-08-29 17:27:11 +01:00
|
|
|
if (IsAtomTerm(t))
|
|
|
|
return AtomTermAdjust(t);
|
2010-12-16 20:39:53 +00:00
|
|
|
return t;
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
|
|
|
|
2005-01-04 02:50:23 +00:00
|
|
|
#include "rclause.h"
|
|
|
|
|
2006-09-20 21:03:51 +01:00
|
|
|
#ifdef DEBUG
|
2015-10-22 00:53:26 +01:00
|
|
|
static UInt total_megaclause, total_released, nof_megaclauses;
|
2006-09-20 21:03:51 +01:00
|
|
|
#endif
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_BuildMegaClause(PredEntry *ap) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2004-09-27 21:45:04 +01:00
|
|
|
StaticClause *cl;
|
|
|
|
UInt sz;
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *ptr;
|
2012-12-14 19:35:26 +00:00
|
|
|
size_t required;
|
2004-09-27 21:45:04 +01:00
|
|
|
UInt has_blobs = 0;
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (ap->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MegaClausePredFlag
|
2004-09-27 21:45:04 +01:00
|
|
|
#ifdef TABLING
|
2015-10-22 00:53:26 +01:00
|
|
|
| TabledPredFlag
|
2005-08-01 16:40:39 +01:00
|
|
|
#endif /* TABLING */
|
2015-10-22 00:53:26 +01:00
|
|
|
| UDIPredFlag) ||
|
|
|
|
ap->cs.p_code.FirstClause == NULL || ap->cs.p_code.NOfClauses < 16) {
|
2004-09-27 21:45:04 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
2004-09-27 21:45:04 +01:00
|
|
|
sz = cl->ClSize;
|
|
|
|
while (TRUE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!(cl->ClFlags & FactMask))
|
|
|
|
return; /* no mega clause, sorry */
|
|
|
|
if (cl->ClSize != sz)
|
|
|
|
return; /* no mega clause, sorry */
|
2004-09-27 21:45:04 +01:00
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
has_blobs |= (cl->ClFlags & HasBlobsMask);
|
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
|
|
|
/* ok, we got the chance for a mega clause */
|
|
|
|
if (has_blobs) {
|
|
|
|
sz -= sizeof(StaticClause);
|
2005-01-04 02:50:23 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
sz -= (UInt)NEXTOP((yamop *)NULL, p) + sizeof(StaticClause);
|
2005-01-04 02:50:23 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
required = sz * ap->cs.p_code.NOfClauses + sizeof(MegaClause) +
|
|
|
|
(UInt)NEXTOP((yamop *)NULL, l);
|
2012-12-14 19:35:26 +00:00
|
|
|
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
|
|
|
|
if (!Yap_growheap(FALSE, required, NULL)) {
|
|
|
|
/* just fail, the system will keep on going */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-09-20 21:03:51 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
total_megaclause += required;
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
|
|
|
total_released += ap->cs.p_code.NOfClauses * cl->ClSize;
|
2006-09-20 21:03:51 +01:00
|
|
|
nof_megaclauses++;
|
|
|
|
#endif
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += required;
|
2004-09-27 21:45:04 +01:00
|
|
|
/* cool, it's our turn to do the conversion */
|
|
|
|
mcl->ClFlags = MegaMask | has_blobs;
|
2011-09-01 05:13:29 +01:00
|
|
|
mcl->ClSize = required;
|
2004-09-27 21:45:04 +01:00
|
|
|
mcl->ClPred = ap;
|
|
|
|
mcl->ClItemSize = sz;
|
2006-03-22 20:07:28 +00:00
|
|
|
mcl->ClNext = NULL;
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
2013-11-05 17:59:19 +00:00
|
|
|
mcl->ClLine = cl->usc.ClLine;
|
2004-09-27 21:45:04 +01:00
|
|
|
ptr = mcl->ClCode;
|
|
|
|
while (TRUE) {
|
|
|
|
memcpy((void *)ptr, (void *)cl->ClCode, sz);
|
2005-01-04 02:50:23 +00:00
|
|
|
if (has_blobs) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_ClDiff = (char *)(ptr) - (char *)cl->ClCode;
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(ptr, NULL PASS_REGS);
|
2005-01-04 02:50:23 +00:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
ptr = (yamop *)((char *)ptr + sz);
|
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
|
|
|
ptr->opc = Yap_opcode(_Ystop);
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
2004-09-27 21:45:04 +01:00
|
|
|
/* recover the space spent on the original clauses */
|
|
|
|
while (TRUE) {
|
2005-12-23 00:20:14 +00:00
|
|
|
StaticClause *ncl, *curcl = cl;
|
2004-09-27 21:45:04 +01:00
|
|
|
|
|
|
|
ncl = cl->ClNext;
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)cl);
|
2005-12-23 00:20:14 +00:00
|
|
|
if (curcl->ClCode == ap->cs.p_code.LastClause)
|
2004-09-27 21:45:04 +01:00
|
|
|
break;
|
|
|
|
cl = ncl;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->cs.p_code.FirstClause = ap->cs.p_code.LastClause = mcl->ClCode;
|
2013-09-28 18:20:04 +01:00
|
|
|
ap->PredFlags |= MegaClausePredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_inform_profiler_of_clause(mcl, (char *)mcl + required, ap, GPROF_MEGA);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void split_megaclause(PredEntry *ap) {
|
2004-09-27 21:45:04 +01:00
|
|
|
StaticClause *start = NULL, *prev = NULL;
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *ptr;
|
|
|
|
UInt ncls = ap->cs.p_code.NOfClauses, i;
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
|
2013-01-14 09:48:05 +00:00
|
|
|
if (mcl->ClFlags & ExoMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, TermNil,
|
|
|
|
"while deleting clause from exo predicate %s/%d\n",
|
|
|
|
RepAtom(NameOfFunctor(ap->FunctorOfPred))->StrOfAE,
|
|
|
|
ap->ArityOfPE);
|
2013-01-14 09:48:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
RemoveIndexation(ap);
|
2004-09-27 21:45:04 +01:00
|
|
|
for (i = 0, ptr = mcl->ClCode; i < ncls; i++) {
|
2015-10-22 00:53:26 +01:00
|
|
|
StaticClause *new = (StaticClause *)Yap_AllocCodeSpace(
|
|
|
|
sizeof(StaticClause) + mcl->ClItemSize +
|
|
|
|
(UInt)NEXTOP((yamop *)NULL, p));
|
2004-09-27 21:45:04 +01:00
|
|
|
if (new == NULL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_growheap(FALSE,
|
|
|
|
(sizeof(StaticClause) + mcl->ClItemSize) * (ncls - i),
|
|
|
|
NULL)) {
|
|
|
|
while (start) {
|
|
|
|
StaticClause *cl = start;
|
|
|
|
start = cl->ClNext;
|
|
|
|
Yap_InformOfRemoval(cl);
|
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
|
|
|
if (ap->ArityOfPE) {
|
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
|
|
|
|
"while breaking up mega clause for %s/%d\n",
|
|
|
|
RepAtom(NameOfFunctor(ap->FunctorOfPred))->StrOfAE,
|
|
|
|
ap->ArityOfPE);
|
|
|
|
} else {
|
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
|
|
|
|
"while breaking up mega clause for %s\n",
|
|
|
|
RepAtom((Atom)ap->FunctorOfPred)->StrOfAE);
|
|
|
|
}
|
|
|
|
return;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2010-12-31 05:37:25 +00:00
|
|
|
break;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_ClauseSpace +=
|
|
|
|
sizeof(StaticClause) + mcl->ClItemSize + (UInt)NEXTOP((yamop *)NULL, p);
|
|
|
|
new->ClFlags = StaticMask | FactMask;
|
2004-10-22 17:53:20 +01:00
|
|
|
new->ClSize = mcl->ClItemSize;
|
2013-11-05 17:59:19 +00:00
|
|
|
new->usc.ClLine = Yap_source_line_no();
|
2004-10-22 17:53:20 +01:00
|
|
|
new->ClNext = NULL;
|
|
|
|
memcpy((void *)new->ClCode, (void *)ptr, mcl->ClItemSize);
|
|
|
|
if (prev) {
|
|
|
|
prev->ClNext = new;
|
|
|
|
} else {
|
|
|
|
start = new;
|
|
|
|
}
|
|
|
|
ptr = (yamop *)((char *)ptr + mcl->ClItemSize);
|
|
|
|
prev = new;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
ap->PredFlags &= ~MegaClausePredFlag;
|
|
|
|
ap->cs.p_code.FirstClause = start->ClCode;
|
|
|
|
ap->cs.p_code.LastClause = prev->ClCode;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
Indexation Info
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
******************************************************************/
|
2015-10-22 00:53:26 +01:00
|
|
|
#define ByteAdr(X) ((Int) & (X))
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* Index a prolog pred, given its predicate entry */
|
2003-12-01 17:27:42 +00:00
|
|
|
/* ap is already locked. */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void IPred(PredEntry *ap, UInt NSlots, yamop *next_pc) {
|
|
|
|
yamop *BaseAddr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-03-07 16:34:20 +00:00
|
|
|
CACHE_REGS
|
2011-05-25 16:40:36 +01:00
|
|
|
if (GLOBAL_Option['i' - 'a' + 1]) {
|
2004-02-12 12:37:12 +00:00
|
|
|
Term tmod = ap->ModuleOfPred;
|
|
|
|
if (!tmod)
|
|
|
|
tmod = TermProlog;
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DebugPutc(stderr, '\t');
|
2009-05-22 19:24:27 +01:00
|
|
|
Yap_DebugPlWrite(tmod);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DebugPutc(stderr, ':');
|
2004-02-12 12:37:12 +00:00
|
|
|
if (ap->ModuleOfPred == IDB_MODULE) {
|
2003-08-27 14:37:10 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
if (IsAtomTerm(t)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DebugPlWrite(t);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else if (IsIntegerTerm(t)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DebugPlWrite(t);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
Atom At = NameOfFunctor(f);
|
|
|
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
|
|
|
Yap_DebugPutc(stderr, '/');
|
|
|
|
Yap_DebugPlWrite(MkIntTerm(ArityOfFunctor(f)));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ap->ArityOfPE == 0) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Atom At = (Atom)ap->FunctorOfPred;
|
|
|
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor f = ap->FunctorOfPred;
|
|
|
|
Atom At = NameOfFunctor(f);
|
|
|
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
|
|
|
Yap_DebugPutc(stderr, '/');
|
|
|
|
Yap_DebugPlWrite(MkIntTerm(ArityOfFunctor(f)));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DebugPutc(stderr, '\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Do not try to index a dynamic predicate or one whithout args */
|
|
|
|
if (is_dynamic(ap)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
|
|
|
"trying to index a dynamic predicate");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-01-29 15:21:00 +00:00
|
|
|
if ((BaseAddr = Yap_PredIsIndexable(ap, NSlots, next_pc)) != NULL) {
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = BaseAddr;
|
2001-04-09 20:54:03 +01:00
|
|
|
ap->PredFlags |= IndexedPredFlag;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (ap->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
2016-07-31 05:15:11 +01:00
|
|
|
if (ap->PredFlags & ProfiledPredFlag) {
|
2016-05-13 11:41:19 +01:00
|
|
|
Yap_initProfiler(ap);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
} else if (ap->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(ap->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
ap->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->OpcodeOfPred = ap->CodeOfPred->opc;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2011-05-25 16:40:36 +01:00
|
|
|
if (GLOBAL_Option['i' - 'a' + 1])
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DebugPutc(stderr, '\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_IPred(PredEntry *p, UInt NSlots, yamop *next_pc) {
|
2010-01-29 15:21:00 +00:00
|
|
|
IPred(p, NSlots, next_pc);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
#define GONEXT(TYPE) code_p = ((yamop *)(&(code_p->y_u.TYPE.next)))
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void RemoveMainIndex(PredEntry *ap) {
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *First = ap->cs.p_code.FirstClause;
|
2015-10-22 00:53:26 +01:00
|
|
|
int spied =
|
|
|
|
ap->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2003-10-14 01:53:10 +01:00
|
|
|
ap->PredFlags &= ~IndexedPredFlag;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (First == NULL) {
|
|
|
|
ap->cs.p_code.TrueCodeOfPred = FAILCODE;
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = First;
|
|
|
|
}
|
|
|
|
if (First != NULL && spied) {
|
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2003-12-18 16:38:40 +00:00
|
|
|
} else if (ap->cs.p_code.NOfClauses > 1
|
|
|
|
#ifdef TABLING
|
2015-10-22 00:53:26 +01:00
|
|
|
|| ap->PredFlags & TabledPredFlag
|
2005-08-01 16:40:39 +01:00
|
|
|
#endif /* TABLING */
|
2015-10-22 00:53:26 +01:00
|
|
|
) {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
(yamop *)(&(ap->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->OpcodeOfPred = ap->cs.p_code.TrueCodeOfPred->opc;
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (ap->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(ap->PredFlags & ThreadLocalPredFlag) &&
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->ModuleOfPred != IDB_MODULE) {
|
|
|
|
ap->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void decrease_ref_counter(yamop *ptr, yamop *b, yamop *e, yamop *sc) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ptr != FAILCODE && ptr != sc && (ptr < b || ptr > e)) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(ptr);
|
|
|
|
cl->ClRefCount--;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (cl->ClFlags & ErasedMask && !(cl->ClRefCount) &&
|
|
|
|
!(cl->ClFlags & InUseMask)) {
|
2003-11-12 12:33:31 +00:00
|
|
|
/* last ref to the clause */
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static yamop *release_wcls(yamop *cop, OPCODE ecs) {
|
2004-04-27 16:03:43 +01:00
|
|
|
if (cop->opc == ecs) {
|
2014-05-30 01:06:09 +01:00
|
|
|
cop->y_u.sssllp.s3--;
|
|
|
|
if (!cop->y_u.sssllp.s3) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UInt sz = (UInt)NEXTOP((yamop *)NULL, sssllp) +
|
|
|
|
cop->y_u.sssllp.s1 * sizeof(yamop *);
|
2008-01-23 17:57:56 +00:00
|
|
|
LOCK(ExpandClausesListLock);
|
|
|
|
#ifdef DEBUG
|
|
|
|
Yap_expand_clauses_sz -= sz;
|
|
|
|
Yap_ExpandClauses--;
|
2004-09-03 04:11:09 +01:00
|
|
|
#endif
|
2014-05-30 01:06:09 +01:00
|
|
|
if (cop->y_u.sssllp.p->PredFlags & LogUpdatePredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_LUIndexSpace_EXT -= sz;
|
2006-11-06 18:35:05 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_IndexSpace_EXT -= sz;
|
2008-01-23 17:57:56 +00:00
|
|
|
}
|
|
|
|
if (ExpandClausesFirst == cop)
|
2015-10-22 00:53:26 +01:00
|
|
|
ExpandClausesFirst = cop->y_u.sssllp.snext;
|
2008-01-23 17:57:56 +00:00
|
|
|
if (ExpandClausesLast == cop) {
|
2015-10-22 00:53:26 +01:00
|
|
|
ExpandClausesLast = cop->y_u.sssllp.sprev;
|
2008-01-23 17:57:56 +00:00
|
|
|
}
|
2014-05-30 01:06:09 +01:00
|
|
|
if (cop->y_u.sssllp.sprev) {
|
2015-10-22 00:53:26 +01:00
|
|
|
cop->y_u.sssllp.sprev->y_u.sssllp.snext = cop->y_u.sssllp.snext;
|
2006-11-06 18:35:05 +00:00
|
|
|
}
|
2014-05-30 01:06:09 +01:00
|
|
|
if (cop->y_u.sssllp.snext) {
|
2015-10-22 00:53:26 +01:00
|
|
|
cop->y_u.sssllp.snext->y_u.sssllp.sprev = cop->y_u.sssllp.sprev;
|
2008-01-23 17:57:56 +00:00
|
|
|
}
|
|
|
|
UNLOCK(ExpandClausesListLock);
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cop);
|
2004-04-27 16:03:43 +01:00
|
|
|
Yap_FreeCodeSpace((char *)cop);
|
|
|
|
}
|
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
return FAILCODE;
|
2004-04-27 16:03:43 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end,
|
|
|
|
yamop *suspend_code) {
|
2004-04-27 16:03:43 +01:00
|
|
|
OPCODE ecs = Yap_opcode(_expand_clauses);
|
|
|
|
|
2006-10-11 15:53:57 +01:00
|
|
|
while (ipc) {
|
2003-08-27 14:37:10 +01:00
|
|
|
op_numbers op = Yap_op_from_opcode(ipc->opc);
|
2006-10-16 18:12:48 +01:00
|
|
|
/* fprintf(stderr,"op: %d %p->%p\n", op, ipc, end);*/
|
2015-10-22 00:53:26 +01:00
|
|
|
switch (op) {
|
2003-08-27 14:37:10 +01:00
|
|
|
case _Ystop:
|
|
|
|
/* end of clause, for now */
|
|
|
|
return;
|
|
|
|
case _index_dbref:
|
|
|
|
case _index_blob:
|
2009-02-09 21:56:40 +00:00
|
|
|
case _index_long:
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, e);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
2004-02-05 16:57:02 +00:00
|
|
|
case _lock_lu:
|
2004-02-09 14:19:05 +00:00
|
|
|
case _unlock_lu:
|
2008-01-23 17:57:56 +00:00
|
|
|
/* locking should be done already */
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, e);
|
2003-08-27 14:37:10 +01:00
|
|
|
case _retry_profiled:
|
|
|
|
case _count_retry:
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, p);
|
2003-10-28 16:20:44 +00:00
|
|
|
break;
|
2004-09-27 21:45:04 +01:00
|
|
|
case _try_clause2:
|
|
|
|
case _try_clause3:
|
|
|
|
case _try_clause4:
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, l);
|
2004-09-27 21:45:04 +01:00
|
|
|
break;
|
|
|
|
case _retry2:
|
|
|
|
case _retry3:
|
|
|
|
case _retry4:
|
2014-05-30 01:06:09 +01:00
|
|
|
decrease_ref_counter(ipc->y_u.l.l, beg, end, suspend_code);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, l);
|
2004-09-27 21:45:04 +01:00
|
|
|
break;
|
2003-10-28 16:20:44 +00:00
|
|
|
case _retry:
|
2003-08-27 14:37:10 +01:00
|
|
|
case _trust:
|
2014-05-30 01:06:09 +01:00
|
|
|
decrease_ref_counter(ipc->y_u.Otapl.d, beg, end, suspend_code);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, Otapl);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _try_clause:
|
|
|
|
case _try_me:
|
|
|
|
case _retry_me:
|
|
|
|
case _profiled_trust_me:
|
|
|
|
case _trust_me:
|
|
|
|
case _count_trust_me:
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, Otapl);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
2006-10-10 15:08:17 +01:00
|
|
|
case _try_logical:
|
|
|
|
case _retry_logical:
|
|
|
|
case _count_retry_logical:
|
2015-10-22 00:53:26 +01:00
|
|
|
case _profiled_retry_logical: {
|
|
|
|
yamop *oipc = ipc;
|
|
|
|
decrease_ref_counter(ipc->y_u.OtaLl.d->ClCode, beg, end, suspend_code);
|
|
|
|
ipc = ipc->y_u.OtaLl.n;
|
|
|
|
Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL, OtaLl);
|
|
|
|
Yap_FreeCodeSpace((ADDR)oipc);
|
2006-10-11 15:53:57 +01:00
|
|
|
#ifdef DEBUG
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DirtyCps--;
|
|
|
|
Yap_FreedCps++;
|
2006-10-11 15:53:57 +01:00
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
} break;
|
2006-10-10 15:08:17 +01:00
|
|
|
case _trust_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_trust_logical:
|
2006-10-11 15:53:57 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
Yap_DirtyCps--;
|
|
|
|
Yap_FreedCps++;
|
|
|
|
#endif
|
2014-05-30 01:06:09 +01:00
|
|
|
decrease_ref_counter(ipc->y_u.OtILl.d->ClCode, beg, end, suspend_code);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL, OtILl);
|
2006-10-10 15:08:17 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)ipc);
|
|
|
|
return;
|
2015-10-22 00:53:26 +01:00
|
|
|
case _enter_lu_pred: {
|
|
|
|
yamop *oipc = ipc;
|
|
|
|
if (ipc->y_u.Illss.I->ClFlags & InUseMask || ipc->y_u.Illss.I->ClRefCount)
|
|
|
|
return;
|
2006-10-11 15:53:57 +01:00
|
|
|
#ifdef DEBUG
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_DirtyCps += ipc->y_u.Illss.s;
|
|
|
|
Yap_LiveCps -= ipc->y_u.Illss.s;
|
2006-10-11 15:53:57 +01:00
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = ipc->y_u.Illss.l1;
|
|
|
|
/* in case we visit again */
|
|
|
|
oipc->y_u.Illss.l1 = FAILCODE;
|
|
|
|
oipc->y_u.Illss.s = 0;
|
|
|
|
oipc->y_u.Illss.e = 0;
|
|
|
|
} break;
|
2003-08-27 14:37:10 +01:00
|
|
|
case _try_in:
|
|
|
|
case _jump:
|
|
|
|
case _jump_if_var:
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.l.l = release_wcls(ipc->y_u.l.l, ecs);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, l);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
2015-10-22 00:53:26 +01:00
|
|
|
/* instructions type xl */
|
2003-10-28 01:16:03 +00:00
|
|
|
case _jump_if_nonvar:
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.xll.l1 = release_wcls(ipc->y_u.xll.l1, ecs);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, xll);
|
2003-10-28 01:16:03 +00:00
|
|
|
break;
|
2015-10-22 00:53:26 +01:00
|
|
|
/* instructions type p */
|
2009-02-12 21:35:31 +00:00
|
|
|
case _user_switch:
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, lp);
|
2009-02-12 21:35:31 +00:00
|
|
|
break;
|
2015-10-22 00:53:26 +01:00
|
|
|
/* instructions type e */
|
2003-08-27 14:37:10 +01:00
|
|
|
case _switch_on_type:
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.llll.l1 = release_wcls(ipc->y_u.llll.l1, ecs);
|
|
|
|
ipc->y_u.llll.l2 = release_wcls(ipc->y_u.llll.l2, ecs);
|
|
|
|
ipc->y_u.llll.l3 = release_wcls(ipc->y_u.llll.l3, ecs);
|
|
|
|
ipc->y_u.llll.l4 = release_wcls(ipc->y_u.llll.l4, ecs);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, llll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _switch_list_nl:
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.ollll.l1 = release_wcls(ipc->y_u.ollll.l1, ecs);
|
|
|
|
ipc->y_u.ollll.l2 = release_wcls(ipc->y_u.ollll.l2, ecs);
|
|
|
|
ipc->y_u.ollll.l3 = release_wcls(ipc->y_u.ollll.l3, ecs);
|
|
|
|
ipc->y_u.ollll.l4 = release_wcls(ipc->y_u.ollll.l4, ecs);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, ollll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _switch_on_arg_type:
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.xllll.l1 = release_wcls(ipc->y_u.xllll.l1, ecs);
|
|
|
|
ipc->y_u.xllll.l2 = release_wcls(ipc->y_u.xllll.l2, ecs);
|
|
|
|
ipc->y_u.xllll.l3 = release_wcls(ipc->y_u.xllll.l3, ecs);
|
|
|
|
ipc->y_u.xllll.l4 = release_wcls(ipc->y_u.xllll.l4, ecs);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, xllll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _switch_on_sub_arg_type:
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.sllll.l1 = release_wcls(ipc->y_u.sllll.l1, ecs);
|
|
|
|
ipc->y_u.sllll.l2 = release_wcls(ipc->y_u.sllll.l2, ecs);
|
|
|
|
ipc->y_u.sllll.l3 = release_wcls(ipc->y_u.sllll.l3, ecs);
|
|
|
|
ipc->y_u.sllll.l4 = release_wcls(ipc->y_u.sllll.l4, ecs);
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, sllll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _if_not_then:
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, clll);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
|
|
|
case _switch_on_func:
|
|
|
|
case _if_func:
|
|
|
|
case _go_on_func:
|
|
|
|
case _switch_on_cons:
|
|
|
|
case _if_cons:
|
|
|
|
case _go_on_cons:
|
2015-10-22 00:53:26 +01:00
|
|
|
/* make sure we don't leave dangling references to memory that is going to
|
|
|
|
* be removed */
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.sssl.l = NULL;
|
2015-10-22 00:53:26 +01:00
|
|
|
ipc = NEXTOP(ipc, sssl);
|
2003-08-27 14:37:10 +01:00
|
|
|
break;
|
2008-01-23 17:57:56 +00:00
|
|
|
case _op_fail:
|
|
|
|
return;
|
2003-08-27 14:37:10 +01:00
|
|
|
default:
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
|
|
|
"Bug in Indexing Code: opcode %d", op);
|
2004-09-27 21:45:04 +01:00
|
|
|
return;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
ipc = (yamop *)((CELL)ipc & ~1);
|
2015-04-13 13:28:17 +01:00
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void decrease_log_indices(LogUpdIndex *c, yamop *suspend_code) {
|
2003-11-12 12:33:31 +00:00
|
|
|
/* decrease all reference counters */
|
|
|
|
yamop *beg = c->ClCode, *end, *ipc;
|
2011-12-30 16:02:59 +00:00
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
if (c->ClFlags & SwitchTableMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
CELL *end = (CELL *)((char *)c + c->ClSize);
|
2004-03-31 02:03:10 +01:00
|
|
|
CELL *beg = (CELL *)(c->ClCode);
|
|
|
|
OPCODE ecs = Yap_opcode(_expand_clauses);
|
|
|
|
|
|
|
|
while (beg < end) {
|
2015-10-22 00:53:26 +01:00
|
|
|
yamop **x = (yamop **)(beg + 1);
|
2004-03-31 02:03:10 +01:00
|
|
|
beg += 2;
|
2008-01-23 17:57:56 +00:00
|
|
|
*x = release_wcls(*x, ecs);
|
2004-03-31 02:03:10 +01:00
|
|
|
}
|
2003-11-12 12:33:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
end = (yamop *)((CODEADDR)c + c->ClSize);
|
2003-11-12 12:33:31 +00:00
|
|
|
ipc = beg;
|
|
|
|
cleanup_dangling_indices(ipc, beg, end, suspend_code);
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void kill_static_child_indxs(StaticIndex *indx, int in_use) {
|
2003-08-27 14:37:10 +01:00
|
|
|
StaticIndex *cl = indx->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
StaticIndex *next = cl->SiblingIndex;
|
2006-03-22 20:07:28 +00:00
|
|
|
kill_static_child_indxs(cl, in_use);
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = next;
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
if (in_use) {
|
|
|
|
LOCK(DeadStaticIndicesLock);
|
|
|
|
indx->SiblingIndex = DeadStaticIndices;
|
|
|
|
indx->ChildIndex = NULL;
|
|
|
|
DeadStaticIndices = indx;
|
|
|
|
UNLOCK(DeadStaticIndicesLock);
|
2006-03-22 16:14:20 +00:00
|
|
|
} else {
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(indx);
|
2006-11-06 18:35:05 +00:00
|
|
|
if (indx->ClFlags & SwitchTableMask)
|
|
|
|
Yap_IndexSpace_SW -= indx->ClSize;
|
|
|
|
else
|
|
|
|
Yap_IndexSpace_Tree -= indx->ClSize;
|
2006-03-22 16:14:20 +00:00
|
|
|
Yap_FreeCodeSpace((char *)indx);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void kill_children(LogUpdIndex *c, PredEntry *ap) {
|
2006-03-20 19:51:44 +00:00
|
|
|
LogUpdIndex *ncl;
|
|
|
|
|
|
|
|
c->ClRefCount++;
|
|
|
|
ncl = c->ChildIndex;
|
|
|
|
/* kill children */
|
|
|
|
while (ncl) {
|
|
|
|
kill_first_log_iblock(ncl, c, ap);
|
|
|
|
ncl = c->ChildIndex;
|
|
|
|
}
|
|
|
|
c->ClRefCount--;
|
|
|
|
}
|
|
|
|
|
2006-03-24 16:26:31 +00:00
|
|
|
/* assumes c is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void kill_off_lu_block(LogUpdIndex *c, LogUpdIndex *parent,
|
|
|
|
PredEntry *ap) {
|
2006-03-20 19:51:44 +00:00
|
|
|
/* first, make sure that I killed off all my children, some children may
|
|
|
|
remain in case I have tables as children */
|
2004-03-19 11:35:42 +00:00
|
|
|
if (parent != NULL) {
|
|
|
|
/* sat bye bye */
|
|
|
|
/* decrease refs */
|
|
|
|
parent->ClRefCount--;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (parent->ClFlags & ErasedMask && !(parent->ClFlags & InUseMask) &&
|
|
|
|
parent->ClRefCount == 0) {
|
2004-03-19 11:35:42 +00:00
|
|
|
/* cool, I can erase the father too. */
|
|
|
|
if (parent->ClFlags & SwitchRootMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
kill_off_lu_block(parent, NULL, ap);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
kill_off_lu_block(parent, parent->ParentIndex, ap);
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
decrease_log_indices(c, (yamop *)&(ap->cs.p_code.ExpandCode));
|
|
|
|
/* remove from list */
|
|
|
|
if (c->SiblingIndex)
|
|
|
|
c->SiblingIndex->PrevSiblingIndex = c->PrevSiblingIndex;
|
|
|
|
if (c->PrevSiblingIndex) {
|
|
|
|
c->PrevSiblingIndex->SiblingIndex = c->SiblingIndex;
|
|
|
|
} else {
|
|
|
|
DBErasedIList = c->SiblingIndex;
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(c);
|
2006-11-06 18:35:05 +00:00
|
|
|
if (c->ClFlags & SwitchTableMask)
|
|
|
|
Yap_LUIndexSpace_SW -= c->ClSize;
|
|
|
|
else {
|
|
|
|
Yap_LUIndexSpace_Tree -= c->ClSize;
|
|
|
|
}
|
2005-07-06 16:10:18 +01:00
|
|
|
Yap_FreeCodeSpace((char *)c);
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void kill_first_log_iblock(LogUpdIndex *c, LogUpdIndex *parent,
|
|
|
|
PredEntry *ap) {
|
2004-02-19 19:24:46 +00:00
|
|
|
/* parent is always locked, now I lock myself */
|
2004-02-20 02:28:19 +00:00
|
|
|
if (parent != NULL) {
|
2004-02-19 19:24:46 +00:00
|
|
|
/* remove myself from parent */
|
2003-11-24 00:00:43 +00:00
|
|
|
if (c == parent->ChildIndex) {
|
|
|
|
parent->ChildIndex = c->SiblingIndex;
|
2005-05-31 20:42:28 +01:00
|
|
|
if (parent->ChildIndex) {
|
2015-10-22 00:53:26 +01:00
|
|
|
parent->ChildIndex->PrevSiblingIndex = NULL;
|
2005-05-31 20:42:28 +01:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
c->PrevSiblingIndex->SiblingIndex = c->SiblingIndex;
|
2005-05-31 20:42:28 +01:00
|
|
|
if (c->SiblingIndex) {
|
2015-10-22 00:53:26 +01:00
|
|
|
c->SiblingIndex->PrevSiblingIndex = c->PrevSiblingIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
} else {
|
|
|
|
/* I am top node */
|
|
|
|
if (ap->cs.p_code.TrueCodeOfPred == c->ClCode) {
|
|
|
|
RemoveMainIndex(ap);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2008-01-23 17:57:56 +00:00
|
|
|
decrease_log_indices(c, (yamop *)&(ap->cs.p_code.ExpandCode));
|
2003-10-30 11:31:05 +00:00
|
|
|
/* make sure that a child cannot remove us */
|
2006-03-20 19:51:44 +00:00
|
|
|
kill_children(c, ap);
|
2003-10-14 02:32:55 +01:00
|
|
|
/* check if we are still the main index */
|
2008-01-23 17:57:56 +00:00
|
|
|
/* always add to erased list */
|
|
|
|
c->SiblingIndex = DBErasedIList;
|
|
|
|
c->PrevSiblingIndex = NULL;
|
|
|
|
if (DBErasedIList)
|
|
|
|
DBErasedIList->PrevSiblingIndex = c;
|
|
|
|
DBErasedIList = c;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (!((c->ClFlags & InUseMask) || c->ClRefCount)) {
|
2004-03-19 11:35:42 +00:00
|
|
|
kill_off_lu_block(c, parent, ap);
|
2003-10-14 01:53:10 +01:00
|
|
|
} else {
|
2004-03-19 11:35:42 +00:00
|
|
|
if (c->ClFlags & ErasedMask)
|
|
|
|
return;
|
2003-10-30 11:31:05 +00:00
|
|
|
c->ClFlags |= ErasedMask;
|
2004-02-20 02:28:19 +00:00
|
|
|
/* try to move up, so that we don't hold a switch table */
|
2015-10-22 00:53:26 +01:00
|
|
|
if (parent != NULL && parent->ClFlags & SwitchTableMask) {
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2005-12-17 03:25:39 +00:00
|
|
|
c->ParentIndex = parent->ParentIndex;
|
|
|
|
parent->ParentIndex->ClRefCount++;
|
2003-11-24 00:00:43 +00:00
|
|
|
parent->ClRefCount--;
|
2003-10-31 00:20:52 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void kill_top_static_iblock(StaticIndex *c, PredEntry *ap) {
|
2015-09-21 23:05:36 +01:00
|
|
|
kill_static_child_indxs(c, Yap_static_in_use(ap, TRUE));
|
2003-08-27 14:37:10 +01:00
|
|
|
RemoveMainIndex(ap);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_kill_iblock(ClauseUnion *blk, ClauseUnion *parent_blk, PredEntry *ap) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ap->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdIndex *c = (LogUpdIndex *)blk;
|
|
|
|
if (parent_blk != NULL) {
|
|
|
|
LogUpdIndex *cl = (LogUpdIndex *)parent_blk;
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
cl->ClRefCount++;
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
kill_first_log_iblock(c, cl, ap);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
cl->ClRefCount--;
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
|
|
|
kill_first_log_iblock(c, NULL, ap);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StaticIndex *c = (StaticIndex *)blk;
|
|
|
|
if (parent_blk != NULL) {
|
|
|
|
StaticIndex *cl = parent_blk->si.ChildIndex;
|
|
|
|
if (cl == c) {
|
2015-10-22 00:53:26 +01:00
|
|
|
parent_blk->si.ChildIndex = c->SiblingIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
while (cl->SiblingIndex != c) {
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
cl->SiblingIndex = c->SiblingIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
kill_static_child_indxs(c, Yap_static_in_use(ap, TRUE));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:53:10 +01:00
|
|
|
/*
|
|
|
|
This predicate is supposed to be called with a
|
|
|
|
lock on the current predicate
|
|
|
|
*/
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_ErLogUpdIndex(LogUpdIndex *clau) {
|
2004-02-19 19:24:46 +00:00
|
|
|
if (clau->ClFlags & ErasedMask) {
|
2006-10-10 15:08:17 +01:00
|
|
|
if (!clau->ClRefCount) {
|
2015-10-22 00:53:26 +01:00
|
|
|
decrease_log_indices(clau,
|
|
|
|
(yamop *)&(clau->ClPred->cs.p_code.ExpandCode));
|
2006-10-10 15:08:17 +01:00
|
|
|
if (clau->ClFlags & SwitchRootMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
kill_off_lu_block(clau, NULL, clau->ClPred);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
kill_off_lu_block(clau, clau->ParentIndex, clau->ClPred);
|
2004-03-19 11:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* otherwise, nothing I can do, I have been erased already */
|
2006-10-10 15:08:17 +01:00
|
|
|
return;
|
2004-02-19 19:24:46 +00:00
|
|
|
}
|
2006-10-10 15:08:17 +01:00
|
|
|
if (clau->ClFlags & SwitchRootMask) {
|
|
|
|
kill_first_log_iblock(clau, NULL, clau->ClPred);
|
2004-03-19 11:35:42 +00:00
|
|
|
} else {
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
clau->ClRefCount++;
|
|
|
|
#endif
|
2005-12-17 03:25:39 +00:00
|
|
|
kill_first_log_iblock(clau, clau->ParentIndex, clau->ClPred);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
clau->ClRefCount--;
|
|
|
|
#endif
|
2004-11-04 18:22:36 +00:00
|
|
|
}
|
2003-10-14 01:53:10 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Routine used when wanting to remove the indexation */
|
|
|
|
/* ap is known to already have been locked for WRITING */
|
2015-10-22 00:53:26 +01:00
|
|
|
static int RemoveIndexation(PredEntry *ap) {
|
2003-10-14 01:53:10 +01:00
|
|
|
if (ap->OpcodeOfPred == INDEX_OPCODE) {
|
2003-08-27 14:37:10 +01:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ap->PredFlags & LogUpdatePredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
kill_first_log_iblock(ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),
|
|
|
|
NULL, ap);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
StaticIndex *cl;
|
|
|
|
|
|
|
|
cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
kill_top_static_iblock(cl, ap);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
int Yap_RemoveIndexation(PredEntry *ap) { return RemoveIndexation(ap); }
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
Adding clauses
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
******************************************************************/
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
#define assertz 0
|
|
|
|
#define consult 1
|
|
|
|
#define asserta 2
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void retract_all(PredEntry *p, int in_use) {
|
|
|
|
yamop *q;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-12-27 16:53:09 +00:00
|
|
|
q = p->cs.p_code.FirstClause;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (q != NULL) {
|
2015-04-13 13:28:17 +01:00
|
|
|
if (p->PredFlags & LogUpdatePredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(q);
|
2003-04-30 18:46:05 +01:00
|
|
|
do {
|
2015-10-22 00:53:26 +01:00
|
|
|
LogUpdClause *ncl = cl->ClNext;
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
cl = ncl;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (cl != NULL);
|
2015-04-13 13:28:17 +01:00
|
|
|
} else if (p->PredFlags & MegaClausePredFlag) {
|
2004-09-27 21:45:04 +01:00
|
|
|
MegaClause *cl = ClauseCodeToMegaClause(q);
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
if (in_use || cl->ClFlags & HasBlobsMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCK(DeadMegaClausesLock);
|
|
|
|
cl->ClNext = DeadMegaClauses;
|
|
|
|
DeadMegaClauses = cl;
|
|
|
|
UNLOCK(DeadMegaClausesLock);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InformOfRemoval(cl);
|
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
/* make sure this is not a MegaClause */
|
|
|
|
p->PredFlags &= ~MegaClausePredFlag;
|
2004-09-27 21:45:04 +01:00
|
|
|
p->cs.p_code.NOfClauses = 0;
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(q);
|
2003-11-26 18:36:35 +00:00
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
while (cl) {
|
2015-10-22 00:53:26 +01:00
|
|
|
StaticClause *ncl = cl->ClNext;
|
|
|
|
|
|
|
|
if (in_use || cl->ClFlags & HasBlobsMask) {
|
|
|
|
LOCK(DeadStaticClausesLock);
|
|
|
|
cl->ClNext = DeadStaticClauses;
|
|
|
|
DeadStaticClauses = cl;
|
|
|
|
UNLOCK(DeadStaticClausesLock);
|
|
|
|
} else {
|
|
|
|
Yap_InformOfRemoval(cl);
|
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
|
|
|
p->cs.p_code.NOfClauses--;
|
|
|
|
if (!ncl)
|
|
|
|
break;
|
|
|
|
cl = ncl;
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
p->cs.p_code.FirstClause = NULL;
|
|
|
|
p->cs.p_code.LastClause = NULL;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (p->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag)) {
|
2006-03-20 19:51:44 +00:00
|
|
|
p->OpcodeOfPred = FAIL_OPCODE;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2006-03-20 19:51:44 +00:00
|
|
|
p->OpcodeOfPred = UNDEF_OPCODE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2016-01-03 01:27:36 +00:00
|
|
|
if (trueGlobalPrologFlag(PROFILING_FLAG)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
2016-07-31 05:15:11 +01:00
|
|
|
if (!Yap_initProfiler(p)) {
|
2016-05-13 11:41:19 +01:00
|
|
|
return;
|
2016-07-31 05:15:11 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
if (CALL_COUNTING) {
|
|
|
|
p->PredFlags |= CountPredFlag;
|
|
|
|
} else
|
|
|
|
p->PredFlags &= ~CountPredFlag;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
bool Yap_unknown(Term t) {
|
2015-12-15 09:18:36 +00:00
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
if (t == TermFastFail) {
|
|
|
|
UndefCode->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
return true;
|
|
|
|
} else if (t == TermError) {
|
|
|
|
UndefCode->OpcodeOfPred = UndefCode->CodeOfPred->opc;
|
|
|
|
return true;
|
|
|
|
} else if (t == TermFail) {
|
|
|
|
UndefCode->OpcodeOfPred = UndefCode->CodeOfPred->opc;
|
|
|
|
return true;
|
|
|
|
} else if (t == TermWarning) {
|
|
|
|
UndefCode->OpcodeOfPred = UndefCode->CodeOfPred->opc;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-12-15 09:18:36 +00:00
|
|
|
}
|
2016-01-03 01:27:36 +00:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static int source_pred(PredEntry *p, yamop *q) {
|
|
|
|
if (p->PredFlags & (DynamicPredFlag | LogUpdatePredFlag))
|
2011-08-25 03:19:27 +01:00
|
|
|
return FALSE;
|
|
|
|
if (p->PredFlags & MultiFileFlag)
|
|
|
|
return TRUE;
|
2015-06-19 01:30:13 +01:00
|
|
|
if (trueGlobalPrologFlag(SOURCE_FLAG)) {
|
2011-08-25 03:19:27 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void add_first_static(PredEntry *p, yamop *cp, int spy_flag) {
|
2014-10-02 14:21:43 +01:00
|
|
|
CACHE_REGS
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *pt = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef TABLING
|
2016-01-03 01:27:36 +00:00
|
|
|
if (is_tabled(p)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* TABLING */
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = pt;
|
|
|
|
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = cp;
|
2008-01-23 17:57:56 +00:00
|
|
|
p->OpcodeOfPred = pt->opc;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) && p->ModuleOfPred != IDB_MODULE) {
|
2008-01-23 17:57:56 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2008-01-23 17:57:56 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
p->CodeOfPred = pt;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 1;
|
2016-01-03 01:27:36 +00:00
|
|
|
if (trueGlobalPrologFlag(PROFILING_FLAG)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
2016-07-31 05:15:11 +01:00
|
|
|
if (!Yap_initProfiler(p)) {
|
2016-05-13 11:41:19 +01:00
|
|
|
return;
|
2016-07-31 05:15:11 +01:00
|
|
|
}
|
|
|
|
spy_flag = TRUE;
|
2009-06-22 18:40:55 +01:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
}
|
|
|
|
if (CALL_COUNTING) {
|
|
|
|
p->PredFlags |= CountPredFlag;
|
|
|
|
spy_flag = TRUE;
|
|
|
|
} else {
|
|
|
|
p->PredFlags &= ~CountPredFlag;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (spy_flag) {
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2011-08-25 03:19:27 +01:00
|
|
|
if (source_pred(p, cp)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags |= SourcePredFlag;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!(p->PredFlags & MultiFileFlag) && p->src.OwnerFile == AtomNil)
|
|
|
|
p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void add_first_dynamic(PredEntry *p, yamop *cp, int spy_flag) {
|
|
|
|
yamop *ncp = ((DynamicClause *)NULL)->ClCode;
|
|
|
|
DynamicClause *cl;
|
2015-12-15 09:28:43 +00:00
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
if (trueGlobalPrologFlag(PROFILING_FLAG)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
2016-05-13 11:41:19 +01:00
|
|
|
if (!Yap_initProfiler(p)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-03 01:27:36 +00:00
|
|
|
spy_flag = true;
|
2009-06-22 18:40:55 +01:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
2009-06-22 18:40:55 +01:00
|
|
|
}
|
|
|
|
if (CALL_COUNTING) {
|
|
|
|
p->PredFlags |= CountPredFlag;
|
2016-01-03 01:27:36 +00:00
|
|
|
spy_flag = true;
|
2009-06-22 18:40:55 +01:00
|
|
|
} else {
|
|
|
|
p->PredFlags &= ~CountPredFlag;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
p->PredFlags |= SequentialPredFlag;
|
|
|
|
#endif /* YAPOR */
|
2015-10-22 00:53:26 +01:00
|
|
|
/* allocate starter block, containing info needed to start execution,
|
|
|
|
* that is a try_mark to start the code and a fail to finish things up */
|
|
|
|
cl = (DynamicClause *)Yap_AllocCodeSpace(
|
|
|
|
(Int)NEXTOP(NEXTOP(NEXTOP(ncp, Otapl), e), l));
|
2001-04-09 20:54:03 +01:00
|
|
|
if (cl == NIL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "Heap crashed against Stacks");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_ClauseSpace += (Int)NEXTOP(NEXTOP(NEXTOP(ncp, Otapl), e), l);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* skip the first entry, this contains the back link and will always be
|
|
|
|
empty for this entry */
|
2015-10-22 00:53:26 +01:00
|
|
|
ncp = (yamop *)(((CELL *)ncp) + 1);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* next we have the flags. For this block mainly say whether we are
|
|
|
|
* being spied */
|
2003-04-30 18:46:05 +01:00
|
|
|
cl->ClFlags = DynamicMask;
|
|
|
|
ncp = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_LOCK(cl->ClLock);
|
|
|
|
INIT_CLREF_COUNT(cl);
|
|
|
|
/* next, set the first instruction to execute in the dyamic
|
|
|
|
* predicate */
|
|
|
|
if (spy_flag)
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = ncp->opc = Yap_opcode(_spy_or_trymark);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = ncp->opc = Yap_opcode(_try_and_mark);
|
2014-05-30 01:06:09 +01:00
|
|
|
ncp->y_u.Otapl.s = p->ArityOfPE;
|
|
|
|
ncp->y_u.Otapl.p = p;
|
|
|
|
ncp->y_u.Otapl.d = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* This is the point we enter the code */
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = ncp;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 1;
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) && p->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* set the first clause to have a retry and mark which will
|
|
|
|
* backtrack to the previous block */
|
|
|
|
if (p->PredFlags & ProfiledPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_profiled_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else if (p->PredFlags & CountPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_count_retry_and_mark);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_retry_and_mark);
|
2014-05-30 01:06:09 +01:00
|
|
|
cp->y_u.Otapl.s = p->ArityOfPE;
|
|
|
|
cp->y_u.Otapl.p = p;
|
|
|
|
cp->y_u.Otapl.d = ncp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* also, keep a backpointer for the days you delete the clause */
|
2003-04-30 18:46:05 +01:00
|
|
|
ClauseCodeToDynamicClause(cp)->ClPrevious = ncp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Don't forget to say who is the only clause for the predicate so
|
|
|
|
far */
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.LastClause = p->cs.p_code.FirstClause = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we're only missing what to do when we actually exit the procedure
|
|
|
|
*/
|
2015-10-22 00:53:26 +01:00
|
|
|
ncp = NEXTOP(ncp, Otapl);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* and the last instruction to execute to exit the predicate, note
|
|
|
|
the retry is pointing to this pseudo clause */
|
2002-11-18 18:18:05 +00:00
|
|
|
ncp->opc = Yap_opcode(_trust_fail);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we're only missing what to do when we actually exit the procedure
|
|
|
|
*/
|
|
|
|
/* and close the code */
|
2015-10-22 00:53:26 +01:00
|
|
|
ncp = NEXTOP(ncp, e);
|
2002-11-18 18:18:05 +00:00
|
|
|
ncp->opc = Yap_opcode(_Ystop);
|
2014-05-30 01:06:09 +01:00
|
|
|
ncp->y_u.l.l = cl->ClCode;
|
2016-01-03 01:27:36 +00:00
|
|
|
// if (!(p->PredFlags & MultiFileFlag) && p->src.OwnerFile == AtomNil)
|
2015-12-15 09:28:43 +00:00
|
|
|
// p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void asserta_stat_clause(PredEntry *p, yamop *q, int spy_flag) {
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(q);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
p->cs.p_code.NOfClauses++;
|
|
|
|
if (is_logupd(p)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LogUpdClause *clp = ClauseCodeToLogUpdClause(p->cs.p_code.FirstClause),
|
|
|
|
*clq = ClauseCodeToLogUpdClause(q);
|
2003-08-27 14:37:10 +01:00
|
|
|
clq->ClPrev = NULL;
|
|
|
|
clq->ClNext = clp;
|
|
|
|
clp->ClPrev = clq;
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.FirstClause = q;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (p->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2011-03-15 09:08:09 +00:00
|
|
|
if (p->ModuleOfPred != IDB_MODULE &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
cl->ClNext = ClauseCodeToStaticClause(p->cs.p_code.FirstClause);
|
|
|
|
p->cs.p_code.FirstClause = q;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = q;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (p->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
2003-10-02 19:20:11 +01:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-10-02 19:20:11 +01:00
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void asserta_dynam_clause(PredEntry *p, yamop *cp) {
|
|
|
|
yamop *q;
|
2003-08-27 14:37:10 +01:00
|
|
|
DynamicClause *cl = ClauseCodeToDynamicClause(cp);
|
2002-12-27 16:53:09 +00:00
|
|
|
q = cp;
|
2003-04-30 18:46:05 +01:00
|
|
|
LOCK(ClauseCodeToDynamicClause(p->cs.p_code.FirstClause)->ClLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* also, keep backpointers for the days we'll delete all the clause */
|
2003-04-30 18:46:05 +01:00
|
|
|
ClauseCodeToDynamicClause(p->cs.p_code.FirstClause)->ClPrevious = q;
|
2003-08-27 14:37:10 +01:00
|
|
|
cl->ClPrevious = (yamop *)(p->CodeOfPred);
|
|
|
|
cl->ClFlags |= DynamicMask;
|
2003-04-30 18:46:05 +01:00
|
|
|
UNLOCK(ClauseCodeToDynamicClause(p->cs.p_code.FirstClause)->ClLock);
|
2014-05-30 01:06:09 +01:00
|
|
|
q->y_u.Otapl.d = p->cs.p_code.FirstClause;
|
|
|
|
q->y_u.Otapl.s = p->ArityOfPE;
|
|
|
|
q->y_u.Otapl.p = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (p->PredFlags & ProfiledPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_profiled_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else if (p->PredFlags & CountPredFlag)
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_count_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else
|
2002-12-27 16:53:09 +00:00
|
|
|
cp->opc = Yap_opcode(_retry_and_mark);
|
2014-05-30 01:06:09 +01:00
|
|
|
cp->y_u.Otapl.s = p->ArityOfPE;
|
|
|
|
cp->y_u.Otapl.p = p;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.FirstClause = cp;
|
|
|
|
q = p->CodeOfPred;
|
2014-05-30 01:06:09 +01:00
|
|
|
q->y_u.Otapl.d = cp;
|
|
|
|
q->y_u.Otapl.s = p->ArityOfPE;
|
|
|
|
q->y_u.Otapl.p = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void assertz_stat_clause(PredEntry *p, yamop *cp, int spy_flag) {
|
|
|
|
yamop *pt;
|
2003-11-26 18:36:35 +00:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
p->cs.p_code.NOfClauses++;
|
|
|
|
pt = p->cs.p_code.LastClause;
|
|
|
|
if (is_logupd(p)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LogUpdClause *clp = ClauseCodeToLogUpdClause(cp),
|
|
|
|
*clq = ClauseCodeToLogUpdClause(pt);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
clq->ClNext = clp;
|
|
|
|
clp->ClPrev = clq;
|
|
|
|
clp->ClNext = NULL;
|
|
|
|
p->cs.p_code.LastClause = cp;
|
2009-04-22 00:51:01 +01:00
|
|
|
if (!(p->PredFlags & IndexedPredFlag)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
2015-10-22 00:53:26 +01:00
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred =
|
|
|
|
(yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2011-03-15 09:08:09 +00:00
|
|
|
if (p->ModuleOfPred != IDB_MODULE &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
if (p->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
2009-04-22 00:51:01 +01:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
return;
|
2006-03-20 19:51:44 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pt);
|
2006-03-20 19:51:44 +00:00
|
|
|
|
|
|
|
cl->ClNext = ClauseCodeToStaticClause(cp);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (p->cs.p_code.FirstClause == p->cs.p_code.LastClause) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!(p->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag))) {
|
2003-11-26 18:36:35 +00:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.LastClause = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void assertz_dynam_clause(PredEntry *p, yamop *cp) {
|
|
|
|
yamop *q;
|
2003-08-27 14:37:10 +01:00
|
|
|
DynamicClause *cl = ClauseCodeToDynamicClause(cp);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-12-27 16:53:09 +00:00
|
|
|
q = p->cs.p_code.LastClause;
|
2003-04-30 18:46:05 +01:00
|
|
|
LOCK(ClauseCodeToDynamicClause(q)->ClLock);
|
2014-05-30 01:06:09 +01:00
|
|
|
q->y_u.Otapl.d = cp;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.LastClause = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* also, keep backpointers for the days we'll delete all the clause */
|
2003-08-27 14:37:10 +01:00
|
|
|
cl->ClPrevious = q;
|
|
|
|
cl->ClFlags |= DynamicMask;
|
2003-04-30 18:46:05 +01:00
|
|
|
UNLOCK(ClauseCodeToDynamicClause(q)->ClLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
q = (yamop *)cp;
|
|
|
|
if (p->PredFlags & ProfiledPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
q->opc = Yap_opcode(_profiled_retry_and_mark);
|
2002-09-03 15:28:09 +01:00
|
|
|
else if (p->PredFlags & CountPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
q->opc = Yap_opcode(_count_retry_and_mark);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
q->opc = Yap_opcode(_retry_and_mark);
|
2014-05-30 01:06:09 +01:00
|
|
|
q->y_u.Otapl.d = p->CodeOfPred;
|
|
|
|
q->y_u.Otapl.s = p->ArityOfPE;
|
|
|
|
q->y_u.Otapl.p = p;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses++;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_AssertzClause(PredEntry *p, yamop *cp) {
|
2011-08-24 04:11:54 +01:00
|
|
|
if (p->PredFlags & DynamicPredFlag) {
|
|
|
|
if (p->cs.p_code.FirstClause == NULL) {
|
|
|
|
add_first_dynamic(p, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_dynam_clause(p, cp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p->cs.p_code.FirstClause == NULL) {
|
|
|
|
add_first_static(p, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_stat_clause(p, cp, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void expand_consult(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2006-04-29 02:15:18 +01:00
|
|
|
consult_obj *new_cl, *new_cs;
|
2011-05-04 10:11:41 +01:00
|
|
|
UInt OldConsultCapacity = LOCAL_ConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-01-01 05:26:25 +00:00
|
|
|
/* now double consult capacity */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultCapacity += InitialConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* I assume it always works ;-) */
|
2015-10-22 00:53:26 +01:00
|
|
|
while ((new_cl = (consult_obj *)Yap_AllocCodeSpace(
|
|
|
|
sizeof(consult_obj) * LOCAL_ConsultCapacity)) == NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, sizeof(consult_obj) * LOCAL_ConsultCapacity,
|
|
|
|
NULL)) {
|
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
2002-02-27 02:10:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-04-28 14:23:23 +01:00
|
|
|
new_cs = new_cl + InitialConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* start copying */
|
2015-10-22 00:53:26 +01:00
|
|
|
memcpy((void *)new_cs, (void *)LOCAL_ConsultLow,
|
|
|
|
OldConsultCapacity * sizeof(consult_obj));
|
2001-04-09 20:54:03 +01:00
|
|
|
/* copying done, release old space */
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_FreeCodeSpace((char *)LOCAL_ConsultLow);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* next, set up pointers correctly */
|
2015-10-22 00:53:26 +01:00
|
|
|
new_cs += (LOCAL_ConsultSp - LOCAL_ConsultLow);
|
2011-05-04 10:11:41 +01:00
|
|
|
/* put LOCAL_ConsultBase at same offset as before move */
|
2016-07-31 05:15:11 +01:00
|
|
|
LOCAL_ConsultBase = new_cl + ((LOCAL_ConsultBase - LOCAL_ConsultLow) +
|
|
|
|
InitialConsultCapacity);
|
|
|
|
/* new consult pointer */
|
|
|
|
LOCAL_ConsultSp =
|
|
|
|
new_cl + ((LOCAL_ConsultSp - LOCAL_ConsultLow) + InitialConsultCapacity);
|
2006-04-28 14:23:23 +01:00
|
|
|
/* new end of memory */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultLow = new_cl;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static int not_was_reconsulted(PredEntry *p, Term t, int mode) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-10-22 00:53:26 +01:00
|
|
|
register consult_obj *fp;
|
|
|
|
Prop p0 = AbsProp((PropEntry *)p);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-05-04 10:11:41 +01:00
|
|
|
if (p == LOCAL_LastAssertedPred)
|
2009-02-10 23:42:26 +00:00
|
|
|
return FALSE;
|
2011-05-04 10:11:41 +01:00
|
|
|
if (!LOCAL_ConsultSp) {
|
2010-03-21 22:12:42 +00:00
|
|
|
InitConsultStack();
|
|
|
|
}
|
2008-05-28 18:18:35 +01:00
|
|
|
if (p->cs.p_code.NOfClauses) {
|
2011-05-04 10:11:41 +01:00
|
|
|
for (fp = LOCAL_ConsultSp; fp < LOCAL_ConsultBase; ++fp)
|
2008-05-28 18:18:35 +01:00
|
|
|
if (fp->p == p0)
|
2015-10-22 00:53:26 +01:00
|
|
|
break;
|
2008-05-28 18:18:35 +01:00
|
|
|
} else {
|
2011-05-04 10:11:41 +01:00
|
|
|
fp = LOCAL_ConsultBase;
|
2008-05-28 18:18:35 +01:00
|
|
|
}
|
2014-04-24 11:40:35 +01:00
|
|
|
if (fp != LOCAL_ConsultBase) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_LastAssertedPred = p;
|
|
|
|
return false; /* careful */
|
2014-04-24 12:54:08 +01:00
|
|
|
} else if (mode) { // consulting again a predicate in the original file.
|
2015-04-13 13:28:17 +01:00
|
|
|
if ((p->cs.p_code.NOfClauses &&
|
2015-10-22 00:53:26 +01:00
|
|
|
p->src.OwnerFile == Yap_ConsultingFile(PASS_REGS1) &&
|
|
|
|
p->src.OwnerFile != AtomNil && !(p->PredFlags & MultiFileFlag) &&
|
|
|
|
p->src.OwnerFile != AtomUserIn)) {
|
|
|
|
// if (p->ArityOfPE)
|
|
|
|
// printf("+ %s %s
|
|
|
|
//%d\n",NameOfFunctor(p->FunctorOfPred)->StrOfAE,p->src.OwnerFile->StrOfAE,
|
2016-01-03 01:27:36 +00:00
|
|
|
// p->cs.p_code.NOfClauses);
|
2015-10-22 00:53:26 +01:00
|
|
|
retract_all(p, Yap_static_in_use(p, TRUE));
|
|
|
|
}
|
|
|
|
// printf("- %s
|
|
|
|
//%s\n",NameOfFunctor(p->FunctorOfPred)->StrOfAE,p->src.OwnerFile->StrOfAE);
|
2014-04-24 11:40:35 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (mode) {
|
2016-07-31 05:15:11 +01:00
|
|
|
if (LOCAL_ConsultSp <= LOCAL_ConsultLow + 6) {
|
|
|
|
expand_consult();
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
--LOCAL_ConsultSp;
|
|
|
|
LOCAL_ConsultSp->p = p0;
|
2016-07-31 05:15:11 +01:00
|
|
|
if (LOCAL_ConsultBase != LOCAL_ConsultLow + LOCAL_ConsultCapacity &&
|
|
|
|
LOCAL_ConsultBase[1].mode &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & MultiFileFlag)) /* we are in reconsult mode */ {
|
|
|
|
retract_all(p, Yap_static_in_use(p, TRUE));
|
2001-12-12 19:36:51 +00:00
|
|
|
}
|
2016-01-03 01:27:36 +00:00
|
|
|
// p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2015-08-18 20:32:24 +01:00
|
|
|
LOCAL_LastAssertedPred = p;
|
2015-10-22 00:53:26 +01:00
|
|
|
return TRUE; /* careful */
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void addcl_permission_error(AtomEntry *ap, Int Arity, int in_use) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE;
|
2016-11-08 07:37:36 +00:00
|
|
|
LOCAL_ErrorMessage = Malloc( 256 );
|
|
|
|
|
2002-01-02 16:55:24 +00:00
|
|
|
if (in_use) {
|
|
|
|
if (Arity == 0)
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage, "static predicate %s is in use", ap->StrOfAE);
|
2002-01-02 16:55:24 +00:00
|
|
|
else
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage,
|
2015-10-22 00:53:26 +01:00
|
|
|
"static predicate %s/" Int_FORMAT " is in use", ap->StrOfAE,
|
|
|
|
Arity);
|
2002-01-02 16:55:24 +00:00
|
|
|
} else {
|
|
|
|
if (Arity == 0)
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage, "system predicate %s", ap->StrOfAE);
|
2002-01-02 16:55:24 +00:00
|
|
|
else
|
2015-10-22 00:53:26 +01:00
|
|
|
sprintf(LOCAL_ErrorMessage, "system predicate %s/" Int_FORMAT,
|
|
|
|
ap->StrOfAE, Arity);
|
2002-01-02 16:55:24 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *Yap_PredFromClause(Term t USES_REGS) {
|
2014-04-24 08:26:31 +01:00
|
|
|
Term cmod = LOCAL_SourceModule;
|
2015-01-06 17:47:58 +00:00
|
|
|
arity_t extra_arity = 0;
|
2014-04-24 08:26:31 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(t))
|
|
|
|
return NULL;
|
2014-04-24 08:26:31 +01:00
|
|
|
while (IsApplTerm(t)) {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
if (f == FunctorModule) {
|
|
|
|
// module
|
2015-10-22 00:53:26 +01:00
|
|
|
cmod = ArgOfTerm(1, t);
|
2014-04-24 08:26:31 +01:00
|
|
|
if (!IsAtomTerm(cmod))
|
2015-10-22 00:53:26 +01:00
|
|
|
return NULL;
|
|
|
|
t = ArgOfTerm(2, t);
|
|
|
|
} else if (f == FunctorAssert) {
|
2014-04-24 08:26:31 +01:00
|
|
|
t = ArgOfTerm(1, t);
|
2015-10-22 00:53:26 +01:00
|
|
|
} else if (f == FunctorComma && extra_arity == 2) {
|
2014-10-07 21:04:54 +01:00
|
|
|
t = ArgOfTerm(1, t);
|
2015-10-22 00:53:26 +01:00
|
|
|
} else if (f == FunctorDoubleArrow) {
|
2014-04-24 08:26:31 +01:00
|
|
|
extra_arity = 2;
|
|
|
|
t = ArgOfTerm(1, t);
|
2015-10-22 00:53:26 +01:00
|
|
|
} else if (f == FunctorQuery || f == FunctorAssert1) {
|
2014-04-24 08:26:31 +01:00
|
|
|
// directives
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
if (extra_arity) {
|
2015-10-22 00:53:26 +01:00
|
|
|
f = Yap_MkFunctor(NameOfFunctor(f), ArityOfFunctor(f) + 2);
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
|
|
|
return RepPredProp(Yap_GetPredPropByFunc(f, cmod));
|
|
|
|
}
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
2014-04-24 08:26:31 +01:00
|
|
|
if (extra_arity) {
|
|
|
|
Functor f = Yap_MkFunctor(AtomOfTerm(t), 2);
|
|
|
|
return RepPredProp(Yap_GetPredPropByFunc(f, cmod));
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), cmod));
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
|
|
|
// ints, lists
|
2015-08-18 20:32:24 +01:00
|
|
|
|
2014-04-24 08:26:31 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
bool Yap_discontiguous(PredEntry *ap, Term mode USES_REGS) {
|
2015-10-22 00:53:26 +01:00
|
|
|
register consult_obj *fp;
|
2014-04-24 08:26:31 +01:00
|
|
|
|
2016-05-12 11:48:39 +01:00
|
|
|
if (ap->PredFlags & (DiscontiguousPredFlag | MultiFileFlag) ||
|
|
|
|
falseGlobalPrologFlag(DISCONTIGUOUS_WARNINGS_FLAG))
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2016-05-12 11:48:39 +01:00
|
|
|
if ((mode != TermConsult && mode != TermReconsult))
|
2015-08-18 20:32:24 +01:00
|
|
|
return false;
|
2014-04-24 08:26:31 +01:00
|
|
|
if (!LOCAL_ConsultSp) {
|
2015-08-18 20:32:24 +01:00
|
|
|
return false;
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
|
|
|
if (ap == LOCAL_LastAssertedPred)
|
2016-05-16 09:35:29 +01:00
|
|
|
return false;
|
2014-04-24 08:26:31 +01:00
|
|
|
if (ap->cs.p_code.NOfClauses) {
|
2016-05-16 09:35:29 +01:00
|
|
|
Term repeat = AbsPair((CELL *)AbsPredProp(ap));
|
2014-04-24 08:26:31 +01:00
|
|
|
for (fp = LOCAL_ConsultSp; fp < LOCAL_ConsultBase; ++fp)
|
2016-05-16 09:35:29 +01:00
|
|
|
if (fp->p == AbsPredProp(ap)) {
|
2016-07-31 05:15:11 +01:00
|
|
|
// detect repeated warnings
|
|
|
|
if (LOCAL_ConsultSp == LOCAL_ConsultLow + 1) {
|
|
|
|
expand_consult();
|
|
|
|
}
|
|
|
|
--LOCAL_ConsultSp;
|
|
|
|
LOCAL_ConsultSp->r = repeat;
|
2015-10-22 00:53:26 +01:00
|
|
|
return true;
|
2016-07-31 05:15:11 +01:00
|
|
|
} else if (fp->r == repeat && ap->cs.p_code.NOfClauses > 4) {
|
|
|
|
return false;
|
2016-05-16 09:35:29 +01:00
|
|
|
}
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
2015-08-18 20:32:24 +01:00
|
|
|
return false;
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
static Int p_is_discontiguous(USES_REGS1) { /* '$is_multifile'(+S,+Mod) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "discontiguous");
|
2016-01-03 01:27:36 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
|
|
|
PELOCK(27, pe);
|
|
|
|
out = (pe->PredFlags & DiscontiguousPredFlag);
|
|
|
|
UNLOCKPE(44, pe);
|
|
|
|
return (out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_new_discontiguous(USES_REGS1) { /* '$new_discontiguous'(+N,+Ar,+Mod) */
|
|
|
|
Atom at;
|
|
|
|
int arity;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG3);
|
|
|
|
|
|
|
|
if (IsVarTerm(t))
|
2016-05-12 11:48:39 +01:00
|
|
|
return false;
|
2016-01-03 01:27:36 +00:00
|
|
|
if (IsAtomTerm(t))
|
|
|
|
at = AtomOfTerm(t);
|
|
|
|
else
|
2016-05-12 11:48:39 +01:00
|
|
|
return false;
|
2016-01-03 01:27:36 +00:00
|
|
|
t = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t))
|
2016-05-12 11:48:39 +01:00
|
|
|
return false;
|
2016-01-03 01:27:36 +00:00
|
|
|
if (IsIntTerm(t))
|
|
|
|
arity = IntOfTerm(t);
|
|
|
|
else
|
2016-05-12 11:48:39 +01:00
|
|
|
return false;
|
2016-01-03 01:27:36 +00:00
|
|
|
if (arity == 0)
|
|
|
|
pe = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, arity), mod));
|
|
|
|
PELOCK(26, pe);
|
|
|
|
pe->PredFlags |= DiscontiguousPredFlag;
|
|
|
|
/* mutifile-predicates are weird, they do not seat really on the default
|
|
|
|
* module */
|
2016-07-31 05:15:11 +01:00
|
|
|
if (pe->cs.p_code.NOfClauses == 0) {
|
|
|
|
pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred = FAILCODE;
|
|
|
|
pe->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
}
|
2016-01-03 01:27:36 +00:00
|
|
|
UNLOCKPE(43, pe);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2016-02-21 11:30:13 +00:00
|
|
|
bool Yap_multiple(PredEntry *ap, Term mode USES_REGS) {
|
2015-10-22 00:53:26 +01:00
|
|
|
register consult_obj *fp;
|
2015-08-18 20:32:24 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if ((ap->PredFlags & (MultiFileFlag | LogUpdatePredFlag | DynamicPredFlag)) ||
|
2016-01-03 01:27:36 +00:00
|
|
|
mode != TermReconsult)
|
2015-09-21 23:05:36 +01:00
|
|
|
return false;
|
|
|
|
if (LOCAL_consult_level == 0)
|
|
|
|
return false;
|
2015-08-18 20:32:24 +01:00
|
|
|
for (fp = LOCAL_ConsultSp; fp < LOCAL_ConsultBase; ++fp)
|
|
|
|
if (fp->p == AbsPredProp(ap)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return ap->cs.p_code.NOfClauses > 0 && ap->src.OwnerFile != AtomNil &&
|
|
|
|
Yap_ConsultingFile(PASS_REGS1) != ap->src.OwnerFile &&
|
|
|
|
LOCAL_Including != MkAtomTerm(ap->src.OwnerFile);
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
2004-09-08 18:56:48 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static int is_fact(Term t) {
|
2004-09-08 18:56:48 +01:00
|
|
|
Term a1;
|
|
|
|
|
|
|
|
if (IsAtomTerm(t))
|
|
|
|
return TRUE;
|
|
|
|
if (FunctorOfTerm(t) != FunctorAssert)
|
|
|
|
return TRUE;
|
|
|
|
a1 = ArgOfTerm(2, t);
|
|
|
|
if (a1 == MkAtomTerm(AtomTrue))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
Int Yap_source_line_no(void) {
|
|
|
|
CACHE_REGS
|
2015-06-19 01:30:13 +01:00
|
|
|
return LOCAL_SourceFileLineno;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
Atom Yap_source_file_name(void) {
|
|
|
|
CACHE_REGS
|
2016-03-05 17:38:08 +00:00
|
|
|
if (LOCAL_SourceFileName)
|
|
|
|
return LOCAL_SourceFileName;
|
|
|
|
return AtomNil;
|
2015-06-19 01:30:13 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
/**
|
2015-12-15 09:28:43 +00:00
|
|
|
* @brief we cannot add clauses to the proceduree
|
2016-01-03 01:27:36 +00:00
|
|
|
*
|
|
|
|
* @param p predicate
|
|
|
|
*
|
2015-12-15 09:28:43 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2016-01-03 01:27:36 +00:00
|
|
|
bool Yap_constPred(PredEntry *p) {
|
2015-12-15 09:28:43 +00:00
|
|
|
pred_flags_t pflags;
|
|
|
|
pflags = p->PredFlags;
|
|
|
|
|
2017-05-19 09:56:37 +01:00
|
|
|
if (pflags &
|
|
|
|
((UserCPredFlag | CArgsPredFlag | NumberDBPredFlag | AtomDBPredFlag |
|
|
|
|
TestPredFlag | AsmPredFlag | CPredFlag | BinaryPredFlag)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (p->PredFlags &
|
|
|
|
(SysExportPredFlag | MultiFileFlag | DynamicPredFlag | LogUpdatePredFlag))
|
|
|
|
return false;
|
2016-01-03 01:27:36 +00:00
|
|
|
if (Yap_isSystemModule(p->ModuleOfPred)) {
|
2015-12-15 09:28:43 +00:00
|
|
|
if (p->cs.p_code.NOfClauses == 0) {
|
2016-01-03 01:27:36 +00:00
|
|
|
p->src.OwnerFile = Yap_source_file_name();
|
2015-12-15 09:28:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-03 01:27:36 +00:00
|
|
|
if (p->src.OwnerFile == Yap_source_file_name()) {
|
2015-12-15 09:28:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-05-19 09:56:37 +01:00
|
|
|
|
2015-12-15 09:28:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-05 17:38:08 +00:00
|
|
|
bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
|
2012-11-07 13:49:54 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
mode
|
|
|
|
0 assertz
|
|
|
|
1 consult
|
|
|
|
2 asserta
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CACHE_REGS
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *p;
|
|
|
|
int spy_flag = FALSE;
|
|
|
|
Atom at;
|
|
|
|
arity_t Arity;
|
|
|
|
pred_flags_t pflags;
|
|
|
|
Term tf;
|
2016-02-21 11:30:13 +00:00
|
|
|
int mode;
|
2012-11-07 13:49:54 +00:00
|
|
|
|
2016-02-21 11:30:13 +00:00
|
|
|
if (tmode == TermConsult) {
|
|
|
|
mode = consult;
|
|
|
|
} else if (tmode == TermReconsult) {
|
|
|
|
mode = consult;
|
2016-03-05 17:38:08 +00:00
|
|
|
} else if (tmode == TermAsserta) {
|
2016-02-21 11:30:13 +00:00
|
|
|
mode = asserta;
|
2016-03-05 17:38:08 +00:00
|
|
|
} else if (tmode == TermAssertz) {
|
2016-02-21 11:30:13 +00:00
|
|
|
mode = assertz;
|
2016-03-05 17:38:08 +00:00
|
|
|
} else if (tmode == TermAssertaStatic) {
|
2016-02-21 11:30:13 +00:00
|
|
|
mode = asserta;
|
2016-03-05 17:38:08 +00:00
|
|
|
} else if (tmode == TermAssertzStatic) {
|
2016-02-21 11:30:13 +00:00
|
|
|
mode = assertz;
|
2016-08-01 23:48:43 +01:00
|
|
|
} else {
|
|
|
|
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, tmode,
|
2016-08-02 01:14:51 +01:00
|
|
|
"compilation mode used to assert");
|
|
|
|
return false;
|
2016-02-21 11:30:13 +00:00
|
|
|
}
|
2012-11-07 13:49:54 +00:00
|
|
|
if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorAssert)
|
|
|
|
tf = ArgOfTerm(1, t);
|
|
|
|
else
|
|
|
|
tf = t;
|
2016-04-28 15:01:16 +01:00
|
|
|
tf = Yap_YapStripModule(tf, &mod);
|
2016-05-12 11:48:39 +01:00
|
|
|
|
2012-11-07 13:49:54 +00:00
|
|
|
if (IsAtomTerm(tf)) {
|
|
|
|
at = AtomOfTerm(tf);
|
|
|
|
p = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
Arity = 0;
|
|
|
|
} else {
|
|
|
|
Functor f = FunctorOfTerm(tf);
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
at = NameOfFunctor(f);
|
|
|
|
p = RepPredProp(PredPropByFunc(f, mod));
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(20, p);
|
2012-11-07 13:49:54 +00:00
|
|
|
/* we are redefining a prolog module predicate */
|
2015-12-15 09:28:43 +00:00
|
|
|
if (Yap_constPred(p)) {
|
2012-11-07 13:49:54 +00:00
|
|
|
addcl_permission_error(RepAtom(at), Arity, FALSE);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(30, p);
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2012-11-07 13:49:54 +00:00
|
|
|
}
|
2017-05-19 09:56:37 +01:00
|
|
|
Yap_PutValue(AtomAbol, TermNil);
|
2015-12-15 09:28:43 +00:00
|
|
|
pflags = p->PredFlags;
|
2012-11-07 13:49:54 +00:00
|
|
|
/* we are redefining a prolog module predicate */
|
|
|
|
if (pflags & MegaClausePredFlag) {
|
|
|
|
split_megaclause(p);
|
|
|
|
}
|
|
|
|
/* The only problem we have now is when we need to throw away
|
|
|
|
Indexing blocks
|
|
|
|
*/
|
|
|
|
if (pflags & IndexedPredFlag) {
|
|
|
|
Yap_AddClauseToIndex(p, cp, mode == asserta);
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (pflags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag))
|
2016-01-03 01:27:36 +00:00
|
|
|
spy_flag = true;
|
2016-02-21 11:30:13 +00:00
|
|
|
if (Yap_discontiguous(p, tmode PASS_REGS)) {
|
2015-09-21 23:05:36 +01:00
|
|
|
Term disc[3], sc[4];
|
|
|
|
if (p->ArityOfPE) {
|
|
|
|
disc[0] = MkAtomTerm(NameOfFunctor(p->FunctorOfPred));
|
|
|
|
} else {
|
2015-12-15 09:28:43 +00:00
|
|
|
disc[0] = MkAtomTerm((Atom)(p->FunctorOfPred));
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
disc[1] = MkIntTerm(p->ArityOfPE);
|
|
|
|
disc[2] = Yap_Module_Name(p);
|
|
|
|
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomDiscontiguous, 3), 3, disc);
|
2015-10-22 00:53:26 +01:00
|
|
|
sc[1] = MkIntegerTerm(Yap_source_line_no());
|
|
|
|
sc[2] = MkAtomTerm(LOCAL_SourceFileName);
|
2015-09-21 23:05:36 +01:00
|
|
|
sc[3] = t;
|
2015-11-05 15:11:57 +00:00
|
|
|
t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc);
|
2016-01-03 01:27:36 +00:00
|
|
|
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
|
|
|
|
sc[1] = MkAtomTerm(AtomWarning);
|
|
|
|
Yap_PrintWarning(Yap_MkApplTerm(Yap_MkFunctor(AtomError, 2), 2, sc));
|
2016-02-21 11:30:13 +00:00
|
|
|
} else if (Yap_multiple(p, tmode PASS_REGS)) {
|
2016-01-03 01:27:36 +00:00
|
|
|
Term disc[4], sc[4];
|
2015-09-21 23:05:36 +01:00
|
|
|
if (p->ArityOfPE) {
|
|
|
|
disc[0] = MkAtomTerm(NameOfFunctor(p->FunctorOfPred));
|
|
|
|
} else {
|
2015-12-15 09:28:43 +00:00
|
|
|
disc[0] = MkAtomTerm((Atom)(p->FunctorOfPred));
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
disc[1] = MkIntTerm(p->ArityOfPE);
|
|
|
|
disc[2] = Yap_Module_Name(p);
|
|
|
|
disc[3] = MkAtomTerm(p->src.OwnerFile);
|
|
|
|
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomMultiple, 4), 4, disc);
|
2015-10-22 00:53:26 +01:00
|
|
|
sc[1] = MkIntegerTerm(Yap_source_line_no());
|
|
|
|
sc[2] = MkAtomTerm(LOCAL_SourceFileName);
|
2015-09-21 23:05:36 +01:00
|
|
|
sc[3] = t;
|
2015-11-05 15:11:57 +00:00
|
|
|
t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc);
|
2016-01-03 01:27:36 +00:00
|
|
|
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
|
|
|
|
sc[1] = MkAtomTerm(AtomWarning);
|
|
|
|
Yap_PrintWarning(Yap_MkApplTerm(Yap_MkFunctor(AtomError, 2), 2, sc));
|
2015-08-18 20:32:24 +01:00
|
|
|
}
|
2015-04-13 13:28:17 +01:00
|
|
|
if (mode == consult)
|
2016-01-03 01:27:36 +00:00
|
|
|
not_was_reconsulted(p, t, true);
|
2002-03-07 05:47:24 +00:00
|
|
|
/* always check if we have a valid error first */
|
2015-10-22 00:53:26 +01:00
|
|
|
if (LOCAL_ErrorMessage &&
|
|
|
|
LOCAL_Error_TYPE == PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE) {
|
|
|
|
UNLOCKPE(31, p);
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2009-02-12 21:35:31 +00:00
|
|
|
if (pflags & UDIPredFlag) {
|
|
|
|
Yap_new_udi_clause(p, cp, t);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!is_dynamic(p)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & LogUpdatePredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LogUpdClause *clp = ClauseCodeToLogUpdClause(cp);
|
2003-08-27 14:37:10 +01:00
|
|
|
clp->ClFlags |= LogUpdMask;
|
2004-09-08 18:56:48 +01:00
|
|
|
if (is_fact(t)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
clp->ClFlags |= FactMask;
|
|
|
|
clp->lusl.ClLine = Yap_source_line_no();
|
2003-11-18 19:24:46 +00:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
StaticClause *clp = ClauseCodeToStaticClause(cp);
|
2003-04-30 18:46:05 +01:00
|
|
|
clp->ClFlags |= StaticMask;
|
2007-03-26 16:18:43 +01:00
|
|
|
if (is_fact(t) && !(p->PredFlags & TabledPredFlag)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
clp->ClFlags |= FactMask;
|
|
|
|
clp->usc.ClLine = Yap_source_line_no();
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (compile_mode)
|
2003-12-04 18:13:04 +00:00
|
|
|
p->PredFlags = p->PredFlags | CompiledPredFlag;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2003-11-27 21:47:44 +00:00
|
|
|
p->PredFlags = p->PredFlags | CompiledPredFlag;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-06-06 12:54:02 +01:00
|
|
|
if (p->cs.p_code.FirstClause == NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (!(pflags & DynamicPredFlag)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
add_first_static(p, cp, spy_flag);
|
|
|
|
/* make sure we have a place to jump to */
|
2002-10-14 17:25:38 +01:00
|
|
|
if (p->OpcodeOfPred == UNDEF_OPCODE ||
|
2015-10-22 00:53:26 +01:00
|
|
|
p->OpcodeOfPred == FAIL_OPCODE) { /* log updates */
|
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred;
|
|
|
|
p->OpcodeOfPred = ((yamop *)(p->CodeOfPred))->opc;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
add_first_dynamic(p, cp, spy_flag);
|
|
|
|
}
|
|
|
|
} else if (mode == asserta) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & DynamicPredFlag)
|
2001-04-09 20:54:03 +01:00
|
|
|
asserta_dynam_clause(p, cp);
|
|
|
|
else
|
|
|
|
asserta_stat_clause(p, cp, spy_flag);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (pflags & DynamicPredFlag)
|
2001-04-09 20:54:03 +01:00
|
|
|
assertz_dynam_clause(p, cp);
|
|
|
|
else {
|
|
|
|
assertz_stat_clause(p, cp, spy_flag);
|
|
|
|
if (p->OpcodeOfPred != INDEX_OPCODE &&
|
2015-10-22 00:53:26 +01:00
|
|
|
p->OpcodeOfPred != Yap_opcode(_spy_pred)) {
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->OpcodeOfPred = ((yamop *)(p->CodeOfPred))->opc;
|
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2007-11-26 23:43:10 +00:00
|
|
|
if (p->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(p->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
p->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
p->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(32, p);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & LogUpdatePredFlag) {
|
2009-08-20 03:53:49 +01:00
|
|
|
LogUpdClause *cl = (LogUpdClause *)ClauseCodeToLogUpdClause(cp);
|
2009-08-12 16:00:38 +01:00
|
|
|
tf = MkDBRefTerm((DBRef)cl);
|
2011-04-14 18:51:11 +01:00
|
|
|
#if MULTIPLE_STACKS
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2009-08-12 16:00:38 +01:00
|
|
|
INC_CLREF_COUNT(cl);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2009-08-12 16:00:38 +01:00
|
|
|
}
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2013-11-05 17:59:19 +00:00
|
|
|
tf = Yap_MkStaticRefTerm(ClauseCodeToStaticClause(cp), p);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2016-08-01 23:48:43 +01:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "add %s/%ld %p",
|
|
|
|
RepAtom(at)->StrOfAE, Arity);
|
2016-01-03 01:27:36 +00:00
|
|
|
if (mod == PROLOG_MODULE)
|
|
|
|
mod = TermProlog;
|
2004-10-06 17:55:48 +01:00
|
|
|
if (pflags & MultiFileFlag) {
|
|
|
|
/* add Info on new clause for multifile predicates to the DB */
|
|
|
|
Term t[5], tn;
|
2015-10-22 00:53:26 +01:00
|
|
|
t[0] = MkAtomTerm(Yap_ConsultingFile(PASS_REGS1));
|
2004-10-06 17:55:48 +01:00
|
|
|
t[1] = MkAtomTerm(at);
|
|
|
|
t[2] = MkIntegerTerm(Arity);
|
|
|
|
t[3] = mod;
|
|
|
|
t[4] = tf;
|
2015-10-22 00:53:26 +01:00
|
|
|
tn = Yap_MkApplTerm(FunctorMultiFileClause, 5, t);
|
|
|
|
Yap_Recordz(AtomMultiFile, tn);
|
2004-10-06 17:55:48 +01:00
|
|
|
}
|
2016-05-12 11:48:39 +01:00
|
|
|
if (t4ref && *t4ref != TermNil) {
|
|
|
|
if (!Yap_unify(*t4ref, tf)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-03 01:27:36 +00:00
|
|
|
return true;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_EraseMegaClause(yamop *cl, PredEntry *ap) {
|
2004-09-27 21:45:04 +01:00
|
|
|
/* just make it fail */
|
|
|
|
cl->opc = Yap_opcode(_op_fail);
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_EraseStaticClause(StaticClause *cl, PredEntry *ap, Term mod) {
|
2003-11-26 18:36:35 +00:00
|
|
|
|
|
|
|
/* ok, first I need to find out the parent predicate */
|
2006-03-20 19:51:44 +00:00
|
|
|
if (ap->PredFlags & MegaClausePredFlag) {
|
|
|
|
split_megaclause(ap);
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (ap->PredFlags & IndexedPredFlag)
|
|
|
|
RemoveIndexation(ap);
|
|
|
|
ap->cs.p_code.NOfClauses--;
|
|
|
|
if (ap->cs.p_code.FirstClause == cl->ClCode) {
|
|
|
|
/* got rid of first clause */
|
|
|
|
if (ap->cs.p_code.LastClause == cl->ClCode) {
|
|
|
|
/* got rid of all clauses */
|
|
|
|
ap->cs.p_code.LastClause = ap->cs.p_code.FirstClause = NULL;
|
|
|
|
ap->OpcodeOfPred = UNDEF_OPCODE;
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
|
|
|
yamop *ncl = cl->ClNext->ClCode;
|
|
|
|
ap->cs.p_code.FirstClause = ncl;
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = ncl;
|
2003-11-26 18:36:35 +00:00
|
|
|
ap->OpcodeOfPred = ncl->opc;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StaticClause *pcl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause),
|
2015-10-22 00:53:26 +01:00
|
|
|
*ocl = NULL;
|
2003-11-26 18:36:35 +00:00
|
|
|
|
|
|
|
while (pcl != cl) {
|
|
|
|
ocl = pcl;
|
|
|
|
pcl = pcl->ClNext;
|
|
|
|
}
|
2015-11-05 15:11:57 +00:00
|
|
|
if (ocl) {
|
|
|
|
ocl->ClNext = cl->ClNext;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause) {
|
2003-11-26 18:36:35 +00:00
|
|
|
ap->cs.p_code.LastClause = ocl->ClCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ap->cs.p_code.NOfClauses == 1) {
|
2016-01-03 01:27:36 +00:00
|
|
|
assert(ap->cs.p_code.FirstClause);
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause;
|
|
|
|
ap->OpcodeOfPred = ap->cs.p_code.TrueCodeOfPred->opc;
|
2003-11-26 18:36:35 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (cl->ClFlags & HasBlobsMask || Yap_static_in_use(ap, TRUE)) {
|
2006-03-24 16:26:31 +00:00
|
|
|
LOCK(DeadStaticClausesLock);
|
2006-03-22 20:07:28 +00:00
|
|
|
cl->ClNext = DeadStaticClauses;
|
|
|
|
DeadStaticClauses = cl;
|
2006-03-24 16:26:31 +00:00
|
|
|
UNLOCK(DeadStaticClausesLock);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
2012-03-09 11:46:34 +00:00
|
|
|
Yap_InformOfRemoval(cl);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2003-11-26 18:36:35 +00:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
|
|
|
if (ap->cs.p_code.NOfClauses == 0) {
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (ap->cs.p_code.NOfClauses > 1) {
|
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
(yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
} else if (ap->PredFlags &
|
|
|
|
(SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
(yamop *)(&(ap->OpcodeOfPred));
|
2003-11-26 18:36:35 +00:00
|
|
|
} else {
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (ap->PredFlags & LogUpdatePredFlag &&
|
2011-03-15 09:08:09 +00:00
|
|
|
!(ap->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
ap->ModuleOfPred != IDB_MODULE) {
|
2007-11-26 23:43:10 +00:00
|
|
|
ap->OpcodeOfPred = LOCKPRED_OPCODE;
|
2015-04-13 13:28:17 +01:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-11-26 18:36:35 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_add_logupd_clause(PredEntry *pe, LogUpdClause *cl, int mode) {
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *cp = cl->ClCode;
|
|
|
|
|
|
|
|
if (pe->PredFlags & IndexedPredFlag) {
|
|
|
|
Yap_AddClauseToIndex(pe, cp, mode == asserta);
|
|
|
|
}
|
|
|
|
if (pe->cs.p_code.FirstClause == NULL) {
|
|
|
|
add_first_static(pe, cp, FALSE);
|
|
|
|
/* make sure we have a place to jump to */
|
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE ||
|
2015-10-22 00:53:26 +01:00
|
|
|
pe->OpcodeOfPred == FAIL_OPCODE) { /* log updates */
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(pe->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
pe->ModuleOfPred != IDB_MODULE) {
|
|
|
|
pe->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
2007-11-26 23:43:10 +00:00
|
|
|
} else {
|
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred;
|
|
|
|
pe->OpcodeOfPred = ((yamop *)(pe->CodeOfPred))->opc;
|
2015-04-13 13:28:17 +01:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (mode == asserta) {
|
|
|
|
asserta_stat_clause(pe, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_stat_clause(pe, cp, FALSE);
|
|
|
|
}
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
static Int p_compile(USES_REGS1) { /* '$compile'(+C,+Flags,+C0,-Ref) */
|
2015-10-22 00:53:26 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term t1 = Deref(ARG2);
|
|
|
|
Term mod = Deref(ARG4);
|
|
|
|
yamop *code_adr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-02-08 04:05:39 +00:00
|
|
|
if (IsVarTerm(t1) || !IsAtomicTerm(t1))
|
2016-02-21 11:30:13 +00:00
|
|
|
return false;
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2016-02-21 11:30:13 +00:00
|
|
|
return false;
|
2011-05-02 23:29:48 +01:00
|
|
|
/* separate assert in current file from reconsult
|
2011-05-04 11:10:20 +01:00
|
|
|
if (mode == assertz && LOCAL_consult_level && mod == CurrentModule)
|
2015-04-13 13:28:17 +01:00
|
|
|
mode = consult;
|
2011-05-02 23:29:48 +01:00
|
|
|
*/
|
2015-10-22 00:53:26 +01:00
|
|
|
code_adr = Yap_cclause(t, 5, mod,
|
|
|
|
Deref(ARG3)); /* vsc: give the number of arguments to
|
|
|
|
cclause() in case there is a overflow */
|
|
|
|
t = Deref(ARG1); /* just in case there was an heap overflow */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!LOCAL_ErrorMessage) {
|
2016-01-31 10:13:51 +00:00
|
|
|
YAPEnterCriticalSection();
|
2016-02-21 11:30:13 +00:00
|
|
|
Yap_addclause(t, code_adr, t1, mod, &ARG5);
|
2016-01-31 10:13:51 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2015-04-13 13:28:17 +01:00
|
|
|
}
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage) {
|
2016-10-20 04:44:59 +01:00
|
|
|
Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2015-12-15 09:28:43 +00:00
|
|
|
return true;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
Atom Yap_ConsultingFile(USES_REGS1) {
|
2015-09-29 23:08:10 +01:00
|
|
|
int sno;
|
|
|
|
if ((sno = Yap_CheckAlias(AtomLoopStream)) >= 0) {
|
|
|
|
// if(sno ==0)
|
|
|
|
// return(AtomUserIn);
|
2015-10-22 00:53:26 +01:00
|
|
|
return StreamFullName(sno);
|
2015-09-29 23:08:10 +01:00
|
|
|
}
|
2015-12-15 09:28:43 +00:00
|
|
|
if (LOCAL_SourceFileName != NULL) {
|
|
|
|
return LOCAL_SourceFileName;
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_consult_level == 0) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (AtomUser);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (Yap_ULookupAtom(LOCAL_ConsultBase[2].filename));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* consult file *file*, *mode* may be one of either consult or reconsult */
|
2015-10-22 00:53:26 +01:00
|
|
|
static void init_consult(int mode, const unsigned char *file) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
if (!LOCAL_ConsultSp) {
|
2010-03-21 22:12:42 +00:00
|
|
|
InitConsultStack();
|
|
|
|
}
|
2016-07-31 05:15:11 +01:00
|
|
|
if (LOCAL_ConsultSp >= LOCAL_ConsultLow + 6) {
|
|
|
|
expand_consult();
|
2016-05-14 11:27:53 +01:00
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultSp--;
|
|
|
|
LOCAL_ConsultSp->filename = file;
|
|
|
|
LOCAL_ConsultSp--;
|
|
|
|
LOCAL_ConsultSp->mode = mode;
|
|
|
|
LOCAL_ConsultSp--;
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_ConsultSp->c = (LOCAL_ConsultBase - LOCAL_ConsultSp);
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp;
|
2011-03-30 15:32:59 +01:00
|
|
|
#if !defined(YAPOR) && !defined(YAPOR_SBA)
|
2015-10-22 00:53:26 +01:00
|
|
|
/* if (LOCAL_consult_level == 0)
|
|
|
|
do_toggle_static_predicates_in_use(TRUE); */
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_consult_level++;
|
|
|
|
LOCAL_LastAssertedPred = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_init_consult(int mode, const char *file) {
|
|
|
|
init_consult(mode, (const unsigned char *)file);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
|
|
|
|
Term t;
|
|
|
|
char *smode = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
|
|
|
|
int mode;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
mode = strcmp("consult", (char *)smode);
|
2015-09-21 23:05:36 +01:00
|
|
|
init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->UStrOfAE);
|
2011-05-04 10:11:41 +01:00
|
|
|
t = MkIntTerm(LOCAL_consult_level);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG3, t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_showconslultlev(USES_REGS1) {
|
|
|
|
Term t;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-05-04 10:11:41 +01:00
|
|
|
t = MkIntTerm(LOCAL_consult_level);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG1, t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void end_consult(USES_REGS1) {
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultSp = LOCAL_ConsultBase;
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_ConsultBase = LOCAL_ConsultSp + LOCAL_ConsultSp->c;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ConsultSp += 3;
|
|
|
|
LOCAL_consult_level--;
|
|
|
|
LOCAL_LastAssertedPred = NULL;
|
2011-03-30 15:32:59 +01:00
|
|
|
#if !defined(YAPOR) && !defined(YAPOR_SBA)
|
2015-10-22 00:53:26 +01:00
|
|
|
/* if (LOCAL_consult_level == 0)
|
|
|
|
do_toggle_static_predicates_in_use(FALSE);*/
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_end_consult(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-10-22 00:53:26 +01:00
|
|
|
end_consult(PASS_REGS1);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_endconsult(USES_REGS1) { /* '$end_consult' */
|
|
|
|
end_consult(PASS_REGS1);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void purge_clauses(PredEntry *pred) {
|
2012-06-21 16:47:19 +01:00
|
|
|
if (pred->PredFlags & UDIPredFlag) {
|
|
|
|
Yap_udi_abolish(pred);
|
|
|
|
}
|
2007-12-18 17:46:58 +00:00
|
|
|
if (pred->cs.p_code.NOfClauses) {
|
|
|
|
if (pred->PredFlags & IndexedPredFlag)
|
|
|
|
RemoveIndexation(pred);
|
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
2015-10-22 00:53:26 +01:00
|
|
|
retract_all(pred, Yap_static_in_use(pred, TRUE));
|
2007-12-18 17:46:58 +00:00
|
|
|
}
|
2004-02-11 01:20:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_Abolish(PredEntry *pred) {
|
2004-02-11 01:20:56 +00:00
|
|
|
purge_clauses(pred);
|
2013-11-25 18:19:44 +00:00
|
|
|
pred->src.OwnerFile = AtomNil;
|
2004-02-11 01:20:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_purge_clauses(USES_REGS1) { /* '$purge_clauses'(+Func) */
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
MegaClause *before = DeadMegaClauses;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2004-02-11 01:20:56 +00:00
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomNil));
|
|
|
|
if (IsVarTerm(t))
|
2004-02-12 12:37:12 +00:00
|
|
|
return FALSE;
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
|
|
|
return FALSE;
|
2004-02-11 01:20:56 +00:00
|
|
|
}
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
pred = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
} else if (IsApplTerm(t)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-11 01:20:56 +00:00
|
|
|
pred = RepPredProp(PredPropByFunc(fun, mod));
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(21, pred);
|
2004-02-11 01:20:56 +00:00
|
|
|
if (pred->PredFlags & StandardPredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(33, pred);
|
2004-02-11 01:20:56 +00:00
|
|
|
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, t, "assert/1");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
purge_clauses(pred);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(34, pred);
|
2012-04-23 23:28:41 +01:00
|
|
|
/* try to use the garbage collector to recover the mega clause,
|
|
|
|
in case the objs pointing to it are dead themselves */
|
|
|
|
if (DeadMegaClauses != before) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_gc(2, ENV, gc_P(P, CP))) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
2012-04-23 23:28:41 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_sys_export(USES_REGS1) { /* '$set_spy'(+Fun,+M) */
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t, mod;
|
2014-04-06 17:06:19 +01:00
|
|
|
|
|
|
|
t = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
pred = RepPredProp(Yap_PredPropByAtomNonThreadLocal(at, mod));
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
pred = RepPredProp(Yap_PredPropByFunctorNonThreadLocal(fun, mod));
|
|
|
|
} else {
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(100, pred);
|
2014-11-25 12:03:48 +00:00
|
|
|
pred->PredFlags |= SysExportPredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(100, pred);
|
2014-04-06 17:06:19 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
MANAGING SPY-POINTS
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
******************************************************************/
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_no_trace(USES_REGS1) { /* '$undefined'(P,Mod) */
|
|
|
|
PredEntry *pe;
|
2013-12-11 01:05:51 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "undefined/1");
|
2013-12-11 01:05:51 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2016-01-04 14:11:09 +00:00
|
|
|
return true;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(36, pe);
|
2016-01-04 17:18:43 +00:00
|
|
|
if (pe->PredFlags & (NoTracePredFlag | HiddenPredFlag)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(57, pe);
|
2016-01-04 14:11:09 +00:00
|
|
|
return true;
|
2013-12-11 01:05:51 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(59, pe);
|
2016-01-04 14:11:09 +00:00
|
|
|
return false;
|
2013-12-11 01:05:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_set_no_trace(USES_REGS1) { /* '$set_no_trace'(+Fun,+M) */
|
|
|
|
PredEntry *pe;
|
2013-12-11 01:05:51 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "undefined/1");
|
2013-12-11 01:05:51 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(36, pe);
|
2014-11-25 12:03:48 +00:00
|
|
|
pe->PredFlags |= NoTracePredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(57, pe);
|
2013-12-11 01:05:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
int Yap_SetNoTrace(char *name, arity_t arity, Term tmod) {
|
|
|
|
PredEntry *pe;
|
2013-12-11 01:05:51 +00:00
|
|
|
|
|
|
|
if (arity == 0) {
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(MkAtomTerm(Yap_LookupAtom(name)), tmod, "no_trace");
|
2013-12-11 01:05:51 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
pe = RepPredProp(
|
|
|
|
PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(name), arity), tmod));
|
2013-12-11 01:05:51 +00:00
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(36, pe);
|
2014-11-25 12:03:48 +00:00
|
|
|
pe->PredFlags |= NoTracePredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(57, pe);
|
2013-12-11 01:05:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_setspy(USES_REGS1) { /* '$set_spy'(+Fun,+M) */
|
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
pred_flags_t fg;
|
|
|
|
Term t, mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
at = AtomSpy;
|
2015-10-22 00:53:26 +01:00
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1), 0));
|
2001-10-30 16:42:05 +00:00
|
|
|
SpyCode = pred;
|
2001-04-09 20:54:03 +01:00
|
|
|
t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = Deref(ARG2);
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(t))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom at = AtomOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByAtomNonThreadLocal(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByFunctorNonThreadLocal(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(22, pred);
|
|
|
|
restart_spy:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pred->PredFlags & (CPredFlag | SafePredFlag)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(35, pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
|
|
|
|
UNLOCKPE(36, pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (pred->OpcodeOfPred == INDEX_OPCODE) {
|
2005-04-10 05:01:15 +01:00
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < pred->ArityOfPE; i++) {
|
2015-10-22 00:53:26 +01:00
|
|
|
XREGS[i + 1] = MkVarTerm();
|
2005-04-10 05:01:15 +01:00
|
|
|
}
|
2010-01-29 15:21:00 +00:00
|
|
|
IPred(pred, 0, CP);
|
2001-04-09 20:54:03 +01:00
|
|
|
goto restart_spy;
|
|
|
|
}
|
|
|
|
fg = pred->PredFlags;
|
|
|
|
if (fg & DynamicPredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
pred->OpcodeOfPred = ((yamop *)(pred->CodeOfPred))->opc =
|
|
|
|
Yap_opcode(_spy_or_trymark);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
pred->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2015-04-13 13:28:17 +01:00
|
|
|
pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
pred->PredFlags |= SpiedPredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(37, pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_rmspy(USES_REGS1) { /* '$rm_spy'(+T,+Mod) */
|
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t;
|
|
|
|
Term mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = Deref(ARG2);
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
at = AtomOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByAtomNonThreadLocal(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-11 13:33:19 +00:00
|
|
|
pred = RepPredProp(Yap_PredPropByFunctorNonThreadLocal(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(23, pred);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!(pred->PredFlags & SpiedPredFlag)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(38, pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#if THREADS
|
2013-02-15 16:30:53 +00:00
|
|
|
if (pred->PredFlags & ThreadLocalPredFlag) {
|
2004-02-11 13:33:19 +00:00
|
|
|
pred->OpcodeOfPred = Yap_opcode(_thread_local);
|
2007-11-26 23:43:10 +00:00
|
|
|
pred->PredFlags ^= SpiedPredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(39, pred);
|
2007-11-26 23:43:10 +00:00
|
|
|
return TRUE;
|
2015-04-13 13:28:17 +01:00
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!(pred->PredFlags & (CountPredFlag | ProfiledPredFlag))) {
|
2009-06-22 17:12:56 +01:00
|
|
|
if (!(pred->PredFlags & DynamicPredFlag)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2009-06-22 17:12:56 +01:00
|
|
|
if (pred->PredFlags & LogUpdatePredFlag &&
|
2015-10-22 00:53:26 +01:00
|
|
|
!(pred->PredFlags & ThreadLocalPredFlag) &&
|
|
|
|
pred->ModuleOfPred != IDB_MODULE) {
|
|
|
|
pred->OpcodeOfPred = LOCKPRED_OPCODE;
|
|
|
|
pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred));
|
2009-06-22 17:12:56 +01:00
|
|
|
} else {
|
2007-11-26 23:43:10 +00:00
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
pred->CodeOfPred = pred->cs.p_code.TrueCodeOfPred;
|
|
|
|
pred->OpcodeOfPred = pred->CodeOfPred->opc;
|
2007-11-26 23:43:10 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2009-06-22 17:12:56 +01:00
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2009-06-22 17:12:56 +01:00
|
|
|
} else if (pred->OpcodeOfPred == Yap_opcode(_spy_or_trymark)) {
|
|
|
|
pred->OpcodeOfPred = Yap_opcode(_try_and_mark);
|
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(39, pred);
|
2009-06-22 17:12:56 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
pred->PredFlags ^= SpiedPredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(40, pred);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
INFO ABOUT PREDICATES
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
******************************************************************/
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
static Int
|
2015-10-22 00:53:26 +01:00
|
|
|
p_number_of_clauses(USES_REGS1) { /* '$number_of_clauses'(Predicate,M,N) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
int ncl = 0;
|
2015-10-22 00:53:26 +01:00
|
|
|
Prop pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
2001-10-03 14:39:16 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = Yap_GetPredPropByAtom(a, mod);
|
2001-10-03 14:39:16 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
register Functor f = FunctorOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = Yap_GetPredPropByFunc(f, mod);
|
2003-05-01 22:07:11 +01:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(24, RepPredProp(pe));
|
2003-05-01 22:07:11 +01:00
|
|
|
ncl = RepPredProp(pe)->cs.p_code.NOfClauses;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(41, RepPredProp(pe));
|
2003-05-01 22:07:11 +01:00
|
|
|
return (Yap_unify_constant(ARG3, MkIntegerTerm(ncl)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_new_multifile(USES_REGS1) { /* '$new_multifile'(+N,+Ar,+Mod) */
|
|
|
|
Atom at;
|
|
|
|
arity_t arity;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG3);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t))
|
|
|
|
at = AtomOfTerm(t);
|
|
|
|
else
|
|
|
|
return (FALSE);
|
|
|
|
t = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsIntTerm(t))
|
|
|
|
arity = IntOfTerm(t);
|
|
|
|
else
|
2005-02-08 04:05:39 +00:00
|
|
|
return FALSE;
|
2015-04-13 13:28:17 +01:00
|
|
|
if (arity == 0)
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = RepPredProp(PredPropByAtom(at, mod));
|
2015-04-13 13:28:17 +01:00
|
|
|
else
|
2015-10-22 00:53:26 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, arity), mod));
|
|
|
|
PELOCK(26, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
if (pe->PredFlags &
|
|
|
|
(UserCPredFlag | CArgsPredFlag | NumberDBPredFlag | AtomDBPredFlag |
|
|
|
|
TestPredFlag | AsmPredFlag | CPredFlag | BinaryPredFlag)) {
|
2015-12-15 09:28:43 +00:00
|
|
|
UNLOCKPE(26, pe);
|
|
|
|
addcl_permission_error(RepAtom(at), arity, FALSE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (pe->PredFlags & MultiFileFlag) {
|
|
|
|
UNLOCKPE(26, pe);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (pe->cs.p_code.NOfClauses) {
|
|
|
|
UNLOCKPE(26, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
addcl_permission_error(RepAtom(at), arity, FALSE);
|
|
|
|
return false;
|
2015-12-15 09:28:43 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags |= MultiFileFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
/* mutifile-predicates are weird, they do not seat really on the default
|
|
|
|
* module */
|
|
|
|
if (!(pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag))) {
|
2003-11-26 18:36:35 +00:00
|
|
|
/* static */
|
2015-10-22 00:53:26 +01:00
|
|
|
pe->PredFlags |= (SourcePredFlag | CompiledPredFlag);
|
2003-11-26 18:36:35 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
pe->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1);
|
2016-07-31 05:15:11 +01:00
|
|
|
if (pe->cs.p_code.NOfClauses == 0) {
|
|
|
|
pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred = FAILCODE;
|
|
|
|
pe->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(43, pe);
|
2015-12-15 09:28:43 +00:00
|
|
|
return true;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_multifile(USES_REGS1) { /* '$is_multifile'(+S,+Mod) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_multifile");
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(27, pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
out = (pe->PredFlags & MultiFileFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(44, pe);
|
|
|
|
return (out);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2016-03-05 12:21:58 +00:00
|
|
|
static Int new_system_predicate(
|
2016-01-03 01:27:36 +00:00
|
|
|
USES_REGS1) { /* '$new_system_predicate'(+N,+Ar,+Mod) */
|
2015-10-22 00:53:26 +01:00
|
|
|
Atom at;
|
|
|
|
arity_t arity;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG3);
|
2014-04-24 08:26:31 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t))
|
|
|
|
at = AtomOfTerm(t);
|
|
|
|
else
|
|
|
|
return (FALSE);
|
|
|
|
t = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsIntTerm(t))
|
|
|
|
arity = IntOfTerm(t);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2015-04-13 13:28:17 +01:00
|
|
|
if (arity == 0)
|
2014-04-24 08:26:31 +01:00
|
|
|
pe = RepPredProp(PredPropByAtom(at, mod));
|
2015-04-13 13:28:17 +01:00
|
|
|
else
|
2015-10-22 00:53:26 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, arity), mod));
|
|
|
|
PELOCK(26, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
if (pe->PredFlags & (LogUpdatePredFlag | DynamicPredFlag | MultiFileFlag)) {
|
|
|
|
UNLOCKPE(43, pe);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-05 12:21:58 +00:00
|
|
|
pe->PredFlags |= (StandardPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(43, pe);
|
2016-03-05 12:21:58 +00:00
|
|
|
return (true);
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
static Int
|
|
|
|
p_is_system_predicate(USES_REGS1) { /* '$is_multifile'(+S,+Mod) */
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2014-04-24 08:26:31 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "system_predicate");
|
2016-03-05 12:21:58 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2014-04-24 08:26:31 +01:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(27, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
out = (pe->PredFlags & SystemPredFlags);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(44, pe);
|
|
|
|
return (out);
|
2014-04-24 08:26:31 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_thread_local(USES_REGS1) { /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2014-07-16 17:55:16 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_log_updatable");
|
2014-07-16 17:55:16 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(27, pe);
|
2014-07-16 17:55:16 +01:00
|
|
|
out = (pe->PredFlags & ThreadLocalPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
|
|
|
return (out);
|
2014-07-16 17:55:16 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_log_updatable(USES_REGS1) { /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_log_updatable");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(27, pe);
|
2003-08-27 14:37:10 +01:00
|
|
|
out = (pe->PredFlags & LogUpdatePredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
|
|
|
return (out);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_source(USES_REGS1) { /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2003-11-21 16:56:20 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(28, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
if (pe->PredFlags & SystemPredFlags) {
|
|
|
|
UNLOCKPE(46, pe);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
out = (pe->PredFlags & (SourcePredFlag | LogUpdatePredFlag |
|
|
|
|
MegaClausePredFlag | DynamicPredFlag));
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(46, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
return out;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_exo(USES_REGS1) { /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2013-01-11 16:45:14 +00:00
|
|
|
MegaClause *mcl;
|
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_exo");
|
2013-01-11 16:45:14 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(28, pe);
|
2013-01-11 16:45:14 +00:00
|
|
|
out = (pe->PredFlags & MegaClausePredFlag);
|
|
|
|
if (out) {
|
2015-10-22 00:53:26 +01:00
|
|
|
mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
2013-01-11 16:45:14 +00:00
|
|
|
out = mcl->ClFlags & ExoMask;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(46, pe);
|
|
|
|
return (out);
|
2013-01-11 16:45:14 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 17:38:08 +00:00
|
|
|
static Int owner_file(USES_REGS1) { /* '$owner_file'(+P,M,F) */
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Atom owner;
|
2010-02-28 22:24:51 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
2010-02-28 22:24:51 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2016-03-05 17:38:08 +00:00
|
|
|
return false;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(29, pe);
|
2010-02-28 22:24:51 +00:00
|
|
|
if (pe->ModuleOfPred == IDB_MODULE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(47, pe);
|
2016-03-05 17:38:08 +00:00
|
|
|
return false;
|
2010-02-28 22:24:51 +00:00
|
|
|
}
|
|
|
|
if (pe->PredFlags & MultiFileFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(48, pe);
|
2016-03-05 17:38:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (is_system(pe) || is_foreign(pe)) {
|
|
|
|
UNLOCKPE(48, pe);
|
|
|
|
return false;
|
2010-02-28 22:24:51 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
owner = pe->src.OwnerFile;
|
|
|
|
UNLOCKPE(49, pe);
|
2016-03-05 17:38:08 +00:00
|
|
|
if (owner == AtomNil || owner == NULL)
|
|
|
|
return false;
|
2010-02-28 22:24:51 +00:00
|
|
|
return Yap_unify(ARG3, MkAtomTerm(owner));
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_set_owner_file(USES_REGS1) { /* '$owner_file'(+P,M,F) */
|
|
|
|
PredEntry *pe;
|
2014-10-02 14:21:43 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
2014-10-02 14:21:43 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(29, pe);
|
2014-10-02 14:21:43 +01:00
|
|
|
if (pe->ModuleOfPred == IDB_MODULE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(47, pe);
|
2014-10-02 14:21:43 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pe->PredFlags & MultiFileFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(48, pe);
|
2014-10-02 14:21:43 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pe->src.OwnerFile = AtomOfTerm(Deref(ARG3));
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(49, pe);
|
2014-10-02 14:21:43 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-31 05:15:11 +01:00
|
|
|
static Int p_mk_d(USES_REGS1) { /* '$make_dynamic'(+P) */
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *pe;
|
2016-07-31 05:15:11 +01:00
|
|
|
Atom at;
|
|
|
|
arity_t arity;
|
2008-04-29 00:02:32 +01:00
|
|
|
|
2016-07-31 05:15:11 +01:00
|
|
|
pe = new_pred(Deref(ARG1), Deref(ARG2), "dynamic");
|
2008-04-29 00:02:32 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(30, pe);
|
2016-07-31 05:15:11 +01:00
|
|
|
arity = pe->ArityOfPE;
|
|
|
|
if (arity == 0)
|
|
|
|
at = (Atom)pe->FunctorOfPred;
|
|
|
|
else
|
|
|
|
at = NameOfFunctor(pe->FunctorOfPred);
|
|
|
|
|
|
|
|
if (pe->PredFlags &
|
|
|
|
(UserCPredFlag | CArgsPredFlag | NumberDBPredFlag | AtomDBPredFlag |
|
|
|
|
TestPredFlag | AsmPredFlag | CPredFlag | BinaryPredFlag)) {
|
|
|
|
UNLOCKPE(30, pe);
|
|
|
|
addcl_permission_error(RepAtom(at), arity, FALSE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (pe->PredFlags & LogUpdatePredFlag) {
|
|
|
|
UNLOCKPE(26, pe);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (pe->PredFlags & DynamicPredFlag) {
|
|
|
|
UNLOCKPE(26, pe);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (pe->cs.p_code.NOfClauses != 0) {
|
|
|
|
UNLOCKPE(26, pe);
|
|
|
|
addcl_permission_error(RepAtom(at), arity, FALSE);
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-29 00:02:32 +01:00
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
|
|
|
pe->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
pe->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1);
|
2016-07-31 05:15:11 +01:00
|
|
|
pe->PredFlags |= LogUpdatePredFlag;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(50, pe);
|
2016-07-31 05:15:11 +01:00
|
|
|
return true;
|
2008-04-29 00:02:32 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_dynamic(USES_REGS1) { /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_dynamic");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(31, pe);
|
|
|
|
out = (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag));
|
|
|
|
UNLOCKPE(51, pe);
|
|
|
|
return (out);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_metapredicate(USES_REGS1) { /* '$is_metapredicate'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2004-12-05 05:01:45 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$is_meta");
|
2004-12-05 05:01:45 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(32, pe);
|
2004-12-05 05:01:45 +00:00
|
|
|
out = (pe->PredFlags & MetaPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(52, pe);
|
2004-12-05 05:01:45 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_pred_exists(USES_REGS1) { /* '$pred_exists'(+P,+M) */
|
|
|
|
PredEntry *pe;
|
|
|
|
bool out;
|
2002-10-14 17:25:38 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "$exists");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(34, pe);
|
|
|
|
if (pe->PredFlags & HiddenPredFlag) {
|
|
|
|
UNLOCKPE(54, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2004-02-22 00:35:07 +00:00
|
|
|
}
|
2002-10-14 17:25:38 +01:00
|
|
|
out = (pe->OpcodeOfPred != UNDEF_OPCODE);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(55, pe);
|
2004-02-22 00:35:07 +00:00
|
|
|
return out;
|
2002-10-14 17:25:38 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_set_pred_module(USES_REGS1) { /* '$set_pred_module'(+P,+Mod)
|
|
|
|
*/
|
|
|
|
PredEntry *pe;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), CurrentModule, "set_pred_module/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(35, pe);
|
2004-02-12 12:37:12 +00:00
|
|
|
pe->ModuleOfPred = Deref(ARG2);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(56, pe);
|
|
|
|
return (TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_set_pred_owner(USES_REGS1) { /* '$set_pred_module'(+P,+File)
|
|
|
|
*/
|
|
|
|
PredEntry *pe;
|
|
|
|
Term a2 = Deref(ARG2);
|
2014-09-22 18:09:23 +01:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), CurrentModule, "set_pred_module/1");
|
2014-09-22 18:09:23 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(35, pe);
|
|
|
|
if (pe->PredFlags &
|
|
|
|
(UserCPredFlag | CArgsPredFlag | NumberDBPredFlag | AtomDBPredFlag |
|
|
|
|
TestPredFlag | AsmPredFlag | CPredFlag | BinaryPredFlag)) {
|
|
|
|
UNLOCKPE(56, pe);
|
2014-09-22 18:09:23 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (IsVarTerm(a2)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, a2, "load_files/2");
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(56, pe);
|
2014-09-22 18:09:23 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(a2)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, a2, "load_files/2");
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(56, pe);
|
2014-09-22 18:09:23 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pe->src.OwnerFile = AtomOfTerm(a2);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(56, pe);
|
|
|
|
return (TRUE);
|
2014-09-22 18:09:23 +01:00
|
|
|
}
|
|
|
|
|
2016-07-31 05:15:11 +01:00
|
|
|
/**
|
|
|
|
* Set handler for undefined predicates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Int undefp_handler(USES_REGS1) { /* '$undefp_handler'(P,Mod) */
|
|
|
|
PredEntry *pe;
|
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "undefined/1");
|
2016-07-31 05:15:11 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return false;
|
|
|
|
PELOCK(59, pe);
|
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
|
|
|
UNLOCKPE(59, pe);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UndefCode = pe;
|
|
|
|
UNLOCKPE(59, pe);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_undefined(USES_REGS1) { /* '$undefined'(P,Mod) */
|
|
|
|
PredEntry *pe;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "undefined/1");
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(36, pe);
|
|
|
|
if (pe->PredFlags & (CPredFlag | UserCPredFlag | TestPredFlag | AsmPredFlag |
|
|
|
|
DynamicPredFlag | LogUpdatePredFlag | TabledPredFlag)) {
|
|
|
|
UNLOCKPE(57, pe);
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(58, pe);
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(59, pe);
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this predicate should only be called when all clauses for the dynamic
|
2015-04-13 13:28:17 +01:00
|
|
|
* predicate were remove, otherwise chaos will follow!!
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_kill_dynamic(USES_REGS1) { /* '$kill_dynamic'(P,M) */
|
|
|
|
PredEntry *pe;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "kill_dynamic/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(37, pe);
|
|
|
|
if (!(pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag))) {
|
|
|
|
UNLOCKPE(60, pe);
|
2008-04-29 00:02:32 +01:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.LastClause != pe->cs.p_code.FirstClause) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(61, pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2006-03-20 19:51:44 +00:00
|
|
|
pe->cs.p_code.LastClause = pe->cs.p_code.FirstClause = NULL;
|
2008-06-02 18:20:28 +01:00
|
|
|
pe->OpcodeOfPred = UNDEF_OPCODE;
|
2015-10-22 00:53:26 +01:00
|
|
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred =
|
|
|
|
(yamop *)(&(pe->OpcodeOfPred));
|
2015-12-15 09:28:43 +00:00
|
|
|
pe->PredFlags = 0;
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(62, pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_optimizer_on(USES_REGS1) { /* '$optimizer_on' */
|
2001-04-09 20:54:03 +01:00
|
|
|
optimizer_on = TRUE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_optimizer_off(USES_REGS1) { /* '$optimizer_off' */
|
2001-04-09 20:54:03 +01:00
|
|
|
optimizer_on = FALSE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_profiled(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
char *s;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Term ta;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
if (trueGlobalPrologFlag(PROFILING_FLAG))
|
2015-10-22 00:53:26 +01:00
|
|
|
ta = MkAtomTerm(AtomOn);
|
|
|
|
else
|
|
|
|
ta = MkAtomTerm(AtomOff);
|
|
|
|
YapBind((CELL *)t, ta);
|
|
|
|
return (TRUE);
|
|
|
|
} else if (!IsAtomTerm(t))
|
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom(AtomOfTerm(t))->StrOfAE;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (strcmp(s, "on") == 0) {
|
2015-09-21 23:05:36 +01:00
|
|
|
Yap_InitComma();
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
|
|
|
} else if (strcmp(s, "off") == 0) {
|
2015-09-21 23:05:36 +01:00
|
|
|
PROFILING = FALSE;
|
|
|
|
Yap_InitComma();
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
2002-02-26 15:51:54 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2002-02-26 17:49:09 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_profile_info(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
Term mod = Deref(ARG1);
|
|
|
|
Term tfun = Deref(ARG2);
|
|
|
|
Term out;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term p[3];
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(tfun)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
} else if (IsApplTerm(tfun)) {
|
|
|
|
Functor f = FunctorOfTerm(tfun);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(f, mod));
|
|
|
|
} else if (IsAtomTerm(tfun)) {
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(tfun), mod));
|
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2006-03-24 16:26:31 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
LOCK(pe->StatisticsForPred->lock);
|
|
|
|
if (!(pe->StatisticsForPred->NOfEntries)) {
|
|
|
|
UNLOCK(pe->StatisticsForPred->lock);
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2006-03-24 16:26:31 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
p[0] = Yap_MkULLIntTerm(pe->StatisticsForPred->NOfEntries);
|
|
|
|
p[1] = Yap_MkULLIntTerm(pe->StatisticsForPred->NOfHeadSuccesses);
|
|
|
|
p[2] = Yap_MkULLIntTerm(pe->StatisticsForPred->NOfRetries);
|
|
|
|
UNLOCK(pe->StatisticsForPred->lock);
|
2015-10-22 00:53:26 +01:00
|
|
|
out = Yap_MkApplTerm(Yap_MkFunctor(AtomProfile, 3), 3, p);
|
|
|
|
return (Yap_unify(ARG3, out));
|
2006-03-24 16:26:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_profile_reset(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
Term mod = Deref(ARG1);
|
|
|
|
Term tfun = Deref(ARG2);
|
|
|
|
PredEntry *pe;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(tfun)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
} else if (IsApplTerm(tfun)) {
|
|
|
|
Functor f = FunctorOfTerm(tfun);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2006-03-24 16:26:31 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(f, mod));
|
|
|
|
} else if (IsAtomTerm(tfun)) {
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(tfun), mod));
|
2006-03-24 16:26:31 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2006-03-24 16:26:31 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
LOCK(pe->StatisticsForPred->lock);
|
|
|
|
pe->StatisticsForPred->NOfEntries = 0;
|
|
|
|
pe->StatisticsForPred->NOfHeadSuccesses = 0;
|
|
|
|
pe->StatisticsForPred->NOfRetries = 0;
|
|
|
|
UNLOCK(pe->StatisticsForPred->lock);
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
2006-03-24 16:26:31 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_is_call_counted(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
char *s;
|
2002-12-10 14:36:22 +00:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Term ta;
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (CALL_COUNTING)
|
|
|
|
ta = MkAtomTerm(AtomOn);
|
|
|
|
else
|
|
|
|
ta = MkAtomTerm(AtomOff);
|
|
|
|
YapBind((CELL *)t, ta);
|
|
|
|
return (TRUE);
|
|
|
|
} else if (!IsAtomTerm(t))
|
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom(AtomOfTerm(t))->StrOfAE;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (strcmp(s, "on") == 0) {
|
2015-09-21 23:05:36 +01:00
|
|
|
CALL_COUNTING = TRUE;
|
|
|
|
Yap_InitComma();
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
|
|
|
} else if (strcmp(s, "off") == 0) {
|
2015-09-21 23:05:36 +01:00
|
|
|
CALL_COUNTING = FALSE;
|
|
|
|
Yap_InitComma();
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
2002-11-26 22:28:32 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2002-12-10 14:36:22 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_call_count_info(USES_REGS1) {
|
|
|
|
return (Yap_unify(MkIntegerTerm(LOCAL_ReductionsCounter), ARG1) &&
|
|
|
|
Yap_unify(MkIntegerTerm(LOCAL_PredEntriesCounter), ARG2) &&
|
|
|
|
Yap_unify(MkIntegerTerm(LOCAL_PredEntriesCounter), ARG3));
|
2002-11-26 22:28:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_call_count_reset(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
LOCAL_ReductionsCounter = 0;
|
|
|
|
LOCAL_ReductionsCounterOn = FALSE;
|
|
|
|
LOCAL_PredEntriesCounter = 0;
|
|
|
|
LOCAL_PredEntriesCounterOn = FALSE;
|
|
|
|
LOCAL_RetriesCounter = 0;
|
|
|
|
LOCAL_RetriesCounterOn = FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
2002-11-26 22:28:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_call_count_set(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
int do_calls = IntOfTerm(ARG2);
|
|
|
|
int do_retries = IntOfTerm(ARG4);
|
|
|
|
int do_entries = IntOfTerm(ARG6);
|
2006-03-06 14:04:57 +00:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (do_calls)
|
|
|
|
LOCAL_ReductionsCounter = IntegerOfTerm(Deref(ARG1));
|
|
|
|
LOCAL_ReductionsCounterOn = do_calls;
|
|
|
|
if (do_retries)
|
|
|
|
LOCAL_RetriesCounter = IntegerOfTerm(Deref(ARG3));
|
|
|
|
LOCAL_RetriesCounterOn = do_retries;
|
|
|
|
if (do_entries)
|
|
|
|
LOCAL_PredEntriesCounter = IntegerOfTerm(Deref(ARG5));
|
|
|
|
LOCAL_PredEntriesCounterOn = do_entries;
|
2015-10-22 00:53:26 +01:00
|
|
|
return (TRUE);
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_clean_up_dead_clauses(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
while (DeadStaticClauses != NULL) {
|
|
|
|
char *pt = (char *)DeadStaticClauses;
|
|
|
|
Yap_ClauseSpace -= DeadStaticClauses->ClSize;
|
|
|
|
DeadStaticClauses = DeadStaticClauses->ClNext;
|
|
|
|
Yap_InformOfRemoval(pt);
|
|
|
|
Yap_FreeCodeSpace(pt);
|
2010-04-29 10:29:06 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
while (DeadStaticIndices != NULL) {
|
|
|
|
char *pt = (char *)DeadStaticIndices;
|
|
|
|
if (DeadStaticIndices->ClFlags & SwitchTableMask)
|
|
|
|
Yap_IndexSpace_SW -= DeadStaticIndices->ClSize;
|
|
|
|
else
|
|
|
|
Yap_IndexSpace_Tree -= DeadStaticIndices->ClSize;
|
|
|
|
DeadStaticIndices = DeadStaticIndices->SiblingIndex;
|
|
|
|
Yap_InformOfRemoval(pt);
|
|
|
|
Yap_FreeCodeSpace(pt);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
while (DeadMegaClauses != NULL) {
|
|
|
|
char *pt = (char *)DeadMegaClauses;
|
|
|
|
Yap_ClauseSpace -= DeadMegaClauses->ClSize;
|
|
|
|
DeadMegaClauses = DeadMegaClauses->ClNext;
|
|
|
|
Yap_InformOfRemoval(pt);
|
|
|
|
Yap_FreeCodeSpace(pt);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-03-24 16:26:31 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_HidePred(PredEntry *pe) {
|
2005-02-08 18:05:21 +00:00
|
|
|
|
2016-01-08 03:18:36 +00:00
|
|
|
pe->PredFlags |= (HiddenPredFlag | NoSpyPredFlag | NoTracePredFlag);
|
2008-12-24 09:04:44 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $system_predicate(P) */
|
|
|
|
p_stash_predicate(USES_REGS1) {
|
|
|
|
PredEntry *pe;
|
2008-12-24 09:04:44 +00:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
2008-12-24 09:04:44 +00:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
restart_system_pred:
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
Atom a = AtomOfTerm(t1);
|
2009-02-26 00:00:23 +00:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(a, mod));
|
|
|
|
} else if (IsApplTerm(t1)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsExtensionFunctor(funt)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2005-12-17 03:25:39 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "hide_predicate/1");
|
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG1, "hide_predicate/1");
|
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
2005-12-17 03:25:39 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return TRUE;
|
|
|
|
} else
|
2003-12-02 00:36:27 +00:00
|
|
|
return FALSE;
|
2015-09-21 23:05:36 +01:00
|
|
|
if (EndOfPAEntr(pe))
|
2003-12-02 00:36:27 +00:00
|
|
|
return FALSE;
|
2015-09-21 23:05:36 +01:00
|
|
|
Yap_HidePred(pe);
|
|
|
|
return TRUE;
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $system_predicate(P) */
|
2016-01-04 14:11:09 +00:00
|
|
|
hide_predicate(USES_REGS1) {
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
restart_system_pred:
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
Atom a = AtomOfTerm(t1);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(a, mod));
|
|
|
|
} else if (IsApplTerm(t1)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsExtensionFunctor(funt)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "hide_predicate/1");
|
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG1, "hide_predicate/1");
|
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
|
|
|
} else if (IsPairTerm(t1)) {
|
2016-01-04 14:11:09 +00:00
|
|
|
return true;
|
2015-09-21 23:05:36 +01:00
|
|
|
} else
|
2016-01-04 14:11:09 +00:00
|
|
|
return false;
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2016-01-04 14:11:09 +00:00
|
|
|
return false;
|
2016-01-08 03:18:36 +00:00
|
|
|
pe->PredFlags |= (HiddenPredFlag | NoSpyPredFlag | NoTracePredFlag);
|
2016-01-04 14:11:09 +00:00
|
|
|
return true;
|
2002-09-03 15:28:09 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_hidden_predicate(USES_REGS1) {
|
|
|
|
PredEntry *pe;
|
2015-09-21 23:05:36 +01:00
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
restart_system_pred:
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
|
|
|
} else if (IsApplTerm(t1)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (IsExtensionFunctor(funt)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "hide_predicate/1");
|
|
|
|
return (FALSE);
|
2006-11-15 00:13:37 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
if (!IsAtomTerm(nmod)) {
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG1, "hide_predicate/1");
|
|
|
|
return (FALSE);
|
2006-11-15 00:13:37 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
2006-11-15 00:13:37 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return (TRUE);
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
2015-10-22 00:53:26 +01:00
|
|
|
return (FALSE);
|
|
|
|
return (pe->PredFlags & HiddenPredFlag);
|
2006-10-11 15:53:57 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb,
|
|
|
|
Term tr, yamop *cp_ptr, int first_time) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-09-21 23:05:36 +01:00
|
|
|
LogUpdClause *cl;
|
2003-11-21 16:56:20 +00:00
|
|
|
Term rtn;
|
2004-03-31 02:03:10 +01:00
|
|
|
Term Terms[3];
|
|
|
|
|
|
|
|
Terms[0] = th;
|
|
|
|
Terms[1] = tb;
|
|
|
|
Terms[2] = tr;
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = Yap_FollowIndexingCode(
|
|
|
|
pe, i_code, Terms, NEXTOP(PredLogUpdClause->CodeOfPred, Otapl), cp_ptr);
|
2015-09-21 23:05:36 +01:00
|
|
|
th = Terms[0];
|
|
|
|
tb = Terms[1];
|
|
|
|
tr = Terms[2];
|
2010-07-28 17:12:17 +01:00
|
|
|
if (cl == NULL) {
|
2015-09-21 23:05:36 +01:00
|
|
|
UNLOCK(pe->PELock);
|
2003-11-21 16:56:20 +00:00
|
|
|
return FALSE;
|
2010-07-28 17:12:17 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
rtn = MkDBRefTerm((DBRef)cl);
|
|
|
|
#if MULTIPLE_STACKS
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2015-09-21 23:05:36 +01:00
|
|
|
INC_CLREF_COUNT(cl);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (cl->ClFlags & FactMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify_constant(tb, MkAtomTerm(AtomTrue)) || !Yap_unify(tr, rtn)) {
|
2015-09-21 23:05:36 +01:00
|
|
|
UNLOCK(pe->PELock);
|
2004-09-27 21:45:04 +01:00
|
|
|
return FALSE;
|
2010-07-28 17:12:17 +01:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
2015-01-06 17:47:58 +00:00
|
|
|
arity_t arity = ArityOfFunctor(f), i;
|
2015-10-22 00:53:26 +01:00
|
|
|
CELL *pt = RepAppl(th) + 1;
|
2004-09-27 21:45:04 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
XREGS[i + 1] = pt[i];
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2015-10-22 00:53:26 +01:00
|
|
|
if (first_time && P->opc != EXECUTE_CPRED_OP_CODE) {
|
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL)B;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
P = cl->ClCode;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->PredFlags & ThreadLocalPredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
2015-09-21 23:05:36 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
PP = pe;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
2015-09-21 23:05:36 +01:00
|
|
|
} else {
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
while ((t = Yap_FetchClauseTermFromDB(cl->lusl.ClSource)) == 0L) {
|
|
|
|
|
|
|
|
if (first_time) {
|
2015-10-22 00:53:26 +01:00
|
|
|
ARG5 = th;
|
|
|
|
ARG6 = tb;
|
|
|
|
ARG7 = tr;
|
|
|
|
if (LOCAL_Error_TYPE == RESOURCE_ERROR_ATTRIBUTED_VARIABLES) {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_growglobal(NULL)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(RESOURCE_ERROR_ATTRIBUTED_VARIABLES, TermNil,
|
|
|
|
LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 7, ENV, gc_P(P, CP))) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
th = ARG5;
|
|
|
|
tb = ARG6;
|
|
|
|
tr = ARG7;
|
2015-09-21 23:05:36 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
ARG6 = th;
|
|
|
|
ARG7 = tb;
|
|
|
|
ARG8 = tr;
|
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, gc_P(P, CP))) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
th = ARG6;
|
|
|
|
tb = ARG7;
|
|
|
|
tr = ARG8;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UNLOCK(pe->PELock);
|
2015-10-22 00:53:26 +01:00
|
|
|
return (Yap_unify(th, ArgOfTerm(1, t)) && Yap_unify(tb, ArgOfTerm(2, t)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_log_update_clause(USES_REGS1) {
|
|
|
|
PredEntry *pe;
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Int ret;
|
|
|
|
yamop *new_cp;
|
|
|
|
|
|
|
|
if (P->opc == EXECUTE_CPRED_OP_CODE) {
|
|
|
|
new_cp = CP;
|
|
|
|
} else {
|
|
|
|
new_cp = P;
|
|
|
|
}
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(t1, Deref(ARG2), "clause/3");
|
2015-09-21 23:05:36 +01:00
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(41, pe);
|
2015-09-21 23:05:36 +01:00
|
|
|
ret = fetch_next_lu_clause(pe, pe->CodeOfPred, t1, ARG3, ARG4, new_cp, TRUE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_continue_log_update_clause(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(42, pe);
|
|
|
|
return fetch_next_lu_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_cp,
|
|
|
|
FALSE);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int fetch_next_lu_clause_erase(PredEntry *pe, yamop *i_code, Term th,
|
|
|
|
Term tb, Term tr, yamop *cp_ptr,
|
|
|
|
int first_time) {
|
2015-09-21 23:05:36 +01:00
|
|
|
CACHE_REGS
|
|
|
|
LogUpdClause *cl;
|
|
|
|
Term rtn;
|
|
|
|
Term Terms[3];
|
|
|
|
|
|
|
|
Terms[0] = th;
|
|
|
|
Terms[1] = tb;
|
|
|
|
Terms[2] = tr;
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = Yap_FollowIndexingCode(pe, i_code, Terms,
|
|
|
|
NEXTOP(PredLogUpdClauseErase->CodeOfPred, Otapl),
|
|
|
|
cp_ptr);
|
2015-09-21 23:05:36 +01:00
|
|
|
th = Terms[0];
|
|
|
|
tb = Terms[1];
|
|
|
|
tr = Terms[2];
|
|
|
|
/* don't do this!! I might have stored a choice-point and changed ASP
|
|
|
|
Yap_RecoverSlots(3);
|
|
|
|
*/
|
|
|
|
if (cl == NULL) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
rtn = MkDBRefTerm((DBRef)cl);
|
|
|
|
#if MULTIPLE_STACKS
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2015-09-21 23:05:36 +01:00
|
|
|
INC_CLREF_COUNT(cl);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
2003-11-21 16:56:20 +00:00
|
|
|
if (cl->ClFlags & FactMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify_constant(tb, MkAtomTerm(AtomTrue)) || !Yap_unify(tr, rtn)) {
|
2015-09-21 23:05:36 +01:00
|
|
|
UNLOCK(pe->PELock);
|
2003-11-21 16:56:20 +00:00
|
|
|
return FALSE;
|
2010-07-28 17:12:17 +01:00
|
|
|
}
|
2003-11-21 16:56:20 +00:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
2015-01-06 17:47:58 +00:00
|
|
|
arity_t arity = ArityOfFunctor(f), i;
|
2015-10-22 00:53:26 +01:00
|
|
|
CELL *pt = RepAppl(th) + 1;
|
2003-11-21 16:56:20 +00:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
XREGS[i + 1] = pt[i];
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2015-10-22 00:53:26 +01:00
|
|
|
if (first_time && P->opc != EXECUTE_CPRED_OP_CODE) {
|
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL)B;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
P = cl->ClCode;
|
2015-09-21 23:05:36 +01:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->PredFlags & ThreadLocalPredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
2015-09-21 23:05:36 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
PP = pe;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* we don't actually need to execute code */
|
|
|
|
UNLOCK(pe->PELock);
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
Yap_ErLogUpdCl(cl);
|
2003-11-21 16:56:20 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
2015-09-21 23:05:36 +01:00
|
|
|
Int res;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
while ((t = Yap_FetchClauseTermFromDB(cl->lusl.ClSource)) == 0L) {
|
2003-11-21 16:56:20 +00:00
|
|
|
if (first_time) {
|
2015-10-22 00:53:26 +01:00
|
|
|
ARG5 = th;
|
|
|
|
ARG6 = tb;
|
|
|
|
ARG7 = tr;
|
|
|
|
if (LOCAL_Error_TYPE == RESOURCE_ERROR_ATTRIBUTED_VARIABLES) {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_locked_growglobal(NULL)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(RESOURCE_ERROR_ATTRIBUTED_VARIABLES, TermNil,
|
|
|
|
LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_locked_gcl(LOCAL_Error_Size, 7, ENV, gc_P(P, CP))) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
th = ARG5;
|
|
|
|
tb = ARG6;
|
|
|
|
tr = ARG7;
|
2003-11-21 16:56:20 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
ARG6 = th;
|
|
|
|
ARG7 = tb;
|
|
|
|
ARG8 = tr;
|
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, CP)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
th = ARG6;
|
|
|
|
tb = ARG7;
|
|
|
|
tr = ARG8;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
res = Yap_unify(th, ArgOfTerm(1, t)) && Yap_unify(tb, ArgOfTerm(2, t)) &&
|
|
|
|
Yap_unify(tr, rtn);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (res)
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return res;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_log_update_clause_erase(USES_REGS1) {
|
|
|
|
PredEntry *pe;
|
2003-11-21 16:56:20 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
2015-09-21 23:05:36 +01:00
|
|
|
Int ret;
|
|
|
|
yamop *new_cp;
|
2003-11-21 16:56:20 +00:00
|
|
|
|
2008-09-01 16:48:05 +01:00
|
|
|
if (P->opc == EXECUTE_CPRED_OP_CODE) {
|
2008-09-01 16:30:37 +01:00
|
|
|
new_cp = CP;
|
|
|
|
} else {
|
|
|
|
new_cp = P;
|
|
|
|
}
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(t1, Deref(ARG2), "clause/3");
|
2003-11-21 16:56:20 +00:00
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(43, pe);
|
|
|
|
ret = fetch_next_lu_clause_erase(pe, pe->CodeOfPred, t1, ARG3, ARG4, new_cp,
|
|
|
|
TRUE);
|
2015-09-21 23:05:36 +01:00
|
|
|
return ret;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_continue_log_update_clause_erase(USES_REGS1) {
|
2003-11-21 16:56:20 +00:00
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(44, pe);
|
|
|
|
return fetch_next_lu_clause_erase(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_cp,
|
|
|
|
FALSE);
|
2010-10-26 22:01:29 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static void adjust_cl_timestamp(LogUpdClause *cl, UInt *arp, UInt *base) {
|
2015-09-21 23:05:36 +01:00
|
|
|
UInt clstamp = cl->ClTimeEnd;
|
|
|
|
if (cl->ClTimeEnd != TIMESTAMP_EOT) {
|
|
|
|
while (arp[0] > clstamp)
|
|
|
|
arp--;
|
|
|
|
if (arp[0] == clstamp) {
|
2015-10-22 00:53:26 +01:00
|
|
|
cl->ClTimeEnd = (arp - base);
|
2003-05-20 20:11:59 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
cl->ClTimeEnd = (arp - base) + 1;
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
2015-04-13 13:28:17 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
clstamp = cl->ClTimeStart;
|
|
|
|
while (arp[0] > clstamp)
|
|
|
|
arp--;
|
|
|
|
if (arp[0] == clstamp) {
|
2015-10-22 00:53:26 +01:00
|
|
|
cl->ClTimeStart = (arp - base);
|
2015-09-21 23:05:36 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
cl->ClTimeStart = (arp - base) + 1;
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
clstamp = cl->ClTimeEnd;
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Term replace_integer(Term orig, UInt new) {
|
2015-09-21 23:05:36 +01:00
|
|
|
CELL *pt;
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IntInBnd((Int) new))
|
2015-09-21 23:05:36 +01:00
|
|
|
return MkIntTerm(new);
|
|
|
|
/* should create an old integer */
|
|
|
|
if (!IsApplTerm(orig)) {
|
|
|
|
CACHE_REGS
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, orig,
|
|
|
|
"%uld-->%uld where it should increase",
|
|
|
|
(unsigned long int)IntegerOfTerm(orig), (unsigned long int)new);
|
2015-09-21 23:05:36 +01:00
|
|
|
return MkIntegerTerm(new);
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
/* appl->appl */
|
|
|
|
/* replace integer in situ */
|
2015-10-22 00:53:26 +01:00
|
|
|
pt = RepAppl(orig) + 1;
|
2015-09-21 23:05:36 +01:00
|
|
|
*pt = new;
|
|
|
|
return orig;
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static UInt tree_index_ssz(StaticIndex *x) {
|
2004-03-05 15:26:33 +00:00
|
|
|
UInt sz = x->ClSize;
|
2003-11-12 12:33:31 +00:00
|
|
|
x = x->ChildIndex;
|
|
|
|
while (x != NULL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
sz += tree_index_ssz(x);
|
2003-11-12 12:33:31 +00:00
|
|
|
x = x->SiblingIndex;
|
|
|
|
}
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static UInt index_ssz(StaticIndex *x, PredEntry *pe) {
|
2013-01-23 09:58:02 +00:00
|
|
|
UInt sz = 0;
|
|
|
|
yamop *ep = ExpandClausesFirst;
|
|
|
|
if (pe->PredFlags & MegaClausePredFlag) {
|
|
|
|
MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
|
|
|
if (mcl->ClFlags & ExoMask) {
|
|
|
|
struct index_t *i = ((struct index_t **)(pe->cs.p_code.FirstClause))[0];
|
|
|
|
sz = 0;
|
|
|
|
|
|
|
|
while (i) {
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = i->size + sz;
|
|
|
|
i = i->next;
|
2013-01-23 09:58:02 +00:00
|
|
|
}
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* expand clause blocks */
|
|
|
|
while (ep) {
|
2014-05-30 01:06:09 +01:00
|
|
|
if (ep->y_u.sssllp.p == pe)
|
2015-10-22 00:53:26 +01:00
|
|
|
sz += (UInt)NEXTOP((yamop *)NULL, sssllp) +
|
|
|
|
ep->y_u.sssllp.s1 * sizeof(yamop *);
|
2014-05-30 01:06:09 +01:00
|
|
|
ep = ep->y_u.sssllp.snext;
|
2013-01-23 09:58:02 +00:00
|
|
|
}
|
|
|
|
/* main indexing tree */
|
|
|
|
sz += tree_index_ssz(x);
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
#ifdef DEBUG
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_predicate_lu_cps(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
return Yap_unify(ARG1, MkIntegerTerm(Yap_LiveCps)) &&
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_unify(ARG2, MkIntegerTerm(Yap_FreedCps)) &&
|
|
|
|
Yap_unify(ARG3, MkIntegerTerm(Yap_DirtyCps)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(Yap_NewCps));
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int static_statistics(PredEntry *pe) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2013-01-23 09:58:02 +00:00
|
|
|
UInt sz = sizeof(PredEntry), cls = 0, isz = 0;
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause);
|
2003-11-12 12:33:31 +00:00
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->cs.p_code.NOfClauses > 1 &&
|
|
|
|
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause) {
|
2013-01-23 09:58:02 +00:00
|
|
|
isz = index_ssz(ClauseCodeToStaticIndex(pe->cs.p_code.TrueCodeOfPred), pe);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
if (pe->PredFlags & MegaClausePredFlag) {
|
|
|
|
MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_unify(ARG3, MkIntegerTerm(mcl->ClSize / mcl->ClItemSize)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(mcl->ClSize)) &&
|
|
|
|
Yap_unify(ARG5, MkIntegerTerm(isz));
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (pe->cs.p_code.NOfClauses) {
|
2003-11-12 12:33:31 +00:00
|
|
|
do {
|
|
|
|
cls++;
|
2004-03-05 15:26:33 +00:00
|
|
|
sz += cl->ClSize;
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClCode == pe->cs.p_code.LastClause)
|
2015-10-22 00:53:26 +01:00
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = cl->ClNext;
|
2003-11-12 12:33:31 +00:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG3, MkIntegerTerm(cls)) &&
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_unify(ARG4, MkIntegerTerm(sz)) &&
|
|
|
|
Yap_unify(ARG5, MkIntegerTerm(isz));
|
2003-11-12 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_static_pred_statistics(USES_REGS1) {
|
2007-11-26 23:43:10 +00:00
|
|
|
Int out;
|
2015-10-22 00:53:26 +01:00
|
|
|
PredEntry *pe;
|
2003-11-12 12:33:31 +00:00
|
|
|
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "predicate_statistics");
|
2003-11-12 12:33:31 +00:00
|
|
|
if (pe == NIL)
|
|
|
|
return (FALSE);
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(50, pe);
|
|
|
|
if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | UserCPredFlag |
|
|
|
|
AsmPredFlag | CPredFlag | BinaryPredFlag)) {
|
2003-11-12 12:33:31 +00:00
|
|
|
/* should use '$recordedp' in this case */
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2003-11-12 12:33:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-26 23:43:10 +00:00
|
|
|
out = static_statistics(pe);
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return out;
|
2003-11-12 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_predicate_erased_statistics(USES_REGS1) {
|
2004-04-07 23:04:04 +01:00
|
|
|
UInt sz = 0, cls = 0;
|
|
|
|
UInt isz = 0, icls = 0;
|
|
|
|
PredEntry *pe;
|
|
|
|
LogUpdClause *cl = DBErasedList;
|
|
|
|
LogUpdIndex *icl = DBErasedIList;
|
2015-10-22 00:53:26 +01:00
|
|
|
Term tpred = ArgOfTerm(2, Deref(ARG1));
|
|
|
|
Term tmod = ArgOfTerm(1, Deref(ARG1));
|
2004-04-07 23:04:04 +01:00
|
|
|
|
2016-10-20 04:44:59 +01:00
|
|
|
if (EndOfPAEntr(pe =
|
|
|
|
Yap_get_pred(tpred, tmod, "predicate_erased_statistics")))
|
2004-04-07 23:04:04 +01:00
|
|
|
return FALSE;
|
|
|
|
while (cl) {
|
|
|
|
if (cl->ClPred == pe) {
|
|
|
|
cls++;
|
|
|
|
sz += cl->ClSize;
|
|
|
|
}
|
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
|
|
|
while (icl) {
|
2005-12-17 03:25:39 +00:00
|
|
|
if (pe == icl->ClPred) {
|
2004-04-07 23:04:04 +01:00
|
|
|
icls++;
|
2005-12-17 03:25:39 +00:00
|
|
|
isz += icl->ClSize;
|
2004-04-07 23:04:04 +01:00
|
|
|
}
|
|
|
|
icl = icl->SiblingIndex;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_unify(ARG2, MkIntegerTerm(cls)) &&
|
|
|
|
Yap_unify(ARG3, MkIntegerTerm(sz)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(icls)) &&
|
|
|
|
Yap_unify(ARG5, MkIntegerTerm(isz));
|
2004-04-07 23:04:04 +01:00
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
void Yap_UpdateTimestamps(PredEntry *ap) {
|
2015-09-21 23:05:36 +01:00
|
|
|
CACHE_REGS
|
|
|
|
choiceptr bptr = B;
|
2015-10-22 00:53:26 +01:00
|
|
|
yamop *cl0 = NEXTOP(PredLogUpdClause0->CodeOfPred, Otapl);
|
|
|
|
yamop *cl = NEXTOP(PredLogUpdClause->CodeOfPred, Otapl);
|
|
|
|
yamop *cle = NEXTOP(PredLogUpdClauseErase->CodeOfPred, Otapl);
|
2015-09-21 23:05:36 +01:00
|
|
|
arity_t ar = ap->ArityOfPE;
|
|
|
|
UInt *arp, *top, *base;
|
|
|
|
LogUpdClause *lcl;
|
|
|
|
|
|
|
|
#if THREADS
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "Timestamp overflow %p", ap);
|
2015-09-21 23:05:36 +01:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
if (!ap->cs.p_code.NOfClauses)
|
|
|
|
return;
|
2015-10-22 00:53:26 +01:00
|
|
|
restart:
|
2015-09-21 23:05:36 +01:00
|
|
|
*--ASP = TIMESTAMP_EOT;
|
|
|
|
top = arp = (UInt *)ASP;
|
|
|
|
while (bptr) {
|
|
|
|
op_numbers opnum = Yap_op_from_opcode(bptr->cp_ap->opc);
|
|
|
|
|
|
|
|
switch (opnum) {
|
|
|
|
case _retry_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_trust_logical:
|
|
|
|
if (bptr->cp_ap->y_u.OtaLl.d->ClPred == ap) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[ar]);
|
|
|
|
if (ts != arp[0]) {
|
|
|
|
if (arp - HR < 1024) {
|
|
|
|
goto overflow;
|
|
|
|
}
|
|
|
|
/* be thrifty, have this in case there is a hole */
|
|
|
|
if (ts != arp[0] - 1) {
|
|
|
|
UInt x = arp[0];
|
|
|
|
*--arp = x;
|
|
|
|
}
|
|
|
|
*--arp = ts;
|
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
break;
|
|
|
|
case _retry:
|
|
|
|
if ((bptr->cp_ap == cl0 || bptr->cp_ap == cl || bptr->cp_ap == cle) &&
|
2015-10-22 00:53:26 +01:00
|
|
|
((PredEntry *)IntegerOfTerm(bptr->cp_args[0]) == ap)) {
|
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[5]);
|
|
|
|
if (ts != arp[0]) {
|
|
|
|
if (arp - HR < 1024) {
|
|
|
|
goto overflow;
|
|
|
|
}
|
|
|
|
if (ts != arp[0] - 1) {
|
|
|
|
UInt x = arp[0];
|
|
|
|
*--arp = x;
|
|
|
|
}
|
|
|
|
*--arp = ts;
|
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*arp)
|
|
|
|
*--arp = 0L;
|
|
|
|
base = arp;
|
|
|
|
lcl = ClauseCodeToLogUpdClause(ap->cs.p_code.FirstClause);
|
|
|
|
while (lcl) {
|
2015-10-22 00:53:26 +01:00
|
|
|
adjust_cl_timestamp(lcl, top - 1, base);
|
2015-09-21 23:05:36 +01:00
|
|
|
lcl = lcl->ClNext;
|
|
|
|
}
|
|
|
|
lcl = DBErasedList;
|
|
|
|
while (lcl) {
|
|
|
|
if (lcl->ClPred == ap)
|
2015-10-22 00:53:26 +01:00
|
|
|
adjust_cl_timestamp(lcl, top - 1, base);
|
2015-09-21 23:05:36 +01:00
|
|
|
lcl = lcl->ClNext;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
arp = top - 1;
|
2015-09-21 23:05:36 +01:00
|
|
|
bptr = B;
|
|
|
|
while (bptr) {
|
|
|
|
op_numbers opnum = Yap_op_from_opcode(bptr->cp_ap->opc);
|
|
|
|
|
|
|
|
switch (opnum) {
|
|
|
|
case _retry_logical:
|
|
|
|
case _count_retry_logical:
|
|
|
|
case _profiled_retry_logical:
|
|
|
|
case _trust_logical:
|
|
|
|
case _count_trust_logical:
|
|
|
|
case _profiled_trust_logical:
|
|
|
|
if (bptr->cp_ap->y_u.OtaLl.d->ClPred == ap) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[ar]);
|
|
|
|
while (ts != arp[0])
|
|
|
|
arp--;
|
|
|
|
bptr->cp_args[ar] = replace_integer(bptr->cp_args[ar], arp - base);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
break;
|
|
|
|
case _retry:
|
|
|
|
if ((bptr->cp_ap == cl0 || bptr->cp_ap == cl || bptr->cp_ap == cle) &&
|
2015-10-22 00:53:26 +01:00
|
|
|
((PredEntry *)IntegerOfTerm(bptr->cp_args[0]) == ap)) {
|
|
|
|
UInt ts = IntegerOfTerm(bptr->cp_args[5]);
|
|
|
|
while (ts != arp[0])
|
|
|
|
arp--;
|
|
|
|
bptr->cp_args[5] = replace_integer(bptr->cp_args[5], arp - base);
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bptr = bptr->cp_b;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2015-10-22 00:53:26 +01:00
|
|
|
overflow:
|
|
|
|
if (!Yap_growstack(64 * 1024)) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
2015-09-21 23:05:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto restart;
|
2006-10-11 15:53:57 +01:00
|
|
|
}
|
2004-04-07 23:04:04 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int fetch_next_static_clause(PredEntry *pe, yamop *i_code, Term th,
|
|
|
|
Term tb, Term tr, yamop *cp_ptr,
|
|
|
|
int first_time) {
|
2015-09-21 23:05:36 +01:00
|
|
|
CACHE_REGS
|
|
|
|
StaticClause *cl;
|
|
|
|
Term rtn;
|
|
|
|
Term Terms[3];
|
|
|
|
|
|
|
|
Terms[0] = th;
|
|
|
|
Terms[1] = tb;
|
|
|
|
Terms[2] = tr;
|
2015-10-22 00:53:26 +01:00
|
|
|
cl = (StaticClause *)Yap_FollowIndexingCode(
|
|
|
|
pe, i_code, Terms, NEXTOP(PredStaticClause->CodeOfPred, Otapl), cp_ptr);
|
2015-09-21 23:05:36 +01:00
|
|
|
th = Deref(Terms[0]);
|
|
|
|
tb = Deref(Terms[1]);
|
|
|
|
tr = Deref(Terms[2]);
|
2016-01-03 01:27:36 +00:00
|
|
|
/*
|
|
|
|
don't do this!! I might have stored a choice-point and changed ASP
|
2015-09-21 23:05:36 +01:00
|
|
|
Yap_RecoverSlots(3);
|
|
|
|
*/
|
2016-05-10 15:22:25 +01:00
|
|
|
if (cl == NULL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2005-10-29 02:28:37 +01:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
if (pe->PredFlags & MegaClausePredFlag) {
|
|
|
|
yamop *code = (yamop *)cl;
|
2015-10-22 00:53:26 +01:00
|
|
|
rtn = Yap_MkMegaRefTerm(pe, code);
|
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) || !Yap_unify(tr, rtn)) {
|
|
|
|
UNLOCKPE(45, pe);
|
2005-10-29 02:28:37 +01:00
|
|
|
return FALSE;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
arity_t arity = ArityOfFunctor(f), i;
|
2015-10-22 00:53:26 +01:00
|
|
|
CELL *pt = RepAppl(th) + 1;
|
2003-05-20 20:11:59 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
XREGS[i + 1] = pt[i];
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
|
|
|
if (first_time && P->opc != EXECUTE_CPRED_OP_CODE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL)B;
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
P = code;
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
2015-09-21 23:05:36 +01:00
|
|
|
return TRUE;
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
rtn = Yap_MkStaticRefTerm(cl, pe);
|
|
|
|
if (cl->ClFlags & FactMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) || !Yap_unify(tr, rtn)) {
|
|
|
|
UNLOCKPE(45, pe);
|
2015-09-21 23:05:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-03-06 14:04:57 +00:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
arity_t arity = ArityOfFunctor(f), i;
|
2015-10-22 00:53:26 +01:00
|
|
|
CELL *pt = RepAppl(th) + 1;
|
2006-12-13 16:10:26 +00:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
XREGS[i + 1] = pt[i];
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
2015-10-22 00:53:26 +01:00
|
|
|
if (first_time && P->opc != EXECUTE_CPRED_OP_CODE) {
|
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL)B;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
P = cl->ClCode;
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
2016-02-11 14:00:56 +00:00
|
|
|
return true;
|
2006-12-13 16:10:26 +00:00
|
|
|
} else {
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t;
|
|
|
|
|
|
|
|
if (!(pe->PredFlags & SourcePredFlag)) {
|
|
|
|
/* no source */
|
|
|
|
rtn = Yap_MkStaticRefTerm(cl, pe);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
2015-09-21 23:05:36 +01:00
|
|
|
return Yap_unify(tr, rtn);
|
|
|
|
}
|
|
|
|
while ((t = Yap_FetchClauseTermFromDB(cl->usc.ClSource)) == 0L) {
|
|
|
|
if (first_time) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (LOCAL_Error_TYPE == RESOURCE_ERROR_ATTRIBUTED_VARIABLES) {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_growglobal(NULL)) {
|
|
|
|
Yap_Error(RESOURCE_ERROR_ATTRIBUTED_VARIABLES, TermNil,
|
|
|
|
LOCAL_ErrorMessage);
|
|
|
|
UNLOCKPE(45, pe);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
ARG5 = th;
|
|
|
|
ARG6 = tb;
|
|
|
|
ARG7 = tr;
|
|
|
|
if (!Yap_gc(7, ENV, gc_P(P, CP))) {
|
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
|
|
|
UNLOCKPE(45, pe);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
th = ARG5;
|
|
|
|
tb = ARG6;
|
|
|
|
tr = ARG7;
|
|
|
|
}
|
2015-09-21 23:05:36 +01:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
ARG6 = th;
|
|
|
|
ARG7 = tb;
|
|
|
|
ARG8 = tr;
|
|
|
|
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, CP)) {
|
|
|
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
|
|
|
UNLOCKPE(45, pe);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
th = ARG6;
|
|
|
|
tb = ARG7;
|
|
|
|
tr = ARG8;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rtn = Yap_MkStaticRefTerm(cl, pe);
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCKPE(45, pe);
|
2015-09-21 23:05:36 +01:00
|
|
|
if (!IsApplTerm(t) || FunctorOfTerm(t) != FunctorAssert) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (Yap_unify(th, t) && Yap_unify(tb, MkAtomTerm(AtomTrue)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
2006-12-13 16:10:26 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
return (Yap_unify(th, ArgOfTerm(1, t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2, t)) && Yap_unify(tr, rtn));
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-24 10:01:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_static_clause(USES_REGS1) {
|
|
|
|
PredEntry *pe;
|
2015-09-21 23:05:36 +01:00
|
|
|
Term t1 = Deref(ARG1);
|
2015-10-22 00:53:26 +01:00
|
|
|
yamop *new_cp;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
if (P->opc == EXECUTE_CPRED_OP_CODE) {
|
|
|
|
new_cp = CP;
|
|
|
|
} else {
|
|
|
|
new_cp = P;
|
|
|
|
}
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(t1, Deref(ARG2), "clause/3");
|
2015-09-21 23:05:36 +01:00
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(46, pe);
|
|
|
|
return fetch_next_static_clause(pe, pe->CodeOfPred, ARG1, ARG3, ARG4, new_cp,
|
2016-01-03 01:27:36 +00:00
|
|
|
true);
|
2006-12-13 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_continue_static_clause(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
2010-01-15 16:15:36 +00:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(48, pe);
|
|
|
|
return fetch_next_static_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap,
|
2016-01-03 01:27:36 +00:00
|
|
|
false);
|
2006-03-06 14:04:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static UInt compute_dbcl_size(arity_t arity) {
|
2011-04-30 01:16:40 +01:00
|
|
|
UInt sz;
|
2015-10-22 00:53:26 +01:00
|
|
|
switch (arity) {
|
2011-04-30 01:16:40 +01:00
|
|
|
case 2:
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL, cc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL, ccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL, cccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL, ccccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = (UInt)NEXTOP((yamop *)NULL, cccccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = arity * (UInt)NEXTOP((yamop *)NULL, xc);
|
2015-04-13 13:28:17 +01:00
|
|
|
break;
|
2011-04-30 01:16:40 +01:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return (UInt)NEXTOP((yamop *)sz, p);
|
2011-04-30 01:16:40 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
#define DerefAndCheck(t, V) \
|
|
|
|
t = Deref(V); \
|
|
|
|
if (IsVarTerm(t) || !(IsAtomOrIntTerm(t))) \
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t0, "load_db");
|
2011-04-30 01:16:40 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static int store_dbcl_size(yamop *pc, arity_t arity, Term t0, PredEntry *pe) {
|
2011-04-30 01:16:40 +01:00
|
|
|
Term t;
|
2015-10-22 00:53:26 +01:00
|
|
|
CELL *tp = RepAppl(t0) + 1;
|
|
|
|
switch (arity) {
|
2011-04-30 01:16:40 +01:00
|
|
|
case 2:
|
|
|
|
pc->opc = Yap_opcode(_get_2atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cc.c1 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[1]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cc.c2 = t;
|
2015-10-22 00:53:26 +01:00
|
|
|
pc = NEXTOP(pc, cc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pc->opc = Yap_opcode(_get_3atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccc.c1 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[1]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccc.c2 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[2]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccc.c3 = t;
|
2015-10-22 00:53:26 +01:00
|
|
|
pc = NEXTOP(pc, ccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pc->opc = Yap_opcode(_get_4atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccc.c1 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[1]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccc.c2 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[2]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccc.c3 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[3]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccc.c4 = t;
|
2015-10-22 00:53:26 +01:00
|
|
|
pc = NEXTOP(pc, cccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
pc->opc = Yap_opcode(_get_5atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccccc.c1 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[1]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccccc.c2 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[2]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccccc.c3 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[3]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccccc.c4 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[4]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.ccccc.c5 = t;
|
2015-10-22 00:53:26 +01:00
|
|
|
pc = NEXTOP(pc, ccccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
pc->opc = Yap_opcode(_get_6atoms);
|
|
|
|
DerefAndCheck(t, tp[0]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccccc.c1 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[1]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccccc.c2 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[2]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccccc.c3 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[3]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccccc.c4 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[4]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccccc.c5 = t;
|
2011-04-30 01:16:40 +01:00
|
|
|
DerefAndCheck(t, tp[5]);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.cccccc.c6 = t;
|
2015-10-22 00:53:26 +01:00
|
|
|
pc = NEXTOP(pc, cccccc);
|
2011-04-30 01:16:40 +01:00
|
|
|
break;
|
2015-10-22 00:53:26 +01:00
|
|
|
default: {
|
|
|
|
arity_t i;
|
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
pc->opc = Yap_opcode(_get_atom);
|
2011-04-30 01:16:40 +01:00
|
|
|
#if PRECOMPUTE_REGADDRESS
|
2015-10-22 00:53:26 +01:00
|
|
|
pc->y_u.xc.x = (CELL)(XREGS + (i + 1));
|
2011-04-30 01:16:40 +01:00
|
|
|
#else
|
2015-10-22 00:53:26 +01:00
|
|
|
pc->y_u.xc.x = i + 1;
|
2011-04-30 01:16:40 +01:00
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
DerefAndCheck(t, tp[0]);
|
|
|
|
pc->y_u.xc.c = t;
|
|
|
|
tp++;
|
|
|
|
pc = NEXTOP(pc, xc);
|
2011-04-30 01:16:40 +01:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
} break;
|
2011-04-30 01:16:40 +01:00
|
|
|
}
|
|
|
|
pc->opc = Yap_opcode(_procceed);
|
2014-05-30 01:06:09 +01:00
|
|
|
pc->y_u.p.p = pe;
|
2011-04-30 01:16:40 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-13 13:28:17 +01:00
|
|
|
static Int
|
2015-10-22 00:53:26 +01:00
|
|
|
p_dbload_get_space(USES_REGS1) { /* '$number_of_clauses'(Predicate,M,N) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
Term tn = Deref(ARG3);
|
|
|
|
arity_t arity;
|
|
|
|
Prop pe;
|
|
|
|
PredEntry *ap;
|
2011-04-30 01:16:40 +01:00
|
|
|
UInt sz;
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *ptr;
|
|
|
|
UInt ncls;
|
|
|
|
UInt required;
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
|
|
|
return (FALSE);
|
2011-04-30 01:16:40 +01:00
|
|
|
}
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
|
|
|
arity = 0;
|
|
|
|
pe = PredPropByAtom(a, mod);
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
arity = ArityOfFunctor(f);
|
|
|
|
pe = PredPropByFunc(f, mod);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
|
|
|
ap = RepPredProp(pe);
|
2015-10-22 00:53:26 +01:00
|
|
|
if (ap->PredFlags & (DynamicPredFlag | LogUpdatePredFlag
|
2011-04-30 01:16:40 +01:00
|
|
|
#ifdef TABLING
|
2015-10-22 00:53:26 +01:00
|
|
|
| TabledPredFlag
|
2011-04-30 01:16:40 +01:00
|
|
|
#endif /* TABLING */
|
2015-10-22 00:53:26 +01:00
|
|
|
)) {
|
|
|
|
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, t,
|
|
|
|
"dbload_get_space/4");
|
2011-04-30 01:16:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(tn) || !IsIntegerTerm(tn)) {
|
2011-04-30 01:16:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ncls = IntegerOfTerm(tn);
|
|
|
|
if (ncls <= 1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
sz = compute_dbcl_size(arity);
|
|
|
|
required = sz * ncls + sizeof(MegaClause) + (UInt)NEXTOP((yamop *)NULL, l);
|
2011-04-30 01:16:40 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
total_megaclause += required;
|
|
|
|
nof_megaclauses++;
|
|
|
|
#endif
|
|
|
|
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
|
|
|
|
if (!Yap_growheap(FALSE, required, NULL)) {
|
|
|
|
/* just fail, the system will keep on going */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Yap_ClauseSpace += required;
|
|
|
|
/* cool, it's our turn to do the conversion */
|
|
|
|
mcl->ClFlags = MegaMask;
|
2015-10-22 00:53:26 +01:00
|
|
|
mcl->ClSize = sz * ncls;
|
2011-04-30 01:16:40 +01:00
|
|
|
mcl->ClPred = ap;
|
|
|
|
mcl->ClItemSize = sz;
|
|
|
|
mcl->ClNext = NULL;
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->cs.p_code.FirstClause = ap->cs.p_code.LastClause = mcl->ClCode;
|
2013-09-28 18:20:04 +01:00
|
|
|
ap->PredFlags |= (MegaClausePredFlag);
|
2011-04-30 01:16:40 +01:00
|
|
|
ap->cs.p_code.NOfClauses = ncls;
|
2015-10-22 00:53:26 +01:00
|
|
|
if (ap->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
2011-04-30 01:16:40 +01:00
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
} else {
|
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
(yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
ptr = (yamop *)((ADDR)mcl->ClCode + ncls * sz);
|
2011-04-30 01:16:40 +01:00
|
|
|
ptr->opc = Yap_opcode(_Ystop);
|
|
|
|
return Yap_unify(ARG4, MkIntegerTerm((Int)mcl));
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_dbassert(USES_REGS1) { /* '$number_of_clauses'(Predicate,M,N) */
|
|
|
|
Term thandle = Deref(ARG2);
|
|
|
|
Term tn = Deref(ARG3);
|
|
|
|
PredEntry *pe;
|
|
|
|
MegaClause *mcl;
|
|
|
|
Int n;
|
2011-04-30 01:16:40 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(thandle) || !IsIntegerTerm(thandle)) {
|
2011-04-30 01:16:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
mcl = (MegaClause *)IntegerOfTerm(thandle);
|
2015-10-22 00:53:26 +01:00
|
|
|
if (IsVarTerm(tn) || !IsIntegerTerm(tn)) {
|
2011-04-30 01:16:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
n = IntegerOfTerm(tn);
|
|
|
|
pe = mcl->ClPred;
|
2015-10-22 00:53:26 +01:00
|
|
|
return store_dbcl_size((yamop *)((ADDR)mcl->ClCode + n * (mcl->ClItemSize)),
|
|
|
|
pe->ArityOfPE, Deref(ARG1), pe);
|
2011-04-30 01:16:40 +01:00
|
|
|
}
|
|
|
|
|
2013-11-05 17:59:19 +00:00
|
|
|
#define CL_PROP_ERASED 0
|
2015-10-22 00:53:26 +01:00
|
|
|
#define CL_PROP_PRED 1
|
|
|
|
#define CL_PROP_FILE 2
|
|
|
|
#define CL_PROP_FACT 3
|
|
|
|
#define CL_PROP_LINE 4
|
2013-11-05 17:59:19 +00:00
|
|
|
#define CL_PROP_STREAM 5
|
|
|
|
|
|
|
|
/* instance(+Ref,?Term) */
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int instance_property(USES_REGS1) {
|
2013-11-05 17:59:19 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
DBRef dbr;
|
|
|
|
|
|
|
|
Int op = IntOfTerm(Deref(ARG2));
|
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsDBRefTerm(t1)) {
|
|
|
|
if (IsApplTerm(t1)) {
|
|
|
|
if (FunctorOfTerm(t1) == FunctorStaticClause) {
|
2015-10-22 00:53:26 +01:00
|
|
|
StaticClause *cl = Yap_ClauseFromTerm(t1);
|
|
|
|
|
|
|
|
if (op == CL_PROP_ERASED) {
|
|
|
|
if (cl->ClFlags & ErasedMask) {
|
|
|
|
if (!Yap_unify(ARG3, MkAtomTerm(AtomTrue)))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!Yap_unify(ARG3, MkAtomTerm(AtomFalse)))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_PRED || op == CL_PROP_FILE || op == CL_PROP_STREAM) {
|
|
|
|
PredEntry *ap = (PredEntry *)IntegerOfTerm(ArgOfTerm(2, t1));
|
|
|
|
if (!ap) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_FILE) {
|
|
|
|
if (ap->src.OwnerFile)
|
|
|
|
return Yap_unify(ARG3, MkAtomTerm(ap->src.OwnerFile));
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
Term t[2];
|
|
|
|
|
|
|
|
if (ap->ArityOfPE == 0) {
|
|
|
|
t[1] = MkAtomTerm((Atom)ap->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
Functor nf = ap->FunctorOfPred;
|
|
|
|
arity_t arity = ArityOfFunctor(nf);
|
|
|
|
Atom name = NameOfFunctor(nf);
|
|
|
|
|
|
|
|
t[0] = MkAtomTerm(name);
|
|
|
|
t[1] = MkIntegerTerm(arity);
|
|
|
|
t[1] = Yap_MkApplTerm(FunctorSlash, 2, t);
|
|
|
|
}
|
|
|
|
if (ap->ModuleOfPred == PROLOG_MODULE) {
|
|
|
|
t[0] = MkAtomTerm(AtomProlog);
|
|
|
|
} else {
|
|
|
|
t[0] = ap->ModuleOfPred;
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG3, Yap_MkApplTerm(FunctorModule, 2, t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_FACT) {
|
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
return Yap_unify(ARG3, MkAtomTerm(AtomTrue));
|
|
|
|
} else {
|
|
|
|
return Yap_unify(ARG3, MkAtomTerm(AtomFalse));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_LINE) {
|
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
return Yap_unify(ARG3, MkIntTerm(cl->usc.ClLine));
|
|
|
|
} else if (cl->ClFlags & SrcMask) {
|
|
|
|
return Yap_unify(ARG3, MkIntTerm(cl->usc.ClSource->ag.line_number));
|
|
|
|
} else
|
|
|
|
return Yap_unify(ARG3, MkIntTerm(0));
|
|
|
|
}
|
|
|
|
} else if (FunctorOfTerm(t1) == FunctorMegaClause) {
|
|
|
|
PredEntry *ap = (PredEntry *)IntegerOfTerm(ArgOfTerm(1, t1));
|
|
|
|
MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
|
|
|
|
|
|
|
|
if (op == CL_PROP_ERASED) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_PRED || op == CL_PROP_FILE || op == CL_PROP_STREAM) {
|
|
|
|
if (op == CL_PROP_FILE) {
|
|
|
|
if (ap->src.OwnerFile)
|
|
|
|
return Yap_unify(ARG3, MkAtomTerm(ap->src.OwnerFile));
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
Functor nf = ap->FunctorOfPred;
|
|
|
|
arity_t arity = ArityOfFunctor(nf);
|
|
|
|
Atom name = NameOfFunctor(nf);
|
|
|
|
Term t[2];
|
|
|
|
|
|
|
|
t[0] = MkAtomTerm(name);
|
|
|
|
t[1] = MkIntegerTerm(arity);
|
|
|
|
t[1] = Yap_MkApplTerm(FunctorSlash, 2, t);
|
|
|
|
if (ap->ModuleOfPred == PROLOG_MODULE) {
|
|
|
|
t[0] = MkAtomTerm(AtomProlog);
|
|
|
|
} else {
|
|
|
|
t[0] = ap->ModuleOfPred;
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG3, Yap_MkApplTerm(FunctorModule, 2, t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_FACT) {
|
|
|
|
return Yap_unify(ARG3, MkAtomTerm(AtomTrue));
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_LINE) {
|
|
|
|
return Yap_unify(ARG3, MkIntTerm(mcl->ClLine));
|
|
|
|
}
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ((dbr = DBRefOfTerm(t1))->Flags & LogUpdMask) {
|
|
|
|
LogUpdClause *cl = (LogUpdClause *)dbr;
|
|
|
|
|
|
|
|
if (op == CL_PROP_ERASED) {
|
|
|
|
if (cl->ClFlags & ErasedMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG3, MkAtomTerm(AtomTrue)))
|
|
|
|
return FALSE;
|
2013-11-05 17:59:19 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG3, MkAtomTerm(AtomFalse)))
|
|
|
|
return FALSE;
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_PRED || op == CL_PROP_FILE) {
|
|
|
|
PredEntry *ap = cl->ClPred;
|
|
|
|
Term t[2];
|
|
|
|
|
|
|
|
if (op == CL_PROP_FILE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (ap->src.OwnerFile)
|
|
|
|
return Yap_unify(ARG3, MkAtomTerm(ap->src.OwnerFile));
|
|
|
|
else
|
|
|
|
return FALSE;
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
if (ap->ArityOfPE == 0) {
|
2015-10-22 00:53:26 +01:00
|
|
|
t[1] = MkAtomTerm((Atom)ap->FunctorOfPred);
|
2013-11-05 17:59:19 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
Functor nf = ap->FunctorOfPred;
|
|
|
|
arity_t arity = ArityOfFunctor(nf);
|
|
|
|
Atom name = NameOfFunctor(nf);
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
t[0] = MkAtomTerm(name);
|
|
|
|
t[1] = MkIntegerTerm(arity);
|
|
|
|
t[1] = Yap_MkApplTerm(FunctorSlash, 2, t);
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
if (ap->ModuleOfPred == PROLOG_MODULE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
t[0] = MkAtomTerm(AtomProlog);
|
2013-11-05 17:59:19 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
t[0] = ap->ModuleOfPred;
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_unify(ARG3, Yap_MkApplTerm(FunctorModule, 2, t));
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
if (op == CL_PROP_FACT) {
|
|
|
|
if (cl->ClFlags & FactMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_unify(ARG3, MkAtomTerm(AtomTrue));
|
2013-11-05 17:59:19 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_unify(ARG3, MkAtomTerm(AtomFalse));
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == CL_PROP_LINE) {
|
|
|
|
if (cl->ClFlags & FactMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_unify(ARG3, MkIntTerm(cl->lusl.ClLine));
|
|
|
|
} else if (cl->ClFlags & SrcMask) {
|
|
|
|
return Yap_unify(ARG3, MkIntTerm(cl->lusl.ClSource->ag.line_number));
|
2015-08-18 20:32:24 +01:00
|
|
|
} else
|
2015-09-21 23:05:36 +01:00
|
|
|
return Yap_unify(ARG3, MkIntTerm(0));
|
2013-11-05 17:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-04-30 01:16:40 +01:00
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int p_nth_instance(USES_REGS1) {
|
|
|
|
PredEntry *pe;
|
2015-01-06 17:47:58 +00:00
|
|
|
arity_t pred_arity;
|
2013-12-09 14:16:30 +00:00
|
|
|
Functor pred_f;
|
|
|
|
Term pred_module;
|
|
|
|
Term t4 = Deref(ARG4);
|
|
|
|
|
|
|
|
if (IsVarTerm(t4)) {
|
|
|
|
// we must know I or count;
|
2015-10-22 00:53:26 +01:00
|
|
|
Term TCount;
|
|
|
|
Int Count;
|
2013-12-09 14:16:30 +00:00
|
|
|
|
|
|
|
TCount = Deref(ARG3);
|
|
|
|
if (IsVarTerm(TCount)) {
|
|
|
|
return FALSE; // backtrack?
|
|
|
|
}
|
|
|
|
if (!IsIntegerTerm(TCount)) {
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, TCount, "nth_instance/3");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
Count = IntegerOfTerm(TCount);
|
|
|
|
if (Count <= 0) {
|
2015-04-13 13:28:17 +01:00
|
|
|
if (Count)
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, TCount, "nth_clause/3");
|
2013-12-09 14:16:30 +00:00
|
|
|
else
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_ZERO, TCount, "nth_clause/3");
|
2013-12-09 14:16:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-09-27 18:31:12 +01:00
|
|
|
pe = Yap_get_pred(Deref(ARG1), Deref(ARG2), "nth_clause/3");
|
2013-12-09 14:16:30 +00:00
|
|
|
if (pe) {
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(47, pe);
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
if (Deref(ARG2) == IDB_MODULE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return Yap_db_nth_recorded(pe, Count PASS_REGS);
|
2013-12-09 14:16:30 +00:00
|
|
|
} else {
|
|
|
|
Int CurSlot, sl4;
|
2015-01-06 17:47:58 +00:00
|
|
|
arity_t i;
|
2013-12-09 14:16:30 +00:00
|
|
|
void *cl0;
|
|
|
|
|
|
|
|
if (!pe)
|
2015-10-22 00:53:26 +01:00
|
|
|
return FALSE;
|
|
|
|
if (!(pe->PredFlags & (SourcePredFlag | LogUpdatePredFlag))) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
CurSlot = Yap_StartSlots();
|
2013-12-09 14:16:30 +00:00
|
|
|
/* I have pe and n */
|
2015-10-22 00:53:26 +01:00
|
|
|
sl4 = Yap_InitSlot(ARG4);
|
2013-12-09 14:16:30 +00:00
|
|
|
/* in case we have to index or to expand code */
|
|
|
|
for (i = 1; i <= pe->ArityOfPE; i++) {
|
2015-10-22 00:53:26 +01:00
|
|
|
XREGS[i] = MkVarTerm();
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (pe->OpcodeOfPred == INDEX_OPCODE) {
|
|
|
|
IPred(pe, 0, CP);
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
cl0 = Yap_NthClause(pe, Count);
|
2015-10-22 00:53:26 +01:00
|
|
|
ARG4 = Yap_GetFromSlot(sl4);
|
2015-04-13 13:28:17 +01:00
|
|
|
LOCAL_CurSlot = CurSlot;
|
2013-12-09 14:16:30 +00:00
|
|
|
if (cl0 == NULL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
if (pe->PredFlags & LogUpdatePredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
LogUpdClause *cl = cl0;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2013-12-09 14:16:30 +00:00
|
|
|
#if MULTIPLE_STACKS
|
2015-10-22 00:53:26 +01:00
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
INC_CLREF_COUNT(cl);
|
2013-12-09 14:16:30 +00:00
|
|
|
#else
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
2013-12-09 14:16:30 +00:00
|
|
|
#endif
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return Yap_unify(MkDBRefTerm((DBRef)cl), ARG4);
|
2013-12-09 14:16:30 +00:00
|
|
|
} else if (pe->PredFlags & MegaClausePredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
|
|
|
if (mcl->ClFlags & ExoMask) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return Yap_unify(Yap_MkExoRefTerm(pe, Count - 1), ARG4);
|
|
|
|
}
|
|
|
|
/* fast access to nth element, all have same size */
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return Yap_unify(Yap_MkMegaRefTerm(pe, cl0), ARG4);
|
2013-12-09 14:16:30 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return Yap_unify(Yap_MkStaticRefTerm(cl0, pe), ARG4);
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* t4 is bound, we have a reference */
|
|
|
|
if (IsDBRefTerm(t4)) {
|
|
|
|
DBRef ref = DBRefOfTerm(t4);
|
|
|
|
if (ref->Flags & LogUpdMask) {
|
|
|
|
LogUpdClause *cl = (LogUpdClause *)ref;
|
|
|
|
LogUpdClause *ocl;
|
|
|
|
UInt icl = 0;
|
|
|
|
|
|
|
|
pe = cl->ClPred;
|
2015-10-22 00:53:26 +01:00
|
|
|
PELOCK(66, pe);
|
2013-12-09 14:16:30 +00:00
|
|
|
if (cl->ClFlags & ErasedMask) {
|
2015-10-22 00:53:26 +01:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
ocl = ClauseCodeToLogUpdClause(pe->cs.p_code.FirstClause);
|
|
|
|
do {
|
2015-10-22 00:53:26 +01:00
|
|
|
icl++;
|
|
|
|
if (cl == ocl)
|
|
|
|
break;
|
|
|
|
ocl = ocl->ClNext;
|
2013-12-09 14:16:30 +00:00
|
|
|
} while (ocl != NULL);
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
if (ocl == NULL) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG3, MkIntegerTerm(icl))) {
|
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Yap_unify_immediate_ref(ref PASS_REGS);
|
|
|
|
}
|
|
|
|
} else if (IsApplTerm(t4)) {
|
|
|
|
Functor f = FunctorOfTerm(t4);
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2013-12-09 14:16:30 +00:00
|
|
|
if (f == FunctorStaticClause) {
|
|
|
|
StaticClause *cl = Yap_ClauseFromTerm(t4), *cl0;
|
|
|
|
pe = (PredEntry *)IntegerOfTerm(ArgOfTerm(2, t4));
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
if (!pe) {
|
2015-10-22 00:53:26 +01:00
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!pe->cs.p_code.NOfClauses)
|
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
cl0 = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause);
|
2015-10-22 00:53:26 +01:00
|
|
|
// linear scan
|
2013-12-09 14:16:30 +00:00
|
|
|
for (i = 1; i < pe->cs.p_code.NOfClauses; i++) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (cl0 == cl) {
|
|
|
|
if (!Yap_unify(MkIntTerm(i), ARG3))
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
} else if (f == FunctorMegaClause) {
|
|
|
|
MegaClause *mcl;
|
|
|
|
yamop *cl = Yap_MegaClauseFromTerm(t4);
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
pe = Yap_MegaClausePredicateFromTerm(t4);
|
|
|
|
mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
2015-10-22 00:53:26 +01:00
|
|
|
i = ((char *)cl - (char *)mcl->ClCode) / mcl->ClItemSize;
|
2013-12-09 14:16:30 +00:00
|
|
|
if (!Yap_unify(MkIntTerm(i), ARG3))
|
2015-10-22 00:53:26 +01:00
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
} else if (f == FunctorExoClause) {
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
pe = Yap_ExoClausePredicateFromTerm(t4);
|
|
|
|
i = Yap_ExoClauseFromTerm(t4);
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(MkIntTerm(i + 1), ARG3)) {
|
|
|
|
return FALSE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_REFERENCE, t4, "nth_clause/3");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_REFERENCE, t4, "nth_clause/3");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pred_module = pe->ModuleOfPred;
|
|
|
|
if (pred_module != IDB_MODULE) {
|
|
|
|
pred_f = pe->FunctorOfPred;
|
|
|
|
pred_arity = pe->ArityOfPE;
|
|
|
|
} else {
|
|
|
|
if (pe->PredFlags & NumberDBPredFlag) {
|
|
|
|
pred_f = (Functor)MkIntegerTerm(pe->src.IndxId);
|
|
|
|
pred_arity = 0;
|
|
|
|
} else {
|
|
|
|
pred_f = pe->FunctorOfPred;
|
|
|
|
if (pe->PredFlags & AtomDBPredFlag) {
|
2015-10-22 00:53:26 +01:00
|
|
|
pred_arity = 0;
|
2013-12-09 14:16:30 +00:00
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
pred_arity = ArityOfFunctor(pred_f);
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pred_arity) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG1, Yap_MkNewApplTerm(pred_f, pred_arity)))
|
2013-12-09 14:16:30 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG1, MkAtomTerm((Atom)pred_f)))
|
2013-12-09 14:16:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pred_module == PROLOG_MODULE) {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG2, TermProlog))
|
2013-12-09 14:16:30 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2015-10-22 00:53:26 +01:00
|
|
|
if (!Yap_unify(ARG2, pred_module))
|
2013-12-09 14:16:30 +00:00
|
|
|
return FALSE;
|
2015-04-13 13:28:17 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
2013-12-09 14:16:30 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int including(USES_REGS1) {
|
2015-09-21 23:05:36 +01:00
|
|
|
bool rc = Yap_unify(ARG1, LOCAL_Including);
|
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
LOCAL_Including = Deref(ARG2);
|
2015-10-22 00:53:26 +01:00
|
|
|
return true;
|
2015-09-21 23:05:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
static Int predicate_flags(
|
|
|
|
USES_REGS1) { /* $predicate_flags(+Functor,+Mod,?OldFlags,?NewFlags) */
|
2015-06-19 01:30:13 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
pred_flags_t newFl;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
|
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
2016-01-03 01:27:36 +00:00
|
|
|
return false;
|
2015-06-19 01:30:13 +01:00
|
|
|
}
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
while ((pe = RepPredProp(PredPropByAtom(AtomOfTerm(t1), mod))) == NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, ARG1, "while generating new predicate");
|
2015-06-19 01:30:13 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
while ((pe = RepPredProp(PredPropByFunc(funt, mod))) == NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_HEAP, ARG1, "while generating new predicate");
|
2015-06-19 01:30:13 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return (FALSE);
|
|
|
|
PELOCK(92, pe);
|
|
|
|
if (!Yap_unify_constant(ARG3, MkIntegerTerm(pe->PredFlags))) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
ARG4 = Deref(ARG4);
|
|
|
|
if (IsVarTerm(ARG4)) {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return (TRUE);
|
|
|
|
} else if (!IsIntegerTerm(ARG4)) {
|
|
|
|
Term te = Yap_Eval(ARG4);
|
|
|
|
|
|
|
|
if (IsIntegerTerm(te)) {
|
|
|
|
newFl = IntegerOfTerm(te);
|
|
|
|
} else {
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, ARG4, "flags");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
newFl = IntegerOfTerm(ARG4);
|
|
|
|
pe->PredFlags = newFl;
|
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
static bool pred_flag_clause(Functor f, Term mod, const char *name,
|
|
|
|
pred_flags_t val USES_REGS) {
|
|
|
|
Term tn;
|
|
|
|
|
|
|
|
Term s[2];
|
|
|
|
s[0] = MkAtomTerm(Yap_LookupAtom(name));
|
|
|
|
#if SIZEOF_INT_P == 8
|
|
|
|
s[1] = MkIntegerTerm(val);
|
|
|
|
#elif USE_GMP
|
|
|
|
{
|
2016-03-30 17:35:03 +01:00
|
|
|
char text[64];
|
2016-01-03 01:27:36 +00:00
|
|
|
MP_INT rop;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2016-03-30 17:35:03 +01:00
|
|
|
snprintf(text, 64, "%I64d", (long long int)val);
|
2016-01-03 01:27:36 +00:00
|
|
|
#elif HAVE_SNPRINTF
|
2016-03-30 17:35:03 +01:00
|
|
|
snprintf(text, 64, "%lld", (long long int)val);
|
2016-01-03 01:27:36 +00:00
|
|
|
#else
|
2016-03-30 17:35:03 +01:00
|
|
|
sprintf(text, "%lld", (long long int)val);
|
2016-01-03 01:27:36 +00:00
|
|
|
#endif
|
2016-03-30 17:35:03 +01:00
|
|
|
mpz_init_set_str(&rop, text, 10);
|
|
|
|
s[1] = Yap_MkBigIntTerm((void *)&rop);
|
2016-01-03 01:27:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
tn = Yap_MkApplTerm(f, 2, s);
|
|
|
|
yamop *code_adr =
|
|
|
|
Yap_cclause(tn, 2, mod, tn); /* vsc: give the number of arguments to
|
|
|
|
cclause() in case there is a overflow */
|
|
|
|
if (LOCAL_ErrorMessage) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-21 11:30:13 +00:00
|
|
|
return Yap_addclause(tn, code_adr, TermAssertz, mod, NULL);
|
2016-01-03 01:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pred_entry *Yap_MkLogPred(struct pred_entry *pe) {
|
|
|
|
pe->PredFlags = LogUpdatePredFlag;
|
|
|
|
pe->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = FAILCODE;
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int init_pred_flag_vals(USES_REGS1) {
|
|
|
|
Functor f;
|
|
|
|
Term mod = Deref(ARG2), t = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
return false;
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
f = FunctorOfTerm(t);
|
|
|
|
arity_t Arity = ArityOfFunctor(f);
|
|
|
|
if (Arity != 2)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pred_flag_clause(f, mod, "asm", AsmPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "atom_db", AtomDBPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "back_c", BackCPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "c", CPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "c_args", CArgsPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "compiled", CompiledPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "count", CountPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "discontiguous", DiscontiguousPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "immediate_update", DynamicPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "hidden", HiddenPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "in_use", InUsePredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "indexed", IndexedPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "log_update", LogUpdatePredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "mega_clause", MegaClausePredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "meta", MetaPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "module_transparent",
|
|
|
|
ModuleTransparentPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "multi", MultiFileFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "no_spy", NoSpyPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "no_trace", NoTracePredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "number_db", NumberDBPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "profiled", ProfiledPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "quasi_quotation", QuasiQuotationPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "safe", SafePredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "sequential", SequentialPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "source", SourcePredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "spied", SpiedPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "standard", StandardPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "swi_env", SWIEnvPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "sync", SyncPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "sys_export", SysExportPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "tabled", TabledPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "test", TestPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "thread_local", ThreadLocalPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "udi", UDIPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "user_c", UserCPredFlag PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "system", SystemPredFlags PASS_REGS);
|
|
|
|
pred_flag_clause(f, mod, "foreign", ForeignPredFlags PASS_REGS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:53:26 +01:00
|
|
|
void Yap_InitCdMgr(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2007-01-24 10:01:40 +00:00
|
|
|
Term cm = CurrentModule;
|
|
|
|
|
2016-01-03 01:27:36 +00:00
|
|
|
Yap_InitCPred("$init_pred_flag_vals", 2, init_pred_flag_vals, SyncPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$start_consult", 3, p_startconsult,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$show_consult_level", 1, p_showconslultlev, SafePredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$end_consult", 0, p_endconsult, SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$set_spy", 2, p_setspy, SyncPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$rm_spy", 2, p_rmspy, SafePredFlag | SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* gc() may happen during compilation, hence these predicates are
|
2015-10-22 00:53:26 +01:00
|
|
|
now unsafe */
|
2015-06-19 01:30:13 +01:00
|
|
|
Yap_InitCPred("$predicate_flags", 4, predicate_flags, SyncPredFlag);
|
2015-12-15 09:28:43 +00:00
|
|
|
Yap_InitCPred("$compile", 5, p_compile, SyncPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$purge_clauses", 2, p_purge_clauses,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$is_dynamic", 2, p_is_dynamic, TestPredFlag | SafePredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$is_metapredicate", 2, p_is_metapredicate,
|
|
|
|
TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_log_updatable", 2, p_is_log_updatable,
|
|
|
|
TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_thread_local", 2, p_is_thread_local,
|
|
|
|
TestPredFlag | SafePredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$is_source", 2, p_is_source, TestPredFlag | SafePredFlag);
|
2013-01-11 16:45:14 +00:00
|
|
|
Yap_InitCPred("$is_exo", 2, p_is_exo, TestPredFlag | SafePredFlag);
|
2016-03-05 17:38:08 +00:00
|
|
|
Yap_InitCPred("$owner_file", 3, owner_file, SafePredFlag);
|
2014-10-02 14:21:43 +01:00
|
|
|
Yap_InitCPred("$set_owner_file", 3, p_set_owner_file, SafePredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$mk_d", 2, p_mk_d, SafePredFlag);
|
2014-04-06 17:06:19 +01:00
|
|
|
Yap_InitCPred("$sys_export", 2, p_sys_export, TestPredFlag | SafePredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$pred_exists", 2, p_pred_exists, TestPredFlag | SafePredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$number_of_clauses", 3, p_number_of_clauses,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$undefined", 2, p_undefined, SafePredFlag | TestPredFlag);
|
2016-07-31 05:15:11 +01:00
|
|
|
Yap_InitCPred("$undefp_handler", 2, undefp_handler,
|
|
|
|
SafePredFlag | TestPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$optimizer_on", 0, p_optimizer_on,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$clean_up_dead_clauses", 0, p_clean_up_dead_clauses,
|
|
|
|
SyncPredFlag);
|
|
|
|
Yap_InitCPred("$optimizer_off", 0, p_optimizer_off,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$kill_dynamic", 2, p_kill_dynamic,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$new_multifile", 3, p_new_multifile,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_multifile", 2, p_is_multifile,
|
|
|
|
TestPredFlag | SafePredFlag);
|
2016-03-05 12:21:58 +00:00
|
|
|
Yap_InitCPred("$new_system_predicate", 3, new_system_predicate,
|
2016-01-03 01:27:36 +00:00
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_system_predicate", 2, p_is_system_predicate,
|
|
|
|
TestPredFlag | SafePredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$new_discontiguous", 3, p_new_discontiguous,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_discontiguous", 2, p_is_discontiguous,
|
|
|
|
TestPredFlag | SafePredFlag);
|
2013-12-11 01:05:51 +00:00
|
|
|
Yap_InitCPred("$is_no_trace", 2, p_is_no_trace, TestPredFlag | SafePredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$set_no_trace", 2, p_set_no_trace,
|
|
|
|
TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$is_profiled", 1, p_is_profiled, SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$profile_info", 3, p_profile_info,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$profile_reset", 2, p_profile_reset,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_call_counted", 1, p_is_call_counted,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$call_count_info", 3, p_call_count_info,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$call_count_set", 6, p_call_count_set,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$call_count_reset", 0, p_call_count_reset,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$set_pred_module", 2, p_set_pred_module, SafePredFlag);
|
2014-09-22 18:09:23 +01:00
|
|
|
Yap_InitCPred("$set_pred_owner", 2, p_set_pred_owner, SafePredFlag);
|
2016-01-04 14:11:09 +00:00
|
|
|
Yap_InitCPred("$hide_predicate", 2, hide_predicate, SafePredFlag);
|
2012-11-25 23:36:43 +00:00
|
|
|
Yap_InitCPred("$stash_predicate", 2, p_stash_predicate, SafePredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$hidden_predicate", 2, p_hidden_predicate, SafePredFlag);
|
|
|
|
Yap_InitCPred("$log_update_clause", 4, p_log_update_clause, SyncPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$continue_log_update_clause", 5, p_continue_log_update_clause,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$log_update_clause_erase", 4, p_log_update_clause_erase,
|
|
|
|
SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_log_update_clause_erase", 5,
|
|
|
|
p_continue_log_update_clause_erase,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$static_clause", 4, p_static_clause, SyncPredFlag);
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$continue_static_clause", 5, p_continue_static_clause,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
|
|
|
Yap_InitCPred("$static_pred_statistics", 5, p_static_pred_statistics,
|
|
|
|
SyncPredFlag);
|
|
|
|
Yap_InitCPred("instance_property", 3, instance_property,
|
|
|
|
SafePredFlag | SyncPredFlag);
|
2013-12-09 14:16:30 +00:00
|
|
|
Yap_InitCPred("$fetch_nth_clause", 4, p_nth_instance, SyncPredFlag);
|
2011-04-30 01:16:40 +01:00
|
|
|
CurrentModule = DBLOAD_MODULE;
|
|
|
|
Yap_InitCPred("dbload_get_space", 4, p_dbload_get_space, 0L);
|
|
|
|
Yap_InitCPred("dbassert", 3, p_dbassert, 0L);
|
|
|
|
CurrentModule = cm;
|
2015-10-22 00:53:26 +01:00
|
|
|
Yap_InitCPred("$predicate_erased_statistics", 5,
|
|
|
|
p_predicate_erased_statistics, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$including", 2, including, SyncPredFlag | HiddenPredFlag);
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2004-04-07 23:04:04 +01:00
|
|
|
#ifdef DEBUG
|
2015-09-21 23:05:36 +01:00
|
|
|
Yap_InitCPred("$predicate_lu_cps", 4, p_predicate_lu_cps, 0L);
|
2004-04-07 23:04:04 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|