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"
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
STATIC_PROTO(Int CallPredicate, (PredEntry *, choiceptr));
|
|
|
|
STATIC_PROTO(Int CallClause, (PredEntry *, unsigned int, Int));
|
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));
|
|
|
|
STATIC_PROTO(Int p_at_execute, (void));
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
static Term
|
|
|
|
current_cp_as_integer(void)
|
|
|
|
{
|
|
|
|
return(MkIntTerm(LCL0-(CELL *)B));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Int
|
|
|
|
CallPredicate(PredEntry *pen, choiceptr cut_pt) {
|
|
|
|
WRITE_LOCK(pen->PRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */
|
|
|
|
if (pen->ModuleOfPred) {
|
|
|
|
if (DEPTH == MkIntTerm(0))
|
|
|
|
return(FALSE);
|
|
|
|
else DEPTH = RESET_DEPTH();
|
|
|
|
}
|
|
|
|
} else if (pen->ModuleOfPred)
|
|
|
|
DEPTH -= MkIntConstant(2);
|
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
if (do_low_level_trace)
|
|
|
|
low_level_trace(enter_pred,pen,XREGS+1);
|
|
|
|
#endif /* LOW_LEVEL_TRACE */
|
|
|
|
CP = P;
|
|
|
|
P = (yamop *)(pen->CodeOfPred);
|
|
|
|
WRITE_UNLOCK(pen->PRWLock);
|
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
2001-10-30 16:42:05 +00:00
|
|
|
YENV[E_CB] = (CELL) cut_pt;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Int
|
2001-11-15 00:01:43 +00:00
|
|
|
CallMetaCall(SMALLUNSGN mod) {
|
2001-10-30 16:42:05 +00:00
|
|
|
ARG2 = current_cp_as_integer(); /* p_save_cp */
|
|
|
|
ARG3 = ARG1;
|
2001-11-15 00:01:43 +00:00
|
|
|
ARG4 = ModuleName[mod];
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(PredMetaCall, B));
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2001-11-15 00:01:43 +00:00
|
|
|
ExecuteCallMetaCall(SMALLUNSGN mod) {
|
|
|
|
Term ts[4];
|
2001-10-30 16:42:05 +00:00
|
|
|
ts[0] = ARG1;
|
|
|
|
ts[1] = current_cp_as_integer(); /* p_save_cp */
|
|
|
|
ts[2] = ARG1;
|
2001-11-15 00:01:43 +00:00
|
|
|
ts[3] = ModuleName[mod];
|
|
|
|
return(MkApplTerm(PredMetaCall->FunctorOfPred,4,ts));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2001-11-15 00:01:43 +00:00
|
|
|
CallError(yap_error_number err, SMALLUNSGN 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 {
|
|
|
|
Error(err, ARG1, "call/1");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2001-10-30 16:42:05 +00:00
|
|
|
CallClause(PredEntry *pen, unsigned int arity, Int position)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
CELL flags;
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
if (position == -1) return(CallPredicate(pen, B));
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(pen->PRWLock);
|
|
|
|
flags = pen->PredFlags;
|
|
|
|
if ((flags & (CompiledPredFlag | DynamicPredFlag)) ||
|
|
|
|
pen->OpcodeOfPred == UNDEF_OPCODE) {
|
2001-10-30 16:42:05 +00:00
|
|
|
CODEADDR q;
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEPTH_LIMIT
|
2001-10-30 16:42:05 +00:00
|
|
|
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */
|
|
|
|
if (pen->ModuleOfPred) {
|
|
|
|
if (DEPTH == MkIntTerm(0))
|
|
|
|
return(FALSE);
|
|
|
|
else DEPTH = RESET_DEPTH();
|
|
|
|
}
|
|
|
|
} else if (pen->ModuleOfPred)
|
|
|
|
DEPTH -= MkIntConstant(2);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2001-10-30 16:42:05 +00:00
|
|
|
if (do_low_level_trace)
|
|
|
|
low_level_trace(enter_pred,pen,XREGS+1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* LOW_LEVEL_TRACE */
|
2001-10-30 16:42:05 +00:00
|
|
|
ENV = YENV;
|
|
|
|
YENV = ASP;
|
|
|
|
YENV[E_CB] = (CELL)(B->cp_b);
|
|
|
|
CP = P;
|
|
|
|
q = pen->FirstClause;
|
|
|
|
if (pen->PredFlags & ProfiledPredFlag) {
|
|
|
|
LOCK(pen->StatisticsForPred.lock);
|
|
|
|
if (position == 1)
|
|
|
|
pen->StatisticsForPred.NOfEntries++;
|
|
|
|
else
|
|
|
|
pen->StatisticsForPred.NOfRetries++;
|
|
|
|
UNLOCK(pen->StatisticsForPred.lock);
|
|
|
|
}
|
|
|
|
if (flags & DynamicPredFlag) {
|
|
|
|
CLAUSECODE->arity = pen->ArityOfPE;
|
|
|
|
CLAUSECODE->func = pen->FunctorOfPred;
|
|
|
|
while (position > 1) {
|
2001-04-09 20:54:03 +01:00
|
|
|
while (ClauseCodeToClause(q)->ClFlags & ErasedMask)
|
|
|
|
q = NextClause(q);
|
2001-10-30 16:42:05 +00:00
|
|
|
position--;
|
|
|
|
q = NextClause(q);
|
|
|
|
}
|
|
|
|
while (ClauseCodeToClause(q)->ClFlags & ErasedMask)
|
|
|
|
q = NextClause(q);
|
2001-04-09 20:54:03 +01:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
|
|
|
Clause *cl = ClauseCodeToClause(q);
|
|
|
|
|
|
|
|
LOCK(cl->ClLock);
|
|
|
|
TRAIL_CLREF(cl);
|
|
|
|
INC_DBREF_COUNT(cl);
|
|
|
|
UNLOCK(cl->ClLock);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2001-10-30 16:42:05 +00:00
|
|
|
if (!(ClauseCodeToClause(q)->ClFlags & InUseMask)) {
|
|
|
|
OPREG *opp = &(ClauseCodeToClause(q)->ClFlags);
|
|
|
|
TRAIL_CLREF(ClauseCodeToClause(q));
|
|
|
|
*opp |= InUseMask;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
#endif
|
|
|
|
CLAUSECODE->clause = (CODEADDR)NEXTOP((yamop *)(q),ld);
|
|
|
|
P = (yamop *)CLAUSECODE->clause;
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(pen->PRWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
return((CELL)(&(CLAUSECODE->clause)));
|
|
|
|
} else {
|
|
|
|
for (; position > 1; position--)
|
|
|
|
q = NextClause(q);
|
|
|
|
P = NEXTOP((yamop *)(q),ld);
|
|
|
|
WRITE_UNLOCK(pen->PRWLock);
|
|
|
|
return (Unsigned(pen));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
} else {
|
|
|
|
Error(SYSTEM_ERROR,ARG1,"debugger tries to debug clause for builtin");
|
|
|
|
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);
|
|
|
|
td = current_cp_as_integer();
|
|
|
|
BIND((CELL *)t,td,bind_save_cp);
|
|
|
|
#ifdef COROUTINING
|
|
|
|
DO_TRAIL(CellPtr(t), td);
|
|
|
|
if (CellPtr(t) < H0) WakeUp((CELL *)t);
|
|
|
|
bind_save_cp:
|
|
|
|
#endif
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2002-04-06 06:33:44 +01:00
|
|
|
static Int
|
2001-12-14 19:03:29 +00:00
|
|
|
EnterCreepMode(SMALLUNSGN mod) {
|
2001-11-15 00:01:43 +00:00
|
|
|
PredEntry *PredSpy = RepPredProp(PredPropByFunc(FunctorSpy,0));
|
2002-04-06 06:33:44 +01:00
|
|
|
Term tn = MkApplTerm(MkFunctor(AtomMetaCall,1),1,&ARG1);
|
|
|
|
ARG1 = MkPairTerm(ModuleName[mod],tn);
|
2001-08-08 22:17:27 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
2001-09-12 16:52:28 +01:00
|
|
|
P_before_spy = P;
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(PredSpy, B));
|
2001-08-08 22:17:27 +01:00
|
|
|
}
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
inline static Int
|
2002-02-04 16:12:54 +00:00
|
|
|
do_execute(Term t, SMALLUNSGN mod)
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
2001-12-07 20:27:03 +00:00
|
|
|
if (yap_flags[SPY_CREEP_FLAG]) {
|
2001-12-14 19:03:29 +00:00
|
|
|
return(EnterCreepMode(mod));
|
2001-12-07 20:27:03 +00:00
|
|
|
} else if (PredGoalExpansion->OpcodeOfPred != UNDEF_OPCODE) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return(CallMetaCall(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)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(TYPE_ERROR_CALLABLE, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
arity = ArityOfFunctor(f);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
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 */
|
|
|
|
if (pen->PredFlags & MetaPredFlag) {
|
2001-11-15 00:01:43 +00:00
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
2001-12-07 16:32:36 +00:00
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod) &&
|
|
|
|
mod == LookupModule(tmod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(CallMetaCall(mod));
|
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)
|
|
|
|
XREGS[i] = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2001-10-30 16:42:05 +00:00
|
|
|
XREGS[i] = *pt++;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(pen, B));
|
|
|
|
} 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));
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(pe, B));
|
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
static Int
|
|
|
|
p_execute(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
return(do_execute(t, CurrentModule));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_in_mod(void)
|
|
|
|
{ /* '$execute'(Goal) */
|
2001-11-15 00:01:43 +00:00
|
|
|
return(do_execute(Deref(ARG1), IntOfTerm(ARG2)));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
inline static Int
|
|
|
|
CallMetaCallWithin(void)
|
|
|
|
{
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(PredMetaCall, B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
/* '$execute_within'(Goal,CutPt,OrigGoal,Mod) */
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
|
|
|
p_execute_within(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tmod = Deref(ARG4);
|
2001-04-09 20:54:03 +01:00
|
|
|
unsigned int arity;
|
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(tmod);
|
2001-12-21 05:41:01 +00:00
|
|
|
#ifdef SBA
|
|
|
|
choiceptr cut_pt = (choiceptr)IntegerOfTerm(Deref(ARG2));
|
|
|
|
#else
|
|
|
|
choiceptr cut_pt = (choiceptr)(LCL0-IntegerOfTerm(Deref(ARG2)));
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
restart_exec:
|
2001-12-07 20:27:03 +00:00
|
|
|
if (yap_flags[SPY_CREEP_FLAG]) {
|
2001-12-14 19:03:29 +00:00
|
|
|
return(EnterCreepMode(mod));
|
2001-12-07 20:27:03 +00:00
|
|
|
} else if (PredGoalExpansion->OpcodeOfPred != UNDEF_OPCODE) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(CallMetaCallWithin());
|
2001-12-07 20:27:03 +00:00
|
|
|
/* at this point check if we should enter creep mode */
|
2001-04-09 20:54:03 +01:00
|
|
|
} else 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 unsigned int i;
|
|
|
|
register CELL *pt;
|
|
|
|
|
|
|
|
if (IsExtensionFunctor(f)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(TYPE_ERROR_CALLABLE, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
{
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pen;
|
|
|
|
arity = ArityOfFunctor(f);
|
|
|
|
a = NameOfFunctor(f);
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(f, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
pen = RepPredProp(pe);
|
|
|
|
/* You thought we would be over by now */
|
|
|
|
/* but no meta calls require special preprocessing */
|
|
|
|
if (pen->PredFlags & MetaPredFlag) {
|
2001-11-15 00:01:43 +00:00
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
2001-12-07 16:32:36 +00:00
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod) &&
|
|
|
|
mod == LookupModule(tmod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
return(CallMetaCallWithin());
|
|
|
|
}
|
|
|
|
/* 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) {
|
|
|
|
#if SBA
|
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
|
|
|
XREGS[i] = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
XREGS[i] = d0;
|
|
|
|
#else
|
|
|
|
XREGS[i] = *pt++;
|
|
|
|
#endif
|
|
|
|
}
|
2001-12-21 05:41:01 +00:00
|
|
|
return (CallPredicate(pen, cut_pt));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
} else if (IsAtomOrIntTerm(t)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
a = AtomOfTerm(t);
|
2001-06-07 17:58:06 +01:00
|
|
|
if (a == AtomTrue || a == AtomOtherwise)
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
2001-06-07 17:58:06 +01:00
|
|
|
else if (a == AtomCut) {
|
2001-12-21 05:41:01 +00:00
|
|
|
if (TopB != NULL && YOUNGER_CP(TopB,cut_pt)) {
|
|
|
|
cut_pt = TopB;
|
|
|
|
if (DelayedB == NULL || YOUNGER_CP(cut_pt,DelayedB))
|
|
|
|
DelayedB = cut_pt;
|
2001-06-07 17:58:06 +01:00
|
|
|
}
|
|
|
|
/* find where to cut to */
|
2001-12-21 05:41:01 +00:00
|
|
|
if (SHOULD_CUT_UP_TO(B,cut_pt)) {
|
2001-10-30 16:42:05 +00:00
|
|
|
#ifdef YAPOR
|
2001-06-07 17:58:06 +01:00
|
|
|
/* Wow, we're gonna cut!!! */
|
2001-12-21 05:41:01 +00:00
|
|
|
CUT_prune_to(cut_pt);
|
2001-06-07 17:58:06 +01:00
|
|
|
#else
|
|
|
|
/* Wow, we're gonna cut!!! */
|
2001-12-21 05:41:01 +00:00
|
|
|
B = cut_pt;
|
2001-06-07 17:58:06 +01:00
|
|
|
#endif /* YAPOR */
|
2001-06-18 19:24:00 +01:00
|
|
|
HB = PROTECT_FROZEN_H(B);
|
2001-06-07 17:58:06 +01:00
|
|
|
}
|
|
|
|
return(TRUE);
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (a == AtomFail || a == AtomFalse) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2001-10-30 16:42:05 +00:00
|
|
|
} else {
|
|
|
|
/* call may not define new system predicates!! */
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByAtom(a, mod);
|
2001-12-21 05:41:01 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), cut_pt));
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Is Pair Term */
|
|
|
|
return(CallMetaCallWithin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '$execute_within2'(Goal) */
|
|
|
|
static Int
|
|
|
|
p_execute_within2(void)
|
|
|
|
{
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Prop pe;
|
|
|
|
|
2001-12-07 20:27:03 +00:00
|
|
|
if (yap_flags[SPY_CREEP_FLAG]) {
|
2001-12-14 19:03:29 +00:00
|
|
|
return(EnterCreepMode(CurrentModule));
|
2001-12-07 20:27:03 +00:00
|
|
|
} else if (PredGoalExpansion->OpcodeOfPred != UNDEF_OPCODE) {
|
2001-10-30 16:42:05 +00:00
|
|
|
return(CallMetaCallWithin());
|
|
|
|
} else if (IsVarTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(INSTANTIATION_ERROR, CurrentModule);
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsApplTerm(t)) {
|
|
|
|
register Functor f = FunctorOfTerm(t);
|
|
|
|
|
|
|
|
if (IsExtensionFunctor(f)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(TYPE_ERROR_CALLABLE, CurrentModule);
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
PredEntry *pen;
|
|
|
|
CELL *dest;
|
|
|
|
register CELL *pt;
|
|
|
|
register unsigned int i;
|
|
|
|
unsigned int arity = ArityOfFunctor(f);
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(f, CurrentModule);
|
2001-10-30 16:42:05 +00:00
|
|
|
pen = RepPredProp(pe);
|
|
|
|
/* You thought we would be over by now */
|
|
|
|
/* but no meta calls require special preprocessing */
|
|
|
|
if (pen->PredFlags & MetaPredFlag) {
|
2001-04-09 20:54:03 +01:00
|
|
|
return(CallMetaCallWithin());
|
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
/* at this point check if we should enter creep mode */
|
|
|
|
/* 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;
|
|
|
|
dest = XREGS+1;
|
|
|
|
for (i = 0; i < arity; ++i) {
|
|
|
|
#if SBA
|
|
|
|
Term d0 = *pt++;
|
|
|
|
if (d0 == 0)
|
|
|
|
*dest++ = (CELL)(pt-1);
|
|
|
|
else
|
|
|
|
*dest++ = d0;
|
|
|
|
#else
|
|
|
|
*dest++ = *pt++;
|
|
|
|
#endif
|
|
|
|
}
|
2001-12-11 16:40:51 +00:00
|
|
|
if (pen->PredFlags & CutTransparentPredFlag)
|
|
|
|
return (CallPredicate(pen, (choiceptr)(ENV[E_CB])));
|
|
|
|
else
|
|
|
|
return (CallPredicate(pen, B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom a = AtomOfTerm(t);
|
|
|
|
|
|
|
|
if (a == AtomTrue || a == AtomOtherwise)
|
|
|
|
return(TRUE);
|
|
|
|
else if (a == AtomCut) {
|
|
|
|
choiceptr pt0;
|
|
|
|
|
|
|
|
pt0 = (choiceptr)(ENV[E_CB]);
|
|
|
|
if (TopB != NULL && YOUNGER_CP(TopB,pt0)) {
|
|
|
|
pt0 = TopB;
|
|
|
|
if (DelayedB == NULL || YOUNGER_CP(pt0,DelayedB))
|
|
|
|
DelayedB = pt0;
|
|
|
|
}
|
|
|
|
/* find where to cut to */
|
|
|
|
if (SHOULD_CUT_UP_TO(B,pt0)) {
|
|
|
|
#ifdef YAPOR
|
|
|
|
/* Wow, we're gonna cut!!! */
|
|
|
|
CUT_prune_to(pt0);
|
|
|
|
#else
|
|
|
|
/* Wow, we're gonna cut!!! */
|
|
|
|
B = pt0;
|
|
|
|
#endif /* YAPOR */
|
|
|
|
HB = PROTECT_FROZEN_H(B);
|
|
|
|
}
|
|
|
|
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 = PredPropByAtom(a, CurrentModule);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
|
|
|
} else if (IsIntTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return CallError(TYPE_ERROR_CALLABLE, CurrentModule);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* Is Pair Term */
|
|
|
|
return(CallMetaCallWithin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2001-11-15 00:01:43 +00:00
|
|
|
Term tmod = Deref(ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
unsigned int arity;
|
|
|
|
Prop pe;
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(tmod);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-19 03:36:51 +00:00
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Error(INSTANTIATION_ERROR,ARG3,"call/1");
|
|
|
|
return(FALSE);
|
|
|
|
} 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))
|
|
|
|
return(FALSE);
|
|
|
|
arity = ArityOfFunctor(f);
|
|
|
|
/* 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-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(f, mod);
|
2001-11-19 03:36:51 +00:00
|
|
|
} else {
|
|
|
|
Error(TYPE_ERROR_CALLABLE,ARG3,"call/1");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* N = arity; */
|
|
|
|
/* call may not define new system predicates!! */
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_0(void)
|
|
|
|
{ /* '$execute_0'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByAtom(a, mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_1(void)
|
|
|
|
{ /* '$execute_0'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG3));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a,1),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_2(void)
|
|
|
|
{ /* '$execute_2'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG4));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 2),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_3(void)
|
|
|
|
{ /* '$execute_3'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG5));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 3),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_4(void)
|
|
|
|
{ /* '$execute_4'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG6));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 4),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_5(void)
|
|
|
|
{ /* '$execute_5'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG7));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
|
|
|
ARG5 = ARG6;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 5),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_6(void)
|
|
|
|
{ /* '$execute_6'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG8));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
|
|
|
ARG5 = ARG6;
|
|
|
|
ARG6 = ARG7;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 6),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_7(void)
|
|
|
|
{ /* '$execute_7'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG9));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
|
|
|
ARG5 = ARG6;
|
|
|
|
ARG6 = ARG7;
|
|
|
|
ARG7 = ARG8;
|
2002-01-03 02:49:33 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 7),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_8(void)
|
|
|
|
{ /* '$execute_8'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG10));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
|
|
|
ARG5 = ARG6;
|
|
|
|
ARG6 = ARG7;
|
|
|
|
ARG7 = ARG8;
|
|
|
|
ARG8 = ARG9;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 8),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_9(void)
|
|
|
|
{ /* '$execute_9'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG11));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
|
|
|
ARG5 = ARG6;
|
|
|
|
ARG6 = ARG7;
|
|
|
|
ARG7 = ARG8;
|
|
|
|
ARG8 = ARG9;
|
|
|
|
ARG9 = ARG10;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 9),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_execute_10(void)
|
|
|
|
{ /* '$execute_10'(Goal) */
|
|
|
|
Term t = Deref(ARG1);
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(Deref(ARG12));
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
ARG1 = ARG2;
|
|
|
|
ARG2 = ARG3;
|
|
|
|
ARG3 = ARG4;
|
|
|
|
ARG4 = ARG5;
|
|
|
|
ARG5 = ARG6;
|
|
|
|
ARG6 = ARG7;
|
|
|
|
ARG7 = ARG8;
|
|
|
|
ARG8 = ARG9;
|
|
|
|
ARG9 = ARG10;
|
|
|
|
ARG10 = ARG11;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(MkFunctor(a, 10),mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallPredicate(RepPredProp(pe), B));
|
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)) {
|
|
|
|
Error(INSTANTIATION_ERROR,d,"depth_bound_call/2");
|
|
|
|
} else if (!IsIntTerm(d)) {
|
|
|
|
Error(TYPE_ERROR_INTEGER, d, "depth_bound_call/2");
|
|
|
|
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 */
|
|
|
|
return (PredGoalExpansion->OpcodeOfPred != UNDEF_OPCODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_at_execute(void)
|
|
|
|
{ /* '$execute'(Goal,ClauseNumber) */
|
2001-11-15 00:01:43 +00:00
|
|
|
Term t = Deref(ARG1), tmod = Deref(ARG2), t2 = Deref(ARG3);
|
|
|
|
unsigned int arity;
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop pe;
|
|
|
|
Atom a;
|
2001-11-15 00:01:43 +00:00
|
|
|
SMALLUNSGN mod = LookupModule(tmod);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
restart_exec:
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
a = AtomOfTerm(t);
|
|
|
|
pe = PredPropByAtom(a, mod);
|
|
|
|
arity = 0;
|
|
|
|
} 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 (IsBlobFunctor(f))
|
|
|
|
return(FALSE);
|
2001-11-15 00:01:43 +00:00
|
|
|
if (f == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
2001-12-07 16:32:36 +00:00
|
|
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod) &&
|
|
|
|
mod == LookupModule(tmod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
goto restart_exec;
|
|
|
|
}
|
|
|
|
if (IsVarTerm(tmod)) {
|
|
|
|
Error(INSTANTIATION_ERROR, ARG1, "calling clause in debugger");
|
|
|
|
}
|
|
|
|
Error(TYPE_ERROR_ATOM, ARG1, "calling clause in debugger");
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = ArityOfFunctor(f);
|
|
|
|
a = NameOfFunctor(f);
|
|
|
|
/* 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
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = PredPropByFunc(f,mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE); /* for the moment */
|
|
|
|
if (IsVarTerm(t2) || !IsIntTerm(t2))
|
|
|
|
return (FALSE);
|
|
|
|
/* N = arity; */
|
|
|
|
/* call may not define new system predicates!! */
|
2001-10-30 16:42:05 +00:00
|
|
|
return (CallClause(RepPredProp(pe), arity, IntOfTerm(t2)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
exec_absmi(int top)
|
|
|
|
{
|
|
|
|
int lval;
|
|
|
|
if (top && (lval = sigsetjmp (RestartEnv, 1)) != 0) {
|
|
|
|
if (lval == 1) { /* restart */
|
|
|
|
/* otherwise, SetDBForThrow will fail entering critical mode */
|
|
|
|
PrologMode = UserMode;
|
|
|
|
/* find out where to cut to */
|
2001-06-27 18:24:27 +01:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#if defined(hppa) || defined(__alpha)
|
|
|
|
/* siglongjmp resets the TR hardware register */
|
|
|
|
restore_TR();
|
|
|
|
#endif
|
|
|
|
#if defined(__alpha)
|
|
|
|
/* siglongjmp resets the H hardware register */
|
|
|
|
restore_H();
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
yap_flags[SPY_CREEP_FLAG] = 0;
|
2001-05-21 21:00:05 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
2001-04-09 20:54:03 +01:00
|
|
|
P = (yamop *)FAILCODE;
|
|
|
|
}
|
|
|
|
if (lval == 2) { /* arithmetic exception */
|
|
|
|
/* must be done here, otherwise siglongjmp will clobber all the registers */
|
|
|
|
Error(YAP_matherror,TermNil,NULL);
|
|
|
|
/* reset the registers so that we don't have trash in abstract machine */
|
|
|
|
set_fpu_exceptions(yap_flags[LANGUAGE_MODE_FLAG] == 1);
|
|
|
|
P = (yamop *)FAILCODE;
|
|
|
|
}
|
|
|
|
if (lval == 3) { /* saved state */
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PrologMode = UserMode;
|
|
|
|
return(absmi(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_goal(CODEADDR CodeAdr, int arity, CELL *pt, int args_to_save, int top)
|
|
|
|
{
|
|
|
|
choiceptr saved_b = B;
|
|
|
|
|
|
|
|
/* create an initial pseudo environment so that when garbage
|
|
|
|
collection is going up in the environment chain it doesn't get
|
|
|
|
confused */
|
|
|
|
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 */
|
|
|
|
CP = (yamop *) YESCODE;
|
|
|
|
/* this is an hack to save the arguments */
|
|
|
|
{
|
|
|
|
CELL *pt1 = XREGS+1+args_to_save;
|
|
|
|
|
|
|
|
while (pt1 > XREGS+1)
|
|
|
|
*--ASP = *--pt1;
|
|
|
|
}
|
|
|
|
*--ASP = MkIntTerm(args_to_save+1);
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < arity; i++) {
|
|
|
|
XREGS[i+1] = *pt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
B = (choiceptr)ASP;
|
|
|
|
B--;
|
|
|
|
#ifdef TABLING
|
|
|
|
if (top) {
|
|
|
|
DepFr_cons_cp(GLOBAL_root_dep_fr) = B;
|
|
|
|
}
|
|
|
|
#endif /* TABLING */
|
|
|
|
B->cp_h = H;
|
|
|
|
B->cp_tr = TR;
|
|
|
|
B->cp_cp = CP;
|
|
|
|
B->cp_ap = (yamop *) NOCODE;
|
|
|
|
B->cp_env = ENV;
|
|
|
|
B->cp_b = saved_b;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
B->cp_depth = DEPTH;
|
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
if (top) {
|
|
|
|
#if COROUTINING
|
|
|
|
RESET_VARIABLE((CELL *)GlobalBase);
|
|
|
|
DelayedVars = NewTimedVar((CELL)GlobalBase);
|
|
|
|
WokenGoals = NewTimedVar(TermNil);
|
|
|
|
MutableList = NewTimedVar(TermNil);
|
|
|
|
AttsMutableList = NewTimedVar(TermNil);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
YENV = ASP = (CELL *)B;
|
|
|
|
HB = H;
|
|
|
|
YENV[E_CB] = Unsigned (B);
|
|
|
|
P = (yamop *) CodeAdr;
|
2001-11-15 00:01:43 +00:00
|
|
|
S = CellPtr (RepPredProp (PredPropByFunc (MkFunctor(AtomCall, 1),0))); /* A1 mishaps */
|
2001-04-09 20:54:03 +01:00
|
|
|
TopB = B;
|
|
|
|
|
|
|
|
return(exec_absmi(top));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Int
|
2001-11-15 00:01:43 +00:00
|
|
|
execute_goal(Term t, int nargs, SMALLUNSGN mod)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int out;
|
|
|
|
CODEADDR CodeAdr;
|
|
|
|
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 */
|
|
|
|
Int MyOldTopB = LCL0-(CELL *)TopB;
|
|
|
|
Int MyOldDelayedB = LCL0-(CELL *)DelayedB;
|
|
|
|
choiceptr OldTopB, OldDelayedB;
|
|
|
|
|
|
|
|
|
|
|
|
DelayedB = NULL;
|
|
|
|
/* forget we have a DelayedB to do, this is not a problem for the embedded computation to solve */
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
|
|
|
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 {
|
|
|
|
Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
|
|
|
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
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
READ_LOCK(ppe->PRWLock);
|
2001-10-03 14:39:16 +01:00
|
|
|
if (IsAtomTerm(t)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
CodeAdr = RepPredProp (pe)->CodeOfPred;
|
2001-10-03 14:39:16 +01:00
|
|
|
READ_UNLOCK(ppe->PRWLock);
|
|
|
|
out = do_goal(CodeAdr, 0, pt, nargs, FALSE);
|
|
|
|
} else {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
2001-11-15 00:01:43 +00:00
|
|
|
CodeAdr = RepPredProp (pe)->CodeOfPred;
|
2001-10-03 14:39:16 +01:00
|
|
|
READ_UNLOCK(ppe->PRWLock);
|
|
|
|
out = do_goal(CodeAdr, ArityOfFunctor(f), pt, nargs, FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (out == 1) {
|
|
|
|
choiceptr old_B;
|
|
|
|
/* we succeeded, let's prune */
|
|
|
|
/* restore the old environment */
|
|
|
|
/* get to previous environment */
|
|
|
|
#ifdef YAPOR
|
|
|
|
CUT_prune_to((choiceptr)(ENV[E_CB]));
|
|
|
|
#else
|
|
|
|
B = (choiceptr)(ENV[E_CB]);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
/* find out where we have the old arguments */
|
|
|
|
old_B = ((choiceptr)(ENV-(EnvSizeInCells+nargs+1)))-1;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=1; i<= nargs; i++) {
|
|
|
|
#if MIN_ARRAY == 0
|
|
|
|
XREGS[i] = old_B->cp_args[i];
|
|
|
|
#else
|
|
|
|
XREGS[i] = old_B->cp_last.cp_args[i];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CP = saved_cp;
|
|
|
|
P = saved_p;
|
|
|
|
ASP = ENV;
|
|
|
|
ENV = (CELL *)(ENV[E_E]);
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH= ENV[E_DEPTH];
|
|
|
|
#endif
|
|
|
|
/* we have failed, and usually we would backtrack to this B,
|
|
|
|
trouble is, we may also have a delayed cut to do */
|
|
|
|
OldTopB = (choiceptr)(LCL0-MyOldTopB);
|
|
|
|
OldDelayedB = (choiceptr)(LCL0-MyOldDelayedB);
|
|
|
|
if (DelayedB != NULL) {
|
2002-04-03 20:33:38 +01:00
|
|
|
if (YOUNGER_CP(B,DelayedB)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we have a delayed cut to do */
|
|
|
|
if (YOUNGER_CP(OldTopB,DelayedB)) {
|
|
|
|
/* and this delayed cut is to before the c-code that actually called us */
|
|
|
|
B = OldTopB;
|
|
|
|
/* did we have a cut which was cutting more than our current cut? */
|
|
|
|
if (OldDelayedB != NULL && YOUNGER_CP(DelayedB,OldDelayedB))
|
|
|
|
DelayedB = OldDelayedB;
|
|
|
|
} else {
|
|
|
|
/* just cut back to where we should cut */
|
|
|
|
B = DelayedB;
|
|
|
|
DelayedB = OldDelayedB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DelayedB = OldDelayedB;
|
|
|
|
}
|
|
|
|
TopB = OldTopB;
|
|
|
|
HB = B->cp_h;
|
|
|
|
YENV = ENV;
|
|
|
|
return(TRUE);
|
|
|
|
} else if (out == 0) {
|
|
|
|
ASP = B->cp_env;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=1; i<= nargs; i++) {
|
|
|
|
#if MIN_ARRAY==0
|
|
|
|
XREGS[i] = B->cp_args[i];
|
|
|
|
#else
|
|
|
|
XREGS[i] = B->cp_last.cp_args[i];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
P = saved_p;
|
|
|
|
CP = saved_cp;
|
|
|
|
H = B->cp_h;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH= B->cp_depth;
|
|
|
|
#endif
|
|
|
|
YENV = ENV = (CELL *)((B->cp_env)[E_E]);
|
|
|
|
B = B->cp_b;
|
|
|
|
SET_BB(B);
|
|
|
|
/* we have failed, and usually we would backtrack to this B,
|
|
|
|
trouble is, we may also have a delayed cut to do */
|
|
|
|
OldTopB = (choiceptr)(LCL0-MyOldTopB);
|
|
|
|
OldDelayedB = (choiceptr)(LCL0-MyOldDelayedB);
|
|
|
|
if (DelayedB != NULL) {
|
2002-04-03 20:33:38 +01:00
|
|
|
if (YOUNGER_CP(B,DelayedB)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we have a delayed cut to do */
|
|
|
|
if (YOUNGER_CP(OldTopB,DelayedB)) {
|
|
|
|
/* and this delayed cut is to before the c-code that actually called us */
|
|
|
|
B = OldTopB;
|
|
|
|
/* did we have a cut which was cutting more than our current cut? */
|
|
|
|
if (OldDelayedB != NULL && YOUNGER_CP(DelayedB,OldDelayedB))
|
|
|
|
DelayedB = OldDelayedB;
|
|
|
|
} else {
|
|
|
|
/* just cut back to where we should cut */
|
|
|
|
B = DelayedB;
|
|
|
|
DelayedB = OldDelayedB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DelayedB = OldDelayedB;
|
|
|
|
}
|
|
|
|
TopB = OldTopB;
|
|
|
|
HB = PROTECT_FROZEN_H(B);
|
|
|
|
return(FALSE);
|
|
|
|
} else {
|
|
|
|
Error(SYSTEM_ERROR,TermNil,"emulator crashed");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
RunTopGoal(Term t)
|
|
|
|
{
|
|
|
|
CODEADDR CodeAdr;
|
|
|
|
Prop pe;
|
|
|
|
PredEntry *ppe;
|
|
|
|
CELL *pt;
|
2001-10-03 14:39:16 +01:00
|
|
|
UInt arity;
|
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)) {
|
|
|
|
Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
/* I cannot use the standard macro here because
|
|
|
|
otherwise I would dereference the argument and
|
|
|
|
might skip a svar */
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = GetPredPropByFunc(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 {
|
|
|
|
Error(TYPE_ERROR_CALLABLE,t,"call/1");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
ppe = RepPredProp(pe);
|
2001-07-05 17:14:15 +01:00
|
|
|
if (pe != NIL) {
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(ppe->PRWLock);
|
2001-07-05 17:14:15 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pe == NIL ||
|
|
|
|
ppe->OpcodeOfPred == UNDEF_OPCODE ||
|
|
|
|
ppe->PredFlags & (UserCPredFlag|CPredFlag|BasicPredFlag) )
|
|
|
|
{
|
2001-07-05 17:14:15 +01:00
|
|
|
if (pe != NIL) {
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_UNLOCK(ppe->PRWLock);
|
2001-07-05 17:14:15 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we must always start the emulator with Prolog code */
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
CodeAdr = ppe->CodeOfPred;
|
|
|
|
READ_UNLOCK(ppe->PRWLock);
|
|
|
|
if (TrailTop - HeapTop < 2048) {
|
|
|
|
PrologMode = BootMode;
|
|
|
|
Error(SYSTEM_ERROR,TermNil,
|
|
|
|
"unable to boot because of too little heap space");
|
|
|
|
}
|
|
|
|
return(do_goal(CodeAdr, arity, pt, 0, TRUE));
|
|
|
|
}
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
Error(INSTANTIATION_ERROR,t,"support for coroutining");
|
|
|
|
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)) {
|
|
|
|
Error(INSTANTIATION_ERROR,t,"support for coroutining");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t)) {
|
|
|
|
restore_regs(t);
|
|
|
|
}
|
|
|
|
d0 = Deref(ARG2);
|
|
|
|
if (IsVarTerm(d0)) {
|
|
|
|
Error(INSTANTIATION_ERROR,d0,"support for coroutining");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
#if SBA
|
|
|
|
if (!IsIntegerTerm(d0)) {
|
|
|
|
#else
|
|
|
|
if (!IsIntTerm(d0)) {
|
|
|
|
#endif
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
#if SBA
|
|
|
|
pt0 = (choiceptr)IntegerOfTerm(d0);
|
|
|
|
#else
|
|
|
|
pt0 = (choiceptr)(LCL0-IntOfTerm(d0));
|
|
|
|
#endif
|
|
|
|
if (TopB != NULL && YOUNGER_CP(TopB,pt0)) {
|
|
|
|
if (DelayedB == NULL || YOUNGER_CP(DelayedB,pt0))
|
|
|
|
DelayedB = pt0;
|
|
|
|
pt0 = TopB;
|
|
|
|
}
|
|
|
|
/* find where to cut to */
|
|
|
|
if (pt0 > B) {
|
|
|
|
/* Wow, we're gonna cut!!! */
|
|
|
|
#ifdef YAPOR
|
2002-04-06 04:54:18 +01:00
|
|
|
CUT_prune_to(pt0);
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
|
|
|
B = pt0;
|
|
|
|
#endif /* YAPOR */
|
|
|
|
HB = B->cp_h;
|
|
|
|
/* trim_trail();*/
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2001-04-24 17:40:11 +01:00
|
|
|
static Int
|
|
|
|
p_clean_ifcp(void) {
|
|
|
|
#if SBA
|
|
|
|
choiceptr pt0 = (choiceptr)IntegerOfTerm(Deref(ARG1));
|
|
|
|
#else
|
|
|
|
choiceptr pt0 = (choiceptr)(LCL0-IntOfTerm(Deref(ARG1)));
|
|
|
|
#endif
|
2001-04-27 17:02:43 +01:00
|
|
|
if (pt0 == B) {
|
|
|
|
B = B->cp_b;
|
|
|
|
HB = B->cp_h;
|
|
|
|
} else {
|
|
|
|
pt0->cp_ap = (yamop *)TRUSTFAILCODE;
|
|
|
|
}
|
2001-04-24 17:40:11 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2002-01-29 05:37:31 +00:00
|
|
|
Int
|
|
|
|
JumpToEnv(Term t) {
|
2002-01-30 03:49:50 +00:00
|
|
|
yamop *pos = (yamop *)(PredDollarCatch->LastClause);
|
|
|
|
CELL *env;
|
2002-04-03 20:33:38 +01:00
|
|
|
choiceptr first_func = NULL;
|
2002-01-30 03:49:50 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
/* find the first choicepoint that may be a catch */
|
|
|
|
while (B->cp_ap != pos) {
|
2002-04-03 20:33:38 +01:00
|
|
|
/* we are already doing a catch */
|
|
|
|
if (B->cp_ap == (yamop *)(PredHandleThrow->LastClause)) {
|
|
|
|
if (DelayedB == NULL || YOUNGER_CP(B,DelayedB))
|
|
|
|
DelayedB = B;
|
|
|
|
P = (yamop *)FAILCODE;
|
|
|
|
if (first_func != NULL) {
|
|
|
|
B = first_func;
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (B->cp_ap == (yamop *) NOCODE && first_func == NULL)
|
|
|
|
first_func = B;
|
2002-01-30 03:49:50 +00:00
|
|
|
B = B->cp_b;
|
|
|
|
}
|
|
|
|
/* is it a continuation? */
|
|
|
|
env = B->cp_env;
|
|
|
|
while (env > ENV)
|
|
|
|
ENV = (CELL *)ENV[E_E];
|
|
|
|
/* yes, we found it ! */
|
|
|
|
if (env == ENV) break;
|
|
|
|
/* oops, try next */
|
2002-01-14 22:26:53 +00:00
|
|
|
B = B->cp_b;
|
2002-01-30 03:49:50 +00:00
|
|
|
} while (TRUE);
|
|
|
|
/* step one environment above */
|
|
|
|
B->cp_cp = (yamop *)env[E_CP];
|
2002-01-24 23:55:34 +00:00
|
|
|
B->cp_ap = (yamop *)(PredHandleThrow->LastClause);
|
2002-01-30 03:49:50 +00:00
|
|
|
B->cp_env = (CELL *)env[E_E];
|
|
|
|
/* cannot recover Heap because of copy term :-( */
|
2002-01-07 06:28:04 +00: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 */
|
2002-01-29 05:37:31 +00:00
|
|
|
B->cp_a3 = t;
|
2002-04-03 20:33:38 +01:00
|
|
|
if (DelayedB == NULL || YOUNGER_CP(B,DelayedB))
|
|
|
|
DelayedB = B;
|
2002-02-04 16:12:54 +00:00
|
|
|
P = (yamop *)FAILCODE;
|
2002-04-03 20:33:38 +01:00
|
|
|
if (first_func != NULL) {
|
|
|
|
B = first_func;
|
|
|
|
}
|
2002-01-07 06:28:04 +00:00
|
|
|
return(FALSE);
|
2001-12-14 19:03:29 +00:00
|
|
|
}
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
|
|
|
InitExecFs(void)
|
|
|
|
{
|
|
|
|
InitCPred("$execute", 1, p_execute, 0);
|
2001-10-30 16:42:05 +00:00
|
|
|
InitCPred("$execute_in_mod", 2, p_execute_in_mod, 0);
|
2001-11-15 00:01:43 +00:00
|
|
|
InitCPred("$execute_within", 4, p_execute_within, 0);
|
2001-10-30 16:42:05 +00:00
|
|
|
InitCPred("$execute_within", 1, p_execute_within2, 0);
|
2001-10-31 20:16:48 +00:00
|
|
|
InitCPred("$last_execute_within", 1, p_execute_within2, 0);
|
2001-11-15 00:01:43 +00:00
|
|
|
InitCPred("$execute", 3, p_at_execute, 0);
|
2001-12-13 17:51:26 +00:00
|
|
|
InitCPred("$call_with_args", 2, p_execute_0, 0);
|
|
|
|
InitCPred("$call_with_args", 3, p_execute_1, 0);
|
|
|
|
InitCPred("$call_with_args", 4, p_execute_2, 0);
|
|
|
|
InitCPred("$call_with_args", 5, p_execute_3, 0);
|
|
|
|
InitCPred("$call_with_args", 6, p_execute_4, 0);
|
|
|
|
InitCPred("$call_with_args", 7, p_execute_5, 0);
|
|
|
|
InitCPred("$call_with_args", 8, p_execute_6, 0);
|
|
|
|
InitCPred("$call_with_args", 9, p_execute_7, 0);
|
|
|
|
InitCPred("$call_with_args", 10, p_execute_8, 0);
|
|
|
|
InitCPred("$call_with_args", 11, p_execute_9, 0);
|
|
|
|
InitCPred("$call_with_args", 12, p_execute_10, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
InitCPred("$execute_under_depth_limit", 2, p_execute_depth_limit, 0);
|
|
|
|
#endif
|
2001-11-15 00:01:43 +00:00
|
|
|
InitCPred("$execute0", 2, p_execute0, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
InitCPred("$save_current_choice_point", 1, p_save_cp, 0);
|
|
|
|
InitCPred("$pred_goal_expansion_on", 0, p_pred_goal_expansion_on, SafePredFlag);
|
|
|
|
InitCPred("$restore_regs", 1, p_restore_regs, SafePredFlag);
|
|
|
|
InitCPred("$restore_regs", 2, p_restore_regs2, SafePredFlag);
|
2001-04-24 17:40:11 +01:00
|
|
|
InitCPred("$clean_ifcp", 1, p_clean_ifcp, SafePredFlag);
|
2002-01-30 02:20:44 +00:00
|
|
|
InitCPred("$jump_env_and_store_ball", 1, p_jump_env, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|