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: exec.c *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: Execute Prolog code *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "absmi.h"
|
|
|
|
#include "yapio.h"
|
2009-06-03 01:46:41 +01:00
|
|
|
#include "attvar.h"
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
#include "cut_c.h"
|
|
|
|
#endif
|
2006-05-22 17:45:07 +01:00
|
|
|
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL
|
|
|
|
#include "myddas.h"
|
2006-01-17 22:54:02 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-05-13 21:54:58 +01:00
|
|
|
STATIC_PROTO(Int CallPredicate, (PredEntry *, choiceptr, yamop *));
|
2004-02-12 12:37:12 +00:00
|
|
|
STATIC_PROTO(Int EnterCreepMode, (Term, Term));
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(Int p_save_cp, (void));
|
|
|
|
STATIC_PROTO(Int p_execute, (void));
|
|
|
|
STATIC_PROTO(Int p_execute0, (void));
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
static Term
|
2003-01-29 14:47:17 +00:00
|
|
|
cp_as_integer(choiceptr cp)
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
2005-08-02 04:09:52 +01:00
|
|
|
return(MkIntegerTerm(LCL0-(CELL *)cp));
|
|
|
|
}
|
|
|
|
|
|
|
|
static choiceptr
|
|
|
|
cp_from_integer(Term cpt)
|
|
|
|
{
|
2006-04-25 04:23:40 +01:00
|
|
|
return (choiceptr)(LCL0-IntegerOfTerm(cpt));
|
2003-01-29 14:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
|
|
|
Yap_cp_as_integer(choiceptr cp)
|
|
|
|
{
|
|
|
|
return cp_as_integer(cp);
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline Int
|
2004-05-13 21:54:58 +01:00
|
|
|
CallPredicate(PredEntry *pen, choiceptr cut_pt, yamop *code) {
|
2003-12-01 17:27:42 +00:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
if (Yap_do_low_level_trace)
|
|
|
|
low_level_trace(enter_pred,pen,XREGS+1);
|
|
|
|
#endif /* LOW_LEVEL_TRACE */
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */
|
|
|
|
if (pen->ModuleOfPred) {
|
2004-02-22 00:35:07 +00:00
|
|
|
if (DEPTH == MkIntTerm(0)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pen->PELock);
|
2003-12-01 17:27:42 +00:00
|
|
|
return FALSE;
|
2004-02-22 00:35:07 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
else DEPTH = RESET_DEPTH();
|
|
|
|
}
|
|
|
|
} else if (pen->ModuleOfPred)
|
|
|
|
DEPTH -= MkIntConstant(2);
|
|
|
|
#endif /* DEPTH_LIMIT */
|
2008-09-01 16:48:05 +01:00
|
|
|
if (P->opc != EXECUTE_CPRED_OP_CODE) {
|
2008-08-28 04:43:00 +01:00
|
|
|
CP = P;
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
}
|
2009-11-04 12:17:17 +00:00
|
|
|
/* make sure we have access to the user given cut */
|
|
|
|
YENV[E_CB] = (CELL) cut_pt;
|
2004-05-13 21:54:58 +01:00
|
|
|
P = code;
|
2006-04-25 04:23:40 +01:00
|
|
|
return TRUE;
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline static Int
|
2004-02-12 12:37:12 +00:00
|
|
|
CallMetaCall(Term mod) {
|
2003-01-29 14:47:17 +00:00
|
|
|
ARG2 = cp_as_integer(B); /* p_save_cp */
|
2001-10-30 16:42:05 +00:00
|
|
|
ARG3 = ARG1;
|
2004-11-22 05:48:43 +00:00
|
|
|
if (mod) {
|
|
|
|
ARG4 = mod;
|
|
|
|
} else {
|
|
|
|
ARG4 = TermProlog;
|
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
return (CallPredicate(PredMetaCall, B, PredMetaCall->CodeOfPred));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_ExecuteCallMetaCall(Term mod) {
|
2001-11-15 00:01:43 +00:00
|
|
|
Term ts[4];
|
2001-10-30 16:42:05 +00:00
|
|
|
ts[0] = ARG1;
|
2003-01-29 14:47:17 +00:00
|
|
|
ts[1] = cp_as_integer(B); /* p_save_cp */
|
2001-10-30 16:42:05 +00:00
|
|
|
ts[2] = ARG1;
|
2004-02-12 12:37:12 +00:00
|
|
|
ts[3] = mod;
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_MkApplTerm(PredMetaCall->FunctorOfPred,4,ts));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2004-02-12 12:37:12 +00:00
|
|
|
CallError(yap_error_number err, Term mod)
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
|
|
|
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return(CallMetaCall(mod));
|
2001-10-30 16:42:05 +00:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(err, ARG1, "call/1");
|
2001-10-30 16:42:05 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_save_cp(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term td;
|
|
|
|
#if SHADOW_HB
|
|
|
|
register CELL *HBREG = HB;
|
|
|
|
#endif
|
|
|
|
if (!IsVarTerm(t)) return(FALSE);
|
2003-01-29 14:47:17 +00:00
|
|
|
td = cp_as_integer(B);
|
2001-04-09 20:54:03 +01:00
|
|
|
BIND((CELL *)t,td,bind_save_cp);
|
|
|
|
#ifdef COROUTINING
|
2010-03-08 09:21:16 +00:00
|
|
|
DO_TRAIL(VarOfTerm(t), td);
|
|
|
|
if (IsAttVar(VarOfTerm(t))) Yap_WakeUp((CELL *)t);
|
2001-04-09 20:54:03 +01:00
|
|
|
bind_save_cp:
|
|
|
|
#endif
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-12-27 01:32:38 +00:00
|
|
|
static Int
|
|
|
|
p_save_env_b(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term td;
|
|
|
|
#if SHADOW_HB
|
|
|
|
register CELL *HBREG = HB;
|
|
|
|
#endif
|
|
|
|
if (!IsVarTerm(t)) return(FALSE);
|
|
|
|
td = cp_as_integer((choiceptr)YENV[E_CB]);
|
|
|
|
BIND((CELL *)t,td,bind_save_cp);
|
|
|
|
#ifdef COROUTINING
|
2010-03-08 09:21:16 +00:00
|
|
|
DO_TRAIL(VarOfTerm(t), td);
|
|
|
|
if (IsAttVar(VarOfTerm(t))) Yap_WakeUp((CELL *)t);
|
2006-12-27 01:32:38 +00:00
|
|
|
bind_save_cp:
|
|
|
|
#endif
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-12-30 03:25:47 +00:00
|
|
|
static Int
|
|
|
|
p_trail_suspension_marker(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
|
|
|
|
TrailTerm(TR) = AbsPair((CELL*)t);
|
|
|
|
TR++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
inline static Int
|
2004-02-12 12:37:12 +00:00
|
|
|
do_execute(Term t, Term mod)
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
2004-05-13 21:54:58 +01:00
|
|
|
/* first do predicate expansion, even before you process signals.
|
|
|
|
This way you don't get to spy goal_expansion(). */
|
2004-12-05 05:01:45 +00:00
|
|
|
if (PRED_GOAL_EXPANSION_ALL) {
|
2004-07-15 16:47:08 +01:00
|
|
|
LOCK(SignalLock);
|
|
|
|
/* disable creeping when we do goal expansion */
|
2009-05-21 06:39:14 +01:00
|
|
|
if (ActiveSignals & YAP_CREEP_SIGNAL && !Yap_InterruptsDisabled) {
|
2004-07-15 16:47:08 +01:00
|
|
|
ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
2004-09-13 22:19:14 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
2004-07-15 16:47:08 +01:00
|
|
|
}
|
|
|
|
UNLOCK(SignalLock);
|
2004-05-13 21:54:58 +01:00
|
|
|
return CallMetaCall(mod);
|
2009-05-21 06:39:14 +01:00
|
|
|
} else if (ActiveSignals && !Yap_InterruptsDisabled) {
|
2004-05-13 21:54:58 +01:00
|
|
|
return EnterCreepMode(t, mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
restart_exec:
|
2001-10-30 16:42:05 +00:00
|
|
|
if (IsVarTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(INSTANTIATION_ERROR, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
register CELL *pt;
|
2001-10-30 16:42:05 +00:00
|
|
|
PredEntry *pen;
|
|
|
|
unsigned int i, arity;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
f = FunctorOfTerm(t);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsExtensionFunctor(f)) {
|
2009-04-26 16:47:41 +01:00
|
|
|
return CallError(TYPE_ERROR_CALLABLE, t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
arity = ArityOfFunctor(f);
|
2009-04-26 16:47:41 +01:00
|
|
|
if (arity > MaxTemps) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, t);
|
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
pen = RepPredProp(PredPropByFunc(f, mod));
|
2001-10-30 16:42:05 +00:00
|
|
|
/* You thought we would be over by now */
|
|
|
|
/* but no meta calls require special preprocessing */
|
2004-12-05 05:01:45 +00:00
|
|
|
if (pen->PredFlags & (GoalExPredFlag|MetaPredFlag)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
2002-05-14 19:24:34 +01:00
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = tmod;
|
2001-11-15 00:01:43 +00:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
2009-05-08 04:14:28 +01:00
|
|
|
} else {
|
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
return CallError(INSTANTIATION_ERROR,t);
|
|
|
|
} else {
|
|
|
|
return CallError(TYPE_ERROR_ATOM,t);
|
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
}
|
2004-01-26 12:41:06 +00:00
|
|
|
} else {
|
2007-11-16 14:58:41 +00:00
|
|
|
return CallMetaCall(mod);
|
2004-01-26 12:41:06 +00:00
|
|
|
}
|
2003-01-30 16:27:45 +00:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
/* now let us do what we wanted to do from the beginning !! */
|
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
|
|
|
pt = RepAppl(t)+1;
|
|
|
|
for (i = 1; i <= arity; i++) {
|
2001-04-09 20:54:03 +01:00
|
|
|
#if SBA
|
2001-10-30 16:42:05 +00:00
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
2003-01-29 14:47:17 +00:00
|
|
|
` XREGS[i] = (CELL)(pt-1);
|
2001-10-30 16:42:05 +00:00
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2008-02-12 17:03:59 +00:00
|
|
|
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
XREGS[i] = *pt++;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
return (CallPredicate(pen, B, pen->CodeOfPred));
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
PredEntry *pe;
|
|
|
|
Atom a = AtomOfTerm(t);
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
if (a == AtomTrue || a == AtomOtherwise || a == AtomCut)
|
|
|
|
return(TRUE);
|
|
|
|
else if (a == AtomFail || a == AtomFalse)
|
|
|
|
return(FALSE);
|
|
|
|
/* call may not define new system predicates!! */
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = RepPredProp(PredPropByAtom(a, mod));
|
2004-05-13 21:54:58 +01:00
|
|
|
return (CallPredicate(pe, B, pe->CodeOfPred));
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsIntTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(TYPE_ERROR_CALLABLE, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* Is Pair Term */
|
2001-11-15 00:01:43 +00:00
|
|
|
return(CallMetaCall(mod));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
static Term
|
|
|
|
copy_execn_to_heap(Functor f, CELL *pt, unsigned int n, unsigned int arity, Term mod)
|
|
|
|
{
|
|
|
|
CELL *h0 = H;
|
|
|
|
Term tf;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (arity == 2 &&
|
|
|
|
NameOfFunctor(f) == AtomDot) {
|
|
|
|
for (i = 0; i<arity-n;i++) {
|
|
|
|
*H++ = pt[i];
|
|
|
|
}
|
|
|
|
for (i=0; i< n; i++) {
|
2008-05-15 19:31:02 +01:00
|
|
|
*H++ = h0[(int)(i-n)];
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
tf = AbsPair(h0);
|
|
|
|
} else {
|
|
|
|
*H++ = (CELL)f;
|
|
|
|
for (i = 0; i<arity-n;i++) {
|
|
|
|
*H++ = pt[i];
|
|
|
|
}
|
|
|
|
for (i=0; i< n; i++) {
|
2008-05-15 19:31:02 +01:00
|
|
|
*H++ = h0[(int)(i-n)];
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
tf = AbsAppl(h0);
|
|
|
|
}
|
|
|
|
if (mod != CurrentModule) {
|
|
|
|
CELL *h0 = H;
|
|
|
|
*H++ = (CELL)FunctorModule;
|
|
|
|
*H++ = mod;
|
|
|
|
*H++ = tf;
|
|
|
|
tf = AbsAppl(h0);
|
|
|
|
}
|
|
|
|
return tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Int
|
|
|
|
do_execute_n(Term t, Term mod, unsigned int n)
|
|
|
|
{
|
|
|
|
Functor f;
|
|
|
|
Atom Name;
|
|
|
|
register CELL *pt;
|
|
|
|
PredEntry *pen;
|
2006-02-01 13:28:57 +00:00
|
|
|
unsigned int i, arity;
|
|
|
|
int j = -n;
|
2005-10-28 18:38:50 +01:00
|
|
|
|
|
|
|
restart_exec:
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
return CallError(INSTANTIATION_ERROR, mod);
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
arity = n;
|
|
|
|
Name = AtomOfTerm(t);
|
|
|
|
pt = NULL;
|
|
|
|
} else if (IsIntTerm(t)) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, mod);
|
|
|
|
} else if (IsPairTerm(t)) {
|
|
|
|
arity = n+2;
|
|
|
|
pt = RepPair(t);
|
|
|
|
Name = AtomOfTerm(TermNil);
|
|
|
|
} else /* if (IsApplTerm(t)) */ {
|
|
|
|
f = FunctorOfTerm(t);
|
|
|
|
while (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
|
|
|
mod = tmod;
|
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
2009-05-08 04:14:28 +01:00
|
|
|
} else {
|
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
return CallError(INSTANTIATION_ERROR,t);
|
|
|
|
} else {
|
|
|
|
return CallError(TYPE_ERROR_ATOM,t);
|
|
|
|
}
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
arity = ArityOfFunctor(f)+n;
|
|
|
|
Name = NameOfFunctor(f);
|
|
|
|
pt = RepAppl(t)+1;
|
|
|
|
}
|
|
|
|
f = Yap_MkFunctor(Name,arity);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, mod);
|
|
|
|
}
|
|
|
|
if (PRED_GOAL_EXPANSION_ALL) {
|
|
|
|
LOCK(SignalLock);
|
|
|
|
/* disable creeping when we do goal expansion */
|
2009-05-21 06:39:14 +01:00
|
|
|
if (ActiveSignals & YAP_CREEP_SIGNAL && !Yap_InterruptsDisabled) {
|
2005-10-28 18:38:50 +01:00
|
|
|
ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
|
|
|
CreepFlag = CalculateStackGap();
|
|
|
|
}
|
|
|
|
UNLOCK(SignalLock);
|
|
|
|
ARG1 = copy_execn_to_heap(f, pt, n, arity, mod);
|
|
|
|
return CallMetaCall(mod);
|
2009-05-21 06:39:14 +01:00
|
|
|
} else if (ActiveSignals && !Yap_InterruptsDisabled) {
|
2005-10-28 18:38:50 +01:00
|
|
|
return EnterCreepMode(copy_execn_to_heap(f, pt, n, arity, CurrentModule), mod);
|
|
|
|
}
|
2009-04-26 16:47:41 +01:00
|
|
|
if (arity > MaxTemps) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, t);
|
|
|
|
}
|
2005-10-28 18:38:50 +01:00
|
|
|
pen = RepPredProp(PredPropByFunc(f, mod));
|
|
|
|
/* You thought we would be over by now */
|
|
|
|
/* but no meta calls require special preprocessing */
|
|
|
|
if (pen->PredFlags & (GoalExPredFlag|MetaPredFlag)) {
|
|
|
|
ARG1 = copy_execn_to_heap(f, pt, n, arity, mod);
|
|
|
|
return(CallMetaCall(mod));
|
|
|
|
}
|
|
|
|
/* now let us do what we wanted to do from the beginning !! */
|
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
|
|
|
for (i = 1; i <= arity-n; i++) {
|
|
|
|
#if SBA
|
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
|
|
|
XREGS[i] = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
|
|
|
#else
|
|
|
|
XREGS[i] = *pt++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
for (i = arity-n+1; i <= arity; i++,j++) {
|
|
|
|
XREGS[i] = H[j];
|
|
|
|
}
|
2007-05-14 17:44:12 +01:00
|
|
|
return CallPredicate(pen, B, pen->CodeOfPred);
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
2004-01-29 13:37:10 +00:00
|
|
|
static Int
|
2004-02-12 12:37:12 +00:00
|
|
|
EnterCreepMode(Term t, Term mod) {
|
2004-01-29 13:37:10 +00:00
|
|
|
PredEntry *PredCreep;
|
|
|
|
|
|
|
|
if (ActiveSignals & YAP_CDOVF_SIGNAL) {
|
|
|
|
ARG1 = t;
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2004-07-22 22:32:23 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap at meta-call");
|
2004-01-29 13:37:10 +00:00
|
|
|
}
|
|
|
|
if (!ActiveSignals) {
|
|
|
|
return do_execute(ARG1, mod);
|
|
|
|
}
|
|
|
|
}
|
2008-08-30 02:39:36 +01:00
|
|
|
PP = PredMetaCall;
|
2004-01-29 13:37:10 +00:00
|
|
|
PredCreep = RepPredProp(PredPropByFunc(FunctorCreep,1));
|
2004-02-12 12:37:12 +00:00
|
|
|
if (mod) {
|
2008-05-15 19:31:02 +01:00
|
|
|
ARG1 = MkPairTerm(mod,t);
|
2004-02-12 12:37:12 +00:00
|
|
|
} else {
|
2008-05-15 19:31:02 +01:00
|
|
|
ARG1 = MkPairTerm(TermProlog,t);
|
2004-02-12 12:37:12 +00:00
|
|
|
}
|
2004-02-06 17:22:24 +00:00
|
|
|
LOCK(SignalLock);
|
2004-01-29 13:37:10 +00:00
|
|
|
CreepFlag = CalculateStackGap();
|
2004-02-06 17:22:24 +00:00
|
|
|
UNLOCK(SignalLock);
|
2004-01-29 13:37:10 +00:00
|
|
|
P_before_spy = P;
|
2007-05-14 17:44:12 +01:00
|
|
|
return CallPredicate(PredCreep, B, PredCreep->CodeOfPred);
|
2004-01-29 13:37:10 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
static Int
|
|
|
|
p_execute(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute(t, CurrentModule);
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
static void
|
|
|
|
heap_store(Term t)
|
|
|
|
{
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
if (VarOfTerm(t) < H) {
|
|
|
|
*H++ = t;
|
|
|
|
} else {
|
|
|
|
RESET_VARIABLE(H);
|
|
|
|
Bind_Local(VarOfTerm(t), (CELL)H);
|
|
|
|
H++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*H++ = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute2(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 1);
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute3(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 2);
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute4(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 3);
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
2006-12-31 12:29:46 +00:00
|
|
|
static Int
|
|
|
|
p_execute5(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 4);
|
2006-12-31 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute6(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 5);
|
2006-12-31 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute7(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
|
|
|
heap_store(Deref(ARG7));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 6);
|
2006-12-31 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute8(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
|
|
|
heap_store(Deref(ARG7));
|
|
|
|
heap_store(Deref(ARG8));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 7);
|
2006-12-31 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute9(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
|
|
|
heap_store(Deref(ARG7));
|
|
|
|
heap_store(Deref(ARG8));
|
|
|
|
heap_store(Deref(ARG9));
|
2007-05-14 17:44:12 +01:00
|
|
|
return do_execute_n(t, CurrentModule, 8);
|
2006-12-31 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute10(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
|
|
|
heap_store(Deref(ARG7));
|
|
|
|
heap_store(Deref(ARG8));
|
|
|
|
heap_store(Deref(ARG9));
|
|
|
|
heap_store(Deref(ARG10));
|
|
|
|
return(do_execute_n(t, CurrentModule, 9));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute11(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
|
|
|
heap_store(Deref(ARG7));
|
|
|
|
heap_store(Deref(ARG8));
|
|
|
|
heap_store(Deref(ARG9));
|
|
|
|
heap_store(Deref(ARG10));
|
|
|
|
heap_store(Deref(ARG11));
|
|
|
|
return(do_execute_n(t, CurrentModule, 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute12(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
heap_store(Deref(ARG2));
|
|
|
|
heap_store(Deref(ARG3));
|
|
|
|
heap_store(Deref(ARG4));
|
|
|
|
heap_store(Deref(ARG5));
|
|
|
|
heap_store(Deref(ARG6));
|
|
|
|
heap_store(Deref(ARG7));
|
|
|
|
heap_store(Deref(ARG8));
|
|
|
|
heap_store(Deref(ARG9));
|
|
|
|
heap_store(Deref(ARG10));
|
|
|
|
heap_store(Deref(ARG11));
|
|
|
|
heap_store(Deref(ARG12));
|
|
|
|
return(do_execute_n(t, CurrentModule, 11));
|
|
|
|
}
|
|
|
|
|
2005-08-02 04:09:52 +01:00
|
|
|
static Int
|
|
|
|
p_execute_clause(void)
|
|
|
|
{ /* '$execute_clause'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
2006-04-25 04:23:40 +01:00
|
|
|
choiceptr cut_cp = cp_from_integer(Deref(ARG4));
|
2005-08-02 04:09:52 +01:00
|
|
|
unsigned int arity;
|
|
|
|
Prop pe;
|
2005-10-18 18:04:43 +01:00
|
|
|
yamop *code;
|
|
|
|
Term clt = Deref(ARG3);
|
2005-08-02 04:09:52 +01:00
|
|
|
|
|
|
|
restart_exec:
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG3,"call/1");
|
|
|
|
return FALSE;
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
|
|
|
pe = PredPropByAtom(a, mod);
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
register unsigned int i;
|
|
|
|
register CELL *pt;
|
|
|
|
|
|
|
|
if (IsExtensionFunctor(f))
|
|
|
|
return(FALSE);
|
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
|
|
|
mod = tmod;
|
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pe = PredPropByFunc(f, mod);
|
|
|
|
arity = ArityOfFunctor(f);
|
2009-04-26 16:47:41 +01:00
|
|
|
if (arity > MaxTemps) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, t);
|
|
|
|
}
|
2005-08-02 04:09:52 +01:00
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
|
|
|
pt = RepAppl(t)+1;
|
|
|
|
for (i = 1; i <= arity; ++i) {
|
|
|
|
#if SBA
|
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
|
|
|
XREGS[i] = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
|
|
|
#else
|
|
|
|
XREGS[i] = *pt++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,ARG3,"call/1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* N = arity; */
|
|
|
|
/* call may not define new system predicates!! */
|
2005-10-18 18:04:43 +01:00
|
|
|
if (RepPredProp(pe)->PredFlags & MegaClausePredFlag) {
|
|
|
|
code = Yap_MegaClauseFromTerm(clt);
|
|
|
|
} else {
|
|
|
|
code = Yap_ClauseFromTerm(clt)->ClCode;
|
|
|
|
}
|
2008-08-30 02:39:36 +01:00
|
|
|
if (ActiveSignals & YAP_CREEP_SIGNAL) {
|
|
|
|
Yap_signal(YAP_CREEP_SIGNAL);
|
|
|
|
}
|
2006-04-25 04:23:40 +01:00
|
|
|
return CallPredicate(RepPredProp(pe), cut_cp, code);
|
2005-08-02 04:09:52 +01:00
|
|
|
}
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
static Int
|
|
|
|
p_execute_in_mod(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
2008-08-28 04:43:00 +01:00
|
|
|
return(do_execute(Deref(ARG1), Deref(ARG2)));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_execute0(void)
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* '$execute0'(Goal,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
|
|
|
unsigned int arity;
|
|
|
|
Prop pe;
|
|
|
|
|
2009-05-21 06:39:14 +01:00
|
|
|
if (ActiveSignals && !Yap_InterruptsDisabled) {
|
2004-05-13 21:54:58 +01:00
|
|
|
return EnterCreepMode(t, mod);
|
|
|
|
}
|
2002-05-20 15:19:03 +01:00
|
|
|
restart_exec:
|
2001-11-19 03:36:51 +00:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG3,"call/1");
|
2004-05-13 21:54:58 +01:00
|
|
|
return FALSE;
|
2001-11-19 03:36:51 +00:00
|
|
|
} else if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom a = AtomOfTerm(t);
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByAtom(a, mod);
|
2001-07-04 17:48:54 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
register unsigned int i;
|
|
|
|
register CELL *pt;
|
|
|
|
|
|
|
|
if (IsExtensionFunctor(f))
|
2009-04-26 16:47:41 +01:00
|
|
|
return FALSE;
|
2002-05-20 15:19:03 +01:00
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = tmod;
|
2002-05-20 15:19:03 +01:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
2009-05-08 04:14:28 +01:00
|
|
|
} else {
|
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
return CallError(INSTANTIATION_ERROR,t);
|
|
|
|
} else {
|
|
|
|
return CallError(TYPE_ERROR_ATOM,t);
|
|
|
|
}
|
2002-05-20 15:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
2002-10-18 15:52:58 +01:00
|
|
|
pe = PredPropByFunc(f, mod);
|
2008-07-23 00:34:50 +01:00
|
|
|
// Yap_DebugPlWrite(mod);fprintf(stderr,"\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = ArityOfFunctor(f);
|
2009-04-26 16:47:41 +01:00
|
|
|
if (arity > MaxTemps) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, t);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
|
|
|
pt = RepAppl(t)+1;
|
2001-10-30 16:42:05 +00:00
|
|
|
for (i = 1; i <= arity; ++i) {
|
2001-04-09 20:54:03 +01:00
|
|
|
#if SBA
|
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
|
|
|
XREGS[i] = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
|
|
|
#else
|
|
|
|
XREGS[i] = *pt++;
|
|
|
|
#endif
|
2001-10-03 14:39:16 +01:00
|
|
|
}
|
2001-11-19 03:36:51 +00:00
|
|
|
} else {
|
2010-02-26 10:04:33 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,ARG1,"call/1");
|
2004-05-13 21:54:58 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* N = arity; */
|
|
|
|
/* call may not define new system predicates!! */
|
|
|
|
return CallPredicate(RepPredProp(pe), B, RepPredProp(pe)->CodeOfPred);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_nonstop(void)
|
|
|
|
{ /* '$execute_nonstop'(Goal,Mod) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Term mod = Deref(ARG2);
|
|
|
|
unsigned int arity;
|
|
|
|
Prop pe;
|
|
|
|
|
|
|
|
restart_exec:
|
2010-02-25 17:52:11 +00:00
|
|
|
if (IsVarTerm(mod)) {
|
|
|
|
mod = CurrentModule;
|
|
|
|
} else if (!IsAtomTerm(mod)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG2, "call/1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
if (IsVarTerm(t)) {
|
2010-02-25 17:52:11 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG1,"call/1");
|
2004-05-13 21:54:58 +01:00
|
|
|
return FALSE;
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
|
|
|
pe = PredPropByAtom(a, mod);
|
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
register unsigned int i;
|
|
|
|
register CELL *pt;
|
|
|
|
|
|
|
|
if (IsExtensionFunctor(f))
|
|
|
|
return(FALSE);
|
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
|
|
|
mod = tmod;
|
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
2009-05-08 04:14:28 +01:00
|
|
|
} else {
|
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
return CallError(INSTANTIATION_ERROR,t);
|
|
|
|
} else {
|
|
|
|
return CallError(TYPE_ERROR_ATOM,t);
|
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pe = PredPropByFunc(f, mod);
|
|
|
|
arity = ArityOfFunctor(f);
|
2009-04-26 16:47:41 +01:00
|
|
|
if (arity > MaxTemps) {
|
|
|
|
return CallError(TYPE_ERROR_CALLABLE, t);
|
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
|
|
|
pt = RepAppl(t)+1;
|
|
|
|
for (i = 1; i <= arity; ++i) {
|
|
|
|
#if SBA
|
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
|
|
|
XREGS[i] = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
|
|
|
#else
|
|
|
|
XREGS[i] = *pt++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,ARG3,"call/1");
|
|
|
|
return FALSE;
|
2001-11-19 03:36:51 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* N = arity; */
|
|
|
|
/* call may not define new system predicates!! */
|
2004-05-13 21:54:58 +01:00
|
|
|
if (RepPredProp(pe)->PredFlags & SpiedPredFlag) {
|
2010-02-21 00:45:49 +00:00
|
|
|
if (ActiveSignals & YAP_CREEP_SIGNAL && !Yap_InterruptsDisabled) {
|
|
|
|
Yap_signal(YAP_CREEP_SIGNAL);
|
2007-06-04 13:11:47 +01:00
|
|
|
}
|
2010-03-03 22:11:50 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (RepPredProp(pe)->PredFlags & LogUpdatePredFlag) {
|
|
|
|
PP = RepPredProp(pe);
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(80,PP);
|
2010-03-03 22:11:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-02-21 00:45:49 +00:00
|
|
|
return CallPredicate(RepPredProp(pe), B, RepPredProp(pe)->cs.p_code.TrueCodeOfPred);
|
|
|
|
} else { if (ActiveSignals & YAP_CREEP_SIGNAL &&
|
|
|
|
!Yap_InterruptsDisabled &&
|
|
|
|
(!(RepPredProp(pe)->PredFlags & (AsmPredFlag|CPredFlag)) ||
|
|
|
|
RepPredProp(pe)->OpcodeOfPred == Yap_opcode(_call_bfunc_xx))) {
|
|
|
|
Yap_signal(YAP_CREEP_SIGNAL);
|
2007-06-04 13:11:47 +01:00
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
return CallPredicate(RepPredProp(pe), B, RepPredProp(pe)->CodeOfPred);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2009-03-13 11:11:04 +00:00
|
|
|
static Term
|
|
|
|
slice_module_for_call_with_args(Term tin, Term *modp, int arity)
|
|
|
|
{
|
|
|
|
if (IsVarTerm(tin)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,tin,"call_with_args/%d", arity);
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
while (IsApplTerm(tin)) {
|
|
|
|
Functor f = FunctorOfTerm(tin);
|
|
|
|
Term newmod;
|
|
|
|
if (f != FunctorModule) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,tin,"call_with_args/%d", arity);
|
|
|
|
return 0L;
|
2002-07-17 21:25:30 +01:00
|
|
|
}
|
2009-03-13 11:11:04 +00:00
|
|
|
newmod = ArgOfTerm(1,tin);
|
|
|
|
if (IsVarTerm(newmod)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,tin,"call_with_args/%d",arity);
|
|
|
|
return 0L;
|
|
|
|
} else if (!IsAtomTerm(newmod)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,newmod,"call_with_args/%d",arity);
|
|
|
|
return 0L;
|
2002-07-17 21:25:30 +01:00
|
|
|
}
|
2009-03-13 11:11:04 +00:00
|
|
|
*modp = newmod;
|
|
|
|
tin = ArgOfTerm(2,tin);
|
2002-06-26 06:10:17 +01:00
|
|
|
}
|
2009-03-13 11:11:04 +00:00
|
|
|
if (!IsAtomTerm(tin)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,tin,"call_with_args/%d",arity);
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
return tin;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2009-03-13 11:11:04 +00:00
|
|
|
p_execute_0(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$execute_0'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
Term mod = CurrentModule;
|
|
|
|
Term t = slice_module_for_call_with_args(Deref(ARG1),&mod,0);
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
return do_execute(t, mod);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2009-03-13 11:11:04 +00:00
|
|
|
static Int
|
|
|
|
call_with_args(int i)
|
|
|
|
{
|
|
|
|
Term mod = CurrentModule, t;
|
|
|
|
int j;
|
2002-07-17 21:25:30 +01:00
|
|
|
|
2009-03-13 11:11:04 +00:00
|
|
|
t = slice_module_for_call_with_args(Deref(ARG1),&mod,i);
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
for (j=0;j<i;j++)
|
2009-04-26 17:16:40 +01:00
|
|
|
heap_store(Deref(XREGS[j+2]));
|
2009-03-13 11:11:04 +00:00
|
|
|
return(do_execute_n(t, mod, i));
|
|
|
|
}
|
2002-07-17 21:25:30 +01:00
|
|
|
|
2009-03-13 11:11:04 +00:00
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_1(void)
|
|
|
|
{ /* '$execute_0'(Goal) */
|
|
|
|
return call_with_args(1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_2(void)
|
|
|
|
{ /* '$execute_2'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(2);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_3(void)
|
|
|
|
{ /* '$execute_3'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(3);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_4(void)
|
|
|
|
{ /* '$execute_4'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(4);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_5(void)
|
|
|
|
{ /* '$execute_5'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(5);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_6(void)
|
|
|
|
{ /* '$execute_6'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(6);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_7(void)
|
|
|
|
{ /* '$execute_7'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(7);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_8(void)
|
|
|
|
{ /* '$execute_8'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(8);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_9(void)
|
|
|
|
{ /* '$execute_9'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(9);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_10(void)
|
|
|
|
{ /* '$execute_10'(Goal) */
|
2009-03-13 11:11:04 +00:00
|
|
|
return call_with_args(10);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
static Int
|
|
|
|
p_execute_depth_limit(void) {
|
|
|
|
Term d = Deref(ARG2);
|
|
|
|
if (IsVarTerm(d)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,d,"depth_bound_call/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (!IsIntTerm(d)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, d, "depth_bound_call/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
DEPTH = MkIntTerm(IntOfTerm(d)*2);
|
|
|
|
return(p_execute());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_pred_goal_expansion_on(void) {
|
|
|
|
/* a goal needs expansion if we have goal_expansion defined or
|
|
|
|
if the goal is a meta-call */
|
2003-01-29 14:47:17 +00:00
|
|
|
return PRED_GOAL_EXPANSION_ON;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-07-27 17:27:47 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
exec_absmi(int top)
|
|
|
|
{
|
2007-06-04 13:28:02 +01:00
|
|
|
int lval, out;
|
2010-07-27 17:27:47 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
if (top && (lval = sigsetjmp (Yap_RestartEnv, 1)) != 0) {
|
2002-09-09 18:40:12 +01:00
|
|
|
switch(lval) {
|
|
|
|
case 1:
|
|
|
|
{ /* restart */
|
|
|
|
/* otherwise, SetDBForThrow will fail entering critical mode */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2002-09-09 18:40:12 +01:00
|
|
|
/* find out where to cut to */
|
|
|
|
/* siglongjmp resets the TR hardware register */
|
2006-02-13 16:58:55 +00:00
|
|
|
/* TR and B are crucial, they might have been changed, or not */
|
2002-09-09 18:40:12 +01:00
|
|
|
restore_TR();
|
2006-02-13 16:58:55 +00:00
|
|
|
restore_B();
|
|
|
|
/* H is not so important, because we're gonna backtrack */
|
2002-09-09 18:40:12 +01:00
|
|
|
restore_H();
|
2010-07-27 17:27:47 +01:00
|
|
|
/* set stack */
|
2010-07-27 23:21:15 +01:00
|
|
|
ASP = (CELL *)PROTECT_FROZEN_B(B);
|
2010-07-27 17:27:47 +01:00
|
|
|
Yap_StartSlots();
|
2004-02-06 17:22:24 +00:00
|
|
|
LOCK(SignalLock);
|
2010-12-04 18:45:09 +00:00
|
|
|
/* forget any signals active, we're reborne */
|
|
|
|
ActiveSignals = 0;
|
2002-09-09 18:40:12 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2004-02-06 17:22:24 +00:00
|
|
|
UNLOCK(SignalLock);
|
|
|
|
P = (yamop *)FAILCODE;
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
/* arithmetic exception */
|
|
|
|
/* must be done here, otherwise siglongjmp will clobber all the registers */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(Yap_matherror,TermNil,NULL);
|
2002-09-09 18:40:12 +01:00
|
|
|
/* reset the registers so that we don't have trash in abstract machine */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_set_fpu_exceptions(yap_flags[LANGUAGE_MODE_FLAG] == 1);
|
2002-09-09 18:40:12 +01:00
|
|
|
P = (yamop *)FAILCODE;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
{ /* saved state */
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
/* do nothing */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-10-03 14:42:23 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2010-06-01 00:40:58 +01:00
|
|
|
Yap_CloseSlots();
|
2007-06-04 13:28:02 +01:00
|
|
|
out = Yap_absmi(0);
|
|
|
|
Yap_StartSlots();
|
2010-12-04 18:45:09 +00:00
|
|
|
/* make sure we don't leave a FAIL signal hanging around */
|
|
|
|
ActiveSignals &= ~YAP_FAIL_SIGNAL;
|
|
|
|
if (!ActiveSignals)
|
|
|
|
CreepFlag = CalculateStackGap();
|
2007-06-04 13:28:02 +01:00
|
|
|
return out;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-04 13:28:02 +01:00
|
|
|
static void
|
|
|
|
init_stack(int arity, CELL *pt, int top, choiceptr saved_b)
|
|
|
|
{
|
2001-04-09 20:54:03 +01:00
|
|
|
/* create an initial pseudo environment so that when garbage
|
|
|
|
collection is going up in the environment chain it doesn't get
|
|
|
|
confused */
|
2010-07-21 12:49:06 +01:00
|
|
|
EX = NULL;
|
2004-06-05 04:37:01 +01:00
|
|
|
// sl = Yap_InitSlot(t);
|
2001-04-09 20:54:03 +01:00
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CP] = (CELL)P;
|
|
|
|
YENV[E_CB] = (CELL)B;
|
|
|
|
YENV[E_E] = (CELL)ENV;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
YENV[E_DEPTH] = DEPTH;
|
|
|
|
#endif
|
|
|
|
ENV = YENV;
|
|
|
|
ASP -= EnvSizeInCells;
|
|
|
|
/* and now create a pseudo choicepoint for much the same reasons */
|
2002-05-14 19:24:34 +01:00
|
|
|
/* CP = YESCODE; */
|
|
|
|
/* keep a place where you can inform you had an exception */
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
XREGS[i+1] = *pt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
B = (choiceptr)ASP;
|
|
|
|
B--;
|
|
|
|
B->cp_h = H;
|
|
|
|
B->cp_tr = TR;
|
|
|
|
B->cp_cp = CP;
|
2002-05-14 19:24:34 +01:00
|
|
|
B->cp_ap = NOCODE;
|
2001-04-09 20:54:03 +01:00
|
|
|
B->cp_env = ENV;
|
|
|
|
B->cp_b = saved_b;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
B->cp_depth = DEPTH;
|
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
YENV = ASP = (CELL *)B;
|
|
|
|
HB = H;
|
2004-02-20 18:56:07 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
WPP = NULL;
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
YENV[E_CB] = Unsigned (B);
|
2002-06-18 03:27:53 +01:00
|
|
|
CP = YESCODE;
|
2010-06-01 00:40:58 +01:00
|
|
|
Yap_StartSlots();
|
2007-06-04 13:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Term
|
|
|
|
do_goal(Term t, yamop *CodeAdr, int arity, CELL *pt, int top)
|
|
|
|
{
|
|
|
|
choiceptr saved_b = B;
|
|
|
|
Term out = 0L;
|
|
|
|
|
|
|
|
init_stack(arity, pt, top, saved_b);
|
|
|
|
P = (yamop *) CodeAdr;
|
|
|
|
S = CellPtr (RepPredProp (PredPropByFunc (Yap_MkFunctor(AtomCall, 1),0))); /* A1 mishaps */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-06-05 04:37:01 +01:00
|
|
|
out = exec_absmi(top);
|
|
|
|
// if (out) {
|
|
|
|
// out = Yap_GetFromSlot(sl);
|
|
|
|
// }
|
|
|
|
// Yap_RecoverSlots(1);
|
|
|
|
return out;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exec_absmi(int top)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
return exec_absmi(top);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
Int
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_execute_goal(Term t, int nargs, Term mod)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int out;
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *CodeAdr;
|
2001-04-09 20:54:03 +01:00
|
|
|
yamop *saved_p, *saved_cp;
|
|
|
|
Prop pe;
|
|
|
|
PredEntry *ppe;
|
|
|
|
CELL *pt;
|
|
|
|
/* preserve the current restart environment */
|
|
|
|
/* visualc*/
|
|
|
|
/* just keep the difference because of possible garbage collections */
|
|
|
|
|
|
|
|
|
|
|
|
saved_p = P;
|
|
|
|
saved_cp = CP;
|
|
|
|
|
|
|
|
if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom a = AtomOfTerm(t);
|
2001-04-09 20:54:03 +01:00
|
|
|
pt = NULL;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByAtom(a, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
|
|
|
|
if (IsBlobFunctor(f)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
|
|
|
pt = RepAppl(t)+1;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(f, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
ppe = RepPredProp(pe);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (pe == NIL) {
|
|
|
|
return(CallMetaCall(mod));
|
2001-10-03 14:39:16 +01:00
|
|
|
}
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(81,ppe);
|
2001-10-03 14:39:16 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
CodeAdr = RepPredProp (pe)->CodeOfPred;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(ppe->PELock);
|
2004-06-05 04:37:01 +01:00
|
|
|
out = do_goal(t, CodeAdr, 0, pt, FALSE);
|
2001-10-03 14:39:16 +01:00
|
|
|
} else {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
2001-11-15 00:01:43 +00:00
|
|
|
CodeAdr = RepPredProp (pe)->CodeOfPred;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(ppe->PELock);
|
2004-06-05 04:37:01 +01:00
|
|
|
out = do_goal(t, CodeAdr, ArityOfFunctor(f), pt, FALSE);
|
2001-10-03 14:39:16 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (out == 1) {
|
2005-04-07 18:56:58 +01:00
|
|
|
choiceptr cut_B, old_B;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we succeeded, let's prune */
|
|
|
|
/* restore the old environment */
|
|
|
|
/* get to previous environment */
|
2005-04-07 18:56:58 +01:00
|
|
|
cut_B = (choiceptr)ENV[E_CB];
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
{
|
|
|
|
/* Note that
|
|
|
|
cut_B == (choiceptr)ENV[E_CB] */
|
|
|
|
while (POP_CHOICE_POINT(ENV[E_CB]))
|
|
|
|
{
|
|
|
|
POP_EXECUTE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CUT_C */
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2005-04-07 18:56:58 +01:00
|
|
|
CUT_prune_to(cut_B);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
2002-05-03 16:30:36 +01:00
|
|
|
#ifdef TABLING
|
2005-04-07 18:56:58 +01:00
|
|
|
if (B != cut_B) {
|
|
|
|
while (B->cp_b < cut_B) {
|
|
|
|
B = B->cp_b;
|
|
|
|
}
|
|
|
|
abolish_incomplete_subgoals(B);
|
|
|
|
}
|
2002-05-03 16:30:36 +01:00
|
|
|
#endif /* TABLING */
|
2005-04-07 18:56:58 +01:00
|
|
|
B = cut_B;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* find out where we have the old arguments */
|
|
|
|
old_B = ((choiceptr)(ENV-(EnvSizeInCells+nargs+1)))-1;
|
|
|
|
CP = saved_cp;
|
|
|
|
P = saved_p;
|
|
|
|
ASP = ENV;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH= ENV[E_DEPTH];
|
|
|
|
#endif
|
2002-05-14 19:24:34 +01:00
|
|
|
ENV = (CELL *)(ENV[E_E]);
|
2010-06-18 00:25:24 +01:00
|
|
|
Yap_StartSlots();
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we have failed, and usually we would backtrack to this B,
|
|
|
|
trouble is, we may also have a delayed cut to do */
|
2002-05-14 19:24:34 +01:00
|
|
|
if (B != NULL)
|
|
|
|
HB = B->cp_h;
|
2001-04-09 20:54:03 +01:00
|
|
|
YENV = ENV;
|
|
|
|
return(TRUE);
|
|
|
|
} else if (out == 0) {
|
|
|
|
ASP = B->cp_env;
|
|
|
|
P = saved_p;
|
|
|
|
CP = saved_cp;
|
|
|
|
H = B->cp_h;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH= B->cp_depth;
|
|
|
|
#endif
|
2002-10-17 01:05:29 +01:00
|
|
|
/* ASP should be set to the top of the local stack when we
|
|
|
|
did the call */
|
|
|
|
ASP = B->cp_env;
|
|
|
|
/* YENV should be set to the current environment */
|
|
|
|
YENV = ENV = (CELL *)((B->cp_env)[E_E]);
|
2001-04-09 20:54:03 +01:00
|
|
|
B = B->cp_b;
|
|
|
|
SET_BB(B);
|
|
|
|
HB = PROTECT_FROZEN_H(B);
|
|
|
|
return(FALSE);
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,"emulator crashed");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-14 19:24:34 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_trust_last(void)
|
2002-05-14 19:24:34 +01:00
|
|
|
{
|
|
|
|
ASP = B->cp_env;
|
|
|
|
CP = B->cp_cp;
|
|
|
|
H = B->cp_h;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH= B->cp_depth;
|
|
|
|
#endif
|
|
|
|
YENV= ASP = B->cp_env;
|
|
|
|
ENV = (CELL *)((B->cp_env)[E_E]);
|
|
|
|
B = B->cp_b;
|
2010-06-01 00:40:58 +01:00
|
|
|
P = (yamop *)(ENV[E_CP]);
|
2002-05-14 19:24:34 +01:00
|
|
|
if (B) {
|
|
|
|
SET_BB(B);
|
|
|
|
HB = PROTECT_FROZEN_H(B);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-05 04:37:01 +01:00
|
|
|
Term
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_RunTopGoal(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *CodeAdr;
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
PredEntry *ppe;
|
|
|
|
CELL *pt;
|
2001-10-03 14:39:16 +01:00
|
|
|
UInt arity;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = CurrentModule;
|
2004-06-05 04:37:01 +01:00
|
|
|
Term goal_out = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-05-14 19:24:34 +01:00
|
|
|
restart_runtopgoal:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom a = AtomOfTerm(t);
|
2001-04-09 20:54:03 +01:00
|
|
|
pt = NULL;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByAtom(a, CurrentModule);
|
2001-10-03 14:39:16 +01:00
|
|
|
arity = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
|
|
|
|
if (IsBlobFunctor(f)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-05-14 19:24:34 +01:00
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = tmod;
|
2002-05-14 19:24:34 +01:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_runtopgoal;
|
2009-05-08 04:14:28 +01:00
|
|
|
} else {
|
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"call/1");
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t,"call/1");
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-05-14 19:24:34 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
2008-08-19 14:33:45 +01:00
|
|
|
pe = PredPropByFunc(f, CurrentModule);
|
2001-04-09 20:54:03 +01:00
|
|
|
pt = RepAppl(t)+1;
|
2001-10-03 14:39:16 +01:00
|
|
|
arity = ArityOfFunctor(f);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
ppe = RepPredProp(pe);
|
2004-02-26 13:37:24 +00:00
|
|
|
if (pe == NIL) {
|
2002-06-18 03:27:53 +01:00
|
|
|
/* we must always start the emulator with Prolog code */
|
2004-02-26 13:37:24 +00:00
|
|
|
return FALSE;
|
2002-06-18 03:27:53 +01:00
|
|
|
}
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(82,ppe);
|
2004-02-22 00:35:07 +00:00
|
|
|
CodeAdr = ppe->CodeOfPred;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(ppe->PELock);
|
2005-11-17 13:40:18 +00:00
|
|
|
#if !USE_SYSTEM_MALLOC
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_TrailTop - HeapTop < 2048) {
|
|
|
|
Yap_PrologMode = BootMode;
|
2004-11-19 22:08:43 +00:00
|
|
|
Yap_Error(OUT_OF_TRAIL_ERROR,TermNil,
|
2005-04-10 05:01:15 +01:00
|
|
|
"unable to boot because of too little Trail space");
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-08-11 17:14:55 +01:00
|
|
|
#endif
|
2004-06-05 04:37:01 +01:00
|
|
|
goal_out = do_goal(t, CodeAdr, arity, pt, TRUE);
|
2002-06-18 03:27:53 +01:00
|
|
|
return(goal_out);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
restore_regs(Term t)
|
|
|
|
{
|
|
|
|
if (IsApplTerm(t)) {
|
|
|
|
Int i;
|
|
|
|
Int max = ArityOfFunctor(FunctorOfTerm(t));
|
|
|
|
CELL *ptr = RepAppl(t)+1;
|
|
|
|
|
|
|
|
for (i = 0; i < max; i += 2) {
|
|
|
|
Int j = IntOfTerm(ptr[0]);
|
|
|
|
XREGS[j] = ptr[1];
|
|
|
|
ptr+=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* low level voodoo to restore temporary registers after a call */
|
|
|
|
static Int
|
|
|
|
p_restore_regs(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"support for coroutining");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsAtomTerm(t)) return(TRUE);
|
|
|
|
restore_regs(t);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* low level voodoo to cut and then restore temporary registers after a call */
|
|
|
|
static Int
|
|
|
|
p_restore_regs2(void)
|
|
|
|
{
|
2002-04-06 06:33:44 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t = Deref(ARG1), d0;
|
|
|
|
choiceptr pt0;
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"support for coroutining");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-07-17 21:25:30 +01:00
|
|
|
d0 = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsAtomTerm(t)) {
|
|
|
|
restore_regs(t);
|
|
|
|
}
|
|
|
|
if (IsVarTerm(d0)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,d0,"support for coroutining");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntegerTerm(d0)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
#if SBA
|
|
|
|
pt0 = (choiceptr)IntegerOfTerm(d0);
|
|
|
|
#else
|
|
|
|
pt0 = (choiceptr)(LCL0-IntOfTerm(d0));
|
|
|
|
#endif
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
{
|
|
|
|
while (POP_CHOICE_POINT(pt0))
|
|
|
|
{
|
|
|
|
POP_EXECUTE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CUT_C */
|
2005-04-07 18:56:58 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
CUT_prune_to(pt0);
|
|
|
|
#endif /* YAPOR */
|
2001-04-09 20:54:03 +01:00
|
|
|
/* find where to cut to */
|
|
|
|
if (pt0 > B) {
|
|
|
|
/* Wow, we're gonna cut!!! */
|
2002-05-03 16:30:36 +01:00
|
|
|
#ifdef TABLING
|
2005-04-07 18:56:58 +01:00
|
|
|
while (B->cp_b < pt0) {
|
|
|
|
B = B->cp_b;
|
|
|
|
}
|
2002-05-03 16:30:36 +01:00
|
|
|
abolish_incomplete_subgoals(B);
|
|
|
|
#endif /* TABLING */
|
2005-04-07 18:56:58 +01:00
|
|
|
B = pt0;
|
2001-04-09 20:54:03 +01:00
|
|
|
HB = B->cp_h;
|
2008-06-04 15:47:18 +01:00
|
|
|
Yap_TrimTrail();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2001-04-24 17:40:11 +01:00
|
|
|
static Int
|
|
|
|
p_clean_ifcp(void) {
|
2008-02-12 17:03:59 +00:00
|
|
|
Term t = Deref(ARG1);
|
2009-04-25 16:58:42 +01:00
|
|
|
choiceptr pt0;
|
|
|
|
|
2008-02-12 17:03:59 +00:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t, "cut_at/1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!IsIntegerTerm(t)) {
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t, "cut_at/1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-24 17:40:11 +01:00
|
|
|
#if SBA
|
2009-04-25 16:58:42 +01:00
|
|
|
pt0 = (choiceptr)IntegerOfTerm(t);
|
2001-04-24 17:40:11 +01:00
|
|
|
#else
|
2009-04-25 16:58:42 +01:00
|
|
|
pt0 = cp_from_integer(t);
|
2001-04-24 17:40:11 +01:00
|
|
|
#endif
|
2008-02-12 17:03:59 +00:00
|
|
|
if (pt0 < B) {
|
|
|
|
/* this should never happen */
|
|
|
|
return TRUE;
|
|
|
|
} else if (pt0 == B) {
|
2001-04-27 17:02:43 +01:00
|
|
|
B = B->cp_b;
|
|
|
|
HB = B->cp_h;
|
|
|
|
} else {
|
|
|
|
pt0->cp_ap = (yamop *)TRUSTFAILCODE;
|
|
|
|
}
|
2008-02-12 17:03:59 +00:00
|
|
|
return TRUE;
|
2001-04-24 17:40:11 +01:00
|
|
|
}
|
|
|
|
|
2003-01-29 14:47:17 +00:00
|
|
|
|
2006-07-27 20:04:56 +01:00
|
|
|
|
|
|
|
static int disj_marker(yamop *apc) {
|
|
|
|
op_numbers opnum = Yap_op_from_opcode(apc->opc);
|
|
|
|
|
|
|
|
return opnum == _or_else || opnum == _or_last;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_cut_up_to_next_disjunction(void) {
|
|
|
|
choiceptr pt0 = B;
|
|
|
|
CELL *qenv = (CELL *)ENV[E_E];
|
|
|
|
|
|
|
|
while (pt0 &&
|
2006-08-01 14:14:17 +01:00
|
|
|
!( qenv == pt0->cp_env && disj_marker(pt0->cp_ap))) {
|
2006-07-27 20:04:56 +01:00
|
|
|
pt0 = pt0->cp_b;
|
|
|
|
}
|
|
|
|
if (!pt0)
|
|
|
|
return TRUE;
|
|
|
|
#ifdef YAPOR
|
|
|
|
CUT_prune_to(pt0);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
/* find where to cut to */
|
|
|
|
if (SHOULD_CUT_UP_TO(B,pt0)) {
|
|
|
|
B = pt0;
|
|
|
|
#ifdef TABLING
|
|
|
|
abolish_incomplete_subgoals(B);
|
|
|
|
#endif /* TABLING */
|
|
|
|
}
|
2008-06-04 15:47:18 +01:00
|
|
|
HB = B->cp_h;
|
|
|
|
Yap_TrimTrail();
|
2006-07-27 20:04:56 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-11-27 11:21:24 +00:00
|
|
|
static int is_cleanup_cp(choiceptr cp_b)
|
2009-05-05 00:12:33 +01:00
|
|
|
{
|
2009-11-27 11:21:24 +00:00
|
|
|
PredEntry *pe;
|
2009-05-05 00:12:33 +01:00
|
|
|
|
2009-11-27 11:21:24 +00:00
|
|
|
if (cp_b->cp_ap->opc != ORLAST_OPCODE)
|
|
|
|
return FALSE;
|
|
|
|
#ifdef YAPOR
|
2010-01-14 15:58:19 +00:00
|
|
|
pe = cp_b->cp_ap->u.Osblp.p0;
|
2009-05-05 00:12:33 +01:00
|
|
|
#else
|
2009-11-27 11:21:24 +00:00
|
|
|
pe = cp_b->cp_ap->u.p.p;
|
|
|
|
#endif /* YAPOR */
|
2009-12-03 02:13:22 +00:00
|
|
|
/*
|
|
|
|
it has to be a cleanup and it has to be a completed goal,
|
|
|
|
otherwise the throw will be caught anyway.
|
|
|
|
*/
|
|
|
|
return pe == PredSafeCallCleanup;
|
2009-05-05 00:12:33 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Int
|
2002-01-29 05:37:31 +00:00
|
|
|
JumpToEnv(Term t) {
|
2004-09-27 21:45:04 +01:00
|
|
|
yamop *pos = NEXTOP(PredDollarCatch->cs.p_code.TrueCodeOfPred,l),
|
|
|
|
*catchpos = NEXTOP(PredHandleThrow->cs.p_code.TrueCodeOfPred,l);
|
2009-11-27 11:21:24 +00:00
|
|
|
CELL *env, *env1;
|
|
|
|
choiceptr handler, previous = NULL;
|
2002-01-30 03:49:50 +00:00
|
|
|
|
2009-11-27 11:21:24 +00:00
|
|
|
/* throws cannot interrupt throws */
|
|
|
|
if (EX)
|
|
|
|
return FALSE;
|
|
|
|
/* just keep the throwed object away, we don't need to care about it */
|
2009-12-02 21:59:41 +00:00
|
|
|
if (!(BallTerm = Yap_StoreTermInDB(t, 0))) {
|
2009-11-27 11:21:24 +00:00
|
|
|
/* fat chance */
|
|
|
|
siglongjmp(Yap_RestartEnv,1);
|
2009-06-12 20:35:15 +01:00
|
|
|
}
|
2009-11-27 11:21:24 +00:00
|
|
|
/* careful, previous step may have caused a stack shift,
|
|
|
|
so get pointers here */
|
|
|
|
handler = B;
|
|
|
|
env1 = ENV;
|
2002-01-30 03:49:50 +00:00
|
|
|
do {
|
|
|
|
/* find the first choicepoint that may be a catch */
|
2009-11-27 11:21:24 +00:00
|
|
|
while (handler != NULL && handler->cp_ap != pos) {
|
2002-04-03 20:33:38 +01:00
|
|
|
/* we are already doing a catch */
|
2009-11-27 11:21:24 +00:00
|
|
|
if (handler->cp_ap == catchpos) {
|
2002-04-03 20:33:38 +01:00
|
|
|
P = (yamop *)FAILCODE;
|
2009-11-27 11:21:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* we have a cleanup handler in the middle */
|
|
|
|
if (is_cleanup_cp(handler)) {
|
|
|
|
/* keep it around */
|
|
|
|
if (previous == NULL)
|
|
|
|
B = handler;
|
|
|
|
else
|
|
|
|
previous->cp_b = handler;
|
|
|
|
previous = handler;
|
|
|
|
#ifdef TABLING
|
|
|
|
} else {
|
2009-12-12 23:22:10 +00:00
|
|
|
if (handler->cp_ap != NOCODE) {
|
|
|
|
abolish_incomplete_subgoals(handler);
|
|
|
|
}
|
2009-11-27 11:21:24 +00:00
|
|
|
#endif /* TABLING */
|
2002-04-03 20:33:38 +01:00
|
|
|
}
|
2009-11-27 11:21:24 +00:00
|
|
|
/* we reached C-Code */
|
|
|
|
if (handler->cp_ap == NOCODE) {
|
2002-05-14 19:24:34 +01:00
|
|
|
/* up to the C-code to deal with this! */
|
2004-11-19 21:32:53 +00:00
|
|
|
UncaughtThrow = TRUE;
|
2009-11-27 11:21:24 +00:00
|
|
|
if (previous == NULL)
|
|
|
|
B = handler;
|
|
|
|
else
|
|
|
|
previous->cp_b = handler;
|
2010-07-21 12:49:06 +01:00
|
|
|
EX = BallTerm;
|
|
|
|
BallTerm = NULL;
|
2009-11-27 11:21:24 +00:00
|
|
|
P = (yamop *)FAILCODE;
|
2010-12-04 19:05:13 +00:00
|
|
|
/* make sure failure will be seen at next port */
|
|
|
|
if (Yap_PrologMode & AsyncIntMode) {
|
|
|
|
Yap_signal(YAP_FAIL_SIGNAL);
|
|
|
|
}
|
2009-11-27 11:21:24 +00:00
|
|
|
HB = B->cp_h;
|
|
|
|
return TRUE;
|
2002-05-14 19:24:34 +01:00
|
|
|
}
|
2009-11-27 11:21:24 +00:00
|
|
|
handler = handler->cp_b;
|
2002-01-30 03:49:50 +00:00
|
|
|
}
|
2002-04-11 16:31:58 +01:00
|
|
|
/* uncaught throw */
|
2009-11-27 11:21:24 +00:00
|
|
|
if (handler == NULL) {
|
2004-11-19 21:32:53 +00:00
|
|
|
UncaughtThrow = TRUE;
|
2002-10-08 15:32:42 +01:00
|
|
|
#if PUSH_REGS
|
2002-11-18 18:18:05 +00:00
|
|
|
restore_absmi_regs(&Yap_standard_regs);
|
2002-10-08 15:32:42 +01:00
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
siglongjmp(Yap_RestartEnv,1);
|
2002-04-11 16:31:58 +01:00
|
|
|
}
|
2002-01-30 03:49:50 +00:00
|
|
|
/* is it a continuation? */
|
2009-11-27 11:21:24 +00:00
|
|
|
env = handler->cp_env;
|
|
|
|
while (env > env1) {
|
|
|
|
env1 = ENV_Parent(env1);
|
2009-05-05 00:12:33 +01:00
|
|
|
}
|
2002-01-30 03:49:50 +00:00
|
|
|
/* yes, we found it ! */
|
2009-05-05 00:12:33 +01:00
|
|
|
// while (env < ENV)
|
|
|
|
// env = ENV_Parent(env);
|
2009-11-27 11:21:24 +00:00
|
|
|
if (env == env1) {
|
2009-05-05 00:12:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2002-01-30 03:49:50 +00:00
|
|
|
/* oops, try next */
|
2009-11-27 11:21:24 +00:00
|
|
|
handler = handler->cp_b;
|
2002-01-30 03:49:50 +00:00
|
|
|
} while (TRUE);
|
2009-05-05 00:12:33 +01:00
|
|
|
/* step one environment above, otherwise we'll redo the original goal */
|
2009-11-27 11:21:24 +00:00
|
|
|
if (previous == NULL) {
|
|
|
|
B = handler;
|
|
|
|
} else {
|
|
|
|
// EX = t;
|
|
|
|
previous->cp_b = handler;
|
|
|
|
}
|
|
|
|
handler->cp_cp = (yamop *)env[E_CP];
|
|
|
|
handler->cp_env = (CELL *)env[E_E];
|
|
|
|
handler->cp_ap = NEXTOP(PredHandleThrow->CodeOfPred,l);
|
2009-05-23 03:51:48 +01:00
|
|
|
/* can recover Heap thanks to copy term :-( */
|
2009-06-14 17:17:12 +01:00
|
|
|
/* B->cp_h = H; */
|
2002-01-24 23:55:34 +00:00
|
|
|
/* I could backtrack here, but it is easier to leave the unwinding
|
|
|
|
to the emulator */
|
2010-12-04 19:05:13 +00:00
|
|
|
if (Yap_PrologMode & AsyncIntMode) {
|
|
|
|
Yap_signal(YAP_FAIL_SIGNAL);
|
|
|
|
}
|
2002-02-04 16:12:54 +00:00
|
|
|
P = (yamop *)FAILCODE;
|
2009-11-27 11:21:24 +00:00
|
|
|
HB = B->cp_h;
|
2009-06-14 17:17:12 +01:00
|
|
|
/* try to recover space */
|
2009-11-17 10:03:14 +00:00
|
|
|
/* can only do that when we recover space */
|
2009-11-27 11:21:24 +00:00
|
|
|
/* first, simulate backtracking */
|
2009-05-05 00:12:33 +01:00
|
|
|
/* so that I will execute op_fail */
|
|
|
|
return TRUE;
|
2001-12-14 19:03:29 +00:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_JumpToEnv(Term t) {
|
2005-03-02 18:35:49 +00:00
|
|
|
if (Yap_PrologMode & BootMode) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-11-11 17:38:10 +00:00
|
|
|
return JumpToEnv(t);
|
|
|
|
}
|
2002-01-24 23:55:34 +00:00
|
|
|
|
2002-01-29 05:37:31 +00:00
|
|
|
|
|
|
|
/* This does very nasty stuff!!!!! */
|
|
|
|
static Int
|
|
|
|
p_jump_env(void) {
|
|
|
|
return(JumpToEnv(Deref(ARG1)));
|
|
|
|
}
|
|
|
|
|
2003-01-29 14:47:17 +00:00
|
|
|
/* set up a meta-call based on . context info */
|
|
|
|
static Int
|
|
|
|
p_generate_pred_info(void) {
|
|
|
|
ARG1 = ARG3 = ENV[-EnvSizeInCells-1];
|
2004-02-12 12:37:12 +00:00
|
|
|
ARG4 = ENV[-EnvSizeInCells-3];
|
2003-01-29 14:47:17 +00:00
|
|
|
ARG2 = cp_as_integer((choiceptr)ENV[E_CB]);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitYaamRegs(void)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2006-08-22 17:12:46 +01:00
|
|
|
Term h0var;
|
2004-01-23 02:23:51 +00:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if PUSH_REGS
|
|
|
|
/* Guarantee that after a longjmp we go back to the original abstract
|
|
|
|
machine registers */
|
2004-01-23 02:23:51 +00:00
|
|
|
#ifdef THREADS
|
|
|
|
int myworker_id = worker_id;
|
2010-03-21 22:12:42 +00:00
|
|
|
pthread_setspecific(Yap_yaamregs_key, (const void *)FOREIGN_ThreadHandle(myworker_id).default_yaam_regs);
|
|
|
|
FOREIGN_ThreadHandle(myworker_id).current_yaam_regs = FOREIGN_ThreadHandle(myworker_id).default_yaam_regs;
|
2004-01-23 02:23:51 +00:00
|
|
|
worker_id = myworker_id;
|
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_regp = &Yap_standard_regs;
|
2004-01-23 02:23:51 +00:00
|
|
|
#endif
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif /* PUSH_REGS */
|
2009-12-03 17:48:25 +00:00
|
|
|
Yap_ResetExceptionTerm ();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue (AtomBreak, MkIntTerm (0));
|
|
|
|
TR = (tr_fr_ptr)Yap_TrailBase;
|
2009-03-27 15:15:54 +00:00
|
|
|
if (Yap_AttsSize > (Yap_LocalBase-Yap_GlobalBase)/8)
|
|
|
|
Yap_AttsSize = (Yap_LocalBase-Yap_GlobalBase)/8;
|
|
|
|
H = H0 = ((CELL *) Yap_GlobalBase)+ Yap_AttsSize/sizeof(CELL);
|
2002-11-18 18:18:05 +00:00
|
|
|
LCL0 = ASP = (CELL *) Yap_LocalBase;
|
2002-11-11 17:38:10 +00:00
|
|
|
/* notice that an initial choice-point and environment
|
|
|
|
*must* be created since for the garbage collector to work */
|
|
|
|
B = NULL;
|
|
|
|
ENV = NULL;
|
|
|
|
P = CP = YESCODE;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH = RESET_DEPTH();
|
|
|
|
#endif
|
|
|
|
STATIC_PREDICATES_MARKED = FALSE;
|
|
|
|
#ifdef FROZEN_STACKS
|
2009-05-01 18:09:49 +01:00
|
|
|
H_FZ = H;
|
2002-11-11 17:38:10 +00:00
|
|
|
#ifdef SBA
|
|
|
|
BSEG =
|
|
|
|
#endif /* SBA */
|
2010-03-12 20:02:32 +00:00
|
|
|
BBREG = B_FZ = (choiceptr) Yap_LocalBase;
|
|
|
|
TR = TR_FZ = (tr_fr_ptr) Yap_TrailBase;
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif /* FROZEN_STACKS */
|
2004-02-06 17:22:24 +00:00
|
|
|
LOCK(SignalLock);
|
2002-11-11 17:38:10 +00:00
|
|
|
CreepFlag = CalculateStackGap();
|
2004-02-06 17:22:24 +00:00
|
|
|
UNLOCK(SignalLock);
|
2010-07-21 12:49:06 +01:00
|
|
|
EX = NULL;
|
2008-01-23 17:57:56 +00:00
|
|
|
init_stack(0, NULL, TRUE, NULL);
|
|
|
|
/* the first real choice-point will also have AP=FAIL */
|
2010-06-01 00:40:58 +01:00
|
|
|
CurSlot = 0;
|
2007-05-14 17:44:12 +01:00
|
|
|
GlobalArena = TermNil;
|
2006-08-22 17:12:46 +01:00
|
|
|
h0var = MkVarTerm();
|
2007-10-05 19:24:30 +01:00
|
|
|
#if COROUTINING
|
2002-11-18 18:18:05 +00:00
|
|
|
WokenGoals = Yap_NewTimedVar(TermNil);
|
2006-08-22 17:12:46 +01:00
|
|
|
AttsMutableList = Yap_NewTimedVar(h0var);
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif
|
2007-10-05 19:24:30 +01:00
|
|
|
GcGeneration = Yap_NewTimedVar(h0var);
|
2006-03-06 14:04:57 +00:00
|
|
|
GcCurrentPhase = 0L;
|
|
|
|
GcPhase = Yap_NewTimedVar(MkIntTerm(GcCurrentPhase));
|
2004-02-11 13:33:19 +00:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
PP = NULL;
|
|
|
|
WPP = NULL;
|
|
|
|
PREG_ADDR = NULL;
|
|
|
|
#endif
|
2009-05-17 17:41:34 +01:00
|
|
|
Yap_AllocateDefaultArena(128*1024, 2);
|
2009-05-23 00:35:24 +01:00
|
|
|
Yap_InitPreAllocCodeSpace();
|
2006-01-17 22:54:02 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
cut_c_initialize();
|
|
|
|
#endif
|
2006-06-06 15:11:36 +01:00
|
|
|
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
|
|
|
Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL;
|
2006-01-17 22:54:02 +00:00
|
|
|
#endif
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
2002-01-29 05:37:31 +00:00
|
|
|
|
2004-11-19 21:32:53 +00:00
|
|
|
static Int
|
|
|
|
p_uncaught_throw(void)
|
|
|
|
{
|
|
|
|
Int out = UncaughtThrow;
|
|
|
|
UncaughtThrow = FALSE; /* just caught it */
|
|
|
|
return out;
|
|
|
|
}
|
2003-01-29 14:47:17 +00:00
|
|
|
|
2008-08-30 02:39:36 +01:00
|
|
|
static Int
|
|
|
|
p_creep_allowed(void)
|
|
|
|
{
|
2008-09-02 03:48:02 +01:00
|
|
|
if (PP != NULL) {
|
|
|
|
LOCK(SignalLock);
|
2009-05-21 06:39:14 +01:00
|
|
|
if (ActiveSignals & YAP_CREEP_SIGNAL && !Yap_InterruptsDisabled) {
|
2008-09-02 03:48:02 +01:00
|
|
|
ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
|
|
|
if (!ActiveSignals)
|
|
|
|
CreepFlag = CalculateStackGap();
|
|
|
|
UNLOCK(SignalLock);
|
|
|
|
} else {
|
|
|
|
UNLOCK(SignalLock);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_debug_on(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
if (DebugOn)
|
|
|
|
return Yap_unify(MkAtomTerm(AtomTrue),ARG1);
|
|
|
|
else
|
|
|
|
return Yap_unify(MkAtomTerm(AtomFalse),ARG1);
|
|
|
|
}
|
|
|
|
if (t == MkAtomTerm(AtomTrue))
|
|
|
|
DebugOn = TRUE;
|
|
|
|
else
|
|
|
|
DebugOn = FALSE;
|
|
|
|
return TRUE;
|
2008-08-30 02:39:36 +01:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:59:41 +00:00
|
|
|
static Term
|
|
|
|
GetException(void)
|
|
|
|
{
|
|
|
|
Term t = 0L;
|
|
|
|
if (BallTerm) {
|
|
|
|
do {
|
|
|
|
t = Yap_PopTermFromDB(BallTerm);
|
|
|
|
if (t == 0) {
|
|
|
|
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
|
|
|
Yap_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_growglobal(NULL)) {
|
|
|
|
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_Error_TYPE = YAP_NO_ERROR;
|
|
|
|
if (!Yap_growstack(BallTerm->NOfCells*CellSize)) {
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (t == 0);
|
|
|
|
BallTerm = NULL;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-11-27 11:21:24 +00:00
|
|
|
static Int
|
|
|
|
p_reset_exception(void)
|
|
|
|
{
|
2009-12-02 21:59:41 +00:00
|
|
|
Term t;
|
2010-07-21 12:49:06 +01:00
|
|
|
EX = NULL;
|
2009-12-02 21:59:41 +00:00
|
|
|
t = GetException();
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
return Yap_unify(t, ARG1);
|
|
|
|
}
|
|
|
|
|
2009-12-03 17:48:25 +00:00
|
|
|
void
|
|
|
|
Yap_ResetExceptionTerm(void)
|
|
|
|
{
|
|
|
|
Yap_ReleaseTermFromDB(BallTerm);
|
|
|
|
BallTerm = NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:59:41 +00:00
|
|
|
static Int
|
|
|
|
p_get_exception(void)
|
|
|
|
{
|
|
|
|
Term t = GetException();
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
return Yap_unify(t, ARG1);
|
2009-11-27 11:21:24 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitExecFs(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2006-12-27 01:32:38 +00:00
|
|
|
Term cm = CurrentModule;
|
2003-01-29 14:47:17 +00:00
|
|
|
Yap_InitComma();
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$execute", 1, p_execute, HiddenPredFlag);
|
2005-10-28 18:38:50 +01:00
|
|
|
Yap_InitCPred("$execute", 2, p_execute2, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 3, p_execute3, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 4, p_execute4, HiddenPredFlag);
|
2006-12-31 12:29:46 +00:00
|
|
|
Yap_InitCPred("$execute", 5, p_execute5, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 6, p_execute6, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 7, p_execute7, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 8, p_execute8, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 9, p_execute9, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 10, p_execute10, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 11, p_execute11, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute", 12, p_execute12, HiddenPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$execute_in_mod", 2, p_execute_in_mod, HiddenPredFlag);
|
2007-11-07 09:25:27 +00:00
|
|
|
Yap_InitCPred("$execute_wo_mod", 2, p_execute_in_mod, HiddenPredFlag);
|
2009-03-13 11:11:04 +00:00
|
|
|
Yap_InitCPred("call_with_args", 1, p_execute_0, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 2, p_execute_1, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 3, p_execute_2, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 4, p_execute_3, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 5, p_execute_4, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 6, p_execute_5, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 7, p_execute_6, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 8, p_execute_7, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 9, p_execute_8, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 10, p_execute_9, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("call_with_args", 11, p_execute_10, HiddenPredFlag);
|
2008-09-02 03:48:02 +01:00
|
|
|
Yap_InitCPred("$debug_on", 1, p_debug_on, HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEPTH_LIMIT
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$execute_under_depth_limit", 2, p_execute_depth_limit, HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$execute0", 2, p_execute0, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$execute_nonstop", 2, p_execute_nonstop, HiddenPredFlag);
|
2005-08-02 04:09:52 +01:00
|
|
|
Yap_InitCPred("$execute_clause", 4, p_execute_clause, HiddenPredFlag);
|
2006-12-27 01:32:38 +00:00
|
|
|
CurrentModule = HACKS_MODULE;
|
|
|
|
Yap_InitCPred("current_choice_point", 1, p_save_cp, HiddenPredFlag);
|
2008-02-12 17:03:59 +00:00
|
|
|
Yap_InitCPred("current_choicepoint", 1, p_save_cp, HiddenPredFlag);
|
2006-12-27 01:32:38 +00:00
|
|
|
Yap_InitCPred("env_choice_point", 1, p_save_env_b, HiddenPredFlag);
|
2006-12-30 03:25:47 +00:00
|
|
|
Yap_InitCPred("trail_suspension_marker", 1, p_trail_suspension_marker, HiddenPredFlag);
|
2008-02-12 17:03:59 +00:00
|
|
|
Yap_InitCPred("cut_at", 1, p_clean_ifcp, SafePredFlag);
|
2006-12-27 01:32:38 +00:00
|
|
|
CurrentModule = cm;
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$pred_goal_expansion_on", 0, p_pred_goal_expansion_on, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$restore_regs", 1, p_restore_regs, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$restore_regs", 2, p_restore_regs2, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$clean_ifcp", 1, p_clean_ifcp, SafePredFlag|HiddenPredFlag);
|
2006-07-27 20:04:56 +01:00
|
|
|
Yap_InitCPred("qpack_clean_up_to_disjunction", 0, p_cut_up_to_next_disjunction, SafePredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$jump_env_and_store_ball", 1, p_jump_env, HiddenPredFlag);
|
2008-08-30 02:39:36 +01:00
|
|
|
Yap_InitCPred("$creep_allowed", 0, p_creep_allowed, HiddenPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, HiddenPredFlag);
|
2004-11-19 21:32:53 +00:00
|
|
|
Yap_InitCPred("$uncaught_throw", 0, p_uncaught_throw, HiddenPredFlag);
|
2009-12-02 21:59:41 +00:00
|
|
|
Yap_InitCPred("$reset_exception", 1, p_reset_exception, HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$get_exception", 1, p_get_exception, HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2005-02-08 18:47:42 +00:00
|
|
|
|