user expansion
pretty
This commit is contained in:
parent
c927cd5133
commit
eabc869c69
99
C/exec.c
99
C/exec.c
@ -54,7 +54,7 @@ static inline Int CallPredicate(PredEntry *pen, choiceptr cut_pt,
|
|||||||
if (pen->ModuleOfPred) {
|
if (pen->ModuleOfPred) {
|
||||||
if (DEPTH == MkIntTerm(0)) {
|
if (DEPTH == MkIntTerm(0)) {
|
||||||
UNLOCK(pen->PELock);
|
UNLOCK(pen->PELock);
|
||||||
return FALSE;
|
return false;
|
||||||
} else
|
} else
|
||||||
DEPTH = RESET_DEPTH();
|
DEPTH = RESET_DEPTH();
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ static inline Int CallPredicate(PredEntry *pen, choiceptr cut_pt,
|
|||||||
/* make sure we have access to the user given cut */
|
/* make sure we have access to the user given cut */
|
||||||
YENV[E_CB] = (CELL)cut_pt;
|
YENV[E_CB] = (CELL)cut_pt;
|
||||||
P = code;
|
P = code;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static Int CallMetaCall(Term t, Term mod USES_REGS) {
|
inline static Int CallMetaCall(Term t, Term mod USES_REGS) {
|
||||||
@ -193,7 +193,7 @@ inline static Int do_execute(Term t, Term mod USES_REGS) {
|
|||||||
/* first do predicate expansion, even before you process signals.
|
/* first do predicate expansion, even before you process signals.
|
||||||
This way you don't get to spy goal_expansion(). */
|
This way you don't get to spy goal_expansion(). */
|
||||||
if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled &&
|
if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled &&
|
||||||
!(LOCAL_PrologMode & (AbortMode | InterruptMode | SystemMode))) {
|
!(LOCAL_PrologMode & (AbortMode | InterruptMode | SystemMode))) {
|
||||||
return EnterCreepMode(t, mod PASS_REGS);
|
return EnterCreepMode(t, mod PASS_REGS);
|
||||||
}
|
}
|
||||||
restart_exec:
|
restart_exec:
|
||||||
@ -216,7 +216,7 @@ restart_exec:
|
|||||||
pen = RepPredProp(PredPropByFunc(f, mod));
|
pen = RepPredProp(PredPropByFunc(f, mod));
|
||||||
/* You thought we would be over by now */
|
/* You thought we would be over by now */
|
||||||
/* but no meta calls require special preprocessing */
|
/* but no meta calls require special preprocessing */
|
||||||
if (pen->PredFlags & MetaPredFlag) {
|
if (pen->PredFlags & MetaPredFlag) {
|
||||||
if (f == FunctorModule) {
|
if (f == FunctorModule) {
|
||||||
Term tmod = ArgOfTerm(1, t);
|
Term tmod = ArgOfTerm(1, t);
|
||||||
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
if (!IsVarTerm(tmod) && IsAtomTerm(tmod)) {
|
||||||
@ -364,7 +364,7 @@ restart_exec:
|
|||||||
pen = RepPredProp(PredPropByFunc(f, mod));
|
pen = RepPredProp(PredPropByFunc(f, mod));
|
||||||
/* You thought we would be over by now */
|
/* You thought we would be over by now */
|
||||||
/* but no meta calls require special preprocessing */
|
/* but no meta calls require special preprocessing */
|
||||||
if (pen->PredFlags & MetaPredFlag) {
|
if (pen->PredFlags & MetaPredFlag) {
|
||||||
Term t = copy_execn_to_heap(f, pt, n, arity, mod PASS_REGS);
|
Term t = copy_execn_to_heap(f, pt, n, arity, mod PASS_REGS);
|
||||||
return (CallMetaCall(t, mod PASS_REGS));
|
return (CallMetaCall(t, mod PASS_REGS));
|
||||||
}
|
}
|
||||||
@ -552,6 +552,7 @@ static Int execute11(USES_REGS1) { /* '$execute'(Goal) */
|
|||||||
|
|
||||||
static Int execute12(USES_REGS1) { /* '$execute'(Goal) */
|
static Int execute12(USES_REGS1) { /* '$execute'(Goal) */
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
|
|
||||||
heap_store(Deref(ARG2) PASS_REGS);
|
heap_store(Deref(ARG2) PASS_REGS);
|
||||||
heap_store(Deref(ARG3) PASS_REGS);
|
heap_store(Deref(ARG3) PASS_REGS);
|
||||||
heap_store(Deref(ARG4) PASS_REGS);
|
heap_store(Deref(ARG4) PASS_REGS);
|
||||||
@ -634,107 +635,105 @@ restart_exec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int execute_in_mod(USES_REGS1) { /* '$execute'(Goal) */
|
static Int execute_in_mod(USES_REGS1) { /* '$execute'(Goal) */
|
||||||
return (do_execute(Deref(ARG1), Deref(ARG2) PASS_REGS));
|
return do_execute(Deref(ARG1), Deref(ARG2) PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool complete_ge(bool out, Term omod, yhandle_t sl, bool creeping) {
|
||||||
|
CACHE_REGS
|
||||||
|
if (creeping) {
|
||||||
|
Yap_signal(YAP_CREEP_SIGNAL);
|
||||||
|
}
|
||||||
|
CurrentModule = omod;
|
||||||
|
Yap_CloseSlots(sl);
|
||||||
|
if (out) {
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int _user_expand_goal(USES_REGS1) {
|
static Int _user_expand_goal(USES_REGS1) {
|
||||||
|
yhandle_t sl = Yap_StartSlots();
|
||||||
Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL);
|
Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL);
|
||||||
Int out = FALSE;
|
|
||||||
PredEntry *pe;
|
PredEntry *pe;
|
||||||
Term cmod = CurrentModule, omod = cmod;
|
Term cmod = CurrentModule, omod = cmod;
|
||||||
Term mg_args[2], mg;
|
Term mg_args[2];
|
||||||
Term g = Yap_YapStripModule( ARG1, &cmod);
|
Term g = Yap_YapStripModule(ARG1, &cmod);
|
||||||
yhandle_t h1 = Yap_InitSlot( ARG1), h2 = Yap_InitSlot( ARG2);
|
yhandle_t h1 = Yap_InitSlot(g), h2 = Yap_InitSlot(ARG2);
|
||||||
|
|
||||||
/* CurMod:goal_expansion(A,B) */
|
/* CurMod:goal_expansion(A,B) */
|
||||||
ARG1 = g;
|
ARG1 = g;
|
||||||
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, cmod))) &&
|
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, cmod))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
pe->OpcodeOfPred != UNDEF_OPCODE &&
|
|
||||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||||
out = true;
|
return complete_ge(true, omod, sl, creeping);
|
||||||
goto complete;
|
|
||||||
}
|
}
|
||||||
/* system:goal_expansion(A,B) */
|
/* system:goal_expansion(A,B) */
|
||||||
mg_args[0] = cmod;
|
mg_args[0] = cmod;
|
||||||
mg_args[1] = Yap_GetFromSlot(h1);
|
mg_args[1] = Yap_GetFromSlot(h1);
|
||||||
ARG1 = Yap_MkApplTerm( FunctorModule, 2, mg_args );
|
ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args);
|
||||||
ARG2 = Yap_GetFromSlot(h2);
|
ARG2 = Yap_GetFromSlot(h2);
|
||||||
if ((pe = RepPredProp(
|
if ((pe = RepPredProp(
|
||||||
Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) &&
|
Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||||
out = true;
|
return complete_ge(true, omod, sl, creeping);
|
||||||
goto complete;
|
|
||||||
}
|
}
|
||||||
ARG1 = Yap_GetFromSlot(h1);
|
ARG1 = Yap_GetFromSlot(h1);
|
||||||
ARG2 = cmod;
|
ARG2 = cmod;
|
||||||
ARG3 = Yap_GetFromSlot(h2);
|
ARG3 = Yap_GetFromSlot(h2);
|
||||||
/* user:goal_expansion(A,CurMod,B) */
|
/* user:goal_expansion(A,CurMod,B) */
|
||||||
if ((pe = RepPredProp(
|
if ((pe = RepPredProp(
|
||||||
Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) &&
|
Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
Yap_execute_pred(pe, NULL PASS_REGS, false)) {
|
Yap_execute_pred(pe, NULL PASS_REGS, false)) {
|
||||||
out = TRUE;
|
return complete_ge(true, omod, sl, creeping);
|
||||||
goto complete;
|
|
||||||
}
|
}
|
||||||
mg_args[0] = cmod;
|
mg_args[0] = cmod;
|
||||||
mg_args[1] = Yap_GetFromSlot(h1);
|
mg_args[1] = Yap_GetFromSlot(h1);
|
||||||
ARG1 = Yap_MkApplTerm( FunctorModule, 2, mg_args );
|
ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args);
|
||||||
ARG2 = Yap_GetFromSlot(h2);
|
ARG2 = Yap_GetFromSlot(h2);
|
||||||
/* user:goal_expansion(A,B) */
|
/* user:goal_expansion(A,B) */
|
||||||
if (cmod != USER_MODULE && /* we have tried this before */
|
if (cmod != USER_MODULE && /* we have tried this before */
|
||||||
(pe = RepPredProp(
|
(pe = RepPredProp(
|
||||||
Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) &&
|
Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
Yap_execute_pred(pe, NULL PASS_REGS, false)) {
|
Yap_execute_pred(pe, NULL PASS_REGS, false)) {
|
||||||
ARG3 = ARG2;
|
return complete_ge(true, omod, sl, creeping);
|
||||||
out = TRUE;
|
|
||||||
}
|
}
|
||||||
complete:
|
return complete_ge(false, omod, sl, creeping);
|
||||||
if (creeping) {
|
|
||||||
Yap_signal(YAP_CREEP_SIGNAL);
|
|
||||||
}
|
|
||||||
CurrentModule = omod;
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int do_term_expansion(USES_REGS1) {
|
static Int do_term_expansion(USES_REGS1) {
|
||||||
|
yhandle_t sl = Yap_StartSlots();
|
||||||
Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL);
|
Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL);
|
||||||
Int out = FALSE;
|
|
||||||
PredEntry *pe;
|
PredEntry *pe;
|
||||||
Term cmod = CurrentModule;
|
Term cmod = CurrentModule, omod = cmod;
|
||||||
|
Term mg_args[2];
|
||||||
|
Term g = Yap_YapStripModule(ARG1, &cmod);
|
||||||
|
yhandle_t h1 = Yap_InitSlot(g), h2 = Yap_InitSlot(ARG2);
|
||||||
|
|
||||||
/* CurMod:term_expansion(A,B) */
|
/* CurMod:term_expansion(A,B) */
|
||||||
|
ARG1 = g;
|
||||||
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, cmod))) &&
|
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorTermExpansion, cmod))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||||
out = TRUE;
|
return complete_ge(true, omod, sl, creeping);
|
||||||
goto complete;
|
|
||||||
}
|
}
|
||||||
/* system:term_expansion(A,B) */
|
/* system:term_expansion(A,B) */
|
||||||
|
mg_args[0] = cmod;
|
||||||
|
mg_args[1] = Yap_GetFromSlot(h1);
|
||||||
|
ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args);
|
||||||
|
ARG2 = Yap_GetFromSlot(h2);
|
||||||
if ((pe = RepPredProp(
|
if ((pe = RepPredProp(
|
||||||
Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) &&
|
Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||||
out = TRUE;
|
return complete_ge(true, omod, sl, creeping);
|
||||||
goto complete;
|
|
||||||
}
|
}
|
||||||
/* user:term_expansion(A,B) */
|
return complete_ge(false, omod, sl, creeping);
|
||||||
if (cmod != USER_MODULE && /* we have tried this before */
|
|
||||||
(pe = RepPredProp(
|
|
||||||
Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE))) &&
|
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
|
||||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
|
||||||
out = TRUE;
|
|
||||||
}
|
|
||||||
complete:
|
|
||||||
if (creeping) {
|
|
||||||
Yap_signal(YAP_CREEP_SIGNAL);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int execute0(USES_REGS1) { /* '$execute0'(Goal,Mod) */
|
static Int execute0(USES_REGS1) { /* '$execute0'(Goal,Mod) */
|
||||||
Term t = Deref(ARG1), t0 = t;
|
Term t = Deref(ARG1), t0 = t;
|
||||||
Term mod = Deref(ARG2);
|
Term mod = Deref(ARG2);
|
||||||
|
Reference in New Issue
Block a user