user expansion
pretty
This commit is contained in:
parent
c927cd5133
commit
eabc869c69
87
C/exec.c
87
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) {
|
||||||
@ -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,38 +635,48 @@ 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;
|
||||||
@ -675,12 +686,11 @@ static Int _user_expand_goal(USES_REGS1) {
|
|||||||
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 */
|
||||||
@ -688,53 +698,42 @@ static Int _user_expand_goal(USES_REGS1) {
|
|||||||
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