This commit is contained in:
Vitor Santos Costa 2018-02-26 21:38:19 +00:00
parent 530246688c
commit 3a36285bb2
12 changed files with 1767 additions and 1807 deletions

270
C/stack.c
View File

@ -73,7 +73,7 @@ static StaticIndex *find_owner_static_index(StaticIndex *, yamop *);
static PredEntry *get_pred(Term t, Term tmod, char *pname) {
Term t0 = t;
restart:
restart:
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t0, pname);
return NULL;
@ -240,7 +240,7 @@ static yamop *cur_log_upd_clause(PredEntry *pe, yamop *codeptr) {
cl = ClauseCodeToLogUpdClause(pe->cs.p_code.FirstClause);
do {
if (IN_BLOCK(codeptr, cl->ClCode, cl->ClSize)) {
return ((yamop *) cl->ClCode);
return ((yamop *)cl->ClCode);
}
cl = cl->ClNext;
} while (cl != NULL);
@ -271,15 +271,15 @@ bool Yap_search_for_static_predicate_in_use(PredEntry *p,
I do not need to check environments for asserts,
only for retracts
*/
while (env_ptr && b_ptr > (choiceptr) env_ptr) {
yamop *cp = (yamop *) env_ptr[E_CP];
while (env_ptr && b_ptr > (choiceptr)env_ptr) {
yamop *cp = (yamop *)env_ptr[E_CP];
PredEntry *pe;
pe = EnvPreg(cp);
if (p == pe)
return true;
if (env_ptr != NULL)
env_ptr = (CELL *) (env_ptr[E_E]);
env_ptr = (CELL *)(env_ptr[E_E]);
}
}
/* now mark the choicepoint */
@ -349,11 +349,11 @@ static void do_toggle_static_predicates_in_use(int mask) {
PredEntry *pe;
/* check first environments that are younger than our latest choicepoint */
while (b_ptr > (choiceptr) env_ptr) {
PredEntry *pe = EnvPreg((yamop *) env_ptr[E_CP]);
while (b_ptr > (choiceptr)env_ptr) {
PredEntry *pe = EnvPreg((yamop *)env_ptr[E_CP]);
mark_pred(mask, pe);
env_ptr = (CELL *) (env_ptr[E_E]);
env_ptr = (CELL *)(env_ptr[E_E]);
}
/* now mark the choicepoint */
if ((b_ptr)) {
@ -402,7 +402,7 @@ static void clause_was_found(PredEntry *pp, Atom *pat, UInt *parity) {
if (parity)
*parity = 0;
if (pat)
*pat = (Atom) pp->FunctorOfPred;
*pat = (Atom)pp->FunctorOfPred;
} else {
if (pat)
*pat = NameOfFunctor(pp->FunctorOfPred);
@ -417,7 +417,7 @@ static void clause_was_found(PredEntry *pp, Atom *pat, UInt *parity) {
if (pp->ArityOfPE) {
*pat = NameOfFunctor(pp->FunctorOfPred);
} else {
*pat = (Atom) (pp->FunctorOfPred);
*pat = (Atom)(pp->FunctorOfPred);
}
}
}
@ -432,9 +432,9 @@ static int code_in_pred_lu_index(LogUpdIndex *icl, yamop *codeptr,
LogUpdIndex *cicl;
if (IN_BLOCK(codeptr, icl, icl->ClSize)) {
if (startp)
*startp = (CODEADDR) icl;
*startp = (CODEADDR)icl;
if (endp)
*endp = (CODEADDR) icl + icl->ClSize;
*endp = (CODEADDR)icl + icl->ClSize;
return TRUE;
}
cicl = icl->ChildIndex;
@ -451,9 +451,9 @@ static int code_in_pred_s_index(StaticIndex *icl, yamop *codeptr, void **startp,
StaticIndex *cicl;
if (IN_BLOCK(codeptr, icl, icl->ClSize)) {
if (startp)
*startp = (CODEADDR) icl;
*startp = (CODEADDR)icl;
if (endp)
*endp = (CODEADDR) icl + icl->ClSize;
*endp = (CODEADDR)icl + icl->ClSize;
return TRUE;
}
cicl = icl->ChildIndex;
@ -475,11 +475,11 @@ static Int find_code_in_clause(PredEntry *pp, yamop *codeptr, void **startp,
if (pp->PredFlags & LogUpdatePredFlag) {
LogUpdClause *cl = ClauseCodeToLogUpdClause(clcode);
do {
if (IN_BLOCK(codeptr, (CODEADDR) cl, cl->ClSize)) {
if (IN_BLOCK(codeptr, (CODEADDR)cl, cl->ClSize)) {
if (startp)
*startp = (CODEADDR) cl;
*startp = (CODEADDR)cl;
if (endp)
*endp = (CODEADDR) cl + cl->ClSize;
*endp = (CODEADDR)cl + cl->ClSize;
return i;
}
i++;
@ -492,9 +492,9 @@ static Int find_code_in_clause(PredEntry *pp, yamop *codeptr, void **startp,
cl = ClauseCodeToDynamicClause(clcode);
if (IN_BLOCK(codeptr, cl, cl->ClSize)) {
if (startp)
*startp = (CODEADDR) cl;
*startp = (CODEADDR)cl;
if (endp)
*endp = (CODEADDR) cl + cl->ClSize;
*endp = (CODEADDR)cl + cl->ClSize;
return i;
}
if (clcode == pp->cs.p_code.LastClause)
@ -508,10 +508,10 @@ static Int find_code_in_clause(PredEntry *pp, yamop *codeptr, void **startp,
cl = ClauseCodeToMegaClause(clcode);
if (IN_BLOCK(codeptr, cl, cl->ClSize)) {
if (startp)
*startp = (CODEADDR) cl;
*startp = (CODEADDR)cl;
if (endp)
*endp = (CODEADDR) cl + cl->ClSize;
return 1 + ((char *) codeptr - (char *) cl->ClCode) / cl->ClItemSize;
*endp = (CODEADDR)cl + cl->ClSize;
return 1 + ((char *)codeptr - (char *)cl->ClCode) / cl->ClItemSize;
}
} else {
StaticClause *cl;
@ -522,9 +522,9 @@ static Int find_code_in_clause(PredEntry *pp, yamop *codeptr, void **startp,
return 0;
if (IN_BLOCK(codeptr, cl, cl->ClSize)) {
if (startp)
*startp = (CODEADDR) cl;
*startp = (CODEADDR)cl;
if (endp)
*endp = (CODEADDR) cl + cl->ClSize;
*endp = (CODEADDR)cl + cl->ClSize;
return i;
}
if (cl->ClCode == pp->cs.p_code.LastClause)
@ -595,11 +595,11 @@ static int cl_code_in_pred(PredEntry *pp, yamop *codeptr, void **startp,
}
if (pp->PredFlags & (CPredFlag | AsmPredFlag | UserCPredFlag)) {
StaticClause *cl = ClauseCodeToStaticClause(pp->CodeOfPred);
if (IN_BLOCK(codeptr, (CODEADDR) cl, cl->ClSize)) {
if (IN_BLOCK(codeptr, (CODEADDR)cl, cl->ClSize)) {
if (startp)
*startp = (CODEADDR) cl;
*startp = (CODEADDR)cl;
if (endp)
*endp = (CODEADDR) cl + cl->ClSize;
*endp = (CODEADDR)cl + cl->ClSize;
UNLOCK(pp->PELock);
return TRUE;
} else {
@ -708,40 +708,40 @@ Int Yap_PredForCode(yamop *codeptr, find_pred_type where_from, Atom *pat,
static PredEntry *walk_got_lu_block(LogUpdIndex *cl, void **startp,
void **endp) {
PredEntry *pp = cl->ClPred;
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
return pp;
}
/* intruction blocks we found ourselves at */
static PredEntry *walk_got_lu_clause(LogUpdClause *cl, void **startp,
void **endp) {
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
return cl->ClPred;
}
/* we hit a meta-call, so we don't know what is happening */
static PredEntry *found_meta_call(void **startp, void **endp) {
PredEntry *pp = PredMetaCall;
*startp = (CODEADDR) &(pp->OpcodeOfPred);
*endp = (CODEADDR) NEXTOP((yamop *) &(pp->OpcodeOfPred), e);
*startp = (CODEADDR) & (pp->OpcodeOfPred);
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->OpcodeOfPred), e);
return pp;
}
/* intruction blocks we found ourselves at */
static PredEntry *walk_found_c_pred(PredEntry *pp, void **startp, void **endp) {
StaticClause *cl = ClauseCodeToStaticClause(pp->CodeOfPred);
*startp = (CODEADDR) &(cl->ClCode);
*endp = (CODEADDR) &(cl->ClCode) + cl->ClSize;
*startp = (CODEADDR) & (cl->ClCode);
*endp = (CODEADDR) & (cl->ClCode) + cl->ClSize;
return pp;
}
/* we hit a mega-clause, no point in going on */
static PredEntry *found_mega_clause(PredEntry *pp, void **startp, void **endp) {
MegaClause *mcl = ClauseCodeToMegaClause(pp->cs.p_code.FirstClause);
*startp = (CODEADDR) mcl;
*endp = (CODEADDR) mcl + mcl->ClSize;
*startp = (CODEADDR)mcl;
*endp = (CODEADDR)mcl + mcl->ClSize;
return pp;
}
@ -749,8 +749,8 @@ static PredEntry *found_mega_clause(PredEntry *pp, void **startp, void **endp) {
static PredEntry *found_idb_clause(yamop *pc, void **startp, void **endp) {
LogUpdClause *cl = ClauseCodeToLogUpdClause(pc);
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
return cl->ClPred;
}
@ -759,8 +759,8 @@ static PredEntry *found_expand_index(yamop *pc, void **startp, void **endp,
yamop *codeptr USES_REGS) {
PredEntry *pp = codeptr->y_u.sssllp.p;
if (pc == codeptr) {
*startp = (CODEADDR) codeptr;
*endp = (CODEADDR) NEXTOP(codeptr, sssllp);
*startp = (CODEADDR)codeptr;
*endp = (CODEADDR)NEXTOP(codeptr, sssllp);
}
return pp;
}
@ -768,17 +768,17 @@ static PredEntry *found_expand_index(yamop *pc, void **startp, void **endp,
/* we hit a expand_index, no point in going on */
static PredEntry *found_fail(yamop *pc, void **startp, void **endp USES_REGS) {
PredEntry *pp = RepPredProp(Yap_GetPredPropByAtom(AtomFail, CurrentModule));
*startp = *endp = (CODEADDR) FAILCODE;
*startp = *endp = (CODEADDR)FAILCODE;
return pp;
}
/* we hit a expand_index, no point in going on */
static PredEntry *found_owner_op(yamop *pc, void **startp,
void **endp USES_REGS) {
PredEntry *pp = ((PredEntry *) (Unsigned(pc) -
(CELL) (&(((PredEntry *) NULL)->OpcodeOfPred))));
*startp = (CODEADDR) &(pp->OpcodeOfPred);
*endp = (CODEADDR) NEXTOP((yamop *) &(pp->OpcodeOfPred), e);
PredEntry *pp = ((PredEntry *)(Unsigned(pc) -
(CELL)(&(((PredEntry *)NULL)->OpcodeOfPred))));
*startp = (CODEADDR) & (pp->OpcodeOfPred);
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->OpcodeOfPred), e);
return pp;
}
@ -786,10 +786,10 @@ static PredEntry *found_owner_op(yamop *pc, void **startp,
static PredEntry *found_expand(yamop *pc, void **startp,
void **endp USES_REGS) {
PredEntry *pp =
((PredEntry *) (Unsigned(pc) -
(CELL) (&(((PredEntry *) NULL)->cs.p_code.ExpandCode))));
*startp = (CODEADDR) &(pp->cs.p_code.ExpandCode);
*endp = (CODEADDR) NEXTOP((yamop *) &(pp->cs.p_code.ExpandCode), e);
((PredEntry *)(Unsigned(pc) -
(CELL)(&(((PredEntry *)NULL)->cs.p_code.ExpandCode))));
*startp = (CODEADDR) & (pp->cs.p_code.ExpandCode);
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->cs.p_code.ExpandCode), e);
return pp;
}
@ -798,9 +798,9 @@ static PredEntry *found_ystop(yamop *pc, int clause_code, void **startp,
if (pc == YESCODE) {
pp = RepPredProp(Yap_GetPredPropByAtom(AtomTrue, CurrentModule));
if (startp)
*startp = (CODEADDR) YESCODE;
*startp = (CODEADDR)YESCODE;
if (endp)
*endp = (CODEADDR) YESCODE + (CELL) (NEXTOP((yamop *) NULL, e));
*endp = (CODEADDR)YESCODE + (CELL)(NEXTOP((yamop *)NULL, e));
return pp;
}
if (!pp) {
@ -809,33 +809,33 @@ static PredEntry *found_ystop(yamop *pc, int clause_code, void **startp,
pp = o->y_u.Osbpp.p0;
} else {
/* must be an index */
PredEntry **pep = (PredEntry **) pc->y_u.l.l;
PredEntry **pep = (PredEntry **)pc->y_u.l.l;
pp = pep[-1];
}
}
if (pp->PredFlags & LogUpdatePredFlag) {
if (clause_code) {
LogUpdClause *cl = ClauseCodeToLogUpdClause(pc->y_u.l.l);
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
} else {
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(pc->y_u.l.l);
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
}
} else if (pp->PredFlags & DynamicPredFlag) {
DynamicClause *cl = ClauseCodeToDynamicClause(pc->y_u.l.l);
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
} else {
if (clause_code) {
StaticClause *cl = ClauseCodeToStaticClause(pc->y_u.l.l);
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
} else {
StaticIndex *cl = ClauseCodeToStaticIndex(pc->y_u.l.l);
*startp = (CODEADDR) cl;
*endp = (CODEADDR) cl + cl->ClSize;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)cl + cl->ClSize;
}
}
return pp;
@ -849,8 +849,8 @@ static PredEntry *ClauseInfoForCode(yamop *codeptr, void **startp,
if (codeptr >= COMMA_CODE && codeptr < FAILCODE) {
pp = RepPredProp(Yap_GetPredPropByFunc(FunctorComma, CurrentModule));
*startp = (CODEADDR) COMMA_CODE;
*endp = (CODEADDR) (FAILCODE - 1);
*startp = (CODEADDR)COMMA_CODE;
*endp = (CODEADDR)(FAILCODE - 1);
return pp;
}
pc = codeptr;
@ -913,9 +913,9 @@ static Int pred_for_code(USES_REGS1) {
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorStaticClause) {
codeptr = Yap_ClauseFromTerm(t)->ClCode;
} else if (IsIntegerTerm(t)) {
codeptr = (yamop *) IntegerOfTerm(t);
codeptr = (yamop *)IntegerOfTerm(t);
} else if (IsDBRefTerm(t)) {
codeptr = (yamop *) DBRefOfTerm(t);
codeptr = (yamop *)DBRefOfTerm(t);
} else {
return FALSE;
}
@ -933,7 +933,7 @@ static Int pred_for_code(USES_REGS1) {
static LogUpdIndex *find_owner_log_index(LogUpdIndex *cl, yamop *code_p) {
yamop *code_beg = cl->ClCode;
yamop *code_end = (yamop *) ((char *) cl + cl->ClSize);
yamop *code_end = (yamop *)((char *)cl + cl->ClSize);
if (code_p >= code_beg && code_p <= code_end) {
return cl;
@ -951,7 +951,7 @@ static LogUpdIndex *find_owner_log_index(LogUpdIndex *cl, yamop *code_p) {
static StaticIndex *find_owner_static_index(StaticIndex *cl, yamop *code_p) {
yamop *code_beg = cl->ClCode;
yamop *code_end = (yamop *) ((char *) cl + cl->ClSize);
yamop *code_end = (yamop *)((char *)cl + cl->ClSize);
if (code_p >= code_beg && code_p <= code_end) {
return cl;
@ -971,10 +971,10 @@ ClauseUnion *Yap_find_owner_index(yamop *ipc, PredEntry *ap) {
/* we assume we have an owner index */
if (ap->PredFlags & LogUpdatePredFlag) {
LogUpdIndex *cl = ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred);
return (ClauseUnion *) find_owner_log_index(cl, ipc);
return (ClauseUnion *)find_owner_log_index(cl, ipc);
} else {
StaticIndex *cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
return (ClauseUnion *) find_owner_static_index(cl, ipc);
return (ClauseUnion *)find_owner_static_index(cl, ipc);
}
}
@ -994,13 +994,13 @@ static Term all_envs(CELL *env_ptr USES_REGS) {
LOCAL_Error_Size = (ASP - 1024) - HR;
while (env_ptr) {
LOCAL_Error_Size += 2;
env_ptr = (CELL *) (env_ptr[E_E]);
env_ptr = (CELL *)(env_ptr[E_E]);
}
return 0L;
} else {
bp[1] = AbsPair(HR);
}
env_ptr = (CELL *) (env_ptr[E_E]);
env_ptr = (CELL *)(env_ptr[E_E]);
}
bp[1] = TermNil;
return tf;
@ -1015,7 +1015,7 @@ static Term all_cps(choiceptr b_ptr USES_REGS) {
bp = HR;
HR += 2;
/* notice that MkIntegerTerm may increase the HReap */
bp[0] = MkIntegerTerm((Int) (LCL0 - (CELL *) b_ptr));
bp[0] = MkIntegerTerm((Int)(LCL0 - (CELL *)b_ptr));
if (HR >= ASP - 1024) {
HR = start;
LOCAL_Error_Size = (ASP - 1024) - HR;
@ -1028,7 +1028,7 @@ static Term all_cps(choiceptr b_ptr USES_REGS) {
bp[1] = AbsPair(HR);
}
b_ptr = b_ptr->cp_b;
if (!IsVarTerm((CELL) b_ptr) || (CELL *) b_ptr < HR || (CELL *) b_ptr > LCL0) {
if (!IsVarTerm((CELL)b_ptr) || (CELL *)b_ptr < HR || (CELL *)b_ptr > LCL0) {
// Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "choice-point chain
// corrupted at %p!!!\n", b_ptr);
break;
@ -1066,7 +1066,7 @@ static Term clause_info(yamop *codeptr, PredEntry *pp) {
void *begin;
if (pp->ArityOfPE == 0) {
ts[0] = MkAtomTerm((Atom) pp->FunctorOfPred);
ts[0] = MkAtomTerm((Atom)pp->FunctorOfPred);
ts[1] = MkIntTerm(0);
} else {
ts[0] = MkAtomTerm(NameOfFunctor(pp->FunctorOfPred));
@ -1091,14 +1091,17 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) {
Term ts[2];
void *begin;
if (pp->ArityOfPE == 0) {
LOCAL_ActiveError->prologPredName = RepAtom((Atom) pp->FunctorOfPred)->StrOfAE;
LOCAL_ActiveError->prologPredName =
RepAtom((Atom)pp->FunctorOfPred)->StrOfAE;
LOCAL_ActiveError->prologPredArity = 0;
} else {
LOCAL_ActiveError->prologPredName = RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE;
LOCAL_ActiveError->prologPredName =
RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE;
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
}
LOCAL_ActiveError->prologPredModule =
(pp->ModuleOfPred ? RepAtom(AtomOfTerm(pp->ModuleOfPred))->StrOfAE : "prolog");
(pp->ModuleOfPred ? RepAtom(AtomOfTerm(pp->ModuleOfPred))->StrOfAE
: "prolog");
LOCAL_ActiveError->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
if (codeptr->opc == UNDEF_OPCODE) {
LOCAL_ActiveError->prologPredFirstLine = 0;
@ -1150,8 +1153,8 @@ static Term error_culprit(bool internal USES_REGS) {
while (curCP != YESCODE) {
if (pe->ModuleOfPred)
return clause_info(curCP, pe);
curENV = (CELL *) (curENV[E_E]);
curCP = (yamop *) (curENV[E_CP]);
curENV = (CELL *)(curENV[E_E]);
curCP = (yamop *)(curENV[E_CP]);
pe = EnvPreg(curCP);
}
}
@ -1171,7 +1174,7 @@ bool Yap_find_prolog_culprit(USES_REGS1) {
PredEntry *pe = EnvPreg(curCP);
while (curCP != YESCODE) {
curENV = (CELL *) (curENV[E_E]);
curENV = (CELL *)(curENV[E_E]);
if (curENV < ASP || curENV >= LCL0) {
break;
}
@ -1181,7 +1184,7 @@ bool Yap_find_prolog_culprit(USES_REGS1) {
}
if (pe->ModuleOfPred)
return set_clause_info(curCP, pe);
curCP = (yamop *) (curENV[E_CP]);
curCP = (yamop *)(curENV[E_CP]);
}
}
return TermNil;
@ -1235,7 +1238,7 @@ static Int current_stack(USES_REGS1) {
#if LOW_PROF
static void add_code_in_lu_index(LogUpdIndex *cl, PredEntry *pp) {
char *code_end = (char *) cl + cl->ClSize;
char *code_end = (char *)cl + cl->ClSize;
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_LU_INDEX);
cl = cl->ChildIndex;
while (cl != NULL) {
@ -1245,7 +1248,7 @@ static void add_code_in_lu_index(LogUpdIndex *cl, PredEntry *pp) {
}
static void add_code_in_static_index(StaticIndex *cl, PredEntry *pp) {
char *code_end = (char *) cl + cl->ClSize;
char *code_end = (char *)cl + cl->ClSize;
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_STATIC_INDEX);
cl = cl->ChildIndex;
while (cl != NULL) {
@ -1269,7 +1272,7 @@ static void add_code_in_pred(PredEntry *pp) {
clcode = pp->CodeOfPred;
cl = ClauseCodeToStaticClause(clcode);
code_end = (char *) cl + cl->ClSize;
code_end = (char *)cl + cl->ClSize;
Yap_inform_profiler_of_clause(cl, code_end, pp, GPROF_INIT_SYSTEM_CODE);
UNLOCK(pp->PELock);
return;
@ -1294,7 +1297,7 @@ static void add_code_in_pred(PredEntry *pp) {
do {
char *code_end;
code_end = (char *) cl + cl->ClSize;
code_end = (char *)cl + cl->ClSize;
Yap_inform_profiler_of_clause(cl, code_end, pp,
GPROF_INIT_LOG_UPD_CLAUSE);
cl = cl->ClNext;
@ -1305,7 +1308,7 @@ static void add_code_in_pred(PredEntry *pp) {
CODEADDR code_end;
cl = ClauseCodeToDynamicClause(clcode);
code_end = (CODEADDR) cl + cl->ClSize;
code_end = (CODEADDR)cl + cl->ClSize;
Yap_inform_profiler_of_clause(cl, code_end, pp,
GPROF_INIT_DYNAMIC_CLAUSE);
if (clcode == pp->cs.p_code.LastClause)
@ -1317,7 +1320,7 @@ static void add_code_in_pred(PredEntry *pp) {
do {
char *code_end;
code_end = (char *) cl + cl->ClSize;
code_end = (char *)cl + cl->ClSize;
Yap_inform_profiler_of_clause(cl, code_end, pp,
GPROF_INIT_STATIC_CLAUSE);
if (cl->ClCode == pp->cs.p_code.LastClause)
@ -1362,7 +1365,7 @@ void Yap_dump_code_area_for_profiler(void) {
#endif /* LOW_PROF */
static Int program_continuation(USES_REGS1) {
PredEntry *pe = EnvPreg((yamop *) ((ENV_Parent(ENV))[E_CP]));
PredEntry *pe = EnvPreg((yamop *)((ENV_Parent(ENV))[E_CP]));
if (pe->ModuleOfPred) {
if (!Yap_unify(ARG1, pe->ModuleOfPred))
return FALSE;
@ -1376,7 +1379,7 @@ static Int program_continuation(USES_REGS1) {
if (!Yap_unify(ARG3, MkIntegerTerm(ArityOfFunctor(pe->FunctorOfPred))))
return FALSE;
} else {
if (!Yap_unify(ARG2, MkAtomTerm((Atom) pe->FunctorOfPred)))
if (!Yap_unify(ARG2, MkAtomTerm((Atom)pe->FunctorOfPred)))
return FALSE;
if (!Yap_unify(ARG3, MkIntTerm(0)))
return FALSE;
@ -1389,7 +1392,7 @@ static Term BuildActivePred(PredEntry *ap, CELL *vect) {
arity_t i;
if (!ap->ArityOfPE) {
return MkVarTerm();
return MkAtomTerm((Atom)ap->FunctorOfPred);
}
for (i = 0; i < ap->ArityOfPE; i++) {
Term t = Deref(vect[i]);
@ -1416,7 +1419,7 @@ static int UnifyPredInfo(PredEntry *pe, int start_arg USES_REGS) {
tmod = pe->ModuleOfPred;
}
if (pe->ArityOfPE == 0) {
tname = MkAtomTerm((Atom) pe->FunctorOfPred);
tname = MkAtomTerm((Atom)pe->FunctorOfPred);
} else {
Functor f = pe->FunctorOfPred;
tname = MkAtomTerm(NameOfFunctor(f));
@ -1426,7 +1429,7 @@ static int UnifyPredInfo(PredEntry *pe, int start_arg USES_REGS) {
if (pe->PredFlags & NumberDBPredFlag) {
tname = MkIntegerTerm(pe->src.IndxId);
} else if (pe->PredFlags & AtomDBPredFlag) {
tname = MkAtomTerm((Atom) pe->FunctorOfPred);
tname = MkAtomTerm((Atom)pe->FunctorOfPred);
} else {
Functor f = pe->FunctorOfPred;
tname = MkAtomTerm(NameOfFunctor(f));
@ -1451,18 +1454,18 @@ static Int env_info(USES_REGS1) {
if (!env)
return FALSE;
env_b = MkIntegerTerm((Int) (LCL0 - (CELL *) env[E_CB]));
env_cp = (yamop *) env[E_CP];
env_b = MkIntegerTerm((Int)(LCL0 - (CELL *)env[E_CB]));
env_cp = (yamop *)env[E_CP];
/* pe = PREVOP(env_cp,Osbpp)->y_u.Osbpp.p0; */
taddr = MkIntegerTerm((Int) env);
return Yap_unify(ARG3, MkIntegerTerm((Int) env_cp)) &&
taddr = MkIntegerTerm((Int)env);
return Yap_unify(ARG3, MkIntegerTerm((Int)env_cp)) &&
Yap_unify(ARG2, taddr) && Yap_unify(ARG4, env_b);
}
static Int p_cpc_info(USES_REGS1) {
PredEntry *pe;
yamop *ipc = (yamop *) IntegerOfTerm(Deref(ARG1));
yamop *ipc = (yamop *)IntegerOfTerm(Deref(ARG1));
pe = PREVOP(ipc, Osbpp)->y_u.Osbpp.p0;
return UnifyPredInfo(pe, 2 PASS_REGS) &&
@ -1470,14 +1473,14 @@ static Int p_cpc_info(USES_REGS1) {
}
static Int p_choicepoint_info(USES_REGS1) {
choiceptr cptr = (choiceptr) (LCL0 - IntegerOfTerm(Deref(ARG1)));
choiceptr cptr = (choiceptr)(LCL0 - IntegerOfTerm(Deref(ARG1)));
PredEntry *pe = NULL;
int go_on = TRUE;
yamop *ipc = cptr->cp_ap;
yamop *ncl = NULL;
Term t = TermNil, taddr;
taddr = MkIntegerTerm((Int) cptr);
taddr = MkIntegerTerm((Int)cptr);
while (go_on) {
op_numbers opnum = Yap_op_from_opcode(ipc->opc);
go_on = FALSE;
@ -1509,7 +1512,7 @@ static Int p_choicepoint_info(USES_REGS1) {
#endif /* DETERMINISTIC_TABLING */
{
pe = GEN_CP(cptr)->cp_pred_entry;
t = BuildActivePred(pe, (CELL *) (GEN_CP(B) + 1));
t = BuildActivePred(pe, (CELL *)(GEN_CP(B) + 1));
}
#else
pe = UndefCode;
@ -1639,8 +1642,7 @@ static Int p_choicepoint_info(USES_REGS1) {
Atom at = AtomLive;
t = MkAtomTerm(at);
pe = RepPredProp(PredPropByAtom(at, CurrentModule));
}
break;
} break;
case _Ystop:
default:
return FALSE;
@ -1699,8 +1701,8 @@ static int legal_env(CELL *ep USES_REGS) {
cp = ep[E_CP];
if (!ONHEAP(cp))
return (FALSE);
ps = *((CELL *) (Addr(cp) - CellSize));
pe = (PredEntry *) (ps - sizeof(OPREG) - sizeof(Prop));
ps = *((CELL *)(Addr(cp) - CellSize));
pe = (PredEntry *)(ps - sizeof(OPREG) - sizeof(Prop));
PELOCK(70, pe);
if (!ONHEAP(pe) || Unsigned(pe) & 3 || pe->KindOfPE & 0xff00) {
UNLOCK(pe->PELock);
@ -1746,14 +1748,14 @@ void Yap_dump_stack(void) {
#if DEBUG
fprintf(stderr, "%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p\n",
P, CP, ASP, HR, TR, HeapTop);
fprintf(stderr, "%% YAP mode: %ux\n", (unsigned int) LOCAL_PrologMode);
fprintf(stderr, "%% YAP mode: %ux\n", (unsigned int)LOCAL_PrologMode);
if (LOCAL_ErrorMessage)
fprintf(stderr, "%% LOCAL_ErrorMessage: %s\n", LOCAL_ErrorMessage);
#endif
if (HR > ASP || HR > LCL0) {
fprintf(stderr, "%% YAP ERROR: Global Collided against Local (%p--%p)\n",
HR, ASP);
} else if (HeapTop > (ADDR) LOCAL_GlobalBase) {
} else if (HeapTop > (ADDR)LOCAL_GlobalBase) {
fprintf(stderr,
"%% YAP ERROR: Code Space Collided against Global (%p--%p)\n",
HeapTop, LOCAL_GlobalBase);
@ -1773,18 +1775,18 @@ void Yap_dump_stack(void) {
#endif
#endif
Yap_detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, 256);
fprintf(stderr, "%%\n%% PC: %s\n", (char *) HR);
fprintf(stderr, "%%\n%% PC: %s\n", (char *)HR);
Yap_detect_bug_location(CP, FIND_PRED_FROM_ANYWHERE, 256);
fprintf(stderr, "%% Continuation: %s\n", (char *) HR);
fprintf(stderr, "%% Continuation: %s\n", (char *)HR);
fprintf(stderr, "%% %luKB of Global Stack (%p--%p)\n",
(unsigned long int) (sizeof(CELL) * (HR - H0)) / 1024, H0, HR);
(unsigned long int)(sizeof(CELL) * (HR - H0)) / 1024, H0, HR);
fprintf(stderr, "%% %luKB of Local Stack (%p--%p)\n",
(unsigned long int) (sizeof(CELL) * (LCL0 - ASP)) / 1024, ASP, LCL0);
(unsigned long int)(sizeof(CELL) * (LCL0 - ASP)) / 1024, ASP, LCL0);
fprintf(stderr, "%% %luKB of Trail (%p--%p)\n",
(unsigned long int) ((ADDR) TR - LOCAL_TrailBase) / 1024,
(unsigned long int)((ADDR)TR - LOCAL_TrailBase) / 1024,
LOCAL_TrailBase, TR);
fprintf(stderr, "%% Performed %ld garbage collections\n",
(unsigned long int) LOCAL_GcCalls);
(unsigned long int)LOCAL_GcCalls);
#if LOW_LEVEL_TRACER
{
extern long long vsc_count;
@ -1802,9 +1804,9 @@ void Yap_dump_stack(void) {
fprintf(stderr, "%% Goals With Alternatives Open (Global In "
"Use--Local In Use)\n%%\n");
while (b_ptr != NULL) {
while (env_ptr && env_ptr <= (CELL *) b_ptr) {
while (env_ptr && env_ptr <= (CELL *)b_ptr) {
Yap_detect_bug_location(ipc, FIND_PRED_FROM_ENV, 256);
if (env_ptr == (CELL *) b_ptr && (choiceptr) env_ptr[E_CB] > b_ptr) {
if (env_ptr == (CELL *)b_ptr && (choiceptr)env_ptr[E_CB] > b_ptr) {
b_ptr = b_ptr->cp_b;
fprintf(stderr, "%% %s\n", tp);
} else {
@ -1814,8 +1816,8 @@ void Yap_dump_stack(void) {
fprintf(stderr, "%% .....\n");
return;
}
ipc = (yamop *) (env_ptr[E_CP]);
env_ptr = (CELL *) (env_ptr[E_E]);
ipc = (yamop *)(env_ptr[E_CP]);
env_ptr = (CELL *)(env_ptr[E_E]);
}
if (b_ptr) {
if (!max_count--) {
@ -1829,8 +1831,8 @@ void Yap_dump_stack(void) {
/* we can safely ignore ; because there is always an upper env */
Yap_detect_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256);
fprintf(stderr, "%% %s (%luKB--%luKB)\n", tp,
(unsigned long int) ((b_ptr->cp_h - H0) * sizeof(CELL) / 1024),
(unsigned long int) ((ADDR) LCL0 - (ADDR) b_ptr) / 1024);
(unsigned long int)((b_ptr->cp_h - H0) * sizeof(CELL) / 1024),
(unsigned long int)((ADDR)LCL0 - (ADDR)b_ptr) / 1024);
}
b_ptr = b_ptr->cp_b;
}
@ -1856,7 +1858,7 @@ void DumpActiveGoals(USES_REGS1) {
cp = ep[E_CP];
if (!ONHEAP(cp) || (Unsigned(cp) & (sizeof(CELL) - 1)))
break;
pe = EnvPreg((yamop *) cp);
pe = EnvPreg((yamop *)cp);
if (!ONHEAP(pe) || Unsigned(pe) & (sizeof(CELL) - 1))
break;
PELOCK(71, pe);
@ -1884,7 +1886,7 @@ void DumpActiveGoals(USES_REGS1) {
UNLOCK(pe->PELock);
}
next:
ep = (CELL *) ep[E_E];
ep = (CELL *)ep[E_E];
}
first = 1;
fprintf(stderr, "Active Choice-Points:\n");
@ -1916,7 +1918,7 @@ void DumpActiveGoals(USES_REGS1) {
Yap_plwrite(MkIntegerTerm(id), GLOBAL_Stream + 2, 0, 0,
GLOBAL_MaxPriority);
} else if (pe->PredFlags & AtomDBPredFlag) {
Atom At = (Atom) pe->FunctorOfPred;
Atom At = (Atom)pe->FunctorOfPred;
Yap_plwrite(MkAtomTerm(At), GLOBAL_Stream + 2, 0, 0,
GLOBAL_MaxPriority);
} else {
@ -1939,7 +1941,7 @@ void DumpActiveGoals(USES_REGS1) {
Yap_plwrite(b_ptr->cp_a2, GLOBAL_Stream + 2, 0, 0, GLOBAL_MaxPriority);
fputc(')', stderr);
} else if (pe->ArityOfPE == 0) {
Yap_plwrite(MkAtomTerm((Atom) f), GLOBAL_Stream + 2, 0, 0,
Yap_plwrite(MkAtomTerm((Atom)f), GLOBAL_Stream + 2, 0, 0,
GLOBAL_MaxPriority);
} else {
Int i = 0, arity = pe->ArityOfPE;
@ -1984,15 +1986,15 @@ void Yap_detect_bug_location(yamop *yap_pc, int where_from, int psize) {
fprintf(stderr, "%s", "meta-call");
} else if (pred_module == 0) {
fprintf(stderr, "in prolog:%s/%lu", RepAtom(pred_name)->StrOfAE,
(unsigned long int) pred_arity);
(unsigned long int)pred_arity);
} else if (cl < 0) {
fprintf(stderr, "%s:%s/%lu", RepAtom(AtomOfTerm(pred_module))->StrOfAE,
RepAtom(pred_name)->StrOfAE, (unsigned long int) pred_arity);
RepAtom(pred_name)->StrOfAE, (unsigned long int)pred_arity);
} else {
fprintf(stderr, "%s:%s/%lu at clause %lu",
RepAtom(AtomOfTerm(pred_module))->StrOfAE,
RepAtom(pred_name)->StrOfAE, (unsigned long int) pred_arity,
(unsigned long int) cl);
RepAtom(pred_name)->StrOfAE, (unsigned long int)pred_arity,
(unsigned long int)cl);
}
}
@ -2006,8 +2008,10 @@ static Term build_bug_location(yamop *codeptr, PredEntry *pe) {
if (pe->ArityOfPE)
p[1] = MkAtomTerm(NameOfFunctor(pe->FunctorOfPred));
else
p[1] = MkAtomTerm((Atom) pe->FunctorOfPred);
p[1] = MkAtomTerm((Atom)pe->FunctorOfPred);
p[2] = MkIntegerTerm(pe->ArityOfPE);
p[3] = TermNil;
p[4] = MkIntTerm(0);
if (pe->src.OwnerFile) {
p[3] = MkAtomTerm(pe->src.OwnerFile);
if (pe->PredFlags & MegaClausePredFlag) {
@ -2043,10 +2047,12 @@ static Term build_bug_location(yamop *codeptr, PredEntry *pe) {
p[4] = MkIntTerm(0);
}
}
} else if (pe->OpcodeOfPred == UNDEF_OPCODE) {
}
else if (pe->OpcodeOfPred == UNDEF_OPCODE) {
RESET_VARIABLE(p + 3);
RESET_VARIABLE(p + 4);
} else {
}
else {
// by default, user_input
p[3] = MkAtomTerm(AtomUserIn);
p[4] = MkIntTerm(0);
@ -2090,7 +2096,7 @@ Term Yap_env_location(yamop *cp, choiceptr b_ptr, CELL *env, Int ignore_first) {
env = b_ptr->cp_env;
b_ptr = b_ptr->cp_b;
} else {
cp = (yamop *) env[E_CP];
cp = (yamop *)env[E_CP];
env = ENV_Parent(env);
}
ignore_first--;

View File

@ -233,15 +233,16 @@ static const char * join(const char *s, ...) {
CACHE_REGS
va_list args;
va_start(args , s);
int lvl = push_text_stack();
char *buf = Malloc(FILENAME_MAX+1);
// int lvl = push_text_stack();
char *buf = malloc(FILENAME_MAX+1);
if (s && s[0])
strcpy(buf, s);
while (true) {
const char *fmt = va_arg(args, char *);
if (fmt == NULL) {
va_end(args);
return pop_output_text_stack(lvl,buf);
// return pop_output_text_stack(lvl,buf);
return buf;
}
strcat(buf, fmt);
}

View File

@ -186,7 +186,6 @@ public:
/// @brief Setup all arguments to a new engine
struct X_API YAPEngineArgs : YAP_init_args {
public:
YAPEngineArgs() {
// const std::string *s = new std::string("startup.yss");
@ -223,30 +222,19 @@ public:
strcpy((char *)LIBDIR, fl);
};
inline const char *getLIBDIR() { return LIBDIR; };
inline void setSHAREDIR(const char *fl) {
SHAREDIR = (const char *)malloc(strlen(fl) + 1);
strcpy((char *)SHAREDIR, fl);
};
inline const char *getSHAREDIR() { return SHAREDIR; };
inline void setINPUT_RESTORE(const char *fl) {
STARTUP = (const char *)malloc(strlen(fl) + 1);
inline const char *setINPUT_STARTUP(const char *fl) {
INPUT_STARTUP = (const char *)malloc(strlen(fl) + 1);
strcpy((char *)INPUT_STARTUP, fl);
};
inline const char *getINPUT_STARTUP() { return INPUT_STARTUP; };
inline void setOUTPUT_RESTORE(const char *fl) {
STARTUP = (const char *)malloc(strlen(fl) + 1);
OUTPUT_STARTUP = (const char *)malloc(strlen(fl) + 1);
strcpy((char *)OUTPUT_STARTUP, fl);
};
inline const char *getINPUT_STARTUP() { return OUTPUT_STARTUP; };
inline const char *getOUTPUT_STARTUP() { return OUTPUT_STARTUP; };
inline void setBOOTFILE(const char *fl) {
BOOTFILE = (const char *)malloc(strlen(fl) + 1);
@ -287,7 +275,6 @@ public:
inline void setArgv(char **fl) { Argv = fl; };
inline char **getArgv() { return Argv; };
};
/**

View File

@ -2041,9 +2041,9 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
#endif
/* init-time boot */
##ifndef YAP_OUTPUT_STARTUP
##define YAP_OUTPUT_STARTUP "${CMAKE_BINARY_DIR}/${YAP_STARTUP}"
##endif
#ifndef YAP_OUTPUT_STARTUP
#define YAP_OUTPUT_STARTUP "${CMAKE_BINARY_DIR}/${YAP_STARTUP}"
#endif
/* HP-UX old socket stuff */
#ifndef _XOPEN_SOURCE

View File

@ -2196,7 +2196,7 @@ X_API int PL_initialise(int myargc, char **myargv) {
#if BOOT_FROM_SAVED_STATE
init_args.STARTUP = "startup.yss";
#else
init_args.STARTUP = NULL;
init_args.INPUT_STARTUP = NULL;
#endif
init_args.LIBDIR = NULL;
init_args.BOOTFILE = NULL;

View File

@ -31,14 +31,14 @@ static void *
py_open(VFS_t *me, int sno, const char *name,
const char *io_mode) {
#if HAVE_STRCASESTR
if (strcasestr(name, "//python/") == name)
name += strlen("//python/");
if (strcasestr(name, "/python/") == name)
name += strlen("/python/");
#else
if (strstr(name, "//python/") == name)
name += strlen("//python/");
if (strstr(name, "/python/") == name)
name += strlen("/python/");
#endif
StreamDesc *st = YAP_RepStreamFromId(sno);
fprintf(stderr,"opened %p\n");
fprintf(stderr,"opened %d\n", sno);
// we assume object is already open, so there is no need to open it.
PyObject *stream = string_to_python(name, true, NULL);
if (stream == Py_None)
@ -133,8 +133,8 @@ static bool init_python_stream(void) {
pystream.name = "python stream";
pystream.vflags =
VFS_CAN_WRITE | VFS_CAN_EXEC | VFS_CAN_SEEK | VFS_HAS_PREFIX;
pystream.prefix = "//python/";
VFS_CAN_WRITE | VFS_CAN_EXEC | VFS_CAN_READ | VFS_HAS_PREFIX;
pystream.prefix = "/python/";
pystream.suffix = NULL;
pystream.open = py_open;
pystream.close = py_close;

View File

@ -1,8 +1,8 @@
%% @file yapi.yap
%% @brief support yap shell
%%
:- module(yapi, [
:- start_low_level_trace.
:- module(yapi, [
python_ouput/0,
show_answer/2,
show_answer/3,
@ -10,7 +10,7 @@
python_query/2,
yapi_query/2
]).
:- stop_low_level_trace.
:- yap_flag(verbose, verbose).

View File

@ -5,7 +5,7 @@ import keyword
# debugging support.
# import pdb
from collections import namedtuple
import readline
from .yap import *
@ -44,46 +44,48 @@ class EngineArgs( YAPEngineArgs ):
class Predicate( YAPPredicate ):
""" Interface to Generic Predicate"""
class Predicate:
"""Goal is a predicate instantiated under a specific environment """
def __init__( self, name, args, module=None, engine = None):
self = namedtuple( name, args )
if module:
self.p = YAPPredicate( name, len(self), module )
else:
self.p = YAPPredicate( name, len(self) )
self.e = engine
def __init__(self, t, module=None):
super().__init__(t)
def goals( self, engine):
class Goal(object):
"""Goal is a predicate instantiated under a specific environment """
def __init__(self, g, engine, module="user",program=None, max_answers=None ):
self.g = g
self.e = engine
def __iter__(self):
return PrologTableIter(self.e, self.p)
def holds(self):
return self.e.run(self._make_())
return PrologTableIter( self.e, self.g )
class PrologTableIter:
def __init__(self, e, goal):
def __init__(self, e, query):
try:
self.e = e
self.q = e.YAPQuery(goal)
self.q = e.query(python_query(self, query))
except:
print('Error')
def __iter__(self):
# Iterators are iterables too.
# Adding this functions to make them so.
# - # Adding this functions to make them so.
return self
def next(self):
def __next__(self):
if not self.q:
raise StopIteration()
if self.q.next():
return goal
rc = self.q.bindings
if self.q.port == "exit":
self.close()
return rc
else:
if self.q:
self.close()
raise StopIteration()
def close(self):
self.q.close()
self.q = None
raise StopIteration()
f2p = {"fails":{}}
for i in range(16):
@ -148,24 +150,15 @@ def numbervars( q ):
class YAPShell:
def answer(self, q):
try:
self.bindings = {}
v = q.next()
if v:
print( self.bindings )
return v
except Exception as e:
print(e.args[1])
return False
def query_prolog(self, engine, s):
# import pdb; pdb.set_trace()
def query_prolog(self, engine, query):
import pdb; pdb.set_trace()
#
# construct a query from a one-line string
# q is opaque to Python
#
q = engine.query(python_query(self, s))
#q = engine.query(python_query(self, s))
#
# # vs is the list of variables
# you can print it out, the left-side is the variable name,
@ -179,15 +172,18 @@ class YAPShell:
# print( "Error: Variable Name matches a Python Symbol")
# return
do_ask = True
self.port = "call"
# launch the query
while self.answer(q):
if self.port == "exit":
# done
q.close()
return True, True
self.e = engine
bindings = []
if not self.q:
self.it = PrologTableIter( self.e, query )
for bind in self.it:
bindings += [bind]
if do_ask:
print(bindings)
bindings = []
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
else:
s = ";"
if s.startswith(';') or s.startswith('y'):
continue
elif s.startswith('#'):
@ -200,12 +196,17 @@ class YAPShell:
continue
else:
break
if self.q:
self.os = query
if bindings:
return True,bindings
print("No (more) answers")
q.close()
return
return False, None
def live(self, engine, **kwargs):
loop = True
self.q = None
while loop:
try:
s = input("?- ")

View File

@ -20,7 +20,7 @@
%% ).
:- reexport(library(yapi)).
%:- reexport(library(yapi)).
:- use_module(library(lists)).
:- use_module(library(maplist)).
:- use_module(library(python)).
@ -28,6 +28,7 @@
:- python_import(sys).
jupyter_query(Self, Cell, Line ) :-
start_low_level_trace,
setup_call_cleanup(
enter_cell(Self),
jupyter_cell(Self, Cell, Line),
@ -61,15 +62,15 @@ blankc('\n').
blankc('\t').
enter_cell(_Self) :-
open('//python/input', read, Input, []),
open('//python/sys.stdout', append, Output, []),
open('//python/sys.stdout', append, Error, []),
open('/python/input', read, Input, []),
open('/python/sys.stdout', append, Output, []),
open('/python/sys.stdout', append, Error, []),
set_prolog_flag(user_input, Input),
set_prolog_flag(user_output, Output),
set_prolog_flag(user_error, Error).
exit_cell(_Self) :-
%close( user_input),
close( user_input),
close( user_output),
close( user_error).

View File

@ -106,6 +106,7 @@ class YAPInputSplitter(InputSplitter):
def validQuery(self, text, line=None):
"""Return whether a legal query
"""
print("valid")
if not line:
(_,line,_) = self.shell.prolog_cell(text)
line = line.strip().rstrip()
@ -524,67 +525,27 @@ class YAPRun:
self.yapeng.mgoal(errors(self,text),"user")
return self.errors
def jupyter_query(self, s):
def jupyter_query(self, s, mx):
#
# construct a self.query from a one-line string
# self.q is opaque to Python
iterations = 0
self.shell.bindings = {}
if self.q and s != self.os:
self.q.close()
self.q = None
if not self.q:
#import pdb; pdb.set_trace()
self.shell.port = "call"
bindings = []
program,query,_ = self.prolog_cell(s)
self.q = self.yapeng.query(jupyter_query(self, program, query))
self.shell.Solutions = []
if not self.q:
return True, []
self.os = s
# vs is the list of variables
# you can print it out, the left-side is the variable name,
# the right side wraps a handle to a variable
# pdb.set_trace()
# #pdb.set_trace()
# atom match either symbols, or if no symbol exists, sttrings, In this case
# variable names should match strings
#for eq in vs:
# if not isinstance(eq[0],str):x
# print( "Error: Variable Name matches a Python Symbol")
# return
# ask = True
# launch the query
# run the new command using the given tracer
while True:
iterations = iterations - 1
rc = YAPRun.answer(self, self.q)
if rc:
# deterministic = one solution
#Dict = {}
#engine.goal(show_answer( q.namedVars(), Dict))
self.shell.Solutions += [self.shell.bindings]
if self.shell.port == "exit":
# done
self.q.close()
self.q = None
self.os = ""
return True, self.shell.Solutions
if iterations == 0:
return True, self.shell.Solutions
if query == self.shell.os:
q = self.shell.q
self.shell.os = None
else:
print("No (more) answers")
self.q.close()
self.q = None
self.os = ''
return True, self.shell.Solutions
def answer(self, q):
try:
return q.next()
except Exception as e:
self.yapeng.goal(exit_cell(self))
return False, None
q = Goal(jupyter_query(self, query), self.yapeng, module="user",program=program)
for q in q:
bindings += [q.bindings()]
iterations += 1
if mx == iterations:
break
if q:
self.shell.os = query
self.shell.q = q
return bindings
def _yrun_cell(self, raw_cell, store_history=True, silent=False,
@ -690,9 +651,9 @@ class YAPRun:
if store_history:
self.shell.history_manager.store_inputs(self.shell.execution_count,
cell, raw_cell)
silent = False
if not silent:
self.shell.logger.log(cell, raw_cell)
# # Display the exception if input processing failed.
# if preprocessing_exc_tuple is not None:
# self.showtraceback(preprocessing_exc_tuple)

View File

@ -71,10 +71,10 @@ elseif(CMAKE_CROSSCOMPILING)
)
else ()
add_custom_target(STARTUP ALL
DEPENDS ${CMAKE_BUILD_DIR}/${YAP_STARTUPFILE}
DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
)
add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
COMMAND yap-bin -B${CMAKE_SOURCE_DIR}/pl/boot.yap --output-saved-state=${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
COMMAND yap-bin -B
VERBATIM
DEPENDS ${PL_BOOT_SOURCES} yap-bin
)

View File

@ -365,6 +365,7 @@ system_module(Mod) :-
functor(G0, N, K),
'$autoloader_find_predicate'(G0,ExportingMod),
ExportingMod \= ImportingMod,
writeln((ExportingMod,ImportingMod,G0,G0, N ,K)),
(recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_) -> true ; true ).
@ -491,9 +492,11 @@ export_list(Module, List) :-
G1=..[N1|Args],
( '$check_import'(M0,ContextMod,N1,K) ->
( ContextMod == prolog ->
writeln((M0,ContextMod,G0,G1,N1,K)),
recordzifnot('$import','$import'(M0,user,G0,G1,N1,K),_),
fail
;
writeln((M0,ContextMod,G0,G1,N1,K)),
recordaifnot('$import','$import'(M0,ContextMod,G0,G1,N1,K),_),
fail
;