Merge branch 'master' of ssh://yap.git.sf.net/gitroot/yap/yap-6.3

This commit is contained in:
Vitor Santos Costa 2011-06-04 09:33:50 +01:00
commit 8d4f51e098
182 changed files with 15202 additions and 5782 deletions

154
C/absmi.c
View File

@ -784,8 +784,8 @@ Yap_absmi(int inp)
op_switch:
#ifdef ANALYST
Yap_opcount[opcode]++;
Yap_2opcount[old_op][opcode]++;
GLOBAL_opcount[opcode]++;
GLOBAL_2opcount[old_op][opcode]++;
#ifdef DEBUG_XX
ops_done++;
/* if (B->cp_b > 0x103fff90)
@ -806,7 +806,7 @@ Yap_absmi(int inp)
saveregs();
/* do a garbage collection first to check if we can recover memory */
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -1556,24 +1556,24 @@ Yap_absmi(int inp)
SET_ASP(YREG, E_CB*sizeof(CELL));
saveregs();
while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
UNLOCKPE(3,PP);
#if defined(YAPOR) || defined(THREADS)
PP = NULL;
#endif
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
FAIL();
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gc(3, ENV, CP)) {
UNLOCKPE(4,PP);
#if defined(YAPOR) || defined(THREADS)
PP = NULL;
#endif
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
FAIL();
}
}
@ -1606,7 +1606,7 @@ Yap_absmi(int inp)
if (!(cl->ClFlags & InUseMask)) {
/* Clause *cl = (Clause *)PREG->u.EC.ClBase;
PREG->u.EC.ClTrail = TR-(tr_fr_ptr)Yap_TrailBase;
PREG->u.EC.ClTrail = TR-(tr_fr_ptr)LOCAL_TrailBase;
PREG->u.EC.ClENV = LCL0-YREG;*/
cl->ClFlags |= InUseMask;
TRAIL_CLREF(cl);
@ -1658,7 +1658,7 @@ Yap_absmi(int inp)
if (!(cl->ClFlags & InUseMask)) {
/* Clause *cl = (Clause *)PREG->u.EC.ClBase;
PREG->u.EC.ClTrail = TR-(tr_fr_ptr)Yap_TrailBase;
PREG->u.EC.ClTrail = TR-(tr_fr_ptr)LOCAL_TrailBase;
PREG->u.EC.ClENV = LCL0-YREG;*/
cl->ClFlags |= InUseMask;
TRAIL_CLREF(cl);
@ -1693,7 +1693,7 @@ Yap_absmi(int inp)
SET_ASP(YREG, PREG->u.Osbpi.s);
saveregs();
if (!Yap_gcl(sz, arity, YENV, PREG)) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
FAIL();
} else {
@ -2021,7 +2021,7 @@ Yap_absmi(int inp)
#endif /* LOW_LEVEL_TRACER */
#ifdef FROZEN_STACKS
#ifdef YAPOR_SBA
if (pt0 < TR_FZ || pt0 > (tr_fr_ptr)Yap_TrailTop)
if (pt0 < TR_FZ || pt0 > (tr_fr_ptr)LOCAL_TrailTop)
#else
if (pt0 < TR_FZ)
#endif /* YAPOR_SBA */
@ -2057,7 +2057,7 @@ Yap_absmi(int inp)
register CELL flags;
CELL *pt1 = RepPair(d1);
#ifdef LIMIT_TABLING
if ((ADDR) pt1 == Yap_TrailBase) {
if ((ADDR) pt1 == LOCAL_TrailBase) {
sg_fr_ptr sg_fr = (sg_fr_ptr) TrailVal(pt0);
TrailTerm(pt0) = AbsPair((CELL *)(pt0 - 1));
SgFr_state(sg_fr)--; /* complete_in_use --> complete : compiled_in_use --> compiled */
@ -2071,7 +2071,7 @@ Yap_absmi(int inp)
#ifdef YAPOR_SBA
(ADDR) pt1 >= HeapTop
#else
IN_BETWEEN(Yap_TrailBase, pt1, Yap_TrailTop)
IN_BETWEEN(LOCAL_TrailBase, pt1, LOCAL_TrailTop)
#endif /* YAPOR_SBA */
)
{
@ -2609,7 +2609,7 @@ Yap_absmi(int inp)
SET_ASP(YREG, PREG->u.Osbpp.s);
saveregs();
if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, YREG, NEXTOP(PREG, Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs();
@ -2663,7 +2663,7 @@ Yap_absmi(int inp)
}
saveregs();
if (!Yap_gc(0, ENV, CPREG)) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs();
SREG = ASP;
@ -2842,7 +2842,7 @@ Yap_absmi(int inp)
ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs();
if (!Yap_gc(0, YREG, NEXTOP(PREG, Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs();
JMPNext();
@ -2967,7 +2967,7 @@ Yap_absmi(int inp)
ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs();
if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, (CELL *)YREG[E_E], (yamop *)YREG[E_CP])) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs();
/* hopefully, gc will succeeded, and we will retry
@ -2989,7 +2989,7 @@ Yap_absmi(int inp)
ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs();
if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, ENV, CPREG)) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs();
/* hopefully, gc will succeeded, and we will retry
@ -3037,12 +3037,12 @@ Yap_absmi(int inp)
/* I need this for Windows and other systems where SIGINT
is not proceesed by same thread as absmi */
LOCK(LOCAL_SignalLock);
if (Yap_PrologMode & (AbortMode|InterruptMode)) {
if (LOCAL_PrologMode & (AbortMode|InterruptMode)) {
CreepFlag = CalculateStackGap();
UNLOCK(LOCAL_SignalLock);
/* same instruction */
if (Yap_PrologMode & InterruptMode) {
Yap_PrologMode &= ~InterruptMode;
if (LOCAL_PrologMode & InterruptMode) {
LOCAL_PrologMode &= ~InterruptMode;
SET_ASP(YREG, E_CB*sizeof(CELL));
saveregs();
Yap_ProcessSIGINT();
@ -7102,7 +7102,7 @@ Yap_absmi(int inp)
yamop *savedP;
Yap_StartSlots( PASS_REGS1 );
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
{
PredEntry *p = PREG->u.Osbpp.p;
@ -7115,7 +7115,7 @@ Yap_absmi(int inp)
}
Yap_CloseSlots( PASS_REGS1 );
setregs();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
restore_machine_regs();
PREG = savedP;
}
@ -7283,7 +7283,7 @@ Yap_absmi(int inp)
#endif
SET_BB(B_YREG);
ENDCACHE_Y();
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
ASP = YREG;
/* for slots to work */
Yap_StartSlots( PASS_REGS1 );
@ -7293,7 +7293,7 @@ Yap_absmi(int inp)
EX = 0L;
restore_machine_regs();
setregs();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
Yap_CloseSlots( PASS_REGS1 );
if (!SREG) {
FAIL();
@ -7326,7 +7326,7 @@ Yap_absmi(int inp)
restore_args(PREG->u.OtapFs.s);
ENDCACHE_Y();
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
SET_ASP(YREG, E_CB*sizeof(CELL));
/* for slots to work */
Yap_StartSlots( PASS_REGS1 );
@ -7336,7 +7336,7 @@ Yap_absmi(int inp)
EX = 0L;
restore_machine_regs();
setregs();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
Yap_CloseSlots( PASS_REGS1 );
if (!SREG) {
#ifdef CUT_C
@ -9164,7 +9164,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9209,7 +9209,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9250,7 +9250,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9302,7 +9302,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9350,7 +9350,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9395,7 +9395,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9436,7 +9436,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9488,7 +9488,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9536,7 +9536,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9581,7 +9581,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9622,7 +9622,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9674,7 +9674,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9729,7 +9729,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9774,7 +9774,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9817,7 +9817,7 @@ Yap_absmi(int inp)
d0 = p_div(MkIntegerTerm(d1),Yap_Eval(d0));
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9865,7 +9865,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9917,7 +9917,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -9968,7 +9968,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10017,7 +10017,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10062,7 +10062,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10103,7 +10103,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10155,7 +10155,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10204,7 +10204,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10248,7 +10248,7 @@ Yap_absmi(int inp)
d0 = p_or(Yap_Eval(d0), MkIntegerTerm(d1));
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10289,7 +10289,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10341,7 +10341,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10394,7 +10394,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10440,7 +10440,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10481,7 +10481,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10525,7 +10525,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10578,7 +10578,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10627,7 +10627,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10678,7 +10678,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10722,7 +10722,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10765,7 +10765,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10810,7 +10810,7 @@ Yap_absmi(int inp)
BEGP(pt0);
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10860,7 +10860,7 @@ Yap_absmi(int inp)
setregs();
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -10909,7 +10909,7 @@ Yap_absmi(int inp)
}
if (d0 == 0L) {
saveregs();
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
@ -12007,7 +12007,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -12124,7 +12124,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -12234,7 +12234,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -12345,7 +12345,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -12484,7 +12484,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -12628,7 +12628,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -13008,7 +13008,7 @@ Yap_absmi(int inp)
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
setregs();
JMPNext();
} else {
@ -13253,7 +13253,7 @@ Yap_absmi(int inp)
}
saveregs_and_ycache();
if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, ENV, NEXTOP(PREG, Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs_and_ycache();
goto execute2_end;
@ -13458,7 +13458,7 @@ Yap_absmi(int inp)
}
saveregs_and_ycache();
if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, ENV, NEXTOP(PREG, Osbmp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs_and_ycache();
goto execute_end;
@ -13688,7 +13688,7 @@ Yap_absmi(int inp)
UNLOCK(LOCAL_SignalLock);
saveregs_and_ycache();
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage);
setregs_and_ycache();
FAIL();
}
@ -13732,7 +13732,7 @@ Yap_absmi(int inp)
UNLOCK(LOCAL_SignalLock);
saveregs_and_ycache();
if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, ENV, NEXTOP(PREG, Osbpp))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
}
setregs_and_ycache();
goto execute_after_comma;

47
C/agc.c
View File

@ -18,7 +18,6 @@
static char SccsId[] = "@(#)agc.c 1.3 3/15/90";
#endif
#include "absmi.h"
#include "Foreign.h"
#include "alloc.h"
@ -30,20 +29,12 @@ static char SccsId[] = "@(#)agc.c 1.3 3/15/90";
/* #define DEBUG_RESTORE1 1 */
/* #define DEBUG_RESTORE2 1 */
/* #define DEBUG_RESTORE3 1 */
#define errout Yap_stderr
#define errout GLOBAL_stderr
#endif
STATIC_PROTO(void RestoreEntries, (PropEntry *, int USES_REGS));
STATIC_PROTO(void CleanCode, (PredEntry * USES_REGS));
static int agc_calls;
static YAP_ULONG_LONG agc_collected;
static Int tot_agc_time = 0; /* total time spent in GC */
static Int tot_agc_recovered = 0; /* number of heap objects in all garbage collections */
#define AtomMarkedBit 1
static inline void
@ -228,11 +219,11 @@ static void init_reg_copies(USES_REGS1)
LOCAL_OldASP = ASP;
LOCAL_OldLCL0 = LCL0;
LOCAL_OldTR = TR;
LOCAL_OldGlobalBase = (CELL *)Yap_GlobalBase;
LOCAL_OldGlobalBase = (CELL *)LOCAL_GlobalBase;
LOCAL_OldH = H;
LOCAL_OldH0 = H0;
LOCAL_OldTrailBase = Yap_TrailBase;
LOCAL_OldTrailTop = Yap_TrailTop;
LOCAL_OldTrailBase = LOCAL_TrailBase;
LOCAL_OldTrailTop = LOCAL_TrailTop;
LOCAL_OldHeapBase = Yap_HeapBase;
LOCAL_OldHeapTop = HeapTop;
}
@ -262,7 +253,7 @@ mark_trail(USES_REGS1)
pt = TR;
/* moving the trail is simple */
while (pt != (tr_fr_ptr)Yap_TrailBase) {
while (pt != (tr_fr_ptr)LOCAL_TrailBase) {
CELL reg = TrailTerm(pt-1);
if (!IsVarTerm(reg)) {
@ -393,12 +384,12 @@ clean_atom_list(AtomHashEntry *HashPtr)
#ifdef DEBUG_RESTORE3
fprintf(stderr, "Purged %p:%S\n", at, at->WStrOfAE);
#endif
agc_collected += sizeof(AtomEntry)+wcslen(at->WStrOfAE);
GLOBAL_agc_collected += sizeof(AtomEntry)+wcslen(at->WStrOfAE);
} else {
#ifdef DEBUG_RESTORE3
fprintf(stderr, "Purged %p:%s patm=%p %p\n", at, at->StrOfAE, patm, at->NextOfAE);
#endif
agc_collected += sizeof(AtomEntry)+strlen(at->StrOfAE);
GLOBAL_agc_collected += sizeof(AtomEntry)+strlen(at->StrOfAE);
}
*patm = atm = at->NextOfAE;
Yap_FreeCodeSpace((char *)at);
@ -448,13 +439,13 @@ atom_gc(USES_REGS1)
if (Yap_GetValue(AtomGcTrace) != TermNil)
gc_trace = 1;
agc_calls++;
agc_collected = 0;
GLOBAL_agc_calls++;
GLOBAL_agc_collected = 0;
if (gc_trace) {
fprintf(Yap_stderr, "%% agc:\n");
fprintf(GLOBAL_stderr, "%% agc:\n");
} else if (gc_verbose) {
fprintf(Yap_stderr, "%% Start of atom garbage collection %d:\n", agc_calls);
fprintf(GLOBAL_stderr, "%% Start of atom garbage collection %d:\n", GLOBAL_agc_calls);
}
time_start = Yap_cputime();
/* get the number of active registers */
@ -465,15 +456,15 @@ atom_gc(USES_REGS1)
clean_atoms();
YAPLeaveCriticalSection();
agc_time = Yap_cputime()-time_start;
tot_agc_time += agc_time;
tot_agc_recovered += agc_collected;
GLOBAL_tot_agc_time += agc_time;
GLOBAL_tot_agc_recovered += GLOBAL_agc_collected;
if (gc_verbose) {
#ifdef _WIN32
fprintf(Yap_stderr, "%% Collected %I64d bytes.\n", agc_collected);
fprintf(GLOBAL_stderr, "%% Collected %I64d bytes.\n", GLOBAL_agc_collected);
#else
fprintf(Yap_stderr, "%% Collected %lld bytes.\n", agc_collected);
fprintf(GLOBAL_stderr, "%% Collected %lld bytes.\n", GLOBAL_agc_collected);
#endif
fprintf(Yap_stderr, "%% GC %d took %g sec, total of %g sec doing GC so far.\n", agc_calls, (double)agc_time/1000, (double)tot_agc_time/1000);
fprintf(GLOBAL_stderr, "%% GC %d took %g sec, total of %g sec doing GC so far.\n", GLOBAL_agc_calls, (double)agc_time/1000, (double)GLOBAL_tot_agc_time/1000);
}
}
@ -495,9 +486,9 @@ p_atom_gc(USES_REGS1)
static Int
p_inform_agc(USES_REGS1)
{
Term tn = MkIntegerTerm(tot_agc_time);
Term tt = MkIntegerTerm(agc_calls);
Term ts = MkIntegerTerm(tot_agc_recovered);
Term tn = MkIntegerTerm(GLOBAL_tot_agc_time);
Term tt = MkIntegerTerm(GLOBAL_agc_calls);
Term ts = MkIntegerTerm(GLOBAL_tot_agc_recovered);
return
Yap_unify(tn, ARG2) &&

216
C/alloc.c
View File

@ -128,6 +128,7 @@ long long unsigned int tmalloc;
static inline char *
call_malloc(unsigned long int size)
{
CACHE_REGS
char *out;
#if USE_DL_MALLOC
LOCK(DLMallocLock);
@ -137,13 +138,13 @@ call_malloc(unsigned long int size)
tmalloc += size;
size += sizeof(CELL);
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
out = (char *) my_malloc(size);
#if INSTRUMENT_MALLOC
*(CELL*)out = size-sizeof(CELL);
out += sizeof(CELL);
#endif
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
@ -160,6 +161,7 @@ Yap_AllocCodeSpace(unsigned long int size)
static inline char *
call_realloc(char *p, unsigned long int size)
{
CACHE_REGS
char *out;
#if USE_DL_MALLOC
LOCK(DLMallocLock);
@ -171,13 +173,13 @@ call_realloc(char *p, unsigned long int size)
p -= sizeof(CELL);
tmalloc -= *(CELL*)p;
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
out = (char *) my_realloc0(p, size);
#if INSTRUMENT_MALLOC
*(CELL*)out = size-sizeof(CELL);
out += sizeof(CELL);
#endif
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
@ -194,17 +196,18 @@ Yap_ReallocCodeSpace(char *p, unsigned long int size)
void
Yap_FreeCodeSpace(char *p)
{
CACHE_REGS
#if USE_DL_MALLOC
LOCK(DLMallocLock);
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
#if INSTRUMENT_MALLOC
p -= sizeof(CELL);
tmalloc -= *(CELL*)p;
frees++;
#endif
my_free (p);
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
@ -220,17 +223,18 @@ Yap_AllocAtomSpace(unsigned long int size)
void
Yap_FreeAtomSpace(char *p)
{
CACHE_REGS
#if USE_DL_MALLOC
LOCK(DLMallocLock);
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
#if INSTRUMENT_MALLOC
p -= sizeof(CELL);
tmalloc -= *(CELL*)p;
frees++;
#endif
my_free (p);
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
@ -250,19 +254,19 @@ Yap_InitPreAllocCodeSpace(void)
#if USE_DL_MALLOC
LOCK(DLMallocLock);
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
#if INSTRUMENT_MALLOC
mallocs++;
tmalloc += sz;
sz += sizeof(CELL);
#endif
while (!(ptr = my_malloc(sz))) {
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return(NULL);
}
#if INSTRUMENT_MALLOC
@ -273,9 +277,9 @@ Yap_InitPreAllocCodeSpace(void)
#if USE_DL_MALLOC
LOCK(DLMallocLock);
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
}
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
@ -305,20 +309,20 @@ Yap_ExpandPreAllocCodeSpace(UInt sz0, void *cip, int safe)
#if USE_DL_MALLOC
LOCK(DLMallocLock);
#endif
Yap_PrologMode |= MallocMode;
LOCAL_PrologMode |= MallocMode;
#if INSTRUMENT_MALLOC
reallocs++;
tmalloc -= LOCAL_ScratchPad.sz;
tmalloc += sz;
#endif
if (!(ptr = my_realloc(LOCAL_ScratchPad.ptr, sz, LOCAL_ScratchPad.sz, safe))) {
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
return NULL;
}
Yap_PrologMode &= ~MallocMode;
LOCAL_PrologMode &= ~MallocMode;
#if USE_DL_MALLOC
UNLOCK(DLMallocLock);
#endif
@ -364,22 +368,22 @@ InitExStacks(int Trail, int Stack)
#ifdef THREADS
if (worker_id)
Yap_GlobalBase = (ADDR)LOCAL_ThreadHandle.stack_address;
LOCAL_GlobalBase = (ADDR)LOCAL_ThreadHandle.stack_address;
#endif
Yap_TrailTop = Yap_GlobalBase + pm;
Yap_LocalBase = Yap_GlobalBase + sa;
Yap_TrailBase = Yap_LocalBase + sizeof(CELL);
LOCAL_TrailTop = LOCAL_GlobalBase + pm;
LOCAL_LocalBase = LOCAL_GlobalBase + sa;
LOCAL_TrailBase = LOCAL_LocalBase + sizeof(CELL);
LOCAL_ScratchPad.ptr = NULL;
LOCAL_ScratchPad.sz = LOCAL_ScratchPad.msz = SCRATCH_START_SIZE;
AuxSp = NULL;
#ifdef DEBUG
if (Yap_output_msg) {
if (GLOBAL_output_msg) {
UInt ta;
fprintf(stderr, "HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n",
Yap_HeapBase, Yap_GlobalBase, Yap_LocalBase, Yap_TrailTop);
Yap_HeapBase, LOCAL_GlobalBase, LOCAL_LocalBase, LOCAL_TrailTop);
ta = Trail*K; /* trail area size */
fprintf(stderr, "Heap+Aux: %lu\tLocal+Global: %lu\tTrail: %lu\n",
@ -408,9 +412,9 @@ Yap_KillStacks(int wid)
void
Yap_KillStacks(void)
{
if (Yap_GlobalBase) {
free(Yap_GlobalBase);
Yap_GlobalBase = NULL;
if (LOCAL_GlobalBase) {
free(LOCAL_GlobalBase);
LOCAL_GlobalBase = NULL;
}
}
#endif
@ -425,15 +429,15 @@ int
Yap_ExtendWorkSpace(Int s)
{
CACHE_REGS
void *basebp = (void *)Yap_GlobalBase, *nbp;
UInt s0 = (char *)Yap_TrailTop-(char *)Yap_GlobalBase;
void *basebp = (void *)LOCAL_GlobalBase, *nbp;
UInt s0 = (char *)LOCAL_TrailTop-(char *)LOCAL_GlobalBase;
nbp = realloc(basebp, s+s0);
if (nbp == NULL)
return FALSE;
#if defined(THREADS)
LOCAL_ThreadHandle.stack_address = (char *)nbp;
#endif
Yap_GlobalBase = (char *)nbp;
LOCAL_GlobalBase = (char *)nbp;
return TRUE;
}
@ -682,7 +686,7 @@ AllocHeap(unsigned long int size)
HeapUsed += size * sizeof(CELL) + sizeof(YAP_SEG_SIZE);
#ifdef YAPOR
if (HeapTop > Addr(Yap_GlobalBase) - MinHeapGap)
if (HeapTop > Addr(LOCAL_GlobalBase) - MinHeapGap)
Yap_Error(INTERNAL_ERROR, TermNil, "no heap left (AllocHeap)");
#else
if (HeapTop > HeapLim - MinHeapGap) {
@ -818,9 +822,9 @@ static int
ExtendWorkSpace(Int s, int fixed_allocation)
{
LPVOID b = brk;
prolog_exec_mode OldPrologMode = Yap_PrologMode;
prolog_exec_mode OldPrologMode = LOCAL_PrologMode;
Yap_PrologMode = ExtendStackMode;
LOCAL_PrologMode = ExtendStackMode;
#if DEBUG_WIN32_ALLOC
fprintf(stderr,"trying: %p (" Int_FORMAT "K) %d\n",b, s/1024, fixed_allocation);
@ -834,7 +838,7 @@ ExtendWorkSpace(Int s, int fixed_allocation)
}
}
if (!b) {
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
#if DEBUG_WIN32_ALLOC
{
char msg[256];
@ -849,11 +853,11 @@ ExtendWorkSpace(Int s, int fixed_allocation)
}
b = VirtualAlloc(b, s, MEM_COMMIT, PAGE_READWRITE);
if (!b) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"VirtualAlloc could not commit %ld bytes",
(long int)s);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
#if DEBUG_WIN32_ALLOC
fprintf(stderr,"NOT OK2: %p--%p\n",b,brk);
#endif
@ -863,7 +867,7 @@ ExtendWorkSpace(Int s, int fixed_allocation)
#if DEBUG_WIN32_ALLOC
fprintf(stderr,"OK: %p--%p " Int_FORMAT "\n",b, brk, s);
#endif
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return TRUE;
}
@ -1021,6 +1025,8 @@ InitWorkSpace(Int s)
return (void *) a;
}
#ifndef YAPOR
static MALLOC_T
mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
{
@ -1043,13 +1049,13 @@ mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
char file[256];
strncpy(file,"/tmp/YAP.TMPXXXXXX",256);
if (mkstemp(file) == -1) {
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
#if HAVE_STRERROR
snprintf5(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf5(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mkstemp could not create temporary file %s (%s)",
file, strerror(errno));
#else
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mkstemp could not create temporary file %s", file);
#endif /* HAVE_STRERROR */
return (MALLOC_T)-1;
@ -1065,28 +1071,28 @@ mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
#endif /* HAVE_MKSTEMP */
fd = open(file, O_CREAT|O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not open %s", file);
return (MALLOC_T)-1;
}
if (lseek(fd, s, SEEK_SET) < 0) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not lseek in mmapped file %s", file);
close(fd);
return (MALLOC_T)-1;
}
if (write(fd, "", 1) < 0) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not write in mmapped file %s", file);
close(fd);
return (MALLOC_T)-1;
}
if (unlink(file) < 0) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not unlink mmapped file %s", file);
close(fd);
return (MALLOC_T)-1;
@ -1100,12 +1106,12 @@ mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
#endif
, fd, 0);
if (close(fd) == -1) {
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
#if HAVE_STRERROR
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not close file (%s) ]\n", strerror(errno));
#else
snprintf3(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf3(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not close file ]\n");
#endif
return (MALLOC_T)-1;
@ -1113,6 +1119,8 @@ mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
#endif
return a;
}
#endif /* !YAPOR */
static int
ExtendWorkSpace(Int s, int fixed_allocation)
@ -1122,23 +1130,23 @@ ExtendWorkSpace(Int s, int fixed_allocation)
return(FALSE);
#else
MALLOC_T a;
prolog_exec_mode OldPrologMode = Yap_PrologMode;
prolog_exec_mode OldPrologMode = LOCAL_PrologMode;
MALLOC_T base = WorkSpaceTop;
if (fixed_allocation == MAP_FIXED)
base = WorkSpaceTop;
else
base = 0L;
Yap_PrologMode = ExtendStackMode;
LOCAL_PrologMode = ExtendStackMode;
a = mmap_extension(s, base, fixed_allocation);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
if (a == (MALLOC_T) - 1) {
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
#if HAVE_STRERROR
snprintf5(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf5(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not allocate %d bytes (%s)", (int)s, strerror(errno));
#else
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not allocate %d bytes", (int)s);
#endif
return FALSE;
@ -1146,10 +1154,10 @@ ExtendWorkSpace(Int s, int fixed_allocation)
if (fixed_allocation) {
if (a != WorkSpaceTop) {
munmap((void *)a, (size_t)s);
Yap_ErrorMessage = Yap_ErrorSay;
snprintf5(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf5(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not grow memory at %p, got %p", WorkSpaceTop, a );
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return FALSE;
}
} else if (a < WorkSpaceTop) {
@ -1160,7 +1168,7 @@ ExtendWorkSpace(Int s, int fixed_allocation)
return res;
}
WorkSpaceTop = (char *) a + s;
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return TRUE;
#endif /* YAPOR */
}
@ -1211,33 +1219,33 @@ ExtendWorkSpace(Int s)
{
MALLOC_T ptr;
int shm_id;
prolog_exec_mode OldPrologMode = Yap_PrologMode;
prolog_exec_mode OldPrologMode = LOCAL_PrologMode;
Yap_PrologMode = ExtendStackMode;
LOCAL_PrologMode = ExtendStackMode;
/* mapping heap area */
if((shm_id = shmget(IPC_PRIVATE, (size_t)s, SHM_R|SHM_W)) == -1) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not shmget %d bytes", s);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return(FALSE);
}
if((ptr = (MALLOC_T)shmat(shm_id, WorkSpaceTop, 0)) == (MALLOC_T) -1) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not shmat at %p", MMAP_ADDR);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return(FALSE);
}
if (shmctl(shm_id, IPC_RMID, 0) != 0) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not remove shm segment", shm_id);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return(FALSE);
}
WorkSpaceTop = (char *) ptr + s;
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return(TRUE);
}
@ -1286,17 +1294,17 @@ static int
ExtendWorkSpace(Int s)
{
MALLOC_T ptr = (MALLOC_T)sbrk(s);
prolog_exec_mode OldPrologMode = Yap_PrologMode;
prolog_exec_mode OldPrologMode = LOCAL_PrologMode;
Yap_PrologMode = ExtendStackMode;
LOCAL_PrologMode = ExtendStackMode;
if (ptr == ((MALLOC_T) - 1)) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not expand stacks over %d bytes", s);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return(FALSE);
}
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return TRUE;
}
@ -1416,34 +1424,34 @@ static int
ExtendWorkSpace(Int s)
{
MALLOC_T ptr;
prolog_exec_mode OldPrologMode = Yap_PrologMode;
prolog_exec_mode OldPrologMode = LOCAL_PrologMode;
Yap_PrologMode = ExtendStackMode;
LOCAL_PrologMode = ExtendStackMode;
total_space += s;
if (total_space < MAX_SPACE) return TRUE;
ptr = (MALLOC_T)realloc((void *)Yap_HeapBase, total_space);
if (ptr == NULL) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not allocate %d bytes", s);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return FALSE;
}
if (ptr != (MALLOC_T)Yap_HeapBase) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf4(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not expand contiguous stacks %d bytes", s);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return FALSE;
}
if ((CELL)ptr & MBIT) {
Yap_ErrorMessage = Yap_ErrorSay;
snprintf5(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
LOCAL_ErrorMessage = LOCAL_ErrorSay;
snprintf5(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE,
"memory at %p conflicts with MBIT %lx", ptr, (unsigned long)MBIT);
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return FALSE;
}
Yap_PrologMode = OldPrologMode;
LOCAL_PrologMode = OldPrologMode;
return TRUE;
}
@ -1513,27 +1521,27 @@ Yap_InitMemory(UInt Trail, UInt Heap, UInt Stack)
InitHeap(addr);
Yap_TrailTop = Yap_HeapBase + pm;
Yap_LocalBase = Yap_TrailTop - ta;
Yap_TrailBase = Yap_LocalBase + sizeof(CELL);
LOCAL_TrailTop = Yap_HeapBase + pm;
LOCAL_LocalBase = LOCAL_TrailTop - ta;
LOCAL_TrailBase = LOCAL_LocalBase + sizeof(CELL);
Yap_GlobalBase = Yap_LocalBase - sa;
HeapLim = Yap_GlobalBase; /* avoid confusions while
LOCAL_GlobalBase = LOCAL_LocalBase - sa;
HeapLim = LOCAL_GlobalBase; /* avoid confusions while
* * restoring */
#if !USE_DL_MALLOC
AuxTop = (ADDR)(AuxSp = (CELL *)Yap_GlobalBase);
AuxTop = (ADDR)(AuxSp = (CELL *)LOCAL_GlobalBase);
#endif
#ifdef DEBUG
#if SIZEOF_INT_P!=SIZEOF_INT
if (Yap_output_msg) {
if (GLOBAL_output_msg) {
fprintf(stderr, "HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n",
Yap_HeapBase, Yap_GlobalBase, Yap_LocalBase, Yap_TrailTop);
Yap_HeapBase, LOCAL_GlobalBase, LOCAL_LocalBase, LOCAL_TrailTop);
#else
if (Yap_output_msg) {
if (GLOBAL_output_msg) {
fprintf(stderr, "HeapBase = %x GlobalBase = %x\n LocalBase = %x TrailTop = %x\n",
(UInt) Yap_HeapBase, (UInt) Yap_GlobalBase,
(UInt) Yap_LocalBase, (UInt) Yap_TrailTop);
(UInt) Yap_HeapBase, (UInt) LOCAL_GlobalBase,
(UInt) LOCAL_LocalBase, (UInt) LOCAL_TrailTop);
#endif
fprintf(stderr, "Heap+Aux: " UInt_FORMAT "\tLocal+Global: " UInt_FORMAT "\tTrail: " UInt_FORMAT "\n",
@ -1588,7 +1596,7 @@ Yap_ExtendWorkSpaceThroughHole(UInt s)
WorkSpaceTop += 512*1024;
if (ExtendWorkSpace(s, MAP_FIXED)) {
Yap_add_memory_hole((ADDR)WorkSpaceTop0, (ADDR)WorkSpaceTop-s);
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
return WorkSpaceTop-WorkSpaceTop0;
}
#if defined(_WIN32)
@ -1606,7 +1614,7 @@ Yap_ExtendWorkSpaceThroughHole(UInt s)
WorkSpaceTop += 512*1024;
if (ExtendWorkSpace(s, MAP_FIXED)) {
Yap_add_memory_hole((ADDR)WorkSpaceTop0, (ADDR)WorkSpaceTop-s);
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
return WorkSpaceTop-WorkSpaceTop0;
}
#if defined(_WIN32)

View File

@ -434,8 +434,8 @@ DumpOpCodes(void)
while (i < 30) {
for (j = i; j <= _std_top; j += 25)
fprintf(Yap_stderr, "%5d %6lx", j, absmadr(j));
fputc('\n',Yap_stderr);
fprintf(GLOBAL_stderr, "%5d %6lx", j, absmadr(j));
fputc('\n',GLOBAL_stderr);
++i;
}
}
@ -3541,7 +3541,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp
if (!pass_no) {
#if !USE_SYSTEM_MALLOC
if (CellPtr(cip->label_offset+cip->cpc->rnd1) > ASP-256) {
Yap_Error_Size = 256+((char *)(cip->label_offset+cip->cpc->rnd1) - (char *)H);
LOCAL_Error_Size = 256+((char *)(cip->label_offset+cip->cpc->rnd1) - (char *)H);
save_machine_regs();
siglongjmp(cip->CompilerBotch, 3);
}
@ -3787,9 +3787,9 @@ fetch_clause_space(Term* tp, UInt size, struct intermediates *cip, UInt *osizep
while ((x = Yap_StoreTermInDBPlusExtraSpace(*tp, size, osizep)) == NULL) {
H = h0;
switch (Yap_Error_TYPE) {
switch (LOCAL_Error_TYPE) {
case OUT_OF_STACK_ERROR:
Yap_Error_Size = 256+((char *)cip->freep - (char *)H);
LOCAL_Error_Size = 256+((char *)cip->freep - (char *)H);
save_machine_regs();
siglongjmp(cip->CompilerBotch,3);
case OUT_OF_TRAIL_ERROR:
@ -3798,15 +3798,15 @@ fetch_clause_space(Term* tp, UInt size, struct intermediates *cip, UInt *osizep
if (!Yap_growtrail(K64, FALSE)) {
return NULL;
}
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
*tp = ARG1;
break;
case OUT_OF_AUXSPACE_ERROR:
ARG1 = *tp;
if (!Yap_ExpandPreAllocCodeSpace(Yap_Error_Size, (void *)cip, TRUE)) {
if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, (void *)cip, TRUE)) {
return NULL;
}
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
*tp = ARG1;
break;
case OUT_OF_HEAP_ERROR:
@ -3815,7 +3815,7 @@ fetch_clause_space(Term* tp, UInt size, struct intermediates *cip, UInt *osizep
if (!Yap_growheap(TRUE, size, cip)) {
return NULL;
}
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
*tp = ARG1;
break;
default:
@ -3932,8 +3932,8 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
while ((cip->code_addr = (yamop *) Yap_AllocCodeSpace(size)) == NULL) {
if (!Yap_growheap(TRUE, size, cip)) {
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Size = size;
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_Error_Size = size;
return NULL;
}
}

View File

@ -28,9 +28,7 @@ static char SccsId[] = "%W% %G%";
#include <string.h>
#endif
YAP_ULONG_LONG Yap_opcount[_std_top + 1];
YAP_ULONG_LONG Yap_2opcount[_std_top + 1][_std_top + 1];
STATIC_PROTO(Int p_reset_op_counters, (void));
@ -43,7 +41,7 @@ p_reset_op_counters()
int i;
for (i = 0; i <= _std_top; ++i)
Yap_opcount[i] = 0;
GLOBAL_opcount[i] = 0;
return TRUE;
}
@ -52,26 +50,26 @@ print_instruction(int inst)
{
int j;
fprintf(Yap_stderr, "%s", Yap_op_names[inst]);
fprintf(GLOBAL_stderr, "%s", Yap_op_names[inst]);
for (j = strlen(Yap_op_names[inst]); j < 25; j++)
putc(' ', Yap_stderr);
j = Yap_opcount[inst];
putc(' ', GLOBAL_stderr);
j = GLOBAL_opcount[inst];
if (j < 100000000) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 10000000) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 1000000) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 100000) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 10000) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 1000) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 100) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
if (j < 10) {
putc(' ', Yap_stderr);
putc(' ', GLOBAL_stderr);
}
}
}
@ -80,7 +78,7 @@ print_instruction(int inst)
}
}
}
fprintf(Yap_stderr, "%llu\n", Yap_opcount[inst]);
fprintf(GLOBAL_stderr, "%llu\n", GLOBAL_opcount[inst]);
}
static Int
@ -98,18 +96,18 @@ p_show_op_counters()
wchar_t *program;
program = RepAtom(at1)->WStrOfAE;
fprintf(Yap_stderr, "\n Instructions Executed in %S\n", program);
fprintf(GLOBAL_stderr, "\n Instructions Executed in %S\n", program);
} else {
char *program;
program = RepAtom(at1)->StrOfAE;
fprintf(Yap_stderr, "\n Instructions Executed in %s\n", program);
fprintf(GLOBAL_stderr, "\n Instructions Executed in %s\n", program);
}
}
for (i = 0; i <= _std_top; ++i)
print_instruction(i);
fprintf(Yap_stderr, "\n Control Instructions \n");
fprintf(GLOBAL_stderr, "\n Control Instructions \n");
print_instruction(_op_fail);
print_instruction(_execute);
print_instruction(_dexecute);
@ -121,7 +119,7 @@ p_show_op_counters()
print_instruction(_allocate);
print_instruction(_deallocate);
fprintf(Yap_stderr, "\n Choice Point Manipulation Instructions\n");
fprintf(GLOBAL_stderr, "\n Choice Point Manipulation Instructions\n");
print_instruction(_try_me);
print_instruction(_retry_me);
print_instruction(_trust_me);
@ -130,38 +128,38 @@ p_show_op_counters()
print_instruction(_retry);
print_instruction(_trust);
fprintf(Yap_stderr, "\n Disjunction Instructions\n");
fprintf(GLOBAL_stderr, "\n Disjunction Instructions\n");
print_instruction(_either);
print_instruction(_or_else);
print_instruction(_or_last);
print_instruction(_jump);
print_instruction(_move_back);
fprintf(Yap_stderr, "\n Dynamic Predicates Choicepoint Instructions\n");
fprintf(GLOBAL_stderr, "\n Dynamic Predicates Choicepoint Instructions\n");
print_instruction(_try_and_mark);
print_instruction(_retry_and_mark);
fprintf(Yap_stderr, "\n C Predicates Choicepoint Instructions\n");
fprintf(GLOBAL_stderr, "\n C Predicates Choicepoint Instructions\n");
print_instruction(_try_c);
print_instruction(_retry_c);
fprintf(Yap_stderr, "\n Indexing Instructions\n");
fprintf(Yap_stderr, "\n Switch on Type\n");
fprintf(GLOBAL_stderr, "\n Indexing Instructions\n");
fprintf(GLOBAL_stderr, "\n Switch on Type\n");
print_instruction(_switch_on_type);
print_instruction(_switch_list_nl);
print_instruction(_switch_on_arg_type);
print_instruction(_switch_on_sub_arg_type);
fprintf(Yap_stderr, "\n Switch on Value\n");
fprintf(GLOBAL_stderr, "\n Switch on Value\n");
print_instruction(_if_cons);
print_instruction(_go_on_cons);
print_instruction(_switch_on_cons);
print_instruction(_if_func);
print_instruction(_go_on_func);
print_instruction(_switch_on_func);
fprintf(Yap_stderr, "\n Other Switches\n");
fprintf(GLOBAL_stderr, "\n Other Switches\n");
print_instruction(_if_not_then);
fprintf(Yap_stderr, "\n Get Instructions\n");
fprintf(GLOBAL_stderr, "\n Get Instructions\n");
print_instruction(_get_x_var);
print_instruction(_get_y_var);
print_instruction(_get_x_val);
@ -174,7 +172,7 @@ p_show_op_counters()
print_instruction(_get_6atoms);
print_instruction(_get_list);
print_instruction(_get_struct);
fprintf(Yap_stderr, "\n Optimised Get Instructions\n");
fprintf(GLOBAL_stderr, "\n Optimised Get Instructions\n");
print_instruction(_glist_valx);
print_instruction(_glist_valy);
print_instruction(_gl_void_varx);
@ -182,7 +180,7 @@ p_show_op_counters()
print_instruction(_gl_void_valx);
print_instruction(_gl_void_valy);
fprintf(Yap_stderr, "\n Unify Read Instructions\n");
fprintf(GLOBAL_stderr, "\n Unify Read Instructions\n");
print_instruction(_unify_x_var);
print_instruction(_unify_x_var2);
print_instruction(_unify_y_var);
@ -195,7 +193,7 @@ p_show_op_counters()
print_instruction(_unify_n_voids);
print_instruction(_unify_list);
print_instruction(_unify_struct);
fprintf(Yap_stderr, "\n Unify Last Read Instructions\n");
fprintf(GLOBAL_stderr, "\n Unify Last Read Instructions\n");
print_instruction(_unify_l_x_var);
print_instruction(_unify_l_x_var2);
print_instruction(_unify_l_y_var);
@ -208,7 +206,7 @@ p_show_op_counters()
print_instruction(_unify_l_list);
print_instruction(_unify_l_struc);
fprintf(Yap_stderr, "\n Unify Write Instructions\n");
fprintf(GLOBAL_stderr, "\n Unify Write Instructions\n");
print_instruction(_unify_x_var_write);
print_instruction(_unify_x_var2_write);
print_instruction(_unify_y_var_write);
@ -221,7 +219,7 @@ p_show_op_counters()
print_instruction(_unify_n_voids_write);
print_instruction(_unify_list_write);
print_instruction(_unify_struct_write);
fprintf(Yap_stderr, "\n Unify Last Read Instructions\n");
fprintf(GLOBAL_stderr, "\n Unify Last Read Instructions\n");
print_instruction(_unify_l_x_var_write);
print_instruction(_unify_l_x_var2_write);
print_instruction(_unify_l_y_var_write);
@ -234,7 +232,7 @@ p_show_op_counters()
print_instruction(_unify_l_list_write);
print_instruction(_unify_l_struc_write);
fprintf(Yap_stderr, "\n Put Instructions\n");
fprintf(GLOBAL_stderr, "\n Put Instructions\n");
print_instruction(_put_x_var);
print_instruction(_put_y_var);
print_instruction(_put_x_val);
@ -245,7 +243,7 @@ p_show_op_counters()
print_instruction(_put_list);
print_instruction(_put_struct);
fprintf(Yap_stderr, "\n Write Instructions\n");
fprintf(GLOBAL_stderr, "\n Write Instructions\n");
print_instruction(_write_x_var);
print_instruction(_write_y_var);
print_instruction(_write_x_val);
@ -257,11 +255,11 @@ p_show_op_counters()
print_instruction(_write_n_voids);
print_instruction(_write_list);
print_instruction(_write_struct);
fprintf(Yap_stderr, "\n Last Write Instructions\n");
fprintf(GLOBAL_stderr, "\n Last Write Instructions\n");
print_instruction(_write_l_list);
print_instruction(_write_l_struc);
fprintf(Yap_stderr, "\n Miscellaneous Instructions\n");
fprintf(GLOBAL_stderr, "\n Miscellaneous Instructions\n");
print_instruction(_cut);
print_instruction(_cut_t);
print_instruction(_cut_e);
@ -292,11 +290,11 @@ p_show_op_counters()
typedef struct {
int nxvar, nxval, nyvar, nyval, ncons, nlist, nstru, nmisc;
} uYap_opcount;
} uGLOBAL_opcount;
typedef struct {
int ncalls, nexecs, nproceeds, ncallbips, ncuts, nallocs, ndeallocs;
} cYap_opcount;
} cGLOBAL_opcount;
typedef struct {
int ntries, nretries, ntrusts;
@ -306,8 +304,8 @@ static Int
p_show_ops_by_group(void)
{
uYap_opcount c_get, c_unify, c_put, c_write;
cYap_opcount c_control;
uGLOBAL_opcount c_get, c_unify, c_put, c_write;
cGLOBAL_opcount c_control;
ccpcount c_cp;
int gets, unifies, puts, writes, controls, choice_pts, indexes, misc,
total;
@ -322,261 +320,261 @@ p_show_ops_by_group(void)
wchar_t *program;
program = RepAtom(at1)->WStrOfAE;
fprintf(Yap_stderr, "\n Instructions Executed in %S\n", program);
fprintf(GLOBAL_stderr, "\n Instructions Executed in %S\n", program);
} else {
char *program;
program = RepAtom(at1)->StrOfAE;
fprintf(Yap_stderr, "\n Instructions Executed in %s\n", program);
fprintf(GLOBAL_stderr, "\n Instructions Executed in %s\n", program);
}
c_get.nxvar =
Yap_opcount[_get_x_var];
GLOBAL_opcount[_get_x_var];
c_get.nyvar =
Yap_opcount[_get_y_var];
GLOBAL_opcount[_get_y_var];
c_get.nxval =
Yap_opcount[_get_x_val];
GLOBAL_opcount[_get_x_val];
c_get.nyval =
Yap_opcount[_get_y_val];
GLOBAL_opcount[_get_y_val];
c_get.ncons =
Yap_opcount[_get_atom]+
Yap_opcount[_get_2atoms]+
Yap_opcount[_get_3atoms]+
Yap_opcount[_get_4atoms]+
Yap_opcount[_get_5atoms]+
Yap_opcount[_get_6atoms];
GLOBAL_opcount[_get_atom]+
GLOBAL_opcount[_get_2atoms]+
GLOBAL_opcount[_get_3atoms]+
GLOBAL_opcount[_get_4atoms]+
GLOBAL_opcount[_get_5atoms]+
GLOBAL_opcount[_get_6atoms];
c_get.nlist =
Yap_opcount[_get_list] +
Yap_opcount[_glist_valx] +
Yap_opcount[_glist_valy] +
Yap_opcount[_gl_void_varx] +
Yap_opcount[_gl_void_vary] +
Yap_opcount[_gl_void_valx] +
Yap_opcount[_gl_void_valy];
GLOBAL_opcount[_get_list] +
GLOBAL_opcount[_glist_valx] +
GLOBAL_opcount[_glist_valy] +
GLOBAL_opcount[_gl_void_varx] +
GLOBAL_opcount[_gl_void_vary] +
GLOBAL_opcount[_gl_void_valx] +
GLOBAL_opcount[_gl_void_valy];
c_get.nstru =
Yap_opcount[_get_struct];
GLOBAL_opcount[_get_struct];
gets = c_get.nxvar + c_get.nyvar + c_get.nxval + c_get.nyval +
c_get.ncons + c_get.nlist + c_get.nstru;
c_unify.nxvar =
Yap_opcount[_unify_x_var] +
Yap_opcount[_unify_void] +
Yap_opcount[_unify_n_voids] +
2 * Yap_opcount[_unify_x_var2] +
2 * Yap_opcount[_gl_void_varx] +
Yap_opcount[_gl_void_vary] +
Yap_opcount[_gl_void_valx] +
Yap_opcount[_unify_l_x_var] +
Yap_opcount[_unify_l_void] +
Yap_opcount[_unify_l_n_voids] +
2 * Yap_opcount[_unify_l_x_var2] +
Yap_opcount[_unify_x_var_write] +
Yap_opcount[_unify_void_write] +
Yap_opcount[_unify_n_voids_write] +
2 * Yap_opcount[_unify_x_var2_write] +
Yap_opcount[_unify_l_x_var_write] +
Yap_opcount[_unify_l_void_write] +
Yap_opcount[_unify_l_n_voids_write] +
2 * Yap_opcount[_unify_l_x_var2_write];
GLOBAL_opcount[_unify_x_var] +
GLOBAL_opcount[_unify_void] +
GLOBAL_opcount[_unify_n_voids] +
2 * GLOBAL_opcount[_unify_x_var2] +
2 * GLOBAL_opcount[_gl_void_varx] +
GLOBAL_opcount[_gl_void_vary] +
GLOBAL_opcount[_gl_void_valx] +
GLOBAL_opcount[_unify_l_x_var] +
GLOBAL_opcount[_unify_l_void] +
GLOBAL_opcount[_unify_l_n_voids] +
2 * GLOBAL_opcount[_unify_l_x_var2] +
GLOBAL_opcount[_unify_x_var_write] +
GLOBAL_opcount[_unify_void_write] +
GLOBAL_opcount[_unify_n_voids_write] +
2 * GLOBAL_opcount[_unify_x_var2_write] +
GLOBAL_opcount[_unify_l_x_var_write] +
GLOBAL_opcount[_unify_l_void_write] +
GLOBAL_opcount[_unify_l_n_voids_write] +
2 * GLOBAL_opcount[_unify_l_x_var2_write];
c_unify.nyvar =
Yap_opcount[_unify_y_var] +
Yap_opcount[_gl_void_vary] +
Yap_opcount[_unify_l_y_var] +
Yap_opcount[_unify_y_var_write] +
Yap_opcount[_unify_l_y_var_write];
GLOBAL_opcount[_unify_y_var] +
GLOBAL_opcount[_gl_void_vary] +
GLOBAL_opcount[_unify_l_y_var] +
GLOBAL_opcount[_unify_y_var_write] +
GLOBAL_opcount[_unify_l_y_var_write];
c_unify.nxval =
Yap_opcount[_unify_x_val] +
Yap_opcount[_unify_x_loc] +
Yap_opcount[_glist_valx] +
Yap_opcount[_gl_void_valx] +
Yap_opcount[_unify_l_x_val] +
Yap_opcount[_unify_l_x_loc] +
Yap_opcount[_unify_x_val_write] +
Yap_opcount[_unify_x_loc_write] +
Yap_opcount[_unify_l_x_val_write] +
Yap_opcount[_unify_l_x_loc_write];
GLOBAL_opcount[_unify_x_val] +
GLOBAL_opcount[_unify_x_loc] +
GLOBAL_opcount[_glist_valx] +
GLOBAL_opcount[_gl_void_valx] +
GLOBAL_opcount[_unify_l_x_val] +
GLOBAL_opcount[_unify_l_x_loc] +
GLOBAL_opcount[_unify_x_val_write] +
GLOBAL_opcount[_unify_x_loc_write] +
GLOBAL_opcount[_unify_l_x_val_write] +
GLOBAL_opcount[_unify_l_x_loc_write];
c_unify.nyval =
Yap_opcount[_unify_y_val] +
Yap_opcount[_unify_y_loc] +
Yap_opcount[_glist_valy] +
Yap_opcount[_gl_void_valy] +
Yap_opcount[_unify_l_y_val] +
Yap_opcount[_unify_l_y_loc] +
Yap_opcount[_unify_y_val_write] +
Yap_opcount[_unify_y_loc_write] +
Yap_opcount[_unify_l_y_val_write] +
Yap_opcount[_unify_l_y_loc_write];
GLOBAL_opcount[_unify_y_val] +
GLOBAL_opcount[_unify_y_loc] +
GLOBAL_opcount[_glist_valy] +
GLOBAL_opcount[_gl_void_valy] +
GLOBAL_opcount[_unify_l_y_val] +
GLOBAL_opcount[_unify_l_y_loc] +
GLOBAL_opcount[_unify_y_val_write] +
GLOBAL_opcount[_unify_y_loc_write] +
GLOBAL_opcount[_unify_l_y_val_write] +
GLOBAL_opcount[_unify_l_y_loc_write];
c_unify.ncons =
Yap_opcount[_unify_atom] +
Yap_opcount[_unify_n_atoms] +
Yap_opcount[_unify_l_atom] +
Yap_opcount[_unify_atom_write] +
Yap_opcount[_unify_n_atoms_write] +
Yap_opcount[_unify_l_atom_write];
GLOBAL_opcount[_unify_atom] +
GLOBAL_opcount[_unify_n_atoms] +
GLOBAL_opcount[_unify_l_atom] +
GLOBAL_opcount[_unify_atom_write] +
GLOBAL_opcount[_unify_n_atoms_write] +
GLOBAL_opcount[_unify_l_atom_write];
c_unify.nlist =
Yap_opcount[_unify_list] +
Yap_opcount[_unify_l_list] +
Yap_opcount[_unify_list_write] +
Yap_opcount[_unify_l_list_write];
GLOBAL_opcount[_unify_list] +
GLOBAL_opcount[_unify_l_list] +
GLOBAL_opcount[_unify_list_write] +
GLOBAL_opcount[_unify_l_list_write];
c_unify.nstru =
Yap_opcount[_unify_struct] +
Yap_opcount[_unify_l_struc] +
Yap_opcount[_unify_struct_write] +
Yap_opcount[_unify_l_struc_write];
GLOBAL_opcount[_unify_struct] +
GLOBAL_opcount[_unify_l_struc] +
GLOBAL_opcount[_unify_struct_write] +
GLOBAL_opcount[_unify_l_struc_write];
c_unify.nmisc =
Yap_opcount[_pop] +
Yap_opcount[_pop_n];
GLOBAL_opcount[_pop] +
GLOBAL_opcount[_pop_n];
unifies = c_unify.nxvar + c_unify.nyvar + c_unify.nxval + c_unify.nyval +
c_unify.ncons + c_unify.nlist + c_unify.nstru + c_unify.nmisc;
c_put.nxvar =
Yap_opcount[_put_x_var];
GLOBAL_opcount[_put_x_var];
c_put.nyvar =
Yap_opcount[_put_y_var];
GLOBAL_opcount[_put_y_var];
c_put.nxval =
Yap_opcount[_put_x_val]+
2*Yap_opcount[_put_xx_val];
GLOBAL_opcount[_put_x_val]+
2*GLOBAL_opcount[_put_xx_val];
c_put.nyval =
Yap_opcount[_put_y_val];
GLOBAL_opcount[_put_y_val];
c_put.ncons =
Yap_opcount[_put_atom];
GLOBAL_opcount[_put_atom];
c_put.nlist =
Yap_opcount[_put_list];
GLOBAL_opcount[_put_list];
c_put.nstru =
Yap_opcount[_put_struct];
GLOBAL_opcount[_put_struct];
puts = c_put.nxvar + c_put.nyvar + c_put.nxval + c_put.nyval +
c_put.ncons + c_put.nlist + c_put.nstru;
c_write.nxvar =
Yap_opcount[_write_x_var] +
Yap_opcount[_write_void] +
Yap_opcount[_write_n_voids];
GLOBAL_opcount[_write_x_var] +
GLOBAL_opcount[_write_void] +
GLOBAL_opcount[_write_n_voids];
c_write.nyvar =
Yap_opcount[_write_y_var];
GLOBAL_opcount[_write_y_var];
c_write.nxval =
Yap_opcount[_write_x_val];
GLOBAL_opcount[_write_x_val];
c_write.nyval =
Yap_opcount[_write_y_val];
GLOBAL_opcount[_write_y_val];
c_write.ncons =
Yap_opcount[_write_atom];
GLOBAL_opcount[_write_atom];
c_write.nlist =
Yap_opcount[_write_list];
GLOBAL_opcount[_write_list];
c_write.nstru =
Yap_opcount[_write_struct];
GLOBAL_opcount[_write_struct];
writes = c_write.nxvar + c_write.nyvar + c_write.nxval + c_write.nyval +
c_write.ncons + c_write.nlist + c_write.nstru;
c_control.nexecs =
Yap_opcount[_execute] +
Yap_opcount[_dexecute];
GLOBAL_opcount[_execute] +
GLOBAL_opcount[_dexecute];
c_control.ncalls =
Yap_opcount[_call] +
Yap_opcount[_fcall];
GLOBAL_opcount[_call] +
GLOBAL_opcount[_fcall];
c_control.nproceeds =
Yap_opcount[_procceed];
GLOBAL_opcount[_procceed];
c_control.ncallbips =
Yap_opcount[_call_cpred] +
Yap_opcount[_call_c_wfail] +
Yap_opcount[_try_c] +
Yap_opcount[_retry_c] +
Yap_opcount[_op_fail] +
Yap_opcount[_trust_fail] +
Yap_opcount[_p_atom_x] +
Yap_opcount[_p_atom_y] +
Yap_opcount[_p_atomic_x] +
Yap_opcount[_p_atomic_y] +
Yap_opcount[_p_compound_x] +
Yap_opcount[_p_compound_y] +
Yap_opcount[_p_float_x] +
Yap_opcount[_p_float_y] +
Yap_opcount[_p_integer_x] +
Yap_opcount[_p_integer_y] +
Yap_opcount[_p_nonvar_x] +
Yap_opcount[_p_nonvar_y] +
Yap_opcount[_p_number_x] +
Yap_opcount[_p_number_y] +
Yap_opcount[_p_var_x] +
Yap_opcount[_p_var_y] +
Yap_opcount[_p_db_ref_x] +
Yap_opcount[_p_db_ref_y] +
Yap_opcount[_p_cut_by_x] +
Yap_opcount[_p_cut_by_y] +
Yap_opcount[_p_primitive_x] +
Yap_opcount[_p_primitive_y] +
Yap_opcount[_p_equal] +
Yap_opcount[_p_plus_vv] +
Yap_opcount[_p_plus_vc] +
Yap_opcount[_p_plus_y_vv] +
Yap_opcount[_p_plus_y_vc] +
Yap_opcount[_p_minus_vv] +
Yap_opcount[_p_minus_cv] +
Yap_opcount[_p_minus_y_vv] +
Yap_opcount[_p_minus_y_cv] +
Yap_opcount[_p_times_vv] +
Yap_opcount[_p_times_vc] +
Yap_opcount[_p_times_y_vv] +
Yap_opcount[_p_times_y_vc] +
Yap_opcount[_p_div_vv] +
Yap_opcount[_p_div_vc] +
Yap_opcount[_p_div_cv] +
Yap_opcount[_p_div_y_vv] +
Yap_opcount[_p_div_y_vc] +
Yap_opcount[_p_div_y_cv] +
Yap_opcount[_p_or_vv] +
Yap_opcount[_p_or_vc] +
Yap_opcount[_p_or_y_vv] +
Yap_opcount[_p_or_y_vc] +
Yap_opcount[_p_and_vv] +
Yap_opcount[_p_and_vc] +
Yap_opcount[_p_and_y_vv] +
Yap_opcount[_p_and_y_vc] +
Yap_opcount[_p_sll_vv] +
Yap_opcount[_p_sll_vc] +
Yap_opcount[_p_sll_y_vv] +
Yap_opcount[_p_sll_y_vc] +
Yap_opcount[_p_slr_vv] +
Yap_opcount[_p_slr_vc] +
Yap_opcount[_p_slr_y_vv] +
Yap_opcount[_p_slr_y_vc] +
Yap_opcount[_p_dif] +
Yap_opcount[_p_eq] +
Yap_opcount[_p_arg_vv] +
Yap_opcount[_p_arg_cv] +
Yap_opcount[_p_arg_y_vv] +
Yap_opcount[_p_arg_y_cv] +
Yap_opcount[_p_functor] +
Yap_opcount[_p_func2s_vv] +
Yap_opcount[_p_func2s_cv] +
Yap_opcount[_p_func2s_vc] +
Yap_opcount[_p_func2s_y_vv] +
Yap_opcount[_p_func2s_y_cv] +
Yap_opcount[_p_func2s_y_vc] +
Yap_opcount[_p_func2f_xx] +
Yap_opcount[_p_func2f_xy] +
Yap_opcount[_p_func2f_yx] +
Yap_opcount[_p_func2f_yy];
GLOBAL_opcount[_call_cpred] +
GLOBAL_opcount[_call_c_wfail] +
GLOBAL_opcount[_try_c] +
GLOBAL_opcount[_retry_c] +
GLOBAL_opcount[_op_fail] +
GLOBAL_opcount[_trust_fail] +
GLOBAL_opcount[_p_atom_x] +
GLOBAL_opcount[_p_atom_y] +
GLOBAL_opcount[_p_atomic_x] +
GLOBAL_opcount[_p_atomic_y] +
GLOBAL_opcount[_p_compound_x] +
GLOBAL_opcount[_p_compound_y] +
GLOBAL_opcount[_p_float_x] +
GLOBAL_opcount[_p_float_y] +
GLOBAL_opcount[_p_integer_x] +
GLOBAL_opcount[_p_integer_y] +
GLOBAL_opcount[_p_nonvar_x] +
GLOBAL_opcount[_p_nonvar_y] +
GLOBAL_opcount[_p_number_x] +
GLOBAL_opcount[_p_number_y] +
GLOBAL_opcount[_p_var_x] +
GLOBAL_opcount[_p_var_y] +
GLOBAL_opcount[_p_db_ref_x] +
GLOBAL_opcount[_p_db_ref_y] +
GLOBAL_opcount[_p_cut_by_x] +
GLOBAL_opcount[_p_cut_by_y] +
GLOBAL_opcount[_p_primitive_x] +
GLOBAL_opcount[_p_primitive_y] +
GLOBAL_opcount[_p_equal] +
GLOBAL_opcount[_p_plus_vv] +
GLOBAL_opcount[_p_plus_vc] +
GLOBAL_opcount[_p_plus_y_vv] +
GLOBAL_opcount[_p_plus_y_vc] +
GLOBAL_opcount[_p_minus_vv] +
GLOBAL_opcount[_p_minus_cv] +
GLOBAL_opcount[_p_minus_y_vv] +
GLOBAL_opcount[_p_minus_y_cv] +
GLOBAL_opcount[_p_times_vv] +
GLOBAL_opcount[_p_times_vc] +
GLOBAL_opcount[_p_times_y_vv] +
GLOBAL_opcount[_p_times_y_vc] +
GLOBAL_opcount[_p_div_vv] +
GLOBAL_opcount[_p_div_vc] +
GLOBAL_opcount[_p_div_cv] +
GLOBAL_opcount[_p_div_y_vv] +
GLOBAL_opcount[_p_div_y_vc] +
GLOBAL_opcount[_p_div_y_cv] +
GLOBAL_opcount[_p_or_vv] +
GLOBAL_opcount[_p_or_vc] +
GLOBAL_opcount[_p_or_y_vv] +
GLOBAL_opcount[_p_or_y_vc] +
GLOBAL_opcount[_p_and_vv] +
GLOBAL_opcount[_p_and_vc] +
GLOBAL_opcount[_p_and_y_vv] +
GLOBAL_opcount[_p_and_y_vc] +
GLOBAL_opcount[_p_sll_vv] +
GLOBAL_opcount[_p_sll_vc] +
GLOBAL_opcount[_p_sll_y_vv] +
GLOBAL_opcount[_p_sll_y_vc] +
GLOBAL_opcount[_p_slr_vv] +
GLOBAL_opcount[_p_slr_vc] +
GLOBAL_opcount[_p_slr_y_vv] +
GLOBAL_opcount[_p_slr_y_vc] +
GLOBAL_opcount[_p_dif] +
GLOBAL_opcount[_p_eq] +
GLOBAL_opcount[_p_arg_vv] +
GLOBAL_opcount[_p_arg_cv] +
GLOBAL_opcount[_p_arg_y_vv] +
GLOBAL_opcount[_p_arg_y_cv] +
GLOBAL_opcount[_p_functor] +
GLOBAL_opcount[_p_func2s_vv] +
GLOBAL_opcount[_p_func2s_cv] +
GLOBAL_opcount[_p_func2s_vc] +
GLOBAL_opcount[_p_func2s_y_vv] +
GLOBAL_opcount[_p_func2s_y_cv] +
GLOBAL_opcount[_p_func2s_y_vc] +
GLOBAL_opcount[_p_func2f_xx] +
GLOBAL_opcount[_p_func2f_xy] +
GLOBAL_opcount[_p_func2f_yx] +
GLOBAL_opcount[_p_func2f_yy];
c_control.ncuts =
Yap_opcount[_cut] +
Yap_opcount[_cut_t] +
Yap_opcount[_cut_e] +
Yap_opcount[_commit_b_x] +
Yap_opcount[_commit_b_y];
GLOBAL_opcount[_cut] +
GLOBAL_opcount[_cut_t] +
GLOBAL_opcount[_cut_e] +
GLOBAL_opcount[_commit_b_x] +
GLOBAL_opcount[_commit_b_y];
c_control.nallocs =
Yap_opcount[_allocate] +
Yap_opcount[_fcall];
GLOBAL_opcount[_allocate] +
GLOBAL_opcount[_fcall];
c_control.ndeallocs =
Yap_opcount[_dexecute] +
Yap_opcount[_deallocate];
GLOBAL_opcount[_dexecute] +
GLOBAL_opcount[_deallocate];
controls =
c_control.nexecs +
@ -585,30 +583,30 @@ p_show_ops_by_group(void)
c_control.ncuts +
c_control.nallocs +
c_control.ndeallocs +
Yap_opcount[_jump] +
Yap_opcount[_move_back] +
Yap_opcount[_try_in];
GLOBAL_opcount[_jump] +
GLOBAL_opcount[_move_back] +
GLOBAL_opcount[_try_in];
c_cp.ntries =
Yap_opcount[_try_me] +
Yap_opcount[_try_and_mark] +
Yap_opcount[_try_c] +
Yap_opcount[_try_clause] +
Yap_opcount[_either];
GLOBAL_opcount[_try_me] +
GLOBAL_opcount[_try_and_mark] +
GLOBAL_opcount[_try_c] +
GLOBAL_opcount[_try_clause] +
GLOBAL_opcount[_either];
c_cp.nretries =
Yap_opcount[_retry_me] +
Yap_opcount[_retry_and_mark] +
Yap_opcount[_retry_c] +
Yap_opcount[_retry] +
Yap_opcount[_or_else];
GLOBAL_opcount[_retry_me] +
GLOBAL_opcount[_retry_and_mark] +
GLOBAL_opcount[_retry_c] +
GLOBAL_opcount[_retry] +
GLOBAL_opcount[_or_else];
c_cp.ntrusts =
Yap_opcount[_trust_me] +
Yap_opcount[_trust] +
Yap_opcount[_or_last];
GLOBAL_opcount[_trust_me] +
GLOBAL_opcount[_trust] +
GLOBAL_opcount[_or_last];
choice_pts =
c_cp.ntries +
@ -616,70 +614,70 @@ p_show_ops_by_group(void)
c_cp.ntrusts;
indexes =
Yap_opcount[_jump_if_var] +
Yap_opcount[_switch_on_type] +
Yap_opcount[_switch_list_nl] +
Yap_opcount[_switch_on_arg_type] +
Yap_opcount[_switch_on_sub_arg_type] +
Yap_opcount[_switch_on_cons] +
Yap_opcount[_go_on_cons] +
Yap_opcount[_if_cons] +
Yap_opcount[_switch_on_func] +
Yap_opcount[_go_on_func] +
Yap_opcount[_if_func] +
Yap_opcount[_if_not_then];
GLOBAL_opcount[_jump_if_var] +
GLOBAL_opcount[_switch_on_type] +
GLOBAL_opcount[_switch_list_nl] +
GLOBAL_opcount[_switch_on_arg_type] +
GLOBAL_opcount[_switch_on_sub_arg_type] +
GLOBAL_opcount[_switch_on_cons] +
GLOBAL_opcount[_go_on_cons] +
GLOBAL_opcount[_if_cons] +
GLOBAL_opcount[_switch_on_func] +
GLOBAL_opcount[_go_on_func] +
GLOBAL_opcount[_if_func] +
GLOBAL_opcount[_if_not_then];
misc =
c_control.ncallbips +
Yap_opcount[_Ystop] +
Yap_opcount[_Nstop] +
Yap_opcount[_index_pred] +
Yap_opcount[_lock_pred] +
GLOBAL_opcount[_Ystop] +
GLOBAL_opcount[_Nstop] +
GLOBAL_opcount[_index_pred] +
GLOBAL_opcount[_lock_pred] +
#if THREADS
Yap_opcount[_thread_local] +
GLOBAL_opcount[_thread_local] +
#endif
Yap_opcount[_save_b_x] +
Yap_opcount[_save_b_y] +
Yap_opcount[_undef_p] +
Yap_opcount[_spy_pred] +
Yap_opcount[_spy_or_trymark] +
Yap_opcount[_save_pair_x] +
Yap_opcount[_save_pair_y] +
Yap_opcount[_save_pair_x_write] +
Yap_opcount[_save_pair_y_write] +
Yap_opcount[_save_appl_x] +
Yap_opcount[_save_appl_y] +
Yap_opcount[_save_appl_x_write] +
Yap_opcount[_save_appl_y_write];
GLOBAL_opcount[_save_b_x] +
GLOBAL_opcount[_save_b_y] +
GLOBAL_opcount[_undef_p] +
GLOBAL_opcount[_spy_pred] +
GLOBAL_opcount[_spy_or_trymark] +
GLOBAL_opcount[_save_pair_x] +
GLOBAL_opcount[_save_pair_y] +
GLOBAL_opcount[_save_pair_x_write] +
GLOBAL_opcount[_save_pair_y_write] +
GLOBAL_opcount[_save_appl_x] +
GLOBAL_opcount[_save_appl_y] +
GLOBAL_opcount[_save_appl_x_write] +
GLOBAL_opcount[_save_appl_y_write];
total = gets + unifies + puts + writes + controls + choice_pts + indexes + misc;
/* for (i = 0; i <= _std_top; ++i)
* print_instruction(i);
*/
fprintf(Yap_stderr, "Groups are\n\n");
fprintf(Yap_stderr, " GET instructions: %8d (%3d%%)\n", gets,
fprintf(GLOBAL_stderr, "Groups are\n\n");
fprintf(GLOBAL_stderr, " GET instructions: %8d (%3d%%)\n", gets,
(gets * 100) / total);
fprintf(Yap_stderr, " UNIFY instructions: %8d (%3d%%)\n", unifies,
fprintf(GLOBAL_stderr, " UNIFY instructions: %8d (%3d%%)\n", unifies,
(unifies * 100) / total);
fprintf(Yap_stderr, " PUT instructions: %8d (%3d%%)\n", puts,
fprintf(GLOBAL_stderr, " PUT instructions: %8d (%3d%%)\n", puts,
(puts * 100) / total);
fprintf(Yap_stderr, " WRITE instructions: %8d (%3d%%)\n", writes,
fprintf(GLOBAL_stderr, " WRITE instructions: %8d (%3d%%)\n", writes,
(writes * 100) / total);
fprintf(Yap_stderr, " CONTROL instructions: %8d (%3d%%)\n", controls,
fprintf(GLOBAL_stderr, " CONTROL instructions: %8d (%3d%%)\n", controls,
(controls * 100) / total);
fprintf(Yap_stderr, " CHOICE POINT instructions: %8d (%3d%%)\n", choice_pts,
fprintf(GLOBAL_stderr, " CHOICE POINT instructions: %8d (%3d%%)\n", choice_pts,
(choice_pts * 100) / total);
fprintf(Yap_stderr, " INDEXING instructions: %8d (%3d%%)\n", indexes,
fprintf(GLOBAL_stderr, " INDEXING instructions: %8d (%3d%%)\n", indexes,
(indexes * 100) / total);
fprintf(Yap_stderr, " MISCELLANEOUS instructions: %8d (%3d%%)\n", misc,
fprintf(GLOBAL_stderr, " MISCELLANEOUS instructions: %8d (%3d%%)\n", misc,
(misc * 100) / total);
fprintf(Yap_stderr, "_______________________________________________\n");
fprintf(Yap_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
fprintf(GLOBAL_stderr, "_______________________________________________\n");
fprintf(GLOBAL_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
(total * 100) / total);
fprintf(Yap_stderr, "\n Analysis of Unification Instructions in %s \n", program);
fprintf(Yap_stderr, " XVAR, YVAR, XVAL, YVAL, CONS, LIST, STRUCT\n");
fprintf(Yap_stderr, " GET: %8d %8d %8d %8d %8d %8d %8d\n",
fprintf(GLOBAL_stderr, "\n Analysis of Unification Instructions in %s \n", program);
fprintf(GLOBAL_stderr, " XVAR, YVAR, XVAL, YVAL, CONS, LIST, STRUCT\n");
fprintf(GLOBAL_stderr, " GET: %8d %8d %8d %8d %8d %8d %8d\n",
c_get.nxvar,
c_get.nyvar,
c_get.nxval,
@ -687,7 +685,7 @@ p_show_ops_by_group(void)
c_get.ncons,
c_get.nlist,
c_get.nstru);
fprintf(Yap_stderr, "UNIFY: %8d %8d %8d %8d %8d %8d %8d\n",
fprintf(GLOBAL_stderr, "UNIFY: %8d %8d %8d %8d %8d %8d %8d\n",
c_unify.nxvar,
c_unify.nyvar,
c_unify.nxval,
@ -695,7 +693,7 @@ p_show_ops_by_group(void)
c_unify.ncons,
c_unify.nlist,
c_unify.nstru);
fprintf(Yap_stderr, " PUT: %8d %8d %8d %8d %8d %8d %8d\n",
fprintf(GLOBAL_stderr, " PUT: %8d %8d %8d %8d %8d %8d %8d\n",
c_put.nxvar,
c_put.nyvar,
c_put.nxval,
@ -703,7 +701,7 @@ p_show_ops_by_group(void)
c_put.ncons,
c_put.nlist,
c_put.nstru);
fprintf(Yap_stderr, "WRITE: %8d %8d %8d %8d %8d %8d %8d\n",
fprintf(GLOBAL_stderr, "WRITE: %8d %8d %8d %8d %8d %8d %8d\n",
c_write.nxvar,
c_write.nyvar,
c_write.nxval,
@ -711,8 +709,8 @@ p_show_ops_by_group(void)
c_write.ncons,
c_write.nlist,
c_write.nstru);
fprintf(Yap_stderr, " ___________________________________________________\n");
fprintf(Yap_stderr, "TOTAL: %8d %8d %8d %8d %8d %8d %8d\n",
fprintf(GLOBAL_stderr, " ___________________________________________________\n");
fprintf(GLOBAL_stderr, "TOTAL: %8d %8d %8d %8d %8d %8d %8d\n",
c_get.nxvar + c_unify.nxvar + c_put.nxvar + c_write.nxvar,
c_get.nyvar + c_unify.nyvar + c_put.nyvar + c_write.nyvar,
c_get.nxval + c_unify.nxval + c_put.nxval + c_write.nxval,
@ -722,9 +720,9 @@ p_show_ops_by_group(void)
c_get.nstru + c_unify.nstru + c_put.nstru + c_write.nstru
);
fprintf(Yap_stderr, "\n Analysis of Unification Instructions in %s \n", program);
fprintf(Yap_stderr, " XVAR, YVAR, XVAL, YVAL, CONS, LIST, STRUCT\n");
fprintf(Yap_stderr, " GET: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
fprintf(GLOBAL_stderr, "\n Analysis of Unification Instructions in %s \n", program);
fprintf(GLOBAL_stderr, " XVAR, YVAR, XVAL, YVAL, CONS, LIST, STRUCT\n");
fprintf(GLOBAL_stderr, " GET: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
(((double) c_get.nxvar) * 100) / total,
(((double) c_get.nyvar) * 100) / total,
(((double) c_get.nxval) * 100) / total,
@ -732,7 +730,7 @@ p_show_ops_by_group(void)
(((double) c_get.ncons) * 100) / total,
(((double) c_get.nlist) * 100) / total,
(((double) c_get.nstru) * 100) / total);
fprintf(Yap_stderr, "UNIFY: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
fprintf(GLOBAL_stderr, "UNIFY: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
(((double) c_unify.nxvar) * 100) / total,
(((double) c_unify.nyvar) * 100) / total,
(((double) c_unify.nxval) * 100) / total,
@ -740,7 +738,7 @@ p_show_ops_by_group(void)
(((double) c_unify.ncons) * 100) / total,
(((double) c_unify.nlist) * 100) / total,
(((double) c_unify.nstru) * 100) / total);
fprintf(Yap_stderr, " PUT: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
fprintf(GLOBAL_stderr, " PUT: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
(((double) c_put.nxvar) * 100) / total,
(((double) c_put.nyvar) * 100) / total,
(((double) c_put.nxval) * 100) / total,
@ -748,7 +746,7 @@ p_show_ops_by_group(void)
(((double) c_put.ncons) * 100) / total,
(((double) c_put.nlist) * 100) / total,
(((double) c_put.nstru) * 100) / total);
fprintf(Yap_stderr, "WRITE: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
fprintf(GLOBAL_stderr, "WRITE: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
(((double) c_write.nxvar) * 100) / total,
(((double) c_write.nyvar) * 100) / total,
(((double) c_write.nxval) * 100) / total,
@ -756,8 +754,8 @@ p_show_ops_by_group(void)
(((double) c_write.ncons) * 100) / total,
(((double) c_write.nlist) * 100) / total,
(((double) c_write.nstru) * 100) / total);
fprintf(Yap_stderr, " ___________________________________________________\n");
fprintf(Yap_stderr, "TOTAL: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
fprintf(GLOBAL_stderr, " ___________________________________________________\n");
fprintf(GLOBAL_stderr, "TOTAL: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
(((double) c_get.nxvar + c_unify.nxvar + c_put.nxvar + c_write.nxvar) * 100) / total,
(((double) c_get.nyvar + c_unify.nyvar + c_put.nyvar + c_write.nyvar) * 100) / total,
(((double) c_get.nxval + c_unify.nxval + c_put.nxval + c_write.nxval) * 100) / total,
@ -767,36 +765,36 @@ p_show_ops_by_group(void)
(((double) c_get.nstru + c_unify.nstru + c_put.nstru + c_write.nstru) * 100) / total
);
fprintf(Yap_stderr, "\n Control Instructions Executed in %s \n", program);
fprintf(Yap_stderr, "Grouped as\n\n");
fprintf(Yap_stderr, " CALL instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, "\n Control Instructions Executed in %s \n", program);
fprintf(GLOBAL_stderr, "Grouped as\n\n");
fprintf(GLOBAL_stderr, " CALL instructions: %8d (%3d%%)\n",
c_control.ncalls, (c_control.ncalls * 100) / total);
fprintf(Yap_stderr, " PROCEED instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " PROCEED instructions: %8d (%3d%%)\n",
c_control.nproceeds, (c_control.nproceeds * 100) / total);
fprintf(Yap_stderr, " EXECUTE instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " EXECUTE instructions: %8d (%3d%%)\n",
c_control.nexecs, (c_control.nexecs * 100) / total);
fprintf(Yap_stderr, " CUT instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " CUT instructions: %8d (%3d%%)\n",
c_control.ncuts, (c_control.ncuts * 100) / total);
fprintf(Yap_stderr, " CALL_BIP instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " CALL_BIP instructions: %8d (%3d%%)\n",
c_control.ncallbips, (c_control.ncallbips * 100) / total);
fprintf(Yap_stderr, " ALLOCATE instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " ALLOCATE instructions: %8d (%3d%%)\n",
c_control.nallocs, (c_control.nallocs * 100) / total);
fprintf(Yap_stderr, " DEALLOCATE instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " DEALLOCATE instructions: %8d (%3d%%)\n",
c_control.ndeallocs, (c_control.ndeallocs * 100) / total);
fprintf(Yap_stderr, "_______________________________________________\n");
fprintf(Yap_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
fprintf(GLOBAL_stderr, "_______________________________________________\n");
fprintf(GLOBAL_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
(total * 100) / total);
fprintf(Yap_stderr, "\n Choice Point Manipulation Instructions Executed in %s \n", program);
fprintf(Yap_stderr, "Grouped as\n\n");
fprintf(Yap_stderr, " TRY instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, "\n Choice Point Manipulation Instructions Executed in %s \n", program);
fprintf(GLOBAL_stderr, "Grouped as\n\n");
fprintf(GLOBAL_stderr, " TRY instructions: %8d (%3d%%)\n",
c_cp.ntries, (c_cp.ntries * 100) / total);
fprintf(Yap_stderr, " RETRY instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " RETRY instructions: %8d (%3d%%)\n",
c_cp.nretries, (c_cp.nretries * 100) / total);
fprintf(Yap_stderr, " TRUST instructions: %8d (%3d%%)\n",
fprintf(GLOBAL_stderr, " TRUST instructions: %8d (%3d%%)\n",
c_cp.ntrusts, (c_cp.ntrusts * 100) / total);
fprintf(Yap_stderr, "_______________________________________________\n");
fprintf(Yap_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
fprintf(GLOBAL_stderr, "_______________________________________________\n");
fprintf(GLOBAL_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
(total * 100) / total);
return TRUE;
@ -828,7 +826,7 @@ p_show_sequences(void)
return FALSE;
}
for (i = 0; i <= _std_top; ++i) {
sum += Yap_opcount[i];
sum += GLOBAL_opcount[i];
}
for (i = 0; i <= _std_top; ++i) {
for (j = 0; j <= _std_top; ++j) {

View File

@ -158,12 +158,11 @@ typedef struct MMAP_ARRAY_BLOCK {
struct MMAP_ARRAY_BLOCK *next;
} mmap_array_block;
static mmap_array_block *mmap_arrays = NULL;
static Int
CloseMmappedArray(StaticArrayEntry *pp, void *area USES_REGS)
{
mmap_array_block *ptr = mmap_arrays, *optr = mmap_arrays;
mmap_array_block *ptr = GLOBAL_mmap_arrays, *optr = GLOBAL_mmap_arrays;
while (ptr != NULL && ptr->start != area) {
ptr = ptr->next;
@ -193,7 +192,7 @@ CloseMmappedArray(StaticArrayEntry *pp, void *area USES_REGS)
static void
ResizeMmappedArray(StaticArrayEntry *pp, Int dim, void *area USES_REGS)
{
mmap_array_block *ptr = mmap_arrays;
mmap_array_block *ptr = GLOBAL_mmap_arrays;
size_t total_size;
while (ptr != NULL && ptr->start != area) {
ptr = ptr->next;
@ -240,16 +239,16 @@ GetTermFromArray(DBTerm *ref USES_REGS)
Term TRef;
while ((TRef = Yap_FetchTermFromDB(ref)) == 0L) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return TermNil;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return TermNil;
}
}
@ -611,7 +610,7 @@ AllocateStaticArraySpace(StaticArrayEntry *p, static_array_types atype, Int arra
while ((p->ValueOfVE.floats = (Float *) Yap_AllocAtomSpace(asize) ) == NULL) {
YAPLeaveCriticalSection();
if (!Yap_growheap(FALSE, asize, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return;
}
YAPEnterCriticalSection();
@ -625,7 +624,7 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
if (EndOfPAEntr(p)) {
while ((p = (StaticArrayEntry *) Yap_AllocAtomSpace(sizeof(*p))) == NULL) {
if (!Yap_growheap(FALSE, sizeof(*p), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -900,12 +899,12 @@ p_create_array( USES_REGS1 )
farray = Yap_MkFunctor(AtomArray, size);
if (H+1+size > ASP-1024) {
if (!Yap_gcl((1+size)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
return(FALSE);
} else {
if (H+1+size > ASP-1024) {
if (!Yap_growstack( sizeof(CELL) * (size+1-(H-ASP-1024)))) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -938,7 +937,7 @@ p_create_array( USES_REGS1 )
if (H+1+size > ASP-1024) {
WRITE_UNLOCK(ae->ARWLock);
if (!Yap_gcl((1+size)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
return(FALSE);
} else
goto restart;
@ -960,7 +959,7 @@ p_create_array( USES_REGS1 )
} else {
if (H+1+size > ASP-1024) {
if (!Yap_gcl((1+size)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
return(FALSE);
} else
goto restart;
@ -1383,8 +1382,8 @@ p_create_mmapped_array( USES_REGS1 )
ptr->items = size;
ptr->start = (void *)array_addr;
ptr->fd = fd;
ptr->next = mmap_arrays;
mmap_arrays = ptr;
ptr->next = GLOBAL_mmap_arrays;
GLOBAL_mmap_arrays = ptr;
WRITE_UNLOCK(pp->ArRWLock);
WRITE_UNLOCK(ae->ARWLock);
return TRUE;
@ -2244,7 +2243,7 @@ static Int
p_sync_mmapped_arrays( USES_REGS1 )
{
#ifdef HAVE_MMAP
mmap_array_block *ptr = mmap_arrays;
mmap_array_block *ptr = GLOBAL_mmap_arrays;
while (ptr != NULL) {
msync(ptr->start, ptr->size, MS_SYNC);
ptr = ptr->next;
@ -2279,12 +2278,12 @@ p_static_array_to_term( USES_REGS1 )
while (H+1+dim > ASP-1024) {
if (!Yap_gcl((1+dim)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
return(FALSE);
} else {
if (H+1+dim > ASP-1024) {
if (!Yap_growstack( sizeof(CELL) * (dim+1-(H-ASP-1024)))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}

View File

@ -205,7 +205,7 @@ BuildAttTerm(Functor mfun, UInt ar USES_REGS)
UInt i;
if (H+(1024+ar) > ASP) {
Yap_Error_Size=ar*sizeof(CELL);
LOCAL_Error_Size=ar*sizeof(CELL);
return 0L;
}
H[0] = (CELL)mfun;
@ -433,9 +433,9 @@ p_put_att( USES_REGS1 ) {
attv = RepAttVar(VarOfTerm(inp));
} else {
while (!(attv = BuildNewAttVar( PASS_REGS1 ))) {
Yap_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(Yap_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(LOCAL_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
inp = Deref(ARG1);
@ -445,8 +445,8 @@ p_put_att( USES_REGS1 ) {
mfun= Yap_MkFunctor(modname,ar);
if (IsVarTerm(tatts = SearchAttsForModule(attv->Atts,mfun))) {
while (!(tatts = BuildAttTerm(mfun,ar PASS_REGS))) {
if (!Yap_gcl(Yap_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_gcl(LOCAL_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -474,9 +474,9 @@ p_put_att_term( USES_REGS1 ) {
MaBind(&(attv->Atts), Deref(ARG2));
} else {
while (!(attv = BuildNewAttVar( PASS_REGS1 ))) {
Yap_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(Yap_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(LOCAL_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
inp = Deref(ARG1);
@ -508,9 +508,9 @@ p_rm_att( USES_REGS1 ) {
attv = RepAttVar(VarOfTerm(inp));
} else {
while (!(attv = BuildNewAttVar( PASS_REGS1 ))) {
Yap_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(Yap_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(LOCAL_Error_Size, 5, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
inp = Deref(ARG1);
@ -521,8 +521,8 @@ p_rm_att( USES_REGS1 ) {
mfun= Yap_MkFunctor(modname,ar);
if (IsVarTerm(tatts = SearchAttsForModule(attv->Atts,mfun))) {
while (!(tatts = BuildAttTerm(mfun, ar PASS_REGS))) {
if (!Yap_gcl(Yap_Error_Size, 4, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_gcl(LOCAL_Error_Size, 4, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -555,9 +555,9 @@ p_put_atts( USES_REGS1 ) {
attv = RepAttVar(VarOfTerm(inp));
} else {
while (!(attv = BuildNewAttVar( PASS_REGS1 ))) {
Yap_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_Size = sizeof(attvar_record);
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
tatts = Deref(ARG2);
@ -902,7 +902,7 @@ AllAttVars( USES_REGS1 ) {
case (CELL)FunctorAttVar:
if (IsUnboundVar(pt+1)) {
if (ASP - myH < 1024) {
Yap_Error_Size = (ASP-H)*sizeof(CELL);
LOCAL_Error_Size = (ASP-H)*sizeof(CELL);
return 0L;
}
if (myH != H) {
@ -952,8 +952,8 @@ p_all_attvars( USES_REGS1 )
Term out;
if (!(out = AllAttVars( PASS_REGS1 ))) {
if (!Yap_gcl(Yap_Error_Size, 1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
@ -1044,11 +1044,11 @@ void Yap_InitAttVarPreds(void)
Term OldCurrentModule = CurrentModule;
CurrentModule = ATTRIBUTES_MODULE;
#ifdef COROUTINING
attas[attvars_ext].bind_op = WakeAttVar;
attas[attvars_ext].copy_term_op = CopyAttVar;
attas[attvars_ext].to_term_op = AttVarToTerm;
attas[attvars_ext].term_to_op = TermToAttVar;
attas[attvars_ext].mark_op = mark_attvar;
GLOBAL_attas[attvars_ext].bind_op = WakeAttVar;
GLOBAL_attas[attvars_ext].copy_term_op = CopyAttVar;
GLOBAL_attas[attvars_ext].to_term_op = AttVarToTerm;
GLOBAL_attas[attvars_ext].term_to_op = TermToAttVar;
GLOBAL_attas[attvars_ext].mark_op = mark_attvar;
Yap_InitCPred("get_att", 4, p_get_att, SafePredFlag);
Yap_InitCPred("get_module_atts", 2, p_get_atts, SafePredFlag);
Yap_InitCPred("has_module_atts", 2, p_has_atts, SafePredFlag);

View File

@ -233,7 +233,7 @@ p_rational( USES_REGS1 )
(mpq_numref(rat)->_mp_alloc)*(sizeof(mp_limb_t)/CellSize) +
(mpq_denref(rat)->_mp_alloc)*(sizeof(mp_limb_t)/CellSize);
if (!Yap_gcl(size, 3, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, t, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, t, LOCAL_ErrorMessage);
return FALSE;
}
}

View File

@ -334,6 +334,7 @@
#include "clause.h"
#include "yapio.h"
#include "attvar.h"
#include "SWI-Stream.h"
#if HAVE_STDARG_H
#include <stdarg.h>
#endif
@ -458,6 +459,7 @@ X_API int STD_PROTO(YAP_GoalHasException,(Term *));
X_API void STD_PROTO(YAP_ClearExceptions,(void));
X_API int STD_PROTO(YAP_ContinueGoal,(void));
X_API void STD_PROTO(YAP_PruneGoal,(void));
X_API IOSTREAM *STD_PROTO(YAP_TermToStream,(Term));
X_API IOSTREAM *STD_PROTO(YAP_InitConsult,(int, char *));
X_API void STD_PROTO(YAP_EndConsult,(IOSTREAM *));
X_API Term STD_PROTO(YAP_Read, (IOSTREAM *));
@ -761,7 +763,7 @@ YAP_MkBlobTerm(unsigned int sz)
while (H+(sz+sizeof(MP_INT)/sizeof(CELL)+2) > ASP-1024) {
if (!doexpand((sz+sizeof(MP_INT)/sizeof(CELL)+2)*sizeof(CELL))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "YAP failed to grow the stack while constructing a blob: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "YAP failed to grow the stack while constructing a blob: %s", LOCAL_ErrorMessage);
return TermNil;
}
}
@ -857,7 +859,7 @@ YAP_LookupAtom(char *c)
a = Yap_LookupAtom(c);
if (a == NIL || (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL)) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage);
}
} else {
return a;
@ -875,7 +877,7 @@ YAP_LookupWideAtom(wchar_t *c)
a = Yap_LookupWideAtom(c);
if (a == NIL || (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL)) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage);
}
} else {
return a;
@ -893,7 +895,7 @@ YAP_FullLookupAtom(char *c)
at = Yap_FullLookupAtom(c);
if (at == NIL || (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL)) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage);
}
} else {
return at;
@ -1794,7 +1796,7 @@ YAP_ReallocSpaceFromYap(void *ptr,unsigned int size) {
BACKUP_MACHINE_REGS();
while ((new_ptr = Yap_ReallocCodeSpace(ptr,size)) == NULL) {
if (!Yap_growheap(FALSE, size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -1810,7 +1812,7 @@ YAP_AllocSpaceFromYap(unsigned int size)
while ((ptr = Yap_AllocCodeSpace(size)) == NULL) {
if (!Yap_growheap(FALSE, size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -1927,35 +1929,35 @@ YAP_ReadBuffer(char *s, Term *tp)
BACKUP_H();
while ((t = Yap_StringToTerm(s,tp)) == 0L) {
if (Yap_ErrorMessage) {
if (!strcmp(Yap_ErrorMessage,"Stack Overflow")) {
if (LOCAL_ErrorMessage) {
if (!strcmp(LOCAL_ErrorMessage,"Stack Overflow")) {
if (!dogc()) {
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
Yap_ErrorMessage = NULL;
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
LOCAL_ErrorMessage = NULL;
RECOVER_H();
return 0L;
}
} else if (!strcmp(Yap_ErrorMessage,"Heap Overflow")) {
} else if (!strcmp(LOCAL_ErrorMessage,"Heap Overflow")) {
if (!Yap_growheap(FALSE, 0, NULL)) {
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
Yap_ErrorMessage = NULL;
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
LOCAL_ErrorMessage = NULL;
RECOVER_H();
return 0L;
}
} else if (!strcmp(Yap_ErrorMessage,"Trail Overflow")) {
} else if (!strcmp(LOCAL_ErrorMessage,"Trail Overflow")) {
if (!Yap_growtrail (0, FALSE)) {
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
Yap_ErrorMessage = NULL;
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
LOCAL_ErrorMessage = NULL;
RECOVER_H();
return 0L;
}
} else {
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
Yap_ErrorMessage = NULL;
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
LOCAL_ErrorMessage = NULL;
RECOVER_H();
return 0L;
}
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
continue;
} else {
break;
@ -2138,9 +2140,9 @@ run_emulator(YAP_dogoalinfo *dgi)
int out;
BACKUP_MACHINE_REGS();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
out = Yap_absmi(0);
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
myB = (choiceptr)(LCL0-dgi->b);
CP = myB->cp_cp;
if (!out ) {
@ -2274,9 +2276,9 @@ YAP_RunGoal(Term t)
BACKUP_MACHINE_REGS();
LOCAL_AllowRestart = FALSE;
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
out = Yap_RunTopGoal(t);
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
if (out) {
P = (yamop *)ENV[E_CP];
ENV = (CELL *)ENV[E_E];
@ -2300,9 +2302,9 @@ YAP_RunGoalOnce(Term t)
yamop *old_CP = CP;
BACKUP_MACHINE_REGS();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
out = Yap_RunTopGoal(t);
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
if (out) {
choiceptr cut_pt;
@ -2338,9 +2340,9 @@ YAP_RestartGoal(void)
if (LOCAL_AllowRestart) {
P = (yamop *)FAILCODE;
do_putcf = myputc;
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
out = Yap_exec_absmi(TRUE);
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
if (out == FALSE) {
/* cleanup */
Yap_CloseSlots( PASS_REGS1 );
@ -2396,12 +2398,13 @@ YAP_ShutdownGoal(int backtrack)
X_API int
YAP_ContinueGoal(void)
{
CACHE_REGS
int out;
BACKUP_MACHINE_REGS();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
out = Yap_exec_absmi(TRUE);
Yap_PrologMode = UserCCallMode;
LOCAL_PrologMode = UserCCallMode;
RECOVER_MACHINE_REGS();
return(out);
@ -2432,22 +2435,22 @@ YAP_GoalHasException(Term *t)
BACKUP_MACHINE_REGS();
if (EX) {
do {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
*t = Yap_FetchTermFromDB(EX);
if (Yap_Error_TYPE == YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == YAP_NO_ERROR) {
RECOVER_MACHINE_REGS();
return TRUE;
} else if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
} else if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
RECOVER_MACHINE_REGS();
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growstack(EX->NOfCells*CellSize)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
RECOVER_MACHINE_REGS();
return FALSE;
}
@ -2487,6 +2490,22 @@ YAP_InitConsult(int mode, char *filename)
return st;
}
X_API IOSTREAM *
YAP_TermToStream(Term t)
{
CACHE_REGS
IOSTREAM *s;
int rc;
BACKUP_MACHINE_REGS();
if ( (rc=PL_get_stream_handle(Yap_InitSlot(t PASS_REGS), &s)) ) {
RECOVER_MACHINE_REGS();
return s;
}
RECOVER_MACHINE_REGS();
return NULL;
}
X_API void
YAP_EndConsult(IOSTREAM *s)
{
@ -2508,20 +2527,20 @@ YAP_Read(IOSTREAM *inp)
BACKUP_MACHINE_REGS();
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(inp, &tpos);
if (Yap_ErrorMessage)
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp, &tpos);
if (LOCAL_ErrorMessage)
{
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
RECOVER_MACHINE_REGS();
return 0;
}
if (inp->flags & (SIO_FEOF|SIO_FEOF2)) {
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
RECOVER_MACHINE_REGS();
return MkAtomTerm (AtomEof);
}
t = Yap_Parse();
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
RECOVER_MACHINE_REGS();
return t;
@ -2572,7 +2591,7 @@ YAP_CompileClause(Term t)
BACKUP_MACHINE_REGS();
/* allow expansion during stack initialization */
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
ARG1 = t;
YAPEnterCriticalSection();
codeaddr = Yap_cclause (t,0, mod, t);
@ -2580,18 +2599,18 @@ YAP_CompileClause(Term t)
t = Deref(ARG1); /* just in case there was an heap overflow */
if (!Yap_addclause (t, codeaddr, TRUE, mod, &tn)) {
YAPLeaveCriticalSection();
return Yap_ErrorMessage;
return LOCAL_ErrorMessage;
}
}
YAPLeaveCriticalSection();
if (LOCAL_ActiveSignals & YAP_CDOVF_SIGNAL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", LOCAL_ErrorMessage);
}
}
RECOVER_MACHINE_REGS();
return(Yap_ErrorMessage);
return(LOCAL_ErrorMessage);
}
static int eof_found = FALSE;
@ -2708,8 +2727,14 @@ YAP_Init(YAP_init_args *yap_init)
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
static char boot_file[256];
Yap_argv = yap_init->Argv;
Yap_argc = yap_init->Argc;
Yap_InitPageSize(); /* init memory page size, required by later functions */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_init_yapor_global_local_memory();
LOCAL = REMOTE(0);
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
Yap_InitSysbits(); /* init signal handling and time, required by later functions */
GLOBAL_argv = yap_init->Argv;
GLOBAL_argc = yap_init->Argc;
#if !BOOT_FROM_SAVED_STATE
if (yap_init->SavedState) {
fprintf(stderr,"[ WARNING: threaded YAP will ignore saved state %s ]\n",yap_init->SavedState);
@ -2718,8 +2743,8 @@ YAP_Init(YAP_init_args *yap_init)
#endif
if (BOOT_FROM_SAVED_STATE && !do_bootstrap) {
if (Yap_SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap) != 1) {
yap_init->ErrorNo = Yap_Error_TYPE;
yap_init->ErrorCause = Yap_ErrorMessage;
yap_init->ErrorNo = LOCAL_Error_TYPE;
yap_init->ErrorCause = LOCAL_ErrorMessage;
return YAP_BOOT_ERROR;
}
}
@ -2754,7 +2779,7 @@ YAP_Init(YAP_init_args *yap_init)
} else {
Heap = yap_init->HeapSize;
}
Yap_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts;
GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts;
Yap_InitWorkspace(Heap, Stack, Trail, Atts,
yap_init->MaxTableSpaceSize,
yap_init->NumberWorkers,
@ -2770,14 +2795,14 @@ YAP_Init(YAP_init_args *yap_init)
Trail = MinTrailSpace;
if (Stack < MinStackSpace)
Stack = MinStackSpace;
if (!(Yap_GlobalBase = (ADDR)malloc((Trail+Stack)*1024))) {
if (!(LOCAL_GlobalBase = (ADDR)malloc((Trail+Stack)*1024))) {
yap_init->ErrorNo = RESOURCE_ERROR_MEMORY;
yap_init->ErrorCause = "could not allocate stack space for main thread";
return YAP_BOOT_ERROR;
}
#if THREADS
/* don't forget this is a thread */
LOCAL_ThreadHandle.stack_address = Yap_GlobalBase;
LOCAL_ThreadHandle.stack_address = LOCAL_GlobalBase;
LOCAL_ThreadHandle.ssize = Trail+Stack;
#endif
#endif
@ -2813,8 +2838,8 @@ YAP_Init(YAP_init_args *yap_init)
} else if (BOOT_FROM_SAVED_STATE) {
restore_result = Yap_Restore(yap_init->SavedState, yap_init->YapLibDir);
if (restore_result == FAIL_RESTORE) {
yap_init->ErrorNo = Yap_Error_TYPE;
yap_init->ErrorCause = Yap_ErrorMessage;
yap_init->ErrorNo = LOCAL_Error_TYPE;
yap_init->ErrorCause = LOCAL_ErrorMessage;
/* shouldn't RECOVER_MACHINE_REGS(); be here ??? */
return YAP_BOOT_ERROR;
}
@ -2823,10 +2848,10 @@ YAP_Init(YAP_init_args *yap_init)
}
yap_flags[FAST_BOOT_FLAG] = yap_init->FastBoot;
#if defined(YAPOR) || defined(TABLING)
Yap_init_root_frames();
Yap_init_root_frames();
#endif /* YAPOR || TABLING */
#ifdef YAPOR
init_yapor_workers();
Yap_init_yapor_workers();
if (worker_id != 0) {
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
/*
@ -2900,8 +2925,8 @@ YAP_Init(YAP_init_args *yap_init)
}
if (BOOT_FROM_SAVED_STATE && !do_bootstrap) {
if (restore_result == FAIL_RESTORE) {
yap_init->ErrorNo = Yap_Error_TYPE;
yap_init->ErrorCause = Yap_ErrorMessage;
yap_init->ErrorNo = LOCAL_Error_TYPE;
yap_init->ErrorCause = LOCAL_ErrorMessage;
return YAP_BOOT_ERROR;
}
if (Atts && Atts*1024 > 2048*sizeof(CELL))
@ -3050,7 +3075,7 @@ X_API void
YAP_SetOutputMessage(void)
{
#if DEBUG
Yap_output_msg = TRUE;
GLOBAL_output_msg = TRUE;
#endif
}
@ -3090,11 +3115,12 @@ YAP_Throw(Term t)
X_API void
YAP_AsyncThrow(Term t)
{
{
CACHE_REGS
BACKUP_MACHINE_REGS();
Yap_PrologMode |= AsyncIntMode;
LOCAL_PrologMode |= AsyncIntMode;
Yap_JumpToEnv(t);
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
RECOVER_MACHINE_REGS();
}
@ -3307,13 +3333,13 @@ YAP_cwd(void)
CACHE_REGS
char *buf;
int len;
if (!Yap_getcwd(Yap_FileNameBuf, YAP_FILENAME_MAX))
if (!Yap_getcwd(LOCAL_FileNameBuf, YAP_FILENAME_MAX))
return FALSE;
len = strlen(Yap_FileNameBuf);
len = strlen(LOCAL_FileNameBuf);
buf = Yap_AllocCodeSpace(len+1);
if (!buf)
return NULL;
strncpy(buf, Yap_FileNameBuf, len);
strncpy(buf, LOCAL_FileNameBuf, len);
return buf;
}
@ -3445,22 +3471,22 @@ YAP_Recorded(void *handle)
BACKUP_MACHINE_REGS();
do {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
t = Yap_FetchTermFromDB(dbterm);
if (Yap_Error_TYPE == YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == YAP_NO_ERROR) {
RECOVER_MACHINE_REGS();
return t;
} else if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
} else if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
RECOVER_MACHINE_REGS();
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growstack(dbterm->NOfCells*CellSize)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
RECOVER_MACHINE_REGS();
return FALSE;
}

128
C/cdmgr.c
View File

@ -483,9 +483,6 @@ STATIC_PROTO(void assertz_dynam_clause, (PredEntry *, yamop *));
STATIC_PROTO(void expand_consult, ( void ));
STATIC_PROTO(int not_was_reconsulted, (PredEntry *, Term, int));
STATIC_PROTO(int RemoveIndexation, (PredEntry *));
#if EMACS
STATIC_PROTO(int last_clause_number, (PredEntry *));
#endif
STATIC_PROTO(int static_in_use, (PredEntry *, int));
#if !defined(YAPOR) && !defined(THREADS)
STATIC_PROTO(Int search_for_static_predicate_in_use, (PredEntry *, int));
@ -961,7 +958,7 @@ IPred(PredEntry *ap, UInt NSlots, yamop *next_pc)
#ifdef DEBUG
CACHE_REGS
if (Yap_Option['i' - 'a' + 1]) {
if (GLOBAL_Option['i' - 'a' + 1]) {
Term tmod = ap->ModuleOfPred;
if (!tmod)
tmod = TermProlog;
@ -1020,7 +1017,7 @@ IPred(PredEntry *ap, UInt NSlots, yamop *next_pc)
ap->OpcodeOfPred = ap->CodeOfPred->opc;
}
#ifdef DEBUG
if (Yap_Option['i' - 'a' + 1])
if (GLOBAL_Option['i' - 'a' + 1])
Yap_DebugPutc(LOCAL_c_error_stream,'\n');
#endif
}
@ -1961,7 +1958,7 @@ static void expand_consult( void )
/* I assume it always works ;-) */
while ((new_cl = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*LOCAL_ConsultCapacity)) == NULL) {
if (!Yap_growheap(FALSE, sizeof(consult_obj)*LOCAL_ConsultCapacity, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,LOCAL_ErrorMessage);
return;
}
}
@ -2027,21 +2024,21 @@ addcl_permission_error(AtomEntry *ap, Int Arity, int in_use)
ti[0] = MkAtomTerm(AbsAtom(ap));
ti[1] = MkIntegerTerm(Arity);
t = Yap_MkApplTerm(FunctorSlash, 2, ti);
Yap_ErrorMessage = Yap_ErrorSay;
Yap_Error_Term = t;
Yap_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
LOCAL_Error_Term = t;
LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE;
if (in_use) {
if (Arity == 0)
sprintf(Yap_ErrorMessage, "static predicate %s is in use", ap->StrOfAE);
sprintf(LOCAL_ErrorMessage, "static predicate %s is in use", ap->StrOfAE);
else
sprintf(Yap_ErrorMessage,
sprintf(LOCAL_ErrorMessage,
"static predicate %s/" Int_FORMAT " is in use",
ap->StrOfAE, Arity);
} else {
if (Arity == 0)
sprintf(Yap_ErrorMessage, "system predicate %s", ap->StrOfAE);
sprintf(LOCAL_ErrorMessage, "system predicate %s", ap->StrOfAE);
else
sprintf(Yap_ErrorMessage,
sprintf(LOCAL_ErrorMessage,
"system predicate %s/" Int_FORMAT,
ap->StrOfAE, Arity);
}
@ -2199,7 +2196,7 @@ addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref)
if (mode == consult)
not_was_reconsulted(p, t, TRUE);
/* always check if we have a valid error first */
if (Yap_ErrorMessage && Yap_Error_TYPE == PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE) {
if (LOCAL_ErrorMessage && LOCAL_Error_TYPE == PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE) {
UNLOCKPE(31,p);
return TermNil;
}
@ -2438,25 +2435,6 @@ Yap_add_logupd_clause(PredEntry *pe, LogUpdClause *cl, int mode) {
}
}
#if EMACS
/*
* the place where one would add a new clause for the propriety pred_prop
*/
int
where_new_clause(pred_prop, mode)
Prop pred_prop;
int mode;
{
PredEntry *p = RepPredProp(pred_prop);
if (mode == consult && not_was_reconsulted(p, TermNil, FALSE))
return (1);
else
return (p->cs.p_code.NOfClauses + 1);
}
#endif
static Int
p_compile( USES_REGS1 )
{ /* '$compile'(+C,+Flags, Mod) */
@ -2475,15 +2453,15 @@ p_compile( USES_REGS1 )
codeadr = Yap_cclause(t, 4, mod, Deref(ARG3)); /* vsc: give the number of arguments
to cclause in case there is overflow */
t = Deref(ARG1); /* just in case there was an heap overflow */
if (!Yap_ErrorMessage)
if (!LOCAL_ErrorMessage)
addclause(t, codeadr, (int) (IntOfTerm(t1) & 3), mod, &tn);
YAPLeaveCriticalSection();
if (Yap_ErrorMessage) {
if (LOCAL_ErrorMessage) {
if (IntOfTerm(t1) & 4) {
Yap_Error(Yap_Error_TYPE, Yap_Error_Term,
"in line %d, %s", Yap_FirstLineInParse(), Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term,
"in line %d, %s", Yap_FirstLineInParse(), LOCAL_ErrorMessage);
} else {
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
}
return FALSE;
}
@ -2517,16 +2495,16 @@ p_compile_dynamic( USES_REGS1 )
code_adr = Yap_cclause(t, 5, mod, Deref(ARG3)); /* vsc: give the number of arguments to
cclause() in case there is a overflow */
t = Deref(ARG1); /* just in case there was an heap overflow */
if (!Yap_ErrorMessage) {
if (!LOCAL_ErrorMessage) {
optimizer_on = old_optimize;
addclause(t, code_adr, mode , mod, &ARG5);
}
if (Yap_ErrorMessage) {
if (!Yap_Error_Term)
Yap_Error_Term = TermNil;
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
if (LOCAL_ErrorMessage) {
if (!LOCAL_Error_Term)
LOCAL_Error_Term = TermNil;
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
YAPLeaveCriticalSection();
return FALSE;
}
@ -3408,9 +3386,9 @@ all_envs(CELL *env_ptr USES_REGS)
bp[0] = MkIntegerTerm(LCL0-env_ptr);
if (H >= ASP-1024) {
H = start;
Yap_Error_Size = (ASP-1024)-H;
LOCAL_Error_Size = (ASP-1024)-H;
while (env_ptr) {
Yap_Error_Size += 2;
LOCAL_Error_Size += 2;
env_ptr = (CELL *)(env_ptr[E_E]);
}
return 0L;
@ -3437,9 +3415,9 @@ all_cps(choiceptr b_ptr USES_REGS)
bp[0] = MkIntegerTerm((Int)(LCL0-(CELL *)b_ptr));
if (H >= ASP-1024) {
H = start;
Yap_Error_Size = (ASP-1024)-H;
LOCAL_Error_Size = (ASP-1024)-H;
while (b_ptr) {
Yap_Error_Size += 2;
LOCAL_Error_Size += 2;
b_ptr = b_ptr->cp_b;
}
return 0L;
@ -3485,7 +3463,7 @@ p_all_choicepoints( USES_REGS1 )
{
Term t;
while ((t = all_cps(B PASS_REGS)) == 0L) {
if (!Yap_gcl(Yap_Error_Size, 1, ENV, gc_P(P,CP))) {
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "while dumping choicepoints");
return FALSE;
}
@ -3498,7 +3476,7 @@ p_all_envs( USES_REGS1 )
{
Term t;
while ((t = all_envs(ENV PASS_REGS)) == 0L) {
if (!Yap_gcl(Yap_Error_Size, 1, ENV, gc_P(P,CP))) {
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "while dumping environments");
return FALSE;
}
@ -3511,7 +3489,7 @@ p_current_stack( USES_REGS1 )
{
Term t;
while ((t = all_calls( PASS_REGS1 )) == 0L) {
if (!Yap_gcl(Yap_Error_Size, 1, ENV, gc_P(P,CP))) {
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "while dumping stack");
return FALSE;
}
@ -4484,18 +4462,18 @@ fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, ya
ARG5 = th;
ARG6 = tb;
ARG7 = tr;
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
UNLOCK(pe->PELock);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 7, ENV, gc_P(P,CP))) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 7, ENV, gc_P(P,CP))) {
UNLOCK(pe->PELock);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -4506,9 +4484,9 @@ fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, ya
ARG6 = th;
ARG7 = tb;
ARG8 = tr;
if (!Yap_gcl(Yap_Error_Size, 8, ENV, gc_P(P,CP))) {
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, gc_P(P,CP))) {
UNLOCK(pe->PELock);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
th = ARG6;
@ -4632,18 +4610,18 @@ fetch_next_lu_clause_erase(PredEntry *pe, yamop *i_code, Term th, Term tb, Term
ARG5 = th;
ARG6 = tb;
ARG7 = tr;
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
UNLOCK(pe->PELock);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 7, ENV, gc_P(P,CP))) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 7, ENV, gc_P(P,CP))) {
UNLOCK(pe->PELock);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -4654,9 +4632,9 @@ fetch_next_lu_clause_erase(PredEntry *pe, yamop *i_code, Term th, Term tb, Term
ARG6 = th;
ARG7 = tb;
ARG8 = tr;
if (!Yap_gcl(Yap_Error_Size, 8, ENV, CP)) {
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, CP)) {
UNLOCK(pe->PELock);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
th = ARG6;
@ -4870,7 +4848,7 @@ Yap_UpdateTimestamps(PredEntry *ap)
return;
overflow:
if (!Yap_growstack(64*1024)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return;
}
goto restart;
@ -4969,19 +4947,19 @@ fetch_next_static_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr
}
while ((t = Yap_FetchTermFromDB(cl->usc.ClSource)) == 0L) {
if (first_time) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
ARG5 = th;
ARG6 = tb;
ARG7 = tr;
if (!Yap_gc(7, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
th = ARG5;
@ -4989,12 +4967,12 @@ fetch_next_static_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr
tr = ARG7;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
ARG6 = th;
ARG7 = tb;
ARG8 = tr;
if (!Yap_gcl(Yap_Error_Size, 8, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_gcl(LOCAL_Error_Size, 8, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
th = ARG6;

View File

@ -513,9 +513,9 @@ a_cmp(Term t1, Term t2 USES_REGS)
Float f2 = FloatOfTerm(t2);
#if HAVE_ISNAN
if (isnan(f2)) {
Yap_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
Yap_Error_Term = t2;
Yap_ErrorMessage = "trying to evaluate nan";
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
}
#endif
@ -531,9 +531,9 @@ a_cmp(Term t1, Term t2 USES_REGS)
Float f1 = FloatOfTerm(t1);
#if HAVE_ISNAN
if (isnan(f1)) {
Yap_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
Yap_Error_Term = t1;
Yap_ErrorMessage = "trying to evaluate nan";
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t1;
LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
}
#endif
@ -550,9 +550,9 @@ a_cmp(Term t1, Term t2 USES_REGS)
Float f2 = FloatOfTerm(t2);
#if HAVE_ISNAN
if (isnan(f2)) {
Yap_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
Yap_Error_Term = t2;
Yap_ErrorMessage = "trying to evaluate nan";
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
}
#endif
@ -575,9 +575,9 @@ a_cmp(Term t1, Term t2 USES_REGS)
Float f2 = FloatOfTerm(t2);
#if HAVE_ISNAN
if (isnan(f2)) {
Yap_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
Yap_Error_Term = t2;
Yap_ErrorMessage = "trying to evaluate nan";
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
}
#endif
@ -603,7 +603,7 @@ p_acomp( USES_REGS1 )
Int out;
out = a_cmp(t1, t2 PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out;
}
@ -637,7 +637,7 @@ a_eq(Term t1, Term t2)
}
}
out = a_cmp(t1,t2 PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out == 0;
}
@ -646,7 +646,7 @@ a_dif(Term t1, Term t2)
{
CACHE_REGS
Int out = a_cmp(Deref(t1),Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out != 0;
}
@ -655,7 +655,7 @@ a_gt(Term t1, Term t2)
{ /* A > B */
CACHE_REGS
Int out = a_cmp(Deref(t1),Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out > 0;
}
@ -664,7 +664,7 @@ a_ge(Term t1, Term t2)
{ /* A >= B */
CACHE_REGS
Int out = a_cmp(Deref(t1),Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out >= 0;
}
@ -673,7 +673,7 @@ a_lt(Term t1, Term t2)
{ /* A < B */
CACHE_REGS
Int out = a_cmp(Deref(t1),Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out < 0;
}
@ -682,7 +682,7 @@ a_le(Term t1, Term t2)
{ /* A <= B */
CACHE_REGS
Int out = a_cmp(Deref(t1),Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage); return FALSE; }
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out <= 0;
}

View File

@ -286,7 +286,7 @@ active_branch(int i, int onbranch)
return(i==onbranch);*/
}
#define FAIL(M,T,E) { Yap_ErrorMessage=M; Yap_Error_TYPE = T; Yap_Error_Term = E; return; }
#define FAIL(M,T,E) { LOCAL_ErrorMessage=M; LOCAL_Error_TYPE = T; LOCAL_Error_Term = E; return; }
#if USE_SYSTEM_MALLOC
#define IsNewVar(v) ((CELL *)(v) >= H0 && (CELL *)(v) < LCL0)
@ -567,9 +567,9 @@ compile_sf_term(Term t, int argno, int level)
if (IsAtomicTerm(t))
Yap_emit((cglobs->onhead ? unify_s_a_op : write_s_a_op), t, (CELL) argno, &cglobs->cint);
else if (!IsVarTerm(t)) {
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "illegal argument of soft functor";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "illegal argument of soft functor";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
}
@ -595,9 +595,9 @@ c_args(Term app, unsigned int level, compiler_struct *cglobs)
if (level == 0) {
if (Arity >= MaxTemps) {
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "exceed maximum arity of compiled goal";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "exceed maximum arity of compiled goal";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
}
@ -619,7 +619,7 @@ try_store_as_dbterm(Term t, Int argno, unsigned int arity, int level, compiler_s
while ((g=Yap_SizeGroundTerm(t,TRUE)) < 0) {
/* oops, too deep a term */
save_machine_regs();
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_AUX_BOTCH);
}
if (g < 16)
@ -628,18 +628,18 @@ try_store_as_dbterm(Term t, Int argno, unsigned int arity, int level, compiler_s
H = CellPtr(cglobs->cint.freep);
if ((dbt = Yap_StoreTermInDB(t, -1)) == NULL) {
H = h0;
switch(Yap_Error_TYPE) {
switch(LOCAL_Error_TYPE) {
case OUT_OF_STACK_ERROR:
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_STACK_BOTCH);
case OUT_OF_TRAIL_ERROR:
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TRAIL_BOTCH);
case OUT_OF_HEAP_ERROR:
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_HEAP_BOTCH);
case OUT_OF_AUXSPACE_ERROR:
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_AUX_BOTCH);
default:
siglongjmp(cglobs->cint.CompilerBotch,COMPILER_ERR_BOTCH);
@ -1010,11 +1010,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
} else {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_NUMBER;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_NUMBER;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2 with output bound", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1025,11 +1025,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
if (IsNewVar(t2)) {
char s[32];
Yap_Error_TYPE = INSTANTIATION_ERROR;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/3",s);
sprintf(LOCAL_ErrorMessage, "compiling %s/3",s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1041,11 +1041,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
if (!IsIntegerTerm(t2)) {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_INTEGER;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling functor/3");
sprintf(LOCAL_ErrorMessage, "compiling functor/3");
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1053,11 +1053,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
if (i2 < 0) {
char s[32];
Yap_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling functor/3");
sprintf(LOCAL_ErrorMessage, "compiling functor/3");
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1068,11 +1068,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
} else if (!IsAtomTerm(t1)) {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_ATOM;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_ATOM;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling functor/3");
sprintf(LOCAL_ErrorMessage, "compiling functor/3");
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1126,11 +1126,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
else {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_INTEGER;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1138,11 +1138,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
(IsApplTerm(t2) && IsExtensionFunctor(FunctorOfTerm(t2)))) {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_COMPOUND;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_COMPOUND;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
} else if (IsApplTerm(t2)) {
@ -1169,11 +1169,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
} else {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_INTEGER;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1182,11 +1182,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
if (!IsAtomicTerm(t1)) {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_ATOM;
Yap_Error_Term = t1;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_ATOM;
LOCAL_Error_Term = t1;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
} else {
@ -1197,11 +1197,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
if (!IsIntegerTerm(t2)) {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_INTEGER;
Yap_Error_Term = t2;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1215,11 +1215,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
if (!IsAtomTerm(t1)) {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_ATOM;
Yap_Error_Term = t1;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_ATOM;
LOCAL_Error_Term = t1;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1259,11 +1259,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
} else {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_VARIABLE;
Yap_Error_Term = t1;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_VARIABLE;
LOCAL_Error_Term = t1;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2 with output bound", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1282,11 +1282,11 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler
} else {
char s[32];
Yap_Error_TYPE = TYPE_ERROR_VARIABLE;
Yap_Error_Term = t3;
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = TYPE_ERROR_VARIABLE;
LOCAL_Error_Term = t3;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
Yap_bip_name(Op, s);
sprintf(Yap_ErrorMessage, "compiling %s/2 with input unbound", s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2 with input unbound", s);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -1450,12 +1450,12 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs)
if (IsVarTerm(M) || !IsAtomTerm(M)) {
CACHE_REGS
if (IsVarTerm(M)) {
Yap_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
} else {
Yap_Error_TYPE = TYPE_ERROR_ATOM;
LOCAL_Error_TYPE = TYPE_ERROR_ATOM;
}
Yap_Error_Term = M;
Yap_ErrorMessage = "in module name";
LOCAL_Error_Term = M;
LOCAL_ErrorMessage = "in module name";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
}
@ -1469,8 +1469,8 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs)
FAIL("goal can not be a number", TYPE_ERROR_CALLABLE, Goal);
} else if (IsRefTerm(Goal)) {
CACHE_REGS
Yap_Error_TYPE = TYPE_ERROR_DBREF;
Yap_Error_Term = Goal;
LOCAL_Error_TYPE = TYPE_ERROR_DBREF;
LOCAL_Error_Term = Goal;
FAIL("goal argument in static procedure can not be a data base reference", TYPE_ERROR_CALLABLE, Goal);
}
else if (IsPairTerm(Goal)) {
@ -1906,10 +1906,10 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs)
Term a2 = ArgOfTerm(2,Goal);
if (IsVarTerm(a2) && !IsNewVar(a2)) {
if (IsNewVar(a2)) {
Yap_Error_TYPE = INSTANTIATION_ERROR;
Yap_Error_Term = a2;
Yap_ErrorMessage = Yap_ErrorSay;
sprintf(Yap_ErrorMessage, "compiling %s/2 with second arg unbound", RepAtom(NameOfFunctor(p->FunctorOfPred))->StrOfAE);
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = a2;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
sprintf(LOCAL_ErrorMessage, "compiling %s/2 with second arg unbound", RepAtom(NameOfFunctor(p->FunctorOfPred))->StrOfAE);
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch,1);
}
@ -2314,9 +2314,9 @@ clear_bvarray(int var, CELL *bvarray
if (*bvarray & nbit) {
CACHE_REGS
/* someone had already marked this variable: complain */
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "compiler internal error: variable initialised twice";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "compiler internal error: variable initialised twice";
fprintf(stderr," vsc: compiling7\n");
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
@ -2357,9 +2357,9 @@ push_bvmap(int label, PInstr *pcpc, compiler_struct *cglobs)
{
if (bvindex == MAX_DISJUNCTIONS) {
CACHE_REGS
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "Too many embedded disjunctions";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "Too many embedded disjunctions";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
}
@ -2381,9 +2381,9 @@ reset_bvmap(CELL *bvarray, int nperm, compiler_struct *cglobs)
if (bvindex == 0) {
CACHE_REGS
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "No embedding in disjunctions";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "No embedding in disjunctions";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
}
@ -2402,9 +2402,9 @@ pop_bvmap(CELL *bvarray, int nperm, compiler_struct *cglobs)
{
if (bvindex == 0) {
CACHE_REGS
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "Too few embedded disjunctions";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "Too few embedded disjunctions";
/* save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); */
}
@ -2673,9 +2673,9 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs)
}
if (target1 == cglobs->MaxCTemps) {
CACHE_REGS
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "too many temporaries";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "too many temporaries";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH);
}
@ -2807,9 +2807,9 @@ c_layout(compiler_struct *cglobs)
#ifdef DEBUG
if (cglobs->pbvars != nperm) {
CACHE_REGS
Yap_Error_TYPE = INTERNAL_COMPILER_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "wrong number of variables found in bitmap";
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "wrong number of variables found in bitmap";
save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH);
}
@ -3357,7 +3357,7 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
compiler_struct cglobs;
/* make sure we know there was no error yet */
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
if ((botch_why = sigsetjmp(cglobs.cint.CompilerBotch, 0))) {
restore_machine_regs();
reset_vars(cglobs.vtable);
@ -3371,14 +3371,14 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
ARG3 = src;
YAPLeaveCriticalSection();
if (!Yap_gcl(Yap_Error_Size, NOfArgs, ENV, gc_P(P,CP))) {
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Term = inp_clause;
if (!Yap_gcl(LOCAL_Error_Size, NOfArgs, ENV, gc_P(P,CP))) {
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Term = inp_clause;
}
if (osize > ASP-H) {
if (!Yap_growstack(2*sizeof(CELL)*(ASP-H))) {
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Term = inp_clause;
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Term = inp_clause;
}
}
YAPEnterCriticalSection();
@ -3391,9 +3391,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
YAPLeaveCriticalSection();
ARG1 = inp_clause;
ARG3 = src;
if (!Yap_ExpandPreAllocCodeSpace(Yap_Error_Size, NULL, TRUE)) {
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_Error_Term = inp_clause;
if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) {
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_Term = inp_clause;
}
YAPEnterCriticalSection();
src = ARG3;
@ -3412,9 +3412,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
ARG1 = inp_clause;
ARG3 = src;
YAPLeaveCriticalSection();
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Term = inp_clause;
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_Error_Term = inp_clause;
return NULL;
}
YAPEnterCriticalSection();
@ -3426,9 +3426,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
ARG1 = inp_clause;
ARG3 = src;
YAPLeaveCriticalSection();
if (!Yap_growtrail(Yap_TrailTop-(ADDR)TR, FALSE)) {
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
Yap_Error_Term = inp_clause;
if (!Yap_growtrail(LOCAL_TrailTop-(ADDR)TR, FALSE)) {
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_Error_Term = inp_clause;
return NULL;
}
YAPEnterCriticalSection();
@ -3441,9 +3441,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
}
my_clause = inp_clause;
HB = H;
Yap_ErrorMessage = NULL;
Yap_Error_Size = 0;
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_ErrorMessage = NULL;
LOCAL_Error_Size = 0;
LOCAL_Error_TYPE = YAP_NO_ERROR;
/* initialize variables for code generation */
cglobs.cint.CodeStart = cglobs.cint.cpc = NULL;
@ -3457,7 +3457,7 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
cglobs.cint.success_handler = 0L;
if (ASP <= CellPtr (cglobs.cint.freep) + 256) {
cglobs.vtable = NULL;
Yap_Error_Size = (256+maxvnum)*sizeof(CELL);
LOCAL_Error_Size = (256+maxvnum)*sizeof(CELL);
save_machine_regs();
siglongjmp(cglobs.cint.CompilerBotch,3);
}
@ -3481,9 +3481,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
cglobs.is_a_fact = FALSE;
cglobs.hasdbrefs = FALSE;
if (IsVarTerm(my_clause)) {
Yap_Error_TYPE = INSTANTIATION_ERROR;
Yap_Error_Term = my_clause;
Yap_ErrorMessage = "in compiling clause";
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = my_clause;
LOCAL_ErrorMessage = "in compiling clause";
return 0;
}
if (IsApplTerm(my_clause) && FunctorOfTerm(my_clause) == FunctorAssert) {
@ -3494,9 +3494,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
head = my_clause, body = MkAtomTerm(AtomTrue);
}
if (IsVarTerm(head) || IsPairTerm(head) || IsIntTerm(head) || IsFloatTerm(head) || IsRefTerm(head)) {
Yap_Error_TYPE = TYPE_ERROR_CALLABLE;
Yap_Error_Term = my_clause;
Yap_ErrorMessage = "clause should be atom or term";
LOCAL_Error_TYPE = TYPE_ERROR_CALLABLE;
LOCAL_Error_Term = my_clause;
LOCAL_ErrorMessage = "clause should be atom or term";
return (0);
} else {
@ -3544,10 +3544,10 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
cglobs.cint.cpc->nextInst = cglobs.cint.BlobsStart;
cglobs.cint.BlobsStart = NULL;
}
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return (0);
#ifdef DEBUG
if (Yap_Option['g' - 96])
if (GLOBAL_Option['g' - 96])
Yap_ShowCode(&cglobs.cint);
#endif
} else {
@ -3577,10 +3577,10 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
if (B != NULL) {
HB = B->cp_h;
}
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return (0);
#ifdef DEBUG
if (Yap_Option['g' - 96])
if (GLOBAL_Option['g' - 96])
Yap_ShowCode(&cglobs.cint);
#endif
/* phase 2: classify variables and optimize temporaries */
@ -3596,7 +3596,7 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src)
/* eliminate superfluous pop's and unify_var's */
c_optimize(cglobs.cint.CodeStart);
#ifdef DEBUG
if (Yap_Option['f' - 96])
if (GLOBAL_Option['f' - 96])
Yap_ShowCode(&cglobs.cint);
#endif

View File

@ -75,12 +75,7 @@ STATIC_PROTO (void ShowOp, (char *, struct PSEUDO *));
* afterwards
*/
#ifdef DEBUG
char Yap_Option[20];
YP_FILE *Yap_logfile;
#endif
typedef struct mem_blk {
union {
@ -121,7 +116,7 @@ AllocCMem (UInt size, struct intermediates *cip)
blksz = FIRST_CMEM_BLK_SIZE;
p = (struct mem_blk *)Yap_AllocCodeSpace(blksz);
if (!p) {
Yap_Error_Size = size;
LOCAL_Error_Size = size;
save_machine_regs();
siglongjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
}
@ -132,7 +127,7 @@ AllocCMem (UInt size, struct intermediates *cip)
p = (struct mem_blk *)Yap_AllocCodeSpace(blksz);
if (!p) {
CACHE_REGS
Yap_Error_Size = size;
LOCAL_Error_Size = size;
save_machine_regs();
siglongjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
}
@ -153,7 +148,7 @@ AllocCMem (UInt size, struct intermediates *cip)
cip->freep += size;
if (ASP <= CellPtr (cip->freep) + 256) {
CACHE_REGS
Yap_Error_Size = 256+((char *)cip->freep - (char *)H);
LOCAL_Error_Size = 256+((char *)cip->freep - (char *)H);
save_machine_regs();
siglongjmp(cip->CompilerBotch, OUT_OF_STACK_BOTCH);
}

View File

@ -6,14 +6,14 @@
void cut_c_initialize(void){
CACHE_REGS
Yap_REGS.CUT_C_TOP=(cut_c_str_ptr)Yap_LocalBase;
Yap_REGS.CUT_C_TOP=(cut_c_str_ptr)LOCAL_LocalBase;
}
/*Removes a choice_point from the stack*/
void cut_c_pop(void){
CACHE_REGS
cut_c_str_ptr to_delete = NULL;
if (((CELL *)Yap_REGS.CUT_C_TOP) == ((CELL *)Yap_LocalBase))
if (((CELL *)Yap_REGS.CUT_C_TOP) == ((CELL *)LOCAL_LocalBase))
{
return;
}

329
C/dbase.c
View File

@ -160,7 +160,6 @@ typedef struct db_globs {
UInt sz; /* total size */
} dbglobs;
static dbglobs *s_dbg;
#ifdef SUPPORT_HASH_TABLES
typedef struct {
@ -249,7 +248,7 @@ STATIC_PROTO(DBProp find_int_key, (Int));
static UInt new_trail_size(void)
{
CACHE_REGS
UInt sz = (Yap_TrailTop-(ADDR)TR)/2;
UInt sz = (LOCAL_TrailTop-(ADDR)TR)/2;
if (sz < K64)
return K64;
if (sz > M1)
@ -261,10 +260,10 @@ static int
recover_from_record_error(int nargs)
{
CACHE_REGS
switch(Yap_Error_TYPE) {
switch(LOCAL_Error_TYPE) {
case OUT_OF_STACK_ERROR:
if (!Yap_gcl(Yap_Error_Size, nargs, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_gcl(LOCAL_Error_Size, nargs, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto recover_record;
@ -275,24 +274,24 @@ recover_from_record_error(int nargs)
}
goto recover_record;
case OUT_OF_HEAP_ERROR:
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, Yap_Error_Term, Yap_ErrorMessage);
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
goto recover_record;
case OUT_OF_AUXSPACE_ERROR:
if (!Yap_ExpandPreAllocCodeSpace(Yap_Error_Size, NULL, TRUE)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, Yap_Error_Term, Yap_ErrorMessage);
if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
goto recover_record;
default:
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
recover_record:
Yap_Error_Size = 0;
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_Size = 0;
LOCAL_Error_TYPE = YAP_NO_ERROR;
return TRUE;
}
@ -368,7 +367,7 @@ static Int cmpclls(CELL *a,CELL *b,Int n)
#if !THREADS
int Yap_DBTrailOverflow()
{
return((CELL *)s_dbg->lr > (CELL *)s_dbg->tofref - 2048);
return((CELL *)LOCAL_s_dbg->lr > (CELL *)LOCAL_s_dbg->tofref - 2048);
}
#endif
@ -906,7 +905,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
the variable, the constraint in some cannonical form, what type
of constraint, and a list pointer */
t[0] = (CELL)ptd0;
t[1] = attas[ExtFromCell(ptd0)].to_term_op(ptd0);
t[1] = GLOBAL_attas[ExtFromCell(ptd0)].to_term_op(ptd0);
t[2] = MkIntegerTerm(ExtFromCell(ptd0));
t[3] = ConstraintsTerm;
ConstraintsTerm = Yap_MkApplTerm(FunctorClist, 4, t);
@ -975,8 +974,8 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
return CodeMax;
error:
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_Error_Size = 1024+((char *)AuxSp-(char *)CodeMaxBase);
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_Size = 1024+((char *)AuxSp-(char *)CodeMaxBase);
*vars_foundp = vars_found;
#ifdef RATIONAL_TREES
while (to_visit > to_visit_base) {
@ -994,7 +993,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
return NULL;
error2:
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
*vars_foundp = vars_found;
#ifdef RATIONAL_TREES
while (to_visit > to_visit_base) {
@ -1012,7 +1011,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
return NULL;
error_tr_overflow:
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
*vars_foundp = vars_found;
#ifdef RATIONAL_TREES
while (to_visit > to_visit_base) {
@ -1078,9 +1077,9 @@ sf_include(SFKeep *sfp, struct db_globs *dbg)
*StoPoint++ = tvalue;
j += 2;
} else {
Yap_Error_TYPE = TYPE_ERROR_DBTERM;
Yap_Error_Term = d0;
Yap_ErrorMessage = "wrong term in SF";
LOCAL_Error_TYPE = TYPE_ERROR_DBTERM;
LOCAL_Error_Term = d0;
LOCAL_ErrorMessage = "wrong term in SF";
return(NULL);
}
}
@ -1208,10 +1207,10 @@ static DBRef
generate_dberror_msg(int errnumb, UInt sz, char *msg)
{
CACHE_REGS
Yap_Error_Size = sz;
Yap_Error_TYPE = errnumb;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = msg;
LOCAL_Error_Size = sz;
LOCAL_Error_TYPE = errnumb;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = msg;
return NULL;
}
@ -1365,11 +1364,11 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc
SMALLUNSGN flag;
int NOfLinks = 0;
/* place DBRefs in ConsultStack */
DBRef *TmpRefBase = (DBRef *)Yap_TrailTop;
DBRef *TmpRefBase = (DBRef *)LOCAL_TrailTop;
CELL *CodeAbs; /* how much code did we find */
int vars_found = FALSE;
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (p == NULL) {
if (IsVarTerm(Tm)) {
@ -1420,15 +1419,15 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc
ppt0 = &(pp0->DBT);
}
if ((ADDR)ppt0 >= (ADDR)AuxSp-1024) {
Yap_Error_Size = (UInt)(extra_size+sizeof(ppt0));
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_Size = (UInt)(extra_size+sizeof(ppt0));
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
return NULL;
}
ntp0 = ppt0->Contents;
if ((ADDR)TR >= Yap_TrailTop-1024) {
Yap_Error_Size = 0;
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
if ((ADDR)TR >= LOCAL_TrailTop-1024) {
LOCAL_Error_Size = 0;
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
return NULL;
}
@ -1501,7 +1500,7 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc
}
}
CodeAbs = (CELL *)((CELL)ntp-(CELL)ntp0);
if (Yap_Error_TYPE) {
if (LOCAL_Error_TYPE) {
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
return NULL; /* Error Situation */
}
@ -1517,8 +1516,8 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc
flag = DBComplex;
CodeAbs += CellPtr(dbg->lr) - CellPtr(dbg->LinkAr);
if ((CELL *)((char *)ntp0+(CELL)CodeAbs) > AuxSp) {
Yap_Error_Size = (UInt)DBLength(CodeAbs);
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_Size = (UInt)DBLength(CodeAbs);
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
return NULL;
}
@ -1536,8 +1535,8 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc
if (dbg->tofref != TmpRefBase) {
CodeAbs += (TmpRefBase - dbg->tofref) + 1;
if ((CELL *)((char *)ntp0+(CELL)CodeAbs) > AuxSp) {
Yap_Error_Size = (UInt)DBLength(CodeAbs);
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_Size = (UInt)DBLength(CodeAbs);
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
return NULL;
}
@ -1647,7 +1646,7 @@ record(int Flag, Term key, Term t_data, Term t_code USES_REGS)
int needs_vars;
struct db_globs dbg;
s_dbg = &dbg;
LOCAL_s_dbg = &dbg;
dbg.found_one = NULL;
#ifdef SFUNC
FathersPlace = NIL;
@ -1724,7 +1723,7 @@ record_at(int Flag, DBRef r0, Term t_data, Term t_code USES_REGS)
int needs_vars;
struct db_globs dbg;
s_dbg = &dbg;
LOCAL_s_dbg = &dbg;
#ifdef SFUNC
FathersPlace = NIL;
#endif
@ -1799,6 +1798,7 @@ record_at(int Flag, DBRef r0, Term t_data, Term t_code USES_REGS)
static LogUpdClause *
new_lu_db_entry(Term t, PredEntry *pe)
{
CACHE_REGS
DBTerm *x;
LogUpdClause *cl;
yamop *ipc;
@ -1811,7 +1811,7 @@ new_lu_db_entry(Term t, PredEntry *pe)
if (!(pe->PredFlags & ThreadLocalPredFlag))
d_flag |= InQueue;
#endif
s_dbg = &dbg;
LOCAL_s_dbg = &dbg;
ipc = NEXTOP(((LogUpdClause *)NULL)->ClCode,e);
if ((x = (DBTerm *)CreateDBStruct(t, NULL, d_flag, &needs_vars, (UInt)ipc, &dbg)) == NULL) {
return NULL; /* crash */
@ -1859,9 +1859,9 @@ Yap_new_ludbe(Term t, PredEntry *pe, UInt nargs)
CACHE_REGS
LogUpdClause *x;
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
while ((x = new_lu_db_entry(t, pe)) == NULL) {
if (Yap_Error_TYPE == YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == YAP_NO_ERROR) {
break;
} else {
XREGS[nargs+1] = t;
@ -1951,7 +1951,7 @@ p_rcda( USES_REGS1 )
if (!IsVarTerm(Deref(ARG3)))
return (FALSE);
pe = find_lu_entry(t1);
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
if (pe) {
LogUpdClause *cl;
@ -1973,7 +1973,7 @@ p_rcda( USES_REGS1 )
} else {
TRef = MkDBRefTerm(record(MkFirst, t1, Deref(ARG2), Unsigned(0) PASS_REGS));
}
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(3)) {
goto restart_record;
} else {
@ -1993,11 +1993,11 @@ p_rcdap( USES_REGS1 )
if (!IsVarTerm(Deref(ARG3)))
return FALSE;
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
TRef = MkDBRefTerm(record(MkFirst | MkCode, t1, t2, Unsigned(0) PASS_REGS));
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(3)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2027,7 +2027,7 @@ p_rcda_at( USES_REGS1 )
Yap_Error(TYPE_ERROR_DBREF, t1, "recorda_at/3");
return FALSE;
}
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
dbr = DBRefOfTerm(t1);
if (dbr->Flags & ErasedMask) {
@ -2039,7 +2039,7 @@ p_rcda_at( USES_REGS1 )
} else {
TRef = MkDBRefTerm(record_at(MkFirst, DBRefOfTerm(t1), t2, Unsigned(0) PASS_REGS));
}
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(3)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2061,7 +2061,7 @@ p_rcdz( USES_REGS1 )
if (!IsVarTerm(Deref(ARG3)))
return (FALSE);
pe = find_lu_entry(t1);
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
if (pe) {
LogUpdClause *cl;
@ -2083,7 +2083,7 @@ p_rcdz( USES_REGS1 )
} else {
TRef = MkDBRefTerm(record(MkLast, t1, t2, Unsigned(0) PASS_REGS));
}
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(3)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2105,14 +2105,14 @@ Yap_Recordz(Atom at, Term t2)
PredEntry *pe;
pe = find_lu_entry(MkAtomTerm(at));
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
if (pe) {
record_lu(pe, t2, MkLast);
} else {
record(MkLast, MkAtomTerm(at), t2, Unsigned(0) PASS_REGS);
}
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
ARG1 = t2;
if (recover_from_record_error(1)) {
t2 = ARG1;
@ -2132,10 +2132,10 @@ p_rcdzp( USES_REGS1 )
if (!IsVarTerm(Deref(ARG3)))
return (FALSE);
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
TRef = MkDBRefTerm(record(MkLast | MkCode, t1, t2, Unsigned(0) PASS_REGS));
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(3)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2165,7 +2165,7 @@ p_rcdz_at( USES_REGS1 )
Yap_Error(TYPE_ERROR_DBREF, t1, "recordz_at/3");
return FALSE;
}
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
dbr = DBRefOfTerm(t1);
if (dbr->Flags & ErasedMask) {
@ -2177,7 +2177,7 @@ p_rcdz_at( USES_REGS1 )
} else {
TRef = MkDBRefTerm(record_at(MkLast, dbr, t2, Unsigned(0) PASS_REGS));
}
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(3)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2202,13 +2202,13 @@ p_rcdstatp( USES_REGS1 )
if (IsVarTerm(t3) || !IsIntTerm(t3))
return (FALSE);
mk_first = ((IntOfTerm(t3) % 4) == 2);
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
if (mk_first)
TRef = MkDBRefTerm(record(MkFirst | MkCode, t1, t2, MkIntTerm(0) PASS_REGS));
else
TRef = MkDBRefTerm(record(MkLast | MkCode, t1, t2, MkIntTerm(0) PASS_REGS));
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(4)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2231,11 +2231,11 @@ p_drcdap( USES_REGS1 )
return (FALSE);
if (IsVarTerm(t4) || !IsIntegerTerm(t4))
return (FALSE);
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
restart_record:
TRef = MkDBRefTerm(record(MkFirst | MkCode | WithRef,
t1, t2, t4 PASS_REGS));
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(4)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2259,10 +2259,10 @@ p_drcdzp( USES_REGS1 )
if (IsVarTerm(t4) || !IsIntegerTerm(t4))
return (FALSE);
restart_record:
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
TRef = MkDBRefTerm(record(MkLast | MkCode | WithRef,
t1, t2, t4 PASS_REGS));
if (Yap_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (recover_from_record_error(4)) {
t1 = Deref(ARG1);
t2 = Deref(ARG2);
@ -2358,7 +2358,7 @@ copy_attachments(CELL *ts USES_REGS)
while (TRUE) {
/* store away in case there is an overflow */
if (attas[IntegerOfTerm(ts[2])].term_to_op(ts[1], ts[0] PASS_REGS) == FALSE) {
if (GLOBAL_attas[IntegerOfTerm(ts[2])].term_to_op(ts[1], ts[0] PASS_REGS) == FALSE) {
/* oops, we did not have enough space to copy the elements */
/* reset queue of woken up goals */
TR = tr0;
@ -2466,13 +2466,13 @@ GetDBTerm(DBTerm *DBSP USES_REGS)
}
pt = CellPtr(DBSP->Contents);
if (H+NOf > ASP-CalculateStackGap()/sizeof(CELL)) {
if (Yap_PrologMode & InErrorMode) {
if (LOCAL_PrologMode & InErrorMode) {
if (H+NOf > ASP)
fprintf(Yap_stderr, "\n\n [ FATAL ERROR: No Stack for Error Handling ]\n");
fprintf(GLOBAL_stderr, "\n\n [ FATAL ERROR: No Stack for Error Handling ]\n");
Yap_exit( 1);
} else {
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Size = NOf*sizeof(CELL);
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = NOf*sizeof(CELL);
return (Term)0;
}
}
@ -2487,8 +2487,8 @@ GetDBTerm(DBTerm *DBSP USES_REGS)
if (DBSP->ag.attachments != 0L) {
if (!copy_attachments((CELL *)AdjustIDBPtr(DBSP->ag.attachments,(CELL)HOld-(CELL)(DBSP->Contents)) PASS_REGS)) {
H = HOld;
Yap_Error_TYPE = OUT_OF_ATTVARS_ERROR;
Yap_Error_Size = 0;
LOCAL_Error_TYPE = OUT_OF_ATTVARS_ERROR;
LOCAL_Error_Size = 0;
return (Term)0;
}
}
@ -2549,9 +2549,9 @@ resize_int_keys(UInt new_size) {
new = (Prop *)Yap_AllocCodeSpace(sizeof(Prop)*new_size);
if (new == NULL) {
YAPLeaveCriticalSection();
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "could not allocate space";
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "could not allocate space";
return FALSE;
}
Yap_LUClauseSpace += sizeof(Prop)*new_size;
@ -2642,9 +2642,9 @@ new_lu_int_key(Int key)
init_int_lu_keys();
if (INT_LU_KEYS == NULL) {
CACHE_REGS
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "could not allocate space";
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "could not allocate space";
return NULL;
}
}
@ -2765,9 +2765,9 @@ FetchIntDBPropFromKey(Int key, int flag, int new, char *error_mssg)
init_int_keys();
if (INT_KEYS == NULL) {
CACHE_REGS
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Term = TermNil;
Yap_ErrorMessage = "could not allocate space";
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "could not allocate space";
return NULL;
}
}
@ -3182,20 +3182,20 @@ i_recorded(DBProp AtProp, Term t3 USES_REGS)
/* make sure the garbage collector sees what we want it to see! */
EXTRA_CBACK_ARG(3,1) = (CELL)ref;
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
twork = Deref(ARG2);
t3 = Deref(ARG3);
}
@ -3254,16 +3254,16 @@ i_recorded(DBProp AtProp, Term t3 USES_REGS)
EXTRA_CBACK_ARG(3,2) = MkIntegerTerm(((Int)mask));
EXTRA_CBACK_ARG(3,3) = MkIntegerTerm(((Int)key));
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -3350,20 +3350,20 @@ c_recorded(int flags USES_REGS)
/* make sure the garbage collector sees what we want it to see! */
EXTRA_CBACK_ARG(3,1) = (CELL)ref;
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
PreviousHeap = H;
}
Yap_unify(ARG2, TermDB);
@ -3393,20 +3393,20 @@ c_recorded(int flags USES_REGS)
/* make sure the garbage collector sees what we want it to see! */
EXTRA_CBACK_ARG(3,1) = (CELL)ref;
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, CP)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
PreviousHeap = H;
}
if (Yap_unify(ARG2, TermDB))
@ -3530,16 +3530,16 @@ p_recorded( USES_REGS1 )
Term TermDB;
while ((TermDB = GetDBTermFromDBEntry(ref PASS_REGS)) == (CELL)0) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -3677,16 +3677,16 @@ p_first_instance( USES_REGS1 )
UNLOCK(ref->lock);
while ((TermDB = GetDBTermFromDBEntry(ref PASS_REGS)) == (CELL)0) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -4197,7 +4197,7 @@ MyEraseClause(DynamicClause *clau USES_REGS)
Yap_FreeCodeSpace((char *)clau);
#ifdef DEBUG
if (ref->NOfRefsTo)
fprintf(Yap_stderr, "Error: references to dynamic clause\n");
fprintf(GLOBAL_stderr, "Error: references to dynamic clause\n");
#endif
RemoveDBEntry(ref PASS_REGS);
}
@ -4622,16 +4622,16 @@ static_instance(StaticClause *cl USES_REGS)
while ((TermDB = GetDBTerm(cl->usc.ClSource PASS_REGS)) == 0L) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -4735,17 +4735,17 @@ p_instance( USES_REGS1 )
Term TermDB;
while ((TermDB = GetDBTerm(cl->ClSource PASS_REGS)) == 0L) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
UNLOCK(ap->PELock);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
UNLOCK(ap->PELock);
return FALSE;
}
@ -4758,16 +4758,16 @@ p_instance( USES_REGS1 )
Term TermDB;
while ((TermDB = GetDBTermFromDBEntry(dbr PASS_REGS)) == 0L) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -4790,16 +4790,16 @@ Yap_LUInstance(LogUpdClause *cl, UInt arity)
CACHE_REGS
while ((TermDB = GetDBTerm(cl->ClSource PASS_REGS)) == 0L) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, arity, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, arity, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
@ -5048,11 +5048,11 @@ StoreTermInDB(Term t, int nargs USES_REGS)
int needs_vars;
struct db_globs dbg;
s_dbg = &dbg;
Yap_Error_Size = 0;
LOCAL_s_dbg = &dbg;
LOCAL_Error_Size = 0;
while ((x = (DBTerm *)CreateDBStruct(t, (DBProp)NULL,
InQueue, &needs_vars, 0, &dbg)) == NULL) {
if (Yap_Error_TYPE == YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == YAP_NO_ERROR) {
break;
} else if (nargs == -1) {
return NULL;
@ -5076,11 +5076,12 @@ Yap_StoreTermInDB(Term t, int nargs) {
DBTerm *
Yap_StoreTermInDBPlusExtraSpace(Term t, UInt extra_size, UInt *sz) {
CACHE_REGS
int needs_vars;
struct db_globs dbg;
DBTerm *o;
s_dbg = &dbg;
LOCAL_s_dbg = &dbg;
o = (DBTerm *)CreateDBStruct(t, (DBProp)NULL,
InQueue, &needs_vars, extra_size, &dbg);
*sz = dbg.sz;
@ -5249,16 +5250,16 @@ p_dequeue( USES_REGS1 )
father_key->FirstInQueue = cur_instance->next;
WRITE_UNLOCK(father_key->QRWLock);
while ((TDB = GetDBTerm(cur_instance->DBT PASS_REGS)) == 0L) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -5293,16 +5294,16 @@ p_dequeue_unlocked( USES_REGS1 )
while (cur_instance) {
Term TDB;
while ((TDB = GetDBTerm(cur_instance->DBT PASS_REGS)) == 0L) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -5350,16 +5351,16 @@ p_peek_queue( USES_REGS1 )
while (cur_instance) {
Term TDB;
while ((TDB = GetDBTerm(cur_instance->DBT PASS_REGS)) == 0L) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}

View File

@ -38,7 +38,7 @@ STATIC_PROTO (void detect_bug_location, (yamop *,find_pred_type,char *, int));
#define ONHEAP(ptr) (CellPtr(ptr) >= CellPtr(Yap_HeapBase) && CellPtr(ptr) < CellPtr(HeapTop))
#define ONLOCAL(ptr) (CellPtr(ptr) > CellPtr(H) && CellPtr(ptr) < CellPtr(Yap_LocalBase))
#define ONLOCAL(ptr) (CellPtr(ptr) > CellPtr(H) && CellPtr(ptr) < CellPtr(LOCAL_LocalBase))
static int
hidden (Atom at)
@ -264,14 +264,14 @@ dump_stack( USES_REGS1 )
return;
#if DEBUG
fprintf(stderr,"%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p\n",P,CP,ASP,H,TR,HeapTop);
fprintf(stderr,"%% YAP mode: %ux\n",(unsigned int)Yap_PrologMode);
if (Yap_ErrorMessage)
fprintf(stderr,"%% YAP_ErrorMessage: %s\n",Yap_ErrorMessage);
fprintf(stderr,"%% YAP mode: %ux\n",(unsigned int)LOCAL_PrologMode);
if (LOCAL_ErrorMessage)
fprintf(stderr,"%% LOCAL_ErrorMessage: %s\n",LOCAL_ErrorMessage);
#endif
if (H > ASP || H > LCL0) {
fprintf(stderr,"%% YAP ERROR: Global Collided against Local (%p--%p)\n",H,ASP);
} else if (HeapTop > (ADDR)Yap_GlobalBase) {
fprintf(stderr,"%% YAP ERROR: Code Space Collided against Global (%p--%p)\n", HeapTop, Yap_GlobalBase);
} else if (HeapTop > (ADDR)LOCAL_GlobalBase) {
fprintf(stderr,"%% YAP ERROR: Code Space Collided against Global (%p--%p)\n", HeapTop, LOCAL_GlobalBase);
} else {
#if !USE_SYSTEM_MALLOC
fprintf (stderr,"%ldKB of Code Space (%p--%p)\n",(long int)((CELL)HeapTop-(CELL)Yap_HeapBase)/1024,Yap_HeapBase,HeapTop);
@ -292,7 +292,7 @@ dump_stack( USES_REGS1 )
fprintf (stderr,"%% Continuation: %s\n",(char *)H);
fprintf (stderr,"%% %luKB of Global Stack (%p--%p)\n",(unsigned long int)(sizeof(CELL)*(H-H0))/1024,H0,H);
fprintf (stderr,"%% %luKB of Local Stack (%p--%p)\n",(unsigned long int)(sizeof(CELL)*(LCL0-ASP))/1024,ASP,LCL0);
fprintf (stderr,"%% %luKB of Trail (%p--%p)\n",(unsigned long int)((ADDR)TR-Yap_TrailBase)/1024,Yap_TrailBase,TR);
fprintf (stderr,"%% %luKB of Trail (%p--%p)\n",(unsigned long int)((ADDR)TR-LOCAL_TrailBase)/1024,LOCAL_TrailBase,TR);
fprintf (stderr,"%% Performed %ld garbage collections\n", (unsigned long int)LOCAL_GcCalls);
#if LOW_LEVEL_TRACER
{
@ -352,7 +352,7 @@ static void
error_exit_yap (int value)
{
CACHE_REGS
if (!(Yap_PrologMode & BootMode)) {
if (!(LOCAL_PrologMode & BootMode)) {
dump_stack( PASS_REGS1 );
#if DEBUG
#endif
@ -391,14 +391,14 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
char *tp = tmpbuf;
int psize = YAP_BUF_SIZE;
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (where == 0L)
where = TermNil;
#if DEBUG_STRICT
if (Yap_heap_regs && !(Yap_PrologMode & BootMode))
fprintf(stderr,"***** Processing Error %d (%lx,%x) %s***\n", type, (unsigned long int)LOCAL_ActiveSignals,Yap_PrologMode,format);
if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode))
fprintf(stderr,"***** Processing Error %d (%lx,%x) %s***\n", type, (unsigned long int)LOCAL_ActiveSignals,LOCAL_PrologMode,format);
else
fprintf(stderr,"***** Processing Error %d (%x) %s***\n", type,Yap_PrologMode,format);
fprintf(stderr,"***** Processing Error %d (%x) %s***\n", type,LOCAL_PrologMode,format);
#endif
if (type == INTERRUPT_ERROR) {
fprintf(stderr,"%% YAP exiting: cannot handle signal %d\n",
@ -406,7 +406,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
Yap_exit(1);
}
/* disallow recursive error handling */
if (Yap_PrologMode & InErrorMode) {
if (LOCAL_PrologMode & InErrorMode) {
/* error within error */
va_start (ap, format);
/* now build the error string */
@ -444,7 +444,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
} else {
tmpbuf[0] = '\0';
}
if (Yap_PrologMode == UserCCallMode) {
if (LOCAL_PrologMode == UserCCallMode) {
fprintf(stderr,"%%\n%%\n");
fprintf(stderr,"%% YAP OOOPS in USER C-CODE: %s.\n",tmpbuf);
fprintf(stderr,"%%\n%%\n");
@ -458,12 +458,12 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
if (P == (yamop *)(FAILCODE))
return P;
/* PURE_ABORT may not have set where correctly, BootMode may not have the data terms ready */
if (type == PURE_ABORT || Yap_PrologMode & BootMode) {
if (type == PURE_ABORT || LOCAL_PrologMode & BootMode) {
where = TermNil;
Yap_PrologMode &= ~AbortMode;
Yap_PrologMode |= InErrorMode;
LOCAL_PrologMode &= ~AbortMode;
LOCAL_PrologMode |= InErrorMode;
/* make sure failure will be seen at next port */
if (Yap_PrologMode & AsyncIntMode)
if (LOCAL_PrologMode & AsyncIntMode)
Yap_signal(YAP_FAIL_SIGNAL);
P = FAILCODE;
} else {
@ -474,8 +474,8 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
where = Deref(where);
}
/* Exit Abort Mode, if we were there */
Yap_PrologMode &= ~AbortMode;
Yap_PrologMode |= InErrorMode;
LOCAL_PrologMode &= ~AbortMode;
LOCAL_PrologMode |= InErrorMode;
if (!(where = Yap_CopyTerm(where))) {
where = TermNil;
}
@ -493,7 +493,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
else
tmpbuf[0] = '\0';
va_end (ap);
if (Yap_PrologMode & BootMode) {
if (LOCAL_PrologMode & BootMode) {
/* crash in flames! */
fprintf(stderr,"%% YAP Fatal Error: %s exiting....\n",tmpbuf);
error_exit_yap (1);
@ -506,7 +506,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
{
fprintf(stderr,"%% Internal YAP Error: %s exiting....\n",tmpbuf);
serious = TRUE;
if (Yap_PrologMode & BootMode) {
if (LOCAL_PrologMode & BootMode) {
fprintf(stderr,"%% YAP crashed while booting %s\n",tmpbuf);
} else {
detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, tmpbuf, YAP_BUF_SIZE);
@ -535,7 +535,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
LOCAL_RetriesCounterOn = FALSE;
Yap_JumpToEnv(MkAtomTerm(AtomCallCounter));
P = (yamop *)FAILCODE;
Yap_PrologMode &= ~InErrorMode;
LOCAL_PrologMode &= ~InErrorMode;
return(P);
case PRED_ENTRY_COUNTER_UNDERFLOW:
/* Do a long jump */
@ -544,7 +544,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
LOCAL_RetriesCounterOn = FALSE;
Yap_JumpToEnv(MkAtomTerm(AtomCallAndRetryCounter));
P = (yamop *)FAILCODE;
Yap_PrologMode &= ~InErrorMode;
LOCAL_PrologMode &= ~InErrorMode;
return(P);
case RETRY_COUNTER_UNDERFLOW:
/* Do a long jump */
@ -553,7 +553,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
LOCAL_RetriesCounterOn = FALSE;
Yap_JumpToEnv(MkAtomTerm(AtomRetryCounter));
P = (yamop *)FAILCODE;
Yap_PrologMode &= ~InErrorMode;
LOCAL_PrologMode &= ~InErrorMode;
return(P);
case CONSISTENCY_ERROR:
{
@ -1831,13 +1831,13 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
if (type != PURE_ABORT) {
/* This is used by some complex procedures to detect there was an error */
if (IsAtomTerm(nt[0])) {
strncpy(Yap_ErrorSay, RepAtom(AtomOfTerm(nt[0]))->StrOfAE, MAX_ERROR_MSG_SIZ\
strncpy(LOCAL_ErrorSay, RepAtom(AtomOfTerm(nt[0]))->StrOfAE, MAX_ERROR_MSG_SIZ\
E);
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
} else {
strncpy(Yap_ErrorSay, RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE,\
strncpy(LOCAL_ErrorSay, RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE,\
MAX_ERROR_MSG_SIZE);
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
}
}
switch (type) {
@ -1852,7 +1852,7 @@ E);
if ((stack_dump = Yap_all_calls()) == 0L) {
stack_dump = TermNil;
Yap_Error_Size = 0L;
LOCAL_Error_Size = 0L;
}
nt[1] = MkPairTerm(MkAtomTerm(Yap_LookupAtom(tmpbuf)), stack_dump);
}
@ -1861,7 +1861,7 @@ E);
/* disable active signals at this point */
LOCAL_ActiveSignals = 0;
CreepFlag = CalculateStackGap();
Yap_PrologMode &= ~InErrorMode;
LOCAL_PrologMode &= ~InErrorMode;
LOCK(LOCAL_SignalLock);
/* we might be in the middle of a critical region */
if (LOCAL_InterruptsDisabled) {
@ -1871,16 +1871,16 @@ E);
#if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs);
#endif
siglongjmp(Yap_RestartEnv,1);
siglongjmp(LOCAL_RestartEnv,1);
}
UNLOCK(LOCAL_SignalLock);
/* wait if we we are in user code,
it's up to her to decide */
if (Yap_PrologMode & UserCCallMode) {
if (LOCAL_PrologMode & UserCCallMode) {
if (!(EX = Yap_StoreTermInDB(Yap_MkApplTerm(fun, 2, nt), 0))) {
/* fat chance */
siglongjmp(Yap_RestartEnv,1);
siglongjmp(LOCAL_RestartEnv,1);
}
} else {
if (type == PURE_ABORT) {
@ -1890,7 +1890,7 @@ E);
P = (yamop *)FAILCODE;
}
} else {
Yap_PrologMode &= ~InErrorMode;
LOCAL_PrologMode &= ~InErrorMode;
}
return P;
}

View File

@ -34,7 +34,7 @@ static char SccsId[] = "%W% %G%";
#include <unistd.h>
#endif
yap_error_number Yap_matherror = YAP_NO_ERROR;
static Term
Eval(Term t USES_REGS)
@ -131,14 +131,14 @@ p_is( USES_REGS1 )
Term out = 0L;
while (!(out = Eval(Deref(ARG2) PASS_REGS))) {
if (Yap_Error_TYPE == RESOURCE_ERROR_STACK) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 2, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, Yap_ErrorMessage);
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(Yap_Error_TYPE, Yap_Error_Term, Yap_ErrorMessage);
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -152,19 +152,19 @@ Yap_ArithError(yap_error_number type, Term where, char *format,...)
va_list ap;
LOCAL_ArithError = TRUE;
Yap_Error_TYPE = type;
Yap_Error_Term = where;
if (!Yap_ErrorMessage)
Yap_ErrorMessage = Yap_ErrorSay;
LOCAL_Error_TYPE = type;
LOCAL_Error_Term = where;
if (!LOCAL_ErrorMessage)
LOCAL_ErrorMessage = LOCAL_ErrorSay;
va_start (ap, format);
if (format != NULL) {
#if HAVE_VSNPRINTF
(void) vsnprintf(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap);
(void) vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap);
#else
(void) vsprintf(Yap_ErrorMessage, format, ap);
(void) vsprintf(LOCAL_ErrorMessage, format, ap);
#endif
} else {
Yap_ErrorMessage[0] = '\0';
LOCAL_ErrorMessage[0] = '\0';
}
va_end (ap);
return 0L;

View File

View File

View File

@ -946,12 +946,12 @@ exec_absmi(int top USES_REGS)
{
int lval, out;
if (top && (lval = sigsetjmp (Yap_RestartEnv, 1)) != 0) {
if (top && (lval = sigsetjmp (LOCAL_RestartEnv, 1)) != 0) {
switch(lval) {
case 1:
{ /* restart */
/* otherwise, SetDBForThrow will fail entering critical mode */
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
/* find out where to cut to */
/* siglongjmp resets the TR hardware register */
/* TR and B are crucial, they might have been changed, or not */
@ -966,7 +966,7 @@ exec_absmi(int top USES_REGS)
/* forget any signals active, we're reborne */
LOCAL_ActiveSignals = 0;
CreepFlag = CalculateStackGap();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
UNLOCK(LOCAL_SignalLock);
P = (yamop *)FAILCODE;
}
@ -975,11 +975,11 @@ exec_absmi(int top USES_REGS)
{
/* arithmetic exception */
/* must be done here, otherwise siglongjmp will clobber all the registers */
Yap_Error(Yap_matherror,TermNil,NULL);
Yap_Error(LOCAL_matherror ,TermNil,NULL);
/* reset the registers so that we don't have trash in abstract machine */
Yap_set_fpu_exceptions(yap_flags[LANGUAGE_MODE_FLAG] == 1);
P = (yamop *)FAILCODE;
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
}
break;
case 3:
@ -988,10 +988,10 @@ exec_absmi(int top USES_REGS)
}
default:
/* do nothing */
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
}
} else {
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
}
Yap_CloseSlots( PASS_REGS1 );
YENV = ASP;
@ -1279,8 +1279,8 @@ Yap_RunTopGoal(Term t)
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
#if !USE_SYSTEM_MALLOC
if (Yap_TrailTop - HeapTop < 2048) {
Yap_PrologMode = BootMode;
if (LOCAL_TrailTop - HeapTop < 2048) {
LOCAL_PrologMode = BootMode;
Yap_Error(OUT_OF_TRAIL_ERROR,TermNil,
"unable to boot because of too little Trail space");
}
@ -1474,7 +1474,7 @@ JumpToEnv(Term t USES_REGS) {
/* just keep the throwed object away, we don't need to care about it */
if (!(LOCAL_BallTerm = Yap_StoreTermInDB(t, 0))) {
/* fat chance */
siglongjmp(Yap_RestartEnv,1);
siglongjmp(LOCAL_RestartEnv,1);
}
/* careful, previous step may have caused a stack shift,
so get pointers here */
@ -1515,7 +1515,7 @@ JumpToEnv(Term t USES_REGS) {
LOCAL_BallTerm = NULL;
P = (yamop *)FAILCODE;
/* make sure failure will be seen at next port */
if (Yap_PrologMode & AsyncIntMode) {
if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
HB = B->cp_h;
@ -1529,7 +1529,7 @@ JumpToEnv(Term t USES_REGS) {
#if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs);
#endif
siglongjmp(Yap_RestartEnv,1);
siglongjmp(LOCAL_RestartEnv,1);
}
/* is it a continuation? */
env = handler->cp_env;
@ -1560,7 +1560,7 @@ JumpToEnv(Term t USES_REGS) {
/* B->cp_h = H; */
/* I could backtrack here, but it is easier to leave the unwinding
to the emulator */
if (Yap_PrologMode & AsyncIntMode) {
if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
P = (yamop *)FAILCODE;
@ -1575,7 +1575,7 @@ JumpToEnv(Term t USES_REGS) {
Int
Yap_JumpToEnv(Term t) {
CACHE_REGS
if (Yap_PrologMode & BootMode) {
if (LOCAL_PrologMode & BootMode) {
return FALSE;
}
return JumpToEnv(t PASS_REGS);
@ -1602,7 +1602,6 @@ Yap_InitYaamRegs(void)
{
CACHE_REGS
Term h0var;
#if PUSH_REGS
/* Guarantee that after a longjmp we go back to the original abstract
machine registers */
@ -1617,12 +1616,12 @@ Yap_InitYaamRegs(void)
#endif /* PUSH_REGS */
Yap_ResetExceptionTerm ();
Yap_PutValue (AtomBreak, MkIntTerm (0));
TR = (tr_fr_ptr)Yap_TrailBase;
if (Yap_AttsSize > (Yap_LocalBase-Yap_GlobalBase)/8)
Yap_AttsSize = (Yap_LocalBase-Yap_GlobalBase)/8;
H = H0 = ((CELL *) Yap_GlobalBase)+ Yap_AttsSize/sizeof(CELL);
TR = (tr_fr_ptr)LOCAL_TrailBase;
if (Yap_AttsSize > (LOCAL_LocalBase-LOCAL_GlobalBase)/8)
Yap_AttsSize = (LOCAL_LocalBase-LOCAL_GlobalBase)/8;
H = H0 = ((CELL *) LOCAL_GlobalBase)+ Yap_AttsSize/sizeof(CELL);
RESET_VARIABLE(H0-1);
LCL0 = ASP = (CELL *) Yap_LocalBase;
LCL0 = ASP = (CELL *) LOCAL_LocalBase;
/* notice that an initial choice-point and environment
*must* be created since for the garbage collector to work */
B = NULL;
@ -1637,8 +1636,8 @@ Yap_InitYaamRegs(void)
#ifdef YAPOR_SBA
BSEG =
#endif /* YAPOR_SBA */
BBREG = B_FZ = (choiceptr) Yap_LocalBase;
TR = TR_FZ = (tr_fr_ptr) Yap_TrailBase;
BBREG = B_FZ = (choiceptr) LOCAL_LocalBase;
TR = TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
#endif /* FROZEN_STACKS */
LOCK(LOCAL_SignalLock);
CreepFlag = CalculateStackGap();
@ -1723,16 +1722,16 @@ Yap_GetException(void)
do {
t = Yap_PopTermFromDB(LOCAL_BallTerm);
if (t == 0) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growstack(LOCAL_BallTerm->NOfCells*CellSize)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}

View File

@ -111,7 +111,7 @@ NewArena(UInt size, UInt arity, CELL *where USES_REGS)
if (where == NULL || where == H) {
while (H+size > ASP-1024) {
if (!Yap_gcl(size*sizeof(CELL), arity, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return TermNil;
}
}
@ -188,7 +188,7 @@ GrowArena(Term arena, CELL *pt, UInt old_size, UInt size, UInt arity USES_REGS)
XREGS[arity+1] = arena;
if (!Yap_gcl(size*sizeof(CELL), arity+1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
arena = XREGS[arity+1];
@ -203,7 +203,7 @@ GrowArena(Term arena, CELL *pt, UInt old_size, UInt size, UInt arity USES_REGS)
/* try to recover some room */
if (arena == LOCAL_GlobalArena && 10*(pt-H0) > 8*(H-H0)) {
if (!Yap_gcl(size*sizeof(CELL), arity+1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
return FALSE;
}
}
@ -474,12 +474,12 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, int cop
CELL new;
bp = to_visit;
if (!attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf PASS_REGS)) {
if (!GLOBAL_attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf PASS_REGS)) {
goto overflow;
}
to_visit = bp;
new = *ptf;
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
/* Trail overflow */
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
@ -491,7 +491,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, int cop
#endif
/* first time we met this term */
RESET_VARIABLE(ptf);
if ((ADDR)TR > Yap_TrailTop-MIN_ARENA_SIZE)
if ((ADDR)TR > LOCAL_TrailTop-MIN_ARENA_SIZE)
goto trail_overflow;
Bind_and_Trail(ptd0, (CELL)ptf);
ptf++;
@ -723,13 +723,13 @@ CopyTermToArena(Term t, Term arena, int share, int copy_att_vars, UInt arity, Te
if (arena == LOCAL_GlobalArena)
LOCAL_GlobalArenaOverflows++;
if (!GrowArena(arena, old_top, old_size, min_grow, arity+3 PASS_REGS)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
break;
default: /* temporary space overflow */
if (!Yap_ExpandPreAllocCodeSpace(0,NULL,TRUE)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
@ -1625,7 +1625,7 @@ p_nb_queue_enqueue( USES_REGS1 )
ARG3 = to;
/* fprintf(stderr,"growing %ld cells\n",(unsigned long int)gsiz);*/
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3 PASS_REGS)) {
Yap_Error(OUT_OF_STACK_ERROR, arena, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, arena, LOCAL_ErrorMessage);
return 0L;
}
to = ARG3;
@ -1803,7 +1803,7 @@ p_nb_heap( USES_REGS1 )
while ((heap = MkZeroApplTerm(Yap_MkFunctor(AtomHeap,2*hsize+HEAP_START+1),2*hsize+HEAP_START+1 PASS_REGS)) == TermNil) {
if (!Yap_gcl((2*hsize+HEAP_START+1)*sizeof(CELL), 2, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1977,7 +1977,7 @@ p_nb_heap_add_to_heap( USES_REGS1 )
}
ARG3 = to;
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3 PASS_REGS)) {
Yap_Error(OUT_OF_STACK_ERROR, arena, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, arena, LOCAL_ErrorMessage);
return 0L;
}
to = ARG3;
@ -2085,7 +2085,7 @@ p_nb_beam( USES_REGS1 )
}
while ((beam = MkZeroApplTerm(Yap_MkFunctor(AtomHeap,5*hsize+HEAP_START+1),5*hsize+HEAP_START+1 PASS_REGS)) == TermNil) {
if (!Yap_gcl((4*hsize+HEAP_START+1)*sizeof(CELL), 2, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2363,7 +2363,7 @@ p_nb_beam_add_to_beam( USES_REGS1 )
}
ARG3 = to;
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3 PASS_REGS)) {
Yap_Error(OUT_OF_STACK_ERROR, arena, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, arena, LOCAL_ErrorMessage);
return 0L;
}
to = ARG3;
@ -2475,7 +2475,7 @@ p_nb_beam_keys( USES_REGS1 )
if (H > ASP-1024) {
H = ho;
if (!Yap_gcl(((ASP-H)-1024)*sizeof(CELL), 2, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return TermNil;
}
goto restart;

195
C/gprof.c
View File

@ -123,13 +123,13 @@ typedef greg_t context_reg;
#include <ucontext.h>
#endif
static Int ProfCalls, ProfGCs, ProfHGrows, ProfSGrows, ProfMallocs, ProfOn, ProfOns;
#define TIMER_DEFAULT 100
#define PROFILING_FILE 1
#define PROFPREDS_FILE 2
static char *DIRNAME=NULL;
typedef struct RB_red_blk_node {
yamop *key; /* first address */
@ -142,7 +142,7 @@ typedef struct RB_red_blk_node {
struct RB_red_blk_node* parent;
} rb_red_blk_node;
static rb_red_blk_node *ProfilerRoot, *ProfilerNil;
static rb_red_blk_node *
RBMalloc(UInt size)
@ -162,14 +162,14 @@ RBTreeCreate(void) {
/* see the comment in the rb_red_blk_tree structure in red_black_tree.h */
/* for information on nil and root */
temp=ProfilerNil= RBMalloc(sizeof(rb_red_blk_node));
temp=GLOBAL_ProfilerNil= RBMalloc(sizeof(rb_red_blk_node));
temp->parent=temp->left=temp->right=temp;
temp->pcs=0;
temp->red=0;
temp->key=temp->lim=NULL;
temp->pe=NULL;
temp = RBMalloc(sizeof(rb_red_blk_node));
temp->parent=temp->left=temp->right=ProfilerNil;
temp->parent=temp->left=temp->right=GLOBAL_ProfilerNil;
temp->key=temp->lim=NULL;
temp->pe=NULL;
temp->pcs=0;
@ -199,7 +199,7 @@ RBTreeCreate(void) {
static void
LeftRotate(rb_red_blk_node* x) {
rb_red_blk_node* y;
rb_red_blk_node* nil=ProfilerNil;
rb_red_blk_node* nil=GLOBAL_ProfilerNil;
/* I originally wrote this function to use the sentinel for */
/* nil to avoid checking for nil. However this introduces a */
@ -230,7 +230,7 @@ LeftRotate(rb_red_blk_node* x) {
x->parent=y;
#ifdef DEBUG_ASSERT
Assert(!ProfilerNil->red,"nil not red in LeftRotate");
Assert(!GLOBAL_ProfilerNil->red,"nil not red in LeftRotate");
#endif
}
@ -255,7 +255,7 @@ LeftRotate(rb_red_blk_node* x) {
static void
RightRotate(rb_red_blk_node* y) {
rb_red_blk_node* x;
rb_red_blk_node* nil=ProfilerNil;
rb_red_blk_node* nil=GLOBAL_ProfilerNil;
/* I originally wrote this function to use the sentinel for */
/* nil to avoid checking for nil. However this introduces a */
@ -285,7 +285,7 @@ RightRotate(rb_red_blk_node* y) {
y->parent=x;
#ifdef DEBUG_ASSERT
Assert(!ProfilerNil->red,"nil not red in RightRotate");
Assert(!GLOBAL_ProfilerNil->red,"nil not red in RightRotate");
#endif
}
@ -309,11 +309,11 @@ TreeInsertHelp(rb_red_blk_node* z) {
/* This function should only be called by InsertRBTree (see above) */
rb_red_blk_node* x;
rb_red_blk_node* y;
rb_red_blk_node* nil=ProfilerNil;
rb_red_blk_node* nil=GLOBAL_ProfilerNil;
z->left=z->right=nil;
y=ProfilerRoot;
x=ProfilerRoot->left;
y=GLOBAL_ProfilerRoot;
x=GLOBAL_ProfilerRoot->left;
while( x != nil) {
y=x;
if (x->key > z->key) { /* x.key > z.key */
@ -323,7 +323,7 @@ TreeInsertHelp(rb_red_blk_node* z) {
}
}
z->parent=y;
if ( (y == ProfilerRoot) ||
if ( (y == GLOBAL_ProfilerRoot) ||
(y->key > z->key)) { /* y.key > z.key */
y->left=z;
} else {
@ -331,7 +331,7 @@ TreeInsertHelp(rb_red_blk_node* z) {
}
#ifdef DEBUG_ASSERT
Assert(!ProfilerNil->red,"nil not red in TreeInsertHelp");
Assert(!GLOBAL_ProfilerNil->red,"nil not red in TreeInsertHelp");
#endif
}
@ -403,12 +403,12 @@ RBTreeInsert(yamop *key, yamop *lim) {
}
}
}
ProfilerRoot->left->red=0;
GLOBAL_ProfilerRoot->left->red=0;
return newNode;
#ifdef DEBUG_ASSERT
Assert(!ProfilerNil->red,"nil not red in RBTreeInsert");
Assert(!ProfilerRoot->red,"root not red in RBTreeInsert");
Assert(!GLOBAL_ProfilerNil->red,"nil not red in RBTreeInsert");
Assert(!GLOBAL_ProfilerRoot->red,"root not red in RBTreeInsert");
#endif
}
@ -429,10 +429,10 @@ RBTreeInsert(yamop *key, yamop *lim) {
static rb_red_blk_node*
RBExactQuery(yamop* q) {
rb_red_blk_node* x;
rb_red_blk_node* nil=ProfilerNil;
rb_red_blk_node* nil=GLOBAL_ProfilerNil;
if (!ProfilerRoot) return NULL;
x=ProfilerRoot->left;
if (!GLOBAL_ProfilerRoot) return NULL;
x=GLOBAL_ProfilerRoot->left;
if (x == nil) return NULL;
while(x->key != q) {/*assignemnt*/
if (x->key > q) { /* x->key > q */
@ -450,10 +450,10 @@ static rb_red_blk_node*
RBLookup(yamop *entry) {
rb_red_blk_node *current;
if (!ProfilerRoot)
if (!GLOBAL_ProfilerRoot)
return NULL;
current = ProfilerRoot->left;
while (current != ProfilerNil) {
current = GLOBAL_ProfilerRoot->left;
while (current != GLOBAL_ProfilerNil) {
if (current->key <= entry && current->lim >= entry) {
return current;
}
@ -483,7 +483,7 @@ RBLookup(yamop *entry) {
/***********************************************************************/
static void RBDeleteFixUp(rb_red_blk_node* x) {
rb_red_blk_node* root=ProfilerRoot->left;
rb_red_blk_node* root=GLOBAL_ProfilerRoot->left;
rb_red_blk_node *w;
while( (!x->red) && (root != x)) {
@ -563,8 +563,8 @@ static void RBDeleteFixUp(rb_red_blk_node* x) {
static rb_red_blk_node*
TreeSuccessor(rb_red_blk_node* x) {
rb_red_blk_node* y;
rb_red_blk_node* nil=ProfilerNil;
rb_red_blk_node* root=ProfilerRoot;
rb_red_blk_node* nil=GLOBAL_ProfilerNil;
rb_red_blk_node* root=GLOBAL_ProfilerRoot;
if (nil != (y = x->right)) { /* assignment to y is intentional */
while(y->left != nil) { /* returns the minium of the right subtree of x */
@ -602,8 +602,8 @@ static void
RBDelete(rb_red_blk_node* z){
rb_red_blk_node* y;
rb_red_blk_node* x;
rb_red_blk_node* nil=ProfilerNil;
rb_red_blk_node* root=ProfilerRoot;
rb_red_blk_node* nil=GLOBAL_ProfilerNil;
rb_red_blk_node* root=GLOBAL_ProfilerRoot;
y= ((z->left == nil) || (z->right == nil)) ? z : TreeSuccessor(z);
x= (y->left == nil) ? y->right : y->left;
@ -656,21 +656,21 @@ int size=0;
if (name!=NULL) {
size=strlen(name)+1;
if (DIRNAME!=NULL) free(DIRNAME);
DIRNAME=malloc(size);
if (DIRNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
strcpy(DIRNAME,name);
if (GLOBAL_DIRNAME!=NULL) free(GLOBAL_DIRNAME);
GLOBAL_DIRNAME=malloc(size);
if (GLOBAL_DIRNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
strcpy(GLOBAL_DIRNAME,name);
}
if (DIRNAME==NULL) {
if (GLOBAL_DIRNAME==NULL) {
do {
if (DIRNAME!=NULL) free(DIRNAME);
if (GLOBAL_DIRNAME!=NULL) free(GLOBAL_DIRNAME);
size+=20;
DIRNAME=malloc(size);
if (DIRNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
} while (getcwd(DIRNAME, size-15)==NULL);
GLOBAL_DIRNAME=malloc(size);
if (GLOBAL_DIRNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
} while (getcwd(GLOBAL_DIRNAME, size-15)==NULL);
}
return DIRNAME;
return GLOBAL_DIRNAME;
}
char *profile_names(int);
@ -678,12 +678,12 @@ char *profile_names(int k) {
static char *FNAME=NULL;
int size=200;
if (DIRNAME==NULL) set_profile_dir(NULL);
size=strlen(DIRNAME)+40;
if (GLOBAL_DIRNAME==NULL) set_profile_dir(NULL);
size=strlen(GLOBAL_DIRNAME)+40;
if (FNAME!=NULL) free(FNAME);
FNAME=malloc(size);
if (FNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
strcpy(FNAME,DIRNAME);
strcpy(FNAME,GLOBAL_DIRNAME);
if (k==PROFILING_FILE) {
sprintf(FNAME,"%s/PROFILING_%d",FNAME,getpid());
@ -697,7 +697,7 @@ int size=200;
void del_profile_files(void);
void del_profile_files() {
if (DIRNAME!=NULL) {
if (GLOBAL_DIRNAME!=NULL) {
remove(profile_names(PROFPREDS_FILE));
remove(profile_names(PROFILING_FILE));
}
@ -708,7 +708,7 @@ Yap_inform_profiler_of_clause(yamop *code_start, yamop *code_end, PredEntry *pe,
static Int order=0;
ProfPreds++;
ProfOn = TRUE;
GLOBAL_ProfOn = TRUE;
if (FPreds != NULL) {
Int temp;
@ -716,7 +716,7 @@ static Int order=0;
if (index_code) temp=-order; else temp=order;
fprintf(FPreds,"+%p %p %p %ld\n",code_start,code_end, pe, (long int)temp);
}
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
}
typedef struct clause_entry {
@ -731,7 +731,7 @@ static Int profend( USES_REGS1 );
static void
clean_tree(rb_red_blk_node* node) {
if (node == ProfilerNil)
if (node == GLOBAL_ProfilerNil)
return;
clean_tree(node->left);
clean_tree(node->right);
@ -740,18 +740,18 @@ clean_tree(rb_red_blk_node* node) {
static void
reset_tree(void) {
clean_tree(ProfilerRoot);
Yap_FreeCodeSpace((char *)ProfilerNil);
ProfilerNil = ProfilerRoot = NULL;
ProfCalls = ProfGCs = ProfHGrows = ProfSGrows = ProfMallocs = ProfOns = 0L;
clean_tree(GLOBAL_ProfilerRoot);
Yap_FreeCodeSpace((char *)GLOBAL_ProfilerNil);
GLOBAL_ProfilerNil = GLOBAL_ProfilerRoot = NULL;
GLOBAL_ProfCalls = GLOBAL_ProfGCs = GLOBAL_ProfHGrows = GLOBAL_ProfSGrows = GLOBAL_ProfMallocs = GLOBAL_ProfOns = 0L;
}
static int
InitProfTree(void)
{
if (ProfilerRoot)
if (GLOBAL_ProfilerRoot)
reset_tree();
while (!(ProfilerRoot = RBTreeCreate())) {
while (!(GLOBAL_ProfilerRoot = RBTreeCreate())) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "while initialisating profiler");
return FALSE;
@ -807,10 +807,10 @@ static void RemoveCode(CODEADDR clau)
PredEntry *pp;
UInt count;
if (!ProfilerRoot) return;
if (!GLOBAL_ProfilerRoot) return;
if (!(x = RBExactQuery((yamop *)clau))) {
/* send message */
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
return;
}
pp = x->pe;
@ -823,7 +823,7 @@ static void RemoveCode(CODEADDR clau)
node->pe = pp;
node->pcs = count;
/* send message */
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
return;
} else {
node->pcs += count;
@ -872,7 +872,7 @@ showprofres( USES_REGS1 ) {
}
}
fclose(FProf);
if (ProfCalls==0)
if (GLOBAL_ProfCalls==0)
return TRUE;
return TRUE;
}
@ -909,7 +909,7 @@ p_test( USES_REGS1 ) {
}
}
fclose(FProf);
if (ProfCalls==0)
if (GLOBAL_ProfCalls==0)
return TRUE;
return TRUE;
}
@ -920,39 +920,40 @@ p_test( USES_REGS1 ) {
static void
prof_alrm(int signo, siginfo_t *si, void *scv)
{
{
CACHE_REGS
void * oldpc=(void *) CONTEXT_PC(scv);
yamop *current_p;
ProfCalls++;
GLOBAL_ProfCalls++;
/* skip an interrupt */
if (ProfOn) {
ProfOns++;
if (GLOBAL_ProfOn) {
GLOBAL_ProfOns++;
return;
}
ProfOn = TRUE;
if (Yap_PrologMode & TestMode) {
if (Yap_PrologMode & GCMode) {
ProfGCs++;
ProfOn = FALSE;
GLOBAL_ProfOn = TRUE;
if (LOCAL_PrologMode & TestMode) {
if (LOCAL_PrologMode & GCMode) {
GLOBAL_ProfGCs++;
GLOBAL_ProfOn = FALSE;
return;
}
if (Yap_PrologMode & MallocMode) {
ProfMallocs++;
ProfOn = FALSE;
if (LOCAL_PrologMode & MallocMode) {
GLOBAL_ProfMallocs++;
GLOBAL_ProfOn = FALSE;
return;
}
if (Yap_PrologMode & GrowHeapMode) {
ProfHGrows++;
ProfOn = FALSE;
if (LOCAL_PrologMode & GrowHeapMode) {
GLOBAL_ProfHGrows++;
GLOBAL_ProfOn = FALSE;
return;
}
if (Yap_PrologMode & GrowStackMode) {
ProfSGrows++;
ProfOn = FALSE;
if (LOCAL_PrologMode & GrowStackMode) {
GLOBAL_ProfSGrows++;
GLOBAL_ProfOn = FALSE;
return;
}
@ -987,34 +988,34 @@ prof_alrm(int signo, siginfo_t *si, void *scv)
#if DEBUG
fprintf(stderr,"Oops: %p, %p\n", oldpc, current_p);
#endif
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
return;
}
#endif
if (Yap_OffLineProfiler) {
fprintf(FProf,"%p\n", current_p);
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
return;
}
LookupNode(current_p);
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
}
void
Yap_InformOfRemoval(CODEADDR clau)
{
ProfOn = TRUE;
GLOBAL_ProfOn = TRUE;
if (FPreds != NULL) {
/* just store info about what is going on */
fprintf(FPreds,"-%p\n",clau);
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
return;
}
RemoveCode(clau);
ProfOn = FALSE;
GLOBAL_ProfOn = FALSE;
}
static Int profend( USES_REGS1 );
@ -1024,25 +1025,25 @@ profnode( USES_REGS1 ) {
Term t1 = Deref(ARG1), tleft, tright;
rb_red_blk_node *node;
if (!ProfilerRoot)
if (!GLOBAL_ProfilerRoot)
return FALSE;
if (!(node = (rb_red_blk_node *)IntegerOfTerm(t1)))
node = ProfilerRoot;
node = GLOBAL_ProfilerRoot;
/*
if (node->key)
fprintf(stderr,"%p: %p,%p,%d,%p(%d),%p,%p\n",node,node->key,node->lim,node->pcs,node->pe,node->pe->ArityOfPE,node->right,node->left);
*/
if (node->left == ProfilerNil) {
if (node->left == GLOBAL_ProfilerNil) {
tleft = TermNil;
} else {
tleft = MkIntegerTerm((Int)node->left);
}
if (node->left == ProfilerNil) {
if (node->left == GLOBAL_ProfilerNil) {
tleft = TermNil;
} else {
tleft = MkIntegerTerm((Int)node->left);
}
if (node->right == ProfilerNil) {
if (node->right == GLOBAL_ProfilerNil) {
tright = TermNil;
} else {
tright = MkIntegerTerm((Int)node->right);
@ -1058,12 +1059,12 @@ profnode( USES_REGS1 ) {
static Int
profglobs( USES_REGS1 ) {
return
Yap_unify(ARG1,MkIntegerTerm(ProfCalls)) &&
Yap_unify(ARG2,MkIntegerTerm(ProfGCs)) &&
Yap_unify(ARG3,MkIntegerTerm(ProfHGrows)) &&
Yap_unify(ARG4,MkIntegerTerm(ProfSGrows)) &&
Yap_unify(ARG5,MkIntegerTerm(ProfMallocs)) &&
Yap_unify(ARG6,MkIntegerTerm(ProfOns)) ;
Yap_unify(ARG1,MkIntegerTerm(GLOBAL_ProfCalls)) &&
Yap_unify(ARG2,MkIntegerTerm(GLOBAL_ProfGCs)) &&
Yap_unify(ARG3,MkIntegerTerm(GLOBAL_ProfHGrows)) &&
Yap_unify(ARG4,MkIntegerTerm(GLOBAL_ProfSGrows)) &&
Yap_unify(ARG5,MkIntegerTerm(GLOBAL_ProfMallocs)) &&
Yap_unify(ARG6,MkIntegerTerm(GLOBAL_ProfOns)) ;
}
static Int
@ -1169,14 +1170,14 @@ static Int profoff( USES_REGS1 ) {
return FALSE;
}
static Int profon( USES_REGS1 ) {
static Int ProfOn( USES_REGS1 ) {
Term p;
profoff( PASS_REGS1 );
p=Deref(ARG1);
return(start_profilers(IntOfTerm(p)));
}
static Int profon0( USES_REGS1 ) {
static Int ProfOn0( USES_REGS1 ) {
profoff( PASS_REGS1 );
return(start_profilers(TIMER_DEFAULT));
}
@ -1187,7 +1188,7 @@ static Int profison( USES_REGS1 ) {
static Int profalt( USES_REGS1 ) {
if (ProfilerOn==0) return(FALSE);
if (ProfilerOn==-1) return profon( PASS_REGS1 );
if (ProfilerOn==-1) return ProfOn( PASS_REGS1 );
return profoff( PASS_REGS1 );
}
@ -1248,15 +1249,15 @@ void
Yap_InitLowProf(void)
{
#if LOW_PROF
ProfCalls = 0;
GLOBAL_ProfCalls = 0;
ProfilerOn = FALSE;
Yap_OffLineProfiler = FALSE;
Yap_InitCPred("profinit",0, profinit, SafePredFlag);
Yap_InitCPred("profinit",1, profinit1, SafePredFlag);
Yap_InitCPred("$proftype",1, proftype, SafePredFlag);
Yap_InitCPred("profend" ,0, profend, SafePredFlag);
Yap_InitCPred("profon" , 0, profon0, SafePredFlag);
Yap_InitCPred("profon" , 1, profon, SafePredFlag);
Yap_InitCPred("ProfOn" , 0, ProfOn0, SafePredFlag);
Yap_InitCPred("ProfOn" , 1, ProfOn, SafePredFlag);
Yap_InitCPred("profoff", 0, profoff, SafePredFlag);
Yap_InitCPred("profalt", 0, profalt, SafePredFlag);
Yap_InitCPred("$offline_showprofres", 0, profres0, SafePredFlag);

267
C/grow.c
View File

@ -42,20 +42,7 @@ typedef enum {
STACK_INCREMENTAL_COPYING = 2
} what_stack_copying;
static int heap_overflows = 0;
static Int total_heap_overflow_time = 0;
int stack_overflows = 0;
static Int total_stack_overflow_time = 0;
int delay_overflows = 0;
static Int total_delay_overflow_time = 0;
static int trail_overflows = 0;
static Int total_trail_overflow_time = 0;
static int atom_table_overflows = 0;
static Int total_atom_table_overflow_time = 0;
STATIC_PROTO(Int p_growheap, ( USES_REGS1 ));
STATIC_PROTO(Int p_growstack, ( USES_REGS1 ));
@ -85,10 +72,11 @@ STATIC_PROTO(Term AdjustGlobTerm, (Term CACHE_TYPE));
static void
LeaveGrowMode(prolog_exec_mode grow_mode)
{
Yap_PrologMode &= ~grow_mode;
if (Yap_PrologMode & AbortMode) {
CACHE_REGS
LOCAL_PrologMode &= ~grow_mode;
if (LOCAL_PrologMode & AbortMode) {
CACHE_REGS
Yap_PrologMode &= ~AbortMode;
LOCAL_PrologMode &= ~AbortMode;
Yap_Error(PURE_ABORT, TermNil, "");
/* in case someone mangles the P register */
save_machine_regs();
@ -98,7 +86,7 @@ LeaveGrowMode(prolog_exec_mode grow_mode)
#if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs);
#endif
siglongjmp (Yap_RestartEnv, 1);
siglongjmp (LOCAL_RestartEnv, 1);
#endif
}
}
@ -121,27 +109,27 @@ static void
SetHeapRegs(int copying_threads USES_REGS)
{
#ifdef undf7
fprintf(Yap_stderr,"HeapBase = %x\tHeapTop=%x\nGlobalBase=%x\tGlobalTop=%x\nLocalBase=%x\tLocatTop=%x\n", Yap_HeapBase, HeapTop, Yap_GlobalBase, H, LCL0, ASP);
fprintf(GLOBAL_stderr,"HeapBase = %x\tHeapTop=%x\nGlobalBase=%x\tGlobalTop=%x\nLocalBase=%x\tLocatTop=%x\n", Yap_HeapBase, HeapTop, LOCAL_GlobalBase, H, LCL0, ASP);
#endif
/* The old stack pointers */
LOCAL_OldLCL0 = LCL0;
LOCAL_OldASP = ASP;
LOCAL_OldGlobalBase = (CELL *)Yap_GlobalBase;
LOCAL_OldGlobalBase = (CELL *)LOCAL_GlobalBase;
LOCAL_OldH = H;
LOCAL_OldH0 = H0;
LOCAL_OldTrailBase = Yap_TrailBase;
LOCAL_OldTrailTop = Yap_TrailTop;
LOCAL_OldTrailBase = LOCAL_TrailBase;
LOCAL_OldTrailTop = LOCAL_TrailTop;
LOCAL_OldTR = TR;
LOCAL_OldHeapBase = Yap_HeapBase;
LOCAL_OldHeapTop = HeapTop;
/* Adjust stack addresses */
Yap_TrailBase = TrailAddrAdjust(Yap_TrailBase);
Yap_TrailTop = TrailAddrAdjust(Yap_TrailTop);
LOCAL_TrailBase = TrailAddrAdjust(LOCAL_TrailBase);
LOCAL_TrailTop = TrailAddrAdjust(LOCAL_TrailTop);
if (LOCAL_GDiff) {
/* make sure we are not just expanding the delay stack */
Yap_GlobalBase = BaseAddrAdjust(Yap_GlobalBase);
LOCAL_GlobalBase = BaseAddrAdjust(LOCAL_GlobalBase);
}
Yap_LocalBase = LocalAddrAdjust(Yap_LocalBase);
LOCAL_LocalBase = LocalAddrAdjust(LOCAL_LocalBase);
#if !USE_SYSTEM_MALLOC && !USE_DL_MALLOC
AuxSp = PtoBaseAdjust(AuxSp);
AuxTop = (ADDR)PtoBaseAdjust((CELL *)AuxTop);
@ -275,7 +263,7 @@ RestoreTrail(int worker_p USES_REGS)
if (IsVarTerm(aux_cell)) {
if (aux_cell < LOCAL_start_global_copy || EQUAL_OR_YOUNGER_CP((choiceptr)LOCAL_end_local_copy, (choiceptr)aux_cell)) {
YAPOR_ERROR_CHECKING((CELL *)aux_cell < H0, "RestoreTrail: aux_cell < H0");
YAPOR_ERROR_CHECKING((ADDR)aux_cell > Yap_LocalBase, "RestoreTrail: aux_cell > LocalBase");
YAPOR_ERROR_CHECKING((ADDR)aux_cell > LOCAL_LocalBase, "RestoreTrail: aux_cell > LocalBase");
#ifdef TABLING
*((CELL *) aux_cell) = TrailVal(aux_tr);
#else
@ -286,7 +274,7 @@ RestoreTrail(int worker_p USES_REGS)
} else if (IsPairTerm(aux_cell)) {
/* avoid frozen segments */
aux_cell = (CELL) RepPair(aux_cell);
if (IN_BETWEEN(Yap_TrailBase, aux_cell, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, aux_cell, LOCAL_TrailTop)) {
aux_tr = (tr_fr_ptr) aux_cell;
}
#endif /* TABLING */
@ -319,7 +307,7 @@ MoveGlobal( USES_REGS1 )
* cpcellsd(To,From,NOfCells) - copy the cells downwards - in
* absmi.asm
*/
cpcellsd((CELL *)Yap_GlobalBase, (CELL *)LOCAL_OldGlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
cpcellsd((CELL *)LOCAL_GlobalBase, (CELL *)LOCAL_OldGlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
}
static void
@ -329,7 +317,7 @@ MoveExpandedGlobal( USES_REGS1 )
* cpcellsd(To,From,NOfCells) - copy the cells downwards - in
* absmi.asm
*/
cpcellsd((CELL *)(Yap_GlobalBase+(LOCAL_GDiff-LOCAL_BaseDiff)), (CELL *)Yap_GlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
cpcellsd((CELL *)(LOCAL_GlobalBase+(LOCAL_GDiff-LOCAL_BaseDiff)), (CELL *)LOCAL_GlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
}
static void
@ -340,7 +328,7 @@ MoveGlobalWithHole( USES_REGS1 )
* absmi.asm
*/
#if USE_SYSTEM_MALLOC
cpcellsd((CELL *)((char *)Yap_GlobalBase+(LOCAL_GDiff0-LOCAL_BaseDiff)), (CELL *)Yap_GlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
cpcellsd((CELL *)((char *)LOCAL_GlobalBase+(LOCAL_GDiff0-LOCAL_BaseDiff)), (CELL *)LOCAL_GlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
#else
cpcellsd((CELL *)((char *)LOCAL_OldGlobalBase+LOCAL_GDiff0), (CELL *)LOCAL_OldGlobalBase, LOCAL_OldH - (CELL *)LOCAL_OldGlobalBase);
#endif
@ -373,7 +361,7 @@ AdjustAppl(register CELL t0 USES_REGS)
#ifdef DEBUG
else {
/* strange cell */
/* fprintf(Yap_stderr,"% garbage appl %lx found in stacks by stack shifter\n", t0);*/
/* fprintf(GLOBAL_stderr,"% garbage appl %lx found in stacks by stack shifter\n", t0);*/
}
#endif
return(t0);
@ -391,7 +379,7 @@ AdjustPair(register CELL t0 USES_REGS)
else if (IsHeapP(t))
return (AbsPair(CellPtoHeapAdjust(t)));
#ifdef DEBUG
/* fprintf(Yap_stderr,"% garbage pair %lx found in stacks by stack shifter\n", t0);*/
/* fprintf(GLOBAL_stderr,"% garbage pair %lx found in stacks by stack shifter\n", t0);*/
#endif
return(t0);
}
@ -399,7 +387,7 @@ AdjustPair(register CELL t0 USES_REGS)
static void
AdjustTrail(int adjusting_heap, int thread_copying USES_REGS)
{
volatile tr_fr_ptr ptt, tr_base = (tr_fr_ptr)Yap_TrailBase;
volatile tr_fr_ptr ptt, tr_base = (tr_fr_ptr)LOCAL_TrailBase;
#if defined(YAPOR_THREADS)
if (thread_copying == STACK_INCREMENTAL_COPYING) {
@ -736,10 +724,10 @@ AdjustScannerStacks(TokEntry **tksp, VarEntry **vep USES_REGS)
ves = *vep = (VarEntry *)TrailAddrAdjust((ADDR)ves);
AdjustVarTable(ves PASS_REGS);
}
ves = Yap_AnonVarTable;
ves = LOCAL_AnonVarTable;
if (ves != NULL) {
if (IsOldVarTableTrailPtr(ves))
ves = Yap_AnonVarTable = VarEntryAdjust(ves);
ves = LOCAL_AnonVarTable = VarEntryAdjust(ves);
}
while (ves != NULL) {
VarEntry *vetmp = ves->VarLeft;
@ -773,28 +761,28 @@ static_growheap(long size, int fix_code, struct intermediates *cip, tr_fr_ptr *o
if (size < YAP_ALLOC_SIZE)
size = YAP_ALLOC_SIZE;
size = AdjustPageSize(size);
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
if (!Yap_ExtendWorkSpace(size)) {
Int min_size = AdjustPageSize(((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)+MinHeapGap);
Int min_size = AdjustPageSize(((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)+MinHeapGap);
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
if (size < min_size) size = min_size;
minimal_request = size;
size = Yap_ExtendWorkSpaceThroughHole(size);
if (size < 0) {
Yap_ErrorMessage = "Database crashed against Stacks";
LOCAL_ErrorMessage = "Database crashed against Stacks";
return FALSE;
}
}
start_growth_time = Yap_cputime();
gc_verbose = Yap_is_gc_verbose();
heap_overflows++;
LOCAL_heap_overflows++;
if (gc_verbose) {
#if defined(YAPOR_THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% Database Overflow %d\n", heap_overflows);
fprintf(Yap_stderr, "%% growing the heap %ld bytes\n", size);
fprintf(GLOBAL_stderr, "%% Database Overflow %d\n", LOCAL_heap_overflows);
fprintf(GLOBAL_stderr, "%% growing the heap %ld bytes\n", size);
}
/* CreepFlag is set to force heap expansion */
if (LOCAL_ActiveSignals == YAP_CDOVF_SIGNAL) {
@ -835,10 +823,10 @@ static_growheap(long size, int fix_code, struct intermediates *cip, tr_fr_ptr *o
if (minimal_request)
Yap_AllocHole(minimal_request, size);
growth_time = Yap_cputime()-start_growth_time;
total_heap_overflow_time += growth_time;
LOCAL_total_heap_overflow_time += growth_time;
if (gc_verbose) {
fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(Yap_stderr, "%% Total of %g sec expanding Database\n", (double)total_heap_overflow_time/1000);
fprintf(GLOBAL_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(GLOBAL_stderr, "%% Total of %g sec expanding Database\n", (double)LOCAL_total_heap_overflow_time/1000);
}
return(TRUE);
}
@ -851,7 +839,7 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
UInt start_growth_time, growth_time;
int gc_verbose;
char *omax = (char *)H0;
ADDR old_GlobalBase = Yap_GlobalBase;
ADDR old_GlobalBase = LOCAL_GlobalBase;
UInt minimal_request = 0L;
long size = request;
char vb_msg1 = '\0', *vb_msg2;
@ -867,10 +855,10 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
if (hsplit) {
/* just a little bit of sanity checking */
if (hsplit < H0 && hsplit > (CELL *)Yap_GlobalBase) {
if (hsplit < H0 && hsplit > (CELL *)LOCAL_GlobalBase) {
insert_in_delays = TRUE;
/* expanding attributed variables */
if (omax - size > Yap_GlobalBase+4096*sizeof(CELL)) {
if (omax - size > LOCAL_GlobalBase+4096*sizeof(CELL)) {
/* we can just ask for more room */
size = 0;
do_grow = FALSE;
@ -899,30 +887,30 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
size = AdjustPageSize(size);
}
/* adjust to a multiple of 256) */
Yap_ErrorMessage = NULL;
Yap_PrologMode |= GrowStackMode;
LOCAL_ErrorMessage = NULL;
LOCAL_PrologMode |= GrowStackMode;
start_growth_time = Yap_cputime();
if (do_grow) {
if (!GLOBAL_AllowGlobalExpansion) {
Yap_ErrorMessage = "Global Stack crashed against Local Stack";
LOCAL_ErrorMessage = "Global Stack crashed against Local Stack";
LeaveGrowMode(GrowStackMode);
return 0;
}
if (!GLOBAL_AllowGlobalExpansion || !Yap_ExtendWorkSpace(size)) {
/* always fails when using malloc */
Yap_ErrorMessage = NULL;
size += AdjustPageSize(((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)+MinHeapGap);
LOCAL_ErrorMessage = NULL;
size += AdjustPageSize(((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)+MinHeapGap);
minimal_request = size;
size = Yap_ExtendWorkSpaceThroughHole(size);
if (size < 0) {
Yap_ErrorMessage = "Global Stack crashed against Local Stack";
LOCAL_ErrorMessage = "Global Stack crashed against Local Stack";
LeaveGrowMode(GrowStackMode);
return 0;
}
}
}
gc_verbose = Yap_is_gc_verbose();
delay_overflows++;
LOCAL_delay_overflows++;
if (gc_verbose) {
if (hsplit) {
if (hsplit > H0) {
@ -937,10 +925,10 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
vb_msg2 = "Delay";
}
#if defined(YAPOR_THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% %cO %s Overflow %d\n", vb_msg1, vb_msg2, delay_overflows);
fprintf(Yap_stderr, "%% %cO growing the stacks %ld bytes\n", vb_msg1, size);
fprintf(GLOBAL_stderr, "%% %cO %s Overflow %d\n", vb_msg1, vb_msg2, LOCAL_delay_overflows);
fprintf(GLOBAL_stderr, "%% %cO growing the stacks %ld bytes\n", vb_msg1, size);
}
ASP -= 256;
YAPEnterCriticalSection();
@ -949,11 +937,11 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
/* we got over a hole */
if (minimal_request) {
/* we went over a hole */
LOCAL_BaseDiff = size+((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)-minimal_request;
LOCAL_BaseDiff = size+((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)-minimal_request;
LOCAL_LDiff = LOCAL_TrDiff = size;
} else {
/* we may still have an overflow */
LOCAL_BaseDiff = Yap_GlobalBase - old_GlobalBase;
LOCAL_BaseDiff = LOCAL_GlobalBase - old_GlobalBase;
/* if we grow, we need to move the stacks */
LOCAL_LDiff = LOCAL_TrDiff = LOCAL_BaseDiff+size;
}
@ -983,7 +971,7 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
}
LOCAL_GSplit = hsplit;
LOCAL_XDiff = LOCAL_HDiff = 0;
Yap_GlobalBase = old_GlobalBase;
LOCAL_GlobalBase = old_GlobalBase;
SetHeapRegs(FALSE PASS_REGS);
if (do_grow) {
MoveLocalAndTrail( PASS_REGS1 );
@ -1019,10 +1007,10 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit USES_REGS)
Yap_AllocHole(minimal_request, size);
}
growth_time = Yap_cputime()-start_growth_time;
total_delay_overflow_time += growth_time;
LOCAL_total_delay_overflow_time += growth_time;
if (gc_verbose) {
fprintf(Yap_stderr, "%% %cO took %g sec\n", vb_msg1, (double)growth_time/1000);
fprintf(Yap_stderr, "%% %cO Total of %g sec expanding stacks \n", vb_msg1, (double)total_delay_overflow_time/1000);
fprintf(GLOBAL_stderr, "%% %cO took %g sec\n", vb_msg1, (double)growth_time/1000);
fprintf(GLOBAL_stderr, "%% %cO Total of %g sec expanding stacks \n", vb_msg1, (double)LOCAL_total_delay_overflow_time/1000);
}
LeaveGrowMode(GrowStackMode);
if (hsplit) {
@ -1246,7 +1234,7 @@ static int
do_growheap(int fix_code, UInt in_size, struct intermediates *cip, tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep USES_REGS)
{
unsigned long size = sizeof(CELL) * K16;
int shift_factor = (heap_overflows > 8 ? 8 : heap_overflows);
int shift_factor = (LOCAL_heap_overflows > 8 ? 8 : LOCAL_heap_overflows);
unsigned long sz = size << shift_factor;
if (sz < in_size) {
@ -1355,13 +1343,13 @@ growatomtable( USES_REGS1 )
#endif
return FALSE;
}
atom_table_overflows++;
LOCAL_atom_table_overflows ++;
if (gc_verbose) {
#if defined(YAPOR_THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% Atom Table Overflow %d\n", atom_table_overflows);
fprintf(Yap_stderr, "%% growing the atom table to %ld entries\n", (long int)(nsize));
fprintf(GLOBAL_stderr, "%% Atom Table Overflow %d\n", LOCAL_atom_table_overflows );
fprintf(GLOBAL_stderr, "%% growing the atom table to %ld entries\n", (long int)(nsize));
}
YAPEnterCriticalSection();
init_new_table(ntb, nsize);
@ -1371,10 +1359,10 @@ growatomtable( USES_REGS1 )
AtomHashTableSize = nsize;
YAPLeaveCriticalSection();
growth_time = Yap_cputime()-start_growth_time;
total_atom_table_overflow_time += growth_time;
LOCAL_total_atom_table_overflow_time += growth_time;
if (gc_verbose) {
fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(Yap_stderr, "%% Total of %g sec expanding atom table \n", (double)total_atom_table_overflow_time/1000);
fprintf(GLOBAL_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(GLOBAL_stderr, "%% Total of %g sec expanding atom table \n", (double)LOCAL_total_atom_table_overflow_time/1000);
}
#if USE_SYSTEM_MALLOC
return TRUE;
@ -1480,7 +1468,7 @@ Yap_growstack(long size)
CACHE_REGS
int res;
Yap_PrologMode |= GrowStackMode;
LOCAL_PrologMode |= GrowStackMode;
res=growstack(size PASS_REGS);
LeaveGrowMode(GrowStackMode);
return res;
@ -1491,30 +1479,30 @@ execute_growstack(long size0, int from_trail, int in_parser, tr_fr_ptr *old_trp,
{
UInt minimal_request = 0L;
long size = size0;
ADDR old_Yap_GlobalBase = Yap_GlobalBase;
ADDR old_LOCAL_GlobalBase = LOCAL_GlobalBase;
if (!GLOBAL_AllowGlobalExpansion) {
Yap_ErrorMessage = "Database crashed against stacks";
LOCAL_ErrorMessage = "Database crashed against stacks";
return FALSE;
}
if (!Yap_ExtendWorkSpace(size)) {
/* make sure stacks and trail are contiguous */
Yap_ErrorMessage = NULL;
minimal_request = AdjustPageSize(((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)+4*MinHeapGap+size0);
LOCAL_ErrorMessage = NULL;
minimal_request = AdjustPageSize(((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)+4*MinHeapGap+size0);
size = Yap_ExtendWorkSpaceThroughHole(minimal_request);
if (size < 0) {
Yap_ErrorMessage = "Database crashed against stacks";
LOCAL_ErrorMessage = "Database crashed against stacks";
return FALSE;
}
YAPEnterCriticalSection();
LOCAL_GDiff = LOCAL_DelayDiff = LOCAL_BaseDiff = size-size0;
} else {
YAPEnterCriticalSection();
if (Yap_GlobalBase != old_Yap_GlobalBase) {
LOCAL_GDiff = LOCAL_BaseDiff = LOCAL_DelayDiff = Yap_GlobalBase-old_Yap_GlobalBase;
Yap_GlobalBase=old_Yap_GlobalBase;
if (LOCAL_GlobalBase != old_LOCAL_GlobalBase) {
LOCAL_GDiff = LOCAL_BaseDiff = LOCAL_DelayDiff = LOCAL_GlobalBase-old_LOCAL_GlobalBase;
LOCAL_GlobalBase=old_LOCAL_GlobalBase;
} else {
LOCAL_GDiff = LOCAL_BaseDiff = LOCAL_DelayDiff = 0;
}
@ -1537,7 +1525,7 @@ execute_growstack(long size0, int from_trail, int in_parser, tr_fr_ptr *old_trp,
ASP -= 256;
SetHeapRegs(FALSE PASS_REGS);
if (from_trail) {
Yap_TrailTop += size0;
LOCAL_TrailTop += size0;
}
if (LOCAL_LDiff) {
MoveLocalAndTrail( PASS_REGS1 );
@ -1599,28 +1587,28 @@ growstack(long size USES_REGS)
if (size < YAP_ALLOC_SIZE)
size = YAP_ALLOC_SIZE;
size = AdjustPageSize(size);
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
start_growth_time = Yap_cputime();
gc_verbose = Yap_is_gc_verbose();
stack_overflows++;
LOCAL_stack_overflows++;
if (gc_verbose) {
#if defined(YAPOR) || defined(THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% Stack Overflow %d\n", stack_overflows);
fprintf(Yap_stderr, "%% Global: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)Yap_GlobalBase),Yap_GlobalBase,H);
fprintf(Yap_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(Yap_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)Yap_TrailBase),Yap_TrailBase,TR);
fprintf(Yap_stderr, "%% Growing the stacks %ld bytes\n", size);
fprintf(GLOBAL_stderr, "%% Stack Overflow %d\n", LOCAL_stack_overflows);
fprintf(GLOBAL_stderr, "%% Global: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)LOCAL_GlobalBase),LOCAL_GlobalBase,H);
fprintf(GLOBAL_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(GLOBAL_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)LOCAL_TrailBase),LOCAL_TrailBase,TR);
fprintf(GLOBAL_stderr, "%% Growing the stacks %ld bytes\n", size);
}
if (!execute_growstack(size, FALSE, FALSE, NULL, NULL, NULL PASS_REGS))
return FALSE;
growth_time = Yap_cputime()-start_growth_time;
total_stack_overflow_time += growth_time;
LOCAL_total_stack_overflow_time += growth_time;
if (gc_verbose) {
fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(Yap_stderr, "%% Total of %g sec expanding stacks \n", (double)total_stack_overflow_time/1000);
fprintf(GLOBAL_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(GLOBAL_stderr, "%% Total of %g sec expanding stacks \n", (double)LOCAL_total_stack_overflow_time/1000);
}
return TRUE;
}
@ -1634,33 +1622,33 @@ Yap_growstack_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
UInt start_growth_time, growth_time;
int gc_verbose;
Yap_PrologMode |= GrowStackMode;
LOCAL_PrologMode |= GrowStackMode;
/* adjust to a multiple of 256) */
size = AdjustPageSize((ADDR)LCL0-Yap_GlobalBase);
Yap_ErrorMessage = NULL;
size = AdjustPageSize((ADDR)LCL0-LOCAL_GlobalBase);
LOCAL_ErrorMessage = NULL;
start_growth_time = Yap_cputime();
gc_verbose = Yap_is_gc_verbose();
stack_overflows++;
LOCAL_stack_overflows++;
if (gc_verbose) {
#if defined(YAPOR) || defined(THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% Stack Overflow %d\n", stack_overflows);
fprintf(Yap_stderr, "%% Global: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)Yap_GlobalBase),Yap_GlobalBase,H);
fprintf(Yap_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(Yap_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)Yap_TrailBase),Yap_TrailBase,TR);
fprintf(Yap_stderr, "%% Growing the stacks %ld bytes\n", (unsigned long int)size);
fprintf(GLOBAL_stderr, "%% Stack Overflow %d\n", LOCAL_stack_overflows);
fprintf(GLOBAL_stderr, "%% Global: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)LOCAL_GlobalBase),LOCAL_GlobalBase,H);
fprintf(GLOBAL_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(GLOBAL_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)LOCAL_TrailBase),LOCAL_TrailBase,TR);
fprintf(GLOBAL_stderr, "%% Growing the stacks %ld bytes\n", (unsigned long int)size);
}
if (!execute_growstack(size, FALSE, TRUE, old_trp, tksp, vep PASS_REGS)) {
LeaveGrowMode(GrowStackMode);
return FALSE;
}
growth_time = Yap_cputime()-start_growth_time;
total_stack_overflow_time += growth_time;
LOCAL_total_stack_overflow_time += growth_time;
if (gc_verbose) {
fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(Yap_stderr, "%% Total of %g sec expanding stacks \n", (double)total_stack_overflow_time/1000);
fprintf(GLOBAL_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(GLOBAL_stderr, "%% Total of %g sec expanding stacks \n", (double)LOCAL_total_stack_overflow_time/1000);
}
LeaveGrowMode(GrowStackMode);
return TRUE;
@ -1678,7 +1666,7 @@ static int do_growtrail(long size, int contiguous_only, int in_parser, tr_fr_ptr
#endif
/* at least 64K for trail */
if (!size)
size = ((ADDR)TR-Yap_TrailBase);
size = ((ADDR)TR-LOCAL_TrailBase);
size *= 2;
if (size < YAP_ALLOC_SIZE)
size = YAP_ALLOC_SIZE;
@ -1688,33 +1676,33 @@ static int do_growtrail(long size, int contiguous_only, int in_parser, tr_fr_ptr
size=size0;
/* adjust to a multiple of 256) */
size = AdjustPageSize(size);
trail_overflows++;
LOCAL_trail_overflows++;
if (gc_verbose) {
#if defined(YAPOR) || defined(THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% Trail Overflow %d\n", trail_overflows);
fprintf(GLOBAL_stderr, "%% Trail Overflow %d\n", LOCAL_trail_overflows);
#if USE_SYSTEM_MALLOC
fprintf(Yap_stderr, "%% Heap: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)Yap_GlobalBase),(CELL *)Yap_GlobalBase,H);
fprintf(Yap_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(Yap_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)Yap_TrailBase),Yap_TrailBase,TR);
fprintf(GLOBAL_stderr, "%% Heap: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)LOCAL_GlobalBase),(CELL *)LOCAL_GlobalBase,H);
fprintf(GLOBAL_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(GLOBAL_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)LOCAL_TrailBase),LOCAL_TrailBase,TR);
#endif
fprintf(Yap_stderr, "%% growing the trail %ld bytes\n", size);
fprintf(GLOBAL_stderr, "%% growing the trail %ld bytes\n", size);
}
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
if (!GLOBAL_AllowTrailExpansion) {
Yap_ErrorMessage = "Trail Overflow";
LOCAL_ErrorMessage = "Trail Overflow";
return FALSE;
}
#if USE_SYSTEM_MALLOC
execute_growstack(size, TRUE, in_parser, old_trp, tksp, vep PASS_REGS);
#else
if (!Yap_ExtendWorkSpace(size)) {
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
if (contiguous_only) {
/* I can't expand in this case */
trail_overflows--;
LOCAL_trail_overflows--;
return FALSE;
}
execute_growstack(size, TRUE, in_parser, old_trp, tksp, vep PASS_REGS);
@ -1724,15 +1712,15 @@ static int do_growtrail(long size, int contiguous_only, int in_parser, tr_fr_ptr
LOCAL_TrDiff = LOCAL_LDiff = LOCAL_GDiff = LOCAL_BaseDiff = LOCAL_DelayDiff = LOCAL_XDiff = LOCAL_HDiff = LOCAL_GDiff0 = 0;
AdjustScannerStacks(tksp, vep PASS_REGS);
}
Yap_TrailTop += size;
LOCAL_TrailTop += size;
YAPLeaveCriticalSection();
}
#endif
growth_time = Yap_cputime()-start_growth_time;
total_trail_overflow_time += growth_time;
LOCAL_total_trail_overflow_time += growth_time;
if (gc_verbose) {
fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(Yap_stderr, "%% Total of %g sec expanding trail \n", (double)total_trail_overflow_time/1000);
fprintf(GLOBAL_stderr, "%% took %g sec\n", (double)growth_time/1000);
fprintf(GLOBAL_stderr, "%% Total of %g sec expanding trail \n", (double)LOCAL_total_trail_overflow_time/1000);
}
LOCK(LOCAL_SignalLock);
if (LOCAL_ActiveSignals == YAP_TROVF_SIGNAL) {
@ -1801,8 +1789,8 @@ Yap_shift_visit(CELL **to_visit, CELL ***to_visit_maxp)
static Int
p_inform_trail_overflows( USES_REGS1 )
{
Term tn = MkIntTerm(trail_overflows);
Term tt = MkIntegerTerm(total_trail_overflow_time);
Term tn = MkIntTerm(LOCAL_trail_overflows);
Term tt = MkIntegerTerm(LOCAL_total_trail_overflow_time);
return(Yap_unify(tn, ARG1) && Yap_unify(tt, ARG2));
}
@ -1831,8 +1819,8 @@ p_growheap( USES_REGS1 )
static Int
p_inform_heap_overflows( USES_REGS1 )
{
Term tn = MkIntTerm(heap_overflows);
Term tt = MkIntegerTerm(total_heap_overflow_time);
Term tn = MkIntTerm(LOCAL_heap_overflows);
Term tt = MkIntegerTerm(LOCAL_total_heap_overflow_time);
return(Yap_unify(tn, ARG1) && Yap_unify(tt, ARG2));
}
@ -1855,10 +1843,10 @@ Yap_CopyThreadStacks(int worker_q, int worker_p, int incremental)
REMOTE_ThreadHandle(worker_q).ssize = REMOTE_ThreadHandle(worker_p).ssize;
REMOTE_ThreadHandle(worker_q).tsize = REMOTE_ThreadHandle(worker_p).tsize;
/* compute offset indicators */
Yap_GlobalBase = Yap_thread_gl[worker_p].global_base;
Yap_LocalBase = Yap_thread_gl[worker_p].local_base;
Yap_TrailBase = Yap_thread_gl[worker_p].trail_base;
Yap_TrailTop = Yap_thread_gl[worker_p].trail_top;
LOCAL_GlobalBase = REMOTE_GlobalBase(worker_p);
LOCAL_LocalBase = REMOTE_LocalBase(worker_p);
LOCAL_TrailBase = REMOTE_TrailBase(worker_p);
LOCAL_TrailTop = REMOTE_TrailTop(worker_p);
size = REMOTE_ThreadHandle(worker_q).stack_address-REMOTE_ThreadHandle(worker_p).stack_address;
LOCAL_TrDiff = LOCAL_LDiff = LOCAL_GDiff = LOCAL_GDiff0 = LOCAL_DelayDiff = LOCAL_BaseDiff = size;
LOCAL_XDiff = LOCAL_HDiff = 0;
@ -1929,8 +1917,8 @@ p_growstack( USES_REGS1 )
static Int
p_inform_stack_overflows( USES_REGS1 )
{ /* */
Term tn = MkIntTerm(stack_overflows);
Term tt = MkIntegerTerm(total_stack_overflow_time);
Term tn = MkIntTerm(LOCAL_stack_overflows);
Term tt = MkIntegerTerm(LOCAL_total_stack_overflow_time);
return(Yap_unify(tn, ARG1) && Yap_unify(tt, ARG2));
@ -1939,9 +1927,10 @@ p_inform_stack_overflows( USES_REGS1 )
Int
Yap_total_stack_shift_time(void)
{
return(total_heap_overflow_time+
total_stack_overflow_time+
total_trail_overflow_time);
CACHE_REGS
return(LOCAL_total_heap_overflow_time+
LOCAL_total_stack_overflow_time+
LOCAL_total_trail_overflow_time);
}
void

View File

@ -102,7 +102,7 @@ typedef struct RB_red_blk_node {
static void
gc_growtrail(int committed, tr_fr_ptr begsTR, cont *old_cont_top0 USES_REGS)
{
UInt sz = Yap_TrailTop-(ADDR)LOCAL_OldTR;
UInt sz = LOCAL_TrailTop-(ADDR)LOCAL_OldTR;
/* ask for double the size */
sz = 2*sz;
@ -131,7 +131,7 @@ PUSH_CONTINUATION(CELL *v, int nof USES_REGS) {
cont *x;
x = LOCAL_cont_top;
x++;
if ((ADDR)x > Yap_TrailTop-1024) {
if ((ADDR)x > LOCAL_TrailTop-1024) {
gc_growtrail(TRUE, NULL, NULL PASS_REGS);
}
x->v = v;
@ -294,7 +294,7 @@ static inline gc_ma_hash_entry *
GC_ALLOC_NEW_MASPACE( USES_REGS1 )
{
gc_ma_hash_entry *new = LOCAL_gc_ma_h_top;
if ((char *)LOCAL_gc_ma_h_top > Yap_TrailTop-1024)
if ((char *)LOCAL_gc_ma_h_top > LOCAL_TrailTop-1024)
gc_growtrail(FALSE, NULL, NULL PASS_REGS);
LOCAL_gc_ma_h_top++;
LOCAL_cont_top = (cont *)LOCAL_gc_ma_h_top;
@ -378,7 +378,7 @@ GC_NEW_MAHASH(gc_ma_hash_entry *top USES_REGS) {
static void
check_pr_trail(tr_fr_ptr trp USES_REGS)
{
if ((tr_fr_ptr)Yap_TrailTop-TR < 1024) {
if ((tr_fr_ptr)LOCAL_TrailTop-TR < 1024) {
if (!Yap_growtrail(0, TRUE) || TRUE) {
/* could not find more trail */
save_machine_regs();
@ -553,7 +553,7 @@ RBMalloc(UInt size USES_REGS)
ADDR new = LOCAL_db_vec;
LOCAL_db_vec += size;
if ((ADDR)LOCAL_db_vec > Yap_TrailTop-1024) {
if ((ADDR)LOCAL_db_vec > LOCAL_TrailTop-1024) {
gc_growtrail(FALSE, NULL, NULL PASS_REGS);
}
return (rb_red_blk_node *)new;
@ -873,7 +873,7 @@ init_dbtable(tr_fr_ptr trail_ptr USES_REGS) {
LOCAL_db_vec0 = LOCAL_db_vec = (ADDR)TR;
LOCAL_db_root = RBTreeCreate();
while (trail_ptr > (tr_fr_ptr)Yap_TrailBase) {
while (trail_ptr > (tr_fr_ptr)LOCAL_TrailBase) {
register CELL trail_cell;
trail_ptr--;
@ -891,7 +891,7 @@ init_dbtable(tr_fr_ptr trail_ptr USES_REGS) {
#ifdef YAPOR_SBA
(ADDR) pt0 >= HeapTop
#else
(ADDR) pt0 >= Yap_TrailBase && (ADDR) pt0 < Yap_TrailTop
(ADDR) pt0 >= LOCAL_TrailBase && (ADDR) pt0 < LOCAL_TrailTop
#endif
) {
continue;
@ -978,17 +978,17 @@ inc_vars_of_type(CELL *curr,gc_types val) {
static void
put_type_info(unsigned long total)
{
fprintf(Yap_stderr,"%% type info for %lu cells\n", total);
fprintf(Yap_stderr,"%% %lu vars\n", vars[gc_var]);
fprintf(Yap_stderr,"%% %lu refs\n", vars[gc_ref]);
fprintf(Yap_stderr,"%% %lu references from env\n", env_vars);
fprintf(Yap_stderr,"%% %lu atoms\n", vars[gc_atom]);
fprintf(Yap_stderr,"%% %lu small ints\n", vars[gc_int]);
fprintf(Yap_stderr,"%% %lu other numbers\n", vars[gc_num]);
fprintf(Yap_stderr,"%% %lu lists\n", vars[gc_list]);
fprintf(Yap_stderr,"%% %lu compound terms\n", vars[gc_appl]);
fprintf(Yap_stderr,"%% %lu functors\n", vars[gc_func]);
fprintf(Yap_stderr,"%% %lu suspensions\n", vars[gc_susp]);
fprintf(GLOBAL_stderr,"%% type info for %lu cells\n", total);
fprintf(GLOBAL_stderr,"%% %lu vars\n", vars[gc_var]);
fprintf(GLOBAL_stderr,"%% %lu refs\n", vars[gc_ref]);
fprintf(GLOBAL_stderr,"%% %lu references from env\n", env_vars);
fprintf(GLOBAL_stderr,"%% %lu atoms\n", vars[gc_atom]);
fprintf(GLOBAL_stderr,"%% %lu small ints\n", vars[gc_int]);
fprintf(GLOBAL_stderr,"%% %lu other numbers\n", vars[gc_num]);
fprintf(GLOBAL_stderr,"%% %lu lists\n", vars[gc_list]);
fprintf(GLOBAL_stderr,"%% %lu compound terms\n", vars[gc_appl]);
fprintf(GLOBAL_stderr,"%% %lu functors\n", vars[gc_func]);
fprintf(GLOBAL_stderr,"%% %lu suspensions\n", vars[gc_susp]);
}
static void
@ -1066,7 +1066,7 @@ check_global(void) {
#if INSTRUMENT_GC
if (IsVarTerm(ccurr)) {
if (IsBlobFunctor((Functor)ccurr)) vars[gc_num]++;
else if (ccurr != 0 && (ccurr < (CELL)Yap_GlobalBase || ccurr > (CELL)Yap_TrailTop)) {
else if (ccurr != 0 && (ccurr < (CELL)LOCAL_GlobalBase || ccurr > (CELL)LOCAL_TrailTop)) {
/* printf("%p: %s/%d\n", current,
RepAtom(NameOfFunctor((Functor)ccurr))->StrOfAE,
ArityOfFunctor((Functor)ccurr));*/
@ -1131,7 +1131,7 @@ mark_variable(CELL_PTR current USES_REGS)
next = GET_NEXT(ccur);
if (IsVarTerm(ccur)) {
if (IN_BETWEEN(Yap_GlobalBase,current,H) && GlobalIsAttVar(current) && current==next) {
if (IN_BETWEEN(LOCAL_GlobalBase,current,H) && GlobalIsAttVar(current) && current==next) {
if (next < H0) POP_CONTINUATION();
if (!UNMARKED_MARK(next-1,local_bp)) {
LOCAL_total_marked++;
@ -1213,8 +1213,8 @@ mark_variable(CELL_PTR current USES_REGS)
}
goto begin;
#ifdef DEBUG
} else if (next < (CELL *)Yap_GlobalBase || next > (CELL *)Yap_TrailTop) {
fprintf(Yap_stderr, "OOPS in GC: marking, current=%p, *current=" UInt_FORMAT " next=%p\n", current, ccur, next);
} else if (next < (CELL *)LOCAL_GlobalBase || next > (CELL *)LOCAL_TrailTop) {
fprintf(GLOBAL_stderr, "OOPS in GC: marking, current=%p, *current=" UInt_FORMAT " next=%p\n", current, ccur, next);
#endif
} else {
#ifdef COROUTING
@ -1455,7 +1455,7 @@ mark_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
#ifdef DEBUG
if (size < 0 || size > 512)
fprintf(Yap_stderr,"OOPS in GC: env size for %p is " UInt_FORMAT "\n", gc_ENV, (CELL)size);
fprintf(GLOBAL_stderr,"OOPS in GC: env size for %p is " UInt_FORMAT "\n", gc_ENV, (CELL)size);
#endif
mark_db_fixed((CELL *)gc_ENV[E_CP] PASS_REGS);
/* for each saved variable */
@ -1533,14 +1533,14 @@ mark_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
PredEntry *pe = EnvPreg(gc_ENV[E_CP]);
op_numbers op = Yap_op_from_opcode(ENV_ToOp(gc_ENV[E_CP]));
#if defined(ANALYST) || defined(DEBUG)
fprintf(Yap_stderr,"ENV %p-%p(%d) %s\n", gc_ENV, pvbmap, size-EnvSizeInCells, Yap_op_names[op]);
fprintf(GLOBAL_stderr,"ENV %p-%p(%d) %s\n", gc_ENV, pvbmap, size-EnvSizeInCells, Yap_op_names[op]);
#else
fprintf(Yap_stderr,"ENV %p-%p(%d) %d\n", gc_ENV, pvbmap, size-EnvSizeInCells, (int)op);
fprintf(GLOBAL_stderr,"ENV %p-%p(%d) %d\n", gc_ENV, pvbmap, size-EnvSizeInCells, (int)op);
#endif
if (pe->ArityOfPE)
fprintf(Yap_stderr," %s/%d\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE);
fprintf(GLOBAL_stderr," %s/%d\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE);
else
fprintf(Yap_stderr," %s\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE);
fprintf(GLOBAL_stderr," %s\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE);
}
#endif
gc_ENV = (CELL_PTR) gc_ENV[E_E]; /* link to prev
@ -1597,10 +1597,10 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
#ifdef FROZEN_STACKS
RESET_VARIABLE(&TrailVal(trail_base));
#endif
} else if (hp < (CELL *)Yap_GlobalBase || hp > (CELL *)Yap_TrailTop) {
} else if (hp < (CELL *)LOCAL_GlobalBase || hp > (CELL *)LOCAL_TrailTop) {
/* pointers from the Heap back into the trail are process in mark_regs. */
/* do nothing !!! */
} else if ((hp < (CELL *)gc_B && hp >= gc_H) || hp > (CELL *)Yap_TrailBase) {
} else if ((hp < (CELL *)gc_B && hp >= gc_H) || hp > (CELL *)LOCAL_TrailBase) {
/* clean the trail, avoid dangling pointers! */
RESET_VARIABLE(&TrailTerm(trail_base));
#ifdef FROZEN_STACKS
@ -1615,7 +1615,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
nondeterministically, I know that after backtracking it will be back to be an unbound variable.
The ideal solution would be to unbind all variables. The current solution is to
remark it as an attributed variable */
if (IN_BETWEEN(Yap_GlobalBase,hp,H) && GlobalIsAttVar(hp) && !UNMARKED_MARK(hp-1,LOCAL_bp)) {
if (IN_BETWEEN(LOCAL_GlobalBase,hp,H) && GlobalIsAttVar(hp) && !UNMARKED_MARK(hp-1,LOCAL_bp)) {
LOCAL_total_marked++;
PUSH_POINTER(hp-1 PASS_REGS);
if (hp-1 < LOCAL_HGEN) {
@ -1633,7 +1633,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
tr_fr_ptr nsTR = (tr_fr_ptr)LOCAL_cont_top0;
CELL *cptr = (CELL *)trail_cell;
if ((ADDR)nsTR > Yap_TrailTop-1024) {
if ((ADDR)nsTR > LOCAL_TrailTop-1024) {
gc_growtrail(TRUE, begsTR, old_cont_top0 PASS_REGS);
}
TrailTerm(nsTR) = (CELL)NULL;
@ -1655,7 +1655,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
} else if (IsPairTerm(trail_cell)) {
/* can safely ignore this */
CELL *cptr = RepPair(trail_cell);
if (IN_BETWEEN(Yap_GlobalBase,cptr,H) &&
if (IN_BETWEEN(LOCAL_GlobalBase,cptr,H) &&
GlobalIsAttVar(cptr)) {
TrailTerm(trail_base) = (CELL)cptr;
mark_external_reference(&TrailTerm(trail_base) PASS_REGS);
@ -1899,19 +1899,19 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
PredEntry *pe = Yap_PredForChoicePt(gc_B);
#if defined(ANALYST) || defined(DEBUG)
if (pe == NULL) {
fprintf(Yap_stderr,"%% marked %ld (%s)\n", LOCAL_total_marked, Yap_op_names[opnum]);
fprintf(GLOBAL_stderr,"%% marked %ld (%s)\n", LOCAL_total_marked, Yap_op_names[opnum]);
} else if (pe->ArityOfPE) {
fprintf(Yap_stderr,"%% %s/%d marked %ld (%s)\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, LOCAL_total_marked, Yap_op_names[opnum]);
fprintf(GLOBAL_stderr,"%% %s/%d marked %ld (%s)\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, LOCAL_total_marked, Yap_op_names[opnum]);
} else {
fprintf(Yap_stderr,"%% %s marked %ld (%s)\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE, LOCAL_total_marked, Yap_op_names[opnum]);
fprintf(GLOBAL_stderr,"%% %s marked %ld (%s)\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE, LOCAL_total_marked, Yap_op_names[opnum]);
}
#else
if (pe == NULL) {
fprintf(Yap_stderr,"%% marked %ld (%u)\n", LOCAL_total_marked, (unsigned int)opnum);
fprintf(GLOBAL_stderr,"%% marked %ld (%u)\n", LOCAL_total_marked, (unsigned int)opnum);
} else if (pe->ArityOfPE) {
fprintf(Yap_stderr,"%% %s/%d marked %ld (%u)\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, LOCAL_total_marked, (unsigned int)opnum);
fprintf(GLOBAL_stderr,"%% %s/%d marked %ld (%u)\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, LOCAL_total_marked, (unsigned int)opnum);
} else {
fprintf(Yap_stderr,"%% %s marked %ld (%u)\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE, LOCAL_total_marked, (unsigned int)opnum);
fprintf(GLOBAL_stderr,"%% %s marked %ld (%u)\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE, LOCAL_total_marked, (unsigned int)opnum);
}
#endif
}
@ -2205,7 +2205,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
nargs = rtp->u.Otapl.s;
break;
default:
fprintf(Yap_stderr, "OOPS in GC: Unexpected opcode: %d\n", opnum);
fprintf(GLOBAL_stderr, "OOPS in GC: Unexpected opcode: %d\n", opnum);
nargs = 0;
#else
default:
@ -2367,7 +2367,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
next = current;
current = NULL;
/* next, clean trail */
source = dest = (tr_fr_ptr)Yap_TrailBase;
source = dest = (tr_fr_ptr)LOCAL_TrailBase;
while (source < old_TR) {
CELL trail_cell;
@ -2397,7 +2397,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
/* first, whatever we dumped on the trail. Easier just to do
the registers separately? */
for (trail_ptr = old_TR; trail_ptr < TR; trail_ptr++) {
if (IN_BETWEEN(Yap_GlobalBase,TrailTerm(trail_ptr),Yap_TrailTop) &&
if (IN_BETWEEN(LOCAL_GlobalBase,TrailTerm(trail_ptr),LOCAL_TrailTop) &&
MARKED_PTR(&TrailTerm(trail_ptr))) {
UNMARK(&TrailTerm(trail_ptr));
if (HEAP_PTR(TrailTerm(trail_ptr))) {
@ -2407,7 +2407,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
}
/* next, follows the real trail entries */
trail_ptr = (tr_fr_ptr)Yap_TrailBase;
trail_ptr = (tr_fr_ptr)LOCAL_TrailBase;
dest = trail_ptr;
while (trail_ptr < old_TR) {
register CELL trail_cell;
@ -2445,7 +2445,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
CELL *pt0 = RepPair(trail_cell);
CELL flags;
if (IN_BETWEEN(Yap_GlobalBase, pt0, H) && GlobalIsAttVar(pt0)) {
if (IN_BETWEEN(LOCAL_GlobalBase, pt0, H) && GlobalIsAttVar(pt0)) {
TrailTerm(dest) = trail_cell;
/* be careful with partial gc */
if (HEAP_PTR(TrailTerm(dest))) {
@ -2459,9 +2459,9 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
/* process all segments */
if (
#ifdef YAPOR_SBA
(ADDR) pt0 >= Yap_GlobalBase
(ADDR) pt0 >= LOCAL_GlobalBase
#else
(ADDR) pt0 >= Yap_TrailBase
(ADDR) pt0 >= LOCAL_TrailBase
#endif
) {
trail_ptr++;
@ -2643,28 +2643,28 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
}
LOCAL_new_TR = dest;
if (is_gc_verbose()) {
if (old_TR != (tr_fr_ptr)Yap_TrailBase)
fprintf(Yap_stderr,
if (old_TR != (tr_fr_ptr)LOCAL_TrailBase)
fprintf(GLOBAL_stderr,
"%% Trail: discarded %d (%ld%%) cells out of %ld\n",
LOCAL_discard_trail_entries,
(unsigned long int)(LOCAL_discard_trail_entries*100/(old_TR-(tr_fr_ptr)Yap_TrailBase)),
(unsigned long int)(old_TR-(tr_fr_ptr)Yap_TrailBase));
(unsigned long int)(LOCAL_discard_trail_entries*100/(old_TR-(tr_fr_ptr)LOCAL_TrailBase)),
(unsigned long int)(old_TR-(tr_fr_ptr)LOCAL_TrailBase));
#ifdef DEBUG
if (hp_entrs > 0)
fprintf(Yap_stderr,
fprintf(GLOBAL_stderr,
"%% Trail: unmarked %ld dbentries (%ld%%) out of %ld\n",
(long int)hp_not_in_use,
(long int)(hp_not_in_use*100/hp_entrs),
(long int)hp_entrs);
if (hp_in_use_erased > 0 && hp_erased > 0)
fprintf(Yap_stderr,
fprintf(GLOBAL_stderr,
"%% Trail: deleted %ld dbentries (%ld%%) out of %ld\n",
(long int)hp_erased,
(long int)(hp_erased*100/(hp_erased+hp_in_use_erased)),
(long int)(hp_erased+hp_in_use_erased));
#endif
if (OldHeapUsed) {
fprintf(Yap_stderr,
fprintf(GLOBAL_stderr,
"%% Heap: recovered %ld bytes (%ld%%) out of %ld\n",
(unsigned long int)(OldHeapUsed-HeapUsed),
(unsigned long int)((OldHeapUsed-HeapUsed)/(OldHeapUsed/100)),
@ -2832,7 +2832,7 @@ sweep_choicepoints(choiceptr gc_B USES_REGS)
restart_cp:
/*
* fprintf(Yap_stderr,"sweeping cps: %x, %x, %x\n",
* fprintf(GLOBAL_stderr,"sweeping cps: %x, %x, %x\n",
* *gc_B,CP_Extra(gc_B),CP_Nargs(gc_B));
*/
/* any choice point */
@ -3279,12 +3279,12 @@ compact_heap( USES_REGS1 )
#ifdef DEBUG
if (dest != start_from-1)
fprintf(Yap_stderr,"%% Bad Dest (%lu): %p should be %p\n",
fprintf(GLOBAL_stderr,"%% Bad Dest (%lu): %p should be %p\n",
(unsigned long int)LOCAL_GcCalls,
dest,
start_from-1);
if (LOCAL_total_marked != found_marked)
fprintf(Yap_stderr,"%% Upward (%lu): %lu total against %lu found\n",
fprintf(GLOBAL_stderr,"%% Upward (%lu): %lu total against %lu found\n",
(unsigned long int)LOCAL_GcCalls,
(unsigned long int)LOCAL_total_marked,
(unsigned long int)found_marked);
@ -3343,7 +3343,7 @@ compact_heap( USES_REGS1 )
}
#ifdef DEBUG
if (LOCAL_total_marked != found_marked)
fprintf(Yap_stderr,"%% Downward (%lu): %lu total against %lu found\n",
fprintf(GLOBAL_stderr,"%% Downward (%lu): %lu total against %lu found\n",
(unsigned long int)LOCAL_GcCalls,
(unsigned long int)LOCAL_total_marked,
(unsigned long int)found_marked);
@ -3452,12 +3452,12 @@ icompact_heap( USES_REGS1 )
#ifdef DEBUG
if (dest != H0-1)
fprintf(Yap_stderr,"%% Bad Dest (%lu): %p should be %p\n",
fprintf(GLOBAL_stderr,"%% Bad Dest (%lu): %p should be %p\n",
(unsigned long int)LOCAL_GcCalls,
dest,
H0-1);
if (LOCAL_total_marked != found_marked)
fprintf(Yap_stderr,"%% Upward (%lu): %lu total against %lu found\n",
fprintf(GLOBAL_stderr,"%% Upward (%lu): %lu total against %lu found\n",
(unsigned long int)LOCAL_GcCalls,
(unsigned long int)LOCAL_total_marked,
(unsigned long int)found_marked);
@ -3515,12 +3515,12 @@ icompact_heap( USES_REGS1 )
}
#ifdef DEBUG
if (H0+LOCAL_total_marked != dest)
fprintf(Yap_stderr,"%% Downward (%lu): %p total against %p found\n",
fprintf(GLOBAL_stderr,"%% Downward (%lu): %p total against %p found\n",
(unsigned long int)LOCAL_GcCalls,
H0+LOCAL_total_marked,
dest);
if (LOCAL_total_marked != found_marked)
fprintf(Yap_stderr,"%% Downward (%lu): %lu total against %lu found\n",
fprintf(GLOBAL_stderr,"%% Downward (%lu): %lu total against %lu found\n",
(unsigned long int)LOCAL_GcCalls,
(unsigned long int)LOCAL_total_marked,
(unsigned long int)found_marked);
@ -3591,7 +3591,7 @@ static void
sweep_oldgen(CELL *max, CELL *base USES_REGS)
{
CELL *ptr = base;
char *bpb = LOCAL_bp+(base-(CELL*)Yap_GlobalBase);
char *bpb = LOCAL_bp+(base-(CELL*)LOCAL_GlobalBase);
while (ptr < max) {
if (*bpb) {
@ -3643,12 +3643,12 @@ compaction_phase(tr_fr_ptr old_TR, CELL *current_env, yamop *curp USES_REGS)
-LOCAL_total_smarked
#endif
!= LOCAL_iptop-(CELL_PTR *)H && LOCAL_iptop < (CELL_PTR *)ASP -1024)
fprintf(Yap_stderr,"%% Oops on LOCAL_iptop-H (%ld) vs %ld\n", (unsigned long int)(LOCAL_iptop-(CELL_PTR *)H), LOCAL_total_marked);
fprintf(GLOBAL_stderr,"%% Oops on LOCAL_iptop-H (%ld) vs %ld\n", (unsigned long int)(LOCAL_iptop-(CELL_PTR *)H), LOCAL_total_marked);
*/
#endif
#if DEBUGX
int effectiveness = (((H-H0)-LOCAL_total_marked)*100)/(H-H0);
fprintf(Yap_stderr,"%% using pointers (%d)\n", effectiveness);
fprintf(GLOBAL_stderr,"%% using pointers (%d)\n", effectiveness);
#endif
if (CurrentH0) {
H0 = CurrentH0;
@ -3719,22 +3719,22 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
if (Yap_GetValue(AtomGcTrace) != TermNil)
gc_trace = 1;
if (gc_trace) {
fprintf(Yap_stderr, "%% gc\n");
fprintf(GLOBAL_stderr, "%% gc\n");
} else if (gc_verbose) {
#if defined(YAPOR) || defined(THREADS)
fprintf(Yap_stderr, "%% Worker Id %d:\n", worker_id);
fprintf(GLOBAL_stderr, "%% Worker Id %d:\n", worker_id);
#endif
fprintf(Yap_stderr, "%% Start of garbage collection %lu:\n", (unsigned long int)LOCAL_GcCalls);
fprintf(Yap_stderr, "%% Global: %8ld cells (%p-%p)\n", (long int)heap_cells,H0,H);
fprintf(Yap_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(Yap_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)Yap_TrailBase),Yap_TrailBase,TR);
fprintf(GLOBAL_stderr, "%% Start of garbage collection %lu:\n", (unsigned long int)LOCAL_GcCalls);
fprintf(GLOBAL_stderr, "%% Global: %8ld cells (%p-%p)\n", (long int)heap_cells,H0,H);
fprintf(GLOBAL_stderr, "%% Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
fprintf(GLOBAL_stderr, "%% Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)LOCAL_TrailBase),LOCAL_TrailBase,TR);
}
#if !USE_SYSTEM_MALLOC
if (HeapTop >= Yap_GlobalBase - MinHeapGap) {
if (HeapTop >= LOCAL_GlobalBase - MinHeapGap) {
*--ASP = (CELL)current_env;
if (!Yap_growheap(FALSE, MinHeapGap, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return -1;
}
current_env = (CELL *)*ASP;
@ -3747,7 +3747,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
/* we cannot recover, fail system */
restore_machine_regs();
sz = Yap_TrailTop-(ADDR)LOCAL_OldTR;
sz = LOCAL_TrailTop-(ADDR)LOCAL_OldTR;
/* ask for double the size */
sz = 2*sz;
TR = LOCAL_OldTR;
@ -3778,7 +3778,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
LOCAL_total_smarked = 0;
#endif
LOCAL_discard_trail_entries = 0;
alloc_sz = (CELL *)Yap_TrailTop-(CELL*)Yap_GlobalBase;
alloc_sz = (CELL *)LOCAL_TrailTop-(CELL*)LOCAL_GlobalBase;
LOCAL_bp = Yap_PreAllocCodeSpace();
while (LOCAL_bp+alloc_sz > (char *)AuxSp) {
/* not enough space */
@ -3826,21 +3826,21 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
} else
effectiveness = 0;
if (gc_verbose) {
fprintf(Yap_stderr, "%% Mark: Marked %ld cells of %ld (efficiency: %ld%%) in %g sec\n",
fprintf(GLOBAL_stderr, "%% Mark: Marked %ld cells of %ld (efficiency: %ld%%) in %g sec\n",
(long int)tot, (long int)heap_cells, (long int)effectiveness, (double)(m_time-time_start)/1000);
if (LOCAL_HGEN-H0)
fprintf(Yap_stderr,"%% previous generation has size " UInt_FORMAT ", with " UInt_FORMAT " (" UInt_FORMAT "%%) unmarked\n", (UInt)(LOCAL_HGEN-H0), (UInt)((LOCAL_HGEN-H0)-LOCAL_total_oldies), (UInt)(100*((LOCAL_HGEN-H0)-LOCAL_total_oldies)/(LOCAL_HGEN-H0)));
fprintf(GLOBAL_stderr,"%% previous generation has size " UInt_FORMAT ", with " UInt_FORMAT " (" UInt_FORMAT "%%) unmarked\n", (UInt)(LOCAL_HGEN-H0), (UInt)((LOCAL_HGEN-H0)-LOCAL_total_oldies), (UInt)(100*((LOCAL_HGEN-H0)-LOCAL_total_oldies)/(LOCAL_HGEN-H0)));
#ifdef INSTRUMENT_GC
{
int i;
for (i=0; i<16; i++) {
if (chain[i]) {
fprintf(Yap_stderr, "%% chain[%d]=%lu\n", i, chain[i]);
fprintf(GLOBAL_stderr, "%% chain[%d]=%lu\n", i, chain[i]);
}
}
put_type_info((unsigned long int)tot);
fprintf(Yap_stderr,"%% %lu/%ld before and %lu/%ld after\n", old_vars, (unsigned long int)(B->cp_h-H0), new_vars, (unsigned long int)(H-B->cp_h));
fprintf(Yap_stderr,"%% %ld choicepoints\n", num_bs);
fprintf(GLOBAL_stderr,"%% %lu/%ld before and %lu/%ld after\n", old_vars, (unsigned long int)(B->cp_h-H0), new_vars, (unsigned long int)(H-B->cp_h));
fprintf(GLOBAL_stderr,"%% %ld choicepoints\n", num_bs);
}
#endif
}
@ -3849,7 +3849,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
TR = old_TR;
pop_registers(predarity, nextop PASS_REGS);
TR = LOCAL_new_TR;
/* fprintf(Yap_stderr,"NEW LOCAL_HGEN %ld (%ld)\n", H-H0, LOCAL_HGEN-H0);*/
/* fprintf(GLOBAL_stderr,"NEW LOCAL_HGEN %ld (%ld)\n", H-H0, LOCAL_HGEN-H0);*/
{
Term t = MkVarTerm();
Yap_UpdateTimedVar(LOCAL_GcGeneration, t);
@ -3857,14 +3857,14 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
Yap_UpdateTimedVar(LOCAL_GcPhase, MkIntegerTerm(LOCAL_GcCurrentPhase));
c_time = Yap_cputime();
if (gc_verbose) {
fprintf(Yap_stderr, "%% Compress: took %g sec\n", (double)(c_time-time_start)/1000);
fprintf(GLOBAL_stderr, "%% Compress: took %g sec\n", (double)(c_time-time_start)/1000);
}
gc_time += (c_time-time_start);
LOCAL_TotGcTime += gc_time;
LOCAL_TotGcRecovered += heap_cells-tot;
if (gc_verbose) {
fprintf(Yap_stderr, "%% GC %lu took %g sec, total of %g sec doing GC so far.\n", (unsigned long int)LOCAL_GcCalls, (double)gc_time/1000, (double)LOCAL_TotGcTime/1000);
fprintf(Yap_stderr, "%% Left %ld cells free in stacks.\n",
fprintf(GLOBAL_stderr, "%% GC %lu took %g sec, total of %g sec doing GC so far.\n", (unsigned long int)LOCAL_GcCalls, (double)gc_time/1000, (double)LOCAL_TotGcTime/1000);
fprintf(GLOBAL_stderr, "%% Left %ld cells free in stacks.\n",
(unsigned long int)(ASP-H));
}
check_global();
@ -3874,7 +3874,8 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
static int
is_gc_verbose(void)
{
if (Yap_PrologMode == BootMode)
CACHE_REGS
if (LOCAL_PrologMode == BootMode)
return FALSE;
#ifdef INSTRUMENT_GC
/* always give info when we are debugging gc */
@ -3894,7 +3895,8 @@ Yap_is_gc_verbose(void)
static int
is_gc_very_verbose(void)
{
if (Yap_PrologMode == BootMode)
CACHE_REGS
if (LOCAL_PrologMode == BootMode)
return FALSE;
return Yap_GetValue(AtomGcVeryVerbose) != TermNil;
}
@ -3947,7 +3949,7 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop USES_REGS)
if (gc_margin < gc_lim)
gc_margin = gc_lim;
LOCAL_HGEN = VarOfTerm(Yap_ReadTimedVar(LOCAL_GcGeneration));
if (gc_on && !(Yap_PrologMode & InErrorMode) &&
if (gc_on && !(LOCAL_PrologMode & InErrorMode) &&
/* make sure there is a point in collecting the heap */
(ASP-H0)*sizeof(CELL) > gc_lim &&
H-LOCAL_HGEN > (LCL0-ASP)/2) {
@ -3979,10 +3981,10 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop USES_REGS)
static void
LeaveGCMode( USES_REGS1 )
{
if (Yap_PrologMode & GCMode)
Yap_PrologMode &= ~GCMode;
if (Yap_PrologMode & AbortMode) {
Yap_PrologMode &= ~AbortMode;
if (LOCAL_PrologMode & GCMode)
LOCAL_PrologMode &= ~GCMode;
if (LOCAL_PrologMode & AbortMode) {
LOCAL_PrologMode &= ~AbortMode;
Yap_Error(PURE_ABORT, TermNil, "");
P = FAILCODE;
}
@ -3993,11 +3995,11 @@ Yap_gc(Int predarity, CELL *current_env, yamop *nextop)
{
CACHE_REGS
int res;
Yap_PrologMode |= GCMode;
LOCAL_PrologMode |= GCMode;
res=call_gc(4096, predarity, current_env, nextop PASS_REGS);
LeaveGCMode( PASS_REGS1 );
if (Yap_PrologMode & GCMode)
Yap_PrologMode &= ~GCMode;
if (LOCAL_PrologMode & GCMode)
LOCAL_PrologMode &= ~GCMode;
return res;
}
@ -4008,7 +4010,7 @@ Yap_gcl(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
int res;
UInt min = CalculateStackGap()*sizeof(CELL);
Yap_PrologMode |= GCMode;
LOCAL_PrologMode |= GCMode;
if (gc_lim < min)
gc_lim = min;
res = call_gc(gc_lim, predarity, current_env, nextop PASS_REGS);
@ -4021,7 +4023,7 @@ static Int
p_gc( USES_REGS1 )
{
int res;
Yap_PrologMode |= GCMode;
LOCAL_PrologMode |= GCMode;
if (P->opc == Yap_opcode(_execute_cpred))
res = do_gc(0, ENV, CP PASS_REGS) >= 0;
else

114
C/index.c
View File

@ -832,14 +832,14 @@ sort_group(GroupDef *grp, CELL *top, struct intermediates *cint)
if (!(base = (CELL *)Yap_AllocCodeSpace(2*max*sizeof(CELL)))) {
CACHE_REGS
save_machine_regs();
Yap_Error_Size = 2*max*sizeof(CELL);
LOCAL_Error_Size = 2*max*sizeof(CELL);
siglongjmp(cint->CompilerBotch,2);
}
#else
base = top;
while (top+2*max > (CELL *)Yap_TrailTop) {
while (top+2*max > (CELL *)LOCAL_TrailTop) {
if (!Yap_growtrail(2*max*CellSize, TRUE)) {
Yap_Error_Size = 2*max*CellSize;
LOCAL_Error_Size = 2*max*CellSize;
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
return;
@ -2058,16 +2058,16 @@ groups_in(ClauseDef *min, ClauseDef *max, GroupDef *grp, struct intermediates *c
}
groups++;
grp++;
while (grp+16 > (GroupDef *)Yap_TrailTop) {
while (grp+16 > (GroupDef *)LOCAL_TrailTop) {
UInt sz = (groups+16)*sizeof(GroupDef);
#if USE_SYSTEM_MALLOC
Yap_Error_Size = sz;
LOCAL_Error_Size = sz;
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
#else
if (!Yap_growtrail(sz, TRUE)) {
Yap_Error_Size = sz;
LOCAL_Error_Size = sz;
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
return 0;
@ -2197,7 +2197,7 @@ emit_switch_space(UInt n, UInt item_size, struct intermediates *cint, CELL func_
UInt sz = sizeof(LogUpdIndex)+n*item_size;
LogUpdIndex *cl = (LogUpdIndex *)Yap_AllocCodeSpace(sz);
if (cl == NULL) {
Yap_Error_Size = sz;
LOCAL_Error_Size = sz;
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,2);
@ -2218,7 +2218,7 @@ emit_switch_space(UInt n, UInt item_size, struct intermediates *cint, CELL func_
UInt sz = sizeof(StaticIndex)+n*item_size;
StaticIndex *cl = (StaticIndex *)Yap_AllocCodeSpace(sz);
if (cl == NULL) {
Yap_Error_Size = sz;
LOCAL_Error_Size = sz;
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,2);
@ -3147,8 +3147,8 @@ copy_clauses(ClauseDef *max0, ClauseDef *min0, CELL *top, struct intermediates *
{
CACHE_REGS
UInt sz = ((max0+1)-min0)*sizeof(ClauseDef);
if ((char *)top + sz >= Yap_TrailTop-4096) {
Yap_Error_Size = sz;
if ((char *)top + sz >= LOCAL_TrailTop-4096) {
LOCAL_Error_Size = sz;
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
@ -3337,13 +3337,13 @@ compile_index(struct intermediates *cint)
/* only global variable I use directly */
cint->i_labelno = 1;
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
#if USE_SYSTEM_MALLOC
if (!cint->cls) {
cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef));
if (!cint->cls) {
/* tell how much space we need */
Yap_Error_Size += NClauses*sizeof(ClauseDef);
LOCAL_Error_Size += NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,2);
@ -3355,7 +3355,7 @@ compile_index(struct intermediates *cint)
cint->cls = (ClauseDef *)H;
if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) {
/* tell how much space we need */
Yap_Error_Size += NClauses*sizeof(ClauseDef);
LOCAL_Error_Size += NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,3);
@ -3402,37 +3402,37 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc)
cint.code_addr = NULL;
cint.blks = NULL;
cint.cls = NULL;
Yap_Error_Size = 0;
LOCAL_Error_Size = 0;
if ((setjres = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
restore_machine_regs();
recover_from_failed_susp_on_cls(&cint, 0);
if (!Yap_gcl(Yap_Error_Size, ap->ArityOfPE+NSlots, ENV, next_pc)) {
if (!Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE+NSlots, ENV, next_pc)) {
CleanCls(&cint);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FAILCODE;
}
} else if (setjres == 2) {
restore_machine_regs();
Yap_Error_Size = recover_from_failed_susp_on_cls(&cint, Yap_Error_Size);
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size);
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
CleanCls(&cint);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FAILCODE;
}
} else if (setjres == 4) {
restore_machine_regs();
recover_from_failed_susp_on_cls(&cint, 0);
if (!Yap_growtrail(Yap_Error_Size, FALSE)) {
if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) {
CleanCls(&cint);
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, LOCAL_ErrorMessage);
return FAILCODE;
}
} else if (setjres != 0) {
restore_machine_regs();
recover_from_failed_susp_on_cls(&cint, 0);
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
CleanCls(&cint);
return FAILCODE;
}
@ -3442,14 +3442,14 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc)
cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL;
cint.expand_block = NULL;
cint.label_offset = NULL;
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
if (compile_index(&cint) == (UInt)FAILCODE) {
Yap_ReleaseCMem(&cint);
CleanCls(&cint);
return FAILCODE;
}
#ifdef DEBUG
if (Yap_Option['i' - 'a' + 1]) {
if (GLOBAL_Option['i' - 'a' + 1]) {
Yap_ShowCode(&cint);
}
#endif
@ -3457,10 +3457,10 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc)
LOCAL_IPredArity = ap->ArityOfPE;
if (cint.CodeStart) {
if ((indx_out = Yap_assemble(ASSEMBLING_INDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) {
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
Yap_ReleaseCMem(&cint);
CleanCls(&cint);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
goto restart_index;
@ -3483,7 +3483,7 @@ static istack_entry *
push_stack(istack_entry *sp, Int arg, Term Tag, Term extra, struct intermediates *cint)
{
CACHE_REGS
if (sp+1 > (istack_entry *)Yap_TrailTop) {
if (sp+1 > (istack_entry *)LOCAL_TrailTop) {
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
}
@ -4369,7 +4369,7 @@ expand_index(struct intermediates *cint) {
cint->cls = (ClauseDef *)Yap_AllocCodeSpace(nclauses*sizeof(ClauseDef));
if (!cint->cls) {
/* tell how much space we need */
Yap_Error_Size += NClauses*sizeof(ClauseDef);
LOCAL_Error_Size += NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,2);
@ -4379,7 +4379,7 @@ expand_index(struct intermediates *cint) {
cint->cls = (ClauseDef *)H;
if (cint->cls+2*nclauses > (ClauseDef *)(ASP-4096)) {
/* tell how much space we need (worst case) */
Yap_Error_Size += 2*NClauses*sizeof(ClauseDef);
LOCAL_Error_Size += 2*NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,3);
@ -4397,7 +4397,7 @@ expand_index(struct intermediates *cint) {
cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef));
if (!cint->cls) {
/* tell how much space we need */
Yap_Error_Size += NClauses*sizeof(ClauseDef);
LOCAL_Error_Size += NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
siglongjmp(cint->CompilerBotch,2);
@ -4407,7 +4407,7 @@ expand_index(struct intermediates *cint) {
cint->cls = (ClauseDef *)H;
if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) {
/* tell how much space we need (worst case) */
Yap_Error_Size += 2*NClauses*sizeof(ClauseDef);
LOCAL_Error_Size += 2*NClauses*sizeof(ClauseDef);
save_machine_regs();
siglongjmp(cint->CompilerBotch,3);
}
@ -4513,11 +4513,11 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) {
restore_machine_regs();
/* grow stack */
recover_from_failed_susp_on_cls(&cint, 0);
Yap_gcl(Yap_Error_Size, ap->ArityOfPE+ExtraArgs, ENV, nextop);
Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE+ExtraArgs, ENV, nextop);
} else if (cb == 2) {
restore_machine_regs();
Yap_Error_Size = recover_from_failed_susp_on_cls(&cint, Yap_Error_Size);
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size);
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
save_machine_regs();
if (ap->PredFlags & LogUpdatePredFlag) {
Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap);
@ -4540,14 +4540,14 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) {
#if defined(YAPOR) || defined(THREADS)
}
#endif
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
CleanCls(&cint);
return FAILCODE;
}
} else if (cb == 4) {
restore_machine_regs();
Yap_ReleaseCMem(&cint);
if (!Yap_growtrail(Yap_Error_Size, FALSE)) {
if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) {
save_machine_regs();
if (ap->PredFlags & LogUpdatePredFlag) {
Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap);
@ -4564,15 +4564,15 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) {
restart_index:
cint.CodeStart = cint.cpc = cint.BlobsStart = cint.icpc = NIL;
cint.CurrentPred = ap;
Yap_ErrorMessage = NULL;
Yap_Error_Size = 0;
LOCAL_ErrorMessage = NULL;
LOCAL_Error_Size = 0;
if (P->opc == Yap_opcode(_expand_clauses)) {
expand_clauses = P;
} else {
expand_clauses = NULL;
}
#ifdef DEBUG
if (Yap_Option['i' - 'a' + 1]) {
if (GLOBAL_Option['i' - 'a' + 1]) {
Term tmod = ap->ModuleOfPred;
if (!tmod) tmod = TermProlog;
#if THREADS
@ -4634,7 +4634,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) {
return FAILCODE;
}
#ifdef DEBUG
if (Yap_Option['i' - 'a' + 1]) {
if (GLOBAL_Option['i' - 'a' + 1]) {
Yap_ShowCode(&cint);
}
#endif
@ -4642,8 +4642,8 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) {
LOCAL_IPredArity = ap->ArityOfPE;
if (cint.CodeStart) {
if ((indx_out = Yap_assemble(ASSEMBLING_EINDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) {
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
Yap_ReleaseCMem(&cint);
CleanCls(&cint);
return FAILCODE;
@ -4715,7 +4715,7 @@ static path_stack_entry *
push_path(path_stack_entry *sp, yamop **pipc, ClauseDef *clp, struct intermediates *cint)
{
CACHE_REGS
if (sp+1 > (path_stack_entry *)Yap_TrailTop) {
if (sp+1 > (path_stack_entry *)LOCAL_TrailTop) {
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
}
@ -4732,7 +4732,7 @@ static path_stack_entry *
fetch_new_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct intermediates *cint)
{
CACHE_REGS
if (sp+1 > (path_stack_entry *)Yap_TrailTop) {
if (sp+1 > (path_stack_entry *)LOCAL_TrailTop) {
save_machine_regs();
siglongjmp(cint->CompilerBotch,4);
}
@ -6028,25 +6028,25 @@ Yap_AddClauseToIndex(PredEntry *ap, yamop *beg, int first) {
cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NIL;
if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
restore_machine_regs();
Yap_gcl(Yap_Error_Size, ap->ArityOfPE, ENV, CP);
Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE, ENV, CP);
save_machine_regs();
} else if (cb == 2) {
restore_machine_regs();
Yap_growheap(FALSE, Yap_Error_Size, NULL);
Yap_growheap(FALSE, LOCAL_Error_Size, NULL);
save_machine_regs();
} else if (cb == 4) {
restore_machine_regs();
Yap_growtrail(Yap_Error_Size, FALSE);
Yap_growtrail(LOCAL_Error_Size, FALSE);
save_machine_regs();
}
if (cb) {
Yap_RemoveIndexation(ap);
return;
}
Yap_Error_Size = 0;
Yap_ErrorMessage = NULL;
LOCAL_Error_Size = 0;
LOCAL_ErrorMessage = NULL;
#ifdef DEBUG
if (Yap_Option['i' - 'a' + 1]) {
if (GLOBAL_Option['i' - 'a' + 1]) {
Term tmod = ap->ModuleOfPred;
if (!tmod) tmod = TermProlog;
Yap_DebugPutc(LOCAL_c_error_stream,'+');
@ -6504,19 +6504,19 @@ Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) {
cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL;
if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
restore_machine_regs();
Yap_gcl(Yap_Error_Size, ap->ArityOfPE, ENV, CP);
Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE, ENV, CP);
save_machine_regs();
} else if (cb == 2) {
restore_machine_regs();
Yap_growheap(FALSE, Yap_Error_Size, NULL);
Yap_growheap(FALSE, LOCAL_Error_Size, NULL);
save_machine_regs();
} else if (cb == 4) {
restore_machine_regs();
Yap_growtrail(Yap_Error_Size, FALSE);
Yap_growtrail(LOCAL_Error_Size, FALSE);
save_machine_regs();
}
Yap_Error_Size = 0;
Yap_ErrorMessage = NULL;
LOCAL_Error_Size = 0;
LOCAL_ErrorMessage = NULL;
if (cb) {
/* cannot rely on the code */
if (ap->PredFlags & LogUpdatePredFlag) {
@ -6530,7 +6530,7 @@ Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) {
return;
}
#ifdef DEBUG
if (Yap_Option['i' - 'a' + 1]) {
if (GLOBAL_Option['i' - 'a' + 1]) {
Term tmod = ap->ModuleOfPred;
if (!tmod) tmod = TermProlog;

156
C/init.c
View File

@ -34,8 +34,11 @@ static char SccsId[] = "%W% %G%";
#include "tracer.h"
#endif
#ifdef YAPOR
#ifdef YAPOR_COW
#include <signal.h>
#endif /* YAPOR_COW */
#include "or.macros.h"
#endif /* YAPOR */
#endif /* YAPOR */
#if defined(YAPOR) || defined(TABLING)
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
@ -55,7 +58,6 @@ static char SccsId[] = "%W% %G%";
#define LOGFILE "logfile"
int Yap_output_msg = FALSE;
#ifdef MACC
STATIC_PROTO(void InTTYLine, (char *));
@ -75,113 +77,13 @@ STATIC_PROTO(void InitCodes, (void));
STATIC_PROTO(void InitVersion, (void));
STD_PROTO(void exit, (int));
static void InitWorker(int wid);
#ifdef YAPOR
void init_yapor_workers(void);
#endif /* YAPOR */
/************** YAP PROLOG GLOBAL VARIABLES *************************/
/************* variables related to memory allocation ***************/
#if defined(THREADS)
ADDR Yap_HeapBase;
struct thread_globs Yap_thread_gl[MAX_THREADS];
pthread_t Yap_master_thread;
#else
ADDR Yap_HeapBase,
Yap_LocalBase,
Yap_GlobalBase,
Yap_TrailBase,
Yap_TrailTop;
/************ variables concerned with Error Handling *************/
char *Yap_ErrorMessage; /* used to pass error messages */
Term Yap_Error_Term; /* used to pass error terms */
yap_error_number Yap_Error_TYPE; /* used to pass the error */
UInt Yap_Error_Size; /* used to pass a size associated with an error */
/******************* storing error messages ****************************/
char Yap_ErrorSay[MAX_ERROR_MSG_SIZE];
/* if we botched in a LongIO operation */
jmp_buf Yap_IOBotch;
/* if we botched in the compiler */
jmp_buf Yap_CompilerBotch;
/************ variables concerned with Error Handling *************/
sigjmp_buf Yap_RestartEnv; /* used to restart after an abort execution */
/********* IO support *****/
/********* parsing ********************************************/
TokEntry *Yap_tokptr, *Yap_toktide;
VarEntry *Yap_VarTable, *Yap_AnonVarTable;
int Yap_eot_before_eof = FALSE;
/******************* intermediate buffers **********************/
char Yap_FileNameBuf[YAP_FILENAME_MAX],
Yap_FileNameBuf2[YAP_FILENAME_MAX];
#endif /* THREADS */
/******** whether Yap is responsible for signal handling******************/
int Yap_PrologShouldHandleInterrupts;
/********* readline support *****/
#if HAVE_LIBREADLINE
char *_line = (char *) NULL;
#endif
#ifdef MPWSHELL
/********** informing if we are in the MPW shell ********************/
int mpwshell = FALSE;
#endif
#ifdef EMACS
int emacs_mode = FALSE;
char emacs_tmp[256], emacs_tmp2[256];
#endif
/********* Prolog State ********************************************/
Int Yap_PrologMode = BootMode;
int Yap_CritLocks = 0;
/********* streams ********************************************/
YP_FILE *Yap_stdin;
YP_FILE *Yap_stdout;
YP_FILE *Yap_stderr;
/************** Access to yap initial arguments ***************************/
char **Yap_argv;
int Yap_argc;
/************** Extensions to Terms ***************************************/
#ifdef COROUTINING
/* array with the ops for your favourite extensions */
ext_op attas[attvars_ext+1];
#endif
/************** declarations local to init.c ************************/
static char *optypes[] =
{"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
@ -194,10 +96,6 @@ int Yap_page_size;
void **Yap_ABSMI_OPCODES;
#endif
#if USE_SOCKET
int Yap_sockets_io=0;
#endif
#if DEBUG
#if COROUTINING
int Yap_Portray_delays = FALSE;
@ -303,7 +201,7 @@ static void
SetOp(int p, int type, char *at, Term m)
{
#ifdef DEBUG
if (Yap_Option[5])
if (GLOBAL_Option[5])
fprintf(stderr,"[setop %d %s %s]\n", p, optypes[type], at);
#endif
OpDec(p, optypes[type], Yap_LookupAtom(at), m);
@ -445,8 +343,8 @@ InitDebug(void)
int i;
for (i = 1; i < 20; ++i)
Yap_Option[i] = 0;
if (Yap_output_msg) {
GLOBAL_Option[i] = 0;
if (GLOBAL_output_msg) {
char ch;
#if HAVE_ISATTY
@ -461,10 +359,10 @@ InitDebug(void)
fprintf(stderr,"m Machine\t p parser\n");
while ((ch = YP_putchar(YP_getchar())) != '\n')
if (ch >= 'a' && ch <= 'z')
Yap_Option[ch - 'a' + 1] = 1;
if (Yap_Option['l' - 96]) {
Yap_logfile = fopen(LOGFILE, "w");
if (Yap_logfile == NULL) {
GLOBAL_Option[ch - 'a' + 1] = 1;
if (GLOBAL_Option['l' - 96]) {
GLOBAL_logfile = fopen(LOGFILE, "w");
if (GLOBAL_logfile == NULL) {
fprintf(stderr,"can not open %s\n", LOGFILE);
getchar();
exit(0);
@ -1165,23 +1063,22 @@ InitInvisibleAtoms(void)
#ifdef YAPOR
void init_yapor_workers(void) {
void Yap_init_yapor_workers(void) {
CACHE_REGS
int proc;
#ifdef YAPOR_THREADS
return;
#endif /* YAPOR_THREADS */
#ifdef YAPOR_COW
GLOBAL_master_worker = getpid();
if (GLOBAL_number_workers > 1) {
int son;
son = fork();
if (son == -1)
Yap_Error(FATAL_ERROR, TermNil, "fork error (init_yapor_workers)");
Yap_Error(FATAL_ERROR, TermNil, "fork error (Yap_init_yapor_workers)");
if (son > 0) {
/* I am the father, I must stay here and wait for my children to all die */
struct sigaction sigact;
GLOBAL_master_worker = getpid();
sigact.sa_handler = SIG_DFL;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = SA_RESTART;
@ -1196,12 +1093,13 @@ void init_yapor_workers(void) {
int son;
son = fork();
if (son == -1)
Yap_Error(FATAL_ERROR, TermNil, "fork error (init_yapor_workers)");
Yap_Error(FATAL_ERROR, TermNil, "fork error (Yap_init_yapor_workers)");
if (son == 0) {
/* new worker */
worker_id = proc;
Yap_remap_optyap_memory();
Yap_remap_yapor_memory();
LOCAL = REMOTE(worker_id);
memcpy(REMOTE(worker_id), REMOTE(0), sizeof(struct worker_local));
InitWorker(worker_id);
break;
} else
@ -1353,7 +1251,7 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
return;
pthread_key_create(&Yap_yaamregs_key, NULL);
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
Yap_master_thread = pthread_self();
GLOBAL_master_thread = pthread_self();
#else
/* In this case we need to initialise the abstract registers */
Yap_regp = &Yap_standard_regs;
@ -1364,10 +1262,8 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
#ifdef THREADS
Yap_regp = ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key));
LOCAL = REMOTE(0);
#endif /* THREADS */
/* Init signal handling and time */
/* also init memory page size, required by later functions */
Yap_InitSysbits ();
if (Heap < MinHeapSpace)
Heap = MinHeapSpace;
Heap = AdjustPageSize(Heap * K);
@ -1399,19 +1295,16 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
#endif /* YAPOR_COPY - YAPOR_COW - YAPOR_SBA - YAPOR_THREADS */
#endif /* YAPOR */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_init_optyap_memory(Trail, Heap, Stack+Atts, n_workers);
Yap_init_yapor_stacks_memory(Trail, Heap, Stack+Atts, n_workers);
#else
Yap_InitMemory(Trail, Heap, Stack+Atts);
#endif
#if defined(YAPOR) || defined(TABLING)
Yap_init_global_optyap_data(max_table_size, n_workers, sch_loop, delay_load);
#endif /* YAPOR || TABLING */
#if defined(YAPOR) || defined(THREADS)
LOCAL = REMOTE(0); /* point to the first area */
#endif /* YAPOR || THREADS */
Yap_AttsSize = Atts;
Yap_InitTime ();
Yap_InitTime();
/* InitAbsmi must be done before InitCodes */
/* This must be done before initialising predicates */
for (i = 0; i <= LAST_FLAG; i++) {
@ -1464,11 +1357,12 @@ run_halt_hooks(int code)
void
Yap_exit (int value)
{
CACHE_REGS
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_unmap_optyap_memory();
#endif
Yap_unmap_yapor_memory();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
if (! (Yap_PrologMode & BootMode) ) {
if (! (LOCAL_PrologMode & BootMode) ) {
#ifdef LOW_PROF
remove("PROFPREDS");
remove("PROFILING");

View File

@ -719,7 +719,7 @@ p_functor( USES_REGS1 ) /* functor(?,?,?) */
d0 = AbsAppl(H);
if (pt1+d1 > ENV - CreepFlag) {
if (!Yap_gcl((1+d1)*sizeof(CELL), 3, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto restart;

View File

@ -183,17 +183,17 @@ Yap_DebugGetc()
}
if ((ch = *lp++) == 0)
ch = '\n', eolflg = 1;
if (Yap_Option['l' - 96])
putc(ch, Yap_logfile);
if (GLOBAL_Option['l' - 96])
putc(ch, GLOBAL_logfile);
return (ch);
}
int
Yap_DebugPutc(int sno, wchar_t ch)
{
if (Yap_Option['l' - 96])
(void) putc(ch, Yap_logfile);
return (putc(ch, Yap_stderr));
if (GLOBAL_Option['l' - 96])
(void) putc(ch, GLOBAL_logfile);
return (putc(ch, GLOBAL_stderr));
}
void
@ -273,8 +273,8 @@ syntax_error (TokEntry * tokptr, IOSTREAM *st, Term *outp)
/* make sure to globalise variable */
Yap_unify(*outp, MkVarTerm());
start = tokptr->TokPos;
clean_vars(Yap_VarTable);
clean_vars(Yap_AnonVarTable);
clean_vars(LOCAL_VarTable);
clean_vars(LOCAL_AnonVarTable);
while (1) {
Term ts[2];
@ -286,7 +286,7 @@ syntax_error (TokEntry * tokptr, IOSTREAM *st, Term *outp)
H = Hi;
break;
}
if (tokptr == Yap_toktide) {
if (tokptr == LOCAL_toktide) {
err = tokptr->TokPos;
out = count;
}
@ -402,31 +402,31 @@ Yap_StringToTerm(char *s,Term *tp)
if (sno == NULL)
return FALSE;
TR_before_parse = TR;
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(sno, &tpos);
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(sno, &tpos);
if (tokstart == NIL || tokstart->Tok == Ord (eot_tok)) {
if (tp) {
*tp = MkAtomTerm(AtomEOFBeforeEOT);
}
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
Sclose(sno);
return FALSE;
} else if (Yap_ErrorMessage) {
} else if (LOCAL_ErrorMessage) {
if (tp) {
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
}
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
Sclose(sno);
return FALSE;
}
t = Yap_Parse();
TR = TR_before_parse;
if (!t || Yap_ErrorMessage) {
if (!t || LOCAL_ErrorMessage) {
GenerateSyntaxError(tp, tokstart, sno PASS_REGS);
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
Sclose(sno);
return FALSE;
}
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
Sclose(sno);
return t;
}
@ -512,25 +512,25 @@ Yap_readTerm(void *st0, Term *tp, Term *varnames, Term *terror, Term *tpos)
if (st == NULL) {
return FALSE;
}
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(st, tpos);
if (Yap_ErrorMessage)
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(st, tpos);
if (LOCAL_ErrorMessage)
{
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
if (terror)
*terror = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
*terror = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return FALSE;
}
pt = Yap_Parse();
if (Yap_ErrorMessage || pt == (CELL)0) {
if (LOCAL_ErrorMessage || pt == (CELL)0) {
GenerateSyntaxError(terror, tokstart, st PASS_REGS);
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return FALSE;
}
if (varnames) {
*varnames = Yap_VarNames(Yap_VarTable, TermNil);
*varnames = Yap_VarNames(LOCAL_VarTable, TermNil);
if (!*varnames) {
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return FALSE;
}
}
@ -554,9 +554,6 @@ static Int
{
Term t, v;
TokEntry *tokstart;
#if EMACS
int emacs_cares = FALSE;
#endif
Term tmod = Deref(ARG3), OCurrentModule = CurrentModule, tpos;
extern void Yap_setCurrentSourceLocation(IOSTREAM **s);
@ -567,7 +564,7 @@ static Int
Yap_Error(TYPE_ERROR_ATOM, tmod, "read_term/2");
return FALSE;
}
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
tpos = Yap_StreamPosition(inp_stream);
if (!Yap_unify(tpos,ARG5)) {
/* do this early so that we do not have to protect it in case of stack expansion */
@ -585,33 +582,32 @@ static Int
/* Scans the term using stack space */
while (TRUE) {
old_H = H;
Yap_eot_before_eof = FALSE;
tpos = Yap_StreamPosition(inp_stream);
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(inp_stream, &tpos);
if (Yap_Error_TYPE != YAP_NO_ERROR && seekable) {
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp_stream, &tpos);
if (LOCAL_Error_TYPE != YAP_NO_ERROR && seekable) {
H = old_H;
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
if (seekable) {
Sseek64(inp_stream, cpos, SIO_SEEK_SET);
}
if (Yap_Error_TYPE == OUT_OF_TRAIL_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_TRAIL_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growtrail (sizeof(CELL) * K16, FALSE)) {
return FALSE;
}
} else if (Yap_Error_TYPE == OUT_OF_AUXSPACE_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
} else if (LOCAL_Error_TYPE == OUT_OF_AUXSPACE_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) {
return FALSE;
}
} else if (Yap_Error_TYPE == OUT_OF_HEAP_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
} else if (LOCAL_Error_TYPE == OUT_OF_HEAP_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growheap(FALSE, 0, NULL)) {
return FALSE;
}
} else if (Yap_Error_TYPE == OUT_OF_STACK_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, nargs, ENV, CP)) {
} else if (LOCAL_Error_TYPE == OUT_OF_STACK_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, nargs, ENV, CP)) {
return FALSE;
}
}
@ -620,18 +616,18 @@ static Int
break;
}
}
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
/* preserve value of H after scanning: otherwise we may lose strings
and floats */
old_H = H;
if (tokstart != NULL && tokstart->Tok == Ord (eot_tok)) {
/* did we get the end of file from an abort? */
if (Yap_ErrorMessage &&
!strcmp(Yap_ErrorMessage,"Abort")) {
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
if (LOCAL_ErrorMessage &&
!strcmp(LOCAL_ErrorMessage,"Abort")) {
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return FALSE;
} else {
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return Yap_unify_constant(ARG2, MkAtomTerm (AtomEof))
&& Yap_unify_constant(ARG4, TermNil);
@ -639,14 +635,14 @@ static Int
}
repeat_cycle:
CurrentModule = tmod;
if (Yap_ErrorMessage || (t = Yap_Parse()) == 0) {
if (LOCAL_ErrorMessage || (t = Yap_Parse()) == 0) {
CurrentModule = OCurrentModule;
if (Yap_ErrorMessage) {
if (LOCAL_ErrorMessage) {
int res;
if (!strcmp(Yap_ErrorMessage,"Stack Overflow") ||
!strcmp(Yap_ErrorMessage,"Trail Overflow") ||
!strcmp(Yap_ErrorMessage,"Heap Overflow")) {
if (!strcmp(LOCAL_ErrorMessage,"Stack Overflow") ||
!strcmp(LOCAL_ErrorMessage,"Trail Overflow") ||
!strcmp(LOCAL_ErrorMessage,"Heap Overflow")) {
/* ignore term we just built */
tr_fr_ptr old_TR = TR;
@ -654,18 +650,18 @@ static Int
H = old_H;
TR = (tr_fr_ptr)LOCAL_ScannerStack;
if (!strcmp(Yap_ErrorMessage,"Stack Overflow"))
res = Yap_growstack_in_parser(&old_TR, &tokstart, &Yap_VarTable);
else if (!strcmp(Yap_ErrorMessage,"Heap Overflow"))
res = Yap_growheap_in_parser(&old_TR, &tokstart, &Yap_VarTable);
if (!strcmp(LOCAL_ErrorMessage,"Stack Overflow"))
res = Yap_growstack_in_parser(&old_TR, &tokstart, &LOCAL_VarTable);
else if (!strcmp(LOCAL_ErrorMessage,"Heap Overflow"))
res = Yap_growheap_in_parser(&old_TR, &tokstart, &LOCAL_VarTable);
else
res = Yap_growtrail_in_parser(&old_TR, &tokstart, &Yap_VarTable);
res = Yap_growtrail_in_parser(&old_TR, &tokstart, &LOCAL_VarTable);
if (res) {
LOCAL_ScannerStack = (char *)TR;
TR = old_TR;
old_H = H;
Yap_tokptr = Yap_toktide = tokstart;
Yap_ErrorMessage = NULL;
LOCAL_tokptr = LOCAL_toktide = tokstart;
LOCAL_ErrorMessage = NULL;
goto repeat_cycle;
}
LOCAL_ScannerStack = (char *)TR;
@ -674,26 +670,26 @@ static Int
}
if (ParserErrorStyle == QUIET_ON_PARSER_ERROR) {
/* just fail */
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return FALSE;
} else if (ParserErrorStyle == CONTINUE_ON_PARSER_ERROR) {
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
/* try again */
goto repeat_cycle;
} else {
Term terr = syntax_error(tokstart, inp_stream, &ARG2);
if (Yap_ErrorMessage == NULL)
Yap_ErrorMessage = "SYNTAX ERROR";
if (LOCAL_ErrorMessage == NULL)
LOCAL_ErrorMessage = "SYNTAX ERROR";
if (ParserErrorStyle == EXCEPTION_ON_PARSER_ERROR) {
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_Error(SYNTAX_ERROR,terr,Yap_ErrorMessage);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
Yap_Error(SYNTAX_ERROR,terr,LOCAL_ErrorMessage);
return FALSE;
} else /* FAIL ON PARSER ERROR */ {
Term t[2];
t[0] = terr;
t[1] = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
t[1] = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return Yap_unify(ARG6,Yap_MkApplTerm(Yap_MkFunctor(AtomError,2),2,t));
}
}
@ -703,17 +699,14 @@ static Int
break;
}
}
#if EMACS
first_char = tokstart->TokPos;
#endif /* EMACS */
if (!Yap_unify(t, ARG2))
return FALSE;
if (AtomOfTerm (Deref (ARG1)) == AtomTrue) {
while (TRUE) {
CELL *old_H = H;
if (setjmp(Yap_IOBotch) == 0) {
v = Yap_VarNames(Yap_VarTable, TermNil);
if (setjmp(LOCAL_IOBotch) == 0) {
v = Yap_VarNames(LOCAL_VarTable, TermNil);
break;
} else {
tr_fr_ptr old_TR;
@ -723,15 +716,15 @@ static Int
/* restart global */
H = old_H;
TR = (tr_fr_ptr)LOCAL_ScannerStack;
Yap_growstack_in_parser(&old_TR, &tokstart, &Yap_VarTable);
Yap_growstack_in_parser(&old_TR, &tokstart, &LOCAL_VarTable);
LOCAL_ScannerStack = (char *)TR;
TR = old_TR;
}
}
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return Yap_unify (v, ARG4);
} else {
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return TRUE;
}
}
@ -976,7 +969,7 @@ p_char_conversion( USES_REGS1 )
CharConversionTable2 = Yap_AllocCodeSpace(NUMBER_OF_CHARS*sizeof(char));
while (CharConversionTable2 == NULL) {
if (!Yap_growheap(FALSE, NUMBER_OF_CHARS*sizeof(char), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
}
@ -1110,9 +1103,6 @@ Yap_InitBackIO (void)
void
Yap_InitIOPreds(void)
{
Yap_stdin = stdin;
Yap_stdout = stdout;
Yap_stderr = stderr;
if (!Stream)
Stream = (StreamDesc *)Yap_AllocCodeSpace(sizeof(StreamDesc)*MaxStreams);
/* here the Input/Output predicates */

View File

@ -65,16 +65,16 @@ LoadForeign(StringList ofiles, StringList libs,
/* load wants to follow the LIBRARY_PATH */
if (ofiles->next != NULL || libs != NULL) {
strcpy(Yap_ErrorSay," Load Failed: in AIX you must load a single object file");
strcpy(LOCAL_ErrorSay," Load Failed: in AIX you must load a single object file");
return LOAD_FAILLED;
}
if (!Yap_TrueFileName(AtomName(ofiles->name), Yap_FileNameBuf, TRUE)) {
strcpy(Yap_ErrorSay, " Trying to open unexisting file in LoadForeign ");
if (!Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) {
strcpy(LOCAL_ErrorSay, " Trying to open unexisting file in LoadForeign ");
return LOAD_FAILLED;
}
/* In AIX, just call load and everything will go in */
if ((*init_proc=((YapInitProc *)load(Yap_FileNameBuf,0,NULL))) == NULL) {
strcpy(Yap_ErrorSay,sys_errlist[errno]);
if ((*init_proc=((YapInitProc *)load(LOCAL_FileNameBuf,0,NULL))) == NULL) {
strcpy(LOCAL_ErrorSay,sys_errlist[errno]);
return LOAD_FAILLED;
}
return LOAD_SUCCEEDED;

View File

@ -18,7 +18,7 @@
#include "Foreign.h"
#ifdef A_OUT
this code is no being maintained anymore
#include <stdio.h>
#if STDC_HEADERS
#include <stdlib.h>
@ -43,7 +43,7 @@
#endif
#include <a.out.h>
static char YapExecutable[YAP_FILE_MAX];
#define oktox(n) \
(0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFREG&&0==access(n,X_OK))
@ -64,10 +64,10 @@ Yap_FindExecutable(char *name)
cp = (char *)getenv("PATH");
if (cp == NULL)
cp = ".:/usr/ucb:/bin:/usr/bin:/usr/local/bin";
if (*Yap_argv[0] == '/') {
if (oktox(Yap_argv[0])) {
strcpy(Yap_FileNameBuf, Yap_argv[0]);
Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE);
if (*GLOBAL_argv[0] == '/') {
if (oktox(GLOBAL_argv[0])) {
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
return;
}
}
@ -79,24 +79,24 @@ Yap_FindExecutable(char *name)
* argv[0]
*/
for (cp2 = Yap_FileNameBuf; (*cp) != 0 && (*cp) != ':';)
for (cp2 = LOCAL_FileNameBuf; (*cp) != 0 && (*cp) != ':';)
*cp2++ = *cp++;
*cp2++ = '/';
strcpy(cp2, Yap_argv[0]);
strcpy(cp2, GLOBAL_argv[0]);
if (*cp)
cp++;
if (!oktox(Yap_FileNameBuf))
if (!oktox(LOCAL_FileNameBuf))
continue;
Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE);
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
return;
}
/* one last try for dual systems */
strcpy(Yap_FileNameBuf, Yap_argv[0]);
Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE);
if (oktox(YapExecutable))
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
if (oktox(GLOBAL_Executable))
return;
else
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(YapExecutable)),
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
"cannot find file being executed");
}
@ -174,22 +174,22 @@ LoadForeign(StringList ofiles,
/* prepare the magic */
if (strlen(o_files) + strlen(l_files) + strlen(proc_name) +
strlen(YapExecutable) > 2*MAXPATHLEN) {
strcpy(Yap_ErrorSay, " too many parameters in load_foreign/3 ");
strlen(GLOBAL_Executable) > 2*MAXPATHLEN) {
strcpy(LOCAL_ErrorSay, " too many parameters in load_foreign/3 ");
return LOAD_FAILLED;
}
sprintf(command, "/usr/bin/ld -N -A %s -o %s -u _%s %s %s -lc",
YapExecutable,
GLOBAL_Executable,
tfile, proc_name, o_files, l_files);
/* now, do the magic */
if (system(command) != 0) {
unlink(tfile);
strcpy(Yap_ErrorSay," ld returned error status in load_foreign_files ");
strcpy(LOCAL_ErrorSay," ld returned error status in load_foreign_files ");
return LOAD_FAILLED;
}
/* now check the music has played */
if ((fildes = open(tfile, O_RDONLY)) < 0) {
strcpy(Yap_ErrorSay," unable to open temp file in load_foreign_files ");
strcpy(LOCAL_ErrorSay," unable to open temp file in load_foreign_files ");
return LOAD_FAILLED;
}
/* it did, get the mice */
@ -204,28 +204,28 @@ LoadForeign(StringList ofiles,
firstloadImSz = loadImageSize;
/* now fetch the space we need */
if (!(FCodeBase = Yap_AllocCodeSpace((int) loadImageSize))) {
strcpy(Yap_ErrorSay," unable to allocate space for external code ");
strcpy(LOCAL_ErrorSay," unable to allocate space for external code ");
return LOAD_FAILLED;
}
/* now, a new incantation to load the new foreign code */
sprintf(command, "/usr/bin/ld -N -A %s -T %lx -o %s -u _%s %s %s -lc",
YapExecutable,
GLOBAL_Executable,
(unsigned long) FCodeBase,
tfile, proc_name, o_files, l_files);
/* and do it */
if (system(command) != 0) {
unlink(tfile);
strcpy(Yap_ErrorSay," ld returned error status in load_foreign_files ");
strcpy(LOCAL_ErrorSay," ld returned error status in load_foreign_files ");
return LOAD_FAILLED;
}
if ((fildes = open(tfile, O_RDONLY)) < 0) {
strcpy(Yap_ErrorSay," unable to open temp file in load_foreign_files ");
strcpy(LOCAL_ErrorSay," unable to open temp file in load_foreign_files ");
return LOAD_FAILLED;
}
read(fildes, (char *) &header, sizeof(header));
loadImageSize = header.a_text + header.a_data + header.a_bss;
if (firstloadImSz < loadImageSize) {
strcpy(Yap_ErrorSay," miscalculation in load_foreign/3 ");
strcpy(LOCAL_ErrorSay," miscalculation in load_foreign/3 ");
return LOAD_FAILLED;
}
/* now search for our init function */
@ -236,11 +236,11 @@ LoadForeign(StringList ofiles,
func_info[0].n_un.n_name = entry_fun;
func_info[1].n_un.n_name = NULL;
if (nlist(tfile, func_info) == -1) {
strcpy(Yap_ErrorSay," in nlist(3) ");
strcpy(LOCAL_ErrorSay," in nlist(3) ");
return LOAD_FAILLED;
}
if (func_info[0].n_type == 0) {
strcpy(Yap_ErrorSay," in nlist(3) ");
strcpy(LOCAL_ErrorSay," in nlist(3) ");
return LOAD_FAILLED;
}
*init_proc = (YapInitProc)(func_info[0].n_value);

View File

@ -19,7 +19,7 @@
#include "Foreign.h"
#ifdef COFF
this code is no being maintained anymore
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
@ -45,8 +45,6 @@
#define N_TXTOFF(x) (sizeof(struct filehdr)+(x).f_opthdr+(x).f_nscns*sizeof(struct scnhdr))
static char YapExecutable[YAP_FILE_MAX];
/*
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
@ -62,10 +60,10 @@ Yap_FindExecutable(char *name)
cp = (char *)getenv("PATH");
if (cp == NULL)
cp = ".:/usr/ucb:/bin:/usr/bin:/usr/local/bin";
if (*Yap_argv[0] == '/') {
if (oktox(Yap_argv[0])) {
strcpy(Yap_FileNameBuf, Yap_argv[0]);
Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE);
if (*GLOBAL_argv[0] == '/') {
if (oktox(GLOBAL_argv[0])) {
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
return;
}
}
@ -77,24 +75,24 @@ Yap_FindExecutable(char *name)
* argv[0]
*/
for (cp2 = Yap_FileNameBuf; (*cp) != 0 && (*cp) != ':';)
for (cp2 = LOCAL_FileNameBuf; (*cp) != 0 && (*cp) != ':';)
*cp2++ = *cp++;
*cp2++ = '/';
strcpy(cp2, Yap_argv[0]);
strcpy(cp2, GLOBAL_argv[0]);
if (*cp)
cp++;
if (!oktox(Yap_FileNameBuf))
if (!oktox(LOCAL_FileNameBuf))
continue;
Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE);
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
return;
}
/* one last try for dual systems */
strcpy(Yap_FileNameBuf, Yap_argv[0]);
Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE);
if (oktox(YapExecutable))
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
if (oktox(GLOBAL_Executable))
return;
else
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(YapExecutable)),
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
"cannot find file being executed");
}
@ -175,22 +173,22 @@ LoadForeign(StringList ofiles,
/* prepare the magic */
if (strlen(o_files) + strlen(l_files) + strlen(proc_name) +
strlen(YapExecutable) > 2*MAXPATHLEN) {
strcpy(Yap_ErrorSay, " too many parameters in load_foreign/3 ");
strlen(GLOBAL_Executable) > 2*MAXPATHLEN) {
strcpy(LOCAL_ErrorSay, " too many parameters in load_foreign/3 ");
return LOAD_FAILLED;
}
sprintf(command, "/usr/bin/ld -N -A %s -o %s %s %s -lc",
YapExecutable,
GLOBAL_Executable,
tfile, o_files, l_files);
/* now, do the magic */
if (system(command) != 0) {
unlink(tfile);
strcpy(Yap_ErrorSay," ld returned error status in load_foreign_files ");
strcpy(LOCAL_ErrorSay," ld returned error status in load_foreign_files ");
return LOAD_FAILLED;
}
/* now check the music has played */
if ((fildes = open(tfile, O_RDONLY)) < 0) {
strcpy(Yap_ErrorSay," unable to open temp file in load_foreign_files ");
strcpy(LOCAL_ErrorSay," unable to open temp file in load_foreign_files ");
return LOAD_FAILLED;
}
/* it did, get the mice */
@ -220,7 +218,7 @@ LoadForeign(StringList ofiles,
|| activate_code(ForeignCodeBase, u1)
#endif /* pyr */
) {
strcpy(Yap_ErrorSay," unable to allocate space for external code ");
strcpy(LOCAL_ErrorSay," unable to allocate space for external code ");
return LOAD_FAILLED;
}
#ifdef mips
@ -253,11 +251,11 @@ LoadForeign(StringList ofiles,
/* and do it */
if (system(command) != 0) {
unlink(tfile);
strcpy(Yap_ErrorSay," ld returned error status in load_foreign_files ");
strcpy(LOCAL_ErrorSay," ld returned error status in load_foreign_files ");
return LOAD_FAILLED;
}
if ((fildes = open(tfile, O_RDONLY)) < 0) {
strcpy(Yap_ErrorSay," unable to open temp file in load_foreign_files ");
strcpy(LOCAL_ErrorSay," unable to open temp file in load_foreign_files ");
return LOAD_FAILLED;
}
read(fildes, (char *) &fileHeader, sizeof(fileHeader));
@ -269,7 +267,7 @@ LoadForeign(StringList ofiles,
}
loadImageSize = sysHeader.tsize + sysHeader.dsize + sysHeader.bsize;
if (firstloadImSz < loadImageSize) {
strcpy(Yap_ErrorSay," miscalculation in load_foreign/3 ");
strcpy(LOCAL_ErrorSay," miscalculation in load_foreign/3 ");
return LOAD_FAILLED;
}
/* now search for our init function */
@ -285,11 +283,11 @@ LoadForeign(StringList ofiles,
func_info[0].n_name = entry_fun;
func_info[1].n_name = NULL;
if (nlist(tfile, func_info) == -1) {
strcpy(Yap_ErrorSay," in nlist(3) ");
strcpy(LOCAL_ErrorSay," in nlist(3) ");
return LOAD_FAILLED;
}
if (func_info[0].n_type == 0) {
strcpy(Yap_ErrorSay," in nlist(3) ");
strcpy(LOCAL_ErrorSay," in nlist(3) ");
return LOAD_FAILLED;
}
*init_proc = (YapInitProc)(func_info[0].n_value);

View File

@ -94,18 +94,18 @@ LoadForeign(StringList ofiles, StringList libs,
CACHE_REGS
while (libs) {
if (!Yap_TrueFileName(AtomName(libs->name), Yap_FileNameBuf, TRUE)) {
if (!Yap_TrueFileName(AtomName(libs->name), LOCAL_FileNameBuf, TRUE)) {
/* use LD_LIBRARY_PATH */
strncpy(Yap_FileNameBuf, AtomName(libs->name), YAP_FILENAME_MAX);
strncpy(LOCAL_FileNameBuf, AtomName(libs->name), YAP_FILENAME_MAX);
}
#ifdef __osf__
if((libs->handle=dlopen(Yap_FileNameBuf,RTLD_LAZY)) == NULL)
if((libs->handle=dlopen(LOCAL_FileNameBuf,RTLD_LAZY)) == NULL)
#else
if((libs->handle=dlopen(Yap_FileNameBuf,RTLD_LAZY|RTLD_GLOBAL)) == NULL)
if((libs->handle=dlopen(LOCAL_FileNameBuf,RTLD_LAZY|RTLD_GLOBAL)) == NULL)
#endif
{
strcpy(Yap_ErrorSay,dlerror());
strcpy(LOCAL_ErrorSay,dlerror());
return LOAD_FAILLED;
}
libs = libs->next;
@ -118,18 +118,18 @@ LoadForeign(StringList ofiles, StringList libs,
other routines */
/* dlopen wants to follow the LD_CONFIG_PATH */
if (!Yap_TrueFileName(AtomName(ofiles->name), Yap_FileNameBuf, TRUE)) {
strcpy(Yap_ErrorSay, "%% Trying to open unexisting file in LoadForeign");
if (!Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) {
strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign");
return LOAD_FAILLED;
}
#ifdef __osf__
if((handle=dlopen(Yap_FileNameBuf,RTLD_LAZY)) == 0)
if((handle=dlopen(LOCAL_FileNameBuf,RTLD_LAZY)) == 0)
#else
if((handle=dlopen(Yap_FileNameBuf,RTLD_LAZY|RTLD_GLOBAL)) == 0)
if((handle=dlopen(LOCAL_FileNameBuf,RTLD_LAZY|RTLD_GLOBAL)) == 0)
#endif
{
fprintf(stderr,"dlopen of %s failed with error %s\n", Yap_FileNameBuf, dlerror());
/* strcpy(Yap_ErrorSay,dlerror());*/
fprintf(stderr,"dlopen of %s failed with error %s\n", LOCAL_FileNameBuf, dlerror());
/* strcpy(LOCAL_ErrorSay,dlerror());*/
return LOAD_FAILLED;
}
@ -142,7 +142,7 @@ LoadForeign(StringList ofiles, StringList libs,
}
if(! *init_proc) {
strcpy(Yap_ErrorSay,"Could not locate initialization routine");
strcpy(LOCAL_ErrorSay,"Could not locate initialization routine");
return LOAD_FAILLED;
}

View File

@ -20,8 +20,7 @@
#include <malloc.h>
#include <stdio.h>
static char YapExecutable[YAP_FILE_MAX];
this code is no being maintained anymore
/*
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
@ -33,9 +32,9 @@ Yap_FindExecutable(char *name)
/* use dld_find_executable */
char *res;
if(name != NULL && (res=dld_find_executable(name))) {
strcpy(YapExecutable,res);
strcpy(GLOBAL_Executable,res);
} else {
strcpy(YapExecutable,"./yap");
strcpy(GLOBAL_Executable,"./yap");
}
}
@ -71,9 +70,9 @@ LoadForeign(StringList ofiles, StringList libs,
int error;
if(firstTime) {
error = dld_init(YapExecutable);
error = dld_init(GLOBAL_Executable);
if(error) {
strcpy(Yap_ErrorSay,dld_strerror(error));
strcpy(LOCAL_ErrorSay,dld_strerror(error));
return LOAD_FAILLED;
}
firstTime=0;
@ -81,7 +80,7 @@ LoadForeign(StringList ofiles, StringList libs,
while (ofiles) {
if((error=dld_link(AtomName(ofiles->name))) !=0) {
strcpy(Yap_ErrorSay,dld_strerror(error));
strcpy(LOCAL_ErrorSay,dld_strerror(error));
return LOAD_FAILLED;
}
ofiles = ofiles->next;
@ -91,14 +90,14 @@ LoadForeign(StringList ofiles, StringList libs,
/* TODO: handle libs */
*init_proc = (YapInitProc) dld_get_func(proc_name);
if(! *init_proc) {
strcpy(Yap_ErrorSay,"Could not locate initialization routine");
strcpy(LOCAL_ErrorSay,"Could not locate initialization routine");
return LOAD_FAILLED;
}
if(!dld_function_executable_p(proc_name)) {
char **undefs = dld_list_undefined_sym();
char **p = undefs;
int k = dld_undefined_sym_count;
strcpy(Yap_ErrorSay,"Could not resolve all symbols");
strcpy(LOCAL_ErrorSay,"Could not resolve all symbols");
while(k) {
YP_printf("[undefined symbol %s]\n",*p++);
--k;

View File

@ -66,16 +66,16 @@ LoadForeign(StringList ofiles, StringList libs,
while (ofiles) {
HINSTANCE handle;
if (Yap_TrueFileName(AtomName(ofiles->name), Yap_FileNameBuf, TRUE) &&
(handle=LoadLibrary(Yap_FileNameBuf)) != 0)
if (Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE) &&
(handle=LoadLibrary(LOCAL_FileNameBuf)) != 0)
{
Yap_ErrorSay[0]=~'\0';
LOCAL_ErrorSay[0]=~'\0';
if (*init_proc == NULL)
*init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name);
} else {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), Yap_ErrorSay, 256,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorSay, 256,
NULL);
}
ofiles = ofiles->next;
@ -87,15 +87,15 @@ LoadForeign(StringList ofiles, StringList libs,
char * s = AtomName(libs->name);
if (s[0] == '-') {
strcat(Yap_FileNameBuf,s+2);
strcat(Yap_FileNameBuf,".dll");
strcat(LOCAL_FileNameBuf,s+2);
strcat(LOCAL_FileNameBuf,".dll");
} else {
strcpy(Yap_FileNameBuf,s);
strcpy(LOCAL_FileNameBuf,s);
}
if((handle=LoadLibrary(Yap_FileNameBuf)) == 0)
if((handle=LoadLibrary(LOCAL_FileNameBuf)) == 0)
{
/* strcpy(Yap_ErrorSay,dlerror());*/
/* strcpy(LOCAL_ErrorSay,dlerror());*/
return LOAD_FAILLED;
}
@ -106,7 +106,7 @@ LoadForeign(StringList ofiles, StringList libs,
}
if(*init_proc == NULL) {
strcpy(Yap_ErrorSay,"Could not locate initialization routine");
strcpy(LOCAL_ErrorSay,"Could not locate initialization routine");
return LOAD_FAILLED;
}

View File

@ -28,13 +28,13 @@
*/
#import <mach-o/dyld.h>
static int dl_errno;
static char *
mydlerror(void)
{
char *errString;
switch(dl_errno) {
switch(LOCAL_dl_errno) {
default:
case NSObjectFileImageFailure:
case NSObjectFileImageFormat:
@ -76,7 +76,7 @@ mydlopen(char *path)
NSModule handle = NULL;
dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
if (dyld_result != NSObjectFileImageSuccess) {
dl_errno = dyld_result;
LOCAL_dl_errno = dyld_result;
} else {
/* NSLinkModule will cause the run to abort on any link error's */
/* not very friendly but the error recovery functionality is limited */
@ -145,14 +145,14 @@ LoadForeign(StringList ofiles, StringList libs,
void *handle;
/* mydlopen wants to follow the LD_CONFIG_PATH */
if (!Yap_TrueFileName(AtomName(ofiles->name), Yap_FileNameBuf, TRUE)) {
strcpy(Yap_ErrorSay, "%% Trying to open unexisting file in LoadForeign");
if (!Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) {
strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign");
return LOAD_FAILLED;
}
if((handle=mydlopen(Yap_FileNameBuf)) == 0)
if((handle=mydlopen(LOCAL_FileNameBuf)) == 0)
{
fprintf(stderr,"calling dlopen with error %s\n", mydlerror());
/* strcpy(Yap_ErrorSay,dlerror());*/
/* strcpy(LOCAL_ErrorSay,dlerror());*/
return LOAD_FAILLED;
}
@ -166,16 +166,16 @@ LoadForeign(StringList ofiles, StringList libs,
char *s = AtomName(lib->name);
if (ls[0] == '-') {
strcpy(Yap_FileNameBuf,"lib");
strcat(Yap_FileNameBuf,s+2);
strcat(Yap_FileNameBuf,".so");
strcpy(LOCAL_FileNameBuf,"lib");
strcat(LOCAL_FileNameBuf,s+2);
strcat(LOCAL_FileNameBuf,".so");
} else {
strcpy(Yap_FileNameBuf,s);
strcpy(LOCAL_FileNameBuf,s);
}
if((libs->handle=mydlopen(Yap_FileNameBuf)) == NULL)
if((libs->handle=mydlopen(LOCAL_FileNameBuf)) == NULL)
{
strcpy(Yap_ErrorSay,mydlerror());
strcpy(LOCAL_ErrorSay,mydlerror());
return LOAD_FAILLED;
}
libs = libs->next;
@ -184,7 +184,7 @@ LoadForeign(StringList ofiles, StringList libs,
*init_proc = (YapInitProc) mydlsym(proc_name);
if(! *init_proc) {
strcpy(Yap_ErrorSay,"Could not locate initialization routine");
strcpy(LOCAL_ErrorSay,"Could not locate initialization routine");
return LOAD_FAILLED;
}

View File

@ -47,7 +47,7 @@ p_load_foreign( USES_REGS1 )
StringList new;
Int returncode = FALSE;
strcpy(Yap_ErrorSay,"Invalid arguments");
strcpy(LOCAL_ErrorSay,"Invalid arguments");
/* collect the list of object files */
t = Deref(ARG1);
@ -225,10 +225,10 @@ p_open_shared_objects( USES_REGS1 ) {
void
Yap_InitLoadForeign( void )
{
if (Yap_argv == NULL)
if (GLOBAL_argv == NULL)
Yap_FindExecutable("yap");
else
Yap_FindExecutable(Yap_argv[0]);
Yap_FindExecutable(GLOBAL_argv[0]);
Yap_InitCPred("$load_foreign_files", 3, p_load_foreign, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$open_shared_objects", 0, p_open_shared_objects, SafePredFlag|HiddenPredFlag);
Yap_InitCPred("$open_shared_object", 3, p_open_shared_object, SyncPredFlag|HiddenPredFlag);

View File

@ -40,7 +40,7 @@ static Int
LoadForeign(StringList ofiles, StringList libs,
char *proc_name, YapInitProc *init_proc)
{
strcpy(Yap_ErrorSay,"load_foreign not supported in this version of Yap");
strcpy(LOCAL_ErrorSay,"load_foreign not supported in this version of Yap");
return LOAD_FAILLED;
}

View File

@ -61,17 +61,17 @@ LoadForeign( StringList ofiles, StringList libs,
int valid_fname;
/* shl_load wants to follow the LD_CONFIG_PATH */
valid_fname = Yap_TrueFileName( AtomName(ofiles->name), Yap_FileNameBuf, TRUE );
valid_fname = Yap_TrueFileName( AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE );
if( !valid_fname ) {
strcpy( Yap_ErrorSay, "%% Trying to open non-existing file in LoadForeign" );
strcpy( LOCAL_ErrorSay, "%% Trying to open non-existing file in LoadForeign" );
return LOAD_FAILLED;
}
ofiles->handle = Yap_AllocCodeSpace( sizeof(shl_t) );
*(shl_t *)ofiles->handle = shl_load( Yap_FileNameBuf, BIND_DEFERRED, 0 );
*(shl_t *)ofiles->handle = shl_load( LOCAL_FileNameBuf, BIND_DEFERRED, 0 );
if( *(shl_t *)ofiles->handle == NULL ) {
strncpy( Yap_ErrorSay, strerror(errno), MAX_ERROR_MSG_SIZE );
strncpy( LOCAL_ErrorSay, strerror(errno), MAX_ERROR_MSG_SIZE );
return LOAD_FAILLED;
}
@ -84,7 +84,7 @@ LoadForeign( StringList ofiles, StringList libs,
}
if( init_missing ) {
strcpy( Yap_ErrorSay, "Could not locate initialization routine" );
strcpy( LOCAL_ErrorSay, "Could not locate initialization routine" );
return LOAD_FAILLED;
}
@ -92,17 +92,17 @@ LoadForeign( StringList ofiles, StringList libs,
char *s = AtomName(lib->s);
if( s[0] == '-' ) {
strcpy( Yap_FileNameBuf, "lib" );
strcat( Yap_FileNameBuf, s+2 );
strcat( Yap_FileNameBuf, ".sl" );
strcpy( LOCAL_FileNameBuf, "lib" );
strcat( LOCAL_FileNameBuf, s+2 );
strcat( LOCAL_FileNameBuf, ".sl" );
}
else {
strcpy( Yap_FileNameBuf, s );
strcpy( LOCAL_FileNameBuf, s );
}
*(shl_t *)libs->handle = shl_load( Yap_FileNameBuf, BIND_DEFERRED, 0 );
*(shl_t *)libs->handle = shl_load( LOCAL_FileNameBuf, BIND_DEFERRED, 0 );
if( *(shl_t *)libs->handle == NULL ) {
strncpy( Yap_ErrorSay, strerror(errno), MAX_ERROR_MSG_SIZE );
strncpy( LOCAL_ErrorSay, strerror(errno), MAX_ERROR_MSG_SIZE );
return LOAD_FAILLED;
}

View File

@ -77,7 +77,7 @@ STATIC_PROTO(Term ParseTerm, (int, JMPBUFF * CACHE_TYPE));
#define TRY(S,P) \
{ Volatile JMPBUFF *saveenv, newenv; \
Volatile TokEntry *saveT=Yap_tokptr; \
Volatile TokEntry *saveT=LOCAL_tokptr; \
Volatile CELL *saveH=H; \
Volatile int savecurprio=curprio; \
saveenv=FailBuff; \
@ -90,13 +90,13 @@ STATIC_PROTO(Term ParseTerm, (int, JMPBUFF * CACHE_TYPE));
else { FailBuff=saveenv; \
H=saveH; \
curprio = savecurprio; \
Yap_tokptr=saveT; \
LOCAL_tokptr=saveT; \
} \
}
#define TRY3(S,P,F) \
{ Volatile JMPBUFF *saveenv, newenv; \
Volatile TokEntry *saveT=Yap_tokptr; \
Volatile TokEntry *saveT=LOCAL_tokptr; \
Volatile CELL *saveH=H; \
saveenv=FailBuff; \
if(!sigsetjmp(newenv.JmpBuff, 0)) { \
@ -108,7 +108,7 @@ STATIC_PROTO(Term ParseTerm, (int, JMPBUFF * CACHE_TYPE));
else { \
FailBuff=saveenv; \
H=saveH; \
Yap_tokptr=saveT; \
LOCAL_tokptr=saveT; \
F } \
}
@ -122,15 +122,15 @@ Yap_LookupVar(char *var) /* lookup variable in variables table */
VarEntry *p;
#ifdef DEBUG
if (Yap_Option[4])
fprintf(Yap_stderr,"[LookupVar %s]", var);
if (GLOBAL_Option[4])
fprintf(GLOBAL_stderr,"[LookupVar %s]", var);
#endif
if (var[0] != '_' || var[1] != '\0') {
VarEntry **op = &Yap_VarTable;
VarEntry **op = &LOCAL_VarTable;
unsigned char *vp = (unsigned char *)var;
UInt hv;
p = Yap_VarTable;
p = LOCAL_VarTable;
hv = HashFunction(vp) % AtomHashTableSize;
while (p != NULL) {
CELL hpv = p->hv;
@ -161,8 +161,8 @@ Yap_LookupVar(char *var) /* lookup variable in variables table */
} else {
/* anon var */
p = (VarEntry *) Yap_AllocScannerMemory(sizeof(VarEntry) + 2);
p->VarLeft = Yap_AnonVarTable;
Yap_AnonVarTable = p;
p->VarLeft = LOCAL_AnonVarTable;
LOCAL_AnonVarTable = p;
p->VarRight = NULL;
p->hv = 0L;
p->VarRep[0] = '_';
@ -182,7 +182,7 @@ VarNames(VarEntry *p,Term l USES_REGS)
VarNames(p->VarLeft,l PASS_REGS) PASS_REGS));
if (H > ASP-4096) {
save_machine_regs();
siglongjmp(Yap_IOBotch,1);
siglongjmp(LOCAL_IOBotch,1);
}
return(o);
} else {
@ -295,24 +295,19 @@ Yap_IsPosfixOp(Atom op, int *pptr, int *lpptr)
inline static void
GNextToken( USES_REGS1 )
{
if (Yap_tokptr->Tok == Ord(eot_tok))
if (LOCAL_tokptr->Tok == Ord(eot_tok))
return;
#ifdef EMACS
if ((Yap_tokptr = Yap_tokptr->TokNext)->TokPos > Yap_toktide->TokPos)
Yap_toktide = Yap_tokptr;
#else
if (Yap_tokptr == Yap_toktide)
Yap_toktide = Yap_tokptr = Yap_tokptr->TokNext;
if (LOCAL_tokptr == LOCAL_toktide)
LOCAL_toktide = LOCAL_tokptr = LOCAL_tokptr->TokNext;
else
Yap_tokptr = Yap_tokptr->TokNext;
#endif
LOCAL_tokptr = LOCAL_tokptr->TokNext;
}
inline static void
checkfor(Term c, JMPBUFF *FailBuff USES_REGS)
{
if (Yap_tokptr->Tok != Ord(Ponctuation_tok)
|| Yap_tokptr->TokInfo != c)
if (LOCAL_tokptr->Tok != Ord(Ponctuation_tok)
|| LOCAL_tokptr->TokInfo != c)
FAIL;
NextToken;
}
@ -331,16 +326,16 @@ ParseArgs(Atom a, JMPBUFF *FailBuff USES_REGS)
p = (Term *) ParserAuxSp;
while (1) {
Term *tp = (Term *)ParserAuxSp;
if (ParserAuxSp+1 > Yap_TrailTop) {
Yap_ErrorMessage = "Trail Overflow";
if (ParserAuxSp+1 > LOCAL_TrailTop) {
LOCAL_ErrorMessage = "Trail Overflow";
FAIL;
}
*tp++ = Unsigned(ParseTerm(999, FailBuff PASS_REGS));
ParserAuxSp = (char *)tp;
++nargs;
if (Yap_tokptr->Tok != Ord(Ponctuation_tok))
if (LOCAL_tokptr->Tok != Ord(Ponctuation_tok))
break;
if (((int) Yap_tokptr->TokInfo) != ',')
if (((int) LOCAL_tokptr->TokInfo) != ',')
break;
NextToken;
}
@ -350,12 +345,12 @@ ParseArgs(Atom a, JMPBUFF *FailBuff USES_REGS)
* order
*/
if (H > ASP-(nargs+1)) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
func = Yap_MkFunctor(a, nargs);
if (func == NULL) {
Yap_ErrorMessage = "Heap Overflow";
LOCAL_ErrorMessage = "Heap Overflow";
FAIL;
}
#ifdef SFUNC
@ -370,7 +365,7 @@ ParseArgs(Atom a, JMPBUFF *FailBuff USES_REGS)
t = Yap_MkApplTerm(func, nargs, p);
#endif
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
return TermNil;
}
/* check for possible overflow against local stack */
@ -389,25 +384,25 @@ ParseList(JMPBUFF *FailBuff USES_REGS)
to_store = H;
H+=2;
to_store[0] = ParseTerm(999, FailBuff PASS_REGS);
if (Yap_tokptr->Tok == Ord(Ponctuation_tok)) {
if (((int) Yap_tokptr->TokInfo) == ',') {
if (LOCAL_tokptr->Tok == Ord(Ponctuation_tok)) {
if (((int) LOCAL_tokptr->TokInfo) == ',') {
NextToken;
if (Yap_tokptr->Tok == Ord(Name_tok)
&& strcmp(RepAtom((Atom)(Yap_tokptr->TokInfo))->StrOfAE, "..") == 0) {
if (LOCAL_tokptr->Tok == Ord(Name_tok)
&& strcmp(RepAtom((Atom)(LOCAL_tokptr->TokInfo))->StrOfAE, "..") == 0) {
NextToken;
to_store[1] = ParseTerm(999, FailBuff PASS_REGS);
} else {
/* check for possible overflow against local stack */
if (H > ASP-4096) {
to_store[1] = TermNil;
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
} else {
to_store[1] = AbsPair(H);
goto loop;
}
}
} else if (((int) Yap_tokptr->TokInfo) == '|') {
} else if (((int) LOCAL_tokptr->TokInfo) == '|') {
NextToken;
to_store[1] = ParseTerm(999, FailBuff PASS_REGS);
} else {
@ -436,14 +431,14 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
Volatile int curprio = 0, opprio, oplprio, oprprio;
Volatile Atom opinfo;
switch (Yap_tokptr->Tok) {
switch (LOCAL_tokptr->Tok) {
case Name_tok:
t = Yap_tokptr->TokInfo;
t = LOCAL_tokptr->TokInfo;
NextToken;
/* special rules apply for +1, -2.3, etc... */
if (Yap_tokptr->Tok == Number_tok) {
if (LOCAL_tokptr->Tok == Number_tok) {
if ((Atom)t == AtomMinus) {
t = Yap_tokptr->TokInfo;
t = LOCAL_tokptr->TokInfo;
if (IsIntTerm(t))
t = MkIntTerm(-IntOfTerm(t));
else if (IsFloatTerm(t))
@ -459,12 +454,12 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
break;
}
}
if ((Yap_tokptr->Tok != Ord(Ponctuation_tok)
|| Unsigned(Yap_tokptr->TokInfo) != 'l')
if ((LOCAL_tokptr->Tok != Ord(Ponctuation_tok)
|| Unsigned(LOCAL_tokptr->TokInfo) != 'l')
&& IsPrefixOp((Atom)t, &opprio, &oprprio PASS_REGS)
) {
if (Yap_tokptr->Tok == Name_tok) {
Atom at = (Atom)Yap_tokptr->TokInfo;
if (LOCAL_tokptr->Tok == Name_tok) {
Atom at = (Atom)LOCAL_tokptr->TokInfo;
#ifndef _MSC_VER
if ((Atom)t == AtomPlus) {
if (at == AtomInf) {
@ -495,14 +490,14 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
/* build appl on the heap */
func = Yap_MkFunctor((Atom) t, 1);
if (func == NULL) {
Yap_ErrorMessage = "Heap Overflow";
LOCAL_ErrorMessage = "Heap Overflow";
FAIL;
}
t = ParseTerm(oprprio, FailBuff PASS_REGS);
t = Yap_MkApplTerm(func, 1, &t);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
curprio = opprio;
@ -511,21 +506,21 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
)
}
}
if (Yap_tokptr->Tok == Ord(Ponctuation_tok)
&& Unsigned(Yap_tokptr->TokInfo) == 'l')
if (LOCAL_tokptr->Tok == Ord(Ponctuation_tok)
&& Unsigned(LOCAL_tokptr->TokInfo) == 'l')
t = ParseArgs((Atom) t, FailBuff PASS_REGS);
else
t = MkAtomTerm((Atom)t);
break;
case Number_tok:
t = Yap_tokptr->TokInfo;
t = LOCAL_tokptr->TokInfo;
NextToken;
break;
case String_tok: /* build list on the heap */
{
Volatile char *p = (char *) Yap_tokptr->TokInfo;
Volatile char *p = (char *) LOCAL_tokptr->TokInfo;
if (*p == 0)
t = MkAtomTerm(AtomNil);
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_CHARS)
@ -533,7 +528,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_ATOM) {
Atom at = Yap_LookupAtom(p);
if (at == NIL) {
Yap_ErrorMessage = "Heap Overflow";
LOCAL_ErrorMessage = "Heap Overflow";
FAIL;
}
t = MkAtomTerm(at);
@ -545,7 +540,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
case WString_tok: /* build list on the heap */
{
Volatile wchar_t *p = (wchar_t *) Yap_tokptr->TokInfo;
Volatile wchar_t *p = (wchar_t *) LOCAL_tokptr->TokInfo;
if (*p == 0)
t = MkAtomTerm(AtomNil);
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_CHARS)
@ -559,7 +554,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
break;
case Var_tok:
varinfo = (VarEntry *) (Yap_tokptr->TokInfo);
varinfo = (VarEntry *) (LOCAL_tokptr->TokInfo);
if ((t = varinfo->VarAdr) == TermNil) {
t = varinfo->VarAdr = MkVarTerm();
}
@ -570,7 +565,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
FAIL;
case Ponctuation_tok:
switch ((int) Yap_tokptr->TokInfo) {
switch ((int) LOCAL_tokptr->TokInfo) {
case '(':
case 'l': /* non solo ( */
NextToken;
@ -588,7 +583,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
t = Yap_MkApplTerm(FunctorBraces, 1, &t);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
checkfor((Term) '}', FailBuff PASS_REGS);
@ -605,17 +600,17 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
/* main loop to parse infix and posfix operators starts here */
while (TRUE) {
if (Yap_tokptr->Tok == Ord(Name_tok)
&& Yap_HasOp((Atom)(Yap_tokptr->TokInfo))) {
Atom save_opinfo = opinfo = (Atom)(Yap_tokptr->TokInfo);
if (LOCAL_tokptr->Tok == Ord(Name_tok)
&& Yap_HasOp((Atom)(LOCAL_tokptr->TokInfo))) {
Atom save_opinfo = opinfo = (Atom)(LOCAL_tokptr->TokInfo);
if (IsInfixOp(save_opinfo, &opprio, &oplprio, &oprprio PASS_REGS)
&& opprio <= prio && oplprio >= curprio) {
/* try parsing as infix operator */
Volatile int oldprio = curprio;
TRY3(
func = Yap_MkFunctor((Atom) Yap_tokptr->TokInfo, 2);
func = Yap_MkFunctor((Atom) LOCAL_tokptr->TokInfo, 2);
if (func == NULL) {
Yap_ErrorMessage = "Heap Overflow";
LOCAL_ErrorMessage = "Heap Overflow";
FAIL;
}
NextToken;
@ -626,7 +621,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
t = Yap_MkApplTerm(func, 2, args);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
},
@ -641,15 +636,15 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
if (IsPosfixOp(opinfo, &opprio, &oplprio PASS_REGS)
&& opprio <= prio && oplprio >= curprio) {
/* parse as posfix operator */
Functor func = Yap_MkFunctor((Atom) Yap_tokptr->TokInfo, 1);
Functor func = Yap_MkFunctor((Atom) LOCAL_tokptr->TokInfo, 1);
if (func == NULL) {
Yap_ErrorMessage = "Heap Overflow";
LOCAL_ErrorMessage = "Heap Overflow";
FAIL;
}
t = Yap_MkApplTerm(func, 1, &t);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
curprio = opprio;
@ -658,8 +653,8 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
}
break;
}
if (Yap_tokptr->Tok == Ord(Ponctuation_tok)) {
if (Unsigned(Yap_tokptr->TokInfo) == ',' &&
if (LOCAL_tokptr->Tok == Ord(Ponctuation_tok)) {
if (Unsigned(LOCAL_tokptr->TokInfo) == ',' &&
prio >= 1000 && curprio <= 999) {
Volatile Term args[2];
NextToken;
@ -668,12 +663,12 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
t = Yap_MkApplTerm(FunctorComma, 2, args);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
curprio = 1000;
continue;
} else if (Unsigned(Yap_tokptr->TokInfo) == '|' &&
} else if (Unsigned(LOCAL_tokptr->TokInfo) == '|' &&
IsInfixOp(AtomVBar, &opprio, &oplprio, &oprprio PASS_REGS)
&& opprio <= prio && oplprio >= curprio) {
Volatile Term args[2];
@ -683,19 +678,19 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
t = Yap_MkApplTerm(FunctorVBar, 2, args);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
Yap_ErrorMessage = "Stack Overflow";
LOCAL_ErrorMessage = "Stack Overflow";
FAIL;
}
curprio = opprio;
continue;
}
}
if (Yap_tokptr->Tok <= Ord(WString_tok))
if (LOCAL_tokptr->Tok <= Ord(WString_tok))
FAIL;
break;
}
#ifdef DEBUG
if (Yap_Option['p' - 'a' + 1]) {
if (GLOBAL_Option['p' - 'a' + 1]) {
Yap_DebugPutc(LOCAL_c_error_stream,'[');
Yap_DebugPlWrite(t);
Yap_DebugPutc(LOCAL_c_error_stream,']');
@ -715,7 +710,7 @@ Yap_Parse(void)
if (!sigsetjmp(FailBuff.JmpBuff, 0)) {
t = ParseTerm(1200, &FailBuff PASS_REGS);
if (Yap_tokptr->Tok != Ord(eot_tok))
if (LOCAL_tokptr->Tok != Ord(eot_tok))
return (0L);
return (t);
} else

276
C/save.c
View File

@ -164,19 +164,19 @@ do_system_error(yap_error_number etype, const char *msg)
CACHE_REGS
#if HAVE_SNPRINTF
#if HAVE_STRERROR
snprintf(Yap_ErrorSay,MAX_ERROR_MSG_SIZE,"%s (%s when reading %s)", msg, strerror(errno), Yap_FileNameBuf);
snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s (%s when reading %s)", msg, strerror(errno), LOCAL_FileNameBuf);
#else
snprintf(Yap_ErrorSay,MAX_ERROR_MSG_SIZE,"%s, (system error %d when reading %s)",msg,errno,Yap_FileNameBuf);
snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
#endif
#else
#if HAVE_STRERROR
sprintf(Yap_ErrorSay,"%s, (%s when reading %s)",msg,strerror(errno),Yap_FileNameBuf);
sprintf(LOCAL_ErrorSay,"%s, (%s when reading %s)",msg,strerror(errno),LOCAL_FileNameBuf);
#else
sprintf(Yap_ErrorSay,"%s, (system error %d when reading %s)",msg,errno,Yap_FileNameBuf);
sprintf(LOCAL_ErrorSay,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
#endif
#endif
Yap_ErrorMessage = Yap_ErrorSay;
Yap_Error_TYPE = etype;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
LOCAL_Error_TYPE = etype;
return -1;
}
@ -227,7 +227,7 @@ static int splfild = 0;
#ifdef DEBUG_RESTORE4
static FILE *errout;
#else
#define errout Yap_stderr
#define errout GLOBAL_stderr
#endif
#endif /* DEBUG */
@ -349,13 +349,13 @@ put_info(int info, int mode USES_REGS)
return -1;
/* current state of stacks, to be used by SavedInfo */
/* space available in heap area */
if (putout(Unsigned(Yap_GlobalBase)-Unsigned(Yap_HeapBase)) < 0)
if (putout(Unsigned(LOCAL_GlobalBase)-Unsigned(Yap_HeapBase)) < 0)
return -1;
/* space available for stacks */
if (putout(Unsigned(Yap_LocalBase)-Unsigned(Yap_GlobalBase)) < 0)
if (putout(Unsigned(LOCAL_LocalBase)-Unsigned(LOCAL_GlobalBase)) < 0)
return -1;
/* space available for trail */
if (putout(Unsigned(Yap_TrailTop)-Unsigned(Yap_TrailBase)) < 0)
if (putout(Unsigned(LOCAL_TrailTop)-Unsigned(LOCAL_TrailBase)) < 0)
return -1;
/* Space used in heap area */
if (putout(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)) < 0)
@ -364,10 +364,10 @@ put_info(int info, int mode USES_REGS)
if (putout(Unsigned(LCL0)-Unsigned(ASP)) < 0)
return -1;
/* Space used for global stack */
if (putout(Unsigned(H) - Unsigned(Yap_GlobalBase)) < 0)
if (putout(Unsigned(H) - Unsigned(LOCAL_GlobalBase)) < 0)
return -1;
/* Space used for trail */
if (putout(Unsigned(TR) - Unsigned(Yap_TrailBase)) < 0)
if (putout(Unsigned(TR) - Unsigned(LOCAL_TrailBase)) < 0)
return -1;
return 0;
}
@ -473,7 +473,7 @@ save_regs(int mode USES_REGS)
if (putout(ARG2) < 0)
return -1;
}
if (putcellptr(CellPtr(Yap_TrailBase)) < 0)
if (putcellptr(CellPtr(LOCAL_TrailBase)) < 0)
return -1;
}
return 0;
@ -528,18 +528,18 @@ save_stacks(int mode USES_REGS)
if (mywrite(splfild, (char *) ASP, j) < 0)
return -1;
/* Save the global stack */
j = Unsigned(H) - Unsigned(Yap_GlobalBase);
if (mywrite(splfild, (char *) Yap_GlobalBase, j) < 0)
j = Unsigned(H) - Unsigned(LOCAL_GlobalBase);
if (mywrite(splfild, (char *) LOCAL_GlobalBase, j) < 0)
return -1;
/* Save the trail */
j = Unsigned(TR) - Unsigned(Yap_TrailBase);
if (mywrite(splfild, (char *) Yap_TrailBase, j) < 0)
j = Unsigned(TR) - Unsigned(LOCAL_TrailBase);
if (mywrite(splfild, (char *) LOCAL_TrailBase, j) < 0)
return -1;
break;
case DO_ONLY_CODE:
{
tr_fr_ptr tr_ptr = TR;
while (tr_ptr != (tr_fr_ptr)Yap_TrailBase) {
while (tr_ptr != (tr_fr_ptr)LOCAL_TrailBase) {
CELL val = TrailTerm(tr_ptr-1);
if (IsVarTerm(val)) {
CELL *d1 = VarOfTerm(val);
@ -577,18 +577,18 @@ do_save(int mode USES_REGS) {
Term t1 = Deref(ARG1);
if (Yap_HoleSize) {
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)),
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
"restore/1: address space has holes of size %ld, cannot save", (long int)Yap_HoleSize);
return FALSE;
}
if (!Yap_GetName(Yap_FileNameBuf, YAP_FILENAME_MAX, t1)) {
if (!Yap_GetName(LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
Yap_Error(TYPE_ERROR_LIST,t1,"save/1");
return FALSE;
}
Scleanup();
Yap_CloseStreams(TRUE);
if ((splfild = open_file(Yap_FileNameBuf, O_WRONLY | O_CREAT)) < 0) {
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)),
if ((splfild = open_file(LOCAL_FileNameBuf, O_WRONLY | O_CREAT)) < 0) {
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
"restore/1, open(%s)", strerror(errno));
return(FALSE);
}
@ -682,42 +682,42 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
}
}
if (strcmp(pp, msg) != 0) {
Yap_ErrorMessage = Yap_ErrorSay;
strncpy(Yap_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE);
strncat(Yap_ErrorMessage, Yap_FileNameBuf, MAX_ERROR_MSG_SIZE);
strncat(Yap_ErrorMessage, " failed to match version ID", MAX_ERROR_MSG_SIZE);
Yap_Error_TYPE = CONSISTENCY_ERROR;
LOCAL_ErrorMessage = LOCAL_ErrorSay;
strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE);
strncat(LOCAL_ErrorMessage, LOCAL_FileNameBuf, MAX_ERROR_MSG_SIZE);
strncat(LOCAL_ErrorMessage, " failed to match version ID", MAX_ERROR_MSG_SIZE);
LOCAL_Error_TYPE = CONSISTENCY_ERROR;
return FAIL_RESTORE;
}
/* check info on header */
/* ignore info on saved state */
*info = get_header_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
/* check the restore mode */
mode = get_header_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
if (mode != DO_EVERYTHING && mode != DO_ONLY_CODE) {
return FAIL_RESTORE;
}
/* ignore info on stacks size */
*AHeap = get_header_cell();
if (Yap_ErrorMessage) {
if (LOCAL_ErrorMessage) {
return FAIL_RESTORE;
}
*AStack = get_header_cell();
if (Yap_ErrorMessage) {
if (LOCAL_ErrorMessage) {
return FAIL_RESTORE;
}
*ATrail = get_header_cell();
if (Yap_ErrorMessage) {
if (LOCAL_ErrorMessage) {
return FAIL_RESTORE;
}
/* now, check whether we got enough enough space to load the
saved space */
hp_size = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
while (Yap_HeapBase != NULL &&
hp_size > Unsigned(HeapLim) - Unsigned(Yap_HeapBase)) {
@ -727,31 +727,31 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
}
if (mode == DO_EVERYTHING) {
lc_size = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
gb_size=get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
if (Yap_HeapBase != NULL && lc_size+gb_size > Unsigned(Yap_LocalBase) - Unsigned(Yap_GlobalBase)) {
if (Yap_ErrorMessage != NULL)
Yap_ErrorMessage = "could not allocate enough stack space";
if (Yap_HeapBase != NULL && lc_size+gb_size > Unsigned(LOCAL_LocalBase) - Unsigned(LOCAL_GlobalBase)) {
if (LOCAL_ErrorMessage != NULL)
LOCAL_ErrorMessage = "could not allocate enough stack space";
return FAIL_RESTORE;
}
if (Yap_HeapBase != NULL && (tr_size = get_cell()) > Unsigned(Yap_TrailTop) - Unsigned(Yap_TrailBase)) {
if (Yap_ErrorMessage != NULL)
Yap_ErrorMessage = "could not allocate enough trail space";
if (Yap_HeapBase != NULL && (tr_size = get_cell()) > Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase)) {
if (LOCAL_ErrorMessage != NULL)
LOCAL_ErrorMessage = "could not allocate enough trail space";
return FAIL_RESTORE;
}
} else {
/* skip cell size */
get_header_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
get_header_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
get_header_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return FAIL_RESTORE;
}
return(mode);
@ -762,35 +762,35 @@ static int
get_heap_info(USES_REGS1)
{
LOCAL_OldHeapBase = (ADDR) get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_OldHeapTop = (ADDR) get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
OldHeapUsed = (Int) get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
FreeBlocks = (BlockHeader *) get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
AuxBase = (ADDR)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
AuxSp = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
AuxTop = (ADDR)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_ScratchPad.ptr = (ADDR)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_ScratchPad.sz = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_ScratchPad.msz = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_HDiff = Unsigned(Yap_HeapBase) - Unsigned(LOCAL_OldHeapBase);
return 1;
@ -802,130 +802,130 @@ get_heap_info(USES_REGS1)
static int
get_regs(int flag USES_REGS)
{
CELL *NewGlobalBase = (CELL *)Yap_GlobalBase;
CELL *NewGlobalBase = (CELL *)LOCAL_GlobalBase;
CELL *NewLCL0 = LCL0;
CELL *OldXREGS;
/* Get regs */
compile_arrays = (int)get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
if (flag == DO_EVERYTHING) {
CP = (yamop *)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
ENV = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
ASP = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
/* N = get_cell(); */
H0 = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LCL0 = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
H = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
HB = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
B = (choiceptr)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
TR = (tr_fr_ptr)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
YENV = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
S = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
P = (yamop *)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
CreepFlag = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
EX = (struct DB_TERM *)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
#if defined(YAPOR_SBA) || defined(TABLING)
H_FZ = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
B_FZ = (choiceptr)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
TR_FZ = (tr_fr_ptr)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
#endif /* YAPOR_SBA || TABLING */
}
CurrentModule = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
if (flag == DO_EVERYTHING) {
#ifdef COROUTINING
LOCAL_WokenGoals = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
#endif
#ifdef DEPTH_LIMIT
DEPTH = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
#endif
LOCAL_GcGeneration = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_GcPhase = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_GcCurrentPhase = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
}
/* Get the old bases */
OldXREGS = get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
which_save = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
LOCAL_XDiff = (CELL)XREGS - (CELL)OldXREGS;
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
if (get_heap_info( PASS_REGS1 ) < 0)
return -1;
if (flag == DO_EVERYTHING) {
ARG1 = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
if (which_save == 2) {
ARG2 = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
}
/* get old trail base */
LOCAL_OldTrailBase = (ADDR)get_cellptr();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
/* Save the old register where we can easily access them */
LOCAL_OldASP = ASP;
LOCAL_OldLCL0 = LCL0;
LOCAL_OldGlobalBase = (CELL *)Yap_GlobalBase;
LOCAL_OldGlobalBase = (CELL *)LOCAL_GlobalBase;
LOCAL_OldH = H;
LOCAL_OldTR = TR;
LOCAL_GDiff = Unsigned(NewGlobalBase) - Unsigned(Yap_GlobalBase);
LOCAL_GDiff = Unsigned(NewGlobalBase) - Unsigned(LOCAL_GlobalBase);
LOCAL_GDiff0 = 0;
LOCAL_LDiff = Unsigned(NewLCL0) - Unsigned(LCL0);
LOCAL_TrDiff = LOCAL_LDiff;
Yap_GlobalBase = (ADDR)NewGlobalBase;
LOCAL_GlobalBase = (ADDR)NewGlobalBase;
LCL0 = NewLCL0;
}
return 1;
@ -968,10 +968,10 @@ CopyStacks( USES_REGS1 )
if (myread(splfild, (char *) NewASP, j) < 0)
return -1;
j = Unsigned(H) - Unsigned(LOCAL_OldGlobalBase);
if (myread(splfild, (char *) Yap_GlobalBase, j) < 0)
if (myread(splfild, (char *) LOCAL_GlobalBase, j) < 0)
return -1;
j = Unsigned(TR) - Unsigned(LOCAL_OldTrailBase);
if (myread(splfild, Yap_TrailBase, j))
if (myread(splfild, LOCAL_TrailBase, j))
return -1;
return 1;
}
@ -983,10 +983,10 @@ CopyTrailEntries( USES_REGS1 )
{
CELL entry, *Entries;
Entries = (CELL *)Yap_TrailBase;
Entries = (CELL *)LOCAL_TrailBase;
do {
*Entries++ = entry = get_cell();
if (Yap_ErrorMessage)
if (LOCAL_ErrorMessage)
return -1;
} while ((CODEADDR)entry != NULL);
return 1;
@ -1020,7 +1020,7 @@ get_coded(int flag, OPCODE old_ops[] USES_REGS)
if (myread(splfild, my_end_msg, 256) < 0)
return -1;
if (strcmp(end_msg,my_end_msg) != 0) {
Yap_ErrorMessage = "bad trailing CRC in saved state";
LOCAL_ErrorMessage = "bad trailing CRC in saved state";
return -1;
}
return 1;
@ -1035,7 +1035,7 @@ restore_heap_regs( USES_REGS1 )
*((YAP_SEG_SIZE *) HeapTop) = InUseFlag;
}
HeapMax = Yap_heap_regs->heap_used = OldHeapUsed;
HeapLim = Yap_GlobalBase;
HeapLim = LOCAL_GlobalBase;
}
/* adjust abstract machine registers */
@ -1142,8 +1142,8 @@ rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS)
basep = H;
if (H + (NOfE*2) > ASP) {
basep = (CELL *)TR;
if (basep + (NOfE*2) > (CELL *)Yap_TrailTop) {
if (!Yap_growtrail((ADDR)(basep + (NOfE*2))-Yap_TrailTop, TRUE)) {
if (basep + (NOfE*2) > (CELL *)LOCAL_TrailTop) {
if (!Yap_growtrail((ADDR)(basep + (NOfE*2))-LOCAL_TrailTop, TRUE)) {
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil,
"not enough space to restore hash tables for indexing");
Yap_exit(1);
@ -1337,7 +1337,7 @@ ShowEntries(pp)
PropEntry *pp;
{
while (!EndOfPAEntr(pp)) {
fprintf(Yap_stderr,"Estou a ver a prop %x em %x\n", pp->KindOfPE, pp);
fprintf(GLOBAL_stderr,"Estou a ver a prop %x em %x\n", pp->KindOfPE, pp);
pp = RepProp(pp->NextOfPE);
}
}
@ -1352,7 +1352,7 @@ ShowAtoms()
AtomEntry *at;
at = RepAtom(HashPtr->Entry);
do {
fprintf(Yap_stderr,"Passei ao %s em %x\n", at->StrOfAE, at);
fprintf(GLOBAL_stderr,"Passei ao %s em %x\n", at->StrOfAE, at);
ShowEntries(RepProp(at->PropsOfAE));
} while (!EndOfPAEntr(at = RepAtom(at->NextOfAE)));
}
@ -1364,7 +1364,7 @@ ShowAtoms()
AtomEntry *at;
at = RepAtom(HashPtr->Entry);
do {
fprintf(Yap_stderr,"Passei ao %s em %x\n", at->StrOfAE, at);
fprintf(GLOBAL_stderr,"Passei ao %s em %x\n", at->StrOfAE, at);
ShowEntries(RepProp(at->PropsOfAE));
} while (!EndOfPAEntr(at = RepAtom(at->NextOfAE)));
}
@ -1383,12 +1383,12 @@ commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *A
if ((mode = check_header(Astate,ATrail,AStack,AHeap PASS_REGS)) == FAIL_RESTORE)
return(FAIL_RESTORE);
Yap_PrologMode = BootMode;
LOCAL_PrologMode = BootMode;
if (Yap_HeapBase) {
extern void Scleanup(void);
if (!yap_flags[HALT_AFTER_CONSULT_FLAG] && !yap_flags[QUIET_MODE_FLAG]) {
Yap_TrueFileName(s,Yap_FileNameBuf2, YAP_FILENAME_MAX);
fprintf(stderr, "%% Restoring file %s\n", Yap_FileNameBuf2);
Yap_TrueFileName(s,LOCAL_FileNameBuf2, YAP_FILENAME_MAX);
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
}
Scleanup();
Yap_CloseStreams(TRUE);
@ -1397,7 +1397,7 @@ commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *A
/*
* This should be another file, like the log file
*/
errout = Yap_stderr;
errout = GLOBAL_stderr;
#endif
return mode;
}
@ -1425,7 +1425,7 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *
strncpy(buf, inpf, YAP_FILENAME_MAX);
if ((mode = commit_to_saved_state(inpf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
CACHE_REGS
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
return mode;
}
return mode;
@ -1437,8 +1437,7 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
CACHE_REGS
int mode = FAIL_RESTORE;
char save_buffer[YAP_FILENAME_MAX+1];
// Yap_ErrorMessage = NULL;
// LOCAL_ErrorMessage = NULL;
if (inpf == NULL) {
#if _MSC_VER || defined(__MINGW32__)
if (!(inpf = Yap_RegistryGetString("startup")))
@ -1449,18 +1448,18 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
if (inpf[0] != '/') {
#if __simplescalar__
/* does not implement getcwd */
strncpy(Yap_FileNameBuf,yap_pwd,YAP_FILENAME_MAX);
strncpy(LOCAL_FileNameBuf,GLOBAL_pwd,YAP_FILENAME_MAX);
#elif HAVE_GETCWD
if (getcwd (Yap_FileNameBuf, YAP_FILENAME_MAX) == NULL)
Yap_FileNameBuf[0] = '\0';
if (getcwd (LOCAL_FileNameBuf, YAP_FILENAME_MAX) == NULL)
LOCAL_FileNameBuf[0] = '\0';
#else
if (getwd (Yap_FileNameBuf) == NULL)
Yap_FileNameBuf[0] = '\0';
if (getwd (LOCAL_FileNameBuf) == NULL)
LOCAL_FileNameBuf[0] = '\0';
#endif
strncat(Yap_FileNameBuf, "/", YAP_FILENAME_MAX-1);
strncat(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
strncat(LOCAL_FileNameBuf, "/", YAP_FILENAME_MAX-1);
strncat(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
} else {
strncat(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
strncat(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
}
if (inpf != NULL && (splfild = open_file(inpf, O_RDONLY)) > 0) {
if ((mode = try_open(inpf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
@ -1473,12 +1472,12 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
using YAPLIBDIR or friends.
*/
if (YapLibDir != NULL) {
cat_file_name(Yap_FileNameBuf, Yap_LibDir, inpf, YAP_FILENAME_MAX);
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
cat_file_name(LOCAL_FileNameBuf, Yap_LibDir, inpf, YAP_FILENAME_MAX);
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
return mode;
}
} else {
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
return mode;
}
}
@ -1486,17 +1485,17 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
{
char *yap_env = getenv("YAPLIBDIR");
if (yap_env != NULL) {
cat_file_name(Yap_FileNameBuf, yap_env, inpf, YAP_FILENAME_MAX);
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
cat_file_name(LOCAL_FileNameBuf, yap_env, inpf, YAP_FILENAME_MAX);
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
return mode;
}
}
}
#endif
if (YAP_LIBDIR != NULL) {
cat_file_name(Yap_FileNameBuf, YAP_LIBDIR, inpf, YAP_FILENAME_MAX);
if ((splfild = open_file(Yap_FileNameBuf, O_RDONLY)) > 0) {
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
cat_file_name(LOCAL_FileNameBuf, YAP_LIBDIR, inpf, YAP_FILENAME_MAX);
if ((splfild = open_file(LOCAL_FileNameBuf, O_RDONLY)) > 0) {
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
return mode;
}
}
@ -1509,34 +1508,34 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
char *pt;
/* try to get it from current executable */
if ((fatts = GetFileAttributes(Yap_FileNameBuf)) == 0xFFFFFFFFL ||
if ((fatts = GetFileAttributes(LOCAL_FileNameBuf)) == 0xFFFFFFFFL ||
!(fatts & FILE_ATTRIBUTE_DIRECTORY)) {
/* couldn't find it where it was supposed to be,
let's try using the executable */
if (!GetModuleFileNameEx( GetCurrentProcess(), NULL, Yap_FileNameBuf, YAP_FILENAME_MAX)) {
if (!GetModuleFileNameEx( GetCurrentProcess(), NULL, LOCAL_FileNameBuf, YAP_FILENAME_MAX)) {
/* do nothing */
goto end;
}
buflen = strlen(Yap_FileNameBuf);
pt = Yap_FileNameBuf+strlen(Yap_FileNameBuf);
buflen = strlen(LOCAL_FileNameBuf);
pt = LOCAL_FileNameBuf+strlen(LOCAL_FileNameBuf);
while (*--pt != '\\') {
/* skip executable */
if (pt == Yap_FileNameBuf) {
if (pt == LOCAL_FileNameBuf) {
/* do nothing */
goto end;
}
}
while (*--pt != '\\') {
/* skip parent directory "bin\\" */
if (pt == Yap_FileNameBuf) {
if (pt == LOCAL_FileNameBuf) {
goto end;
}
}
/* now, this is a possible location for the ROOT_DIR, let's look for a share directory here */
pt[1] = '\0';
strncat(Yap_FileNameBuf,"lib/Yap/startup.yss",YAP_FILENAME_MAX);
strncat(LOCAL_FileNameBuf,"lib/Yap/startup.yss",YAP_FILENAME_MAX);
}
if ((mode = try_open(Yap_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
return mode;
}
}
@ -1544,12 +1543,12 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
#endif
/* try to open from current directory */
/* could not open file */
if (Yap_ErrorMessage == NULL) {
if (LOCAL_ErrorMessage == NULL) {
if (save_buffer[0]) {
strncpy(Yap_FileNameBuf, save_buffer, YAP_FILENAME_MAX-1);
strncpy(LOCAL_FileNameBuf, save_buffer, YAP_FILENAME_MAX-1);
do_system_error(PERMISSION_ERROR_OPEN_SOURCE_SINK,"incorrect saved state");
} else {
strncpy(Yap_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
do_system_error(PERMISSION_ERROR_OPEN_SOURCE_SINK,"could not open saved state");
}
}
@ -1559,11 +1558,12 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
static void
CloseRestore(void)
{
CACHE_REGS
#ifdef DEBUG_RESTORE3
ShowAtoms();
#endif
close_file();
Yap_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
}
#if !defined(_WIN32)
@ -1660,7 +1660,7 @@ UnmarkTrEntries( USES_REGS1 )
B = (choiceptr)LCL0;
B--;
B->cp_ap = NOCODE;
Entries = (CELL *)Yap_TrailBase;
Entries = (CELL *)LOCAL_TrailBase;
while ((entry = *Entries++) != (CELL)NULL) {
if (!IsVarTerm(entry)) {
if(IsPairTerm(entry)) {
@ -1742,8 +1742,8 @@ Restore(char *s, char *lib_dir USES_REGS)
case DO_EVERYTHING:
if (LOCAL_OldHeapBase != Yap_HeapBase ||
LOCAL_OldLCL0 != LCL0 ||
LOCAL_OldGlobalBase != (CELL *)Yap_GlobalBase ||
LOCAL_OldTrailBase != Yap_TrailBase) {
LOCAL_OldGlobalBase != (CELL *)LOCAL_GlobalBase ||
LOCAL_OldTrailBase != LOCAL_TrailBase) {
Yap_AdjustStacksAndTrail();
if (which_save == 2) {
Yap_AdjustRegs(2);
@ -1816,7 +1816,7 @@ p_restore( USES_REGS1 )
restore_absmi_regs(&Yap_standard_regs);
#endif
/* back to the top level we go */
siglongjmp(Yap_RestartEnv,3);
siglongjmp(LOCAL_RestartEnv,3);
}
return(mode != FAIL_RESTORE);
}

View File

@ -184,7 +184,7 @@ AllocScannerMemory(unsigned int size)
ptr->next = LOCAL_ScannerExtraBlocks;
LOCAL_ScannerExtraBlocks = ptr;
return (char *)(ptr+1);
} else if (Yap_TrailTop <= AuxSpScan+size) {
} else if (LOCAL_TrailTop <= AuxSpScan+size) {
UInt alloc_size = sizeof(CELL) * K16;
if (size > alloc_size)
@ -235,7 +235,7 @@ float_send(char *s, int sign)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
if (!finite(f)) {
CACHE_REGS
Yap_ErrorMessage = "Float overflow while scanning";
LOCAL_ErrorMessage = "Float overflow while scanning";
return(MkEvalFl(0.0));
}
}
@ -268,7 +268,7 @@ static int
send_error_message(char s[])
{
CACHE_REGS
Yap_ErrorMessage = s;
LOCAL_ErrorMessage = s;
return 0;
}
@ -502,7 +502,7 @@ static int
num_send_error_message(char s[])
{
CACHE_REGS
Yap_ErrorMessage = s;
LOCAL_ErrorMessage = s;
return TermNil;
}
@ -727,12 +727,12 @@ Yap_scan_num(IOSTREAM *inp)
int ch, cherr;
char *ptr;
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
LOCAL_ScannerStack = (char *)TR;
LOCAL_ScannerExtraBlocks = NULL;
if (!(ptr = AllocScannerMemory(4096))) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
return TermNil;
}
ch = getchr(inp);
@ -755,7 +755,7 @@ Yap_scan_num(IOSTREAM *inp)
out = get_num(&ch, &cherr, inp, ptr, 4096, sign); /* */
PopScannerMemory(ptr, 4096);
Yap_clean_tokenizer(NULL, NULL, NULL);
if (Yap_ErrorMessage != NULL || ch != -1 || cherr)
if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr)
return TermNil;
return out;
}
@ -769,8 +769,8 @@ ch_to_wide(char *base, char *charp)
wchar_t *nb = (wchar_t *)base;
if ((nb+n) + 1024 > (wchar_t *)AuxSp) {
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
return NULL;
}
for (i=n; i > 0; i--) {
@ -800,11 +800,10 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
int ch;
wchar_t *wcharp;
Yap_ErrorMessage = NULL;
Yap_Error_Size = 0;
Yap_VarTable = NULL;
Yap_AnonVarTable = NULL;
Yap_eot_before_eof = FALSE;
LOCAL_ErrorMessage = NULL;
LOCAL_Error_Size = 0;
LOCAL_VarTable = NULL;
LOCAL_AnonVarTable = NULL;
LOCAL_ScannerStack = (char *)TR;
LOCAL_ScannerExtraBlocks = NULL;
l = NULL;
@ -826,8 +825,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
t = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
t->TokNext = NULL;
if (t == NULL) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
if (p)
p->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -855,6 +854,15 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
}
if (ASP-H < 1024) {
LOCAL_ErrorMessage = "Stack Overflow";
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = 0L;
if (p)
p->Tok = Ord(kind = eot_tok);
/* serious error now */
return l;
}
*tposp = Yap_StreamPosition(inp_stream);
}
goto restart;
@ -878,8 +886,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
if (charp == (char *)AuxSp-1024) {
huge_var_error:
/* huge atom or variable, we are in trouble */
Yap_ErrorMessage = "Code Space Overflow due to huge atom";
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_ErrorMessage = "Code Space Overflow due to huge atom";
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
if (p)
p->Tok = Ord(kind = eot_tok);
@ -905,8 +913,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
ae = Yap_LookupAtom(TokImage);
}
if (ae == NIL) {
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_ErrorMessage = "Code Space Overflow";
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_ErrorMessage = "Code Space Overflow";
if (p)
t->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -932,17 +940,17 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
cherr = 0;
if (!(ptr = AllocScannerMemory(4096))) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
if (p)
t->Tok = Ord(kind = eot_tok);
/* serious error now */
return l;
}
if (ASP-H < 1024) {
Yap_ErrorMessage = "Stack Overflow";
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Size = 0L;
LOCAL_ErrorMessage = "Stack Overflow";
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = 0L;
if (p)
p->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -962,8 +970,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
t->TokPos = GetCurInpPos(inp_stream);
e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
if (e == NULL) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
if (p)
p->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -991,8 +999,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
t->TokPos = GetCurInpPos(inp_stream);
e2 = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
if (e2 == NULL) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
if (p)
p->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -1022,8 +1030,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
t->TokPos = GetCurInpPos(inp_stream);
e2 = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
if (e2 == NULL) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
t->Tok = Ord(kind = eot_tok);
/* serious error now */
return l;
@ -1055,13 +1063,13 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
while (TRUE) {
if (charp + 1024 > (char *)AuxSp) {
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
break;
}
if (ch == 10 && yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
/* in ISO a new line terminates a string */
Yap_ErrorMessage = "layout character \n inside quotes";
LOCAL_ErrorMessage = "layout character \n inside quotes";
break;
}
if (ch == quote) {
@ -1088,8 +1096,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
++len;
if (charp > (char *)AuxSp - 1024) {
/* Not enough space to read in the string. */
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ErrorMessage = "not enough space to read in string or quoted atom";
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_ErrorMessage = "not enough space to read in string or quoted atom";
/* serious error now */
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = eot_tok);
@ -1108,7 +1116,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
mp = AllocScannerMemory(len + 1);
}
if (mp == NULL) {
Yap_ErrorMessage = "not enough heap space to read in string or quoted atom";
LOCAL_ErrorMessage = "not enough heap space to read in string or quoted atom";
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = eot_tok);
return l;
@ -1131,8 +1139,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
}
if (!(t->TokInfo)) {
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_ErrorMessage = "Code Space Overflow";
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_ErrorMessage = "Code Space Overflow";
if (p)
t->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -1162,6 +1170,15 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
}
if (ASP-H < 1024) {
LOCAL_ErrorMessage = "Stack Overflow";
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = 0L;
if (p)
p->Tok = Ord(kind = eot_tok);
/* serious error now */
return l;
}
*tposp = Yap_StreamPosition(inp_stream);
}
goto restart;
@ -1169,7 +1186,6 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
enter_symbol:
if (och == '.' && (chtype(ch) == BS || chtype(ch) == EF
|| chtype(ch) == CC)) {
Yap_eot_before_eof = TRUE;
if (chtype(ch) == CC)
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF);
t->Tok = Ord(kind = eot_tok);
@ -1183,8 +1199,8 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
*charp = '\0';
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
if (t->TokInfo == (CELL)NIL) {
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_ErrorMessage = "Code Space Overflow";
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
LOCAL_ErrorMessage = "Code Space Overflow";
if (p)
t->Tok = Ord(kind = eot_tok);
/* serious error now */
@ -1247,29 +1263,29 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
default:
#ifdef DEBUG
fprintf(Yap_stderr, "\n++++ token: wrong char type %c %d\n", ch, chtype(ch));
fprintf(GLOBAL_stderr, "\n++++ token: wrong char type %c %d\n", ch, chtype(ch));
#endif
t->Tok = Ord(kind = eot_tok);
}
#ifdef DEBUG
if(Yap_Option[2]) fprintf(Yap_stderr,"[Token %d %ld]",Ord(kind),(unsigned long int)t->TokInfo);
if(GLOBAL_Option[2]) fprintf(GLOBAL_stderr,"[Token %d %ld]",Ord(kind),(unsigned long int)t->TokInfo);
#endif
if (Yap_ErrorMessage) {
if (LOCAL_ErrorMessage) {
/* insert an error token to inform the system of what happened */
TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
if (e == NULL) {
Yap_ErrorMessage = "Trail Overflow";
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
p->Tok = Ord(kind = eot_tok);
/* serious error now */
return l;
}
p->TokNext = e;
e->Tok = Error_tok;
e->TokInfo = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
e->TokPos = GetCurInpPos(inp_stream);
e->TokNext = NULL;
Yap_ErrorMessage = NULL;
LOCAL_ErrorMessage = NULL;
p = e;
}
} while (kind != eot_tok);

View File

@ -59,7 +59,7 @@ build_new_list(CELL *pt, Term t USES_REGS)
pt += 2;
if (pt > ASP - 4096) {
if (!Yap_gcl((ASP-H)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
t = Deref(ARG1);

View File

@ -904,8 +904,8 @@ ch_to_wide(char *base, char *charp USES_REGS)
wchar_t *nb = (wchar_t *)base;
if ((nb+n) + 1024 > (wchar_t *)AuxSp) {
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
return NULL;
}
for (i=n; i > 0; i--) {
@ -1241,7 +1241,7 @@ p_atom_chars( USES_REGS1 )
*ws++ = '\0';
while ((at = Yap_LookupWideAtom((wchar_t *)String)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1249,7 +1249,7 @@ p_atom_chars( USES_REGS1 )
*s++ = '\0';
while ((at = Yap_LookupAtom(String)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1313,7 +1313,7 @@ p_atom_concat( USES_REGS1 )
if (cptr+sz >= top-1024) {
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto restart;
@ -1340,7 +1340,7 @@ p_atom_concat( USES_REGS1 )
cptr[0] = '\0';
while ((at = Yap_LookupWideAtom(cpt0)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1376,7 +1376,7 @@ p_atom_concat( USES_REGS1 )
if (cptr+sz >= top-1024) {
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto restart;
@ -1396,7 +1396,7 @@ p_atom_concat( USES_REGS1 )
cptr[0] = '\0';
while ((at = Yap_LookupAtom(cpt0)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1460,7 +1460,7 @@ p_atomic_concat( USES_REGS1 )
if (wcptr+sz >= wtop-1024) {
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto restart;
@ -1474,7 +1474,7 @@ p_atomic_concat( USES_REGS1 )
if (wcptr+sz >= wtop-1024) {
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto restart;
@ -1517,7 +1517,7 @@ p_atomic_concat( USES_REGS1 )
if (!Yap_gmp_to_string(thead, tmp, (wtop-wcptr)-1024, 10 )) {
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
goto restart;
@ -1541,7 +1541,7 @@ p_atomic_concat( USES_REGS1 )
wcptr[0] = '\0';
while ((at = Yap_LookupWideAtom(wcpt0)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1580,7 +1580,7 @@ p_atomic_concat( USES_REGS1 )
if (cptr+sz >= top-1024) {
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
goto restart;
@ -1607,7 +1607,7 @@ p_atomic_concat( USES_REGS1 )
size_t sz = Yap_gmp_to_size(thead, 10);
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
goto restart;
@ -1628,7 +1628,7 @@ p_atomic_concat( USES_REGS1 )
cptr[0] = '\0';
while ((at = Yap_LookupAtom(cpt0)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2001,7 +2001,7 @@ p_number_chars( USES_REGS1 )
size_t sz = Yap_gmp_to_size(t1, 10);
Yap_ReleasePreAllocCodeSpace((ADDR)String);
if (!Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
goto restart_aux;
@ -2159,7 +2159,7 @@ p_number_atom( USES_REGS1 )
while (!Yap_gmp_to_string(t1, String, ((char *)AuxSp-String)-1024, 10 )) {
size_t sz = Yap_gmp_to_size(t1, 10);
if (!(String = Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE))) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, t1, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, t1, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2170,7 +2170,7 @@ p_number_atom( USES_REGS1 )
}
while ((at = Yap_LookupAtom(String)) == NIL) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2221,7 +2221,7 @@ p_number_codes( USES_REGS1 )
while (!Yap_gmp_to_string(t1, String, ((char *)AuxSp-String)-1024, 10 )) {
size_t sz = Yap_gmp_to_size(t1, 10);
if (!(String = Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE))) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, t1, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, t1, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2318,7 +2318,7 @@ p_atom_number( USES_REGS1 )
while (!Yap_gmp_to_string(t2, String, ((char *)AuxSp-String)-1024, 10 )) {
size_t sz = Yap_gmp_to_size(t2, 10);
if (!(String = Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE))) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, t2, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, t2, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2415,7 +2415,7 @@ p_univ( USES_REGS1 )
/* restore space */
H = Ar;
if (!Yap_gcl((ASP-H)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
twork = TailOfTerm(Deref(ARG2));
@ -2480,7 +2480,7 @@ p_univ( USES_REGS1 )
twork = Yap_ArrayToList(CellPtr(TR), argno - 1);
while (IsIntTerm(twork)) {
if (!Yap_gc(2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
twork = Yap_ArrayToList(CellPtr(TR), argno - 1);
@ -2490,7 +2490,7 @@ p_univ( USES_REGS1 )
{
while (H+arity*2 > ASP-1024) {
if (!Yap_gcl((arity*2)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return(FALSE);
}
tin = Deref(ARG1);
@ -3135,7 +3135,7 @@ p_debug( USES_REGS1 )
int i = IntOfTerm(Deref(ARG1));
if (i >= 'a' && i <= 'z')
Yap_Option[i - 96] = !Yap_Option[i - 96];
GLOBAL_Option[i - 96] = !GLOBAL_Option[i - 96];
return (1);
}
#endif
@ -3329,21 +3329,21 @@ Yap_show_statistics(void)
#endif
frag = (100.0*(heap_space_taken-HeapUsed))/heap_space_taken;
fprintf(Yap_stderr, "Code Space: %ld (%ld bytes needed, %ld bytes used, fragmentation %.3f%%).\n",
fprintf(GLOBAL_stderr, "Code Space: %ld (%ld bytes needed, %ld bytes used, fragmentation %.3f%%).\n",
(unsigned long int)(Unsigned (H0) - Unsigned (Yap_HeapBase)),
(unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)),
(unsigned long int)(HeapUsed),
frag);
fprintf(Yap_stderr, "Stack Space: %ld (%ld for Global, %ld for local).\n",
fprintf(GLOBAL_stderr, "Stack Space: %ld (%ld for Global, %ld for local).\n",
(unsigned long int)(sizeof(CELL)*(LCL0-H0)),
(unsigned long int)(sizeof(CELL)*(H-H0)),
(unsigned long int)(sizeof(CELL)*(LCL0-ASP)));
fprintf(Yap_stderr, "Trail Space: %ld (%ld used).\n",
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(Yap_TrailTop)-Unsigned(Yap_TrailBase))),
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(TR)-Unsigned(Yap_TrailBase))));
fprintf(Yap_stderr, "Runtime: %lds.\n", (unsigned long int)(runtime ( PASS_REGS1 )));
fprintf(Yap_stderr, "Cputime: %lds.\n", (unsigned long int)(Yap_cputime ()));
fprintf(Yap_stderr, "Walltime: %lds.\n", (unsigned long int)(Yap_walltime ()));
fprintf(GLOBAL_stderr, "Trail Space: %ld (%ld used).\n",
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(LOCAL_TrailTop)-Unsigned(LOCAL_TrailBase))),
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(TR)-Unsigned(LOCAL_TrailBase))));
fprintf(GLOBAL_stderr, "Runtime: %lds.\n", (unsigned long int)(runtime ( PASS_REGS1 )));
fprintf(GLOBAL_stderr, "Cputime: %lds.\n", (unsigned long int)(Yap_cputime ()));
fprintf(GLOBAL_stderr, "Walltime: %lds.\n", (unsigned long int)(Yap_walltime ()));
}
static Int
@ -3366,12 +3366,12 @@ TrailMax(void)
{
CACHE_REGS
Int i;
Int TrWidth = Unsigned(Yap_TrailTop) - Unsigned(Yap_TrailBase);
Int TrWidth = Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase);
CELL *pt;
if (TrailTide != TrWidth) {
pt = (CELL *)TR;
while (pt+2 < (CELL *)Yap_TrailTop) {
while (pt+2 < (CELL *)LOCAL_TrailTop) {
if (pt[0] == 0 &&
pt[1] == 0 &&
pt[2] == 0)
@ -3379,8 +3379,8 @@ TrailMax(void)
else
pt++;
}
if (pt+2 < (CELL *)Yap_TrailTop)
i = Unsigned(pt) - Unsigned(Yap_TrailBase);
if (pt+2 < (CELL *)LOCAL_TrailTop)
i = Unsigned(pt) - Unsigned(LOCAL_TrailBase);
else
i = TrWidth;
} else
@ -3495,12 +3495,12 @@ p_statistics_heap_info( USES_REGS1 )
#if USE_SYSTEM_MALLOC && HAVE_MALLINFO
struct mallinfo mi = mallinfo();
UInt sstack = Yap_HoleSize+(Yap_TrailTop-Yap_GlobalBase);
UInt sstack = Yap_HoleSize+(LOCAL_TrailTop-LOCAL_GlobalBase);
UInt mmax = (mi.arena+mi.hblkhd);
Term tmax = MkIntegerTerm(mmax-sstack);
tusage = MkIntegerTerm(mmax-(mi.fordblks+sstack));
#else
Term tmax = MkIntegerTerm((Yap_GlobalBase - Yap_HeapBase)-Yap_HoleSize);
Term tmax = MkIntegerTerm((LOCAL_GlobalBase - Yap_HeapBase)-Yap_HoleSize);
#endif
return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2));
@ -3524,8 +3524,8 @@ p_statistics_stacks_info( USES_REGS1 )
static Int
p_statistics_trail_info( USES_REGS1 )
{
Term tmax = MkIntegerTerm(Unsigned(Yap_TrailTop) - Unsigned(Yap_TrailBase));
Term tusage = MkIntegerTerm(Unsigned(TR) - Unsigned(Yap_TrailBase));
Term tmax = MkIntegerTerm(Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase));
Term tusage = MkIntegerTerm(Unsigned(TR) - Unsigned(LOCAL_TrailBase));
return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2));
@ -3623,8 +3623,8 @@ mk_argc_list( USES_REGS1 )
{
int i =0;
Term t = TermNil;
while (i < Yap_argc) {
char *arg = Yap_argv[i];
while (i < GLOBAL_argc) {
char *arg = GLOBAL_argv[i];
/* check for -L -- */
if (arg[0] == '-' && arg[1] == 'L') {
arg += 2;
@ -3633,15 +3633,15 @@ mk_argc_list( USES_REGS1 )
if (*arg == '-' && arg[1] == '-' && arg[2] == '\0') {
/* we found the separator */
int j;
for (j = Yap_argc-1; j > i+1; --j) {
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(Yap_argv[j])),t);
for (j = GLOBAL_argc-1; j > i+1; --j) {
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])),t);
}
return t;
} else if (Yap_argv[i+1] && Yap_argv[i+1][0] == '-' && Yap_argv[i+1][1] == '-' && Yap_argv[i+1][2] == '\0') {
} else if (GLOBAL_argv[i+1] && GLOBAL_argv[i+1][0] == '-' && GLOBAL_argv[i+1][1] == '-' && GLOBAL_argv[i+1][2] == '\0') {
/* we found the separator */
int j;
for (j = Yap_argc-1; j > i+2; --j) {
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(Yap_argv[j])),t);
for (j = GLOBAL_argc-1; j > i+2; --j) {
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])),t);
}
return t;
}
@ -3649,8 +3649,8 @@ mk_argc_list( USES_REGS1 )
if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0') {
/* we found the separator */
int j;
for (j = Yap_argc-1; j > i; --j) {
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(Yap_argv[j])),t);
for (j = GLOBAL_argc-1; j > i; --j) {
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])),t);
}
return(t);
}
@ -3670,8 +3670,8 @@ static Int
p_executable( USES_REGS1 )
{
Yap_TrueFileName (Yap_argv[0], Yap_FileNameBuf, FALSE);
return Yap_unify(MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)),ARG1);
Yap_TrueFileName (GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),ARG1);
}
static Int
@ -3904,9 +3904,9 @@ p_system_mode( USES_REGS1 )
{
Int i = IntegerOfTerm(Deref(ARG1));
if (i == 0)
Yap_PrologMode &= ~SystemMode;
LOCAL_PrologMode &= ~SystemMode;
else
Yap_PrologMode |= SystemMode;
LOCAL_PrologMode |= SystemMode;
return TRUE;
}
@ -4110,7 +4110,7 @@ Proc E_Modules[]= {/* init_fc,*/ (Proc) 0 };
#ifndef YAPOR
static
Int p_yapor_threads(void) {
Int p_yapor_threads( USES_REGS1 ) {
return FALSE;
}
#endif

View File

@ -88,7 +88,7 @@ static char SccsId[] = "%W% %G%";
#include <readline/readline.h>
#endif
STATIC_PROTO (void InitPageSize, (void));
STATIC_PROTO (void InitTime, (void));
STATIC_PROTO (void InitWTime, (void));
STATIC_PROTO (Int p_sh, ( USES_REGS1 ));
@ -107,9 +107,6 @@ STATIC_PROTO (int chdir, (char *));
/* #define signal skel_signal */
#endif /* MACYAP */
#if __simplescalar__
char yap_pwd[YAP_FILENAME_MAX];
#endif
STD_PROTO (void exit, (int));
@ -202,27 +199,27 @@ Yap_InitSysPath(void) {
if (dir_done && commons_done)
return;
#endif
strncpy(Yap_FileNameBuf, YAP_SHAREDIR, YAP_FILENAME_MAX);
strncpy(LOCAL_FileNameBuf, YAP_SHAREDIR, YAP_FILENAME_MAX);
#if _MSC_VER || defined(__MINGW32__)
{
DWORD fatts;
int buflen;
char *pt;
if ((fatts = GetFileAttributes(Yap_FileNameBuf)) == 0xFFFFFFFFL ||
if ((fatts = GetFileAttributes(LOCAL_FileNameBuf)) == 0xFFFFFFFFL ||
!(fatts & FILE_ATTRIBUTE_DIRECTORY)) {
/* couldn't find it where it was supposed to be,
let's try using the executable */
if (!GetModuleFileNameEx( GetCurrentProcess(), NULL, Yap_FileNameBuf, YAP_FILENAME_MAX)) {
if (!GetModuleFileNameEx( GetCurrentProcess(), NULL, LOCAL_FileNameBuf, YAP_FILENAME_MAX)) {
Yap_Error(OPERATING_SYSTEM_ERROR, TermNil, "could not find executable name");
/* do nothing */
return;
}
buflen = strlen(Yap_FileNameBuf);
pt = Yap_FileNameBuf+strlen(Yap_FileNameBuf);
buflen = strlen(LOCAL_FileNameBuf);
pt = LOCAL_FileNameBuf+strlen(LOCAL_FileNameBuf);
while (*--pt != '\\') {
/* skip executable */
if (pt == Yap_FileNameBuf) {
if (pt == LOCAL_FileNameBuf) {
Yap_Error(OPERATING_SYSTEM_ERROR, TermNil, "could not find executable name");
/* do nothing */
return;
@ -230,7 +227,7 @@ Yap_InitSysPath(void) {
}
while (*--pt != '\\') {
/* skip parent directory "bin\\" */
if (pt == Yap_FileNameBuf) {
if (pt == LOCAL_FileNameBuf) {
Yap_Error(OPERATING_SYSTEM_ERROR, TermNil, "could not find executable name");
/* do nothing */
}
@ -238,34 +235,34 @@ Yap_InitSysPath(void) {
/* now, this is a possible location for the ROOT_DIR, let's look for a share directory here */
pt[1] = '\0';
/* grosse */
strncat(Yap_FileNameBuf,"lib\\Yap",YAP_FILENAME_MAX);
libdir = Yap_AllocCodeSpace(strlen(Yap_FileNameBuf)+1);
strncpy(libdir, Yap_FileNameBuf, strlen(Yap_FileNameBuf)+1);
strncat(LOCAL_FileNameBuf,"lib\\Yap",YAP_FILENAME_MAX);
libdir = Yap_AllocCodeSpace(strlen(LOCAL_FileNameBuf)+1);
strncpy(libdir, LOCAL_FileNameBuf, strlen(LOCAL_FileNameBuf)+1);
pt[1] = '\0';
strncat(Yap_FileNameBuf,"share",YAP_FILENAME_MAX);
strncat(LOCAL_FileNameBuf,"share",YAP_FILENAME_MAX);
}
}
strncat(Yap_FileNameBuf,"\\", YAP_FILENAME_MAX);
strncat(LOCAL_FileNameBuf,"\\", YAP_FILENAME_MAX);
#else
strncat(Yap_FileNameBuf,"/", YAP_FILENAME_MAX);
strncat(LOCAL_FileNameBuf,"/", YAP_FILENAME_MAX);
#endif
len = strlen(Yap_FileNameBuf);
strncat(Yap_FileNameBuf, "Yap", YAP_FILENAME_MAX);
len = strlen(LOCAL_FileNameBuf);
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
#if _MSC_VER || defined(__MINGW32__)
if (!dir_done)
#endif
{
Yap_PutValue(AtomSystemLibraryDir,
MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)));
MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
}
#if _MSC_VER || defined(__MINGW32__)
if (!commons_done)
#endif
{
Yap_FileNameBuf[len] = '\0';
strncat(Yap_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
LOCAL_FileNameBuf[len] = '\0';
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
Yap_PutValue(AtomPrologCommonsDir,
MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)));
MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
}
}
@ -287,8 +284,8 @@ p_dir_sp ( USES_REGS1 )
}
static void
InitPageSize(void)
void
Yap_InitPageSize(void)
{
#ifdef _WIN32
SYSTEM_INFO si;
@ -1197,7 +1194,7 @@ HandleSIGSEGV(int sig, siginfo_t *sip, ucontext_t *uap)
sip->si_code != SI_NOINFO &&
sip->si_code == SEGV_MAPERR &&
(void *)(sip->si_addr) > (void *)(Yap_HeapBase) &&
(void *)(sip->si_addr) < (void *)(Yap_TrailTop+K64)) {
(void *)(sip->si_addr) < (void *)(LOCAL_TrailTop+K64)) {
Yap_growtrail(K64, TRUE);
} else
#endif
@ -1211,6 +1208,7 @@ HandleSIGSEGV(int sig, siginfo_t *sip, ucontext_t *uap)
static void
HandleMatherr(int sig, siginfo_t *sip, ucontext_t *uap)
{
CACHE_REGS
yap_error_number error_no;
/* reset the registers so that we don't have trash in abstract machine */
@ -1308,6 +1306,7 @@ STATIC_PROTO (void my_signal, (int, void (*)(int)));
static RETSIGTYPE
HandleMatherr(int sig)
{
CACHE_REGS
#if HAVE_FETESTEXCEPT
/* This should work in Linux, but it doesn't seem to. */
@ -1315,19 +1314,19 @@ HandleMatherr(int sig)
int raised = fetestexcept(FE_ALL_EXCEPT);
if (raised & FE_OVERFLOW) {
Yap_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW;
LOCAL_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW;
} else if (raised & (FE_INVALID|FE_INEXACT)) {
Yap_matherror = EVALUATION_ERROR_UNDEFINED;
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED;
} else if (raised & FE_DIVBYZERO) {
Yap_matherror = EVALUATION_ERROR_ZERO_DIVISOR;
LOCAL_matherror = EVALUATION_ERROR_ZERO_DIVISOR;
} else if (raised & FE_UNDERFLOW) {
Yap_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW;
LOCAL_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW;
} else
#endif
Yap_matherror = EVALUATION_ERROR_UNDEFINED;
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED;
/* something very bad happened on the way to the forum */
set_fpu_exceptions(FALSE);
Yap_Error(Yap_matherror, TermNil, "");
Yap_Error(LOCAL_matherror , TermNil, "");
}
#if HAVE_SIGSEGV && !defined(THREADS)
@ -1358,8 +1357,8 @@ SearchForTrailFault(siginfo_t *siginfo)
crash again
*/
#if OS_HANDLES_TR_OVERFLOW && !USE_SYSTEM_MALLOC
if ((ptr > (void *)Yap_TrailTop-1024 &&
TR < (tr_fr_ptr) Yap_TrailTop+(64*1024))) {
if ((ptr > (void *)LOCAL_TrailTop-1024 &&
TR < (tr_fr_ptr) LOCAL_TrailTop+(64*1024))) {
if (!Yap_growtrail(64*1024, TRUE)) {
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, "YAP failed to reserve %ld bytes in growtrail", K64);
}
@ -1376,8 +1375,8 @@ SearchForTrailFault(siginfo_t *siginfo)
static RETSIGTYPE
HandleSIGSEGV(int sig, siginfo_t *siginfo, void *context)
{
if (Yap_PrologMode & ExtendStackMode) {
Yap_Error(FATAL_ERROR, TermNil, "OS memory allocation crashed at address %p, bailing out\n",Yap_TrailTop);
if (LOCAL_PrologMode & ExtendStackMode) {
Yap_Error(FATAL_ERROR, TermNil, "OS memory allocation crashed at address %p, bailing out\n",LOCAL_TrailTop);
}
SearchForTrailFault(siginfo);
}
@ -1445,19 +1444,19 @@ HandleMatherr(int sig)
int raised = fetestexcept(FE_ALL_EXCEPT);
if (raised & FE_OVERFLOW) {
Yap_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW;
LOCAL_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW;
} else if (raised & (FE_INVALID|FE_INEXACT)) {
Yap_matherror = EVALUATION_ERROR_UNDEFINED;
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED;
} else if (raised & FE_DIVBYZERO) {
Yap_matherror = EVALUATION_ERROR_ZERO_DIVISOR;
LOCAL_matherror = EVALUATION_ERROR_ZERO_DIVISOR;
} else if (raised & FE_UNDERFLOW) {
Yap_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW;
LOCAL_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW;
} else
#endif
Yap_matherror = EVALUATION_ERROR_UNDEFINED;
LOCAL_matherror = EVALUATION_ERROR_UNDEFINED;
/* something very bad happened on the way to the forum */
set_fpu_exceptions(FALSE);
Yap_Error(Yap_matherror, TermNil, "");
Yap_Error(LOCAL_matherror , TermNil, "");
}
static void
@ -1472,11 +1471,11 @@ SearchForTrailFault(void)
/* fprintf(stderr,"Catching a sigsegv at %p with %p\n", TR, TrailTop); */
#endif
#if OS_HANDLES_TR_OVERFLOW && !USE_SYSTEM_MALLOC
if ((TR > (tr_fr_ptr)Yap_TrailTop-1024 &&
TR < (tr_fr_ptr)Yap_TrailTop+(64*1024))|| Yap_DBTrailOverflow()) {
if ((TR > (tr_fr_ptr)LOCAL_TrailTop-1024 &&
TR < (tr_fr_ptr)LOCAL_TrailTop+(64*1024))|| Yap_DBTrailOverflow()) {
long trsize = K64;
while ((CELL)TR > (CELL)Yap_TrailTop+trsize) {
while ((CELL)TR > (CELL)LOCAL_TrailTop+trsize) {
trsize += K64;
}
if (!Yap_growtrail(trsize, TRUE)) {
@ -1493,9 +1492,9 @@ SearchForTrailFault(void)
static RETSIGTYPE
HandleSIGSEGV(int sig)
{
if (Yap_PrologMode & ExtendStackMode) {
if (LOCAL_PrologMode & ExtendStackMode) {
CACHE_REGS
Yap_Error(FATAL_ERROR, TermNil, "OS memory allocation crashed at address %p, bailing out\n",Yap_TrailTop);
Yap_Error(FATAL_ERROR, TermNil, "OS memory allocation crashed at address %p, bailing out\n",LOCAL_TrailTop);
}
SearchForTrailFault();
}
@ -1554,71 +1553,71 @@ void (*handler)(int);
static int
InteractSIGINT(int ch) {
CACHE_REGS
Yap_PrologMode |= AsyncIntMode;
LOCAL_PrologMode |= AsyncIntMode;
switch (ch) {
case 'a':
/* abort computation */
if (Yap_PrologMode & (GCMode|ConsoleGetcMode|GrowStackMode|GrowHeapMode)) {
Yap_PrologMode |= AbortMode;
if (LOCAL_PrologMode & (GCMode|ConsoleGetcMode|GrowStackMode|GrowHeapMode)) {
LOCAL_PrologMode |= AbortMode;
} else {
Yap_Error(PURE_ABORT, TermNil, "abort from console");
/* in case someone mangles the P register */
}
Yap_PrologMode &= ~AsyncIntMode;
siglongjmp(Yap_RestartEnv,1);
LOCAL_PrologMode &= ~AsyncIntMode;
siglongjmp(LOCAL_RestartEnv,1);
return -1;
case 'b':
/* continue */
Yap_signal (YAP_BREAK_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
return 1;
case 'c':
/* continue */
return 1;
case 'd':
Yap_signal (YAP_DEBUG_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
/* enter debug mode */
return 1;
case 'e':
/* exit */
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
Yap_exit(0);
return -1;
case 'g':
/* exit */
Yap_signal (YAP_STACK_DUMP_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
return -1;
case 't':
/* start tracing */
Yap_signal (YAP_TRACE_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
return 1;
#ifdef LOW_LEVEL_TRACER
case 'T':
toggle_low_level_trace();
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
return 1;
#endif
case 's':
/* show some statistics */
Yap_signal (YAP_STATISTICS_SIGNAL);
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
return 1;
case EOF:
Yap_PrologMode &= ~AsyncIntMode;
LOCAL_PrologMode &= ~AsyncIntMode;
return(0);
break;
case 'h':
case '?':
default:
/* show an helpful message */
fprintf(Yap_stderr, "Please press one of:\n");
fprintf(Yap_stderr, " a for abort\n c for continue\n d for debug\n");
fprintf(Yap_stderr, " e for exit\n g for stack dump\n s for statistics\n t for trace\n");
fprintf(Yap_stderr, " b for break\n");
Yap_PrologMode &= ~AsyncIntMode;
fprintf(GLOBAL_stderr, "Please press one of:\n");
fprintf(GLOBAL_stderr, " a for abort\n c for continue\n d for debug\n");
fprintf(GLOBAL_stderr, " e for exit\n g for stack dump\n s for statistics\n t for trace\n");
fprintf(GLOBAL_stderr, " b for break\n");
LOCAL_PrologMode &= ~AsyncIntMode;
return(0);
}
}
@ -1666,7 +1665,7 @@ HandleSIGINT (int sig)
my_signal(SIGINT, HandleSIGINT);
/* do this before we act */
#if HAVE_ISATTY
if (!isatty(0) && !Yap_sockets_io) {
if (!isatty(0)) {
Yap_Error(INTERRUPT_ERROR,MkIntTerm(SIGINT),NULL);
return;
}
@ -1674,8 +1673,8 @@ HandleSIGINT (int sig)
if (LOCAL_InterruptsDisabled) {
return;
}
if (Yap_PrologMode & (CritMode|ConsoleGetcMode)) {
Yap_PrologMode |= InterruptMode;
if (LOCAL_PrologMode & (CritMode|ConsoleGetcMode)) {
LOCAL_PrologMode |= InterruptMode;
}
#ifdef HAVE_SETBUF
/* make sure we are not waiting for the end of line */
@ -1777,7 +1776,7 @@ ReceiveSignal (int s)
break;
#endif /* defined(SIGHUP) */
default:
fprintf(Yap_stderr, "\n[ Unexpected signal ]\n");
fprintf(GLOBAL_stderr, "\n[ Unexpected signal ]\n");
exit (EXIT_FAILURE);
}
}
@ -1793,7 +1792,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
Yap_signal(YAP_ALARM_SIGNAL);
Yap_PrologMode |= InterruptMode;
LOCAL_PrologMode |= InterruptMode;
return(TRUE);
default:
return(FALSE);
@ -1805,7 +1804,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
static void
InitSignals (void)
{
if (Yap_PrologShouldHandleInterrupts) {
if (GLOBAL_PrologShouldHandleInterrupts) {
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
my_signal (SIGQUIT, ReceiveSignal);
my_signal (SIGKILL, ReceiveSignal);
@ -1878,7 +1877,7 @@ int Yap_getcwd(const char *buf, int len)
CACHE_REGS
#if __simplescalar__
/* does not implement getcwd */
strncpy(Yap_buf,yap_pwd,len);
strncpy(Yap_buf,GLOBAL_pwd,len);
#elif HAVE_GETCWD
if (getcwd ((char *)buf, len) == NULL) {
#if HAVE_STRERROR
@ -2007,7 +2006,7 @@ TrueFileName (char *source, char *root, char *result, int in_lib)
if ((tmpf = open(ares1, O_RDONLY)) < 0) {
/* not in current directory, let us try the library */
if (Yap_LibDir != NULL) {
strncpy(Yap_FileNameBuf, Yap_LibDir, YAP_FILENAME_MAX);
strncpy(LOCAL_FileNameBuf, Yap_LibDir, YAP_FILENAME_MAX);
#if HAVE_GETENV
} else {
char *yap_env = getenv("YAPLIBDIR");
@ -2105,8 +2104,8 @@ p_true_file_name ( USES_REGS1 )
Yap_Error(TYPE_ERROR_ATOM,t,"argument to true_file_name");
return FALSE;
}
TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, Yap_FileNameBuf, FALSE);
return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)));
TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, NULL, LOCAL_FileNameBuf, FALSE);
return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
}
static Int
@ -2130,8 +2129,8 @@ p_true_file_name3 ( USES_REGS1 )
}
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
}
TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, root, Yap_FileNameBuf, FALSE);
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)));
TrueFileName (RepAtom(AtomOfTerm(t))->StrOfAE, root, LOCAL_FileNameBuf, FALSE);
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
}
/* Executes $SHELL under Prolog */
@ -2239,11 +2238,11 @@ p_system ( USES_REGS1 )
} else if (IsAtomTerm(t1)) {
s = RepAtom(AtomOfTerm(t1))->StrOfAE;
} else {
if (!Yap_GetName (Yap_FileNameBuf, YAP_FILENAME_MAX, t1)) {
if (!Yap_GetName (LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
Yap_Error(TYPE_ERROR_ATOM,t1,"argument to system/1");
return FALSE;
}
s = Yap_FileNameBuf;
s = LOCAL_FileNameBuf;
}
/* Yap_CloseStreams(TRUE); */
#if _MSC_VER
@ -2397,7 +2396,7 @@ static Int p_putenv( USES_REGS1 )
} else s2 = RepAtom(AtomOfTerm(t2))->StrOfAE;
while (!(p0 = p = Yap_AllocAtomSpace(strlen(s)+strlen(s2)+3))) {
if (!Yap_growheap(FALSE, MinHeapGap, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2730,10 +2729,9 @@ Yap_InitSysbits (void)
#if __simplescalar__
{
char *pwd = getenv("PWD");
strncpy(yap_pwd,pwd,YAP_FILENAME_MAX);
strncpy(GLOBAL_pwd,pwd,YAP_FILENAME_MAX);
}
#endif
InitPageSize();
InitWTime ();
InitRandom ();
/* let the caller control signals as it sees fit */

View File

@ -212,17 +212,17 @@ thread_run(void *widp)
do {
t = tgs[0] = Yap_PopTermFromDB(LOCAL_ThreadHandle.tgoal);
if (t == 0) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
thread_die(worker_id, FALSE);
return NULL;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growstack(LOCAL_ThreadHandle.tgoal->NOfCells*CellSize)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
thread_die(worker_id, FALSE);
return NULL;
}
@ -405,7 +405,7 @@ Yap_thread_create_engine(thread_attr *ops)
ops->sysize = 0;
ops->egoal = t;
}
if (pthread_self() != Yap_master_thread) {
if (pthread_self() != GLOBAL_master_thread) {
/* we are worker_id 0 for now, lock master thread so that no one messes with us */
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
pthread_mutex_lock(&(REMOTE_ThreadHandle(0).tlock));
@ -416,7 +416,7 @@ Yap_thread_create_engine(thread_attr *ops)
REMOTE_ThreadHandle(new_id).id = new_id;
REMOTE_ThreadHandle(new_id).ref_count = 0;
setup_engine(new_id, FALSE);
if (pthread_self() != Yap_master_thread) {
if (pthread_self() != GLOBAL_master_thread) {
pthread_setspecific(Yap_yaamregs_key, NULL);
pthread_mutex_unlock(&(REMOTE_ThreadHandle(0).tlock));
}
@ -773,17 +773,17 @@ p_thread_atexit( USES_REGS1 )
t = Yap_PopTermFromDB(LOCAL_ThreadHandle.texit);
LOCAL_ThreadHandle.texit = NULL;
if (t == 0) {
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, LOCAL_ErrorMessage);
thread_die(worker_id, FALSE);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growstack(LOCAL_ThreadHandle.tgoal->NOfCells*CellSize)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
thread_die(worker_id, FALSE);
return FALSE;
}

View File

@ -28,12 +28,12 @@
STATIC_PROTO(int TracePutchar, (int, int));
STATIC_PROTO(void send_tracer_message, (char *, char *, Int, char *, CELL *));
static int do_trace_primitives = TRUE;
static int
TracePutchar(int sno, int ch)
{
return(putc(ch, Yap_stderr)); /* use standard error stream, which is supposed to be 2*/
return(putc(ch, GLOBAL_stderr)); /* use standard error stream, which is supposed to be 2*/
}
static void
@ -42,24 +42,24 @@ send_tracer_message(char *start, char *name, Int arity, char *mname, CELL *args)
CACHE_REGS
if (name == NULL) {
#ifdef YAPOR
fprintf(Yap_stderr, "(%d)%s", worker_id, start);
fprintf(GLOBAL_stderr, "(%d)%s", worker_id, start);
#else
fprintf(Yap_stderr, "%s", start);
fprintf(GLOBAL_stderr, "%s", start);
#endif
} else {
int i;
if (arity) {
if (args)
fprintf(Yap_stderr, "%s %s:%s(", start, mname, name);
fprintf(GLOBAL_stderr, "%s %s:%s(", start, mname, name);
else
fprintf(Yap_stderr, "%s %s:%s/%lu", start, mname, name, (unsigned long int)arity);
fprintf(GLOBAL_stderr, "%s %s:%s/%lu", start, mname, name, (unsigned long int)arity);
} else {
fprintf(Yap_stderr, "%s %s:%s", start, mname, name);
fprintf(GLOBAL_stderr, "%s %s:%s", start, mname, name);
}
if (args) {
for (i= 0; i < arity; i++) {
if (i > 0) fprintf(Yap_stderr, ",");
if (i > 0) fprintf(GLOBAL_stderr, ",");
#if DEBUG
#if COROUTINING
Yap_Portray_delays = TRUE;
@ -73,11 +73,11 @@ send_tracer_message(char *start, char *name, Int arity, char *mname, CELL *args)
#endif
}
if (arity) {
fprintf(Yap_stderr, ")");
fprintf(GLOBAL_stderr, ")");
}
}
}
fprintf(Yap_stderr, "\n");
fprintf(GLOBAL_stderr, "\n");
}
#if defined(__GNUC__)
@ -94,7 +94,7 @@ static int thread_trace;
static int
check_trail_consistency(void) {
tr_fr_ptr ptr = TR;
while (ptr > (CELL *)Yap_TrailBase) {
while (ptr > (CELL *)LOCAL_TrailBase) {
ptr = --ptr;
if (!IsVarTerm(TrailTerm(ptr))) {
if (IsApplTerm(TrailTerm(ptr))) {
@ -186,7 +186,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
} else
return;
{
tr_fr_ptr pt = (tr_fr_ptr)Yap_TrailBase;
tr_fr_ptr pt = (tr_fr_ptr)LOCAL_TrailBase;
if (pt[140].term == 0 && pt[140].value != 0)
jmp_deb(1);
}
@ -235,7 +235,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
if (TR_FZ > TR)
jmp_deb(1);
{
tr_fr_ptr pt = (tr_fr_ptr)Yap_TrailBase;
tr_fr_ptr pt = (tr_fr_ptr)LOCAL_TrailBase;
if (pt[153].term == 0 && pt[153].value == 0 &&
pt[154].term != 0 && pt[154].value != 0 && ( TR > pt+154 ||
TR_FZ > pt+154))
@ -293,16 +293,16 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
printf("\n");
}
#endif
fprintf(Yap_stderr,"%lld ",vsc_count);
fprintf(GLOBAL_stderr,"%lld ",vsc_count);
#if defined(THREADS) || defined(YAPOR)
fprintf(Yap_stderr,"(%d)", worker_id);
fprintf(GLOBAL_stderr,"(%d)", worker_id);
#endif
/* check_trail_consistency(); */
if (pred == NULL) {
UNLOCK(Yap_heap_regs->low_level_trace_lock);
return;
}
if (pred->ModuleOfPred == 0 && !do_trace_primitives) {
if (pred->ModuleOfPred == 0 && !LOCAL_do_trace_primitives) {
UNLOCK(Yap_heap_regs->low_level_trace_lock);
return;
}
@ -425,7 +425,7 @@ static Int p_start_low_level_trace2( USES_REGS1 )
static Int p_stop_low_level_trace( USES_REGS1 )
{
Yap_do_low_level_trace = FALSE;
do_trace_primitives = TRUE;
LOCAL_do_trace_primitives = TRUE;
return(TRUE);
}

View File

@ -244,7 +244,7 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
CELL new;
bp = to_visit;
if (!attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf PASS_REGS)) {
if (!GLOBAL_attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf PASS_REGS)) {
goto overflow;
}
to_visit = bp;
@ -255,7 +255,7 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
#endif
/* first time we met this term */
RESET_VARIABLE(ptf);
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
/* Trail overflow */
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
@ -355,7 +355,7 @@ trail_overflow:
}
#endif
reset_trail(TR0);
Yap_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
return -3;
}
@ -368,7 +368,7 @@ handle_cp_overflow(int res, tr_fr_ptr TR0, UInt arity, Term t)
switch(res) {
case -1:
if (!Yap_gcl((ASP-H)*sizeof(CELL), arity+1, ENV, gc_P(P,CP))) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
return Deref(XREGS[arity+1]);
@ -376,19 +376,19 @@ handle_cp_overflow(int res, tr_fr_ptr TR0, UInt arity, Term t)
return Deref(XREGS[arity+1]);
case -3:
{
UInt size = Yap_Error_Size;
Yap_Error_Size = 0L;
UInt size = LOCAL_Error_Size;
LOCAL_Error_Size = 0L;
if (size > 4*1024*1024)
size = 4*1024*1024;
if (!Yap_ExpandPreAllocCodeSpace(size, NULL, TRUE)) {
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
return Deref(XREGS[arity+1]);
case -4:
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), FALSE)) {
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
return Deref(XREGS[arity+1]);
@ -751,7 +751,7 @@ break_rationals_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow USE
}
#endif
reset_trail(TR0);
Yap_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
return -3;
}
@ -1066,7 +1066,7 @@ restore_rationals_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow,
}
#endif
reset_trail(TR0);
Yap_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
return -3;
}
@ -1400,7 +1400,7 @@ export_complex_term(Term tf, CELL *pt0, CELL *pt0_end, char * buf, size_t len0,
CELL new;
bp = to_visit;
if (!attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf PASS_REGS)) {
if (!GLOBAL_attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf PASS_REGS)) {
goto overflow;
}
to_visit = bp;
@ -1411,7 +1411,7 @@ export_complex_term(Term tf, CELL *pt0, CELL *pt0_end, char * buf, size_t len0,
#endif
/* first time we met this term */
*ptf = (CELL)CellDifH(ptf,HLow);
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
/* Trail overflow */
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
@ -1501,7 +1501,7 @@ trail_overflow:
}
#endif
reset_trail(TR0);
Yap_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
return -3;
}
@ -1749,7 +1749,7 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Ter
H += 2;
H[-2] = (CELL)ptd0;
/* next make sure noone will see this as a variable again */
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
/* Trail overflow */
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
@ -1796,15 +1796,15 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Ter
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
Yap_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
return 0L;
aux_overflow:
Yap_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
LOCAL_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) {
to_visit -= 3;
@ -1812,7 +1812,7 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Ter
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
@ -1829,8 +1829,8 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Ter
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Size = (ASP-H)*sizeof(CELL);
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = (ASP-H)*sizeof(CELL);
return 0L;
}
@ -1838,11 +1838,11 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Ter
static int
expand_vts( USES_REGS1 )
{
UInt expand = Yap_Error_Size;
yap_error_number yap_errno = Yap_Error_TYPE;
UInt expand = LOCAL_Error_Size;
yap_error_number yap_errno = LOCAL_Error_TYPE;
Yap_Error_Size = 0;
Yap_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_Size = 0;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (yap_errno == OUT_OF_TRAIL_ERROR) {
/* Trail overflow */
if (!Yap_growtrail(expand, FALSE)) {
@ -1881,7 +1881,7 @@ p_variables_in_term( USES_REGS1 ) /* variables in term t */
*ptr = TermFoundVar;
TrailTerm(TR++) = t;
count++;
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
clean_tr(TR-count PASS_REGS);
if (!Yap_growtrail(count*sizeof(tr_fr_ptr *), FALSE)) {
return FALSE;
@ -2032,7 +2032,7 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
/* do or pt2 are unbound */
*ptd0 = TermNil;
/* next make sure noone will see this as a variable again */
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
/* Trail overflow */
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
@ -2106,15 +2106,15 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
Yap_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
return 0L;
aux_overflow:
Yap_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
LOCAL_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) {
to_visit -= 3;
@ -2122,7 +2122,7 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
@ -2139,8 +2139,8 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Size = (ASP-H)*sizeof(CELL);
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = (ASP-H)*sizeof(CELL);
return 0L;
}
@ -2225,7 +2225,7 @@ static Term vars_within_complex_term(register CELL *pt0, register CELL *pt0_end,
CELL *ptr = VarOfTerm(t);
*ptr = TermFoundVar;
TrailTerm(TR++) = t;
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
}
@ -2338,15 +2338,15 @@ static Term vars_within_complex_term(register CELL *pt0, register CELL *pt0_end,
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
Yap_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
return 0L;
aux_overflow:
Yap_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
LOCAL_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) {
to_visit -= 3;
@ -2354,7 +2354,7 @@ static Term vars_within_complex_term(register CELL *pt0, register CELL *pt0_end,
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
@ -2371,8 +2371,8 @@ static Term vars_within_complex_term(register CELL *pt0, register CELL *pt0_end,
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Size = (ASP-H)*sizeof(CELL);
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = (ASP-H)*sizeof(CELL);
return 0L;
}
@ -2422,7 +2422,7 @@ static Term new_vars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
CELL *ptr = VarOfTerm(t);
*ptr = TermFoundVar;
TrailTerm(TR++) = t;
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
}
@ -2503,7 +2503,7 @@ static Term new_vars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
H += 2;
H[-2] = (CELL)ptd0;
/* next make sure noone will see this as a variable again */
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
/* Trail overflow */
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
goto trail_overflow;
@ -2543,15 +2543,15 @@ static Term new_vars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_TRAIL_ERROR;
Yap_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
LOCAL_Error_TYPE = OUT_OF_TRAIL_ERROR;
LOCAL_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
return 0L;
aux_overflow:
Yap_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
LOCAL_Error_Size = (to_visit-to_visit0)*sizeof(CELL **);
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) {
to_visit -= 3;
@ -2559,7 +2559,7 @@ static Term new_vars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
*pt0 = (CELL)to_visit[2];
}
#endif
Yap_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
@ -2576,8 +2576,8 @@ static Term new_vars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
H = InitialH;
Yap_Error_TYPE = OUT_OF_STACK_ERROR;
Yap_Error_Size = (ASP-H)*sizeof(CELL);
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
LOCAL_Error_Size = (ASP-H)*sizeof(CELL);
return 0L;
}

View File

@ -149,7 +149,7 @@ ensure_space(size_t sz) {
}
if (!s) {
s = (char *)TR;
while (s+sz >= Yap_TrailTop) {
while (s+sz >= LOCAL_TrailTop) {
if (!Yap_growtrail(sz/sizeof(CELL), FALSE)) {
s = NULL;
break;

View File

@ -208,7 +208,6 @@ extern REGSTORE Yap_REGS;
#define MinTrailGap (sizeof(CELL)*1024)
#define MinHeapGap (sizeof(CELL)*4096)
#define MinStackGap (sizeof(CELL)*8*1024)
extern int Yap_stack_overflows;
#define ENV Yap_REGS.ENV_ /* current environment */

28
H/ScannerTypes.h Normal file
View File

@ -0,0 +1,28 @@
typedef enum TokenKinds {
Name_tok,
Number_tok,
Var_tok,
String_tok,
WString_tok,
Ponctuation_tok,
Error_tok,
eot_tok
} tkinds;
typedef struct TOKEN {
enum TokenKinds Tok;
Term TokInfo;
int TokPos;
struct TOKEN *TokNext;
} TokEntry;
#define Ord(X) ((enum TokenKinds) (X))
#define NextToken GNextToken( PASS_REGS1 )
typedef struct VARSTRUCT {
Term VarAdr;
CELL hv;
struct VARSTRUCT *VarLeft, *VarRight;
char VarRep[1];
} VarEntry;

View File

@ -136,8 +136,7 @@ typedef enum
exts;
/* array with the ops for your favourite extensions */
extern ext_op attas[attvars_ext + 1];
#endif

718
H/Yap.h
View File

@ -45,11 +45,8 @@
/*
#define RATIONAL_TREES 1
#define DEPTH_LIMIT 1
#define COROUTINING 1
#define ANALYST 1
*/
@ -73,52 +70,47 @@
#define USE_SYSTEM_MALLOC 1
#endif /* THREADS || SUPPORT_CONDOR */
#ifdef ANALYST
#ifdef USE_THREADED_CODE
#if defined(ANALYST) && defined(USE_THREADED_CODE)
#undef USE_THREADED_CODE
#endif
#endif
#endif /* ANALYST && USE_THREADED_CODE */
#ifdef COROUTINING
#ifndef TERM_EXTENSIONS
#if defined(COROUTINING) && !defined(TERM_EXTENSIONS)
#define TERM_EXTENSIONS 1
#endif
#endif
#endif /* COROUTINING && !TERM_EXTENSIONS */
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
/* adjust a config.h from mingw32 to work with vc++ */
/* Microsoft's Visual C++ Compiler */
#ifdef _MSC_VER /* adjust a config.h from mingw32 to work with vc++ */
#ifdef HAVE_GCC
#undef HAVE_GCC
#endif
#undef HAVE_GCC
#endif /* HAVE_GCC */
#ifdef USE_THREADED_CODE
#undef USE_THREADED_CODE
#endif
#endif /* USE_THREADED_CODE */
#define inline __inline
#define YAP_VERSION "YAP-6.3.0"
#define BIN_DIR "c:\\Yap\\bin"
#define LIB_DIR "c:\\Yap\\lib\\Yap"
#define SHARE_DIR "c:\\Yap\\share\\Yap"
#ifdef HOST_ALIAS
#undef HOST_ALIAS
#endif
#ifdef HOST_ALIAS
#undef HOST_ALIAS
#endif /* HOST_ALIAS */
#define HOST_ALIAS "i386-pc-win32"
#ifdef HAVE_IEEEFP_H
#undef HAVE_IEEEFP_H
#endif
#ifdef HAVE_UNISTD_H
#undef HAVE_UNISTD_H
#endif
#ifdef HAVE_SYS_TIME_H
#undef HAVE_SYS_TIME_H
#endif
#endif
#ifdef HAVE_IEEEFP_H
#undef HAVE_IEEEFP_H
#endif /* HAVE_IEEEFP_H */
#ifdef HAVE_UNISTD_H
#undef HAVE_UNISTD_H
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_TIME_H
#undef HAVE_SYS_TIME_H
#endif /* HAVE_SYS_TIME_H */
#endif /* _MSC_VER */
#ifdef __MINGW32__
#ifndef _WIN32
#define _WIN32 1
#endif
#endif
#endif /* _WIN32 */
#endif /* __MINGW32__ */
#if HAVE_GCC
#define MIN_ARRAY 0
@ -126,35 +118,36 @@
#else
#define MIN_ARRAY 1
#define DUMMY_FILLER_FOR_ABS_TYPE int dummy;
#endif
#endif /* HAVE_GCC */
#ifndef ADTDEFS_C
#define EXTERN static
#else
#define EXTERN
#endif
#endif /* ADTDEFS_C */
/* truth-values */
/* truth-values */
#define TRUE 1
#define FALSE 0
/* null pointer */
/* null pointer */
#define NIL 0
/* Basic types */
/* defines integer types Int and UInt (unsigned) with the same size as a ptr
** and integer types Short and UShort with half the size of a ptr
*/
** and integer types Short and UShort with half the size of a ptr */
#ifdef THREADS
#if USE_PTHREAD_LOCKING
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#endif
#endif /* !_XOPEN_SOURCE */
#endif /* USE_PTHREAD_LOCKING */
#include <pthread.h>
#endif
#endif /* THREADS */
#if SIZEOF_INT_P==4
@ -173,7 +166,7 @@
#define UInt_FORMAT "%lu"
#else
# error Yap require integer types of the same size as a pointer
#error Yap require integer types of the same size as a pointer
#endif
#if SIZEOF_SHORT_INT==2
@ -249,16 +242,13 @@ typedef unsigned long int YAP_ULONG_LONG;
#define LOW_PROF 1
#endif
#ifdef DEBUG
extern char Yap_Option[20];
#endif
/* #define FORCE_SECOND_QUADRANT 1 */
#if defined(FORCE_SECOND_QUADRANT)
#define IN_SECOND_QUADRANT 1
#define MMAP_ADDR 0x42000000
#endif
#endif /* FORCE_SECOND_QUADRANT */
#if !defined(IN_SECOND_QUADRANT)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(mips) || defined(__APPLE__) || defined(__DragonFly__)
@ -276,10 +266,10 @@ extern char Yap_Option[20];
#define MMAP_ADDR 0x20000000
#else
#define MMAP_ADDR 0x10000000
#endif
#endif /* YAPOR && __alpha */
#elif __svr4__ || defined(__SVR4)
#define MMAP_ADDR 0x02000000
#endif
#endif /* __linux__ || __FreeBSD__ || __NetBSD__ || mips || __APPLE__ || __DragonFly__ */
#endif /* !IN_SECOND_QUADRANT */
/* #define RANDOMIZE_START_ADDRESS 1 */
@ -287,15 +277,15 @@ extern char Yap_Option[20];
#ifdef USE_SYSTEM_MALLOC
#define HEAP_INIT_BASE 0L
#define AtomBase NULL
#else
#else /* !USE_SYSTEM_MALLOC */
#if defined(MMAP_ADDR) && (defined(USE_MMAP) || USE_SHMAT) && !defined(__simplescalar__) && !defined(RANDOMIZE_START_ADDRESS)
#define HEAP_INIT_BASE (MMAP_ADDR)
#define AtomBase ((char *)MMAP_ADDR)
#else
#else /*! (MMAP_ADDR && (USE_MMAP || USE_SHMAT) && !__simplescalar__ && !RANDOMIZE_START_ADDRESS) */
#define HEAP_INIT_BASE ((CELL)Yap_HeapBase)
#define AtomBase (Yap_HeapBase)
#endif
#endif
#endif /* MMAP_ADDR && (USE_MMAP || USE_SHMAT) && !__simplescalar__ && !RANDOMIZE_START_ADDRESS */
#endif /* USE_SYSTEM_MALLOC */
@ -315,7 +305,9 @@ extern char Yap_Option[20];
#define M1 ((CELL)(1024*1024))
#define M2 ((CELL)(2048*1024))
/* basic data types */
/*************************************************************************************************
basic data types
*************************************************************************************************/
typedef UInt CELL;
typedef UShort BITS16;
@ -336,7 +328,9 @@ typedef unsigned char *CODEADDR;
#define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN)
/* type casting macros */
/*************************************************************************************************
type casting macros
*************************************************************************************************/
#define Addr(V) ((ADDR) (V))
#define Unsigned(V) ((CELL) (V))
@ -351,7 +345,9 @@ typedef unsigned char *CODEADDR;
#define DisplPtr(V) ((DISPREG *)(V))
#define TermPtr(V) ((Term *) (V))
/* Abstract Type Definitions for YAPProlog */
/*************************************************************************************************
Abstract Type Definitions for YAPProlog
*************************************************************************************************/
typedef CELL Term;
@ -390,7 +386,9 @@ typedef pthread_rwlock_t rwlock_t;
#include <locks_pthread.h>
#endif
/********************** use an auxiliary function for ranges ************/
/*************************************************************************************************
use an auxiliary function for ranges
*************************************************************************************************/
#ifdef __GNUC__
#define IN_BETWEEN(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) <= \
@ -404,19 +402,25 @@ typedef pthread_rwlock_t rwlock_t;
#define OUTSIDE(MIN,X,MAX) ((void *)(X) < (void *)(MIN) || (void *)(X) > (void *)(MAX))
#endif
/* ************************* Atoms *************************************/
/*************************************************************************************************
Atoms
*************************************************************************************************/
#include "Atoms.h"
/* ************************* Coroutining **********************************/
/*************************************************************************************************
Coroutining
*************************************************************************************************/
#ifdef COROUTINING
/* Support for co-routining */
#include "corout.h"
#endif
/********* abstract machine registers **********************************/
/*************************************************************************************************
abstract machine registers
*************************************************************************************************/
#include "amidefs.h"
@ -431,7 +435,9 @@ typedef pthread_rwlock_t rwlock_t;
#endif
#endif
/************ variables concerned with Error Handling *************/
/*************************************************************************************************
variables concerned with Error Handling
*************************************************************************************************/
#include <setjmp.h>
@ -444,7 +450,6 @@ typedef pthread_rwlock_t rwlock_t;
/* Support for arrays */
#include "arrays.h"
/************ variables concerned with Error Handling *************/
/* Types of Errors */
typedef enum
@ -622,7 +627,9 @@ typedef enum
#define NUMBER_OF_YAP_FLAGS LAST_FLAG
/************************ prototypes **********************************/
/*************************************************************************************************
prototypes
*************************************************************************************************/
#include "Yapproto.h"
@ -740,7 +747,9 @@ typedef enum
#define TermSize sizeof(Term)
/************* variables related to memory allocation *******************/
/*************************************************************************************************
variables related to memory allocation
*************************************************************************************************/
/* must be before TermExt.h */
extern ADDR Yap_HeapBase;
@ -750,71 +759,17 @@ extern ADDR Yap_HeapBase;
#define MAX_ERROR_MSG_SIZE YAP_FILENAME_MAX
#ifdef THREADS
typedef struct thread_globs
{
ADDR local_base;
ADDR global_base;
ADDR trail_base;
ADDR trail_top;
char *error_message;
Term error_term;
Term error_type;
UInt error_size;
char error_say[MAX_ERROR_MSG_SIZE];
jmp_buf io_botch;
sigjmp_buf restart_env;
struct TOKEN *tokptr;
struct TOKEN *toktide;
struct VARSTRUCT *var_table;
struct VARSTRUCT *anon_var_table;
int eot_before_eof;
char file_name_buf[YAP_FILENAME_MAX];
char file_name_buf2[YAP_FILENAME_MAX];
} tglobs;
extern struct thread_globs Yap_thread_gl[MAX_THREADS];
#define Yap_LocalBase Yap_thread_gl[worker_id].local_base
#define Yap_GlobalBase Yap_thread_gl[worker_id].global_base
#define Yap_TrailBase Yap_thread_gl[worker_id].trail_base
#define Yap_TrailTop Yap_thread_gl[worker_id].trail_top
#define Yap_ErrorMessage Yap_thread_gl[worker_id].error_message
#define Yap_Error_Term Yap_thread_gl[worker_id].error_term
#define Yap_Error_TYPE Yap_thread_gl[worker_id].error_type
#define Yap_Error_Size Yap_thread_gl[worker_id].error_size
#define Yap_ErrorSay Yap_thread_gl[worker_id].error_say
#define Yap_RestartEnv Yap_thread_gl[worker_id].restart_env
/* This is the guy who actually started the system, and who has the correct registers */
extern pthread_t Yap_master_thread;
#else
extern ADDR Yap_HeapBase,
Yap_LocalBase, Yap_GlobalBase, Yap_TrailBase, Yap_TrailTop;
extern sigjmp_buf Yap_RestartEnv; /* used to restart after an abort */
extern char *Yap_ErrorMessage; /* used to pass error messages */
extern Term Yap_Error_Term; /* used to pass error terms */
extern yap_error_number Yap_Error_TYPE; /* used to pass the error */
extern UInt Yap_Error_Size; /* used to pass the error */
/******************* storing error messages ****************************/
extern char Yap_ErrorSay[MAX_ERROR_MSG_SIZE];
#endif
#ifdef DEBUG
/************** Debugging Support ***************************/
extern int Yap_output_msg;
#endif
/*************************************************************************************************
???
*************************************************************************************************/
#define MkVarTerm() MkVarTerm__( PASS_REGS1 )
#define MkPairTerm(A,B) MkPairTerm__( A, B PASS_REGS )
/* applies to unbound variables */
/*************************************************************************************************
applies to unbound variables
*************************************************************************************************/
inline EXTERN Term *VarOfTerm (Term t);
@ -1058,18 +1013,317 @@ IntegerOfTerm (Term t)
/*************************************************************************************************
variables concerned with atoms table
*************************************************************************************************/
/*************** unification routines ***********************************/
#define MaxHash 3333
#define MaxWideHash (MaxHash/10+1)
#define FAIL_RESTORE 0
#define DO_EVERYTHING 1
#define DO_ONLY_CODE 2
/*************************************************************************************************
common instructions codes
*************************************************************************************************/
#define MAX_PROMPT 256
#if USE_THREADED_CODE
/*************************************************************************************************
reverse lookup of instructions
*************************************************************************************************/
typedef struct opcode_tab_entry
{
OPCODE opc;
op_numbers opnum;
} opentry;
#endif
/*************************************************************************************************
Prolog may be in several modes
*************************************************************************************************/
typedef enum
{
BootMode = 0x1, /* if booting or restoring */
UserMode = 0x2, /* Normal mode */
CritMode = 0x4, /* If we are meddling with the heap */
AbortMode = 0x8, /* expecting to abort */
InterruptMode = 0x10, /* under an interrupt */
InErrorMode = 0x20, /* under an interrupt */
ConsoleGetcMode = 0x40, /* blocked reading from console */
ExtendStackMode = 0x80, /* trying to extend stack */
GrowHeapMode = 0x100, /* extending Heap */
GrowStackMode = 0x200, /* extending Stack */
GCMode = 0x400, /* doing Garbage Collecting */
ErrorHandlingMode = 0x800, /* doing error handling */
CCallMode = 0x1000, /* In c Call */
UnifyMode = 0x2000, /* In Unify Code */
UserCCallMode = 0x4000, /* In User C-call Code */
MallocMode = 0x8000, /* Doing malloc, realloc, free */
SystemMode = 0x10000, /* in system mode */
AsyncIntMode = 0x20000, /* YAP has just been interrupted from the outside */
InReadlineMode = 0x40000 /* YAP has just been interrupted from the outside */
} prolog_exec_mode;
/*************************************************************************************************
number of modules
*************************************************************************************************/
#define DefaultMaxModules 256
/*************************************************************************************************
Critical sections
*************************************************************************************************/
#ifdef YAPOR
#define YAPEnterCriticalSection() \
{ \
if (worker_id != GLOBAL_locks_who_locked_heap) { \
LOCK(GLOBAL_locks_heap_access); \
GLOBAL_locks_who_locked_heap = worker_id; \
} \
LOCAL_PrologMode |= CritMode; \
LOCAL_CritLocks++; \
}
#define YAPLeaveCriticalSection() \
{ \
LOCAL_CritLocks--; \
if (!LOCAL_CritLocks) { \
LOCAL_PrologMode &= ~CritMode; \
if (LOCAL_PrologMode & InterruptMode) { \
LOCAL_PrologMode &= ~InterruptMode; \
Yap_ProcessSIGINT(); \
} \
if (LOCAL_PrologMode & AbortMode) { \
LOCAL_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
GLOBAL_locks_who_locked_heap = MAX_WORKERS; \
UNLOCK(GLOBAL_locks_heap_access); \
} \
}
#elif defined(THREADS)
#define YAPEnterCriticalSection() \
{ \
/* LOCK(BGL); */ \
LOCAL_PrologMode |= CritMode; \
}
#define YAPLeaveCriticalSection() \
{ \
LOCAL_PrologMode &= ~CritMode; \
if (LOCAL_PrologMode & InterruptMode) { \
LOCAL_PrologMode &= ~InterruptMode; \
Yap_ProcessSIGINT(); \
} \
if (LOCAL_PrologMode & AbortMode) { \
LOCAL_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
/* UNLOCK(BGL); */ \
}
#else
#define YAPEnterCriticalSection() \
{ \
LOCAL_PrologMode |= CritMode; \
LOCAL_CritLocks++; \
}
#define YAPLeaveCriticalSection() \
{ \
LOCAL_CritLocks--; \
if (!LOCAL_CritLocks) { \
LOCAL_PrologMode &= ~CritMode; \
if (LOCAL_PrologMode & InterruptMode) { \
LOCAL_PrologMode &= ~InterruptMode; \
Yap_ProcessSIGINT(); \
} \
if (LOCAL_PrologMode & AbortMode) { \
LOCAL_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
} \
}
#endif /* YAPOR */
/* when we are calling the InitStaff procedures */
#define AT_BOOT 0
#define AT_RESTORE 1
/*************************************************************************************************
mutable variables
*************************************************************************************************/
/* I assume that the size of this structure is a multiple of the size
of CELL!!! */
typedef struct TIMED_MAVAR
{
CELL value;
CELL clock;
} timed_var;
/*************************************************************************************************
execution mode
*************************************************************************************************/
typedef enum
{
INTERPRETED, /* interpreted */
MIXED_MODE_USER, /* mixed mode only for user predicates */
MIXED_MODE_ALL, /* mixed mode for all predicates */
COMPILE_USER, /* compile all user predicates*/
COMPILE_ALL /* compile all predicates */
} yap_exec_mode;
/*************************************************************************************************
slots
*************************************************************************************************/
static inline void
Yap_StartSlots( USES_REGS1 ) {
*--ASP = MkIntegerTerm(CurSlot);
*--ASP = MkIntTerm(0);
CurSlot = LCL0-ASP;
}
static inline void
Yap_CloseSlots( USES_REGS1 ) {
Int old_slots;
old_slots = IntOfTerm(ASP[0]);
ASP += (old_slots+1);
CurSlot = IntOfTerm(*ASP);
ASP++;
}
static inline Int
Yap_CurrentSlot( USES_REGS1 ) {
return IntOfTerm(ASP[0]);
}
/************************/
#ifdef THREADS
typedef struct thandle {
int in_use;
int zombie;
UInt ssize;
UInt tsize;
UInt sysize;
void *stack_address;
Term tdetach;
Term cmod, texit_mod;
struct DB_TERM *tgoal, *texit;
int id;
int ret;
REGSTORE *default_yaam_regs;
REGSTORE *current_yaam_regs;
struct pred_entry *local_preds;
pthread_t pthread_handle;
int ref_count;
#ifdef LOW_LEVEL_TRACER
long long int thread_inst_count;
int been_here1;
int been_here2;
#endif
#ifdef DEBUG
int been_here;
#endif
pthread_mutex_t tlock;
pthread_mutex_t tlock_status;
#if HAVE_GETRUSAGE||defined(_WIN32)
struct timeval *start_of_timesp;
struct timeval *last_timep;
#endif
} yap_thandle;
#endif /* THREADS */
#define GC_MAVARS_HASH_SIZE 512
typedef struct gc_ma_hash_entry_struct {
UInt timestmp;
#ifdef TABLING
tr_fr_ptr loc;
struct gc_ma_hash_entry_struct *more;
#endif
CELL* addr;
struct gc_ma_hash_entry_struct *next;
} gc_ma_hash_entry;
typedef int (*Agc_hook)(Atom);
typedef struct scratch_block_struct {
char *ptr;
UInt sz, msz;
} scratch_block;
/* scanner types */
#include "ScannerTypes.h"
/*************************************************************************************************
OPTYAP includes
*************************************************************************************************/
#if defined(YAPOR) || defined(TABLING)
#include "opt.structs.h"
#include "opt.proto.h"
#include "opt.macros.h"
#endif /* YAPOR || TABLING */
/*************************************************************************************************
GLOBAL and LOCAL variables
*************************************************************************************************/
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
extern struct global_data *Yap_global;
extern long Yap_worker_area_size;
#else
extern struct global_data Yap_Global;
#define Yap_global (&Yap_Global)
#endif
#if defined(THREADS)
extern struct worker_local *Yap_local[MAX_THREADS];
#define REMOTE(wid) (Yap_local[wid])
#elif defined(YAPOR)
extern struct worker_local *Yap_local;
#define REMOTE(wid) (Yap_local + wid)
#else /* !THREADS && !YAPOR */
extern struct worker_local Yap_local;
#define REMOTE(wid) (&Yap_local)
#endif
#define YP_FILE FILE
#include "hglobals.h"
#include "dglobals.h"
#include "hlocals.h"
#include "dlocals.h"
/*************************************************************************************************
unification routines
*************************************************************************************************/
#ifdef YAPOR_SBA
#include "or.sba_amiops.h"
#include "or.sba_unify.h"
#else
#include "amiops.h"
#endif
#endif /* YAPOR_SBA */
/*************** High level macros to access arguments ******************/
/*************************************************************************************************
High level macros to access arguments
*************************************************************************************************/
inline EXTERN Term ArgOfTerm (int i, Term t);
inline EXTERN Term
@ -1129,214 +1383,4 @@ TailOfTermCell (Term t)
return (Term) ((CELL) (RepPair (t) + 1));
}
/*************** variables concerned with atoms table *******************/
#define MaxHash 3333
#define MaxWideHash (MaxHash/10+1)
#define FAIL_RESTORE 0
#define DO_EVERYTHING 1
#define DO_ONLY_CODE 2
#ifdef EMACS
/******************** using Emacs mode ********************************/
extern int emacs_mode;
#endif
/********* common instructions codes*************************/
#define MAX_PROMPT 256
#if USE_THREADED_CODE
/************ reverse lookup of instructions *****************/
typedef struct opcode_tab_entry
{
OPCODE opc;
op_numbers opnum;
} opentry;
#endif
/********* Prolog may be in several modes *******************************/
typedef enum
{
BootMode = 0x1, /* if booting or restoring */
UserMode = 0x2, /* Normal mode */
CritMode = 0x4, /* If we are meddling with the heap */
AbortMode = 0x8, /* expecting to abort */
InterruptMode = 0x10, /* under an interrupt */
InErrorMode = 0x20, /* under an interrupt */
ConsoleGetcMode = 0x40, /* blocked reading from console */
ExtendStackMode = 0x80, /* trying to extend stack */
GrowHeapMode = 0x100, /* extending Heap */
GrowStackMode = 0x200, /* extending Stack */
GCMode = 0x400, /* doing Garbage Collecting */
ErrorHandlingMode = 0x800, /* doing error handling */
CCallMode = 0x1000, /* In c Call */
UnifyMode = 0x2000, /* In Unify Code */
UserCCallMode = 0x4000, /* In User C-call Code */
MallocMode = 0x8000, /* Doing malloc, realloc, free */
SystemMode = 0x10000, /* in system mode */
AsyncIntMode = 0x20000, /* YAP has just been interrupted from the outside */
InReadlineMode = 0x40000 /* YAP has just been interrupted from the outside */
} prolog_exec_mode;
extern Int Yap_PrologMode;
extern int Yap_CritLocks;
/************** Access to yap initial arguments ***************************/
extern char **Yap_argv;
extern int Yap_argc;
/******** whether Yap is responsible for signal handling ******************/
extern int Yap_PrologShouldHandleInterrupts;
/******************* number of modules ****************************/
#define DefaultMaxModules 256
#ifdef YAPOR
#define YAPEnterCriticalSection() \
{ \
if (worker_id != GLOBAL_locks_who_locked_heap) { \
LOCK(GLOBAL_locks_heap_access); \
GLOBAL_locks_who_locked_heap = worker_id; \
} \
Yap_PrologMode |= CritMode; \
Yap_CritLocks++; \
}
#define YAPLeaveCriticalSection() \
{ \
Yap_CritLocks--; \
if (!Yap_CritLocks) { \
Yap_PrologMode &= ~CritMode; \
if (Yap_PrologMode & InterruptMode) { \
Yap_PrologMode &= ~InterruptMode; \
Yap_ProcessSIGINT(); \
} \
if (Yap_PrologMode & AbortMode) { \
Yap_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
GLOBAL_locks_who_locked_heap = MAX_WORKERS; \
UNLOCK(GLOBAL_locks_heap_access); \
} \
}
#elif defined(THREADS)
#define YAPEnterCriticalSection() \
{ \
/* LOCK(BGL); */ \
Yap_PrologMode |= CritMode; \
}
#define YAPLeaveCriticalSection() \
{ \
Yap_PrologMode &= ~CritMode; \
if (Yap_PrologMode & InterruptMode) { \
Yap_PrologMode &= ~InterruptMode; \
Yap_ProcessSIGINT(); \
} \
if (Yap_PrologMode & AbortMode) { \
Yap_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
/* UNLOCK(BGL); */ \
}
#else
#define YAPEnterCriticalSection() \
{ \
Yap_PrologMode |= CritMode; \
Yap_CritLocks++; \
}
#define YAPLeaveCriticalSection() \
{ \
Yap_CritLocks--; \
if (!Yap_CritLocks) { \
Yap_PrologMode &= ~CritMode; \
if (Yap_PrologMode & InterruptMode) { \
Yap_PrologMode &= ~InterruptMode; \
Yap_ProcessSIGINT(); \
} \
if (Yap_PrologMode & AbortMode) { \
Yap_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
} \
}
#endif /* YAPOR */
/* when we are calling the InitStaff procedures */
#define AT_BOOT 0
#define AT_RESTORE 1
/********* mutable variables ******************/
/* I assume that the size of this structure is a multiple of the size
of CELL!!! */
typedef struct TIMED_MAVAR
{
CELL value;
CELL clock;
} timed_var;
/********* while debugging you may need some info ***********************/
#ifdef EMACS
extern char emacs_tmp[], emacs_tmp2[];
#endif
#if defined(YAPOR) || defined(TABLING)
#include "opt.structs.h"
#include "opt.proto.h"
#include "opt.macros.h"
#endif /* YAPOR || TABLING */
#ifdef YAPOR_SBA
#include "or.sba_unify.h"
#endif
/********* execution mode ***********************/
typedef enum
{
INTERPRETED, /* interpreted */
MIXED_MODE_USER, /* mixed mode only for user predicates */
MIXED_MODE_ALL, /* mixed mode for all predicates */
COMPILE_USER, /* compile all user predicates*/
COMPILE_ALL /* compile all predicates */
} yap_exec_mode;
/********* slots ***********************/
static inline void
Yap_StartSlots( USES_REGS1 ) {
*--ASP = MkIntegerTerm(CurSlot);
*--ASP = MkIntTerm(0);
CurSlot = LCL0-ASP;
}
static inline void
Yap_CloseSlots( USES_REGS1 ) {
Int old_slots;
old_slots = IntOfTerm(ASP[0]);
ASP += (old_slots+1);
CurSlot = IntOfTerm(*ASP);
ASP++;
}
static inline Int
Yap_CurrentSlot( USES_REGS1 ) {
return IntOfTerm(ASP[0]);
}
#endif /* YAP_H */

View File

@ -52,17 +52,17 @@ typedef struct swi_reverse_hash {
Int pos;
} swi_rev_hash;
#define GC_MAVARS_HASH_SIZE 512
typedef struct gc_ma_hash_entry_struct {
UInt timestmp;
#ifdef TABLING
tr_fr_ptr loc;
struct gc_ma_hash_entry_struct *more;
#endif
CELL* addr;
struct gc_ma_hash_entry_struct *next;
} gc_ma_hash_entry;
//#define GC_MAVARS_HASH_SIZE 512
//
//typedef struct gc_ma_hash_entry_struct {
// UInt timestmp;
//#ifdef TABLING
// tr_fr_ptr loc;
// struct gc_ma_hash_entry_struct *more;
//#endif
// CELL* addr;
// struct gc_ma_hash_entry_struct *next;
//} gc_ma_hash_entry;
typedef void (*HaltHookFunc)(int, void *);
@ -81,10 +81,10 @@ typedef struct atom_hash_entry {
Atom Entry;
} AtomHashEntry;
typedef struct scratch_block_struct {
char *ptr;
UInt sz, msz;
} scratch_block;
//typedef struct scratch_block_struct {
// char *ptr;
// UInt sz, msz;
//} scratch_block;
typedef struct record_list {
/* a list of dbterms associated with a clause */
@ -97,6 +97,7 @@ typedef struct record_list {
#define SWI_TMP_BUF_SIZE 2*SWI_BUF_SIZE
#define SWI_BUF_RINGS 16
/* ricardo
#ifdef THREADS
typedef struct thandle {
int in_use;
@ -130,9 +131,9 @@ typedef struct thandle {
struct timeval *last_timep;
#endif
} yap_thandle;
#endif
#endif */
typedef int (*Agc_hook)(Atom);
//typedef int (*Agc_hook)(Atom);
/*******************
this is the data base: everything here should be possible to restore
@ -145,9 +146,10 @@ typedef struct various_codes {
} all_heap_codes;
#include "hglobals.h"
#include "hlocals.h"
//#include "hglobals.h"
//#include "hlocals.h"
/* ricardo
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
extern struct global_data *Yap_global;
extern long Yap_worker_area_size;
@ -162,10 +164,11 @@ extern struct worker_local *Yap_local[MAX_THREADS];
#elif defined(YAPOR)
extern struct worker_local *Yap_local;
#define REMOTE(wid) (Yap_local + wid)
#else /* !THREADS && !YAPOR */
#else
extern struct worker_local Yap_local;
#define REMOTE(wid) (&Yap_local)
#endif
*/
#ifdef USE_SYSTEM_MALLOC
extern struct various_codes *Yap_heap_regs;
@ -174,8 +177,8 @@ extern struct various_codes *Yap_heap_regs;
#endif
#include "dhstruct.h"
#include "dglobals.h"
#include "dlocals.h"
//#include "dglobals.h"
//#include "dlocals.h"
/*******************
these are the global variables: they need not be restored...

View File

@ -132,9 +132,6 @@ Term STD_PROTO(Yap_all_calls,(void));
Atom STD_PROTO(Yap_ConsultingFile,(void));
struct pred_entry *STD_PROTO(Yap_PredForChoicePt,(choiceptr));
void STD_PROTO(Yap_InitCdMgr,(void));
#ifdef EMACS
int STD_PROTO(where_new_clause, (Prop, int));
#endif
void STD_PROTO(Yap_init_consult,(int, char *));
void STD_PROTO(Yap_end_consult,(void));
void STD_PROTO(Yap_Abolish,(struct pred_entry *));
@ -239,6 +236,9 @@ void STD_PROTO(Yap_InitCPredBack_,(char *, unsigned long int, unsigned int, C
#endif
void STD_PROTO(Yap_InitWorkspace,(UInt,UInt,UInt,UInt,UInt,int,int,int));
#ifdef YAPOR
void STD_PROTO(Yap_init_yapor_workers, (void));
#endif /* YAPOR */
#if defined(YAPOR) || defined(THREADS)
void STD_PROTO(Yap_KillStacks,(int));
#else
@ -328,6 +328,7 @@ void STD_PROTO(Yap_undo_signal,(yap_signals));
int STD_PROTO(Yap_IsOpMaxPrio,(Atom));
/* sysbits.c */
void STD_PROTO(Yap_InitPageSize, (void));
void STD_PROTO(Yap_set_fpu_exceptions,(int));
UInt STD_PROTO(Yap_cputime,(void));
Int STD_PROTO(Yap_walltime,(void));
@ -391,6 +392,11 @@ void STD_PROTO(Yap_InitUtilCPreds,(void));
Int STD_PROTO(Yap_TermHash,(Term, Int, Int, int));
/* yap.c */
/* write.c */
void STD_PROTO(Yap_plwrite,(Term,int (*)(int, wchar_t), int, int));
/* MYDDAS */
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC

View File

@ -682,10 +682,10 @@ Macros to check the limits of stacks
#else
#define check_trail(x) if (Unsigned(Yap_TrailTop) - Unsigned(x) < MinTrailGap) \
#define check_trail(x) if (Unsigned(LOCAL_TrailTop) - Unsigned(x) < MinTrailGap) \
goto notrailleft
#define check_trail_in_indexing(x) if (Unsigned(Yap_TrailTop) - Unsigned(x) < MinTrailGap) \
#define check_trail_in_indexing(x) if (Unsigned(LOCAL_TrailTop) - Unsigned(x) < MinTrailGap) \
goto notrailleft_from_index
#endif

View File

@ -1095,12 +1095,8 @@ extern void **Yap_ABSMI_OPCODES;
#define absmadr(i) ((OPCODE)(i))
#endif
/* used to find out how many instructions of each kind are executed */
#ifdef ANALYST
extern YAP_ULONG_LONG Yap_opcount[_std_top + 1];
extern YAP_ULONG_LONG Yap_2opcount[_std_top + 1][_std_top + 1];
#endif /* ANALYST */
#if DEPTH_LIMIT
/*

View File

@ -15,6 +15,7 @@
* dereferencing, binding, trailing, and unification. *
* *
*************************************************************************/
#ifdef SCCS
static char SccsId[] = "%W% %G%";
#endif /* SCCS */
@ -276,7 +277,7 @@ Binding Macros for Multiple Assignment Variables.
#define TRAIL_CLREF(REF) TrailTerm(TR++) = CLREF_TO_TRENTRY(REF)
#define TRAIL_LINK(REF) TrailTerm(TR++) = AbsPair((CELL *)(REF))
#endif
#define TRAIL_FRAME(FR) DO_TRAIL(AbsPair((CELL *)(Yap_TrailBase)), FR)
#define TRAIL_FRAME(FR) DO_TRAIL(AbsPair((CELL *)(LOCAL_TrailBase)), FR)
extern void Yap_WakeUp(CELL *v);

View File

@ -32,7 +32,7 @@ struct cut_c_str{
#define POP_CHOICE_POINT(cp) \
(((CELL *)Yap_REGS.CUT_C_TOP != (CELL *)Yap_LocalBase) && ((CELL *)(cp) > (CELL *)Yap_REGS.CUT_C_TOP))
(((CELL *)Yap_REGS.CUT_C_TOP != (CELL *)LOCAL_LocalBase) && ((CELL *)(cp) > (CELL *)Yap_REGS.CUT_C_TOP))
#define POP_EXECUTE() \

View File

@ -44,7 +44,7 @@
#define GLOBAL_ThreadsTotalTime Yap_global->ThreadsTotalTime_
#define GLOBAL_ThreadHandlesLock Yap_global->ThreadHandlesLock_
#endif
#endif
#if defined(YAPOR) || defined(THREADS)
#define GLOBAL_BGL Yap_global->BGL_
@ -53,3 +53,58 @@
#define GLOBAL_optyap_data Yap_global->optyap_data_
#endif /* YAPOR || TABLING */
#define GLOBAL_PrologShouldHandleInterrupts Yap_global->PrologShouldHandleInterrupts_
#if defined(THREADS)
#define GLOBAL_master_thread Yap_global->master_thread_
#endif /* THREADS */
#define GLOBAL_stdout Yap_global->stdout_
#define GLOBAL_stderr Yap_global->stderr_
#define GLOBAL_argv Yap_global->argv_
#define GLOBAL_argc Yap_global->argc_
#ifdef COROUTINING
#define GLOBAL_attas Yap_global->attas_
#endif
#define GLOBAL_agc_calls Yap_global->agc_calls_
#define GLOBAL_agc_collected Yap_global->agc_collected_
#define GLOBAL_tot_agc_time Yap_global->tot_agc_time_
#define GLOBAL_tot_agc_recovered Yap_global->tot_agc_recovered_
#if HAVE_MMAP
#define GLOBAL_mmap_arrays Yap_global->mmap_arrays_
#endif
#ifdef DEBUG
#define GLOBAL_Option Yap_global->Option_
#define GLOBAL_logfile Yap_global->logfile_
#define GLOBAL_output_msg Yap_global->output_msg_
#endif
#define GLOBAL_ProfCalls Yap_global->ProfCalls_
#define GLOBAL_ProfGCs Yap_global->ProfGCs_
#define GLOBAL_ProfHGrows Yap_global->ProfHGrows_
#define GLOBAL_ProfSGrows Yap_global->ProfSGrows_
#define GLOBAL_ProfMallocs Yap_global->ProfMallocs_
#define GLOBAL_ProfOn Yap_global->ProfOn_
#define GLOBAL_ProfOns Yap_global->ProfOns_
#define GLOBAL_ProfilerRoot Yap_global->ProfilerRoot_
#define GLOBAL_ProfilerNil Yap_global->ProfilerNil_
#define GLOBAL_DIRNAME Yap_global->DIRNAME_
#if defined(COFF) || defined(A_OUT)
#define GLOBAL_Executable Yap_global->Executable_
#endif
#if __simplescalar__
#define GLOBAL_pwd Yap_global->pwd_
#endif

View File

@ -227,3 +227,93 @@
#define REMOTE_SignalLock(wid) REMOTE(wid)->SignalLock_
#endif
#define LOCAL_LocalBase LOCAL->LocalBase_
#define REMOTE_LocalBase(wid) REMOTE(wid)->LocalBase_
#define LOCAL_GlobalBase LOCAL->GlobalBase_
#define REMOTE_GlobalBase(wid) REMOTE(wid)->GlobalBase_
#define LOCAL_TrailBase LOCAL->TrailBase_
#define REMOTE_TrailBase(wid) REMOTE(wid)->TrailBase_
#define LOCAL_TrailTop LOCAL->TrailTop_
#define REMOTE_TrailTop(wid) REMOTE(wid)->TrailTop_
#define LOCAL_ErrorMessage LOCAL->ErrorMessage_
#define REMOTE_ErrorMessage(wid) REMOTE(wid)->ErrorMessage_
#define LOCAL_Error_Term LOCAL->Error_Term_
#define REMOTE_Error_Term(wid) REMOTE(wid)->Error_Term_
#ifdef THREADS
#define LOCAL_Error_TYPE LOCAL->Error_TYPE_
#define REMOTE_Error_TYPE(wid) REMOTE(wid)->Error_TYPE_
#else
#define LOCAL_Error_TYPE LOCAL->Error_TYPE_
#define REMOTE_Error_TYPE(wid) REMOTE(wid)->Error_TYPE_
#endif
#define LOCAL_Error_Size LOCAL->Error_Size_
#define REMOTE_Error_Size(wid) REMOTE(wid)->Error_Size_
#define LOCAL_ErrorSay LOCAL->ErrorSay_
#define REMOTE_ErrorSay(wid) REMOTE(wid)->ErrorSay_
#define LOCAL_IOBotch LOCAL->IOBotch_
#define REMOTE_IOBotch(wid) REMOTE(wid)->IOBotch_
#define LOCAL_tokptr LOCAL->tokptr_
#define REMOTE_tokptr(wid) REMOTE(wid)->tokptr_
#define LOCAL_toktide LOCAL->toktide_
#define REMOTE_toktide(wid) REMOTE(wid)->toktide_
#define LOCAL_VarTable LOCAL->VarTable_
#define REMOTE_VarTable(wid) REMOTE(wid)->VarTable_
#define LOCAL_AnonVarTable LOCAL->AnonVarTable_
#define REMOTE_AnonVarTable(wid) REMOTE(wid)->AnonVarTable_
#define LOCAL_RestartEnv LOCAL->RestartEnv_
#define REMOTE_RestartEnv(wid) REMOTE(wid)->RestartEnv_
#define LOCAL_FileNameBuf LOCAL->FileNameBuf_
#define REMOTE_FileNameBuf(wid) REMOTE(wid)->FileNameBuf_
#define LOCAL_FileNameBuf2 LOCAL->FileNameBuf2_
#define REMOTE_FileNameBuf2(wid) REMOTE(wid)->FileNameBuf2_
#define LOCAL_PrologMode LOCAL->PrologMode_
#define REMOTE_PrologMode(wid) REMOTE(wid)->PrologMode_
#define LOCAL_CritLocks LOCAL->CritLocks_
#define REMOTE_CritLocks(wid) REMOTE(wid)->CritLocks_
#ifdef ANALYST
#define LOCAL_opcount LOCAL->opcount_
#define REMOTE_opcount(wid) REMOTE(wid)->opcount_
#define LOCAL_2opcount LOCAL->2opcount_
#define REMOTE_2opcount(wid) REMOTE(wid)->2opcount_
#endif /* ANALYST */
#define LOCAL_s_dbg LOCAL->s_dbg_
#define REMOTE_s_dbg(wid) REMOTE(wid)->s_dbg_
#define LOCAL_matherror LOCAL->matherror_
#define REMOTE_matherror(wid) REMOTE(wid)->matherror_
#define LOCAL_heap_overflows LOCAL->heap_overflows_
#define REMOTE_heap_overflows(wid) REMOTE(wid)->heap_overflows_
#define LOCAL_total_heap_overflow_time LOCAL->total_heap_overflow_time_
#define REMOTE_total_heap_overflow_time(wid) REMOTE(wid)->total_heap_overflow_time_
#define LOCAL_stack_overflows LOCAL->stack_overflows_
#define REMOTE_stack_overflows(wid) REMOTE(wid)->stack_overflows_
#define LOCAL_total_stack_overflow_time LOCAL->total_stack_overflow_time_
#define REMOTE_total_stack_overflow_time(wid) REMOTE(wid)->total_stack_overflow_time_
#define LOCAL_delay_overflows LOCAL->delay_overflows_
#define REMOTE_delay_overflows(wid) REMOTE(wid)->delay_overflows_
#define LOCAL_total_delay_overflow_time LOCAL->total_delay_overflow_time_
#define REMOTE_total_delay_overflow_time(wid) REMOTE(wid)->total_delay_overflow_time_
#define LOCAL_trail_overflows LOCAL->trail_overflows_
#define REMOTE_trail_overflows(wid) REMOTE(wid)->trail_overflows_
#define LOCAL_total_trail_overflow_time LOCAL->total_trail_overflow_time_
#define REMOTE_total_trail_overflow_time(wid) REMOTE(wid)->total_trail_overflow_time_
#define LOCAL_atom_table_overflows LOCAL->atom_table_overflows_
#define REMOTE_atom_table_overflows(wid) REMOTE(wid)->atom_table_overflows_
#define LOCAL_total_atom_table_overflow_time LOCAL->total_atom_table_overflow_time_
#define REMOTE_total_atom_table_overflow_time(wid) REMOTE(wid)->total_atom_table_overflow_time_
#ifdef LOAD_DYLD
#define LOCAL_dl_errno LOCAL->dl_errno_
#define REMOTE_dl_errno(wid) REMOTE(wid)->dl_errno_
#endif
#ifdef LOW_LEVEL_TRACER
#define LOCAL_do_trace_primitives LOCAL->do_trace_primitives_
#define REMOTE_do_trace_primitives(wid) REMOTE(wid)->do_trace_primitives_
#endif

View File

@ -161,8 +161,6 @@ Functor STD_PROTO(EvalArg,(Term));
#define FL(X) ((double)(X))
#endif
extern yap_error_number Yap_matherror;
void STD_PROTO(Yap_InitConstExps,(void));
void STD_PROTO(Yap_InitUnaryExps,(void));
void STD_PROTO(Yap_InitBinaryExps,(void));
@ -190,8 +188,8 @@ inline static Term
Yap_FoundArithError(Term t, Term inp)
{
CACHE_REGS
if (Yap_Error_TYPE) {
Yap_Error(Yap_Error_TYPE, (inp ? inp : Yap_Error_Term), Yap_ErrorMessage);
if (LOCAL_Error_TYPE) {
Yap_Error(LOCAL_Error_TYPE, (inp ? inp : LOCAL_Error_Term), LOCAL_ErrorMessage);
P = FAILCODE;
return 0L;
}

View File

@ -49,7 +49,7 @@
/* is ptr a pointer to code space? */
#if USE_SYSTEM_MALLOC
#define ONCODE(ptr) (Addr(ptr) < Yap_GlobalBase || Addr(ptr) > Yap_TrailTop)
#define ONCODE(ptr) (Addr(ptr) < LOCAL_GlobalBase || Addr(ptr) > LOCAL_TrailTop)
#else
#define ONCODE(ptr) (Addr(ptr) < HeapTop && Addr(ptr) >= Yap_HeapBase)
#endif
@ -80,7 +80,7 @@
#define MARK_BIT ((char)1)
#define RMARK_BIT ((char)2)
#define mcell(X) LOCAL_bp[(X)-(CELL *)Yap_GlobalBase]
#define mcell(X) LOCAL_bp[(X)-(CELL *)LOCAL_GlobalBase]
#define MARKED_PTR(P) MARKED_PTR__(P PASS_REGS)
#define UNMARKED_MARK(P, BP) UNMARKED_MARK__(P, BP PASS_REGS)
@ -99,7 +99,7 @@ MARKED_PTR__(CELL* ptr USES_REGS)
static inline Int
UNMARKED_MARK__(CELL* ptr, char *bp USES_REGS)
{
Int pos = ptr - (CELL *)Yap_GlobalBase;
Int pos = ptr - (CELL *)LOCAL_GlobalBase;
char t = bp[pos];
if (t & MARK_BIT) {
return TRUE;

View File

@ -44,7 +44,7 @@ typedef struct global_data {
UInt ThreadsTotalTime_;
lockvar ThreadHandlesLock_;
#endif
#endif
#if defined(YAPOR) || defined(THREADS)
lockvar BGL_;
@ -52,4 +52,59 @@ typedef struct global_data {
#if defined(YAPOR) || defined(TABLING)
struct global_optyap_data optyap_data_;
#endif /* YAPOR || TABLING */
int PrologShouldHandleInterrupts_;
#if defined(THREADS)
pthread_t master_thread_;
#endif /* THREADS */
YP_FILE* stdout_;
YP_FILE* stderr_;
char** argv_;
int argc_;
#ifdef COROUTINING
ext_op attas_[attvars_ext+1];
#endif
int agc_calls_;
YAP_ULONG_LONG agc_collected_;
Int tot_agc_time_;
Int tot_agc_recovered_;
#if HAVE_MMAP
struct MMAP_ARRAY_BLOCK* mmap_arrays_;
#endif
#ifdef DEBUG
char Option_[20];
YP_FILE* logfile_;
int output_msg_;
#endif
Int ProfCalls_;
Int ProfGCs_;
Int ProfHGrows_;
Int ProfSGrows_;
Int ProfMallocs_;
Int ProfOn_;
Int ProfOns_;
struct RB_red_blk_node* ProfilerRoot_;
struct RB_red_blk_node* ProfilerNil_;
char* DIRNAME_;
#if defined(COFF) || defined(A_OUT)
char Executable_[YAP_FILENAME_MAX];
#endif
#if __simplescalar__
char pwd_[YAP_FILENAME_MAX];
#endif
} w_shared;

View File

@ -23,7 +23,7 @@ typedef struct worker_local {
Int GDiff_;
Int HDiff_;
Int GDiff0_;
Int GSplit_;
CELL* GSplit_;
Int LDiff_;
Int TrDiff_;
Int XDiff_;
@ -128,4 +128,58 @@ typedef struct worker_local {
#if defined(YAPOR) || defined(THREADS)
lockvar SignalLock_;
#endif
ADDR LocalBase_;
ADDR GlobalBase_;
ADDR TrailBase_;
ADDR TrailTop_;
char* ErrorMessage_;
Term Error_Term_;
#ifdef THREADS
Term Error_TYPE_;
#else
yap_error_number Error_TYPE_;
#endif
UInt Error_Size_;
char ErrorSay_[MAX_ERROR_MSG_SIZE];
jmp_buf IOBotch_;
TokEntry* tokptr_;
TokEntry* toktide_;
VarEntry* VarTable_;
VarEntry* AnonVarTable_;
sigjmp_buf RestartEnv_;
char FileNameBuf_[YAP_FILENAME_MAX];
char FileNameBuf2_[YAP_FILENAME_MAX];
Int PrologMode_;
int CritLocks_;
#ifdef ANALYST
YAP_ULONG_LONG opcount_[_std_top+1];
YAP_ULONG_LONG 2opcount[_std_top+1][_std_top+1]_;
#endif /* ANALYST */
struct db_globs* s_dbg_;
yap_error_number matherror_;
int heap_overflows_;
Int total_heap_overflow_time_;
int stack_overflows_;
Int total_stack_overflow_time_;
int delay_overflows_;
Int total_delay_overflow_time_;
int trail_overflows_;
Int total_trail_overflow_time_;
int atom_table_overflows_;
Int total_atom_table_overflow_time_;
#ifdef LOAD_DYLD
static dl_errno_;
#endif
#ifdef LOW_LEVEL_TRACER
int do_trace_primitives_;
#endif
} w_local;

View File

@ -44,7 +44,7 @@ static void InitGlobal(void) {
GLOBAL_ThreadsTotalTime = 0L;
INIT_LOCK(GLOBAL_ThreadHandlesLock);
#endif
#endif
#if defined(YAPOR) || defined(THREADS)
INIT_LOCK(GLOBAL_BGL);
@ -52,4 +52,59 @@ static void InitGlobal(void) {
#if defined(YAPOR) || defined(TABLING)
#endif /* YAPOR || TABLING */
#if defined(THREADS)
#endif /* THREADS */
GLOBAL_stdout = stdout;
GLOBAL_stderr = stderr;
#ifdef COROUTINING
#endif
GLOBAL_tot_agc_time = 0;
GLOBAL_tot_agc_recovered = 0;
#if HAVE_MMAP
GLOBAL_mmap_arrays = NULL;
#endif
#ifdef DEBUG
GLOBAL_output_msg = FALSE;
#endif
GLOBAL_DIRNAME = NULL;
#if defined(COFF) || defined(A_OUT)
#endif
#if __simplescalar__
#endif
}

View File

@ -128,4 +128,58 @@ static void InitWorker(int wid) {
#if defined(YAPOR) || defined(THREADS)
INIT_LOCK(REMOTE_SignalLock(wid));
#endif
#ifdef THREADS
#else
#endif
REMOTE_PrologMode(wid) = BootMode;
REMOTE_CritLocks(wid) = 0;
#ifdef ANALYST
#endif /* ANALYST */
REMOTE_matherror(wid) = YAP_NO_ERROR;
REMOTE_heap_overflows(wid) = 0;
REMOTE_total_heap_overflow_time(wid) = 0;
REMOTE_stack_overflows(wid) = 0;
REMOTE_total_stack_overflow_time(wid) = 0;
REMOTE_delay_overflows(wid) = 0;
REMOTE_total_delay_overflow_time(wid) = 0;
REMOTE_trail_overflows(wid) = 0;
REMOTE_total_trail_overflow_time(wid) = 0;
REMOTE_atom_table_overflows(wid) = 0;
REMOTE_total_atom_table_overflow_time(wid) = 0;
#ifdef LOAD_DYLD
REMOTE_dl_errno(wid) = 0;
#endif
#ifdef LOW_LEVEL_TRACER
REMOTE_do_trace_primitives(wid) = TRUE;
#endif
}

View File

@ -115,4 +115,5 @@ StreamDesc;
void STD_PROTO (Yap_InitStdStreams, (void));
Term STD_PROTO (Yap_StreamPosition, (struct io_stream *));
void STD_PROTO (Yap_InitPlIO, (void));

View File

@ -44,7 +44,7 @@ static void RestoreGlobal(void) {
REINIT_LOCK(GLOBAL_ThreadHandlesLock);
#endif
#endif
#if defined(YAPOR) || defined(THREADS)
REINIT_LOCK(GLOBAL_BGL);
@ -52,4 +52,59 @@ static void RestoreGlobal(void) {
#if defined(YAPOR) || defined(TABLING)
#endif /* YAPOR || TABLING */
#if defined(THREADS)
#endif /* THREADS */
#ifdef COROUTINING
#endif
#if HAVE_MMAP
#endif
#ifdef DEBUG
#endif
#if defined(COFF) || defined(A_OUT)
#endif
#if __simplescalar__
#endif
}

View File

@ -128,4 +128,58 @@ static void RestoreWorker(int wid USES_REGS) {
#if defined(YAPOR) || defined(THREADS)
REINIT_LOCK(REMOTE_SignalLock(wid));
#endif
#ifdef THREADS
#else
#endif
#ifdef ANALYST
#endif /* ANALYST */
#ifdef LOAD_DYLD
#endif
#ifdef LOW_LEVEL_TRACER
#endif
}

View File

@ -124,7 +124,7 @@ inline EXTERN int
IsHeapP__ (CELL * ptr USES_REGS)
{
#if USE_SYSTEM_MALLOC
return (int) ((ptr < (CELL *) Yap_GlobalBase || ptr > (CELL *) Yap_TrailTop));
return (int) ((ptr < (CELL *) LOCAL_GlobalBase || ptr > (CELL *) LOCAL_TrailTop));
#else
return (int) ((ptr >= (CELL *) Yap_HeapBase && ptr <= (CELL *) HeapTop));
#endif
@ -1123,7 +1123,7 @@ inline EXTERN int IsGlobal__ (CELL CACHE_TYPE);
inline EXTERN int
IsGlobal__ (CELL reg USES_REGS)
{
return (int) (IN_BETWEEN (Yap_GlobalBase, reg, H));
return (int) (IN_BETWEEN (LOCAL_GlobalBase, reg, H));
}

View File

@ -17,13 +17,13 @@
} else if (IsPairTerm(d1)) {
CELL *pt = RepPair(d1);
#ifdef LIMIT_TABLING
if ((ADDR) pt == Yap_TrailBase) {
if ((ADDR) pt == LOCAL_TrailBase) {
sg_fr_ptr sg_fr = (sg_fr_ptr) TrailVal(pt1);
SgFr_state(sg_fr)--; /* complete_in_use --> complete : compiled_in_use --> compiled */
insert_into_global_sg_fr_list(sg_fr);
} else
#endif /* LIMIT_TABLING */
if (IN_BETWEEN(Yap_TrailBase, pt, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, pt, LOCAL_TrailTop)) {
/* skip, this is a problem because we lose information,
namely active references */
pt1 = (tr_fr_ptr)pt;

View File

@ -65,9 +65,6 @@
#endif
#define YP_FILE FILE
extern YP_FILE *Yap_stdin;
extern YP_FILE *Yap_stdout;
extern YP_FILE *Yap_stderr;
int STD_PROTO(YP_putc,(int, int));
@ -167,6 +164,7 @@ extern YP_FILE yp_iob[YP_MAX_FILES];
typedef YP_FILE *YP_File;
/* ricardo
typedef enum TokenKinds {
Name_tok,
Number_tok,
@ -195,6 +193,7 @@ typedef struct VARSTRUCT {
struct VARSTRUCT *VarLeft, *VarRight;
char VarRep[1];
} VarEntry;
*/
/* Character types for tokenizer and write.c */
@ -325,8 +324,7 @@ Atom STD_PROTO(Yap_LookupWideAtom,(wchar_t *));
#define Unfold_cyclics_f 0x20
#define Use_SWI_Stream_f 0x40
/* write.c */
void STD_PROTO(Yap_plwrite,(Term,int (*)(int, wchar_t), int, int));
/* grow.c */
int STD_PROTO(Yap_growheap_in_parser, (tr_fr_ptr *, TokEntry **, VarEntry **));
@ -386,32 +384,4 @@ WideHashFunction(wchar_t *CHP)
#define CONTINUE_ON_PARSER_ERROR 2
#define EXCEPTION_ON_PARSER_ERROR 3
#ifdef THREADS
#define Yap_IOBotch Yap_thread_gl[worker_id].io_botch
#define Yap_tokptr Yap_thread_gl[worker_id].tokptr
#define Yap_toktide Yap_thread_gl[worker_id].toktide
#define Yap_VarTable Yap_thread_gl[worker_id].var_table
#define Yap_AnonVarTable Yap_thread_gl[worker_id].anon_var_table
#define Yap_eot_before_eof Yap_thread_gl[worker_id].eot_before_eof
#define Yap_FileNameBuf Yap_thread_gl[worker_id].file_name_buf
#define Yap_FileNameBuf2 Yap_thread_gl[worker_id].file_name_buf2
#else
extern jmp_buf Yap_IOBotch;
/*************** variables concerned with parsing *********************/
extern TokEntry *Yap_tokptr, *Yap_toktide;
extern VarEntry *Yap_VarTable, *Yap_AnonVarTable;
extern int Yap_eot_before_eof;
extern char Yap_FileNameBuf[YAP_FILENAME_MAX], Yap_FileNameBuf2[YAP_FILENAME_MAX];
#endif
#ifdef DEBUG
extern YP_FILE *Yap_logfile;
#endif
#if USE_SOCKET
extern int Yap_sockets_io;
#endif

View File

@ -260,7 +260,7 @@ C_SOURCES= \
$(srcdir)/BEAM/eam_am.c $(srcdir)/BEAM/eam_showcode.c \
$(srcdir)/BEAM/eamindex.c $(srcdir)/BEAM/eamamasm.c \
$(srcdir)/BEAM/eam_gc.c $(srcdir)/BEAM/eam_split.c \
$(srcdir)/OPTYap/opt.memory.c $(srcdir)/OPTYap/opt.init.c \
$(srcdir)/OPTYap/or.memory.c $(srcdir)/OPTYap/opt.init.c \
$(srcdir)/OPTYap/opt.preds.c $(srcdir)/OPTYap/or.copy_engine.c \
$(srcdir)/OPTYap/or.cow_engine.c $(srcdir)/OPTYap/or.sba_engine.c \
$(srcdir)/OPTYap/or.thread_engine.c \
@ -378,7 +378,7 @@ C_INTERFACE_OBJECTS = \
c_interface.o clause_list.o
OR_OBJECTS = \
opt.memory.o opt.init.o opt.preds.o \
or.memory.o opt.init.o opt.preds.o \
or.copy_engine.o or.cow_engine.o or.sba_engine.o or.thread_engine.o \
or.scheduler.o or.cut.o \
tab.tries.o tab.completion.o
@ -489,8 +489,8 @@ myddas_wkb2prolog.o: $(srcdir)/MYDDAS/myddas_wkb2prolog.c config.h
myddas_statistics.o: $(srcdir)/MYDDAS/myddas_statistics.c config.h
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_statistics.c -o $@
opt.memory.o: $(srcdir)/OPTYap/opt.memory.c config.h
$(CC) -c $(CFLAGS) $(srcdir)/OPTYap/opt.memory.c -o $@
or.memory.o: $(srcdir)/OPTYap/or.memory.c config.h
$(CC) -c $(CFLAGS) $(srcdir)/OPTYap/or.memory.c -o $@
opt.init.o: $(srcdir)/OPTYap/opt.init.c config.h
$(CC) -c $(CFLAGS) $(srcdir)/OPTYap/opt.init.c -o $@

View File

@ -17,9 +17,9 @@
** General Configuration Parameters **
************************************************************************/
/****************************************************************
** use shared pages memory alloc scheme ? (optional) **
****************************************************************/
/******************************************************************************************
** use shared pages memory alloc scheme for OPTYap data structures? (optional) **
******************************************************************************************/
/* #define USE_PAGES_MALLOC 1 */
@ -92,7 +92,7 @@
** memory mapping scheme (mandatory, define one) **
************************************************************/
#define MMAP_MEMORY_MAPPING_SCHEME 1
/* #define SHM_MEMORY_MAPPING_SCHEME 1 */
/* #define SHM_MEMORY_MAPPING_SCHEME 1 */
/*************************************************
** enable error checking ? (optional) **

View File

@ -71,8 +71,8 @@ void Yap_init_global_optyap_data(int max_table_size, int n_workers, int sch_loop
#endif /* LIMIT_TABLING */
INIT_PAGES(GLOBAL_pages_void, void *);
#ifdef YAPOR
INIT_PAGES(GLOBAL_pages_or_fr , struct or_frame);
INIT_PAGES(GLOBAL_pages_qg_sol_fr , struct query_goal_solution_frame);
INIT_PAGES(GLOBAL_pages_or_fr, struct or_frame);
INIT_PAGES(GLOBAL_pages_qg_sol_fr, struct query_goal_solution_frame);
INIT_PAGES(GLOBAL_pages_qg_ans_fr, struct query_goal_answer_frame);
#endif /* YAPOR */
#ifdef TABLING_INNER_CUTS
@ -164,7 +164,7 @@ void Yap_init_local_optyap_data(int wid) {
#ifdef YAPOR
CACHE_REGS
/* local data related to or-parallelism */
Set_REMOTE_top_cp(wid, (choiceptr) Yap_LocalBase);
Set_REMOTE_top_cp(wid, (choiceptr) LOCAL_LocalBase);
REMOTE_top_or_fr(wid) = GLOBAL_root_or_fr;
REMOTE_load(wid) = 0;
REMOTE_share_request(wid) = MAX_WORKERS;
@ -173,15 +173,16 @@ void Yap_init_local_optyap_data(int wid) {
INIT_LOCK(REMOTE_lock_signals(wid));
#endif /* YAPOR_COPY */
Set_REMOTE_prune_request(wid, NULL);
#endif /* YAPOR */
INIT_LOCK(REMOTE_lock(wid));
#endif /* YAPOR */
#ifdef TABLING
/* local data related to tabling */
REMOTE_next_free_ans_node(wid) = NULL;
REMOTE_top_sg_fr(wid) = NULL;
REMOTE_top_dep_fr(wid) = GLOBAL_root_dep_fr;
#ifdef YAPOR
Set_REMOTE_top_cp_on_stack(wid, (choiceptr) Yap_LocalBase); /* ??? */
Set_REMOTE_top_cp_on_stack(wid, (choiceptr) LOCAL_LocalBase); /* ??? */
REMOTE_top_susp_or_fr(wid) = GLOBAL_root_or_fr;
#endif /* YAPOR */
#endif /* TABLING */
@ -198,7 +199,7 @@ void Yap_init_root_frames(void) {
INIT_LOCK(OrFr_lock(or_fr));
OrFr_alternative(or_fr) = NULL;
BITMAP_copy(OrFr_members(or_fr), GLOBAL_bm_present_workers);
SetOrFr_node(or_fr, (choiceptr) Yap_LocalBase);
SetOrFr_node(or_fr, (choiceptr) LOCAL_LocalBase);
OrFr_nearest_livenode(or_fr) = NULL;
OrFr_depth(or_fr) = 0;
Set_OrFr_pend_prune_cp(or_fr, NULL);

View File

@ -173,7 +173,7 @@ extern int Yap_page_size;
/* see function 'InteractSIGINT' in file 'sysbits.c' */ \
/* Yap_Error(PURE_ABORT, TermNil, ""); */ \
/* restore_absmi_regs(&Yap_standard_regs); */ \
/* siglongjmp (Yap_RestartEnv, 1); */ \
/* siglongjmp (LOCAL_RestartEnv, 1); */ \
if (SgFr_first_answer(sg_fr) && \
SgFr_first_answer(sg_fr) != SgFr_answer_trie(sg_fr)) { \
SgFr_state(sg_fr) = ready; \
@ -263,7 +263,7 @@ extern int Yap_page_size;
** USE_PAGES_MALLOC && ! LIMIT_TABLING **
*************************************************************************************************/
#define ALLOC_PAGE(PG_HD) \
LOCK(Pg_lock(GLOBAL_pages_void)); \
LOCK(Pg_lock(GLOBAL_pages_void)); \
if (Pg_free_pg(GLOBAL_pages_void) == NULL) { \
int i, shmid; \
pg_hd_ptr pg_hd, aux_pg_hd; \
@ -457,7 +457,7 @@ extern int Yap_page_size;
************************************************************************/
#define INFORMATION_MESSAGE(MESSAGE,ARGS...) \
fprintf(stderr, "[ " MESSAGE " ]\n", ##ARGS)
Sfprintf(Serror, "[ " MESSAGE " ]\n", ##ARGS)
#ifdef YAPOR
#define ERROR_MESSAGE(MESSAGE) \

View File

@ -1,274 +0,0 @@
/************************************************************************
** **
** The YapTab/YapOr/OPTYap systems **
** **
** YapTab extends the Yap Prolog engine to support sequential tabling **
** YapOr extends the Yap Prolog engine to support or-parallelism **
** OPTYap extends the Yap Prolog engine to support or-parallel tabling **
** **
** **
** Yap Prolog was developed at University of Porto, Portugal **
** **
************************************************************************/
/**************************************
** Includes & Declarations **
**************************************/
#include "Yap.h"
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include "Yatom.h"
#include "YapHeap.h"
#include "alloc.h"
#include "heapgc.h"
#include "or.macros.h"
/************************************
** Macros & Declarations **
************************************/
#define KBYTES 1024
#ifdef MMAP_MEMORY_MAPPING_SCHEME
int fd_mapfile;
#else /* SHM_MEMORY_MAPPING_SCHEME */
int shm_mapid[MAX_WORKERS + 1];
#endif /* MEMORY_MAPPING_SCHEME */
/******************************************
** Local functions declaration **
******************************************/
#ifdef MMAP_MEMORY_MAPPING_SCHEME
void open_mapfile(long TotalArea);
#else /* SHM_MEMORY_MAPPING_SCHEME */
void shm_map_memory(int id, int size, void *shmaddr);
#endif /* MEMORY_MAPPING_SCHEME */
/********************************
** Global functions **
********************************/
void Yap_init_optyap_memory(long TrailAuxArea, long HeapArea, long GlobalLocalArea, int n_workers) {
#ifdef YAPOR_COW
int private_fd_mapfile;
#if MMAP_MEMORY_MAPPING_SCHEME
long TotalArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
long TotalArea;
#endif
long ExtraArea;
HeapArea = ADJUST_SIZE_TO_PAGE(HeapArea);
GlobalLocalArea = ADJUST_SIZE(GlobalLocalArea);
TrailAuxArea = ADJUST_SIZE(TrailAuxArea);
/* initial allocation - model independent */
ExtraArea = ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local));
Yap_local = (struct worker_local *)(MMAP_ADDR - ExtraArea);
Yap_global = (struct global_data *)(MMAP_ADDR - sizeof(struct global_data));
Yap_HeapBase = (ADDR) MMAP_ADDR;
Yap_GlobalBase = (ADDR) (MMAP_ADDR + HeapArea);
/* shared memory allocation - model dependent */
#ifdef YAPOR_COW
/* acow just needs one stack */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* I need this for MMAP to know what it must allocate */
TotalArea = HeapArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
/* the others need n stacks */
Yap_worker_area_size = ADJUST_SIZE_TO_PAGE(GlobalLocalArea + TrailAuxArea);
TotalArea = ExtraArea + HeapArea + Yap_worker_area_size * n_workers;
#endif
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map total area in a single go */
open_mapfile(TotalArea);
if (mmap((void *) Yap_local, (size_t) TotalArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
/* most systems are limited regarding what we can allocate */
#ifdef YAPOR_COW
/* single shared segment in ACOW */
shm_map_memory(0, ExtraArea + HeapArea, (void *) MMAP_ADDR);
#else /* YAPOR_COPY || YAPOR_SBA */
/* place as segment n otherwise (0..n-1 reserved for worker areas */
shm_map_memory(n_workers, ExtraArea + HeapArea, (void *) Yap_local);
{ int i;
for (i = 0; i < n_workers; i++)
shm_map_memory(i, Yap_worker_area_size, Yap_GlobalBase + Yap_worker_area_size * i);
}
#endif
#endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
/* just allocate local space for stacks */
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_optyap_memory)");
if (mmap(Yap_GlobalBase, GlobalLocalArea + TrailAuxArea, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
close(private_fd_mapfile);
#endif /* YAPOR_COW */
#ifdef YAPOR_SBA
/* alloc space for the sparse binding array */
sba_size = Yap_worker_area_size * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_optyap_memory)");
if ((CELL)binding_array & MBIT) {
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_optyap_memory)");
}
sba_offset = binding_array - Yap_GlobalBase;
sba_end = (int)binding_array + sba_size;
#endif /* YAPOR_SBA */
Yap_TrailBase = Yap_GlobalBase + GlobalLocalArea;
Yap_LocalBase = Yap_TrailBase - CellSize;
if (TrailAuxArea > 262144) /* 262144 = 256 * 1024 */
Yap_TrailTop = Yap_TrailBase + (TrailAuxArea - 131072); /* 131072 = 262144 / 2 */
else
Yap_TrailTop = Yap_TrailBase + (TrailAuxArea / 2);
HeapMax = (CELL)(Yap_TrailBase + (TrailAuxArea - CellSize));
Yap_InitHeap(Yap_HeapBase);
}
void Yap_remap_optyap_memory(void) {
#ifdef YAPOR_SBA
/* setup workers so that they have different areas */
Yap_GlobalBase += worker_id * Yap_worker_area_size;
Yap_TrailBase += worker_id * Yap_worker_area_size;
Yap_LocalBase += worker_id * Yap_worker_area_size;
Yap_TrailTop += worker_id * Yap_worker_area_size;
#endif /* YAPOR_SBA */
#ifdef YAPOR_COPY
int i;
void *remap_addr = Yap_GlobalBase;
#ifdef MMAP_MEMORY_MAPPING_SCHEME
long remap_offset = (ADDR) remap_addr - (ADDR) Yap_local;
if (munmap(remap_addr, (size_t)(Yap_worker_area_size * GLOBAL_number_workers)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "munmap error (Yap_remap_optyap_memory)");
for (i = 0; i < GLOBAL_number_workers; i++)
if (mmap(remap_addr + worker_offset(i), (size_t)Yap_worker_area_size, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * Yap_worker_area_size) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_remap_optyap_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
for (i = 0; i < GLOBAL_number_workers; i++)
if (shmdt(remap_addr + Yap_worker_area_size * i) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmdt error (Yap_remap_optyap_memory)");
for (i = 0; i < GLOBAL_number_workers; i++)
if(shmat(shm_mapid[i], remap_addr + worker_offset(i), 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (Yap_remap_optyap_memory)");
#endif /* MEMORY_MAPPING_SCHEME */
#endif /* YAPOR_COPY */
}
void Yap_unmap_optyap_memory (void) {
#ifdef MMAP_MEMORY_MAPPING_SCHEME
char MapFile[20];
#else /* SHM_MEMORY_MAPPING_SCHEME */
int i;
#endif /* MEMORY_MAPPING_SCHEME */
int proc;
INFORMATION_MESSAGE("Worker %d exiting...", worker_id);
for (proc = 0; proc < GLOBAL_number_workers; proc++) {
if (proc != worker_id && GLOBAL_worker_pid(proc) != 0) {
if (kill(GLOBAL_worker_pid(proc), SIGKILL) != 0)
INFORMATION_MESSAGE("Can't kill process %d", GLOBAL_worker_pid(proc));
else
INFORMATION_MESSAGE("Killing process %d", GLOBAL_worker_pid(proc));
}
}
#ifdef YAPOR_COW
if (GLOBAL_number_workers > 1) {
if (kill(GLOBAL_master_worker, SIGINT) != 0)
INFORMATION_MESSAGE("Can't kill process %d", GLOBAL_master_worker);
else
INFORMATION_MESSAGE("Killing process %d", GLOBAL_master_worker);
}
#endif /* YAPOR_COW */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
strcpy(MapFile,"./mapfile");
#ifdef YAPOR_COW
itos(GLOBAL_master_worker, &MapFile[9]);
#else /* YAPOR_COPY || YAPOR_SBA */
itos(GLOBAL_worker_pid(0), &MapFile[9]);
#endif
if (remove(MapFile) == 0)
INFORMATION_MESSAGE("Removing mapfile \"%s\"", MapFile);
else
INFORMATION_MESSAGE("Can't remove mapfile \"%s\"", MapFile);
#else /* SHM_MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
i = 0;
#else /* YAPOR_COPY || YAPOR_SBA */
for (i = 0; i < GLOBAL_number_workers + 1; i++)
#endif
{
if (shmctl(shm_mapid[i], IPC_RMID, 0) == 0)
INFORMATION_MESSAGE("Removing shared memory segment %d", shm_mapid[i]);
else
INFORMATION_MESSAGE("Can't remove shared memory segment %d", shm_mapid[i]);
}
#endif /* MEMORY_MAPPING_SCHEME */
return;
}
/* ------------------------- **
** Local functions **
** ------------------------- */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
void open_mapfile(long TotalArea) {
char mapfile[20];
strcpy(mapfile,"./mapfile");
itos(getpid(), &mapfile[9]);
if ((fd_mapfile = open(mapfile, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (open_mapfile)");
if (lseek(fd_mapfile, TotalArea, SEEK_SET) < 0)
Yap_Error(FATAL_ERROR, TermNil, "lseek error (open_mapfile)");
if (write(fd_mapfile, "", 1) < 0)
Yap_Error(FATAL_ERROR, TermNil, "write error (open_mapfile)");
return;
}
#else /* SHM_MEMORY_MAPPING_SCHEME */
void shm_map_memory(int id, int size, void *shmaddr) {
if (size > SHMMAX)
Yap_Error(FATAL_ERROR, TermNil, "maximum size for a shm segment exceeded (shm_map_memory)");
if ((shm_mapid[id] = shmget(IPC_PRIVATE, size, SHM_R|SHM_W)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmget error (shm_map_memory)");
if (shmat(shm_mapid[id], shmaddr, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (shm_map_memory)");
return;
}
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */

View File

@ -17,14 +17,13 @@
#include "Yap.h"
#if defined(YAPOR) || defined(TABLING)
#include <stdio.h>
#include "Yatom.h"
#include "YapHeap.h"
#include "SWI-Prolog.h"
#ifdef YAPOR
#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#include "Yatom.h"
#include "YapHeap.h"
#include "yapio.h"
#ifdef YAPOR
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */
@ -43,9 +42,11 @@ static Int p_table( USES_REGS1 );
static Int p_tabling_mode( USES_REGS1 );
static Int p_abolish_table( USES_REGS1 );
static Int p_abolish_all_tables( USES_REGS1 );
static Int p_abolish_all_local_tables( USES_REGS1 );
static Int p_show_tabled_predicates( USES_REGS1 );
static Int p_show_table( USES_REGS1 );
static Int p_show_all_tables( USES_REGS1 );
static Int p_show_all_local_tables( USES_REGS1 );
static Int p_show_global_trie( USES_REGS1 );
static Int p_show_statistics_table( USES_REGS1 );
static Int p_show_statistics_tabling( USES_REGS1 );
@ -76,26 +77,26 @@ static inline void answer_to_stdout(char *answer);
#endif /* YAPOR */
#ifdef TABLING
static inline long show_statistics_table_entries(void);
static inline long show_statistics_subgoal_frames(void);
static inline long show_statistics_dependency_frames(void);
static inline long show_statistics_subgoal_trie_nodes(void);
static inline long show_statistics_answer_trie_nodes(void);
static inline long show_statistics_subgoal_trie_hashes(void);
static inline long show_statistics_answer_trie_hashes(void);
static inline long show_statistics_global_trie_nodes(void);
static inline long show_statistics_global_trie_hashes(void);
static inline long show_statistics_table_entries(IOSTREAM *out);
static inline long show_statistics_subgoal_frames(IOSTREAM *out);
static inline long show_statistics_dependency_frames(IOSTREAM *out);
static inline long show_statistics_subgoal_trie_nodes(IOSTREAM *out);
static inline long show_statistics_answer_trie_nodes(IOSTREAM *out);
static inline long show_statistics_subgoal_trie_hashes(IOSTREAM *out);
static inline long show_statistics_answer_trie_hashes(IOSTREAM *out);
static inline long show_statistics_global_trie_nodes(IOSTREAM *out);
static inline long show_statistics_global_trie_hashes(IOSTREAM *out);
#endif /* TABLING */
#ifdef YAPOR
static inline long show_statistics_or_frames(void);
static inline long show_statistics_query_goal_solution_frames(void);
static inline long show_statistics_query_goal_answer_frames(void);
static inline long show_statistics_or_frames(IOSTREAM *out);
static inline long show_statistics_query_goal_solution_frames(IOSTREAM *out);
static inline long show_statistics_query_goal_answer_frames(IOSTREAM *out);
#endif /* YAPOR */
#if defined(YAPOR) && defined(TABLING)
static inline long show_statistics_suspension_frames(void);
static inline long show_statistics_suspension_frames(IOSTREAM *out);
#ifdef TABLING_INNER_CUTS
static inline long show_statistics_table_subgoal_solution_frames(void);
static inline long show_statistics_table_subgoal_answer_frames(void);
static inline long show_statistics_table_subgoal_solution_frames(IOSTREAM *out);
static inline long show_statistics_table_subgoal_answer_frames(IOSTREAM *out);
#endif /* TABLING_INNER_CUTS */
#endif /* YAPOR && TABLING */
@ -129,13 +130,15 @@ void Yap_init_optyap_preds(void) {
Yap_InitCPred("$c_tabling_mode", 3, p_tabling_mode, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$c_abolish_table", 2, p_abolish_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("abolish_all_tables", 0, p_abolish_all_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_tabled_predicates", 0, p_show_tabled_predicates, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_show_table", 2, p_show_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("show_all_tables", 0, p_show_all_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_global_trie", 0, p_show_global_trie, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_table_statistics", 2, p_show_statistics_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("tabling_statistics", 0, p_show_statistics_tabling, SafePredFlag|SyncPredFlag);
Yap_InitCPred("global_trie_statistics", 0, p_show_statistics_global_trie, SafePredFlag|SyncPredFlag);
Yap_InitCPred("abolish_all_local_tables", 0, p_abolish_all_local_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_tabled_predicates", 1, p_show_tabled_predicates, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_show_table", 3, p_show_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("show_all_tables", 1, p_show_all_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_all_local_tables", 1, p_show_all_local_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_global_trie", 1, p_show_global_trie, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_table_statistics", 3, p_show_statistics_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("tabling_statistics", 1, p_show_statistics_tabling, SafePredFlag|SyncPredFlag);
Yap_InitCPred("global_trie_statistics", 1, p_show_statistics_global_trie, SafePredFlag|SyncPredFlag);
#endif /* TABLING */
Yap_InitCPred("$c_yapor_threads", 1, p_yapor_threads, SafePredFlag|SyncPredFlag|HiddenPredFlag);
#ifdef YAPOR
@ -147,10 +150,10 @@ void Yap_init_optyap_preds(void) {
Yap_InitCPred("performance", 1, p_performance, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_parallel_new_answer", 1, p_parallel_new_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$c_parallel_yes_answer", 0, p_parallel_yes_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("or_statistics", 0, p_show_statistics_or, SafePredFlag|SyncPredFlag);
Yap_InitCPred("or_statistics", 1, p_show_statistics_or, SafePredFlag|SyncPredFlag);
#endif /* YAPOR */
#if defined(YAPOR) && defined(TABLING)
Yap_InitCPred("opt_statistics", 0, p_show_statistics_opt, SafePredFlag|SyncPredFlag);
Yap_InitCPred("opt_statistics", 1, p_show_statistics_opt, SafePredFlag|SyncPredFlag);
#endif /* YAPOR && TABLING */
Yap_InitCPred("$c_get_optyap_statistics", 3, p_get_optyap_statistics, SafePredFlag|SyncPredFlag|HiddenPredFlag);
}
@ -384,16 +387,29 @@ static Int p_abolish_all_tables( USES_REGS1 ) {
}
static Int p_abolish_all_local_tables( USES_REGS1 ) {
#ifdef THREADS
#else
p_abolish_all_tables();
#endif /* THREADS */
return (TRUE);
}
static Int p_show_tabled_predicates( USES_REGS1 ) {
IOSTREAM *out;
tab_ent_ptr tab_ent;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
tab_ent = GLOBAL_root_tab_ent;
fprintf(Yap_stdout, "Tabled predicates\n");
Sfprintf(out, "Tabled predicates\n");
if (tab_ent == NULL)
fprintf(Yap_stdout, " NONE\n");
Sfprintf(out, " NONE\n");
else
while(tab_ent) {
fprintf(Yap_stdout, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
Sfprintf(out, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
tab_ent = TabEnt_next(tab_ent);
}
return (TRUE);
@ -401,96 +417,124 @@ static Int p_show_tabled_predicates( USES_REGS1 ) {
static Int p_show_table( USES_REGS1 ) {
IOSTREAM *out;
Term mod, t;
tab_ent_ptr tab_ent;
mod = Deref(ARG1);
t = Deref(ARG2);
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
mod = Deref(ARG2);
t = Deref(ARG3);
if (IsAtomTerm(t))
tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred;
else if (IsApplTerm(t))
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
else
return (FALSE);
show_table(tab_ent, SHOW_MODE_STRUCTURE);
show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
return (TRUE);
}
static Int p_show_all_tables( USES_REGS1 ) {
IOSTREAM *out;
tab_ent_ptr tab_ent;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) {
show_table(tab_ent, SHOW_MODE_STRUCTURE);
show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
tab_ent = TabEnt_next(tab_ent);
}
return (TRUE);
}
static Int p_show_all_local_tables( USES_REGS1 ) {
#ifdef THREADS
#else
p_show_all_tables();
#endif /* THREADS */
return (TRUE);
}
static Int p_show_global_trie( USES_REGS1 ) {
show_global_trie(SHOW_MODE_STRUCTURE);
IOSTREAM *out;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
show_global_trie(SHOW_MODE_STRUCTURE, out);
return (TRUE);
}
static Int p_show_statistics_table( USES_REGS1 ) {
IOSTREAM *out;
Term mod, t;
tab_ent_ptr tab_ent;
mod = Deref(ARG1);
t = Deref(ARG2);
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
mod = Deref(ARG2);
t = Deref(ARG3);
if (IsAtomTerm(t))
tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred;
else if (IsApplTerm(t))
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
else
return (FALSE);
show_table(tab_ent, SHOW_MODE_STATISTICS);
show_table(tab_ent, SHOW_MODE_STATISTICS, out);
return (TRUE);
}
static Int p_show_statistics_tabling( USES_REGS1 ) {
IOSTREAM *out;
long total_bytes = 0, aux_bytes;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
aux_bytes = 0;
fprintf(Yap_stdout, "Execution data structures\n");
aux_bytes += show_statistics_table_entries();
aux_bytes += show_statistics_subgoal_frames();
aux_bytes += show_statistics_dependency_frames();
fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Execution data structures\n");
aux_bytes += show_statistics_table_entries(out);
aux_bytes += show_statistics_subgoal_frames(out);
aux_bytes += show_statistics_dependency_frames(out);
Sfprintf(out, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
aux_bytes = 0;
fprintf(Yap_stdout, "Local trie data structures\n");
aux_bytes += show_statistics_subgoal_trie_nodes();
aux_bytes += show_statistics_answer_trie_nodes();
aux_bytes += show_statistics_subgoal_trie_hashes();
aux_bytes += show_statistics_answer_trie_hashes();
fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Local trie data structures\n");
aux_bytes += show_statistics_subgoal_trie_nodes(out);
aux_bytes += show_statistics_answer_trie_nodes(out);
aux_bytes += show_statistics_subgoal_trie_hashes(out);
aux_bytes += show_statistics_answer_trie_hashes(out);
Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
aux_bytes = 0;
fprintf(Yap_stdout, "Global trie data structures\n");
aux_bytes += show_statistics_global_trie_nodes();
aux_bytes += show_statistics_global_trie_hashes();
fprintf(Yap_stdout, " Memory in use (III): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Global trie data structures\n");
aux_bytes += show_statistics_global_trie_nodes(out);
aux_bytes += show_statistics_global_trie_hashes(out);
Sfprintf(out, " Memory in use (III): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n",
Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void));
fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes);
Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */
fflush(Yap_stdout);
return (TRUE);
}
static Int p_show_statistics_global_trie( USES_REGS1 ) {
show_global_trie(SHOW_MODE_STATISTICS);
IOSTREAM *out;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
show_global_trie(SHOW_MODE_STATISTICS, out);
return (TRUE);
}
#endif /* TABLING */
@ -640,32 +684,33 @@ static Int p_performance( USES_REGS1 ) {
return(FALSE);
if (GLOBAL_number_goals) {
fprintf(Yap_stdout, "[\n Best execution times:\n");
Sfprintf(Soutput, "[\n Best execution times:\n");
for (i = 1; i <= GLOBAL_number_goals; i++) {
fprintf(Yap_stdout, " %d. time: %f seconds", i, GLOBAL_best_times(i));
Sfprintf(Soutput, " %d. time: %f seconds", i, GLOBAL_best_times(i));
if (one_worker_execution_time != 0)
fprintf(Yap_stdout, " --> speedup %f (%6.2f %% )\n",
Sfprintf(Soutput, " --> speedup %f (%6.2f %% )\n",
one_worker_execution_time / GLOBAL_best_times(i),
one_worker_execution_time / GLOBAL_best_times(i) / GLOBAL_number_workers* 100 );
else fprintf(Yap_stdout, "\n");
else Sfprintf(Soutput, "\n");
}
fprintf(Yap_stdout, " Average : %f seconds",
Sfprintf(Soutput, " Average : %f seconds",
GLOBAL_best_times(0) / GLOBAL_number_goals);
if (one_worker_execution_time != 0)
fprintf(Yap_stdout, " --> speedup %f (%6.2f %% )",
Sfprintf(Soutput, " --> speedup %f (%6.2f %% )",
one_worker_execution_time * GLOBAL_number_goals / GLOBAL_best_times(0),
one_worker_execution_time * GLOBAL_number_goals / GLOBAL_best_times(0) / GLOBAL_number_workers* 100 );
if (GLOBAL_number_goals >= 3) {
fprintf(Yap_stdout, "\n Average (best three): %f seconds",
Sfprintf(Soutput, "\n Average (best three): %f seconds",
(GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)) / 3);
if (one_worker_execution_time != 0)
fprintf(Yap_stdout, " --> speedup %f (%6.2f %% ) ]\n\n",
Sfprintf(Soutput, " --> speedup %f (%6.2f %% ) ]\n\n",
one_worker_execution_time * 3 / (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)),
one_worker_execution_time * 3 / (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)) / GLOBAL_number_workers* 100 );
else fprintf(Yap_stdout, "\n]\n\n");
} else fprintf(Yap_stdout, "\n]\n\n");
else Sfprintf(Soutput, "\n]\n\n");
} else Sfprintf(Soutput, "\n]\n\n");
Sflush(Soutput);
return (TRUE);
}
return (FALSE);
@ -700,28 +745,30 @@ static Int p_parallel_yes_answer( USES_REGS1 ) {
static Int p_show_statistics_or( USES_REGS1 ) {
IOSTREAM *out;
long total_bytes = 0, aux_bytes;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
aux_bytes = 0;
fprintf(Yap_stdout, "Execution data structures\n");
aux_bytes += show_statistics_or_frames();
fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Execution data structures\n");
aux_bytes += show_statistics_or_frames(out);
Sfprintf(out, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
aux_bytes = 0;
fprintf(Yap_stdout, "Cut support data structures\n");
aux_bytes += show_statistics_query_goal_solution_frames();
aux_bytes += show_statistics_query_goal_answer_frames();
fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Cut support data structures\n");
aux_bytes += show_statistics_query_goal_solution_frames(out);
aux_bytes += show_statistics_query_goal_answer_frames(out);
Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n",
Sfprintf(out, "Total memory in use (I+II): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void));
fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes);
Sfprintf(out, "Total memory in use (I+II): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */
return (TRUE);
}
#endif /* YAPOR */
@ -734,50 +781,52 @@ static Int p_show_statistics_or( USES_REGS1 ) {
#if defined(YAPOR) && defined(TABLING)
static Int p_show_statistics_opt( USES_REGS1 ) {
IOSTREAM *out;
long total_bytes = 0, aux_bytes;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
aux_bytes = 0;
fprintf(Yap_stdout, "Execution data structures\n");
aux_bytes += show_statistics_table_entries();
aux_bytes += show_statistics_subgoal_frames();
aux_bytes += show_statistics_dependency_frames();
aux_bytes += show_statistics_or_frames();
aux_bytes += show_statistics_suspension_frames();
fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Execution data structures\n");
aux_bytes += show_statistics_table_entries(out);
aux_bytes += show_statistics_subgoal_frames(out);
aux_bytes += show_statistics_dependency_frames(out);
aux_bytes += show_statistics_or_frames(out);
aux_bytes += show_statistics_suspension_frames(out);
Sfprintf(out, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
aux_bytes = 0;
fprintf(Yap_stdout, "Local trie data structures\n");
aux_bytes += show_statistics_subgoal_trie_nodes();
aux_bytes += show_statistics_answer_trie_nodes();
aux_bytes += show_statistics_subgoal_trie_hashes();
aux_bytes += show_statistics_answer_trie_hashes();
fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Local trie data structures\n");
aux_bytes += show_statistics_subgoal_trie_nodes(out);
aux_bytes += show_statistics_answer_trie_nodes(out);
aux_bytes += show_statistics_subgoal_trie_hashes(out);
aux_bytes += show_statistics_answer_trie_hashes(out);
Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
aux_bytes = 0;
fprintf(Yap_stdout, "Global trie data structures\n");
aux_bytes += show_statistics_global_trie_nodes();
aux_bytes += show_statistics_global_trie_hashes();
fprintf(Yap_stdout, " Memory in use (III): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, "Global trie data structures\n");
aux_bytes += show_statistics_global_trie_nodes(out);
aux_bytes += show_statistics_global_trie_hashes(out);
Sfprintf(out, " Memory in use (III): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
aux_bytes = 0;
fprintf(Yap_stdout, "Cut support data structures\n");
aux_bytes += show_statistics_query_goal_solution_frames();
aux_bytes += show_statistics_query_goal_answer_frames();
Sfprintf(out, "Cut support data structures\n");
aux_bytes += show_statistics_query_goal_solution_frames(out);
aux_bytes += show_statistics_query_goal_answer_frames(out);
#ifdef TABLING_INNER_CUTS
aux_bytes += show_statistics_table_subgoal_solution_frames();
aux_bytes += show_statistics_table_subgoal_answer_frames();
aux_bytes += show_statistics_table_subgoal_solution_frames(out);
aux_bytes += show_statistics_table_subgoal_answer_frames(out);
#endif /* TABLING_INNER_CUTS */
fprintf(Yap_stdout, " Memory in use (IV): %10ld bytes\n\n", aux_bytes);
Sfprintf(out, " Memory in use (IV): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC
fprintf(Yap_stdout, "Total memory in use (I+II+III+IV): %10ld bytes (%ld pages in use)\n",
Sfprintf(out, "Total memory in use (I+II+III+IV): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void));
fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else
fprintf(Yap_stdout, "Total memory in use (I+II+III+IV): %10ld bytes\n", total_bytes);
Sfprintf(out, "Total memory in use (I+II+III+IV): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */
return (TRUE);
}
#endif /* YAPOR && TABLING */
@ -945,19 +994,20 @@ static inline void show_answers(void) {
}
switch(GLOBAL_answers) {
case YES_ANSWER:
fprintf(Yap_stderr, "[ yes");
Sfprintf(Serror, "[ yes");
break;
case NO_ANSWER:
fprintf(Yap_stderr, "[ no");
Sfprintf(Serror, "[ no");
break;
case 1:
fprintf(Yap_stderr, "[ 1 answer found");
Sfprintf(Serror, "[ 1 answer found");
break;
default:
fprintf(Yap_stderr, "[ %d answers found", GLOBAL_answers);
Sfprintf(Serror, "[ %d answers found", GLOBAL_answers);
break;
}
fprintf(Yap_stderr, " (in %f seconds) ]\n\n", GLOBAL_execution_time);
Sfprintf(Serror, " (in %f seconds) ]\n\n", GLOBAL_execution_time);
Sflush(Serror);
if (GLOBAL_performance_mode == PERFORMANCE_ON) {
for (i = GLOBAL_number_goals; i > 0; i--) {
@ -1017,14 +1067,15 @@ static inline void answer_to_stdout(char *answer) {
else break;
}
output[length_output] = 0;
fprintf(Yap_stderr, " %s\n", output);
Sfprintf(Serror, " %s\n", output);
Sflush(Serror);
return;
}
#endif /* YAPOR */
#ifdef TABLING
static inline long show_statistics_table_entries(void) {
static inline long show_statistics_table_entries(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1042,17 +1093,17 @@ static inline long show_statistics_table_entries(void) {
}
TABLING_ERROR_CHECKING(statistics_table_entries, Pg_str_free(GLOBAL_pages_tab_ent) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Table entries: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry), Pg_pg_alloc(GLOBAL_pages_tab_ent), Pg_str_in_use(GLOBAL_pages_tab_ent));
#else
fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Table entries: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry), Pg_str_in_use(GLOBAL_pages_tab_ent));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry);
}
static inline long show_statistics_subgoal_frames(void) {
static inline long show_statistics_subgoal_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1070,17 +1121,17 @@ static inline long show_statistics_subgoal_frames(void) {
}
TABLING_ERROR_CHECKING(statistics_subgoal_frames, Pg_str_free(GLOBAL_pages_sg_fr) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Subgoal frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame), Pg_pg_alloc(GLOBAL_pages_sg_fr), Pg_str_in_use(GLOBAL_pages_sg_fr));
#else
fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Subgoal frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame), Pg_str_in_use(GLOBAL_pages_sg_fr));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame);
}
static inline long show_statistics_dependency_frames(void) {
static inline long show_statistics_dependency_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1098,17 +1149,17 @@ static inline long show_statistics_dependency_frames(void) {
}
TABLING_ERROR_CHECKING(statistics_dependency_frames, Pg_str_free(GLOBAL_pages_dep_fr) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Dependency frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame), Pg_pg_alloc(GLOBAL_pages_dep_fr), Pg_str_in_use(GLOBAL_pages_dep_fr));
#else
fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Dependency frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame), Pg_str_in_use(GLOBAL_pages_dep_fr));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame);
}
static inline long show_statistics_subgoal_trie_nodes(void) {
static inline long show_statistics_subgoal_trie_nodes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1126,17 +1177,17 @@ static inline long show_statistics_subgoal_trie_nodes(void) {
}
TABLING_ERROR_CHECKING(statistics_subgoal_trie_nodes, Pg_str_free(GLOBAL_pages_sg_node) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Subgoal trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node), Pg_pg_alloc(GLOBAL_pages_sg_node), Pg_str_in_use(GLOBAL_pages_sg_node));
#else
fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Subgoal trie nodes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node), Pg_str_in_use(GLOBAL_pages_sg_node));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node);
}
static inline long show_statistics_answer_trie_nodes(void) {
static inline long show_statistics_answer_trie_nodes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1154,17 +1205,17 @@ static inline long show_statistics_answer_trie_nodes(void) {
}
TABLING_ERROR_CHECKING(statistics_answer_trie_nodes, Pg_str_free(GLOBAL_pages_ans_node) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Answer trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node), Pg_pg_alloc(GLOBAL_pages_ans_node), Pg_str_in_use(GLOBAL_pages_ans_node));
#else
fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Answer trie nodes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node), Pg_str_in_use(GLOBAL_pages_ans_node));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node);
}
static inline long show_statistics_subgoal_trie_hashes(void) {
static inline long show_statistics_subgoal_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1182,17 +1233,17 @@ static inline long show_statistics_subgoal_trie_hashes(void) {
}
TABLING_ERROR_CHECKING(statistics_subgoal_trie_hashes, Pg_str_free(GLOBAL_pages_sg_hash) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Subgoal trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_pg_alloc(GLOBAL_pages_sg_hash), Pg_str_in_use(GLOBAL_pages_sg_hash));
#else
fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Subgoal trie hashes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_str_in_use(GLOBAL_pages_sg_hash));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash);
}
static inline long show_statistics_answer_trie_hashes(void) {
static inline long show_statistics_answer_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1210,17 +1261,17 @@ static inline long show_statistics_answer_trie_hashes(void) {
}
TABLING_ERROR_CHECKING(statistics_answer_trie_hashes, Pg_str_free(GLOBAL_pages_ans_hash) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Answer trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash), Pg_pg_alloc(GLOBAL_pages_ans_hash), Pg_str_in_use(GLOBAL_pages_ans_hash));
#else
fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Answer trie hashes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash), Pg_str_in_use(GLOBAL_pages_ans_hash));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash);
}
static inline long show_statistics_global_trie_nodes(void) {
static inline long show_statistics_global_trie_nodes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
pg_hd_ptr pg_hd;
@ -1238,19 +1289,20 @@ static inline long show_statistics_global_trie_nodes(void) {
}
TABLING_ERROR_CHECKING(statistics_global_trie_nodes, Pg_str_free(GLOBAL_pages_gt_node) != cont);
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Global trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node), Pg_pg_alloc(GLOBAL_pages_gt_node), Pg_str_in_use(GLOBAL_pages_gt_node));
#else
fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Global trie nodes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node), Pg_str_in_use(GLOBAL_pages_gt_node));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node);
}
static inline long show_statistics_global_trie_hashes(void) {
static inline long show_statistics_global_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING
/* suport not yet implemented :(
pg_hd_ptr pg_hd;
gt_hash_ptr aux_ptr;
long cont = 0;
@ -1265,11 +1317,12 @@ static inline long show_statistics_global_trie_hashes(void) {
pg_hd = PgHd_next(pg_hd);
}
TABLING_ERROR_CHECKING(statistics_global_trie_hashes, Pg_str_free(GLOBAL_pages_gt_hash) != cont);
*/
#endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_pg_alloc(GLOBAL_pages_gt_hash), Pg_str_in_use(GLOBAL_pages_gt_hash));
#else
fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Global trie hashes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_str_in_use(GLOBAL_pages_gt_hash));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash);
@ -1278,7 +1331,7 @@ static inline long show_statistics_global_trie_hashes(void) {
#ifdef YAPOR
static inline long show_statistics_or_frames(void) {
static inline long show_statistics_or_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_YAPOR
pg_hd_ptr pg_hd;
@ -1296,17 +1349,17 @@ static inline long show_statistics_or_frames(void) {
}
YAPOR_ERROR_CHECKING(statistics_or_frames, Pg_str_free(GLOBAL_pages_or_fr ) != cont);
#endif /* DEBUG_YAPOR */
fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Or-frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame), Pg_pg_alloc(GLOBAL_pages_or_fr ), Pg_str_in_use(GLOBAL_pages_or_fr ));
#else
fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Or-frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame), Pg_str_in_use(GLOBAL_pages_or_fr ));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame);
}
static inline long show_statistics_query_goal_solution_frames(void) {
static inline long show_statistics_query_goal_solution_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_YAPOR
pg_hd_ptr pg_hd;
@ -1324,17 +1377,17 @@ static inline long show_statistics_query_goal_solution_frames(void) {
}
YAPOR_ERROR_CHECKING(statistics_query_goal_solution_frames, Pg_str_free(GLOBAL_pages_qg_sol_fr ) != cont);
#endif /* DEBUG_YAPOR */
fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Query goal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame), Pg_pg_alloc(GLOBAL_pages_qg_sol_fr ), Pg_str_in_use(GLOBAL_pages_qg_sol_fr ));
#else
fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Query goal solution frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame), Pg_str_in_use(GLOBAL_pages_qg_sol_fr ));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame);
}
static inline long show_statistics_query_goal_answer_frames(void) {
static inline long show_statistics_query_goal_answer_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_YAPOR
pg_hd_ptr pg_hd;
@ -1352,10 +1405,10 @@ static inline long show_statistics_query_goal_answer_frames(void) {
}
YAPOR_ERROR_CHECKING(statistics_query_goal_answer_frames, Pg_str_free(GLOBAL_pages_qg_ans_fr) != cont);
#endif /* DEBUG_YAPOR */
fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Query goal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_pg_alloc(GLOBAL_pages_qg_ans_fr), Pg_str_in_use(GLOBAL_pages_qg_ans_fr));
#else
fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Query goal answer frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_str_in_use(GLOBAL_pages_qg_ans_fr));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame);
@ -1364,7 +1417,7 @@ static inline long show_statistics_query_goal_answer_frames(void) {
#if defined(YAPOR) && defined(TABLING)
static inline long show_statistics_suspension_frames(void) {
static inline long show_statistics_suspension_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_OPTYAP
pg_hd_ptr pg_hd;
@ -1382,10 +1435,10 @@ static inline long show_statistics_suspension_frames(void) {
}
OPTYAP_ERROR_CHECKING(statistics_suspension_frames, Pg_str_free(GLOBAL_pages_susp_fr) != cont);
#endif /* DEBUG_OPTYAP */
fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Suspension frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame), Pg_pg_alloc(GLOBAL_pages_susp_fr), Pg_str_in_use(GLOBAL_pages_susp_fr));
#else
fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Suspension frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame), Pg_str_in_use(GLOBAL_pages_susp_fr));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame);
@ -1393,7 +1446,7 @@ static inline long show_statistics_suspension_frames(void) {
#ifdef TABLING_INNER_CUTS
static inline long show_statistics_table_subgoal_solution_frames(void) {
static inline long show_statistics_table_subgoal_solution_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_OPTYAP
pg_hd_ptr pg_hd;
@ -1411,17 +1464,17 @@ static inline long show_statistics_table_subgoal_solution_frames(void) {
}
OPTYAP_ERROR_CHECKING(statistics_table_subgoal_solution_frames, Pg_str_free(GLOBAL_pages_tg_sol_fr) != cont);
#endif /* DEBUG_OPTYAP */
fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Table subgoal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_pg_alloc(GLOBAL_pages_tg_sol_fr), Pg_str_in_use(GLOBAL_pages_tg_sol_fr));
#else
fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Table subgoal solution frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_str_in_use(GLOBAL_pages_tg_sol_fr));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame);
}
static inline long show_statistics_table_subgoal_answer_frames(void) {
static inline long show_statistics_table_subgoal_answer_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC
#ifdef DEBUG_OPTYAP
pg_hd_ptr pg_hd;
@ -1439,10 +1492,10 @@ static inline long show_statistics_table_subgoal_answer_frames(void) {
}
OPTYAP_ERROR_CHECKING(statistics_table_subgoal_answer_frames, Pg_str_free(GLOBAL_pages_tg_ans_fr) != cont);
#endif /* DEBUG_OPTYAP */
fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Sfprintf(out, " Table subgoal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_pg_alloc(GLOBAL_pages_tg_ans_fr), Pg_str_in_use(GLOBAL_pages_tg_ans_fr));
#else
fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld structs in use)\n",
Sfprintf(out, " Table subgoal answer frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_str_in_use(GLOBAL_pages_tg_ans_fr));
#endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame);

View File

@ -11,15 +11,9 @@
** **
************************************************************************/
/***************************
** opt.memory.c **
***************************/
#ifdef YAPOR
void Yap_init_optyap_memory(long, long, long, int);
void Yap_unmap_optyap_memory(void);
void Yap_remap_optyap_memory(void);
#endif /* YAPOR */
#if defined(TABLING) || defined(YAPOR)
#include "SWI-Stream.h"
#endif /* TABLING || YAPOR */
@ -58,8 +52,8 @@ void free_subgoal_trie(sg_node_ptr, int, int);
void free_answer_trie(ans_node_ptr, int, int);
void free_subgoal_hash_chain(sg_hash_ptr);
void free_answer_hash_chain(ans_hash_ptr);
void show_table(tab_ent_ptr, int);
void show_global_trie(int);
void show_table(tab_ent_ptr, int, IOSTREAM *);
void show_global_trie(int, IOSTREAM *);
#endif /* TABLING */
@ -81,9 +75,22 @@ void resume_suspension_frame(susp_fr_ptr, or_fr_ptr);
/**************************
** or.copy_engine.c **
** or.memory.c **
**************************/
#ifdef YAPOR
void Yap_init_yapor_global_local_memory(void);
void Yap_init_yapor_stacks_memory(long, long, long, int);
void Yap_unmap_yapor_memory(void);
void Yap_remap_yapor_memory(void);
#endif /* YAPOR */
/*******************************
** or.copy_engine.c **
*******************************/
#ifdef YAPOR
void make_root_choice_point(void);
void free_root_choice_point(void);

View File

@ -57,6 +57,7 @@ cptr_to_offset_with_null(choiceptr node)
** Struct page_header **
*********************************/
#ifdef USE_PAGES_MALLOC
typedef struct page_header {
volatile int structs_in_use;
void *first_free_struct;
@ -68,6 +69,7 @@ typedef struct page_header {
#define PgHd_free_str(X) ((X)->first_free_struct)
#define PgHd_previous(X) ((X)->previous)
#define PgHd_next(X) ((X)->next)
#endif /* USE_PAGES_MALLOC */

View File

@ -58,7 +58,7 @@ static void share_private_nodes(int worker_q);
REMOTE_end_global_copy(Q) = (CELL) (H); \
REMOTE_start_local_copy(Q) = (CELL) (B); \
REMOTE_end_local_copy(Q) = (CELL) (LCL0); \
REMOTE_start_trail_copy(Q) = (CELL) (Yap_TrailBase); \
REMOTE_start_trail_copy(Q) = (CELL) (LOCAL_TrailBase); \
REMOTE_end_trail_copy(Q) = (CELL) (TR)
#endif
@ -125,7 +125,7 @@ void free_root_choice_point(void) {
#ifdef TABLING
LOCAL_top_cp_on_stack =
#endif /* TABLING */
LOCAL_top_cp = GLOBAL_root_cp = OrFr_node(GLOBAL_root_or_fr) = (choiceptr) Yap_LocalBase;
LOCAL_top_cp = GLOBAL_root_cp = OrFr_node(GLOBAL_root_or_fr) = (choiceptr) LOCAL_LocalBase;
return;
}
@ -220,10 +220,10 @@ int q_share_work(int worker_p) {
#ifdef TABLING
} else if (IsPairTerm(aux_cell)) {
aux_cell = (CELL) RepPair(aux_cell);
if (IN_BETWEEN(Yap_TrailBase, aux_cell, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, aux_cell, LOCAL_TrailTop)) {
/* avoid frozen segments */
TR = (tr_fr_ptr) aux_cell;
TABLING_ERROR_CHECKING(q_share_work, TR > (tr_fr_ptr) Yap_TrailTop);
TABLING_ERROR_CHECKING(q_share_work, TR > (tr_fr_ptr) LOCAL_TrailTop);
TABLING_ERROR_CHECKING(q_share_work, TR < aux_tr);
}
#endif /* TABLING */
@ -308,7 +308,7 @@ sync_with_p:
if (IsVarTerm(aux_cell)) {
if (aux_cell < LOCAL_start_global_copy || EQUAL_OR_YOUNGER_CP((choiceptr)LOCAL_end_local_copy, (choiceptr)aux_cell)) {
YAPOR_ERROR_CHECKING(q_share_work, (CELL *)aux_cell < H0);
YAPOR_ERROR_CHECKING(q_share_work, (ADDR)aux_cell > Yap_LocalBase);
YAPOR_ERROR_CHECKING(q_share_work, (ADDR)aux_cell > LOCAL_LocalBase);
#ifdef TABLING
*((CELL *) aux_cell) = TrailVal(aux_tr);
#else
@ -318,7 +318,7 @@ sync_with_p:
#ifdef TABLING
} else if (IsPairTerm(aux_cell)) {
aux_cell = (CELL) RepPair(aux_cell);
if (IN_BETWEEN(Yap_TrailBase, aux_cell, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, aux_cell, LOCAL_TrailTop)) {
/* avoid frozen segments */
aux_tr = (tr_fr_ptr) aux_cell;
}
@ -443,7 +443,7 @@ void share_private_nodes(int worker_q) {
consumer_cp = DepFr_cons_cp(dep_frame);
next_node_on_branch = NULL;
stack_limit = (CELL *)TR;
stack = (CELL *)Yap_TrailTop;
stack = (CELL *)LOCAL_TrailTop;
#endif /* TABLING */
/* initialize auxiliary variables */
@ -549,7 +549,7 @@ void share_private_nodes(int worker_q) {
#ifdef TABLING
/* update or-frames stored in auxiliary stack */
while (STACK_NOT_EMPTY(stack, (CELL *)Yap_TrailTop)) {
while (STACK_NOT_EMPTY(stack, (CELL *)LOCAL_TrailTop)) {
next_node_on_branch = (choiceptr) STACK_POP_DOWN(stack);
or_frame = (or_fr_ptr) STACK_POP_DOWN(stack);
OrFr_nearest_livenode(or_frame) = OrFr_next(or_frame) = next_node_on_branch->cp_or_fr;

View File

@ -75,7 +75,7 @@ void make_root_choice_point(void) {
void free_root_choice_point(void) {
B = LOCAL_top_cp->cp_b;
LOCAL_top_cp = (choiceptr) Yap_LocalBase;
LOCAL_top_cp = (choiceptr) LOCAL_LocalBase;
return;
}

View File

@ -40,7 +40,6 @@ void prune_shared_branch(choiceptr prune_cp) {
#ifdef TABLING_INNER_CUTS
tg_sol_fr_ptr tg_solutions, aux_tg_solutions;
#endif /* TABLING_INNER_CUTS */
leftmost_or_fr = CUT_leftmost_or_frame();
leftmost_cp = GetOrFr_node(leftmost_or_fr);
qg_solutions = NULL;

254
OPTYap/or.memory.c Normal file
View File

@ -0,0 +1,254 @@
/************************************************************************
** **
** The YapTab/YapOr/OPTYap systems **
** **
** YapTab extends the Yap Prolog engine to support sequential tabling **
** YapOr extends the Yap Prolog engine to support or-parallelism **
** OPTYap extends the Yap Prolog engine to support or-parallel tabling **
** **
** **
** Yap Prolog was developed at University of Porto, Portugal **
** **
************************************************************************/
/**************************************
** Includes & Declarations **
**************************************/
#include "Yap.h"
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include "Yatom.h"
#include "alloc.h"
#include "or.macros.h"
/************************************
** Macros & Declarations **
************************************/
#define GLOBAL_LOCAL_STRUCTS_AREA ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local))
#ifdef MMAP_MEMORY_MAPPING_SCHEME
int fd_mapfile;
#elif SHM_MEMORY_MAPPING_SCHEME
int shm_mapid[MAX_WORKERS + 2];
#endif /* MEMORY_MAPPING_SCHEME */
/******************************************
** Local functions declaration **
******************************************/
#ifdef SHM_MEMORY_MAPPING_SCHEME
void shm_map_memory(int id, int size, void *shmaddr);
void shm_unmap_memory(int id);
#endif /* SHM_MEMORY_MAPPING_SCHEME */
/********************************
** Global functions **
********************************/
void Yap_init_yapor_global_local_memory(void) {
Yap_local = (struct worker_local *)(MMAP_ADDR - GLOBAL_LOCAL_STRUCTS_AREA);
Yap_global = (struct global_data *)(MMAP_ADDR - sizeof(struct global_data));
#ifdef MMAP_MEMORY_MAPPING_SCHEME
{ char mapfile[20];
strcpy(mapfile,"./mapfile");
itos(getpid(), &mapfile[9]);
if ((fd_mapfile = open(mapfile, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_yapor_global_local_memory)");
if (lseek(fd_mapfile, GLOBAL_LOCAL_STRUCTS_AREA, SEEK_SET) < 0)
Yap_Error(FATAL_ERROR, TermNil, "lseek error (Yap_init_yapor_global_local_memory)");
if (write(fd_mapfile, "", 1) < 0)
Yap_Error(FATAL_ERROR, TermNil, "write error (Yap_init_yapor_global_local_memory)");
if (mmap((void *) Yap_local, (size_t) GLOBAL_LOCAL_STRUCTS_AREA, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_global_local_memory)");
}
#elif SHM_MEMORY_MAPPING_SCHEME
/* place as segment MAX_WORKERS (0..MAX_WORKERS-1 reserved for worker areas) */
shm_map_memory(MAX_WORKERS, GLOBAL_LOCAL_STRUCTS_AREA, (void *) Yap_local);
#endif /* MEMORY_MAPPING_SCHEME */
return;
}
void Yap_init_yapor_stacks_memory(long TrailStackArea, long HeapStackArea, long GlobalLocalStackArea, int n_workers) {
long StacksArea;
TrailStackArea = ADJUST_SIZE_TO_PAGE(TrailStackArea);
HeapStackArea = ADJUST_SIZE_TO_PAGE(HeapStackArea);
GlobalLocalStackArea = ADJUST_SIZE_TO_PAGE(GlobalLocalStackArea);
Yap_worker_area_size = GlobalLocalStackArea + TrailStackArea;
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
StacksArea = HeapStackArea + Yap_worker_area_size * n_workers;
#elif defined(YAPOR_COW)
StacksArea = HeapStackArea;
#endif /* YAPOR_COPY || YAPOR_SBA || YAPOR_COW */
Yap_HeapBase = (ADDR) MMAP_ADDR;
LOCAL_GlobalBase = (ADDR) (MMAP_ADDR + HeapStackArea);
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map stacks in a single go */
if (lseek(fd_mapfile, GLOBAL_LOCAL_STRUCTS_AREA + StacksArea, SEEK_SET) < 0)
Yap_Error(FATAL_ERROR, TermNil, "lseek error (Yap_init_yapor_stacks_memory)");
if (write(fd_mapfile, "", 1) < 0)
Yap_Error(FATAL_ERROR, TermNil, "write error (Yap_init_yapor_stacks_memory)");
if (mmap((void *) Yap_HeapBase, (size_t) StacksArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, GLOBAL_LOCAL_STRUCTS_AREA) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_yapor_stacks_memory)");
#elif SHM_MEMORY_MAPPING_SCHEME
/* place heap stack segment as MAX_WORKERS+1 */
shm_map_memory(MAX_WORKERS + 1, HeapStackArea, (void *) Yap_HeapBase);
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
/* map segments for worker areas as 0..MAX_WORKERS-1 */
{ int i;
for (i = 0; i < n_workers; i++)
shm_map_memory(i, Yap_worker_area_size, LOCAL_GlobalBase + Yap_worker_area_size * i);
}
#endif /* YAPOR_COPY || YAPOR_SBA */
#endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
/* just allocate local space for stacks */
{ int private_fd_mapfile;
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_yapor_stacks_memory)");
if (mmap(LOCAL_GlobalBase, Yap_worker_area_size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_yapor_stacks_memory)");
close(private_fd_mapfile);
}
#endif /* YAPOR_COW */
#ifdef YAPOR_SBA
/* alloc space for the sparse binding array */
sba_size = Yap_worker_area_size * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_yapor_stacks_memory)");
if ((CELL)binding_array & MBIT)
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_yapor_stacks_memory)");
sba_offset = binding_array - LOCAL_GlobalBase;
sba_end = (int)binding_array + sba_size;
#endif /* YAPOR_SBA */
LOCAL_TrailBase = LOCAL_GlobalBase + GlobalLocalStackArea;
LOCAL_LocalBase = LOCAL_TrailBase - CellSize;
LOCAL_TrailTop = LOCAL_TrailBase + TrailStackArea;
HeapLim = LOCAL_GlobalBase;
Yap_InitHeap(Yap_HeapBase);
return;
}
void Yap_remap_yapor_memory(void) {
#if defined(YAPOR_COPY)
int i;
void *remap_addr = LOCAL_GlobalBase;
#ifdef MMAP_MEMORY_MAPPING_SCHEME
long remap_offset = (ADDR) remap_addr - (ADDR) Yap_local;
if (munmap(remap_addr, (size_t)(Yap_worker_area_size * GLOBAL_number_workers)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "munmap error (Yap_remap_yapor_memory)");
for (i = 0; i < GLOBAL_number_workers; i++)
if (mmap(remap_addr + worker_offset(i), (size_t)Yap_worker_area_size, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * Yap_worker_area_size) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_remap_yapor_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
for (i = 0; i < GLOBAL_number_workers; i++)
if (shmdt(remap_addr + Yap_worker_area_size * i) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmdt error (Yap_remap_yapor_memory)");
for (i = 0; i < GLOBAL_number_workers; i++)
if(shmat(shm_mapid[i], remap_addr + worker_offset(i), 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (Yap_remap_yapor_memory)");
#endif /* MEMORY_MAPPING_SCHEME */
#elif defined(YAPOR_SBA)
/* setup workers so that they have different areas */
LOCAL_GlobalBase += worker_id * Yap_worker_area_size;
LOCAL_TrailBase += worker_id * Yap_worker_area_size;
LOCAL_LocalBase += worker_id * Yap_worker_area_size;
LOCAL_TrailTop += worker_id * Yap_worker_area_size;
#endif /* YAPOR_COPY || YAPOR_SBA */
}
void Yap_unmap_yapor_memory (void) {
int i;
INFORMATION_MESSAGE("Worker %d exiting...", worker_id);
for (i = 0; i < GLOBAL_number_workers; i++)
if (i != worker_id && GLOBAL_worker_pid(i) != 0) {
if (kill(GLOBAL_worker_pid(i), SIGKILL) != 0)
INFORMATION_MESSAGE("Can't kill process %d", GLOBAL_worker_pid(i));
else
INFORMATION_MESSAGE("Killing process %d", GLOBAL_worker_pid(i));
}
#ifdef YAPOR_COW
if (GLOBAL_number_workers > 1) {
if (kill(GLOBAL_master_worker, SIGINT) != 0)
INFORMATION_MESSAGE("Can't kill process %d", GLOBAL_master_worker);
else
INFORMATION_MESSAGE("Killing process %d", GLOBAL_master_worker);
}
#endif /* YAPOR_COW */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
{ char mapfile[20];
strcpy(mapfile,"./mapfile");
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
itos(GLOBAL_worker_pid(0), &mapfile[9]);
#elif defined(YAPOR_COW)
itos(GLOBAL_master_worker, &mapfile[9]);
#endif /* YAPOR_COPY || YAPOR_SBA || YAPOR_COW */
if (remove(mapfile) == 0)
INFORMATION_MESSAGE("Removing mapfile \"%s\"", mapfile);
else
INFORMATION_MESSAGE("Can't remove mapfile \"%s\"", mapfile);
}
#elif SHM_MEMORY_MAPPING_SCHEME
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
shm_unmap_memory(MAX_WORKERS);
shm_unmap_memory(MAX_WORKERS + 1);
for (i = 0; i < GLOBAL_number_workers; i++)
shm_unmap_memory(i);
#elif defined(YAPOR_COW)
shm_unmap_memory(0);
#endif /* YAPOR_COPY || YAPOR_SBA || YAPOR_COW */
#endif /* MEMORY_MAPPING_SCHEME */
return;
}
/* ------------------------- **
** Local functions **
** ------------------------- */
#ifdef SHM_MEMORY_MAPPING_SCHEME
void shm_map_memory(int id, int size, void *shmaddr) {
if ((shm_mapid[id] = shmget(IPC_PRIVATE, size, SHM_R|SHM_W)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmget error (shm_map_memory)");
if (shmat(shm_mapid[id], shmaddr, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (shm_map_memory)");
return;
}
void shm_unmap_memory(int id) {
if (shmctl(shm_mapid[id], IPC_RMID, 0) == 0)
INFORMATION_MESSAGE("Removing shared memory segment %d", shm_mapid[id]);
else
INFORMATION_MESSAGE("Can't remove shared memory segment %d", shm_mapid[id]);
return;
}
#endif /* SHM_MEMORY_MAPPING_SCHEME */
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */

View File

@ -66,7 +66,6 @@ Dereferencing macros
if (0 == (D)) break; \
if (IsPairTerm(D)) goto LabelList; \
} while (TRUE);
#endif /* UNIQUE_TAG_FOR_PAIRS */
EXTERN inline Term Deref(Term a)
@ -108,6 +107,7 @@ A contains the address of the variable that is to be trailed
#define RESET_VARIABLE(V) (*(CELL *)(V) = 0)
#if SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT
inline EXTERN void
AlignGlobalForDouble(void)
{
@ -118,6 +118,7 @@ AlignGlobalForDouble(void)
H++;
}
}
#endif /* SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT */
#ifdef YAPOR

View File

@ -99,9 +99,9 @@ void make_root_choice_point(void) {
LOCAL_load = 0;
LOCAL_prune_request = NULL;
BRANCH(worker_id, 0) = 0;
H_FZ = (CELL *) Yap_GlobalBase;
B_FZ = (choiceptr) Yap_LocalBase;
TR_FZ = (tr_fr_ptr) Yap_TrailBase;
H_FZ = (CELL *) LOCAL_GlobalBase;
B_FZ = (choiceptr) LOCAL_LocalBase;
TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
}
@ -109,10 +109,10 @@ void free_root_choice_point(void) {
reset_trail(LOCAL_top_cp->cp_tr, TR);
TR = LOCAL_top_cp->cp_tr;
B = LOCAL_top_cp->cp_b;
LOCAL_top_cp = (choiceptr) Yap_LocalBase;
H_FZ = (CELL *) Yap_GlobalBase;
B_FZ = (choiceptr) Yap_LocalBase;
TR_FZ = (tr_fr_ptr) Yap_TrailBase;
LOCAL_top_cp = (choiceptr) LOCAL_LocalBase;
H_FZ = (CELL *) LOCAL_GlobalBase;
B_FZ = (choiceptr) LOCAL_LocalBase;
TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
}

View File

@ -37,9 +37,6 @@ Int bind_variable(Term t0, Term t1)
}
EXTERN inline
/*
Int unify(Term t0, Term t1)
*/
Int unify(Term t0, Term t1)
{
tr_fr_ptr TR0 = TR;
@ -69,7 +66,7 @@ EXTERN inline Int unify_constant(register Term a, register Term cons)
return(IsLongIntTerm(cons) && LongIntOfTerm(a) == LongIntOfTerm(cons));
#ifdef TERM_EXTENSIONS
} else if (IsAttachFunc(fun)) {
return(attas[ExtFromFunctor(fun)].bind_op(SBIND,a,cons));
return(GLOBAL_attas[ExtFromFunctor(fun)].bind_op(SBIND,a,cons));
#endif /* TERM_EXTENSIONS */
} else
return(FALSE);

View File

@ -95,11 +95,11 @@ void free_root_choice_point(void) {
CACHE_REGS
B = Get_LOCAL_top_cp()->cp_b;
#ifdef TABLING
Set_LOCAL_top_cp_on_stack((choiceptr) Yap_LocalBase);
Set_LOCAL_top_cp_on_stack((choiceptr) LOCAL_LocalBase);
#endif /* TABLING */
Set_GLOBAL_root_cp((choiceptr) Yap_LocalBase);
Set_LOCAL_top_cp((choiceptr) Yap_LocalBase);
SetOrFr_node(GLOBAL_root_or_fr, (choiceptr) Yap_LocalBase);
Set_GLOBAL_root_cp((choiceptr) LOCAL_LocalBase);
Set_LOCAL_top_cp((choiceptr) LOCAL_LocalBase);
SetOrFr_node(GLOBAL_root_or_fr, (choiceptr) LOCAL_LocalBase);
return;
}
@ -282,7 +282,7 @@ void share_private_nodes(int worker_q) {
consumer_cp = DepFr_cons_cp(dep_frame);
next_node_on_branch = NULL;
stack_limit = (CELL *)TR;
stack = (CELL *)Yap_TrailTop;
stack = (CELL *)LOCAL_TrailTop;
#endif /* TABLING */
/* initialize auxiliary variables */
@ -388,7 +388,7 @@ void share_private_nodes(int worker_q) {
#ifdef TABLING
/* update or-frames stored in auxiliary stack */
while (STACK_NOT_EMPTY(stack, (CELL *)Yap_TrailTop)) {
while (STACK_NOT_EMPTY(stack, (CELL *)LOCAL_TrailTop)) {
next_node_on_branch = (choiceptr) STACK_POP_DOWN(stack);
or_frame = (or_fr_ptr) STACK_POP_DOWN(stack);
OrFr_nearest_livenode(or_frame) = OrFr_next(or_frame) = next_node_on_branch->cp_or_fr;

View File

@ -304,7 +304,7 @@
-> we need a shared data structure to avoid redundant computations!
UNLOCK_OR_FRAME(LOCAL_top_or_fr);
#else
fprintf(stderr,"PROBLEM: cp_last_answer field is local to the cp!\n");
Sfprintf(Serror, "PROBLEM: cp_last_answer field is local to the cp!\n");
exit(1);
#endif
}

View File

@ -435,13 +435,13 @@ static inline Int freeze_current_cp(void) {
TR_FZ = freeze_cp->cp_tr;
B = B->cp_b;
HB = B->cp_h;
return (Yap_LocalBase - (ADDR)freeze_cp);
return (LOCAL_LocalBase - (ADDR)freeze_cp);
}
static inline void wake_frozen_cp(Int frozen_offset) {
CACHE_REGS
choiceptr frozen_cp = (choiceptr)(Yap_LocalBase - frozen_offset);
choiceptr frozen_cp = (choiceptr)(LOCAL_LocalBase - frozen_offset);
restore_bindings(TR, frozen_cp->cp_tr);
B = frozen_cp;
@ -453,7 +453,7 @@ static inline void wake_frozen_cp(Int frozen_offset) {
static inline void abolish_frozen_cps_until(Int frozen_offset) {
CACHE_REGS
choiceptr frozen_cp = (choiceptr)(Yap_LocalBase - frozen_offset);
choiceptr frozen_cp = (choiceptr)(LOCAL_LocalBase - frozen_offset);
B_FZ = frozen_cp;
H_FZ = frozen_cp->cp_h;
@ -464,9 +464,9 @@ static inline void abolish_frozen_cps_until(Int frozen_offset) {
static inline void abolish_frozen_cps_all(void) {
CACHE_REGS
B_FZ = (choiceptr) Yap_LocalBase;
H_FZ = (CELL *) Yap_GlobalBase;
TR_FZ = (tr_fr_ptr) Yap_TrailBase;
B_FZ = (choiceptr) LOCAL_LocalBase;
H_FZ = (CELL *) LOCAL_GlobalBase;
TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
return;
}
@ -500,10 +500,10 @@ static inline void unbind_variables(tr_fr_ptr unbind_tr, tr_fr_ptr end_tr) {
RESET_VARIABLE(ref);
} else if (IsPairTerm(ref)) {
ref = (CELL) RepPair(ref);
if (IN_BETWEEN(Yap_TrailBase, ref, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, ref, LOCAL_TrailTop)) {
/* avoid frozen segments */
unbind_tr = (tr_fr_ptr) ref;
TABLING_ERROR_CHECKING(unbind_variables, unbind_tr > (tr_fr_ptr) Yap_TrailTop);
TABLING_ERROR_CHECKING(unbind_variables, unbind_tr > (tr_fr_ptr) LOCAL_TrailTop);
TABLING_ERROR_CHECKING(unbind_variables, unbind_tr < end_tr);
}
#ifdef MULTI_ASSIGNMENT_VARIABLES
@ -523,7 +523,7 @@ static inline void rebind_variables(tr_fr_ptr rebind_tr, tr_fr_ptr end_tr) {
CACHE_REGS
TABLING_ERROR_CHECKING(rebind_variables, rebind_tr < end_tr);
/* rebind loop */
Yap_NEW_MAHASH((ma_h_inner_struct *)H);
Yap_NEW_MAHASH((ma_h_inner_struct *)H PASS_REGS);
while (rebind_tr != end_tr) {
CELL ref = (CELL) TrailTerm(--rebind_tr);
/* check for global or local variables */
@ -532,16 +532,16 @@ static inline void rebind_variables(tr_fr_ptr rebind_tr, tr_fr_ptr end_tr) {
*((CELL *)ref) = TrailVal(rebind_tr);
} else if (IsPairTerm(ref)) {
ref = (CELL) RepPair(ref);
if (IN_BETWEEN(Yap_TrailBase, ref, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, ref, LOCAL_TrailTop)) {
/* avoid frozen segments */
rebind_tr = (tr_fr_ptr) ref;
TABLING_ERROR_CHECKING(rebind_variables, rebind_tr > (tr_fr_ptr) Yap_TrailTop);
TABLING_ERROR_CHECKING(rebind_variables, rebind_tr > (tr_fr_ptr) LOCAL_TrailTop);
TABLING_ERROR_CHECKING(rebind_variables, rebind_tr < end_tr);
}
#ifdef MULTI_ASSIGNMENT_VARIABLES
} else {
CELL *cell_ptr = RepAppl(ref);
if (!Yap_lookup_ma_var(cell_ptr)) {
if (!Yap_lookup_ma_var(cell_ptr PASS_REGS)) {
/* first time we found the variable, let's put the new value */
*cell_ptr = TrailVal(rebind_tr);
}
@ -560,7 +560,7 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
TABLING_ERROR_CHECKING(restore_variables, unbind_tr < rebind_tr);
end_tr = rebind_tr;
Yap_NEW_MAHASH((ma_h_inner_struct *)H);
Yap_NEW_MAHASH((ma_h_inner_struct *)H PASS_REGS);
while (unbind_tr != end_tr) {
/* unbind loop */
while (unbind_tr > end_tr) {
@ -569,10 +569,10 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
RESET_VARIABLE(ref);
} else if (IsPairTerm(ref)) {
ref = (CELL) RepPair(ref);
if (IN_BETWEEN(Yap_TrailBase, ref, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, ref, LOCAL_TrailTop)) {
/* avoid frozen segments */
unbind_tr = (tr_fr_ptr) ref;
TABLING_ERROR_CHECKING(restore_variables, unbind_tr > (tr_fr_ptr) Yap_TrailTop);
TABLING_ERROR_CHECKING(restore_variables, unbind_tr > (tr_fr_ptr) LOCAL_TrailTop);
}
#ifdef MULTI_ASSIGNMENT_VARIABLES
} else if (IsApplTerm(ref)) {
@ -582,7 +582,7 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
/* multi-assignment variable */
/* so that the upper cell is the old value */
--unbind_tr;
if (!Yap_lookup_ma_var(pt)) {
if (!Yap_lookup_ma_var(pt PASS_REGS)) {
pt[0] = TrailVal(unbind_tr);
}
#endif /* MULTI_ASSIGNMENT_VARIABLES */
@ -593,10 +593,10 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
ref = (CELL) TrailTerm(--end_tr);
if (IsPairTerm(ref)) {
ref = (CELL) RepPair(ref);
if (IN_BETWEEN(Yap_TrailBase, ref, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, ref, LOCAL_TrailTop)) {
/* avoid frozen segments */
end_tr = (tr_fr_ptr) ref;
TABLING_ERROR_CHECKING(restore_variables, end_tr > (tr_fr_ptr) Yap_TrailTop);
TABLING_ERROR_CHECKING(restore_variables, end_tr > (tr_fr_ptr) LOCAL_TrailTop);
}
}
}
@ -608,10 +608,10 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
*((CELL *)ref) = TrailVal(rebind_tr);
} else if (IsPairTerm(ref)) {
ref = (CELL) RepPair(ref);
if (IN_BETWEEN(Yap_TrailBase, ref, Yap_TrailTop)) {
if (IN_BETWEEN(LOCAL_TrailBase, ref, LOCAL_TrailTop)) {
/* avoid frozen segments */
rebind_tr = (tr_fr_ptr) ref;
TABLING_ERROR_CHECKING(restore_variables, rebind_tr > (tr_fr_ptr) Yap_TrailTop);
TABLING_ERROR_CHECKING(restore_variables, rebind_tr > (tr_fr_ptr) LOCAL_TrailTop);
TABLING_ERROR_CHECKING(restore_variables, rebind_tr < end_tr);
}
#ifdef MULTI_ASSIGNMENT_VARIABLES
@ -629,13 +629,13 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
static inline CELL *expand_auxiliary_stack(CELL *stack) {
CACHE_REGS
void *old_top = Yap_TrailTop;
void *old_top = LOCAL_TrailTop;
INFORMATION_MESSAGE("Expanding trail in 64 Kbytes");
if (! Yap_growtrail(K64, TRUE)) { /* TRUE means 'contiguous_only' */
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, "stack full (STACK_CHECK_EXPAND)");
return NULL;
} else {
UInt diff = (void *)Yap_TrailTop - old_top;
UInt diff = (void *)LOCAL_TrailTop - old_top;
CELL *new_stack = (CELL *)((void *)stack + diff);
memmove((void *)new_stack, (void *)stack, old_top - (void *)stack);
return new_stack;

View File

@ -17,13 +17,8 @@
#include "Yap.h"
#ifdef TABLING
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#include "Yatom.h"
#include "YapHeap.h"
#include "yapio.h"
#include "tab.macros.h"
static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr, sg_node_ptr, Term);
@ -78,6 +73,7 @@ static inline void traverse_update_arity(char *, int *, int *);
*******************************/
static struct trie_statistics{
IOSTREAM *out;
int show;
long subgoals;
long subgoals_incomplete;
@ -94,6 +90,7 @@ static struct trie_statistics{
long global_trie_references;
} trie_stats;
#define TrStat_out trie_stats.out
#define TrStat_show trie_stats.show
#define TrStat_subgoals trie_stats.subgoals
#define TrStat_sg_incomplete trie_stats.subgoals_incomplete
@ -110,7 +107,7 @@ static struct trie_statistics{
#define SHOW_TABLE_ARITY_ARRAY_SIZE 10000
#define SHOW_TABLE_STRUCTURE(MESG, ARGS...) \
if (TrStat_show == SHOW_MODE_STRUCTURE) \
fprintf(Yap_stdout, MESG, ##ARGS)
Sfprintf(TrStat_out, MESG, ##ARGS)
#define CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) \
if (MODE == TRAVERSE_MODE_NORMAL && IsVarTerm(REF) && REF > VarIndexOfTableTerm(MAX_TABLE_VARS)) { \
@ -185,47 +182,47 @@ static struct trie_statistics{
static inline CELL *exec_substitution_loop(gt_node_ptr current_node, CELL **stack_vars_ptr, CELL *stack_terms) {
/************************************************************************
===========
| |
| ... |
| |
-----------
YENV --> | N+1 | <-- stack_vars
-----------
| VAR_N |
-----------
| ... |
-----------
| VAR_0 |
-----------
| |
| ... |
| |
===========
| |
| ... |
| |
-----------
TR --> | | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| | stack_terms_pair_offset (TRIE_COMPACT_PAIRS)
| TERM_1 | \|/
=========== *
Yap_TrailTop --> | | <-- stack_terms_base (TRIE_COMPACT_PAIRS)
-----------
===========
| |
| ... |
| |
-----------
YENV --> | N+1 | <-- stack_vars
-----------
| VAR_N |
-----------
| ... |
-----------
| VAR_0 |
-----------
| |
| ... |
| |
===========
| |
| ... |
| |
-----------
TR --> | | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| | stack_terms_pair_offset (TRIE_COMPACT_PAIRS)
| TERM_1 | \|/
=========== *
LOCAL_TrailTop --> | | <-- stack_terms_base (TRIE_COMPACT_PAIRS)
-----------
************************************************************************/
CACHE_REGS
CELL *stack_vars = *stack_vars_ptr;
CELL *stack_terms_limit = (CELL *) TR;
#ifdef TRIE_COMPACT_PAIRS
#define stack_terms_base ((CELL *) Yap_TrailTop)
#define stack_terms_base ((CELL *) LOCAL_TrailTop)
int stack_terms_pair_offset = 0;
#endif /* TRIE_COMPACT_PAIRS */
Term t = TrNode_entry(current_node);
@ -1085,7 +1082,7 @@ void load_answer(ans_node_ptr current_ans_node, CELL *subs_ptr) {
Term t = STACK_POP_DOWN(stack_terms);
Bind((CELL *) subs_ptr[i], t);
}
TABLING_ERROR_CHECKING(load_answer, stack_terms != (CELL *)Yap_TrailTop);
TABLING_ERROR_CHECKING(load_answer, stack_terms != (CELL *)LOCAL_TrailTop);
return;
#undef subs_arity
@ -1099,13 +1096,13 @@ CELL *exec_substitution(gt_node_ptr current_node, CELL *aux_stack) {
Term t;
++aux_stack; /* skip the heap_arity entry */
stack_terms = exec_substitution_loop(current_node, &aux_stack, (CELL *) Yap_TrailTop);
stack_terms = exec_substitution_loop(current_node, &aux_stack, (CELL *) LOCAL_TrailTop);
*--aux_stack = 0; /* restore the heap_arity entry */
subs_ptr = aux_stack + aux_stack[1] + 2;
t = STACK_POP_DOWN(stack_terms);
Bind((CELL *) subs_ptr[subs_arity], t);
TABLING_ERROR_CHECKING(exec_substitution, stack_terms != (CELL *)Yap_TrailTop);
TABLING_ERROR_CHECKING(exec_substitution, stack_terms != (CELL *)LOCAL_TrailTop);
*subs_ptr = subs_arity - 1;
return aux_stack;
@ -1297,9 +1294,10 @@ void free_answer_hash_chain(ans_hash_ptr hash) {
}
void show_table(tab_ent_ptr tab_ent, int show_mode) {
void show_table(tab_ent_ptr tab_ent, int show_mode, IOSTREAM *out) {
sg_node_ptr sg_node;
TrStat_out = out;
TrStat_show = show_mode;
if (show_mode == SHOW_MODE_STATISTICS) {
TrStat_subgoals = 0;
@ -1313,9 +1311,9 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
#endif /* TABLING_INNER_CUTS */
TrStat_ans_nodes = 0;
TrStat_gt_refs = 0;
fprintf(Yap_stdout, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
Sfprintf(TrStat_out, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
} else { /* SHOW_MODE_STRUCTURE */
fprintf(Yap_stdout, "Table structure for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
Sfprintf(TrStat_out, "Table structure for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
}
sg_node = TrNode_child(TabEnt_subgoal_trie(tab_ent));
if (sg_node) {
@ -1349,34 +1347,34 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
} else
SHOW_TABLE_STRUCTURE(" EMPTY\n");
if (show_mode == SHOW_MODE_STATISTICS) {
fprintf(Yap_stdout, " Subgoal trie structure\n");
fprintf(Yap_stdout, " Subgoals: %ld (%ld incomplete)\n", TrStat_subgoals, TrStat_sg_incomplete);
fprintf(Yap_stdout, " Subgoal trie nodes: %ld\n", TrStat_sg_nodes);
fprintf(Yap_stdout, " Answer trie structure(s)\n");
Sfprintf(TrStat_out, " Subgoal trie structure\n");
Sfprintf(TrStat_out, " Subgoals: %ld (%ld incomplete)\n", TrStat_subgoals, TrStat_sg_incomplete);
Sfprintf(TrStat_out, " Subgoal trie nodes: %ld\n", TrStat_sg_nodes);
Sfprintf(TrStat_out, " Answer trie structure(s)\n");
#ifdef TABLING_INNER_CUTS
fprintf(Yap_stdout, " Answers: %ld (%ld pruned)\n", TrStat_answers, TrStat_answers_pruned);
Sfprintf(TrStat_out, " Answers: %ld (%ld pruned)\n", TrStat_answers, TrStat_answers_pruned);
#else
fprintf(Yap_stdout, " Answers: %ld\n", TrStat_answers);
Sfprintf(TrStat_out, " Answers: %ld\n", TrStat_answers);
#endif /* TABLING_INNER_CUTS */
fprintf(Yap_stdout, " Answers 'TRUE': %ld\n", TrStat_answers_true);
fprintf(Yap_stdout, " Answers 'NO': %ld\n", TrStat_answers_no);
fprintf(Yap_stdout, " Answer trie nodes: %ld\n", TrStat_ans_nodes);
fprintf(Yap_stdout, " Global trie references: %ld\n", TrStat_gt_refs);
Sfprintf(TrStat_out, " Answers 'TRUE': %ld\n", TrStat_answers_true);
Sfprintf(TrStat_out, " Answers 'NO': %ld\n", TrStat_answers_no);
Sfprintf(TrStat_out, " Answer trie nodes: %ld\n", TrStat_ans_nodes);
Sfprintf(TrStat_out, " Global trie references: %ld\n", TrStat_gt_refs);
}
fflush(Yap_stdout);
return;
}
void show_global_trie(int show_mode) {
void show_global_trie(int show_mode, IOSTREAM *out) {
TrStat_out = out;
TrStat_show = show_mode;
if (show_mode == SHOW_MODE_STATISTICS) {
TrStat_gt_terms = 0;
TrStat_gt_nodes = 1;
TrStat_gt_refs = 0;
fprintf(Yap_stdout, "Global trie statistics\n");
Sfprintf(TrStat_out, "Global trie statistics\n");
} else { /* SHOW_MODE_STRUCTURE */
fprintf(Yap_stdout, "Global trie structure\n");
Sfprintf(TrStat_out, "Global trie structure\n");
}
if (TrNode_child(GLOBAL_root_gt)) {
char *str = (char *) malloc(sizeof(char) * SHOW_TABLE_STR_ARRAY_SIZE);
@ -1388,9 +1386,9 @@ void show_global_trie(int show_mode) {
} else
SHOW_TABLE_STRUCTURE(" EMPTY\n");
if (show_mode == SHOW_MODE_STATISTICS) {
fprintf(Yap_stdout, " Terms: %ld\n", TrStat_gt_terms);
fprintf(Yap_stdout, " Global trie nodes: %ld\n", TrStat_gt_nodes);
fprintf(Yap_stdout, " Global trie auto references: %ld\n", TrStat_gt_refs);
Sfprintf(TrStat_out, " Terms: %ld\n", TrStat_gt_terms);
Sfprintf(TrStat_out, " Global trie nodes: %ld\n", TrStat_gt_nodes);
Sfprintf(TrStat_out, " Global trie auto references: %ld\n", TrStat_gt_refs);
}
return;
}

View File

@ -791,43 +791,43 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c
#endif /* MODE_TERMS_LOOP */
#endif /* MODE_GLOBAL_TRIE_LOOP */
/************************************************************************
===========
| |
| ... |
| |
-----------
| VAR_N | <-- stack_vars
----------- *
| ... | /|\
----------- | subs_arity (N+1)
| VAR_0 | \|/
----------- *
YENV --> | |
-----------
| |
| ... |
| |
===========
| |
| ... |
| |
-----------
TR --> | | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| |
| TERM_1 | |
----------| |
| NULL | \|/
=========== *
Yap_TrailTop --> | |
-----------
===========
| |
| ... |
| |
-----------
| VAR_N | <-- stack_vars
----------- *
| ... | /|\
----------- | subs_arity (N+1)
| VAR_0 | \|/
----------- *
YENV --> | |
-----------
| |
| ... |
| |
===========
| |
| ... |
| |
-----------
TR --> | | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| |
| TERM_1 | |
----------| |
| NULL | \|/
=========== *
LOCAL_TrailTop --> | |
-----------
************************************************************************/
CACHE_REGS
#ifdef MODE_GLOBAL_TRIE_LOOP
@ -836,7 +836,7 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c
int subs_arity = *subs_arity_ptr;
CELL *stack_vars = *stack_vars_ptr;
#if ! defined(MODE_GLOBAL_TRIE_LOOP) || ! defined(GLOBAL_TRIE_FOR_SUBTERMS)
CELL *stack_terms = (CELL *) Yap_TrailTop;
CELL *stack_terms = (CELL *) LOCAL_TrailTop;
#endif /* ! MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE_FOR_SUBTERMS */
CELL *stack_terms_limit = (CELL *) TR;
AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1); /* + 1 because initially we stiil haven't done any STACK_POP_DOWN */
@ -1005,33 +1005,33 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr
#endif /* MODE_TERMS_LOOP */
#endif /* MODE_GLOBAL_TRIE_LOOP */
/************************************************************************
===========
| |
| ... |
| |
-----------
TR --> | VAR_0 | <-- stack_vars_base
----------- *
| ... | /|\
----------- | vars_arity (N+1)
| VAR_N | \|/
----------- *
| | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| |
| TERM_1 | |
----------| |
| NULL | \|/
=========== *
Yap_TrailTop --> | |
-----------
===========
| |
| ... |
| |
-----------
TR --> | VAR_0 | <-- stack_vars_base
----------- *
| ... | /|\
----------- | vars_arity (N+1)
| VAR_N | \|/
----------- *
| | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| |
| TERM_1 | |
----------| |
| NULL | \|/
=========== *
LOCAL_TrailTop --> | |
-----------
************************************************************************/
CACHE_REGS
#ifdef MODE_GLOBAL_TRIE_LOOP
@ -1039,7 +1039,7 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr
#endif /* MODE_GLOBAL_TRIE_LOOP */
int vars_arity = *vars_arity_ptr;
#if ! defined(MODE_GLOBAL_TRIE_LOOP) || ! defined(GLOBAL_TRIE_FOR_SUBTERMS)
CELL *stack_terms = (CELL *) Yap_TrailTop;
CELL *stack_terms = (CELL *) LOCAL_TrailTop;
#endif /* ! MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE_FOR_SUBTERMS */
CELL *stack_vars_base = (CELL *) TR;
#define stack_terms_limit (stack_vars_base + vars_arity)
@ -1219,43 +1219,43 @@ static inline CELL *load_substitution_loop(gt_node_ptr current_node, int *vars_a
static inline CELL *load_answer_loop(ans_node_ptr current_node) {
#endif /* MODE_GLOBAL_TRIE_LOOP */
/************************************************************************
===========
| |
| ... |
| |
-----------
TR --> | VAR_0 | <-- stack_vars_base
----------- *
| ... | /|\
----------- | vars_arity (N+1)
| VAR_N | \|/
----------- *
| | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| | stack_terms_pair_offset (TRIE_COMPACT_PAIRS)
| TERM_1 | \|/
=========== *
Yap_TrailTop --> | | <-- stack_terms_base (TRIE_COMPACT_PAIRS)
-----------
===========
| |
| ... |
| |
-----------
TR --> | VAR_0 | <-- stack_vars_base
----------- *
| ... | /|\
----------- | vars_arity (N+1)
| VAR_N | \|/
----------- *
| | <-- stack_terms_limit
-----------
| |
| ... |
| |
----------|
| TERM_N | <-- stack_terms
----------| *
| ... | /|\
----------| | stack_terms_pair_offset (TRIE_COMPACT_PAIRS)
| TERM_1 | \|/
=========== *
LOCAL_TrailTop --> | | <-- stack_terms_base (TRIE_COMPACT_PAIRS)
-----------
************************************************************************/
CACHE_REGS
#ifdef MODE_GLOBAL_TRIE_LOOP
int vars_arity = *vars_arity_ptr;
#else
int vars_arity = 0;
CELL *stack_terms = (CELL *) Yap_TrailTop;
CELL *stack_terms = (CELL *) LOCAL_TrailTop;
#endif /* MODE_GLOBAL_TRIE_LOOP */
CELL *stack_vars_base = (CELL *) TR;
#define stack_terms_limit (stack_vars_base + vars_arity)
#ifdef TRIE_COMPACT_PAIRS
#define stack_terms_base ((CELL *) Yap_TrailTop)
#define stack_terms_base ((CELL *) LOCAL_TrailTop)
int stack_terms_pair_offset = 0;
#endif /* TRIE_COMPACT_PAIRS */
Term t = TrNode_entry(current_node);

View File

@ -900,16 +900,6 @@ extern int splfild;
#define DO_EVERYTHING 1
#define DO_ONLY_CODE 2
#ifdef EMACS
/******************** using Emacs mode ********************************/
extern int emacs_mode;
#endif
/************ variable concerned with version number *****************/
extern char version_number[];
@ -1033,10 +1023,6 @@ typedef struct TIMED_MAVAR{
extern int output_msg;
#endif
#if EMACS
extern char emacs_tmp[], emacs_tmp2[];
#endif
#if HAVE_SIGNAL
extern int snoozing;
#endif

View File

@ -81,7 +81,7 @@ CLEAN :
-@erase "$(INTDIR)\mavar.obj"
-@erase "$(INTDIR)\modules.obj"
-@erase "$(INTDIR)\opt.init.obj"
-@erase "$(INTDIR)\opt.memory.obj"
-@erase "$(INTDIR)\or.memory.obj"
-@erase "$(INTDIR)\opt.preds.obj"
-@erase "$(INTDIR)\or.cowengine.obj"
-@erase "$(INTDIR)\or.cut.obj"
@ -161,7 +161,7 @@ LINK32_OBJS= \
"$(INTDIR)\mavar.obj" \
"$(INTDIR)\modules.obj" \
"$(INTDIR)\opt.init.obj" \
"$(INTDIR)\opt.memory.obj" \
"$(INTDIR)\or.memory.obj" \
"$(INTDIR)\opt.preds.obj" \
"$(INTDIR)\or.cowengine.obj" \
"$(INTDIR)\or.cut.obj" \
@ -242,7 +242,7 @@ CLEAN :
-@erase "$(INTDIR)\mavar.obj"
-@erase "$(INTDIR)\modules.obj"
-@erase "$(INTDIR)\opt.init.obj"
-@erase "$(INTDIR)\opt.memory.obj"
-@erase "$(INTDIR)\or.memory.obj"
-@erase "$(INTDIR)\opt.preds.obj"
-@erase "$(INTDIR)\or.cowengine.obj"
-@erase "$(INTDIR)\or.cut.obj"
@ -325,7 +325,7 @@ LINK32_OBJS= \
"$(INTDIR)\mavar.obj" \
"$(INTDIR)\modules.obj" \
"$(INTDIR)\opt.init.obj" \
"$(INTDIR)\opt.memory.obj" \
"$(INTDIR)\or.memory.obj" \
"$(INTDIR)\opt.preds.obj" \
"$(INTDIR)\or.cowengine.obj" \
"$(INTDIR)\or.cut.obj" \
@ -637,9 +637,9 @@ SOURCE="\Yap\Yap-4.3.17\OPTYap\opt.init.c"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE="\Yap\Yap-4.3.17\OPTYap\opt.memory.c"
SOURCE="\Yap\Yap-4.3.17\OPTYap\or.memory.c"
"$(INTDIR)\opt.memory.obj" : $(SOURCE) "$(INTDIR)"
"$(INTDIR)\or.memory.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)

View File

@ -1035,6 +1035,7 @@ win32main(rlc_console c, int argc, TCHAR **argv)
if ( !PL_initialise(argc, av) )
PL_halt(1);
rlc_bind_terminal(c);
PL_halt(PL_toplevel() ? 0 : 1);
return 0;
@ -1050,7 +1051,6 @@ int PASCAL
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{ LPTSTR cmdline;
fprintf(stderr,"Hello\n");
InitializeCriticalSection(&mutex);

View File

@ -259,48 +259,6 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
if (!strcmp("dump-runtime-variables",p))
return dump_runtime_variables();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
#ifdef USE_SOCKET
case 'c': /* running as client */
{
char *host, *p1;
long port;
char *ptr;
host = *++argv;
argc--;
if (host == NULL || host[0] == '-')
YAP_Error(0,0L,"sockets must receive host to connect to");
p1 = *++argv;
argc--;
if (p1 == NULL || p1[0] == '-')
YAP_Error(0,0L,"sockets must receive port to connect to");
port = strtol(p1, &ptr, 10);
if (ptr == NULL || ptr[0] != '\0')
YAP_Error(0,0L,"port argument to socket must be a number");
YAP_InitSocks(host,port);
}
break;
#endif
#ifdef EMACS
case 'e':
emacs_mode = TRUE;
{
File fd;
strcpy (emacs_tmp, ++p);
if ((fd = fopen (emacs_tmp, "w")) == NIL)
fprintf(stderr, "[ Warning: unable to communicate with emacs: failed to open %s ]\n", emacs_tmp);
fclose (fd);
unlink (emacs_tmp);
p = *++argv;
--argc;
strcpy (emacs_tmp2, p);
if ((fd = fopen (emacs_tmp2, "w")) == NIL)
fprintf(stderr, "Unable to communicate with emacs: failed to open %s\n", emacs_tmp2);
fclose (fd);
unlink (emacs_tmp2);
}
break;
#endif /* EMACS */
case 'F':
/* just ignore for now */
argc--;
@ -348,12 +306,6 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
goto myddas_error_print;
break;
}
#endif
#ifdef MPWSHELL
case 'm':
if (*++p == 'p' && *++p == 'w' && *++p == '\0')
mpwshell = TRUE;
break;
#endif
// execution mode
case 'J':

View File

@ -325,6 +325,9 @@ extern X_API int PROTO(YAP_Init,(YAP_init_args *));
/* int YAP_FastInit(const char *) */
extern X_API int PROTO(YAP_FastInit,(CONST char *));
/* void * YAP_TermToStream(YAP_Term) */
extern X_API void * PROTO(YAP_TermToStream,(YAP_Term));
/* void * YAP_InitConsult(int, const char *) */
extern X_API void * PROTO(YAP_InitConsult,(int, CONST char *));

View File

@ -210,27 +210,21 @@ delete_remaining_edges(SortedVs,Vs0,Vsf) :-
dgraph_transpose(Graph, TGraph) :-
rb_visit(Graph, Edges),
rb_clone(Graph, TGraph, NewNodes),
tedges(Edges,UnsortedTEdges),
sort(UnsortedTEdges,TEdges),
fill_nodes(NewNodes,TEdges).
transpose(Edges, Nodes, TEdges, []),
dgraph_new(G0),
% make sure we have all vertices, even if they are unconnected.
dgraph_add_vertices(G0, Nodes, G1),
dgraph_add_edges(G1, TEdges, TGraph).
tedges([],[]).
tedges([V-Vs|Edges],TEdges) :-
fill_tedges(Vs, V, TEdges, TEdges0),
tedges(Edges,TEdges0).
transpose([], []) --> [].
transpose([V-Edges|MoreVs], [V|Vs]) -->
transpose_edges(Edges, V),
transpose(MoreVs, Vs).
fill_tedges([], _, TEdges, TEdges).
fill_tedges([V1|Vs], V, [V1-V|TEdges], TEdges0) :-
fill_tedges(Vs, V, TEdges, TEdges0).
fill_nodes([],[]).
fill_nodes([V-[Child|MoreChildren]|Nodes],[V-Child|Edges]) :- !,
get_extra_children(Edges,V,MoreChildren,REdges),
fill_nodes(Nodes,REdges).
fill_nodes([_-[]|Edges],TEdges) :-
fill_nodes(Edges,TEdges).
transpose_edges([], _V) --> [].
transpose_edges(E.Edges, V) -->
[E-V],
transpose_edges(Edges, V).
dgraph_compose(T1,T2,CT) :-
rb_visit(T1,Nodes),

View File

@ -9,6 +9,8 @@
*/
#define PL_KERNEL 1
//=== includes ===============================================================
#include <stdlib.h>
#include <string.h>
@ -118,7 +120,7 @@ UserCPredicate(char *a, CPredicate def, unsigned long int arity, Term mod, int f
Atom at;
while ((at = Yap_LookupAtom(a)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return;
}
}
@ -129,7 +131,7 @@ UserCPredicate(char *a, CPredicate def, unsigned long int arity, Term mod, int f
while ((at = Yap_LookupAtom(a)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return;
}
}
@ -630,7 +632,7 @@ X_API atom_t PL_new_atom(const char *c)
while ((at = Yap_LookupAtom((char *)c)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
@ -646,7 +648,7 @@ X_API atom_t PL_new_atom_nchars(size_t len, const char *c)
while ((pt = (char *)Yap_AllocCodeSpace(len+1)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
@ -658,7 +660,7 @@ X_API atom_t PL_new_atom_nchars(size_t len, const char *c)
while ((at = Yap_LookupAtom(pt)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
@ -680,7 +682,7 @@ X_API atom_t PL_new_atom_wchars(size_t len, const wchar_t *c)
while (!(nbf = (wchar_t *)YAP_AllocSpaceFromYap((len+1)*sizeof(wchar_t)))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0;
}
}
@ -690,7 +692,7 @@ X_API atom_t PL_new_atom_wchars(size_t len, const wchar_t *c)
while ((at0 = Yap_LookupWideAtom(nbf)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0L;
}
}
@ -703,7 +705,7 @@ X_API atom_t PL_new_atom_wchars(size_t len, const wchar_t *c)
while (!(nbf = (char *)YAP_AllocSpaceFromYap((len+1)*sizeof(char)))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0;
}
}
@ -713,7 +715,7 @@ X_API atom_t PL_new_atom_wchars(size_t len, const wchar_t *c)
while (!(at0 = Yap_LookupAtom(nbf))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return 0;
}
}
@ -853,7 +855,7 @@ X_API int PL_put_atom_chars(term_t t, const char *s)
while (!(at = Yap_LookupAtom((char *)s))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -870,7 +872,7 @@ X_API int PL_put_atom_nchars(term_t t, size_t len, const char *s)
if (strlen(s) > len) {
while (!(buf = (char *)Yap_AllocCodeSpace(len+1))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -881,7 +883,7 @@ X_API int PL_put_atom_nchars(term_t t, size_t len, const char *s)
}
while (!(at = Yap_LookupAtom(buf))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1078,7 +1080,7 @@ X_API int PL_unify_atom_chars(term_t t, const char *s)
Term cterm;
while (!(catom = Yap_LookupAtom((char *)s))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1101,7 +1103,7 @@ X_API int PL_unify_atom_nchars(term_t t, size_t len, const char *s)
buf[len] = '\0';
while (!(catom = Yap_LookupAtom(buf))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1336,7 +1338,7 @@ X_API int PL_unify_wchars(term_t t, int type, size_t len, const pl_wchar_t *char
Atom at;
while ((at = Yap_LookupMaybeWideAtomWithLength((wchar_t *)chars, len)) == NULL) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1395,7 +1397,7 @@ LookupMaxAtom(size_t n, char *s)
buf[n] = '\0';
while (!(catom = Yap_LookupAtom(buf))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -1416,7 +1418,7 @@ LookupMaxWideAtom(size_t n, wchar_t *s)
while (!(catom = Yap_LookupMaybeWideAtom(buf))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
CACHE_REGS
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -1499,7 +1501,7 @@ X_API int PL_unify_term(term_t l,...)
char *s = va_arg(ap, char *);
while (!(at = Yap_LookupAtom(s))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1594,7 +1596,7 @@ X_API int PL_unify_term(term_t l,...)
while (!(at = Yap_LookupAtom(fname))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -1606,7 +1608,7 @@ X_API int PL_unify_term(term_t l,...)
while (!(at = Yap_LookupAtom(fname))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return FALSE;
}
}
@ -2057,7 +2059,7 @@ X_API predicate_t PL_predicate(const char *name, int arity, const char *m)
Atom at;
while (!(at = Yap_LookupAtom((char *)m))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -2065,7 +2067,7 @@ X_API predicate_t PL_predicate(const char *name, int arity, const char *m)
}
while (!(at = Yap_LookupAtom((char *)name))) {
if (!Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
}
@ -2741,9 +2743,9 @@ PL_query(int query)
{
switch(query) {
case PL_QUERY_ARGC:
return (intptr_t)Yap_argc;
return (intptr_t)GLOBAL_argc;
case PL_QUERY_ARGV:
return (intptr_t)Yap_argv;
return (intptr_t)GLOBAL_argv;
case PL_QUERY_USER_CPU:
return (intptr_t)Yap_cputime();
case PL_QUERY_VERSION:

View File

@ -52,7 +52,6 @@ Comments: This file provides a set of functions to convert a prolog term to a C
#endif
struct buffer_ds buffer;
extern char *Yap_ErrorMessage;
/*********************************************************************************************/
// prototypes
@ -229,10 +228,10 @@ string2term(char *const ptr,const size_t *size) {
b.ptr=NULL;
}
BUFFER_POS=0;
Yap_ErrorMessage=NULL;
LOCAL_ErrorMessage=NULL;
t = YAP_Read(p2c_getc);
if ( t==FALSE ) {
write_msg(__FUNCTION__,__FILE__,__LINE__,"FAILED string2term>>>>size:%d %d %s\n",BUFFER_SIZE,strlen(BUFFER_PTR),Yap_ErrorMessage);
write_msg(__FUNCTION__,__FILE__,__LINE__,"FAILED string2term>>>>size:%d %d %s\n",BUFFER_SIZE,strlen(BUFFER_PTR),LOCAL_ErrorMessage);
exit(1);
}

Some files were not shown because too many files have changed in this diff Show More