2001-04-09 20:54:03 +01: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 *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: Code manager *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "clause.h"
|
|
|
|
#include "yapio.h"
|
|
|
|
#include "eval.h"
|
|
|
|
#include "tracer.h"
|
|
|
|
#ifdef YAPOR
|
|
|
|
#include "or.macros.h"
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-06-18 06:22:35 +01:00
|
|
|
STATIC_PROTO(void retract_all, (PredEntry *, int));
|
2002-12-27 16:53:09 +00:00
|
|
|
STATIC_PROTO(void add_first_static, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void add_first_dynamic, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void asserta_stat_clause, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void asserta_dynam_clause, (PredEntry *, yamop *));
|
|
|
|
STATIC_PROTO(void assertz_stat_clause, (PredEntry *, yamop *, int));
|
|
|
|
STATIC_PROTO(void assertz_dynam_clause, (PredEntry *, yamop *));
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void expand_consult, (void));
|
2001-12-12 19:36:51 +00:00
|
|
|
STATIC_PROTO(int not_was_reconsulted, (PredEntry *, Term, int));
|
2001-04-09 20:54:03 +01:00
|
|
|
#if EMACS
|
|
|
|
STATIC_PROTO(int last_clause_number, (PredEntry *));
|
|
|
|
#endif
|
|
|
|
STATIC_PROTO(int static_in_use, (PredEntry *, int));
|
|
|
|
#if !defined(YAPOR) && !defined(THREADS)
|
|
|
|
STATIC_PROTO(Int search_for_static_predicate_in_use, (PredEntry *, int));
|
|
|
|
STATIC_PROTO(void mark_pred, (int, PredEntry *));
|
|
|
|
STATIC_PROTO(void do_toggle_static_predicates_in_use, (int));
|
|
|
|
#endif
|
|
|
|
STATIC_PROTO(Int p_number_of_clauses, (void));
|
|
|
|
STATIC_PROTO(Int p_compile, (void));
|
|
|
|
STATIC_PROTO(Int p_compile_dynamic, (void));
|
|
|
|
STATIC_PROTO(Int p_purge_clauses, (void));
|
|
|
|
STATIC_PROTO(Int p_setspy, (void));
|
|
|
|
STATIC_PROTO(Int p_rmspy, (void));
|
|
|
|
STATIC_PROTO(Int p_startconsult, (void));
|
|
|
|
STATIC_PROTO(Int p_showconslultlev, (void));
|
|
|
|
STATIC_PROTO(Int p_endconsult, (void));
|
|
|
|
STATIC_PROTO(Int p_undefined, (void));
|
|
|
|
STATIC_PROTO(Int p_in_use, (void));
|
|
|
|
STATIC_PROTO(Int p_new_multifile, (void));
|
|
|
|
STATIC_PROTO(Int p_is_multifile, (void));
|
|
|
|
STATIC_PROTO(Int p_optimizer_on, (void));
|
|
|
|
STATIC_PROTO(Int p_optimizer_off, (void));
|
|
|
|
STATIC_PROTO(Int p_in_this_f_before, (void));
|
|
|
|
STATIC_PROTO(Int p_first_cl_in_f, (void));
|
|
|
|
STATIC_PROTO(Int p_mk_cl_not_first, (void));
|
|
|
|
STATIC_PROTO(Int p_is_dynamic, (void));
|
|
|
|
STATIC_PROTO(Int p_kill_dynamic, (void));
|
|
|
|
STATIC_PROTO(Int p_compile_mode, (void));
|
|
|
|
STATIC_PROTO(Int p_is_profiled, (void));
|
|
|
|
STATIC_PROTO(Int p_profile_info, (void));
|
|
|
|
STATIC_PROTO(Int p_profile_reset, (void));
|
2002-09-03 15:28:09 +01:00
|
|
|
STATIC_PROTO(Int p_is_call_counted, (void));
|
|
|
|
STATIC_PROTO(Int p_call_count_info, (void));
|
|
|
|
STATIC_PROTO(Int p_call_count_set, (void));
|
|
|
|
STATIC_PROTO(Int p_call_count_reset, (void));
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(Int p_toggle_static_predicates_in_use, (void));
|
2002-11-11 17:38:10 +00:00
|
|
|
STATIC_PROTO(Atom YapConsultingFile, (void));
|
2004-02-12 12:37:12 +00:00
|
|
|
STATIC_PROTO(Int PredForCode,(yamop *, Atom *, UInt *, Term *));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define PredArity(p) (p->ArityOfPE)
|
|
|
|
#define TRYCODE(G,F,N) ( (N)<5 ? (op_numbers)((int)F+(N)*3) : G)
|
|
|
|
#define NEXTOP(V,TYPE) ((yamop *)(&((V)->u.TYPE.next)))
|
|
|
|
|
2003-11-16 22:12:29 +00:00
|
|
|
#define IN_BLOCK(P,B,SZ) ((CODEADDR)(P) >= (CODEADDR)(B) && \
|
|
|
|
(CODEADDR)(P) < (CODEADDR)(B)+(SZ))
|
2002-12-27 16:53:09 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
EXECUTING PROLOG CLAUSES
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
static_in_use(PredEntry *p, int check_everything)
|
|
|
|
{
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
return(FALSE);
|
|
|
|
#else
|
|
|
|
CELL pflags = p->PredFlags;
|
|
|
|
if (pflags & (DynamicPredFlag|LogUpdatePredFlag)) {
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
if (STATIC_PREDICATES_MARKED) {
|
2003-04-30 18:46:05 +01:00
|
|
|
return (p->PredFlags & InUsePredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* This code does not work for YAPOR or THREADS!!!!!!!! */
|
2002-02-26 20:16:36 +00:00
|
|
|
return(search_for_static_predicate_in_use(p, check_everything));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
ADDING AND REMOVE INFO TO A PROCEDURE
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* supportted for fast predicates
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define is_dynamic(pe) (pe->PredFlags & DynamicPredFlag)
|
|
|
|
#define is_static(pe) (pe->PredFlags & CompiledPredFlag)
|
|
|
|
#define is_fast(pe) (pe->PredFlags & FastPredFlag)
|
|
|
|
#define is_logupd(pe) (pe->PredFlags & LogUpdatePredFlag)
|
|
|
|
#ifdef TABLING
|
|
|
|
#define is_tabled(pe) (pe->PredFlags & TabledPredFlag)
|
|
|
|
#endif /* TABLING */
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
Indexation Info
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
#define ByteAdr(X) ((Int) &(X))
|
|
|
|
|
|
|
|
/* Index a prolog pred, given its predicate entry */
|
2003-12-01 17:27:42 +00:00
|
|
|
/* ap is already locked. */
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
IPred(PredEntry *ap)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *BaseAddr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_Option['i' - 'a' + 1]) {
|
2004-02-12 12:37:12 +00:00
|
|
|
Term tmod = ap->ModuleOfPred;
|
|
|
|
if (!tmod)
|
|
|
|
tmod = TermProlog;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\t');
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_plwrite(tmod, Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,':');
|
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)) {
|
|
|
|
Yap_plwrite(t, Yap_DebugPutc, 0);
|
|
|
|
} else {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
Atom At = NameOfFunctor(f);
|
|
|
|
Yap_plwrite(MkAtomTerm(At), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite(MkIntTerm(ArityOfFunctor(f)), Yap_DebugPutc, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ap->ArityOfPE == 0) {
|
|
|
|
Atom At = (Atom)ap->FunctorOfPred;
|
|
|
|
Yap_plwrite(MkAtomTerm(At), Yap_DebugPutc, 0);
|
|
|
|
} else {
|
|
|
|
Functor f = ap->FunctorOfPred;
|
|
|
|
Atom At = NameOfFunctor(f);
|
|
|
|
Yap_plwrite(MkAtomTerm(At), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite(MkIntTerm(ArityOfFunctor(f)), Yap_DebugPutc, 0);
|
|
|
|
}
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\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)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"trying to index a dynamic predicate");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
if ((BaseAddr = Yap_PredIsIndexable(ap)) != NULL) {
|
|
|
|
ap->cs.p_code.TrueCodeOfPred = BaseAddr;
|
2001-04-09 20:54:03 +01:00
|
|
|
ap->PredFlags |= IndexedPredFlag;
|
|
|
|
}
|
|
|
|
if (ap->PredFlags & SpiedPredFlag) {
|
2002-11-18 18:18:05 +00:00
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-12-27 16:53:09 +00:00
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
ap->OpcodeOfPred = ((yamop *)(ap->CodeOfPred))->opc;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_Option['i' - 'a' + 1])
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-12-27 16:53:09 +00:00
|
|
|
Yap_IPred(PredEntry *p)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2002-12-27 16:53:09 +00:00
|
|
|
IPred(p);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define GONEXT(TYPE) code_p = ((yamop *)(&(code_p->u.TYPE.next)))
|
|
|
|
|
|
|
|
static void
|
2003-08-27 14:37:10 +01:00
|
|
|
RemoveMainIndex(PredEntry *ap)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *First = ap->cs.p_code.FirstClause;
|
|
|
|
int spied = ap->PredFlags & SpiedPredFlag;
|
|
|
|
|
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);
|
|
|
|
ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
2003-12-18 16:38:40 +00:00
|
|
|
} else if (ap->cs.p_code.NOfClauses > 1
|
|
|
|
#ifdef TABLING
|
|
|
|
||ap->PredFlags & TabledPredFlag
|
|
|
|
#endif
|
|
|
|
) {
|
2003-08-27 14:37:10 +01:00
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
|
|
|
decrease_ref_counter(yamop *ptr, yamop *b, yamop *e, yamop *sc)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
if (ptr != FAILCODE && ptr != sc && (ptr < b || ptr > e)) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(ptr);
|
|
|
|
LOCK(cl->ClLock);
|
|
|
|
cl->ClRefCount--;
|
2003-11-12 12:33:31 +00:00
|
|
|
if (cl->ClFlags & ErasedMask &&
|
|
|
|
!(cl->ClRefCount) &&
|
|
|
|
!(cl->ClFlags & InUseMask)) {
|
|
|
|
/* last ref to the clause */
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(cl->ClLock);
|
2003-11-12 12:33:31 +00:00
|
|
|
Yap_ErLogUpdCl(cl);
|
2004-02-19 19:24:46 +00:00
|
|
|
} else {
|
|
|
|
UNLOCK(cl->ClLock);
|
2003-11-12 12:33:31 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2003-11-12 12:33:31 +00:00
|
|
|
cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *suspend_code)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
while (ipc < end) {
|
|
|
|
op_numbers op = Yap_op_from_opcode(ipc->opc);
|
|
|
|
/* printf("op: %d %p->%p\n", op, ipc, end); */
|
|
|
|
switch(op) {
|
|
|
|
case _Ystop:
|
|
|
|
/* end of clause, for now */
|
|
|
|
return;
|
|
|
|
case _index_dbref:
|
|
|
|
case _index_blob:
|
|
|
|
ipc = NEXTOP(ipc,e);
|
|
|
|
break;
|
2004-02-05 16:57:02 +00:00
|
|
|
case _lock_lu:
|
|
|
|
/* just skip for now, but should worry about locking */
|
|
|
|
ipc = NEXTOP(ipc,p);
|
|
|
|
break;
|
2004-02-09 14:19:05 +00:00
|
|
|
case _unlock_lu:
|
|
|
|
/* just skip for now, but should worry about locking */
|
|
|
|
ipc = NEXTOP(ipc,e);
|
|
|
|
break;
|
2003-08-27 14:37:10 +01:00
|
|
|
case _retry_profiled:
|
|
|
|
case _count_retry:
|
2003-10-28 16:20:44 +00:00
|
|
|
ipc = NEXTOP(ipc,p);
|
|
|
|
break;
|
|
|
|
case _retry:
|
|
|
|
case _retry_killed:
|
2003-08-27 14:37:10 +01:00
|
|
|
case _trust:
|
2003-09-15 02:25:29 +01:00
|
|
|
case _trust_killed:
|
2003-08-27 14:37:10 +01:00
|
|
|
decrease_ref_counter(ipc->u.ld.d, beg, end, suspend_code);
|
|
|
|
ipc = NEXTOP(ipc,ld);
|
|
|
|
break;
|
|
|
|
case _try_clause:
|
|
|
|
case _try_me:
|
|
|
|
case _try_me1:
|
|
|
|
case _try_me2:
|
|
|
|
case _try_me3:
|
|
|
|
case _try_me4:
|
|
|
|
case _retry_me:
|
|
|
|
case _retry_me1:
|
|
|
|
case _retry_me2:
|
|
|
|
case _retry_me3:
|
|
|
|
case _retry_me4:
|
|
|
|
case _profiled_trust_me:
|
|
|
|
case _trust_me:
|
|
|
|
case _count_trust_me:
|
|
|
|
case _trust_me1:
|
|
|
|
case _trust_me2:
|
|
|
|
case _trust_me3:
|
|
|
|
case _trust_me4:
|
|
|
|
ipc = NEXTOP(ipc,ld);
|
|
|
|
break;
|
2003-09-15 02:25:29 +01:00
|
|
|
case _enter_lu_pred:
|
|
|
|
case _stale_lu_index:
|
|
|
|
ipc = ipc->u.Ill.l1;
|
|
|
|
break;
|
2003-08-27 14:37:10 +01:00
|
|
|
case _try_in:
|
|
|
|
case _trust_logical_pred:
|
|
|
|
case _jump:
|
|
|
|
case _jump_if_var:
|
|
|
|
ipc = NEXTOP(ipc,l);
|
|
|
|
break;
|
2003-10-28 01:16:03 +00:00
|
|
|
/* instructions type xl */
|
|
|
|
case _jump_if_nonvar:
|
|
|
|
ipc = NEXTOP(ipc,xl);
|
|
|
|
break;
|
2003-08-27 14:37:10 +01:00
|
|
|
/* instructions type e */
|
|
|
|
case _switch_on_type:
|
|
|
|
ipc = NEXTOP(ipc,llll);
|
|
|
|
break;
|
|
|
|
case _switch_list_nl:
|
|
|
|
ipc = NEXTOP(ipc,ollll);
|
|
|
|
break;
|
|
|
|
case _switch_on_arg_type:
|
|
|
|
ipc = NEXTOP(ipc,xllll);
|
|
|
|
break;
|
|
|
|
case _switch_on_sub_arg_type:
|
|
|
|
ipc = NEXTOP(ipc,sllll);
|
|
|
|
break;
|
|
|
|
case _if_not_then:
|
2003-10-02 13:59:05 +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:
|
|
|
|
ipc = NEXTOP(ipc,sl);
|
|
|
|
break;
|
|
|
|
default:
|
2003-12-01 17:27:42 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"Bug in Indexing Code: opcode %d", op);
|
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);
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
void
|
|
|
|
Yap_cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *sc)
|
|
|
|
{
|
|
|
|
cleanup_dangling_indices(ipc, beg, end, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
decrease_log_indices(LogUpdIndex *c, yamop *suspend_code)
|
|
|
|
{
|
|
|
|
/* decrease all reference counters */
|
|
|
|
yamop *beg = c->ClCode, *end, *ipc;
|
|
|
|
op_numbers op;
|
|
|
|
if (c->ClFlags & SwitchTableMask) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
op = Yap_op_from_opcode(beg->opc);
|
|
|
|
if ((op == _enter_lu_pred ||
|
|
|
|
op == _stale_lu_index) &&
|
|
|
|
beg->u.Ill.l1 != beg->u.Ill.l2) {
|
|
|
|
end = beg->u.Ill.l2;
|
|
|
|
} else {
|
|
|
|
end = (yamop *)((CODEADDR)c+Yap_SizeOfBlock((CODEADDR)c));
|
|
|
|
}
|
|
|
|
ipc = beg;
|
|
|
|
cleanup_dangling_indices(ipc, beg, end, suspend_code);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
|
|
|
kill_static_child_indxs(StaticIndex *indx)
|
|
|
|
{
|
|
|
|
StaticIndex *cl = indx->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
StaticIndex *next = cl->SiblingIndex;
|
|
|
|
kill_static_child_indxs(cl);
|
|
|
|
cl = next;
|
|
|
|
}
|
|
|
|
Yap_FreeCodeSpace((CODEADDR)indx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-24 00:00:43 +00:00
|
|
|
kill_first_log_iblock(LogUpdIndex *c, LogUpdIndex *parent, PredEntry *ap)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
|
|
|
|
2004-02-19 19:24:46 +00:00
|
|
|
LogUpdIndex *ncl;
|
|
|
|
/* parent is always locked, now I lock myself */
|
|
|
|
LOCK(c->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
if (parent != NULL) {
|
2004-02-19 19:24:46 +00:00
|
|
|
/* remove myself from parent */
|
2004-02-20 02:28:19 +00:00
|
|
|
LOCK(parent->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
if (c == parent->ChildIndex) {
|
|
|
|
parent->ChildIndex = c->SiblingIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2003-11-24 00:00:43 +00:00
|
|
|
LogUpdIndex *tcl = parent->ChildIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
while (tcl->SiblingIndex != c) {
|
|
|
|
tcl = tcl->SiblingIndex;
|
|
|
|
}
|
|
|
|
tcl->SiblingIndex = c->SiblingIndex;
|
|
|
|
}
|
2004-02-20 02:28:19 +00:00
|
|
|
UNLOCK(parent->ClLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2003-10-30 11:31:05 +00:00
|
|
|
/* make sure that a child cannot remove us */
|
2003-08-27 14:37:10 +01:00
|
|
|
c->ClRefCount++;
|
2004-02-19 19:24:46 +00:00
|
|
|
ncl = c->ChildIndex;
|
2004-02-20 02:28:19 +00:00
|
|
|
/* kill children */
|
|
|
|
while (ncl) {
|
|
|
|
UNLOCK(c->ClLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
kill_first_log_iblock(ncl, c, ap);
|
2004-02-20 02:28:19 +00:00
|
|
|
LOCK(c->ClLock);
|
|
|
|
ncl = c->ChildIndex;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2004-02-20 15:00:51 +00:00
|
|
|
UNLOCK(c->ClLock);
|
2003-10-14 02:32:55 +01:00
|
|
|
/* check if we are still the main index */
|
2003-11-24 00:00:43 +00:00
|
|
|
if (parent == NULL &&
|
2003-10-14 02:32:55 +01:00
|
|
|
ap->cs.p_code.TrueCodeOfPred == c->ClCode) {
|
2003-08-27 14:37:10 +01:00
|
|
|
RemoveMainIndex(ap);
|
|
|
|
}
|
2004-02-20 15:00:51 +00:00
|
|
|
LOCK(c->ClLock);
|
|
|
|
c->ClRefCount--;
|
2004-02-19 19:24:46 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
LogUpdIndex *parent = DBErasedIList, *c0 = NULL;
|
|
|
|
while (parent != NULL) {
|
|
|
|
if (c == parent) {
|
|
|
|
if (c0) c0->SiblingIndex = c->SiblingIndex;
|
|
|
|
else DBErasedIList = c->SiblingIndex;
|
|
|
|
}
|
|
|
|
c0 = parent;
|
|
|
|
parent = parent->SiblingIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
if (!((c->ClFlags & InUseMask) || c->ClRefCount)) {
|
2003-11-24 00:00:43 +00:00
|
|
|
if (parent != NULL) {
|
2004-02-20 02:28:19 +00:00
|
|
|
/* sat bye bye */
|
2004-02-20 15:00:51 +00:00
|
|
|
/* decrease refs */
|
|
|
|
decrease_log_indices(c, (yamop *)&(ap->cs.p_code.ExpandCode));
|
2004-02-20 02:28:19 +00:00
|
|
|
LOCK(parent->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
parent->ClRefCount--;
|
|
|
|
if (parent->ClFlags & ErasedMask &&
|
|
|
|
!(parent->ClFlags & InUseMask) &&
|
|
|
|
parent->ClRefCount == 0) {
|
2003-08-27 14:37:10 +01:00
|
|
|
/* cool, I can erase the father too. */
|
2003-11-24 00:00:43 +00:00
|
|
|
if (parent->ClFlags & SwitchRootMask) {
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(parent->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
kill_first_log_iblock(parent, NULL, ap);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(parent->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
kill_first_log_iblock(parent, parent->u.ParentIndex, ap);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2004-02-20 02:28:19 +00:00
|
|
|
} else {
|
|
|
|
UNLOCK(parent->ClLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(c->ClLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_FreeCodeSpace((CODEADDR)c);
|
2003-10-14 01:53:10 +01:00
|
|
|
} else {
|
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 */
|
2003-11-24 00:00:43 +00:00
|
|
|
if (parent != NULL &&
|
|
|
|
parent->ClFlags & SwitchTableMask) {
|
2004-02-20 02:28:19 +00:00
|
|
|
|
|
|
|
LOCK(parent->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
c->u.ParentIndex = parent->u.ParentIndex;
|
2004-02-20 02:28:19 +00:00
|
|
|
LOCK(parent->u.ParentIndex->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
parent->u.ParentIndex->ClRefCount++;
|
2004-02-20 02:28:19 +00:00
|
|
|
UNLOCK(parent->u.ParentIndex->ClLock);
|
2003-11-24 00:00:43 +00:00
|
|
|
parent->ClRefCount--;
|
2004-02-20 02:28:19 +00:00
|
|
|
UNLOCK(parent->ClLock);
|
2003-10-31 00:20:52 +00:00
|
|
|
}
|
2003-10-14 01:53:10 +01:00
|
|
|
c->ChildIndex = NULL;
|
2004-02-20 02:28:19 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
c->SiblingIndex = DBErasedIList;
|
|
|
|
DBErasedIList = c;
|
|
|
|
#endif
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(c->ClLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kill_top_static_iblock(StaticIndex *c, PredEntry *ap)
|
|
|
|
{
|
|
|
|
kill_static_child_indxs(c);
|
|
|
|
RemoveMainIndex(ap);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_kill_iblock(ClauseUnion *blk, ClauseUnion *parent_blk, PredEntry *ap)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
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;
|
2004-02-20 02:28:19 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
2004-02-19 19:24:46 +00:00
|
|
|
LOCK(cl->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
cl->ClRefCount++;
|
|
|
|
UNLOCK(cl->ClLock);
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
kill_first_log_iblock(c, cl, ap);
|
2004-02-20 02:28:19 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
|
|
|
LOCK(cl->ClLock);
|
|
|
|
cl->ClRefCount--;
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(cl->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
#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) {
|
|
|
|
parent_blk->si.ChildIndex = c->SiblingIndex;
|
|
|
|
} else {
|
|
|
|
while (cl->SiblingIndex != c) {
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
cl->SiblingIndex = c->SiblingIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kill_static_child_indxs(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:53:10 +01:00
|
|
|
/*
|
|
|
|
This predicate is supposed to be called with a
|
|
|
|
lock on the current predicate
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Yap_ErLogUpdIndex(LogUpdIndex *clau)
|
|
|
|
{
|
2003-10-30 11:31:05 +00:00
|
|
|
LogUpdIndex *c = clau;
|
2004-02-19 19:24:46 +00:00
|
|
|
if (clau->ClFlags & ErasedMask) {
|
|
|
|
/* nothing I can do, I have been erased already */
|
|
|
|
return;
|
|
|
|
}
|
2003-10-30 11:31:05 +00:00
|
|
|
if (c->ClFlags & SwitchRootMask) {
|
2004-02-20 02:28:19 +00:00
|
|
|
kill_first_log_iblock(clau, NULL, c->u.pred);
|
2003-10-30 11:31:05 +00:00
|
|
|
} else {
|
|
|
|
while (!(c->ClFlags & SwitchRootMask))
|
|
|
|
c = c->u.ParentIndex;
|
2004-02-20 02:28:19 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
2004-02-19 19:24:46 +00:00
|
|
|
LOCK(clau->u.ParentIndex->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
clau->ClRefCount++;
|
|
|
|
UNLOCK(clau->u.ParentIndex->ClLock);
|
|
|
|
#endif
|
2003-10-30 11:31:05 +00:00
|
|
|
kill_first_log_iblock(clau, clau->u.ParentIndex, c->u.pred);
|
2004-02-20 02:28:19 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
|
|
|
LOCK(clau->u.ParentIndex->ClLock);
|
|
|
|
/* protect against attempts at erasing */
|
|
|
|
clau->ClRefCount--;
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(clau->u.ParentIndex->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
#endif
|
2003-10-30 11:31:05 +00:00
|
|
|
}
|
2003-10-14 01:53:10 +01:00
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
void
|
|
|
|
Yap_RemoveLogUpdIndex(LogUpdIndex *cl)
|
|
|
|
{
|
2004-02-19 19:24:46 +00:00
|
|
|
if (cl->ClFlags & ErasedMask) {
|
|
|
|
/* nothing I can do, I have been erased already */
|
|
|
|
return;
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
if (cl->ClFlags & SwitchRootMask) {
|
|
|
|
kill_first_log_iblock(cl, NULL, cl->u.pred);
|
|
|
|
} else {
|
|
|
|
LogUpdIndex *pcl = cl;
|
|
|
|
while (!(pcl->ClFlags & SwitchRootMask)) {
|
|
|
|
pcl = pcl->u.ParentIndex;
|
|
|
|
}
|
2004-02-20 02:28:19 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
2004-02-19 19:24:46 +00:00
|
|
|
LOCK(cl->u.ParentIndex->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
/* protect against attempts at erasing */
|
|
|
|
cl->u.ParentIndex->ClRefCount++;
|
|
|
|
UNLOCK(cl->u.ParentIndex->ClLock);
|
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
kill_first_log_iblock(cl, cl->u.ParentIndex, pcl->u.pred);
|
2004-02-20 02:28:19 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
|
|
|
LOCK(cl->u.ParentIndex->ClLock);
|
|
|
|
/* protect against attempts at erasing */
|
|
|
|
cl->u.ParentIndex->ClRefCount--;
|
2004-02-19 19:24:46 +00:00
|
|
|
UNLOCK(cl->u.ParentIndex->ClLock);
|
2004-02-20 02:28:19 +00:00
|
|
|
#endif
|
2003-08-27 14:37: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 */
|
2002-11-11 17:38:10 +00:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
kill_top_static_iblock(cl, ap);
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_RemoveIndexation(PredEntry *ap)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
return RemoveIndexation(ap);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
Adding clauses
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#define assertz 0
|
|
|
|
#define consult 1
|
|
|
|
#define asserta 2
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-06-18 06:22:35 +01:00
|
|
|
retract_all(PredEntry *p, int in_use)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
yamop *fclause = NULL, *lclause = NULL;
|
2003-08-27 14:37:10 +01:00
|
|
|
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) {
|
2003-04-30 18:46:05 +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 {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdClause *ncl = cl->ClNext;
|
2003-11-26 18:36:35 +00:00
|
|
|
Yap_ErLogUpdCl(cl);
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = ncl;
|
|
|
|
} while (cl != NULL);
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(q);
|
|
|
|
|
2003-04-30 18:46:05 +01:00
|
|
|
do {
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClFlags & HasBlobsMask) {
|
|
|
|
DeadClause *dcl = (DeadClause *)cl;
|
|
|
|
dcl->NextCl = DeadClauses;
|
|
|
|
dcl->ClFlags = 0;
|
|
|
|
DeadClauses = dcl;
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2003-11-26 18:36:35 +00:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
2002-06-11 06:30:47 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.NOfClauses--;
|
|
|
|
if (cl->ClCode == p->cs.p_code.LastClause) break;
|
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (TRUE);
|
2003-04-30 18:46:05 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.FirstClause = fclause;
|
|
|
|
p->cs.p_code.LastClause = lclause;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (fclause == NIL) {
|
2002-10-14 17:25:38 +01:00
|
|
|
if (p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag)) {
|
|
|
|
p->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
} else {
|
|
|
|
p->OpcodeOfPred = UNDEF_OPCODE;
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
} else {
|
|
|
|
if (p->PredFlags & SpiedPredFlag) {
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2003-08-27 14:37:10 +01:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (p->PredFlags & IndexedPredFlag) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
2003-08-27 14:37:10 +01:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PROFILING) {
|
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
|
|
|
} else
|
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
|
|
|
#ifdef YAPOR
|
|
|
|
if (SEQUENTIAL_IS_DEFAULT) {
|
|
|
|
p->PredFlags |= SequentialPredFlag;
|
|
|
|
}
|
|
|
|
#endif /* YAPOR */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
add_first_static(PredEntry *p, yamop *cp, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *pt = cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
if (is_logupd(p)) {
|
|
|
|
if (p == PredGoalExpansion) {
|
|
|
|
PRED_GOAL_EXPANSION_ON = TRUE;
|
|
|
|
Yap_InitComma();
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2003-08-27 14:37:10 +01:00
|
|
|
if (SEQUENTIAL_IS_DEFAULT) {
|
|
|
|
p->PredFlags |= SequentialPredFlag;
|
|
|
|
PUT_YAMOP_SEQ(pt);
|
|
|
|
}
|
|
|
|
if (YAMOP_LTT(pt) != 1)
|
|
|
|
abort_optyap("YAMOP_LTT error in function add_first_static");
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef TABLING
|
2003-08-27 14:37:10 +01:00
|
|
|
if (is_tabled(p)) {
|
2003-12-18 16:38:40 +00:00
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* TABLING */
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
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;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
if (PROFILING) {
|
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
|
|
|
} else
|
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
|
|
|
#ifdef YAPOR
|
|
|
|
p->PredFlags |= SequentialPredFlag;
|
|
|
|
PUT_YAMOP_SEQ((yamop *)cp);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
if (spy_flag) {
|
2002-11-18 18:18:05 +00:00
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if ((yap_flags[SOURCE_MODE_FLAG] ||
|
|
|
|
(p->PredFlags & MultiFileFlag)) &&
|
|
|
|
!(p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags |= SourcePredFlag;
|
|
|
|
} else {
|
|
|
|
p->PredFlags &= ~SourcePredFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
add_first_dynamic(PredEntry *p, yamop *cp, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
yamop *ncp = ((DynamicClause *)NULL)->ClCode;
|
|
|
|
DynamicClause *cl;
|
2003-01-29 14:47:17 +00:00
|
|
|
if (p == PredGoalExpansion) {
|
|
|
|
PRED_GOAL_EXPANSION_ON = TRUE;
|
|
|
|
Yap_InitComma();
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
if (PROFILING) {
|
|
|
|
p->PredFlags |= ProfiledPredFlag;
|
|
|
|
} else
|
|
|
|
p->PredFlags &= ~ProfiledPredFlag;
|
|
|
|
#ifdef YAPOR
|
|
|
|
p->PredFlags |= SequentialPredFlag;
|
|
|
|
#endif /* YAPOR */
|
|
|
|
/* 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 =
|
2003-04-30 18:46:05 +01:00
|
|
|
(DynamicClause *) Yap_AllocCodeSpace((Int)NEXTOP(NEXTOP(NEXTOP(ncp,ld),e),e));
|
2001-04-09 20:54:03 +01:00
|
|
|
if (cl == NIL) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"Heap crashed against Stacks");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* skip the first entry, this contains the back link and will always be
|
|
|
|
empty for this entry */
|
|
|
|
ncp = (yamop *)(((CELL *)ncp)+1);
|
|
|
|
/* 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);
|
2001-04-09 20:54:03 +01:00
|
|
|
ncp->u.ld.s = p->ArityOfPE;
|
2002-05-16 21:33:00 +01:00
|
|
|
ncp->u.ld.p = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
ncp->u.ld.d = cp;
|
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(ncp, 1);
|
|
|
|
PUT_YAMOP_SEQ(ncp);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
/* 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;
|
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);
|
|
|
|
cp->u.ld.s = p->ArityOfPE;
|
|
|
|
cp->u.ld.p = p;
|
|
|
|
cp->u.ld.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
|
|
|
|
*/
|
|
|
|
ncp = NEXTOP(ncp,ld);
|
|
|
|
/* 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 */
|
|
|
|
ncp = NEXTOP(ncp,e);
|
2002-11-18 18:18:05 +00:00
|
|
|
ncp->opc = Yap_opcode(_Ystop);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2003-11-26 18:36:35 +00:00
|
|
|
asserta_stat_clause(PredEntry *p, yamop *q, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
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)) {
|
|
|
|
LogUpdClause
|
|
|
|
*clp = ClauseCodeToLogUpdClause(p->cs.p_code.FirstClause),
|
2003-11-26 18:36:35 +00:00
|
|
|
*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;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (p->PredFlags & SpiedPredFlag) {
|
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
cl->ClNext = ClauseCodeToStaticClause(p->cs.p_code.FirstClause);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2002-12-27 16:53:09 +00:00
|
|
|
PUT_YAMOP_LTT(q, YAMOP_LTT((yamop *)(p->cs.p_code.FirstClause)) + 1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.FirstClause = q;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = q;
|
2003-10-02 19:20:11 +01:00
|
|
|
if (p->PredFlags & SpiedPredFlag) {
|
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
p->cs.p_code.LastClause->u.ld.d = q;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
asserta_dynam_clause(PredEntry *p, yamop *cp)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
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);
|
2002-12-27 16:53:09 +00:00
|
|
|
q->u.ld.d = p->cs.p_code.FirstClause;
|
2001-04-09 20:54:03 +01:00
|
|
|
q->u.ld.s = p->ArityOfPE;
|
2002-05-16 21:33:00 +01:00
|
|
|
q->u.ld.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);
|
|
|
|
cp->u.ld.s = p->ArityOfPE;
|
|
|
|
cp->u.ld.p = p;
|
|
|
|
p->cs.p_code.FirstClause = cp;
|
|
|
|
q = p->CodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
q->u.ld.d = cp;
|
|
|
|
q->u.ld.s = p->ArityOfPE;
|
2002-05-16 21:33:00 +01:00
|
|
|
q->u.ld.p = p;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
assertz_stat_clause(PredEntry *p, yamop *cp, int spy_flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
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)) {
|
|
|
|
LogUpdClause
|
|
|
|
*clp = ClauseCodeToLogUpdClause(cp),
|
|
|
|
*clq = ClauseCodeToLogUpdClause(pt);
|
|
|
|
|
|
|
|
clq->ClNext = clp;
|
|
|
|
clp->ClPrev = clq;
|
|
|
|
clp->ClNext = NULL;
|
|
|
|
p->cs.p_code.LastClause = cp;
|
|
|
|
if (p->PredFlags & SpiedPredFlag) {
|
|
|
|
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
} else if (!(p->PredFlags & IndexedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (p->cs.p_code.FirstClause == p->cs.p_code.LastClause) {
|
|
|
|
if (!(p->PredFlags & SpiedPredFlag)) {
|
|
|
|
p->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
{
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pt);
|
|
|
|
cl->ClNext = ClauseCodeToStaticClause(cp);
|
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
|
|
|
#ifdef YAPOR
|
|
|
|
{
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(p->cs.p_code.FirstClause);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
while (TRUE) {
|
|
|
|
PUT_YAMOP_LTT((yamop *)code, YAMOP_LTT(cl->ClCode) + 1);
|
|
|
|
if (cl->ClCode == p->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
cl = cl->NextCl;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* YAPOR */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* p is already locked */
|
|
|
|
static void
|
2002-12-27 16:53:09 +00:00
|
|
|
assertz_dynam_clause(PredEntry *p, yamop *cp)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
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);
|
2001-04-09 20:54:03 +01:00
|
|
|
q->u.ld.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);
|
2001-04-09 20:54:03 +01:00
|
|
|
q->u.ld.d = p->CodeOfPred;
|
|
|
|
q->u.ld.s = p->ArityOfPE;
|
2002-05-16 21:33:00 +01:00
|
|
|
q->u.ld.p = p;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses++;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void expand_consult(void)
|
|
|
|
{
|
2002-01-01 05:26:25 +00:00
|
|
|
consult_obj *new_cl, *new_cb, *new_cs;
|
|
|
|
UInt OldConsultCapacity = ConsultCapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-01-01 05:26:25 +00:00
|
|
|
/* now double consult capacity */
|
2001-04-09 20:54:03 +01:00
|
|
|
ConsultCapacity += InitialConsultCapacity;
|
|
|
|
/* I assume it always works ;-) */
|
2002-11-18 18:18:05 +00:00
|
|
|
while ((new_cl = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*ConsultCapacity)) == NULL) {
|
2004-01-23 02:23:51 +00:00
|
|
|
if (!Yap_growheap(FALSE, sizeof(consult_obj)*ConsultCapacity, NULL)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,Yap_ErrorMessage);
|
2002-02-27 02:10:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-12-15 04:47:41 +00:00
|
|
|
new_cs = new_cl + (InitialConsultCapacity+1);
|
2002-01-01 05:26:25 +00:00
|
|
|
new_cb = new_cs + (ConsultBase-ConsultSp);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* start copying */
|
2002-01-01 05:26:25 +00:00
|
|
|
memcpy((void *)(new_cs), (void *)(ConsultSp), OldConsultCapacity*sizeof(consult_obj));
|
2001-04-09 20:54:03 +01:00
|
|
|
/* copying done, release old space */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace((char *)ConsultLow);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* next, set up pointers correctly */
|
|
|
|
ConsultSp = new_cs;
|
|
|
|
ConsultBase = new_cb;
|
|
|
|
ConsultLow = new_cl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* p was already locked */
|
|
|
|
static int
|
2001-12-12 19:36:51 +00:00
|
|
|
not_was_reconsulted(PredEntry *p, Term t, int mode)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
register consult_obj *fp;
|
|
|
|
Prop p0 = AbsProp((PropEntry *)p);
|
|
|
|
|
|
|
|
for (fp = ConsultSp; fp < ConsultBase; ++fp)
|
|
|
|
if (fp->p == p0)
|
|
|
|
break;
|
|
|
|
if (fp != ConsultBase)
|
|
|
|
return (FALSE);
|
|
|
|
if (mode) {
|
|
|
|
if (ConsultSp == ConsultLow+1)
|
|
|
|
expand_consult();
|
|
|
|
--ConsultSp;
|
|
|
|
ConsultSp->p = p0;
|
2003-11-26 18:36:35 +00:00
|
|
|
if (ConsultBase[1].mode &&
|
|
|
|
!(p->PredFlags & MultiFileFlag)) /* we are in reconsult mode */ {
|
2002-06-18 06:22:35 +01:00
|
|
|
retract_all(p, static_in_use(p,TRUE));
|
2001-12-12 19:36:51 +00:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
p->src.OwnerFile = YapConsultingFile();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return (TRUE); /* careful */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-01-02 16:55:24 +00:00
|
|
|
addcl_permission_error(AtomEntry *ap, Int Arity, int in_use)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t, ti[2];
|
|
|
|
|
|
|
|
ti[0] = MkAtomTerm(AbsAtom(ap));
|
|
|
|
ti[1] = MkIntegerTerm(Arity);
|
2002-11-18 18:18:05 +00:00
|
|
|
t = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("/"),2), 2, ti);
|
|
|
|
Yap_ErrorMessage = Yap_ErrorSay;
|
|
|
|
Yap_Error_Term = t;
|
|
|
|
Yap_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE;
|
2002-01-02 16:55:24 +00:00
|
|
|
if (in_use) {
|
|
|
|
if (Arity == 0)
|
2002-11-18 18:18:05 +00:00
|
|
|
sprintf(Yap_ErrorMessage, "static predicate %s is in use", ap->StrOfAE);
|
2002-01-02 16:55:24 +00:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
sprintf(Yap_ErrorMessage,
|
2002-01-02 16:55:24 +00:00
|
|
|
#if SHORT_INTS
|
|
|
|
"static predicate %s/%ld is in use",
|
|
|
|
#else
|
|
|
|
"static predicate %s/%d is in use",
|
|
|
|
#endif
|
|
|
|
ap->StrOfAE, Arity);
|
|
|
|
} else {
|
|
|
|
if (Arity == 0)
|
2002-11-18 18:18:05 +00:00
|
|
|
sprintf(Yap_ErrorMessage, "system predicate %s", ap->StrOfAE);
|
2002-01-02 16:55:24 +00:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
sprintf(Yap_ErrorMessage,
|
2001-04-09 20:54:03 +01:00
|
|
|
#if SHORT_INTS
|
2002-01-02 16:55:24 +00:00
|
|
|
"system predicate %s/%ld",
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2002-01-02 16:55:24 +00:00
|
|
|
"system predicate %s/%d",
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2002-01-02 16:55:24 +00:00
|
|
|
ap->StrOfAE, Arity);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static Term
|
2003-11-21 16:56:20 +00:00
|
|
|
addclause(Term t, yamop *cp, int mode, int mod)
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
2003-08-27 14:37:10 +01:00
|
|
|
*
|
|
|
|
mode
|
|
|
|
0 assertz
|
|
|
|
1 consult
|
|
|
|
2 asserta
|
|
|
|
*/
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
PredEntry *p;
|
|
|
|
int spy_flag = FALSE;
|
2001-11-15 00:01:43 +00:00
|
|
|
Atom at;
|
|
|
|
UInt Arity;
|
2003-08-27 14:37:10 +01:00
|
|
|
CELL pflags;
|
2003-11-18 19:24:46 +00:00
|
|
|
Term tf;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorAssert)
|
2003-11-18 19:24:46 +00:00
|
|
|
tf = ArgOfTerm(1, t);
|
|
|
|
else
|
|
|
|
tf = t;
|
|
|
|
if (IsAtomTerm(tf)) {
|
|
|
|
at = AtomOfTerm(tf);
|
2001-11-15 00:01:43 +00:00
|
|
|
p = RepPredProp(PredPropByAtom(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
Arity = 0;
|
|
|
|
} else {
|
2003-11-18 19:24:46 +00:00
|
|
|
Functor f = FunctorOfTerm(tf);
|
2001-04-09 20:54:03 +01:00
|
|
|
Arity = ArityOfFunctor(f);
|
2001-11-15 00:01:43 +00:00
|
|
|
at = NameOfFunctor(f);
|
|
|
|
p = RepPredProp(PredPropByFunc(f, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomAbol, TermNil);
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(p->PRWLock);
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-11 13:33:19 +00:00
|
|
|
WPP = p;
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
pflags = p->PredFlags;
|
2001-10-30 16:42:05 +00:00
|
|
|
/* we are redefining a prolog module predicate */
|
2004-02-12 12:37:12 +00:00
|
|
|
if (p->ModuleOfPred == PROLOG_MODULE &&
|
|
|
|
mod != TermProlog && mod) {
|
2004-02-20 18:56:07 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
WPP = NULL;
|
|
|
|
#endif
|
2001-11-15 00:01:43 +00:00
|
|
|
WRITE_UNLOCK(p->PRWLock);
|
2002-01-02 16:55:24 +00:00
|
|
|
addcl_permission_error(RepAtom(at), Arity, FALSE);
|
2003-08-27 14:37:10 +01:00
|
|
|
return TermNil;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* The only problem we have now is when we need to throw away
|
|
|
|
Indexing blocks
|
|
|
|
*/
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & IndexedPredFlag) {
|
|
|
|
Yap_AddClauseToIndex(p, cp, mode == asserta);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & SpiedPredFlag)
|
2001-04-09 20:54:03 +01:00
|
|
|
spy_flag = TRUE;
|
|
|
|
if (mode == consult)
|
2001-12-12 19:36:51 +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 */
|
2003-08-27 14:37:10 +01:00
|
|
|
if (Yap_ErrorMessage && Yap_Error_TYPE == PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE) {
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-11 13:33:19 +00:00
|
|
|
WPP = NULL;
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2003-08-27 14:37:10 +01:00
|
|
|
WRITE_UNLOCK(p->PRWLock);
|
|
|
|
return TermNil;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!is_dynamic(p)) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & LogUpdatePredFlag) {
|
2003-04-30 18:46:05 +01:00
|
|
|
LogUpdClause *clp = ClauseCodeToLogUpdClause(cp);
|
2003-08-27 14:37:10 +01:00
|
|
|
clp->ClFlags |= LogUpdMask;
|
2003-11-18 19:24:46 +00:00
|
|
|
if (IsAtomTerm(t) ||
|
|
|
|
FunctorOfTerm(t) != FunctorAssert) {
|
|
|
|
clp->ClFlags |= FactMask;
|
|
|
|
clp->ClSource = NULL;
|
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
|
|
|
StaticClause *clp = ClauseCodeToStaticClause(cp);
|
|
|
|
clp->ClFlags |= StaticMask;
|
2003-11-18 19:24:46 +00:00
|
|
|
if (IsAtomTerm(t) ||
|
2003-11-21 16:56:20 +00:00
|
|
|
FunctorOfTerm(t) != FunctorAssert) {
|
2003-11-18 19:24:46 +00:00
|
|
|
clp->ClFlags |= FactMask;
|
2003-11-24 00:00:43 +00:00
|
|
|
clp->usc.ClPred = p;
|
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 ||
|
|
|
|
p->OpcodeOfPred == FAIL_OPCODE) { /* log updates */
|
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;
|
|
|
|
}
|
|
|
|
} 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 &&
|
2002-11-18 18:18:05 +00: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)
|
2004-02-11 13:33:19 +00:00
|
|
|
WPP = NULL;
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(p->PRWLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pflags & LogUpdatePredFlag) {
|
|
|
|
return MkDBRefTerm((DBRef)ClauseCodeToLogUpdClause(cp));
|
|
|
|
} else {
|
|
|
|
return MkIntegerTerm((Int)cp);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_addclause(Term t, yamop *cp, int mode, Term mod) {
|
2003-11-21 16:56:20 +00:00
|
|
|
addclause(t, cp, mode, mod);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
void
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_EraseStaticClause(StaticClause *cl, Term mod) {
|
2003-11-26 18:36:35 +00:00
|
|
|
PredEntry *ap;
|
|
|
|
|
|
|
|
/* ok, first I need to find out the parent predicate */
|
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
ap = cl->usc.ClPred;
|
|
|
|
} else {
|
|
|
|
Term t = ArgOfTerm(1,cl->usc.ClSource->Entry);
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
ap = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
|
|
|
} else {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
ap = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WRITE_LOCK(ap->PRWLock);
|
2004-02-20 18:56:07 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
WPP = NULL;
|
|
|
|
#endif
|
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;
|
|
|
|
ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
(yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
} else {
|
|
|
|
yamop *ncl = cl->ClNext->ClCode;
|
|
|
|
ap->cs.p_code.FirstClause = ncl;
|
|
|
|
ncl->opc = Yap_opcode(_try_me);
|
|
|
|
ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
ncl;
|
|
|
|
ap->OpcodeOfPred = ncl->opc;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StaticClause *pcl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause),
|
|
|
|
*ocl = NULL;
|
|
|
|
|
|
|
|
while (pcl != cl) {
|
|
|
|
ocl = pcl;
|
|
|
|
pcl = pcl->ClNext;
|
|
|
|
}
|
|
|
|
ocl->ClCode->u.ld.d = cl->ClCode->u.ld.d;
|
|
|
|
ocl->ClNext = cl->ClNext;
|
|
|
|
if (cl->ClCode == ap->cs.p_code.LastClause) {
|
|
|
|
ap->cs.p_code.LastClause = ocl->ClCode;
|
|
|
|
if (ap->cs.p_code.NOfClauses > 1)
|
|
|
|
ocl->ClCode->opc = Yap_opcode(_trust_me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ap->cs.p_code.NOfClauses == 1) {
|
|
|
|
ap->cs.p_code.TrueCodeOfPred =
|
|
|
|
ap->cs.p_code.FirstClause;
|
|
|
|
ap->OpcodeOfPred =
|
|
|
|
ap->cs.p_code.TrueCodeOfPred->opc;
|
|
|
|
}
|
2004-02-20 18:56:07 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
WPP = NULL;
|
|
|
|
#endif
|
2003-11-26 18:36:35 +00:00
|
|
|
WRITE_UNLOCK(ap->PRWLock);
|
|
|
|
if (cl->ClFlags & HasBlobsMask || static_in_use(ap,TRUE)) {
|
|
|
|
DeadClause *dcl = (DeadClause *)cl;
|
|
|
|
dcl->NextCl = DeadClauses;
|
|
|
|
dcl->ClFlags = 0;
|
|
|
|
DeadClauses = dcl;
|
|
|
|
} else {
|
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
|
|
|
}
|
|
|
|
if (ap->cs.p_code.NOfClauses == 0) {
|
|
|
|
ap->CodeOfPred =
|
|
|
|
ap->cs.p_code.TrueCodeOfPred;
|
|
|
|
} else if (ap->cs.p_code.NOfClauses > 1) {
|
|
|
|
ap->OpcodeOfPred = INDEX_OPCODE;
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
} else if (ap->PredFlags & SpiedPredFlag) {
|
|
|
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
|
|
|
} else {
|
|
|
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
void
|
|
|
|
Yap_add_logupd_clause(PredEntry *pe, LogUpdClause *cl, int mode) {
|
|
|
|
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 ||
|
|
|
|
pe->OpcodeOfPred == FAIL_OPCODE) { /* log updates */
|
|
|
|
pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred;
|
|
|
|
pe->OpcodeOfPred = ((yamop *)(pe->CodeOfPred))->opc;
|
|
|
|
}
|
|
|
|
} else if (mode == asserta) {
|
|
|
|
asserta_stat_clause(pe, cp, FALSE);
|
|
|
|
} else {
|
|
|
|
assertz_stat_clause(pe, cp, FALSE);
|
|
|
|
if (pe->OpcodeOfPred != INDEX_OPCODE &&
|
|
|
|
pe->OpcodeOfPred != Yap_opcode(_spy_pred)) {
|
|
|
|
pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred;
|
|
|
|
pe->OpcodeOfPred = ((yamop *)(pe->CodeOfPred))->opc;
|
|
|
|
}
|
|
|
|
}
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_in_this_f_before(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$in_this_file_before'(N,A,M) */
|
2001-04-09 20:54:03 +01:00
|
|
|
unsigned int arity;
|
|
|
|
Atom at;
|
|
|
|
Term t;
|
|
|
|
register consult_obj *fp;
|
|
|
|
Prop p0;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-04-03 20:33:38 +01:00
|
|
|
if (IsVarTerm(t = Deref(ARG1)) || !IsAtomTerm(t))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
at = AtomOfTerm(t);
|
2002-04-03 20:33:38 +01:00
|
|
|
if (IsVarTerm(t = Deref(ARG2)) || !IsIntTerm(t))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
arity = IntOfTerm(t);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod = Deref(ARG3)) || !IsAtomTerm(mod))
|
|
|
|
return FALSE;
|
2001-11-15 00:01:43 +00:00
|
|
|
if (arity)
|
2002-11-18 18:18:05 +00:00
|
|
|
p0 = PredPropByFunc(Yap_MkFunctor(at, arity),CurrentModule);
|
2001-11-15 00:01:43 +00:00
|
|
|
else
|
|
|
|
p0 = PredPropByAtom(at, CurrentModule);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (ConsultSp == ConsultBase || (fp = ConsultSp)->p == p0)
|
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
fp++;
|
|
|
|
for (; fp < ConsultBase; ++fp)
|
|
|
|
if (fp->p == p0)
|
|
|
|
break;
|
|
|
|
if (fp != ConsultBase)
|
|
|
|
return (TRUE);
|
|
|
|
else
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_first_cl_in_f(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$first_cl_in_file'(+N,+Ar,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
unsigned int arity;
|
|
|
|
Atom at;
|
|
|
|
Term t;
|
|
|
|
register consult_obj *fp;
|
|
|
|
Prop p0;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-04-03 20:33:38 +01:00
|
|
|
if (IsVarTerm(t = Deref(ARG1)) || !IsAtomTerm(t))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
at = AtomOfTerm(t);
|
2002-04-03 20:33:38 +01:00
|
|
|
if (IsVarTerm(t = Deref(ARG2)) || !IsIntTerm(t))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
arity = IntOfTerm(t);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod = Deref(ARG3)) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
|
|
|
if (arity)
|
2002-11-18 18:18:05 +00:00
|
|
|
p0 = PredPropByFunc(Yap_MkFunctor(at, arity),mod);
|
2001-11-15 00:01:43 +00:00
|
|
|
else
|
|
|
|
p0 = PredPropByAtom(at, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
for (fp = ConsultSp; fp < ConsultBase; ++fp)
|
|
|
|
if (fp->p == p0)
|
|
|
|
break;
|
|
|
|
if (fp != ConsultBase)
|
|
|
|
return (FALSE);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_mk_cl_not_first(void)
|
|
|
|
{ /* '$mk_cl_not_first'(+N,+Ar) */
|
|
|
|
unsigned int arity;
|
|
|
|
Atom at;
|
|
|
|
Term t;
|
|
|
|
Prop p0;
|
|
|
|
|
|
|
|
if (IsVarTerm(t = Deref(ARG1)) && !IsAtomTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
at = AtomOfTerm(t);
|
|
|
|
if (IsVarTerm(t = Deref(ARG2)) && !IsIntTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
arity = IntOfTerm(t);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (arity)
|
2002-11-18 18:18:05 +00:00
|
|
|
p0 = PredPropByFunc(Yap_MkFunctor(at, arity),CurrentModule);
|
2001-11-15 00:01:43 +00:00
|
|
|
else
|
|
|
|
p0 = PredPropByAtom(at, CurrentModule);
|
2001-04-09 20:54:03 +01:00
|
|
|
--ConsultSp;
|
|
|
|
ConsultSp->p = p0;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if EMACS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the place where one would add a new clause for the propriety pred_prop
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
where_new_clause(pred_prop, mode)
|
|
|
|
Prop pred_prop;
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
PredEntry *p = RepPredProp(pred_prop);
|
|
|
|
|
2001-12-12 19:36:51 +00:00
|
|
|
if (mode == consult && not_was_reconsulted(p, TermNil, FALSE))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (1);
|
|
|
|
else
|
2003-08-27 14:37:10 +01:00
|
|
|
return (p->cs.p_code.NOfClauses + 1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_compile(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$compile'(+C,+Flags, Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term t1 = Deref(ARG2);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG4);
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *codeadr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsIntTerm(t1))
|
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2003-12-01 17:27:42 +00:00
|
|
|
|
|
|
|
YAPEnterCriticalSection();
|
2003-11-21 16:56:20 +00:00
|
|
|
codeadr = Yap_cclause(t, 2, mod, Deref(ARG3)); /* vsc: give the number of arguments
|
2001-04-09 20:54:03 +01:00
|
|
|
to cclause in case there is overflow */
|
|
|
|
t = Deref(ARG1); /* just in case there was an heap overflow */
|
2002-11-18 18:18:05 +00:00
|
|
|
if (!Yap_ErrorMessage)
|
2003-11-21 16:56:20 +00:00
|
|
|
addclause(t, codeadr, (int) (IntOfTerm(t1) & 3), mod);
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_ErrorMessage) {
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IntOfTerm(t1) & 4) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(Yap_Error_TYPE, Yap_Error_Term,
|
|
|
|
"in line %d, %s", Yap_FirstLineInParse(), Yap_ErrorMessage);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_compile_dynamic(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$compile_dynamic'(+C,+Flags,Mod,-Ref) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term t1 = Deref(ARG2);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG4);
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *code_adr;
|
2001-04-09 20:54:03 +01:00
|
|
|
int old_optimize;
|
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsIntTerm(t1))
|
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return (FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
old_optimize = optimizer_on;
|
|
|
|
optimizer_on = FALSE;
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPEnterCriticalSection();
|
2003-11-21 16:56:20 +00:00
|
|
|
code_adr = Yap_cclause(t, 3, mod, Deref(ARG3)); /* vsc: give the number of arguments to
|
2001-04-09 20:54:03 +01:00
|
|
|
cclause() in case there is a overflow */
|
|
|
|
t = Deref(ARG1); /* just in case there was an heap overflow */
|
2002-11-18 18:18:05 +00:00
|
|
|
if (!Yap_ErrorMessage) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
optimizer_on = old_optimize;
|
2003-11-21 16:56:20 +00:00
|
|
|
t = addclause(t, code_adr, (int) (IntOfTerm(t1) & 3), mod);
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IntOfTerm(t1) & 4) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, "line %d, %s", Yap_FirstLineInParse(), Yap_ErrorMessage);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2003-12-01 17:27:42 +00:00
|
|
|
YAPLeaveCriticalSection();
|
2003-08-27 14:37:10 +01:00
|
|
|
return Yap_unify(ARG5, t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int consult_level = 0;
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Atom
|
2001-04-09 20:54:03 +01:00
|
|
|
YapConsultingFile (void)
|
|
|
|
{
|
|
|
|
if (consult_level == 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_LookupAtom("user"));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_LookupAtom(ConsultBase[2].filename));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Atom
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ConsultingFile (void)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
return YapConsultingFile();
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* consult file *file*, *mode* may be one of either consult or reconsult */
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
init_consult(int mode, char *file)
|
|
|
|
{
|
|
|
|
ConsultSp--;
|
|
|
|
ConsultSp->filename = file;
|
|
|
|
ConsultSp--;
|
|
|
|
ConsultSp->mode = mode;
|
|
|
|
ConsultSp--;
|
2002-01-01 05:26:25 +00:00
|
|
|
ConsultSp->c = (ConsultBase-ConsultSp);
|
2001-04-09 20:54:03 +01:00
|
|
|
ConsultBase = ConsultSp;
|
|
|
|
#if !defined(YAPOR) && !defined(SBA)
|
2002-02-26 15:51:54 +00:00
|
|
|
/* if (consult_level == 0)
|
|
|
|
do_toggle_static_predicates_in_use(TRUE); */
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
consult_level++;
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_init_consult(int mode, char *file)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
init_consult(mode,file);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_startconsult(void)
|
|
|
|
{ /* '$start_consult'(+Mode) */
|
|
|
|
Term t;
|
|
|
|
char *smode = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
mode = strcmp("consult",smode);
|
|
|
|
init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE);
|
|
|
|
t = MkIntTerm(consult_level);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG3, t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_showconslultlev(void)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = MkIntTerm(consult_level);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG1, t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
end_consult(void)
|
|
|
|
{
|
|
|
|
ConsultSp = ConsultBase;
|
2002-01-01 05:26:25 +00:00
|
|
|
ConsultBase = ConsultSp+ConsultSp->c;
|
2001-04-09 20:54:03 +01:00
|
|
|
ConsultSp += 3;
|
|
|
|
consult_level--;
|
|
|
|
#if !defined(YAPOR) && !defined(SBA)
|
2002-02-26 15:51:54 +00:00
|
|
|
/* if (consult_level == 0)
|
|
|
|
do_toggle_static_predicates_in_use(FALSE);*/
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_end_consult(void) {
|
2002-11-11 17:38:10 +00:00
|
|
|
end_consult();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_endconsult(void)
|
|
|
|
{ /* '$end_consult' */
|
|
|
|
end_consult();
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2004-02-11 01:20:56 +00:00
|
|
|
static void
|
|
|
|
purge_clauses(PredEntry *pred)
|
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *q;
|
2002-06-18 06:22:35 +01:00
|
|
|
int in_use;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (pred->PredFlags & IndexedPredFlag)
|
|
|
|
RemoveIndexation(pred);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
2002-12-27 16:53:09 +00:00
|
|
|
q = pred->cs.p_code.FirstClause;
|
2003-02-11 16:33:24 +00:00
|
|
|
in_use = static_in_use(pred,TRUE);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (q != NULL) {
|
|
|
|
if (pred->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(q);
|
|
|
|
do {
|
|
|
|
LogUpdClause *ncl = cl->ClNext;
|
|
|
|
Yap_ErLogUpdCl(cl);
|
|
|
|
cl = ncl;
|
|
|
|
} while (cl != NULL);
|
|
|
|
} else {
|
2003-11-26 18:36:35 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(q);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
do {
|
2002-06-18 06:22:35 +01:00
|
|
|
if (cl->ClFlags & HasBlobsMask || in_use) {
|
2003-04-30 18:46:05 +01:00
|
|
|
DeadClause *dcl = (DeadClause *)cl;
|
|
|
|
dcl->NextCl = DeadClauses;
|
|
|
|
dcl->ClFlags = 0;
|
|
|
|
DeadClauses = dcl;
|
2002-06-11 06:30:47 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace((char *)cl);
|
2002-06-11 06:30:47 +01:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClCode == pred->cs.p_code.LastClause) break;
|
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (TRUE);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
pred->cs.p_code.FirstClause = pred->cs.p_code.LastClause = NULL;
|
2002-10-14 17:25:38 +01:00
|
|
|
if (pred->PredFlags & (DynamicPredFlag|LogUpdatePredFlag)) {
|
|
|
|
pred->OpcodeOfPred = FAIL_OPCODE;
|
|
|
|
} else {
|
|
|
|
pred->OpcodeOfPred = UNDEF_OPCODE;
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
pred->cs.p_code.TrueCodeOfPred =
|
2001-04-09 20:54:03 +01:00
|
|
|
pred->CodeOfPred =
|
2002-12-27 16:53:09 +00:00
|
|
|
(yamop *)(&(pred->OpcodeOfPred));
|
2003-08-27 14:37:10 +01:00
|
|
|
pred->src.OwnerFile = AtomNil;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pred->PredFlags & MultiFileFlag)
|
|
|
|
pred->PredFlags ^= MultiFileFlag;
|
2004-02-11 01:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_Abolish(PredEntry *pred)
|
|
|
|
{
|
|
|
|
purge_clauses(pred);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_purge_clauses(void)
|
|
|
|
{ /* '$purge_clauses'(+Func) */
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
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)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
pred = RepPredProp(PredPropByFunc(fun, mod));
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
WRITE_LOCK(pred->PRWLock);
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-11 13:33:19 +00:00
|
|
|
WPP = pred;
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2004-02-11 01:20:56 +00:00
|
|
|
if (pred->PredFlags & StandardPredFlag) {
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-11 13:33:19 +00:00
|
|
|
WPP = NULL;
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2004-02-11 01:20:56 +00:00
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, t, "assert/1");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
purge_clauses(pred);
|
2004-02-11 16:18:16 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-11 13:33:19 +00:00
|
|
|
WPP = NULL;
|
2004-02-11 16:18:16 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
MANAGING SPY-POINTS
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_setspy(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$set_spy'(+Fun,+M) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
CELL fg;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term t, mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
at = Yap_FullLookupAtom("$spy");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
WRITE_LOCK(pred->PRWLock);
|
2003-12-01 17:27:42 +00:00
|
|
|
restart_spy:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pred->PredFlags & (CPredFlag | SafePredFlag)) {
|
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-10-14 17:25:38 +01:00
|
|
|
if (pred->OpcodeOfPred == UNDEF_OPCODE ||
|
|
|
|
pred->OpcodeOfPred == FAIL_OPCODE) {
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
if (pred->OpcodeOfPred == INDEX_OPCODE) {
|
2002-12-27 16:53:09 +00:00
|
|
|
IPred(pred);
|
2001-04-09 20:54:03 +01:00
|
|
|
goto restart_spy;
|
|
|
|
}
|
|
|
|
fg = pred->PredFlags;
|
|
|
|
if (fg & DynamicPredFlag) {
|
|
|
|
pred->OpcodeOfPred =
|
|
|
|
((yamop *)(pred->CodeOfPred))->opc =
|
2002-11-18 18:18:05 +00:00
|
|
|
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);
|
2002-12-27 16:53:09 +00:00
|
|
|
pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
pred->PredFlags |= SpiedPredFlag;
|
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_rmspy(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$rm_spy'(+T,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
Term t;
|
2004-02-12 12:37:12 +00:00
|
|
|
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
|
|
|
|
return (FALSE);
|
|
|
|
WRITE_LOCK(pred->PRWLock);
|
|
|
|
if (!(pred->PredFlags & SpiedPredFlag)) {
|
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2004-02-11 16:18:16 +00:00
|
|
|
#if THREADS
|
2004-02-11 13:33:19 +00:00
|
|
|
if (!(pred->PredFlags & ThreadLocalPredFlag)) {
|
|
|
|
pred->OpcodeOfPred = Yap_opcode(_thread_local);
|
2004-02-11 16:18:16 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (!(pred->PredFlags & DynamicPredFlag)) {
|
2003-04-30 18:46:05 +01:00
|
|
|
pred->CodeOfPred = pred->cs.p_code.TrueCodeOfPred;
|
2001-04-09 20:54:03 +01:00
|
|
|
pred->OpcodeOfPred = ((yamop *)(pred->CodeOfPred))->opc;
|
2002-11-18 18:18:05 +00:00
|
|
|
} else if (pred->OpcodeOfPred == Yap_opcode(_spy_or_trymark)) {
|
|
|
|
pred->OpcodeOfPred = Yap_opcode(_try_and_mark);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
pred->PredFlags ^= SpiedPredFlag;
|
|
|
|
WRITE_UNLOCK(pred->PRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
INFO ABOUT PREDICATES
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_number_of_clauses(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$number_of_clauses'(Predicate,M,N) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
int ncl = 0;
|
|
|
|
Prop pe;
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
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;
|
2003-05-01 22:07:11 +01:00
|
|
|
READ_LOCK(RepPredProp(pe)->PRWLock);
|
|
|
|
ncl = RepPredProp(pe)->cs.p_code.NOfClauses;
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_UNLOCK(RepPredProp(pe)->PRWLock);
|
2003-05-01 22:07:11 +01:00
|
|
|
return (Yap_unify_constant(ARG3, MkIntegerTerm(ncl)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_in_use(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$in_use'(+P,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Int out;
|
|
|
|
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
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-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
2004-02-05 16:57:02 +00:00
|
|
|
return FALSE;
|
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
out = static_in_use(pe,TRUE);
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_new_multifile(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$new_multifile'(+N,+Ar,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
Atom at;
|
|
|
|
int arity;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
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
|
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (arity == 0)
|
|
|
|
pe = RepPredProp(PredPropByAtom(at, mod));
|
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, arity),mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(pe->PRWLock);
|
|
|
|
pe->PredFlags |= MultiFileFlag;
|
2003-11-26 18:36:35 +00:00
|
|
|
if (!(pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
|
|
|
/* static */
|
2003-12-04 18:13:04 +00:00
|
|
|
pe->PredFlags |= (SourcePredFlag|CompiledPredFlag);
|
2003-11-26 18:36:35 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_is_multifile(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$is_multifile'(+S,+Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
Int out;
|
|
|
|
|
|
|
|
if (IsVarTerm(t))
|
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (!IsAtomTerm(mod))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (IsAtomTerm(t)) {
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsApplTerm(t)) {
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(FunctorOfTerm(t), mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else
|
|
|
|
return(FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
out = (pe->PredFlags & MultiFileFlag);
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static Int
|
|
|
|
p_is_log_updatable(void)
|
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Int out;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
2003-08-27 14:37:10 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
2003-08-27 14:37:10 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2003-08-27 14:37:10 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
out = (pe->PredFlags & LogUpdatePredFlag);
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
static Int
|
|
|
|
p_is_source(void)
|
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2003-11-21 16:56:20 +00:00
|
|
|
Int out;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
2003-11-21 16:56:20 +00:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2004-02-05 16:57:02 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
2003-11-21 16:56:20 +00:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2003-11-21 16:56:20 +00:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
out = (pe->PredFlags & SourcePredFlag);
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_is_dynamic(void)
|
|
|
|
{ /* '$is_dynamic'(+P) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
Int out;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom at = AtomOfTerm(t);
|
2003-11-12 12:33:31 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2003-11-12 12:33:31 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
out = (pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag));
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2002-10-14 17:25:38 +01:00
|
|
|
static Int
|
|
|
|
p_pred_exists(void)
|
|
|
|
{ /* '$pred_exists'(+P,+M) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-10-14 17:25:38 +01:00
|
|
|
Int out;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
2003-10-28 21:04:52 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
2002-10-14 17:25:38 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2003-10-28 21:04:52 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
2002-10-14 17:25:38 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2002-10-14 17:25:38 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
2004-02-22 00:35:07 +00:00
|
|
|
if (pe->PredFlags & HiddenPredFlag){
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-10-14 17:25:38 +01:00
|
|
|
out = (pe->OpcodeOfPred != UNDEF_OPCODE);
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2004-02-22 00:35:07 +00:00
|
|
|
return out;
|
2002-10-14 17:25:38 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_set_pred_module(void)
|
|
|
|
{ /* '$set_pred_module'(+P,+Mod) */
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = CurrentModule;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
|
|
|
restart_set_pred:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (fun == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1, t);
|
|
|
|
if (IsVarTerm(tmod) ) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"set_pred_module/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(tmod) ) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"set_pred_module/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = tmod;
|
2001-11-15 00:01:43 +00:00
|
|
|
t = ArgOfTerm(2, t);
|
|
|
|
goto restart_set_pred;
|
|
|
|
}
|
|
|
|
pe = RepPredProp(PredPropByFunc(fun, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(pe->PRWLock);
|
2004-02-12 12:37:12 +00:00
|
|
|
pe->ModuleOfPred = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_undefined(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$undefined'(P,Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Term t;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
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)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG2,"undefined/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-12 12:37:12 +00:00
|
|
|
if (!IsAtomTerm(mod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG2,"undefined/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
restart_undefined:
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"undefined/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom at = AtomOfTerm(t);
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at,mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor funt = FunctorOfTerm(t);
|
|
|
|
if (funt == FunctorModule) {
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tmod = ArgOfTerm(1, t);
|
|
|
|
if (IsVarTerm(tmod) ) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"undefined/1");
|
2001-10-30 16:42:05 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
if (!IsAtomTerm(tmod) ) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"undefined/1");
|
2001-10-30 16:42:05 +00:00
|
|
|
return(FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = tmod;
|
2001-10-30 16:42:05 +00:00
|
|
|
t = ArgOfTerm(2, t);
|
|
|
|
goto restart_undefined;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2004-02-05 16:57:02 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
2003-02-12 13:17:36 +00:00
|
|
|
if (pe->PredFlags & (CPredFlag|UserCPredFlag|TestPredFlag|AsmPredFlag|DynamicPredFlag|LogUpdatePredFlag)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2004-02-10 01:07:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
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
|
|
|
|
* predicate were remove, otherwise chaos will follow!!
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_kill_dynamic(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$kill_dynamic'(P,M) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Term t;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = Deref(ARG2);
|
|
|
|
if (IsVarTerm(mod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG2,"undefined/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-12 12:37:12 +00:00
|
|
|
if (!IsAtomTerm(mod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG2,"undefined/1");
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
t = Deref(ARG1);
|
2001-10-03 14:39:16 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
2003-11-26 18:36:35 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
2001-10-03 14:39:16 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Functor funt = FunctorOfTerm(t);
|
2003-11-26 18:36:35 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
2004-02-10 01:07:46 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(pe->PRWLock);
|
2003-11-26 18:36:35 +00:00
|
|
|
if (!(pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.LastClause != pe->cs.p_code.FirstClause) {
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.p_code.LastClause = pe->cs.p_code.FirstClause = NIL;
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->OpcodeOfPred = UNDEF_OPCODE;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags = 0L;
|
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_optimizer_on(void)
|
|
|
|
{ /* '$optimizer_on' */
|
|
|
|
optimizer_on = TRUE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_optimizer_off(void)
|
|
|
|
{ /* '$optimizer_off' */
|
|
|
|
optimizer_on = FALSE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_compile_mode(void)
|
|
|
|
{ /* $compile_mode(Old,New) */
|
|
|
|
Term t2, t3 = MkIntTerm(compile_mode);
|
2002-11-18 18:18:05 +00:00
|
|
|
if (!Yap_unify_constant(ARG1, t3))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
t2 = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t2) || !IsIntTerm(t2))
|
|
|
|
return (FALSE);
|
|
|
|
compile_mode = IntOfTerm(t2) & 1;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2002-10-21 23:14:29 +01:00
|
|
|
#if !defined(YAPOR)
|
2003-04-30 18:46:05 +01:00
|
|
|
static yamop *cur_clause(PredEntry *pe, yamop *codeptr)
|
2002-02-26 20:16:36 +00:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
StaticClause *cl;
|
2003-11-26 18:36:35 +00:00
|
|
|
|
|
|
|
cl = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause);
|
2002-02-26 20:16:36 +00:00
|
|
|
do {
|
2002-12-27 16:53:09 +00:00
|
|
|
if (IN_BLOCK(codeptr,cl,Yap_SizeOfBlock((CODEADDR)cl))) {
|
2003-11-26 18:36:35 +00:00
|
|
|
return cl->ClCode;
|
2002-02-26 20:16:36 +00:00
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClCode == pe->cs.p_code.LastClause)
|
2003-04-30 18:46:05 +01:00
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = cl->ClNext;
|
2002-02-26 20:16:36 +00:00
|
|
|
} while (TRUE);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"could not find clause for indexing code");
|
2002-02-26 20:16:36 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2003-04-30 18:46:05 +01:00
|
|
|
static yamop *cur_log_upd_clause(PredEntry *pe, yamop *codeptr)
|
2002-02-26 20:16:36 +00:00
|
|
|
{
|
2003-04-30 18:46:05 +01:00
|
|
|
LogUpdClause *cl;
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = ClauseCodeToLogUpdClause(pe->cs.p_code.FirstClause);
|
2002-02-26 20:16:36 +00:00
|
|
|
do {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (IN_BLOCK(codeptr,cl->ClCode,Yap_SizeOfBlock((CODEADDR)cl))) {
|
|
|
|
return((yamop *)cl->ClCode);
|
2002-02-26 20:16:36 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (cl != NULL);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"could not find clause for indexing code");
|
2002-02-26 20:16:36 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static LogUpdIndex *
|
|
|
|
find_owner_log_index(LogUpdIndex *cl, yamop *code_p)
|
|
|
|
{
|
|
|
|
yamop *code_beg = cl->ClCode;
|
|
|
|
yamop *code_end = (yamop *)((char *)cl + Yap_SizeOfBlock((CODEADDR)cl));
|
|
|
|
|
|
|
|
if (code_p >= code_beg && code_p <= code_end) {
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
cl = cl->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
LogUpdIndex *out;
|
|
|
|
if ((out = find_owner_log_index(cl, code_p)) != NULL) {
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static StaticIndex *
|
|
|
|
find_owner_static_index(StaticIndex *cl, yamop *code_p)
|
|
|
|
{
|
|
|
|
yamop *code_beg = cl->ClCode;
|
|
|
|
yamop *code_end = (yamop *)((char *)cl + Yap_SizeOfBlock((CODEADDR)cl));
|
|
|
|
|
|
|
|
if (code_p >= code_beg && code_p <= code_end) {
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
cl = cl->ChildIndex;
|
|
|
|
while (cl != NULL) {
|
|
|
|
StaticIndex *out;
|
|
|
|
if ((out = find_owner_static_index(cl, code_p)) != NULL) {
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
cl = cl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClauseUnion *
|
|
|
|
Yap_find_owner_index(yamop *ipc, PredEntry *ap)
|
|
|
|
{
|
|
|
|
/* we assume we have an owner index */
|
|
|
|
if (ap->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred);
|
|
|
|
return (ClauseUnion *)find_owner_log_index(cl,ipc);
|
|
|
|
} else {
|
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
|
|
|
|
return (ClauseUnion *)find_owner_static_index(cl,ipc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
search_for_static_predicate_in_use(PredEntry *p, int check_everything)
|
|
|
|
{
|
|
|
|
choiceptr b_ptr = B;
|
|
|
|
CELL *env_ptr = ENV;
|
|
|
|
|
2003-02-11 16:33:24 +00:00
|
|
|
if (check_everything) {
|
|
|
|
PredEntry *pe = EnvPreg(P);
|
|
|
|
if (p == pe) return(TRUE);
|
|
|
|
pe = EnvPreg(CP);
|
|
|
|
if (p == pe) return(TRUE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
do {
|
|
|
|
/* check first environments that are younger than our latest choicepoint */
|
|
|
|
if (check_everything) {
|
|
|
|
/*
|
|
|
|
I do not need to check environments for asserts,
|
|
|
|
only for retracts
|
|
|
|
*/
|
|
|
|
while (b_ptr > (choiceptr)env_ptr) {
|
|
|
|
PredEntry *pe = EnvPreg(env_ptr[E_CP]);
|
|
|
|
if (p == pe) return(TRUE);
|
|
|
|
if (env_ptr != NULL)
|
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now mark the choicepoint */
|
|
|
|
if (b_ptr != NULL) {
|
|
|
|
PredEntry *pe;
|
2002-11-18 18:18:05 +00:00
|
|
|
op_numbers opnum = Yap_op_from_opcode(b_ptr->cp_ap->opc);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
restart_cp:
|
|
|
|
switch(opnum) {
|
|
|
|
case _or_else:
|
|
|
|
case _or_last:
|
|
|
|
if (!check_everything) {
|
|
|
|
b_ptr = b_ptr->cp_b;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef YAPOR
|
2002-02-26 15:51:54 +00:00
|
|
|
pe = b_ptr->cp_cp->u.ldl.p;
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2002-02-26 15:51:54 +00:00
|
|
|
pe = b_ptr->cp_cp->u.sla.p0;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
break;
|
|
|
|
case _retry_profiled:
|
2002-11-18 18:18:05 +00:00
|
|
|
opnum = Yap_op_from_opcode(NEXTOP(b_ptr->cp_ap,l)->opc);
|
2001-04-09 20:54:03 +01:00
|
|
|
goto restart_cp;
|
2002-09-03 15:28:09 +01:00
|
|
|
case _count_retry:
|
2002-11-18 18:18:05 +00:00
|
|
|
opnum = Yap_op_from_opcode(NEXTOP(b_ptr->cp_ap,l)->opc);
|
2002-09-03 15:28:09 +01:00
|
|
|
goto restart_cp;
|
2001-04-09 20:54:03 +01:00
|
|
|
default:
|
|
|
|
pe = (PredEntry *)(b_ptr->cp_ap->u.ld.p);
|
|
|
|
}
|
|
|
|
if (pe == p) {
|
2002-02-26 20:16:36 +00:00
|
|
|
if (check_everything)
|
2003-08-27 14:37:10 +01:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
if (p->PredFlags & IndexedPredFlag) {
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *code_p = b_ptr->cp_ap;
|
2003-08-27 14:37:10 +01:00
|
|
|
yamop *code_beg = p->cs.p_code.TrueCodeOfPred;
|
2003-04-30 18:46:05 +01:00
|
|
|
|
|
|
|
if (p->PredFlags & LogUpdatePredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(code_beg);
|
|
|
|
if (find_owner_log_index(cl, code_p))
|
2003-04-30 18:46:05 +01:00
|
|
|
b_ptr->cp_ap = cur_log_upd_clause(pe, b_ptr->cp_ap->u.ld.d);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
|
|
|
/* static clause */
|
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(code_beg);
|
|
|
|
if (find_owner_static_index(cl, code_p)) {
|
2003-04-30 18:46:05 +01:00
|
|
|
b_ptr->cp_ap = cur_clause(pe, b_ptr->cp_ap->u.ld.d);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-02-22 00:35:07 +00:00
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
env_ptr = b_ptr->cp_env;
|
|
|
|
b_ptr = b_ptr->cp_b;
|
|
|
|
}
|
|
|
|
} while (b_ptr != NULL);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2002-02-26 17:49:09 +00:00
|
|
|
static void
|
|
|
|
mark_pred(int mark, PredEntry *pe)
|
|
|
|
{
|
|
|
|
/* if the predicate is static mark it */
|
|
|
|
if (pe->ModuleOfPred) {
|
|
|
|
WRITE_LOCK(pe->PRWLock);
|
|
|
|
if (mark) {
|
2003-04-30 18:46:05 +01:00
|
|
|
pe->PredFlags |= InUsePredFlag;
|
2002-02-26 17:49:09 +00:00
|
|
|
} else {
|
2003-04-30 18:46:05 +01:00
|
|
|
pe->PredFlags &= ~InUsePredFlag;
|
2002-02-26 15:51:54 +00:00
|
|
|
}
|
2002-02-26 17:49:09 +00:00
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
2002-02-26 15:51:54 +00:00
|
|
|
}
|
2002-02-26 17:49:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* go up the chain of choice_points and environments,
|
|
|
|
marking all static predicates that current execution is depending
|
|
|
|
upon */
|
|
|
|
static void
|
|
|
|
do_toggle_static_predicates_in_use(int mask)
|
|
|
|
{
|
|
|
|
choiceptr b_ptr = B;
|
|
|
|
CELL *env_ptr = ENV;
|
|
|
|
|
|
|
|
if (b_ptr == NULL)
|
|
|
|
return;
|
2002-02-26 15:51:54 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
do {
|
2001-12-12 19:36:51 +00:00
|
|
|
PredEntry *pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* check first environments that are younger than our latest choicepoint */
|
|
|
|
while (b_ptr > (choiceptr)env_ptr) {
|
|
|
|
PredEntry *pe = EnvPreg(env_ptr[E_CP]);
|
2002-02-26 15:51:54 +00:00
|
|
|
|
2002-02-26 17:49:09 +00:00
|
|
|
mark_pred(mask, pe);
|
2001-04-09 20:54:03 +01:00
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
/* now mark the choicepoint */
|
|
|
|
{
|
|
|
|
op_numbers opnum;
|
2001-12-12 19:36:51 +00:00
|
|
|
restart_cp:
|
2002-11-18 18:18:05 +00:00
|
|
|
opnum = Yap_op_from_opcode(b_ptr->cp_ap->opc);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-12-12 19:36:51 +00:00
|
|
|
switch(opnum) {
|
|
|
|
case _or_else:
|
|
|
|
case _or_last:
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2002-02-26 15:51:54 +00:00
|
|
|
pe = b_ptr->cp_cp->u.ldl.p;
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2002-02-26 15:51:54 +00:00
|
|
|
pe = b_ptr->cp_cp->u.sla.p0;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
2001-12-12 19:36:51 +00:00
|
|
|
break;
|
|
|
|
case _Nstop:
|
|
|
|
pe = NULL;
|
|
|
|
break;
|
|
|
|
case _retry_profiled:
|
2002-11-18 18:18:05 +00:00
|
|
|
opnum = Yap_op_from_opcode(NEXTOP(b_ptr->cp_ap,l)->opc);
|
2001-12-12 19:36:51 +00:00
|
|
|
goto restart_cp;
|
2002-09-03 15:28:09 +01:00
|
|
|
case _count_retry:
|
2002-11-18 18:18:05 +00:00
|
|
|
opnum = Yap_op_from_opcode(NEXTOP(b_ptr->cp_ap,l)->opc);
|
2002-09-03 15:28:09 +01:00
|
|
|
goto restart_cp;
|
2001-12-12 19:36:51 +00:00
|
|
|
default:
|
2001-04-09 20:54:03 +01:00
|
|
|
pe = (PredEntry *)(b_ptr->cp_ap->u.ld.p);
|
|
|
|
}
|
2001-12-12 19:36:51 +00:00
|
|
|
if (pe != NULL)
|
2001-04-09 20:54:03 +01:00
|
|
|
mark_pred(mask, pe);
|
|
|
|
env_ptr = b_ptr->cp_env;
|
|
|
|
b_ptr = b_ptr->cp_b;
|
|
|
|
}
|
|
|
|
} while (b_ptr != NULL);
|
2001-12-12 19:36:51 +00:00
|
|
|
/* mark or unmark all predicates */
|
|
|
|
STATIC_PREDICATES_MARKED = mask;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2002-11-26 22:28:32 +00:00
|
|
|
static Term
|
2002-12-10 14:36:22 +00:00
|
|
|
all_envs(CELL *env_ptr)
|
2002-11-26 22:28:32 +00:00
|
|
|
{
|
2002-12-10 14:36:22 +00:00
|
|
|
Term tf = AbsPair(H);
|
2002-11-26 22:28:32 +00:00
|
|
|
CELL *bp = NULL;
|
2002-12-10 14:36:22 +00:00
|
|
|
|
2002-11-26 22:28:32 +00:00
|
|
|
/* walk the environment chain */
|
|
|
|
while (env_ptr != NULL) {
|
|
|
|
bp = H;
|
|
|
|
H += 2;
|
|
|
|
/* notice that MkIntegerTerm may increase the Heap */
|
|
|
|
bp[0] = MkIntegerTerm((Int)env_ptr[E_CP]);
|
|
|
|
if (H >= ASP) {
|
|
|
|
bp[1] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
return tf;
|
2002-11-26 22:28:32 +00:00
|
|
|
} else {
|
|
|
|
bp[1] = AbsPair(H);
|
|
|
|
}
|
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
bp[1] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
return tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Term
|
|
|
|
all_cps(choiceptr b_ptr)
|
|
|
|
{
|
|
|
|
CELL *bp = NULL;
|
|
|
|
Term tf = AbsPair(H);
|
|
|
|
|
2002-11-26 22:28:32 +00:00
|
|
|
while (b_ptr != NULL) {
|
|
|
|
bp = H;
|
|
|
|
H += 2;
|
|
|
|
/* notice that MkIntegerTerm may increase the Heap */
|
|
|
|
bp[0] = MkIntegerTerm((Int)b_ptr->cp_ap);
|
|
|
|
if (H >= ASP) {
|
|
|
|
bp[1] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
return tf;
|
2002-11-26 22:28:32 +00:00
|
|
|
} else {
|
|
|
|
bp[1] = AbsPair(H);
|
|
|
|
}
|
|
|
|
b_ptr = b_ptr->cp_b;
|
|
|
|
}
|
|
|
|
bp[1] = TermNil;
|
2002-12-10 14:36:22 +00:00
|
|
|
return tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Term
|
|
|
|
all_calls(void)
|
|
|
|
{
|
|
|
|
Term ts[3];
|
|
|
|
Functor f = Yap_MkFunctor(AtomLocal,3);
|
|
|
|
|
|
|
|
ts[0] = MkIntegerTerm((Int)P);
|
|
|
|
if (yap_flags[STACK_DUMP_ON_ERROR_FLAG]) {
|
|
|
|
ts[1] = all_envs(ENV);
|
2003-11-12 12:33:31 +00:00
|
|
|
ts[2] = all_cps(B);
|
2002-12-10 14:36:22 +00:00
|
|
|
} else {
|
|
|
|
ts[1] = ts[2] = TermNil;
|
|
|
|
}
|
2002-11-26 22:28:32 +00:00
|
|
|
return(Yap_MkApplTerm(f,3,ts));
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
|
|
|
Yap_all_calls(void)
|
|
|
|
{
|
|
|
|
return all_calls();
|
|
|
|
}
|
|
|
|
|
2002-10-21 23:14:29 +01:00
|
|
|
static Int
|
|
|
|
p_current_stack(void)
|
|
|
|
{
|
|
|
|
#ifdef YAPOR
|
|
|
|
return(FALSE);
|
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG1,all_calls()));
|
2002-10-21 23:14:29 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* This predicate is to be used by reconsult to mark all predicates
|
|
|
|
currently in use as being executed.
|
|
|
|
|
|
|
|
The idea is to go up the chain of choice_points and environments.
|
|
|
|
|
|
|
|
*/
|
|
|
|
static Int
|
|
|
|
p_toggle_static_predicates_in_use(void)
|
|
|
|
{
|
|
|
|
#if !defined(YAPOR) && !defined(THREADS)
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Int mask;
|
|
|
|
|
|
|
|
/* find out whether we need to mark or unmark */
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"toggle_static_predicates_in_use/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,t,"toggle_static_predicates_in_use/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else {
|
|
|
|
mask = IntOfTerm(t);
|
|
|
|
}
|
|
|
|
do_toggle_static_predicates_in_use(mask);
|
|
|
|
#endif
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static void
|
|
|
|
clause_was_found(PredEntry *pp, Atom *pat, UInt *parity) {
|
|
|
|
/* we found it */
|
|
|
|
*parity = pp->ArityOfPE;
|
|
|
|
if (pp->ArityOfPE) {
|
|
|
|
*pat = NameOfFunctor(pp->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
*pat = (Atom)(pp->FunctorOfPred);
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-12-02 00:36:27 +00:00
|
|
|
static void
|
|
|
|
code_in_pred_info(PredEntry *pp, Atom *pat, UInt *parity) {
|
|
|
|
*parity = pp->ArityOfPE;
|
|
|
|
if (pp->ArityOfPE) {
|
|
|
|
*pat = NameOfFunctor(pp->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
*pat = (Atom)(pp->FunctorOfPred);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
code_in_pred_lu_index(LogUpdIndex *icl, yamop *codeptr) {
|
|
|
|
LogUpdIndex *cicl;
|
|
|
|
if (IN_BLOCK(codeptr,icl,Yap_SizeOfBlock((CODEADDR)icl))) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
cicl = icl->ChildIndex;
|
|
|
|
while (cicl != NULL) {
|
|
|
|
if (code_in_pred_lu_index(cicl, codeptr))
|
|
|
|
return TRUE;
|
|
|
|
cicl = cicl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
code_in_pred_s_index(StaticIndex *icl, yamop *codeptr) {
|
|
|
|
StaticIndex *cicl;
|
|
|
|
if (IN_BLOCK(codeptr,icl,Yap_SizeOfBlock((CODEADDR)icl))) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
cicl = icl->ChildIndex;
|
|
|
|
while (cicl != NULL) {
|
|
|
|
if (code_in_pred_s_index(cicl, codeptr))
|
|
|
|
return TRUE;
|
|
|
|
cicl = cicl->SiblingIndex;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2002-12-27 16:53:09 +00:00
|
|
|
code_in_pred(PredEntry *pp, Atom *pat, UInt *parity, yamop *codeptr) {
|
|
|
|
yamop *clcode;
|
2001-12-11 19:12:41 +00:00
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
READ_LOCK(pp->PRWLock);
|
2003-12-02 00:36:27 +00:00
|
|
|
/* check if the codeptr comes from the indexing code */
|
|
|
|
if (pp->PredFlags & IndexedPredFlag) {
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
if (code_in_pred_lu_index(ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr)) {
|
|
|
|
code_in_pred_info(pp, pat, parity);
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (code_in_pred_s_index(ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr)) {
|
|
|
|
code_in_pred_info(pp, pat, parity);
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
clcode = pp->cs.p_code.FirstClause;
|
2003-04-30 18:46:05 +01:00
|
|
|
if (clcode != NULL) {
|
|
|
|
char *code_end;
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(pp->cs.p_code.TrueCodeOfPred);
|
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
} else if (!(pp->PredFlags & DynamicPredFlag)) {
|
|
|
|
code_end = NULL;
|
|
|
|
} else {
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(pp->cs.p_code.TrueCodeOfPred);
|
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(clcode);
|
|
|
|
do {
|
|
|
|
if (IN_BLOCK(codeptr,(CODEADDR)cl,Yap_SizeOfBlock((CODEADDR)cl))) {
|
|
|
|
clause_was_found(pp, pat, parity);
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (cl != NULL);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (pp->PredFlags & DynamicPredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
do {
|
|
|
|
CODEADDR cl;
|
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = (CODEADDR)ClauseCodeToDynamicClause(clcode);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (IN_BLOCK(codeptr,cl,Yap_SizeOfBlock((CODEADDR)cl))) {
|
|
|
|
clause_was_found(pp, pat, parity);
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (clcode == pp->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
i++;
|
2003-11-26 18:36:35 +00:00
|
|
|
clcode = NextDynamicClause(clcode);
|
|
|
|
} while (TRUE);
|
|
|
|
} else {
|
|
|
|
StaticClause *cl;
|
|
|
|
|
|
|
|
cl = ClauseCodeToStaticClause(clcode);
|
|
|
|
do {
|
|
|
|
if (IN_BLOCK(codeptr,cl,Yap_SizeOfBlock((CODEADDR)cl))) {
|
|
|
|
clause_was_found(pp, pat, parity);
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (cl->ClCode == pp->cs.p_code.LastClause)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
cl = cl->ClNext;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-12-11 19:12:41 +00:00
|
|
|
READ_UNLOCK(pp->PRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Int
|
2004-02-12 12:37:12 +00:00
|
|
|
PredForCode(yamop *codeptr, Atom *pat, UInt *parity, Term *pmodule) {
|
2001-12-12 19:36:51 +00:00
|
|
|
Int found = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i_table;
|
2001-12-11 19:12:41 +00:00
|
|
|
|
2001-12-12 19:36:51 +00:00
|
|
|
/* should we allow the user to see hidden predicates? */
|
|
|
|
for (i_table = NoOfModules-1; i_table >= 0; --i_table) {
|
2001-12-11 19:12:41 +00:00
|
|
|
PredEntry *pp = ModulePred[i_table];
|
|
|
|
while (pp != NULL) {
|
|
|
|
if ((found = code_in_pred(pp, pat, parity, codeptr)) != 0) {
|
2004-02-12 17:09:17 +00:00
|
|
|
if (i_table)
|
|
|
|
*pmodule = ModuleName[i_table];
|
|
|
|
else
|
|
|
|
*pmodule = TermProlog;
|
2001-12-12 19:36:51 +00:00
|
|
|
return(found);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-12-11 19:12:41 +00:00
|
|
|
pp = pp->NextPredOfModule;
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
|
|
|
}
|
2001-12-12 19:36:51 +00:00
|
|
|
return(0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Int
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_PredForCode(yamop *codeptr, Atom *pat, UInt *parity, Term *pmodule) {
|
2002-11-11 17:38:10 +00:00
|
|
|
return PredForCode(codeptr, pat, parity, pmodule);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-09 18:40:12 +01:00
|
|
|
static Int
|
|
|
|
p_pred_for_code(void) {
|
2003-12-02 00:36:27 +00:00
|
|
|
yamop *codeptr;
|
2002-09-09 18:40:12 +01:00
|
|
|
Atom at;
|
|
|
|
UInt arity;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term module;
|
2002-09-09 18:40:12 +01:00
|
|
|
Int cl;
|
2003-12-02 00:36:27 +00:00
|
|
|
Term t = Deref(ARG1);
|
2002-09-09 18:40:12 +01:00
|
|
|
|
2003-12-02 00:36:27 +00:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return FALSE;
|
|
|
|
} else if (IsIntegerTerm(t)) {
|
|
|
|
codeptr = (yamop *)IntegerOfTerm(t);
|
|
|
|
} else if (IsDBRefTerm(t)) {
|
|
|
|
codeptr = (yamop *)DBRefOfTerm(t);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-09-09 18:40:12 +01:00
|
|
|
cl = PredForCode(codeptr, &at, &arity, &module);
|
2004-02-12 12:37:12 +00:00
|
|
|
if (!module) module = TermProlog;
|
2003-12-02 00:36:27 +00:00
|
|
|
if (cl == 0) {
|
|
|
|
return(Yap_unify(ARG5,MkIntTerm(0)));
|
|
|
|
} else {
|
|
|
|
return(Yap_unify(ARG2,MkAtomTerm(at)) &&
|
|
|
|
Yap_unify(ARG3,MkIntegerTerm(arity)) &&
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_unify(ARG4,module) &&
|
2003-12-02 00:36:27 +00:00
|
|
|
Yap_unify(ARG5,MkIntegerTerm(cl)));
|
|
|
|
}
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_is_profiled(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Term ta;
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
if (PROFILING) ta = MkAtomTerm(Yap_LookupAtom("on"));
|
|
|
|
else ta = MkAtomTerm(Yap_LookupAtom("off"));
|
2001-04-09 20:54:03 +01:00
|
|
|
BIND((CELL *)t,ta,bind_is_profiled);
|
|
|
|
#ifdef COROUTINING
|
|
|
|
DO_TRAIL(CellPtr(t), ta);
|
2002-11-18 18:18:05 +00:00
|
|
|
if (CellPtr(t) < H0) Yap_WakeUp((CELL *)t);
|
2001-04-09 20:54:03 +01:00
|
|
|
bind_is_profiled:
|
|
|
|
#endif
|
|
|
|
return(TRUE);
|
|
|
|
} else if (!IsAtomTerm(t)) return(FALSE);
|
|
|
|
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
|
|
|
if (strcmp(s,"on") == 0) {
|
|
|
|
PROFILING = TRUE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
} else if (strcmp(s,"off") == 0) {
|
|
|
|
PROFILING = FALSE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_profile_info(void)
|
|
|
|
{
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tfun = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
Term out;
|
|
|
|
PredEntry *pe;
|
|
|
|
Term p[3];
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (IsVarTerm(tfun)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsApplTerm(tfun)) {
|
|
|
|
Functor f = FunctorOfTerm(tfun);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(f, mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsAtomTerm(tfun)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(tfun), mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
LOCK(pe->StatisticsForPred.lock);
|
|
|
|
if (!(pe->StatisticsForPred.NOfEntries)) {
|
|
|
|
UNLOCK(pe->StatisticsForPred.lock);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2003-03-20 15:10:18 +00:00
|
|
|
p[0] = Yap_MkULLIntTerm(pe->StatisticsForPred.NOfEntries);
|
|
|
|
p[1] = Yap_MkULLIntTerm(pe->StatisticsForPred.NOfHeadSuccesses);
|
|
|
|
p[2] = Yap_MkULLIntTerm(pe->StatisticsForPred.NOfRetries);
|
2001-04-09 20:54:03 +01:00
|
|
|
UNLOCK(pe->StatisticsForPred.lock);
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_MkApplTerm(Yap_MkFunctor(AtomProfile,3),3,p);
|
|
|
|
return(Yap_unify(ARG3,out));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_profile_reset(void)
|
|
|
|
{
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tfun = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod))
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
if (IsVarTerm(tfun)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsApplTerm(tfun)) {
|
|
|
|
Functor f = FunctorOfTerm(tfun);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(f, mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else if (IsAtomTerm(tfun)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(tfun), mod));
|
2001-11-15 00:01:43 +00:00
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
|
|
|
if (EndOfPAEntr(pe))
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
LOCK(pe->StatisticsForPred.lock);
|
|
|
|
pe->StatisticsForPred.NOfEntries = 0;
|
|
|
|
pe->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
pe->StatisticsForPred.NOfRetries = 0;
|
|
|
|
UNLOCK(pe->StatisticsForPred.lock);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2002-09-03 15:28:09 +01:00
|
|
|
static Int
|
|
|
|
p_is_call_counted(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Term ta;
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
if (CALL_COUNTING) ta = MkAtomTerm(Yap_LookupAtom("on"));
|
|
|
|
else ta = MkAtomTerm(Yap_LookupAtom("off"));
|
2002-09-03 15:28:09 +01:00
|
|
|
BIND((CELL *)t,ta,bind_is_call_counted);
|
|
|
|
#ifdef COROUTINING
|
|
|
|
DO_TRAIL(CellPtr(t), ta);
|
2002-11-18 18:18:05 +00:00
|
|
|
if (CellPtr(t) < H0) Yap_WakeUp((CELL *)t);
|
2002-09-03 15:28:09 +01:00
|
|
|
bind_is_call_counted:
|
|
|
|
#endif
|
|
|
|
return(TRUE);
|
|
|
|
} else if (!IsAtomTerm(t)) return(FALSE);
|
|
|
|
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
|
|
|
if (strcmp(s,"on") == 0) {
|
|
|
|
CALL_COUNTING = TRUE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
} else if (strcmp(s,"off") == 0) {
|
|
|
|
CALL_COUNTING = FALSE;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2002-09-03 15:28:09 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_call_count_info(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(MkIntegerTerm(ReductionsCounter),ARG1) &&
|
|
|
|
Yap_unify(MkIntegerTerm(PredEntriesCounter),ARG2) &&
|
|
|
|
Yap_unify(MkIntegerTerm(PredEntriesCounter),ARG3));
|
2002-09-03 15:28:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_call_count_reset(void)
|
|
|
|
{
|
|
|
|
ReductionsCounter = 0;
|
|
|
|
ReductionsCounterOn = FALSE;
|
|
|
|
PredEntriesCounter = 0;
|
|
|
|
PredEntriesCounterOn = FALSE;
|
|
|
|
RetriesCounter = 0;
|
|
|
|
RetriesCounterOn = FALSE;
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_call_count_set(void)
|
|
|
|
{
|
|
|
|
int do_calls = IntOfTerm(ARG2);
|
|
|
|
int do_retries = IntOfTerm(ARG4);
|
|
|
|
int do_entries = IntOfTerm(ARG6);
|
|
|
|
|
|
|
|
if (do_calls)
|
|
|
|
ReductionsCounter = IntegerOfTerm(Deref(ARG1));
|
|
|
|
ReductionsCounterOn = do_calls;
|
|
|
|
if (do_retries)
|
|
|
|
RetriesCounter = IntegerOfTerm(Deref(ARG3));
|
|
|
|
RetriesCounterOn = do_retries;
|
|
|
|
if (do_entries)
|
|
|
|
PredEntriesCounter = IntegerOfTerm(Deref(ARG5));
|
|
|
|
PredEntriesCounterOn = do_entries;
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_clean_up_dead_clauses(void)
|
|
|
|
{
|
|
|
|
while (DeadClauses != NULL) {
|
|
|
|
char *pt = (char *)DeadClauses;
|
2003-04-30 18:46:05 +01:00
|
|
|
DeadClauses = DeadClauses->NextCl;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace(pt);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2001-08-08 22:17:27 +01:00
|
|
|
static Int /* $parent_pred(Module, Name, Arity) */
|
|
|
|
p_parent_pred(void)
|
|
|
|
{
|
2001-09-12 16:52:28 +01:00
|
|
|
/* This predicate is called from the debugger.
|
|
|
|
We assume a sequence of the form a -> b */
|
2001-08-08 22:17:27 +01:00
|
|
|
Atom at;
|
2002-12-06 20:03:26 +00:00
|
|
|
UInt arity;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term module;
|
2002-12-27 16:53:09 +00:00
|
|
|
if (!PredForCode(P_before_spy, &at, &arity, &module)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG1, MkIntTerm(0)) &&
|
|
|
|
Yap_unify(ARG2, MkAtomTerm(AtomMetaCall)) &&
|
|
|
|
Yap_unify(ARG3, MkIntTerm(0)));
|
2001-08-08 22:17:27 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG1, MkIntTerm(module)) &&
|
|
|
|
Yap_unify(ARG2, MkAtomTerm(at)) &&
|
|
|
|
Yap_unify(ARG3, MkIntTerm(arity)));
|
2001-08-08 22:17:27 +01:00
|
|
|
}
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
static Int /* $system_predicate(P) */
|
2001-10-30 16:42:05 +00:00
|
|
|
p_system_pred(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-01-08 05:22:40 +00:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
restart_system_pred:
|
2001-10-30 16:42:05 +00:00
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-02-22 06:12:18 +00:00
|
|
|
if (funt == FunctorModule) {
|
2001-10-30 16:42:05 +00:00
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"system_predicate/1");
|
2001-10-30 16:42:05 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"system_predicate/1");
|
2001-10-30 16:42:05 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
2001-11-15 00:01:43 +00:00
|
|
|
goto restart_system_pred;
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2002-03-04 15:55:13 +00:00
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return (TRUE);
|
2001-10-30 16:42:05 +00:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return(FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
return(!pe->ModuleOfPred || pe->PredFlags & (UserCPredFlag|CPredFlag|BinaryTestPredFlag|AsmPredFlag|TestPredFlag));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 17:00:54 +01:00
|
|
|
static Int /* $system_predicate(P) */
|
|
|
|
p_hide_predicate(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-08-14 17:00:54 +01:00
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
2002-08-14 17:00:54 +01:00
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"hide_predicate/1");
|
2002-08-14 17:00:54 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"hide_predicate/1");
|
2002-08-14 17:00:54 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2002-08-14 17:00:54 +01:00
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return (TRUE);
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return(FALSE);
|
|
|
|
pe->PredFlags |= HiddenPredFlag;
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2002-09-02 18:33:00 +01:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_hidden_predicate(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-09-02 18:33:00 +01:00
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
2002-09-02 18:33:00 +01:00
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"hide_predicate/1");
|
2002-09-02 18:33:00 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,ARG1,"hide_predicate/1");
|
2002-09-02 18:33:00 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
2002-09-02 18:33:00 +01:00
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return (TRUE);
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return(FALSE);
|
|
|
|
return(pe->PredFlags & HiddenPredFlag);
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static PredEntry *
|
2004-02-12 12:37:12 +00:00
|
|
|
get_pred(Term t1, Term mod, char *command)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
restart_system_pred:
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return NULL;
|
|
|
|
if (IsAtomTerm(t1)) {
|
|
|
|
return RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t1), mod));
|
|
|
|
} else if (IsApplTerm(t1)) {
|
|
|
|
Functor funt = FunctorOfTerm(t1);
|
|
|
|
if (IsExtensionFunctor(funt)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (funt == FunctorModule) {
|
|
|
|
Term nmod = ArgOfTerm(1, t1);
|
|
|
|
if (IsVarTerm(nmod)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,command);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(nmod)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,command);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
t1 = ArgOfTerm(2, t1);
|
|
|
|
goto restart_system_pred;
|
|
|
|
}
|
|
|
|
return RepPredProp(Yap_GetPredPropByFunc(funt, mod));
|
|
|
|
} else if (IsPairTerm(t1)) {
|
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2003-10-17 03:11:21 +01:00
|
|
|
fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, yamop *cp_ptr, int first_time)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
2003-12-01 17:27:42 +00:00
|
|
|
LogUpdClause *cl;
|
2003-08-27 14:37:10 +01:00
|
|
|
Term rtn;
|
|
|
|
|
2003-12-01 19:22:01 +00:00
|
|
|
cl = Yap_FollowIndexingCode(pe, i_code, th, tb, tr, NEXTOP(PredLogUpdClause->CodeOfPred,ld), cp_ptr);
|
2003-12-01 17:27:42 +00:00
|
|
|
if (cl == NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
return FALSE;
|
2003-12-01 17:27:42 +00:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
rtn = MkDBRefTerm((DBRef)cl);
|
2003-12-18 17:23:22 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2003-08-27 14:37:10 +01:00
|
|
|
LOCK(cl->ClLock);
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2003-12-18 17:23:22 +00:00
|
|
|
INC_CLREF_COUNT(cl);
|
2003-08-27 14:37:10 +01:00
|
|
|
UNLOCK(cl->ClLock);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
|
|
|
#endif
|
2004-02-22 00:35:07 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (PP == pe) {
|
|
|
|
PP = NULL;
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
}
|
|
|
|
#endif
|
2004-02-19 19:24:46 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
WPP = NULL;
|
|
|
|
#endif
|
2003-11-18 19:24:46 +00:00
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) ||
|
|
|
|
!Yap_unify(tr, rtn))
|
|
|
|
return FALSE;
|
2003-11-21 16:56:20 +00:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
|
|
|
if (first_time) {
|
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
|
|
|
}
|
2003-12-01 17:27:42 +00:00
|
|
|
READ_LOCK(pe->PRWLock);
|
2003-11-21 16:56:20 +00:00
|
|
|
P = cl->ClCode;
|
2003-12-01 17:27:42 +00:00
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2003-11-18 19:24:46 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) {
|
|
|
|
if (first_time) {
|
|
|
|
if (!Yap_gc(4, YENV, P)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!Yap_gc(5, ENV, CP)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
return(Yap_unify(th, ArgOfTerm(1,t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2,t)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_log_update_clause(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-19 19:24:46 +00:00
|
|
|
Int ret;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2003-11-21 16:56:20 +00:00
|
|
|
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
2004-02-19 19:24:46 +00:00
|
|
|
WRITE_LOCK(pe->PRWLock);
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->OpcodeOfPred == INDEX_OPCODE)
|
|
|
|
#endif
|
|
|
|
IPred(pe);
|
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
|
|
|
}
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-22 00:35:07 +00:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
PP = pe;
|
2004-02-19 19:24:46 +00:00
|
|
|
#endif
|
|
|
|
ret = fetch_next_lu_clause(pe, pe->cs.p_code.TrueCodeOfPred, t1, ARG3, ARG4, P, TRUE);
|
|
|
|
return ret;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_continue_log_update_clause(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2003-10-17 03:11:21 +01:00
|
|
|
return fetch_next_lu_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap, FALSE);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2003-10-17 03:11:21 +01:00
|
|
|
fetch_next_lu_clause0(PredEntry *pe, yamop *i_code, Term th, Term tb, yamop *cp_ptr, int first_time)
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
2003-12-01 17:27:42 +00:00
|
|
|
LogUpdClause *cl;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
2003-12-01 19:22:01 +00:00
|
|
|
cl = Yap_FollowIndexingCode(pe, i_code, th, tb, TermNil, NEXTOP(PredLogUpdClause0->CodeOfPred,ld), cp_ptr);
|
2004-02-22 00:35:07 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (PP == pe) {
|
|
|
|
PP = NULL;
|
|
|
|
READ_UNLOCK(pe->PRWLock);
|
|
|
|
}
|
|
|
|
#endif
|
2003-12-01 17:27:42 +00:00
|
|
|
if (cl == NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
return FALSE;
|
2003-12-01 17:27:42 +00:00
|
|
|
}
|
2003-11-18 19:24:46 +00:00
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)))
|
|
|
|
return FALSE;
|
2003-11-21 16:56:20 +00:00
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
|
|
|
if (first_time) {
|
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
|
|
|
}
|
2003-12-01 17:27:42 +00:00
|
|
|
READ_LOCK(pe->PRWLock);
|
2003-11-21 16:56:20 +00:00
|
|
|
P = cl->ClCode;
|
2003-12-01 17:27:42 +00:00
|
|
|
READ_UNLOCK(pe->PRWLock);
|
2003-11-18 19:24:46 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) {
|
|
|
|
if (first_time) {
|
|
|
|
if (!Yap_gc(4, YENV, P)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!Yap_gc(5, ENV, CP)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-10-17 03:11:21 +01:00
|
|
|
}
|
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
return(Yap_unify(th, ArgOfTerm(1,t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2,t)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_log_update_clause0(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-19 19:24:46 +00:00
|
|
|
Int ret;
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2003-11-21 16:56:20 +00:00
|
|
|
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
2004-02-19 19:24:46 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->OpcodeOfPred == INDEX_OPCODE)
|
|
|
|
#endif
|
|
|
|
IPred(pe);
|
|
|
|
}
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-02-22 00:35:07 +00:00
|
|
|
READ_LOCK(pe->PRWLock);
|
|
|
|
PP = pe;
|
2004-02-19 19:24:46 +00:00
|
|
|
#endif
|
|
|
|
ret = fetch_next_lu_clause0(pe, pe->cs.p_code.TrueCodeOfPred, t1, ARG3, P, TRUE);
|
|
|
|
return ret;
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_continue_log_update_clause0(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
2003-10-17 03:11:21 +01:00
|
|
|
return fetch_next_lu_clause0(pe, ipc, Deref(ARG3), ARG4, B->cp_ap, FALSE);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
static Int
|
|
|
|
fetch_next_static_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, yamop *cp_ptr, int first_time)
|
|
|
|
{
|
2003-12-01 17:27:42 +00:00
|
|
|
StaticClause *cl;
|
2003-11-21 16:56:20 +00:00
|
|
|
Term rtn;
|
|
|
|
|
2003-12-01 19:22:01 +00:00
|
|
|
cl = (StaticClause *)Yap_FollowIndexingCode(pe, i_code, th, tb, tr, NEXTOP(PredStaticClause->CodeOfPred,ld), cp_ptr);
|
2003-11-21 16:56:20 +00:00
|
|
|
if (cl == NULL)
|
|
|
|
return FALSE;
|
|
|
|
rtn = MkDBRefTerm((DBRef)cl);
|
|
|
|
if (cl->ClFlags & FactMask) {
|
|
|
|
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) ||
|
|
|
|
!Yap_unify(tr, rtn))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (pe->ArityOfPE) {
|
|
|
|
Functor f = FunctorOfTerm(th);
|
|
|
|
UInt arity = ArityOfFunctor(f), i;
|
|
|
|
CELL *pt = RepAppl(th)+1;
|
|
|
|
|
|
|
|
for (i=0; i<arity; i++) {
|
|
|
|
XREGS[i+1] = pt[i];
|
|
|
|
}
|
|
|
|
/* don't need no ENV */
|
|
|
|
if (first_time) {
|
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL) B;
|
|
|
|
}
|
2003-11-26 18:36:35 +00:00
|
|
|
P = cl->ClCode;
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
Term t;
|
|
|
|
|
2003-11-24 00:00:43 +00:00
|
|
|
while ((t = Yap_FetchTermFromDB(cl->usc.ClSource)) == 0L) {
|
2003-11-21 16:56:20 +00:00
|
|
|
if (first_time) {
|
|
|
|
if (!Yap_gc(4, YENV, P)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!Yap_gc(5, ENV, CP)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(Yap_unify(th, ArgOfTerm(1,t)) &&
|
|
|
|
Yap_unify(tb, ArgOfTerm(2,t)) &&
|
|
|
|
Yap_unify(tr, rtn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_static_clause(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
|
|
|
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
2004-02-19 19:24:46 +00:00
|
|
|
WRITE_LOCK(pe->PRWLock);
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (pe->OpcodeOfPred == INDEX_OPCODE)
|
|
|
|
#endif
|
|
|
|
IPred(pe);
|
|
|
|
WRITE_UNLOCK(pe->PRWLock);
|
2003-11-21 16:56:20 +00:00
|
|
|
}
|
|
|
|
return fetch_next_static_clause(pe, pe->cs.p_code.TrueCodeOfPred, t1, ARG3, ARG4, P, TRUE);
|
|
|
|
}
|
|
|
|
|
2003-12-01 19:22:01 +00:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_nth_clause(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term tn = Deref(ARG3);
|
|
|
|
LogUpdClause *cl;
|
|
|
|
Int ncls;
|
|
|
|
|
|
|
|
if (!IsIntegerTerm(tn))
|
|
|
|
return FALSE;
|
|
|
|
ncls = IntegerOfTerm(tn);
|
|
|
|
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
|
|
|
if (pe == NULL || EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
2004-02-18 01:43:32 +00:00
|
|
|
if (!(pe->PredFlags & (SourcePredFlag|LogUpdatePredFlag))) {
|
2003-12-01 19:22:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* in case we have to index or to expand code */
|
2004-02-12 12:37:12 +00:00
|
|
|
if (pe->ModuleOfPred != IDB_MODULE) {
|
2003-12-01 19:22:01 +00:00
|
|
|
UInt i;
|
|
|
|
|
|
|
|
for (i = 1; i <= pe->ArityOfPE; i++) {
|
|
|
|
XREGS[i] = MkVarTerm();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XREGS[2] = MkVarTerm();
|
|
|
|
}
|
2004-02-19 19:24:46 +00:00
|
|
|
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
|
|
|
IPred(pe);
|
2004-02-18 01:43:32 +00:00
|
|
|
}
|
2004-02-19 19:24:46 +00:00
|
|
|
cl = Yap_NthClause(pe, ncls);
|
|
|
|
if (cl == NULL)
|
2003-12-01 19:22:01 +00:00
|
|
|
return FALSE;
|
|
|
|
if (cl->ClFlags & LogUpdatePredFlag) {
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
LOCK(cl->ClLock);
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
2003-12-18 17:23:22 +00:00
|
|
|
INC_CLREF_COUNT(cl);
|
2003-12-01 19:22:01 +00:00
|
|
|
UNLOCK(cl->ClLock);
|
|
|
|
#else
|
|
|
|
if (!(cl->ClFlags & InUseMask)) {
|
|
|
|
cl->ClFlags |= InUseMask;
|
|
|
|
TRAIL_CLREF(cl); /* So that fail will erase it */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return Yap_unify(MkDBRefTerm((DBRef)cl), ARG4);
|
|
|
|
}
|
|
|
|
|
2003-11-21 16:56:20 +00:00
|
|
|
static Int /* $hidden_predicate(P) */
|
|
|
|
p_continue_static_clause(void)
|
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
|
|
|
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
|
|
|
|
|
|
|
return fetch_next_static_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
#ifdef LOW_PROF
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_code_in_pred(PredEntry *pp) {
|
|
|
|
yamop *clcode;
|
|
|
|
|
|
|
|
READ_LOCK(pp->PRWLock);
|
|
|
|
/* check if the codeptr comes from the indexing code */
|
2003-05-21 13:15:09 +01:00
|
|
|
|
|
|
|
if (pp->PredFlags & (CPredFlag|AsmPredFlag)) {
|
|
|
|
char *code_end;
|
|
|
|
StaticClause *cl;
|
|
|
|
|
|
|
|
clcode = pp->CodeOfPred;
|
|
|
|
cl = ClauseCodeToStaticClause(clcode);
|
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
2003-05-21 14:00:23 +01:00
|
|
|
Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp);
|
2004-02-22 00:35:07 +00:00
|
|
|
READ_UNLOCK(pp->PRWLock);
|
2003-05-21 13:15:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2003-05-20 20:11:59 +01:00
|
|
|
clcode = pp->cs.p_code.TrueCodeOfPred;
|
|
|
|
if (pp->PredFlags & IndexedPredFlag) {
|
|
|
|
char *code_end;
|
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(clcode);
|
2003-05-20 20:11:59 +01:00
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
} else {
|
2003-08-27 14:37:10 +01:00
|
|
|
StaticIndex *cl = ClauseCodeToStaticIndex(clcode);
|
2003-05-20 20:11:59 +01:00
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
}
|
2003-05-21 14:00:23 +01:00
|
|
|
Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp);
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
clcode = pp->cs.p_code.FirstClause;
|
|
|
|
if (clcode != NULL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(clcode);
|
|
|
|
do {
|
|
|
|
char *code_end;
|
|
|
|
|
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
Yap_inform_profiler_of_clause(cl->ClCode, (yamop *)code_end, pp);
|
|
|
|
cl = cl->ClNext;
|
|
|
|
} while (cl != NULL);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (pp->PredFlags & DynamicPredFlag) {
|
2003-08-27 14:37:10 +01:00
|
|
|
do {
|
|
|
|
CODEADDR cl;
|
|
|
|
char *code_end;
|
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = (CODEADDR)ClauseCodeToDynamicClause(clcode);
|
2003-08-27 14:37:10 +01:00
|
|
|
code_end = cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp);
|
|
|
|
if (clcode == pp->cs.p_code.LastClause)
|
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
clcode = NextDynamicClause(clcode);
|
|
|
|
} while (TRUE);
|
|
|
|
} else {
|
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(clcode);
|
|
|
|
do {
|
|
|
|
char *code_end;
|
|
|
|
|
|
|
|
code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl);
|
|
|
|
Yap_inform_profiler_of_clause(cl->ClCode, (yamop *)code_end, pp);
|
|
|
|
if (cl->ClCode == pp->cs.p_code.FirstClause)
|
|
|
|
break;
|
|
|
|
cl = cl->ClNext;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
READ_UNLOCK(pp->PRWLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_dump_code_area_for_profiler(void) {
|
|
|
|
Int i_table;
|
|
|
|
|
|
|
|
for (i_table = NoOfModules-1; i_table >= 0; --i_table) {
|
|
|
|
PredEntry *pp = ModulePred[i_table];
|
|
|
|
while (pp != NULL) {
|
2003-05-21 14:00:23 +01:00
|
|
|
/* if (pp->ArityOfPE) {
|
2003-05-21 13:15:09 +01:00
|
|
|
fprintf(stderr,"%s/%d %p\n",
|
|
|
|
RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE,
|
|
|
|
pp->ArityOfPE,
|
|
|
|
pp);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"%s %p\n",
|
|
|
|
RepAtom((Atom)(pp->FunctorOfPred))->StrOfAE,
|
|
|
|
pp);
|
2003-05-21 14:00:23 +01:00
|
|
|
}*/
|
2003-05-20 20:11:59 +01:00
|
|
|
add_code_in_pred(pp);
|
|
|
|
pp = pp->NextPredOfModule;
|
|
|
|
}
|
|
|
|
}
|
2003-05-21 14:00:23 +01:00
|
|
|
Yap_inform_profiler_of_clause(COMMA_CODE, FAILCODE, RepPredProp(Yap_GetPredPropByFunc(FunctorComma,0)));
|
|
|
|
Yap_inform_profiler_of_clause(FAILCODE, FAILCODE+1, RepPredProp(Yap_GetPredPropByAtom(AtomFail,0)));
|
2003-05-20 20:11:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LOW_PROF */
|
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
static UInt
|
|
|
|
index_ssz(StaticIndex *x)
|
|
|
|
{
|
|
|
|
UInt sz = Yap_SizeOfBlock((CODEADDR)x);
|
|
|
|
x = x->ChildIndex;
|
|
|
|
while (x != NULL) {
|
|
|
|
sz += index_ssz(x);
|
|
|
|
x = x->SiblingIndex;
|
|
|
|
}
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
static_statistics(PredEntry *pe)
|
|
|
|
{
|
|
|
|
UInt sz = 0, 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
|
|
|
|
2003-11-26 18:36:35 +00:00
|
|
|
if (pe->cs.p_code.NOfClauses) {
|
2003-11-12 12:33:31 +00:00
|
|
|
do {
|
|
|
|
cls++;
|
|
|
|
sz += Yap_SizeOfBlock((CODEADDR)cl);
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl->ClCode == pe->cs.p_code.LastClause)
|
2003-11-12 12:33:31 +00:00
|
|
|
break;
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = cl->ClNext;
|
2003-11-12 12:33:31 +00:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
|
|
|
if (pe->cs.p_code.NOfClauses > 1 &&
|
|
|
|
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause) {
|
|
|
|
isz = index_ssz(ClauseCodeToStaticIndex(pe->cs.p_code.TrueCodeOfPred));
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG3, MkIntegerTerm(cls)) &&
|
|
|
|
Yap_unify(ARG4, MkIntegerTerm(sz)) &&
|
|
|
|
Yap_unify(ARG5, MkIntegerTerm(isz));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_static_pred_statistics(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2003-11-12 12:33:31 +00:00
|
|
|
PredEntry *pe;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return (FALSE);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByAtom(at, mod));
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor fun = FunctorOfTerm(t);
|
|
|
|
pe = RepPredProp(Yap_GetPredPropByFunc(fun, mod));
|
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (pe == NIL)
|
|
|
|
return (FALSE);
|
|
|
|
if (pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|UserCPredFlag|AsmPredFlag|CPredFlag|BinaryTestPredFlag)) {
|
|
|
|
/* should use '$recordedp' in this case */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return static_statistics(pe);
|
|
|
|
}
|
|
|
|
|
2003-05-20 20:11:59 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCdMgr(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("$compile_mode", 2, p_compile_mode, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$start_consult", 3, p_startconsult, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$show_consult_level", 1, p_showconslultlev, SafePredFlag);
|
|
|
|
Yap_InitCPred("$end_consult", 0, p_endconsult, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$set_spy", 2, p_setspy, SafePredFlag|SyncPredFlag);
|
|
|
|
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
|
|
|
|
now unsafe */
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_InitCPred("$compile", 4, p_compile, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$compile_dynamic", 5, p_compile_dynamic, SyncPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("$purge_clauses", 2, p_purge_clauses, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$in_use", 2, p_in_use, TestPredFlag | SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_dynamic", 2, p_is_dynamic, TestPredFlag | SafePredFlag);
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_InitCPred("$is_log_updatable", 2, p_is_log_updatable, TestPredFlag | SafePredFlag);
|
2003-11-21 16:56:20 +00:00
|
|
|
Yap_InitCPred("$is_source", 2, p_is_source, TestPredFlag | SafePredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("$pred_exists", 2, p_pred_exists, TestPredFlag | SafePredFlag);
|
|
|
|
Yap_InitCPred("$number_of_clauses", 3, p_number_of_clauses, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$undefined", 2, p_undefined, SafePredFlag|TestPredFlag);
|
|
|
|
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("$in_this_file_before", 3, p_in_this_f_before, SafePredFlag);
|
|
|
|
Yap_InitCPred("$first_clause_in_file", 3, p_first_cl_in_f, SafePredFlag);
|
|
|
|
Yap_InitCPred("$mk_cl_not_first", 2, p_mk_cl_not_first, SafePredFlag);
|
|
|
|
Yap_InitCPred("$new_multifile", 3, p_new_multifile, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$is_multifile", 2, p_is_multifile, 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);
|
|
|
|
Yap_InitCPred("$toggle_static_predicates_in_use", 0, p_toggle_static_predicates_in_use, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$set_pred_module", 2, p_set_pred_module, SafePredFlag);
|
|
|
|
Yap_InitCPred("$parent_pred", 3, p_parent_pred, SafePredFlag);
|
|
|
|
Yap_InitCPred("$system_predicate", 2, p_system_pred, SafePredFlag);
|
|
|
|
Yap_InitCPred("$hide_predicate", 2, p_hide_predicate, SafePredFlag);
|
|
|
|
Yap_InitCPred("$hidden_predicate", 2, p_hidden_predicate, SafePredFlag);
|
|
|
|
Yap_InitCPred("$pred_for_code", 5, p_pred_for_code, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$current_stack", 1, p_current_stack, SyncPredFlag);
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_InitCPred("$log_update_clause", 4, p_log_update_clause, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_log_update_clause", 5, p_continue_log_update_clause, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$log_update_clause", 3, p_log_update_clause0, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_log_update_clause", 4, p_continue_log_update_clause0, SafePredFlag|SyncPredFlag);
|
2003-11-21 16:56:20 +00:00
|
|
|
Yap_InitCPred("$static_clause", 4, p_static_clause, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$continue_static_clause", 5, p_continue_static_clause, SafePredFlag|SyncPredFlag);
|
2003-11-12 12:33:31 +00:00
|
|
|
Yap_InitCPred("$static_pred_statistics", 5, p_static_pred_statistics, SyncPredFlag);
|
2003-12-01 19:22:01 +00:00
|
|
|
Yap_InitCPred("$p_nth_clause", 4, p_nth_clause, SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
|