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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -106,6 +106,7 @@ class YAPInputSplitter(InputSplitter):
def validQuery(self, text, line=None): def validQuery(self, text, line=None):
"""Return whether a legal query """Return whether a legal query
""" """
print("valid")
if not line: if not line:
(_,line,_) = self.shell.prolog_cell(text) (_,line,_) = self.shell.prolog_cell(text)
line = line.strip().rstrip() line = line.strip().rstrip()
@ -524,67 +525,27 @@ class YAPRun:
self.yapeng.mgoal(errors(self,text),"user") self.yapeng.mgoal(errors(self,text),"user")
return self.errors return self.errors
def jupyter_query(self, s): def jupyter_query(self, s, mx):
# #
# construct a self.query from a one-line string # construct a self.query from a one-line string
# self.q is opaque to Python # self.q is opaque to Python
iterations = 0 iterations = 0
self.shell.bindings = {} 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"
program,query,_ = self.prolog_cell(s) program,query,_ = self.prolog_cell(s)
self.q = self.yapeng.query(jupyter_query(self, program, query)) if query == self.shell.os:
self.shell.Solutions = [] q = self.shell.q
if not self.q: self.shell.os = None
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
else: else:
print("No (more) answers") q = Goal(jupyter_query(self, query), self.yapeng, module="user",program=program)
self.q.close() for q in q:
self.q = None bindings += [q.bindings()]
self.os = '' iterations += 1
return True, self.shell.Solutions if mx == iterations:
break
def answer(self, q): if q:
try: self.shell.os = query
return q.next() self.shell.q = q
except Exception as e: return bindings
self.yapeng.goal(exit_cell(self))
return False, None
def _yrun_cell(self, raw_cell, store_history=True, silent=False, def _yrun_cell(self, raw_cell, store_history=True, silent=False,
@ -690,9 +651,9 @@ class YAPRun:
if store_history: if store_history:
self.shell.history_manager.store_inputs(self.shell.execution_count, self.shell.history_manager.store_inputs(self.shell.execution_count,
cell, raw_cell) cell, raw_cell)
silent = False
if not silent: if not silent:
self.shell.logger.log(cell, raw_cell) self.shell.logger.log(cell, raw_cell)
# # Display the exception if input processing failed. # # Display the exception if input processing failed.
# if preprocessing_exc_tuple is not None: # if preprocessing_exc_tuple is not None:
# self.showtraceback(preprocessing_exc_tuple) # self.showtraceback(preprocessing_exc_tuple)

View File

@ -71,10 +71,10 @@ elseif(CMAKE_CROSSCOMPILING)
) )
else () else ()
add_custom_target(STARTUP ALL 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} 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 VERBATIM
DEPENDS ${PL_BOOT_SOURCES} yap-bin DEPENDS ${PL_BOOT_SOURCES} yap-bin
) )

View File

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