move handles to a separate handle stack.
This commit is contained in:
parent
9f945c152d
commit
36e4cbf98b
12
C/absmi.c
12
C/absmi.c
@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* Yap Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
@ -1231,8 +1231,9 @@ interrupt_either( USES_REGS1 )
|
||||
{
|
||||
int v;
|
||||
|
||||
#ifdef DEBUG_INTERRUPTS
|
||||
if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s:%d: (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \
|
||||
#ifdef DEBUGX
|
||||
//if (trace_interrupts)
|
||||
fprintf(stderr,"[%d] %s:%d: (YENV=%p ENV=%p ASP=%p)\n", worker_id, \
|
||||
__FUNCTION__, __LINE__,YENV,ENV,ASP);
|
||||
#endif
|
||||
if ((v = check_alarm_fail_int( 2 PASS_REGS )) >= 0) {
|
||||
@ -1250,9 +1251,12 @@ interrupt_either( USES_REGS1 )
|
||||
if ((v = code_overflow(YENV PASS_REGS)) >= 0) {
|
||||
return v;
|
||||
}
|
||||
if ((v = stack_overflow(RepPredProp(Yap_GetPredPropByFunc(FunctorRestoreRegs1,0)), YENV, NEXTOP(P, Osbpp) PASS_REGS )) >= 0) {
|
||||
//P = NEXTOP(P, Osblp);
|
||||
if ((v = stack_overflow(RepPredProp(Yap_GetPredPropByFunc(FunctorRestoreRegs1,0)), YENV, NEXTOP(P,Osblp) PASS_REGS )) >= 0) {
|
||||
//P = PREVOP(P, Osblp);
|
||||
return v;
|
||||
}
|
||||
// P = PREVOP(P, Osblp);
|
||||
return interrupt_handler_either( MkIntTerm(0), RepPredProp(Yap_GetPredPropByFunc(FunctorRestoreRegs1,0)) PASS_REGS );
|
||||
}
|
||||
|
||||
|
336
C/c_interface.c
336
C/c_interface.c
@ -1260,17 +1260,17 @@ YAP_PutInSlot(Int slot, Term t)
|
||||
|
||||
|
||||
typedef Int (*CPredicate0)(void);
|
||||
typedef Int (*CPredicate1)(Int);
|
||||
typedef Int (*CPredicate2)(Int,Int);
|
||||
typedef Int (*CPredicate3)(Int,Int,Int);
|
||||
typedef Int (*CPredicate4)(Int,Int,Int,Int);
|
||||
typedef Int (*CPredicate5)(Int,Int,Int,Int,Int);
|
||||
typedef Int (*CPredicate6)(Int,Int,Int,Int,Int,Int);
|
||||
typedef Int (*CPredicate7)(Int,Int,Int,Int,Int,Int,Int);
|
||||
typedef Int (*CPredicate8)(Int,Int,Int,Int,Int,Int,Int,Int);
|
||||
typedef Int (*CPredicate9)(Int,Int,Int,Int,Int,Int,Int,Int,Int);
|
||||
typedef Int (*CPredicate10)(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int);
|
||||
typedef Int (*CPredicateV)(Int,Int,struct foreign_context *);
|
||||
typedef Int (*CPredicate1)(yhandle_t);
|
||||
typedef Int (*CPredicate2)(yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate3)(yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate4)(yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate5)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate6)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate7)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate8)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate9)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicate10)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t);
|
||||
typedef Int (*CPredicateV)(yhandle_t,yhandle_t,struct foreign_context *);
|
||||
|
||||
static Int
|
||||
execute_cargs(PredEntry *pe, CPredicate exec_code USES_REGS)
|
||||
@ -1279,119 +1279,85 @@ execute_cargs(PredEntry *pe, CPredicate exec_code USES_REGS)
|
||||
case 0:
|
||||
{
|
||||
CPredicate0 code0 = (CPredicate0)exec_code;
|
||||
return ((code0)());
|
||||
return code0();
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
CPredicate1 code1 = (CPredicate1)exec_code;
|
||||
return ((code1)(Yap_InitSlot(Deref(ARG1) PASS_REGS)));
|
||||
CPredicate1 code1 = (CPredicate1)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 1, & ARG1);
|
||||
return code1( a1 );
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
CPredicate2 code2 = (CPredicate2)exec_code;
|
||||
return ((code2)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS)));
|
||||
CPredicate2 code2 = (CPredicate2)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 2, & ARG1 );
|
||||
return code2(a1, a1+1);
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
CPredicate3 code3 = (CPredicate3)exec_code;
|
||||
return ((code3)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS)));
|
||||
CPredicate3 code3 = (CPredicate3)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 3, & ARG1 );
|
||||
return code3(a1, a1+1, a1+2);
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
CPredicate4 code4 = (CPredicate4)exec_code;
|
||||
return ((code4)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS)));
|
||||
CPredicate4 code4 = (CPredicate4)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 4, & ARG1 );
|
||||
return code4(a1, a1+1, a1+2, a1+3);
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
CPredicate5 code5 = (CPredicate5)exec_code;
|
||||
return ((code5)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG5) PASS_REGS)));
|
||||
{
|
||||
CPredicate5 code5 = (CPredicate5)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 5, & ARG1 );
|
||||
return code5(a1, a1+1, a1+2, a1+3, a1+4);
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
CPredicate6 code6 = (CPredicate6)exec_code;
|
||||
return ((code6)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG5) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG6) PASS_REGS)));
|
||||
CPredicate6 code6 = (CPredicate6)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 6, & ARG1 );
|
||||
return code6(a1, a1+1, a1+2, a1+3, a1+4, a1+5);
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
CPredicate7 code7 = (CPredicate7)exec_code;
|
||||
return ((code7)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG5) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG6) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG7) PASS_REGS)));
|
||||
{
|
||||
CPredicate7 code7 = (CPredicate7)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 7, & ARG1 );
|
||||
return code7(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6);
|
||||
}
|
||||
case 8:
|
||||
case 8:
|
||||
{
|
||||
CPredicate8 code8 = (CPredicate8)exec_code;
|
||||
return ((code8)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG5) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG6) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG7) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG8) PASS_REGS)));
|
||||
CPredicate8 code8 = (CPredicate8)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 8, & ARG1 );
|
||||
return code8(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, a1+7);
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
CPredicate9 code9 = (CPredicate9)exec_code;
|
||||
return ((code9)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG5) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG6) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG7) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG8) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG9) PASS_REGS)));
|
||||
{
|
||||
CPredicate9 code9 = (CPredicate9)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 9, & ARG1 );
|
||||
return code9(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, a1+7, a1+8);
|
||||
}
|
||||
case 10:
|
||||
{
|
||||
CPredicate10 code10 = (CPredicate10)exec_code;
|
||||
return ((code10)(Yap_InitSlot(Deref(ARG1) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG2) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG3) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG4) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG5) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG6) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG7) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG8) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG9) PASS_REGS),
|
||||
Yap_InitSlot(Deref(ARG10) PASS_REGS)));
|
||||
CPredicate10 code10 = (CPredicate10)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 10, & ARG1 );
|
||||
return code10(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, a1+7, a1+8, a1+9);
|
||||
}
|
||||
default:
|
||||
YAP_Error(SYSTEM_ERROR, TermNil, "YAP only supports SWI C-call with arity =< 10");
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
typedef uintptr_t (*CBPredicate)(struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate1)(Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate2)(Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate3)(Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate4)(Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate5)(Int,Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate6)(Int,Int,Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate7)(Int,Int,Int,Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate8)(Int,Int,Int,Int,Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate9)(Int,Int,Int,Int,Int,Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate10)(Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate0)(struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate1)(yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate2)(yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate3)(yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate4)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate5)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate6)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate7)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate8)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate9)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
typedef uintptr_t (*CBPredicate10)(yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,yhandle_t,struct foreign_context *);
|
||||
|
||||
static uintptr_t
|
||||
execute_cargs_back(PredEntry *pe, CPredicate exec_code, struct foreign_context *ctx USES_REGS)
|
||||
@ -1399,116 +1365,71 @@ execute_cargs_back(PredEntry *pe, CPredicate exec_code, struct foreign_context *
|
||||
switch (pe->ArityOfPE) {
|
||||
case 0:
|
||||
{
|
||||
CBPredicate code0 = (CBPredicate)exec_code;
|
||||
return ((code0)(ctx));
|
||||
}
|
||||
CBPredicate0 code0 = (CBPredicate0)exec_code;
|
||||
return code0(ctx);
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
CBPredicate1 code1 = (CBPredicate1)exec_code;
|
||||
return ((code1)(&B->cp_a1-LCL0,
|
||||
ctx));
|
||||
}
|
||||
CBPredicate1 code1 = (CBPredicate1)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 1, & B->cp_a1);
|
||||
return code1( a1, ctx);
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
CBPredicate2 code2 = (CBPredicate2)exec_code;
|
||||
uintptr_t val = ((code2)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
ctx));
|
||||
return val;
|
||||
CBPredicate2 code2 = (CBPredicate2)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 2, & B->cp_a1 );
|
||||
return code2(a1, a1+1, ctx);
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
CBPredicate3 code3 = (CBPredicate3)exec_code;
|
||||
return ((code3)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
ctx));
|
||||
CBPredicate3 code3 = (CBPredicate3)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 3, & B->cp_a1 );
|
||||
return code3(a1, a1+1, a1+2, ctx);
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
CBPredicate4 code4 = (CBPredicate4)exec_code;
|
||||
return ((code4)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
ctx));
|
||||
CBPredicate4 code4 = (CBPredicate4)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 4, & B->cp_a1 );
|
||||
return code4(a1, a1+1, a1+2, a1+3, ctx);
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
CBPredicate5 code5 = (CBPredicate5)exec_code;
|
||||
return ((code5)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
&B->cp_a5-LCL0,
|
||||
ctx));
|
||||
{
|
||||
CBPredicate5 code5 = (CBPredicate5)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 5, & B->cp_a1 );
|
||||
return code5(a1, a1+1, a1+2, a1+3, a1+4, ctx);
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
CBPredicate6 code6 = (CBPredicate6)exec_code;
|
||||
return ((code6)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
&B->cp_a5-LCL0,
|
||||
&B->cp_a6-LCL0,
|
||||
ctx));
|
||||
CBPredicate6 code6 = (CBPredicate6)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 6, & B->cp_a1 );
|
||||
return code6(a1, a1+1, a1+2, a1+3, a1+4, a1+5, ctx);
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
CBPredicate7 code7 = (CBPredicate7)exec_code;
|
||||
return ((code7)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
&B->cp_a5-LCL0,
|
||||
&B->cp_a6-LCL0,
|
||||
&B->cp_a7-LCL0,
|
||||
ctx));
|
||||
{
|
||||
CBPredicate7 code7 = (CBPredicate7)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 7, & B->cp_a1 );
|
||||
return code7(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, ctx);
|
||||
}
|
||||
case 8:
|
||||
case 8:
|
||||
{
|
||||
CBPredicate8 code8 = (CBPredicate8)exec_code;
|
||||
return ((code8)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
&B->cp_a5-LCL0,
|
||||
&B->cp_a6-LCL0,
|
||||
&B->cp_a7-LCL0,
|
||||
&B->cp_a8-LCL0,
|
||||
ctx));
|
||||
CBPredicate8 code8 = (CBPredicate8)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 8, & B->cp_a1 );
|
||||
return code8(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, a1+7, ctx);
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
CBPredicate9 code9 = (CBPredicate9)exec_code;
|
||||
return ((code9)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
&B->cp_a5-LCL0,
|
||||
&B->cp_a6-LCL0,
|
||||
&B->cp_a7-LCL0,
|
||||
&B->cp_a8-LCL0,
|
||||
&B->cp_a9-LCL0,
|
||||
ctx));
|
||||
{
|
||||
CBPredicate9 code9 = (CBPredicate9)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 9, & B->cp_a1 );
|
||||
return code9(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, a1+7, a1+8, ctx);
|
||||
}
|
||||
case 10:
|
||||
{
|
||||
CBPredicate10 code10 = (CBPredicate10)exec_code;
|
||||
return ((code10)(&B->cp_a1-LCL0,
|
||||
&B->cp_a2-LCL0,
|
||||
&B->cp_a3-LCL0,
|
||||
&B->cp_a4-LCL0,
|
||||
&B->cp_a5-LCL0,
|
||||
&B->cp_a6-LCL0,
|
||||
&B->cp_a7-LCL0,
|
||||
&B->cp_a8-LCL0,
|
||||
&B->cp_a9-LCL0,
|
||||
&B->cp_a10-LCL0,
|
||||
ctx));
|
||||
CBPredicate10 code10 = (CBPredicate10)exec_code;
|
||||
yhandle_t a1 = Yap_InitSlots( 10, & B->cp_a1 );
|
||||
return code10(a1, a1+1, a1+2, a1+3, a1+4, a1+5, a1+6, a1+7, a1+8, a1+9, ctx);
|
||||
}
|
||||
default:
|
||||
YAP_Error(SYSTEM_ERROR, TermNil, "YAP only supports SWI C-call with arity =< 10");
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
@ -1569,23 +1490,19 @@ YAP_Execute(PredEntry *pe, CPredicate exec_code)
|
||||
CACHE_REGS
|
||||
Int ret;
|
||||
Int OASP = LCL0-(CELL *)B;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
// Term omod = CurrentModule;
|
||||
//if (pe->PredFlags & CArgsPredFlag) {
|
||||
// CurrentModule = pe->ModuleOfPred;
|
||||
//}
|
||||
Int CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
if (pe->PredFlags & SWIEnvPredFlag) {
|
||||
CPredicateV codev = (CPredicateV)exec_code;
|
||||
struct foreign_context ctx;
|
||||
UInt i;
|
||||
Int sl = 0;
|
||||
|
||||
|
||||
ctx.engine = NULL;
|
||||
for (i=pe->ArityOfPE; i > 0; i--) {
|
||||
sl = Yap_InitSlot(XREGS[i] PASS_REGS);
|
||||
}
|
||||
PP = pe;
|
||||
ret = ((codev)(sl,0,&ctx));
|
||||
yhandle_t s0 = Yap_InitSlots(pe->ArityOfPE, &ARG1);
|
||||
PP = pe;
|
||||
ret = codev(s0,0,&ctx);
|
||||
} else if (pe->PredFlags & CArgsPredFlag) {
|
||||
PP = pe;
|
||||
ret = execute_cargs(pe, exec_code PASS_REGS);
|
||||
@ -1595,7 +1512,7 @@ YAP_Execute(PredEntry *pe, CPredicate exec_code)
|
||||
}
|
||||
PP = NULL;
|
||||
// check for junk: open frames, etc */
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
if (ret)
|
||||
complete_exit(((choiceptr)(LCL0-OASP)), FALSE, FALSE PASS_REGS);
|
||||
else
|
||||
@ -1638,9 +1555,9 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code)
|
||||
if (pe->PredFlags & CArgsPredFlag) {
|
||||
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
|
||||
} else {
|
||||
val = ((codev)(B->cp_args-LCL0,0,ctx));
|
||||
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1),0,ctx);
|
||||
}
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
PP = NULL;
|
||||
if (val == 0) {
|
||||
Term t;
|
||||
@ -1666,7 +1583,7 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code)
|
||||
}
|
||||
} else {
|
||||
Int ret = (exec_code)( PASS_REGS1 );
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
if (!ret) {
|
||||
Term t;
|
||||
|
||||
@ -1686,6 +1603,7 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
||||
{
|
||||
CACHE_REGS
|
||||
choiceptr oB = B;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
/* find out where we belong */
|
||||
while (B->cp_b < (choiceptr)top)
|
||||
B = B->cp_b;
|
||||
@ -1693,21 +1611,18 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
||||
Int val;
|
||||
CPredicateV codev = (CPredicateV)exec_code;
|
||||
struct foreign_context *ctx = (struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE,1));
|
||||
Int CurSlot;
|
||||
CELL *args = B->cp_args;
|
||||
|
||||
B = oB;
|
||||
PP = pe;
|
||||
ctx->control = FRG_CUTTED;
|
||||
ctx->engine = NULL; //(PL_local_data *)Yap_regp;
|
||||
/* for slots to work */
|
||||
CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
if (pe->PredFlags & CArgsPredFlag) {
|
||||
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
|
||||
} else {
|
||||
val = ((codev)(args-LCL0,0,ctx));
|
||||
val = codev(Yap_InitSlots(pe->ArityOfPE, args),0,ctx);
|
||||
}
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
|
||||
PP = NULL;
|
||||
// B = LCL0-(CELL*)oB;
|
||||
@ -1731,7 +1646,7 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
||||
/* for slots to work */
|
||||
CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
ret = (exec_code)( PASS_REGS1 );
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
if (!ret) {
|
||||
Term t;
|
||||
|
||||
@ -1752,8 +1667,9 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code)
|
||||
{
|
||||
CACHE_REGS
|
||||
/* for slots to work */
|
||||
Int CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
UInt ocp = LCL0-(CELL *)B;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) {
|
||||
Int val;
|
||||
CPredicateV codev = (CPredicateV)exec_code;
|
||||
@ -1764,9 +1680,9 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code)
|
||||
if (pe->PredFlags & CArgsPredFlag) {
|
||||
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
|
||||
} else {
|
||||
val = ((codev)(B->cp_args-LCL0,0,ctx));
|
||||
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1),0,ctx);
|
||||
}
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
/* we are below the original choice point ?? */
|
||||
/* make sure we clean up the frames left by the user */
|
||||
PP = NULL;
|
||||
@ -1795,7 +1711,7 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code)
|
||||
return complete_exit(((choiceptr)(LCL0-ocp)), FALSE, FALSE PASS_REGS);
|
||||
} else {
|
||||
Int ret = (exec_code)( PASS_REGS1 );
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
if (!ret) {
|
||||
Term t;
|
||||
|
||||
@ -2396,7 +2312,6 @@ YAP_RunGoal(Term t)
|
||||
CACHE_REGS
|
||||
Term out;
|
||||
yamop *old_CP = CP;
|
||||
Int CurSlot = LOCAL_CurSlot;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
LOCAL_AllowRestart = FALSE;
|
||||
@ -2420,8 +2335,6 @@ YAP_RunGoal(Term t)
|
||||
LOCAL_AllowRestart = FALSE;
|
||||
SET_ASP(ENV, E_CB*sizeof(CELL));
|
||||
// make sure the slots are ok.
|
||||
ASP = LCL0-(CurSlot+2+IntOfTerm(LCL0[-CurSlot-1]));
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
@ -2877,6 +2790,7 @@ do_bootfile (char *bootfilename)
|
||||
Term term_end_of_file = MkAtomTerm(AtomEof);
|
||||
Term term_true = YAP_MkAtomTerm(AtomTrue);
|
||||
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"),1);
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
|
||||
/* consult boot.pl */
|
||||
/* the consult mode does not matter here, really */
|
||||
@ -2893,9 +2807,9 @@ do_bootfile (char *bootfilename)
|
||||
while (!eof_found)
|
||||
{
|
||||
CACHE_REGS
|
||||
Int CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
t = YAP_Read(bootfile);
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
if (eof_found) {
|
||||
break;
|
||||
}
|
||||
@ -3287,8 +3201,7 @@ YAP_Reset(yap_reset_t mode)
|
||||
/* always have an empty slots for people to use */
|
||||
P = CP = YESCODE;
|
||||
// ensure that we have slots where we need them
|
||||
LOCAL_CurSlot = 0;
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_CloseSlots(1 PASS_REGS);
|
||||
RECOVER_MACHINE_REGS();
|
||||
return res;
|
||||
}
|
||||
@ -3882,19 +3795,14 @@ X_API yhandle_t
|
||||
YAP_ArgsToSlots(int n)
|
||||
{
|
||||
CACHE_REGS
|
||||
yhandle_t slot = Yap_NewSlots(n PASS_REGS);
|
||||
CELL *ptr0 = LCL0+slot, *ptr1=&ARG1;
|
||||
while (n--) {
|
||||
*ptr0++ = *ptr1++;
|
||||
}
|
||||
return slot;
|
||||
return Yap_NewSlots(n PASS_REGS);
|
||||
}
|
||||
|
||||
X_API void
|
||||
YAP_SlotsToArgs(int n, yhandle_t slot)
|
||||
{
|
||||
CACHE_REGS
|
||||
CELL *ptr0 = LCL0+slot, *ptr1=&ARG1;
|
||||
CELL *ptr0 = Yap_AddressFromSlot(slot PASS_REGS), *ptr1=&ARG1;
|
||||
while (n--) {
|
||||
*ptr1++ = *ptr0++;
|
||||
}
|
||||
@ -3907,7 +3815,7 @@ YAP_signal(int sig)
|
||||
}
|
||||
|
||||
X_API int
|
||||
YAP_SetYAPFlag(yap_flag_t flag, int val)
|
||||
YAP_SetYAPFlag(yap_flag_t flag, int val)
|
||||
{
|
||||
switch (flag) {
|
||||
case YAPC_ENABLE_GC:
|
||||
|
5
C/exec.c
5
C/exec.c
@ -1844,7 +1844,7 @@ Yap_InitYaamRegs( int myworker_id )
|
||||
h0var = MkVarTerm();
|
||||
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
|
||||
#endif
|
||||
REMOTE_CurSlot(myworker_id) = 0;
|
||||
REMOTE_CurSlot(myworker_id) = 1; /* This function has direct access to the Handles class AKA InitSlot */
|
||||
h0var = MkVarTerm();
|
||||
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
|
||||
REMOTE_GcCurrentPhase(myworker_id) = 0L;
|
||||
@ -1860,9 +1860,6 @@ Yap_InitYaamRegs( int myworker_id )
|
||||
if (REMOTE_top_dep_fr(myworker_id))
|
||||
DepFr_cons_cp(REMOTE_top_dep_fr(myworker_id)) = NORM_CP(B);
|
||||
#endif
|
||||
// make sure we have slots in case we don go through the top-level */
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
|
||||
}
|
||||
|
||||
static Int
|
||||
|
82
C/heapgc.c
Executable file → Normal file
82
C/heapgc.c
Executable file → Normal file
@ -44,11 +44,11 @@ static void mark_external_reference(CELL * CACHE_TYPE);
|
||||
static void mark_db_fixed(CELL * CACHE_TYPE);
|
||||
static void mark_regs(tr_fr_ptr CACHE_TYPE);
|
||||
static void mark_trail(tr_fr_ptr, tr_fr_ptr, CELL *, choiceptr CACHE_TYPE);
|
||||
static void mark_environments(CELL *, OPREG, CELL * CACHE_TYPE);
|
||||
static void mark_environments(CELL *, size_t, CELL * CACHE_TYPE);
|
||||
static void mark_choicepoints(choiceptr, tr_fr_ptr, int CACHE_TYPE);
|
||||
static void into_relocation_chain(CELL *, CELL * CACHE_TYPE);
|
||||
static void sweep_trail(choiceptr, tr_fr_ptr CACHE_TYPE);
|
||||
static void sweep_environments(CELL *, OPREG, CELL * CACHE_TYPE);
|
||||
static void sweep_environments(CELL *, size_t, CELL * CACHE_TYPE);
|
||||
static void sweep_choicepoints(choiceptr CACHE_TYPE);
|
||||
static void compact_heap( CACHE_TYPE1 );
|
||||
static void update_relocation_chain(CELL *, CELL * CACHE_TYPE);
|
||||
@ -446,8 +446,17 @@ push_registers(Int num_regs, yamop *nextop USES_REGS)
|
||||
TrailTerm(TR+1) = LOCAL_AttsMutableList;
|
||||
TR += 2;
|
||||
#endif
|
||||
{
|
||||
CELL *curslot = LOCAL_SlotBase,
|
||||
*topslot = LOCAL_SlotBase + LOCAL_CurSlot;
|
||||
while (curslot < topslot) {
|
||||
// printf("%p <- %p\n", TR, topslot);
|
||||
check_pr_trail(TR PASS_REGS);
|
||||
TrailTerm(TR++) = *curslot++;
|
||||
}
|
||||
}
|
||||
for (i = 1; i <= num_regs; i++) {
|
||||
check_pr_trail(TR PASS_REGS);
|
||||
check_pr_trail(TR PASS_REGS);
|
||||
TrailTerm(TR++) = (CELL) XREGS[i];
|
||||
}
|
||||
/* push any live registers we might have hanging around */
|
||||
@ -544,6 +553,16 @@ pop_registers(Int num_regs, yamop *nextop USES_REGS)
|
||||
LOCAL_AttsMutableList = TrailTerm(ptr++);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// copy slots back
|
||||
{
|
||||
CELL *curslot = LOCAL_SlotBase,
|
||||
*topslot = LOCAL_SlotBase + LOCAL_CurSlot;
|
||||
while (curslot < topslot) {
|
||||
*curslot++ = TrailTerm(ptr++);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= num_regs; i++)
|
||||
XREGS[i] = TrailTerm(ptr++);
|
||||
/* pop any live registers we might have hanging around */
|
||||
@ -1553,14 +1572,14 @@ mark_regs(tr_fr_ptr old_TR USES_REGS)
|
||||
/* mark all heap objects accessible from a chain of environments */
|
||||
|
||||
static void
|
||||
mark_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
|
||||
mark_environments(CELL_PTR gc_ENV, size_t size, CELL *pvbmap USES_REGS)
|
||||
{
|
||||
CELL_PTR saved_var;
|
||||
while (gc_ENV != NULL) { /* no more environments */
|
||||
Int bmap = 0;
|
||||
int currv = 0;
|
||||
|
||||
// printf("MARK %p--%p\n", gc_ENV, gc_ENV-size);
|
||||
//fprintf(stderr,"ENV %p %ld\n", gc_ENV, size);
|
||||
#ifdef DEBUG
|
||||
if (size < 0 || size > 512)
|
||||
fprintf(stderr,"OOPS in GC: env size for %p is " UInt_FORMAT "\n", gc_ENV, (CELL)size);
|
||||
@ -1706,7 +1725,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
|
||||
RESET_VARIABLE(&TrailVal(trail_base));
|
||||
#endif
|
||||
} else if (hp < (CELL *)LOCAL_GlobalBase || hp > (CELL *)LOCAL_TrailTop) {
|
||||
/* pointers from the Heap back into the trail are process in mark_regs. */
|
||||
/* 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 *)LOCAL_TrailBase) {
|
||||
/* clean the trail, avoid dangling pointers! */
|
||||
@ -1916,24 +1935,6 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
|
||||
#endif /* TABLING */
|
||||
|
||||
|
||||
static void
|
||||
mark_slots( USES_REGS1 )
|
||||
{
|
||||
Int curslot = LOCAL_CurSlot;
|
||||
while (curslot) {
|
||||
CELL *ptr = LCL0-curslot;
|
||||
Int ns = IntegerOfTerm(ptr[-1]);
|
||||
curslot = IntegerOfTerm(ptr[0]);
|
||||
ptr-=2;
|
||||
while (ns > 0) {
|
||||
mark_external_reference(ptr PASS_REGS);
|
||||
ptr--;
|
||||
ns--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef TABLING
|
||||
static choiceptr
|
||||
youngest_cp(choiceptr gc_B, dep_fr_ptr *depfrp)
|
||||
@ -1980,6 +1981,10 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
|
||||
register OPCODE op;
|
||||
yamop *rtp = gc_B->cp_ap;
|
||||
|
||||
/* if (gc_B->cp_ap) */
|
||||
/* fprintf(stderr,"B %p->%p %s\n", gc_B, gc_B->cp_b, Yap_op_names[Yap_op_from_opcode(gc_B->cp_ap->opc)]) ; */
|
||||
/* else */
|
||||
/* fprintf(stderr,"B %p->%p\n", gc_B, gc_B->cp_b); */
|
||||
mark_db_fixed((CELL *)rtp PASS_REGS);
|
||||
#ifdef DETERMINISTIC_TABLING
|
||||
if (!IS_DET_GEN_CP(gc_B))
|
||||
@ -2866,7 +2871,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR USES_REGS)
|
||||
*/
|
||||
|
||||
static void
|
||||
sweep_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
|
||||
sweep_environments(CELL_PTR gc_ENV, size_t size, CELL *pvbmap USES_REGS)
|
||||
{
|
||||
CELL_PTR saved_var;
|
||||
|
||||
@ -2928,29 +2933,6 @@ sweep_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sweep_slots( USES_REGS1 )
|
||||
{
|
||||
Int curslot = LOCAL_CurSlot;
|
||||
while (curslot) {
|
||||
CELL *ptr = LCL0-curslot;
|
||||
Int ns = IntOfTerm(ptr[-1]);
|
||||
curslot = IntegerOfTerm(ptr[0]);
|
||||
ptr-=2;
|
||||
while (ns > 0) {
|
||||
CELL cp_cell = *ptr;
|
||||
if (MARKED_PTR(ptr)) {
|
||||
UNMARK(ptr);
|
||||
if (HEAP_PTR(cp_cell)) {
|
||||
into_relocation_chain(ptr, GET_NEXT(cp_cell) PASS_REGS);
|
||||
}
|
||||
}
|
||||
ptr--;
|
||||
ns--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sweep_b(choiceptr gc_B, UInt arity USES_REGS)
|
||||
{
|
||||
@ -3816,7 +3798,6 @@ marking_phase(tr_fr_ptr old_TR, CELL *current_env, yamop *curp USES_REGS)
|
||||
LOCAL_cont_top = (cont *)LOCAL_db_vec;
|
||||
/* These two must be marked first so that our trail optimisation won't lose
|
||||
values */
|
||||
mark_slots( PASS_REGS1 );
|
||||
mark_regs(old_TR PASS_REGS); /* active registers & trail */
|
||||
/* active environments */
|
||||
mark_environments(current_env, EnvSize(curp), EnvBMap(curp) PASS_REGS);
|
||||
@ -3869,7 +3850,6 @@ compaction_phase(tr_fr_ptr old_TR, CELL *current_env, yamop *curp USES_REGS)
|
||||
sweep_oldgen(LOCAL_HGEN, CurrentH0 PASS_REGS);
|
||||
}
|
||||
}
|
||||
sweep_slots( PASS_REGS1 );
|
||||
sweep_environments(current_env, EnvSize(curp), EnvBMap(curp) PASS_REGS);
|
||||
sweep_choicepoints(B PASS_REGS);
|
||||
sweep_trail(B, old_TR PASS_REGS);
|
||||
@ -4344,5 +4324,5 @@ void
|
||||
Yap_inc_mark_variable()
|
||||
{
|
||||
CACHE_REGS
|
||||
LOCAL_total_marked++;
|
||||
LOCAL_total_marked++;
|
||||
}
|
||||
|
17
C/init.c
17
C/init.c
@ -1234,6 +1234,23 @@ InitScratchPad(int wid)
|
||||
REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE;
|
||||
}
|
||||
|
||||
CELL *
|
||||
InitHandles(int wid) {
|
||||
size_t initial_slots = 1024;
|
||||
CELL *handles;
|
||||
|
||||
REMOTE_CurSlot(wid) = 1;
|
||||
REMOTE_NSlots(wid) = initial_slots;
|
||||
handles = malloc(initial_slots * sizeof(CELL));
|
||||
|
||||
if(handles == NULL) {
|
||||
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "No space for handles at " __FILE__ " : %d", __LINE__);
|
||||
}
|
||||
|
||||
RESET_VARIABLE(handles);
|
||||
return handles;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_CloseScratchPad(void)
|
||||
{
|
||||
|
@ -48,6 +48,7 @@ p_load_foreign( USES_REGS1 )
|
||||
Term t, t1;
|
||||
StringList new;
|
||||
Int returncode = FALSE;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
|
||||
strcpy(LOCAL_ErrorSay,"Invalid arguments");
|
||||
|
||||
@ -81,9 +82,9 @@ p_load_foreign( USES_REGS1 )
|
||||
|
||||
/* call the OS specific function for dynamic loading */
|
||||
if(Yap_LoadForeign(ofiles,libs,InitProcName,&InitProc)==LOAD_SUCCEEDED) {
|
||||
Int CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
(*InitProc)();
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
returncode = TRUE;
|
||||
}
|
||||
|
||||
|
11
C/pl-yap.c
11
C/pl-yap.c
@ -858,10 +858,11 @@ char *
|
||||
Yap_TermToString(Term t, char *s, size_t sz, size_t *length, int *encoding, int flags)
|
||||
{
|
||||
CACHE_REGS
|
||||
Int l, CurSlot;
|
||||
Int l;
|
||||
Int myASP = LCL0-ASP;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
|
||||
CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
l = Yap_InitSlot(t PASS_REGS );
|
||||
|
||||
{ IOENC encodings[3];
|
||||
@ -900,14 +901,14 @@ Yap_TermToString(Term t, char *s, size_t sz, size_t *length, int *encoding, int
|
||||
if (r == buf) {
|
||||
char *bf = malloc(*length+1);
|
||||
if (!bf) {
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
ASP = LCL0-myASP;
|
||||
return NULL;
|
||||
}
|
||||
strncpy(bf,buf,*length+1);
|
||||
r = bf;
|
||||
}
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
ASP = LCL0-myASP;
|
||||
return r;
|
||||
} else
|
||||
@ -919,7 +920,7 @@ Yap_TermToString(Term t, char *s, size_t sz, size_t *length, int *encoding, int
|
||||
Sfree(r);
|
||||
}
|
||||
}
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
ASP = LCL0-myASP;
|
||||
return NULL;
|
||||
}
|
||||
|
7
C/save.c
7
C/save.c
@ -633,7 +633,8 @@ do_save(int mode USES_REGS) {
|
||||
static Int
|
||||
p_save2( USES_REGS1 )
|
||||
{
|
||||
Int res, CurSlot;
|
||||
Int res;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
|
||||
Term t;
|
||||
#ifdef YAPOR
|
||||
@ -656,9 +657,9 @@ p_save2( USES_REGS1 )
|
||||
if (!Yap_unify(ARG2,MkIntTerm(1)))
|
||||
return FALSE;
|
||||
which_save = 2;
|
||||
CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
res = do_save(DO_EVERYTHING PASS_REGS);
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -519,7 +519,7 @@ getchr__(IOSTREAM *inp)
|
||||
#define getchr(inp) getchr__(inp)
|
||||
#define getchrq(inp) Sgetcode(inp)
|
||||
|
||||
EXTERN inline int
|
||||
static int
|
||||
GetCurInpPos (IOSTREAM *inp_stream)
|
||||
{
|
||||
return inp_stream->posbuf.lineno;
|
||||
|
7
C/text.c
7
C/text.c
@ -395,6 +395,7 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
||||
{
|
||||
char *s;
|
||||
wchar_t *ws;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
|
||||
/* we know what the term is */
|
||||
switch (inp->type & YAP_TYPE_MASK) {
|
||||
@ -523,7 +524,7 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
||||
return (void *)inp->val.w;
|
||||
case YAP_STRING_LITERAL:
|
||||
{
|
||||
Int CurSlot = Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
if (buf) s = buf;
|
||||
else s = Yap_PreAllocCodeSpace();
|
||||
size_t sz = LOCAL_MAX_SIZE-1;
|
||||
@ -534,10 +535,10 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
||||
if ( ! PL_write_term(fd, Yap_InitSlot(inp->val.t PASS_REGS), 1200, 0) ||
|
||||
Sputcode(EOS, fd) < 0 ||
|
||||
Sflush(fd) < 0 ) {
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
AUX_ERROR( inp->val.t, LOCAL_MAX_SIZE, s, char);
|
||||
} else {
|
||||
LOCAL_CurSlot = CurSlot;
|
||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
||||
}
|
||||
*enc = YAP_UTF8;
|
||||
*lengp = strlen(s);
|
||||
|
117
H/YapHandles.h
117
H/YapHandles.h
@ -49,17 +49,15 @@ This section lists the main internal functions for slot management. These functi
|
||||
*************************************************************************************************/
|
||||
|
||||
/// @brief start a new set of slots, linking them to the last active slots (who may, or not, be active).
|
||||
/// Also states how many slots we had when we entered a segment of code.
|
||||
static inline yhandle_t
|
||||
|
||||
Yap_StartSlots( USES_REGS1 ) {
|
||||
yhandle_t CurSlot = LOCAL_CurSlot;
|
||||
// if (CurSlot == LCL0-(ASP+(IntOfTerm(ASP[0])+2)))
|
||||
// return CurSlot;
|
||||
/* new slot */
|
||||
*--ASP = MkIntegerTerm(CurSlot);
|
||||
LOCAL_CurSlot = LCL0-ASP;
|
||||
*--ASP = MkIntTerm(0);
|
||||
*--ASP = MkIntTerm(0);
|
||||
return CurSlot;
|
||||
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
|
||||
if (LOCAL_CurSlot < 0) {
|
||||
Yap_Error( SYSTEM_ERROR, 0L, " StartSlots = %ld", LOCAL_CurSlot);
|
||||
}
|
||||
return LOCAL_CurSlot;
|
||||
}
|
||||
|
||||
|
||||
@ -72,90 +70,115 @@ Yap_CloseSlots( yhandle_t slot USES_REGS ) {
|
||||
/// @brief report the current position of the slots, assuming that they occupy the top of the stack.
|
||||
static inline yhandle_t
|
||||
Yap_CurrentSlot( USES_REGS1 ) {
|
||||
return IntOfTerm(ASP[0]);
|
||||
return LOCAL_CurSlot;
|
||||
}
|
||||
|
||||
/// @brief read from a slot.
|
||||
static inline Term
|
||||
Yap_GetFromSlot(yhandle_t slot USES_REGS)
|
||||
{
|
||||
return(Deref(LCL0[slot]));
|
||||
return(Deref(LOCAL_SlotBase[slot]));
|
||||
}
|
||||
|
||||
/// @brief read from a slot. but does not try to dereference the slot.
|
||||
static inline Term
|
||||
Yap_GetDerefedFromSlot(yhandle_t slot USES_REGS)
|
||||
{
|
||||
return LCL0[slot];
|
||||
return LOCAL_SlotBase[slot];
|
||||
}
|
||||
|
||||
/// @brief read the object in a slot. but do not try to dereference the slot.
|
||||
static inline Term
|
||||
Yap_GetPtrFromSlot(yhandle_t slot USES_REGS)
|
||||
{
|
||||
return(LCL0[slot]);
|
||||
return LOCAL_SlotBase[slot];
|
||||
}
|
||||
|
||||
/// @brief get the memory address of a slot
|
||||
static inline Term *
|
||||
Yap_AddressFromSlot(yhandle_t slot USES_REGS)
|
||||
{
|
||||
return(LCL0+slot);
|
||||
return LOCAL_SlotBase+slot;
|
||||
}
|
||||
|
||||
/// @brief store term in a slot
|
||||
static inline void
|
||||
Yap_PutInSlot(yhandle_t slot, Term t USES_REGS)
|
||||
{
|
||||
LCL0[slot] = t;
|
||||
LOCAL_SlotBase[slot] = t;
|
||||
}
|
||||
|
||||
/// @brief allocate n empty new slots
|
||||
static inline yhandle_t
|
||||
Yap_NewSlots(int n USES_REGS)
|
||||
#define max(X,Y) ( X > Y ? X : Y )
|
||||
|
||||
static inline void
|
||||
ensure_slots(int N)
|
||||
{
|
||||
yhandle_t old_slots = IntOfTerm(ASP[0]), oldn = n;
|
||||
while (n > 0) {
|
||||
RESET_VARIABLE(ASP);
|
||||
ASP--;
|
||||
n--;
|
||||
if (LOCAL_CurSlot+N >= LOCAL_NSlots) {
|
||||
size_t inc = max(16*1024, LOCAL_NSlots/2); // measured in cells
|
||||
LOCAL_SlotBase = (CELL *)realloc( LOCAL_SlotBase, (inc + LOCAL_NSlots )*sizeof(CELL));
|
||||
if (!LOCAL_SlotBase) {
|
||||
unsigned long int kneeds = ((inc + LOCAL_NSlots )*sizeof(CELL))/1024;
|
||||
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "Out of memory for the term handles (term_t) aka slots, l needed", kneeds);
|
||||
}
|
||||
}
|
||||
ASP[old_slots+oldn+1] = ASP[0] = MkIntTerm(old_slots+oldn);
|
||||
return((ASP+1)-LCL0);
|
||||
}
|
||||
|
||||
/// @brief report the number of slots in the current
|
||||
static inline size_t
|
||||
Yap_countSlots( USES_REGS1 )
|
||||
{
|
||||
return IntOfTerm(ASP[0]);;
|
||||
}
|
||||
|
||||
/// @brief create a new slot with term t
|
||||
static inline Int
|
||||
Yap_InitSlot(Term t USES_REGS)
|
||||
{
|
||||
yhandle_t old_slots = IntOfTerm(ASP[0]);
|
||||
*ASP = t;
|
||||
ASP--;
|
||||
ASP[old_slots+2] = ASP[0] = MkIntTerm(old_slots+1);
|
||||
return((ASP+1)-LCL0);
|
||||
yhandle_t old_slots = LOCAL_CurSlot;
|
||||
|
||||
ensure_slots( 1 );
|
||||
LOCAL_SlotBase[old_slots] = t;
|
||||
LOCAL_CurSlot++;
|
||||
return old_slots;
|
||||
}
|
||||
|
||||
/// @brief allocate n empty new slots
|
||||
static inline yhandle_t
|
||||
Yap_NewSlots(int n USES_REGS)
|
||||
{
|
||||
yhandle_t old_slots = LOCAL_CurSlot;
|
||||
int i;
|
||||
|
||||
ensure_slots(n);
|
||||
for (i = 0; i< n; i++) {
|
||||
RESET_VARIABLE(Yap_AddressFromSlot(old_slots+i) );
|
||||
}
|
||||
LOCAL_CurSlot += n;
|
||||
return old_slots;
|
||||
}
|
||||
|
||||
#define Yap_InitSlots(n, ts) Yap_InitSlots__(n, ts PASS_REGS)
|
||||
|
||||
/// @brief create n new slots with terms ts[]
|
||||
static inline yhandle_t
|
||||
Yap_InitSlots__(int n, Term *ts USES_REGS)
|
||||
{
|
||||
yhandle_t old_slots = LOCAL_CurSlot;
|
||||
int i;
|
||||
|
||||
ensure_slots( n );
|
||||
for (i=0; i< n; i++)
|
||||
LOCAL_SlotBase[old_slots+i] = ts[i];
|
||||
LOCAL_CurSlot += n;
|
||||
return old_slots;
|
||||
}
|
||||
|
||||
/// @brief Succeeds if it is to recover the space allocated for $n$ contiguos slots starting at topSlot.
|
||||
static inline int
|
||||
static inline bool
|
||||
Yap_RecoverSlots(int n, yhandle_t topSlot USES_REGS)
|
||||
{
|
||||
yhandle_t old_slots = IntOfTerm(ASP[0]),
|
||||
new_slots = old_slots-n;
|
||||
if (old_slots < n) {
|
||||
return FALSE;
|
||||
if (topSlot + n < LOCAL_CurSlot)
|
||||
return false;
|
||||
#ifdef DEBUG
|
||||
if (topSlot + n > LOCAL_CurSlot) {
|
||||
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "Inconsistent slot state in Yap_RecoverSlots.");
|
||||
return false;
|
||||
}
|
||||
if (ASP+1 != LCL0+topSlot)
|
||||
return FALSE;
|
||||
ASP += n;
|
||||
ASP[new_slots+1] = ASP[0] = MkIntTerm(new_slots);
|
||||
return TRUE;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1065,7 +1065,7 @@ OPCODE ENV_ToOp(yamop *cp)
|
||||
}
|
||||
|
||||
static inline
|
||||
UInt EnvSize(yamop *cp)
|
||||
size_t EnvSize(yamop *cp)
|
||||
{
|
||||
return ((-ENV_Size(cp))/(OPREG)sizeof(CELL));
|
||||
}
|
||||
|
@ -421,6 +421,10 @@
|
||||
|
||||
#define LOCAL_CurSlot LOCAL->CurSlot_
|
||||
#define REMOTE_CurSlot(wid) REMOTE(wid)->CurSlot_
|
||||
#define LOCAL_NSlots LOCAL->NSlots_
|
||||
#define REMOTE_NSlots(wid) REMOTE(wid)->NSlots_
|
||||
#define LOCAL_SlotBase LOCAL->SlotBase_
|
||||
#define REMOTE_SlotBase(wid) REMOTE(wid)->SlotBase_
|
||||
|
||||
#define LOCAL_Mutexes LOCAL->Mutexes_
|
||||
#define REMOTE_Mutexes(wid) REMOTE(wid)->Mutexes_
|
||||
|
@ -236,6 +236,8 @@ typedef struct worker_local {
|
||||
struct scan_atoms* search_atoms_;
|
||||
|
||||
yhandle_t CurSlot_;
|
||||
yhandle_t NSlots_;
|
||||
CELL* SlotBase_;
|
||||
|
||||
struct swi_mutex* Mutexes_;
|
||||
Term SourceModule_;
|
||||
|
@ -236,6 +236,8 @@ static void InitWorker(int wid) {
|
||||
|
||||
|
||||
REMOTE_CurSlot(wid) = 0;
|
||||
REMOTE_NSlots(wid) = 0;
|
||||
REMOTE_SlotBase(wid) = InitHandles(wid);
|
||||
|
||||
REMOTE_Mutexes(wid) = NULL;
|
||||
REMOTE_SourceModule(wid) = 0;
|
||||
|
@ -240,4 +240,6 @@ static void RestoreWorker(int wid USES_REGS) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -2302,11 +2302,10 @@ PL_open_foreign_frame(void)
|
||||
#ifdef DEPTH_LIMIT
|
||||
cp_b->cp_depth = DEPTH;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
cp_b->cp_a1 = MkIntTerm(LOCAL_CurSlot);
|
||||
cp_b->cp_a1 = MkIntTerm(Yap_StartSlots( PASS_REGS1 ));
|
||||
HB = HR;
|
||||
B = cp_b;
|
||||
ASP = (CELL *)B;
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
|
||||
return (fid_t)(LCL0-(CELL*)cp_b);
|
||||
}
|
||||
@ -2316,7 +2315,7 @@ PL_close_foreign_frame(fid_t f)
|
||||
{
|
||||
CACHE_REGS
|
||||
choiceptr cp_b = (choiceptr)(LCL0-(UInt)f);
|
||||
LOCAL_CurSlot = IntOfTerm(cp_b->cp_a1);
|
||||
Yap_CloseSlots( IntOfTerm(cp_b->cp_a1) );
|
||||
B = cp_b;
|
||||
HB = B->cp_h;
|
||||
Yap_TrimTrail();
|
||||
@ -2327,14 +2326,7 @@ PL_close_foreign_frame(fid_t f)
|
||||
DEPTH = cp_b->cp_depth;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
HB = B->cp_h;
|
||||
if (LOCAL_CurSlot) {
|
||||
/* we can assume there was a slot before */
|
||||
CELL *old_slot;
|
||||
old_slot = LCL0-(LOCAL_CurSlot);
|
||||
ASP = old_slot-(2+IntOfTerm(old_slot[-1]));
|
||||
} else {
|
||||
ASP = ((CELL *)(cp_b+1))+1;
|
||||
}
|
||||
ASP = ((CELL *)(cp_b+1))+1;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2350,7 +2342,7 @@ X_API void
|
||||
PL_rewind_foreign_frame(fid_t f)
|
||||
{
|
||||
CACHE_REGS
|
||||
choiceptr cp_b = (choiceptr)(LCL0-(UInt)f);
|
||||
choiceptr cp_b = (choiceptr)(LCL0-(UInt)f);
|
||||
if (B != cp_b) {
|
||||
while (B->cp_b != cp_b)
|
||||
B = B->cp_b;
|
||||
@ -2358,8 +2350,7 @@ PL_rewind_foreign_frame(fid_t f)
|
||||
backtrack();
|
||||
// restore to original location
|
||||
ASP = (CELL *)B;
|
||||
LOCAL_CurSlot = IntOfTerm(B->cp_a1);
|
||||
Yap_StartSlots( PASS_REGS1 );
|
||||
Yap_CloseSlots( IntOfTerm(cp_b->cp_a1) );
|
||||
}
|
||||
|
||||
X_API void
|
||||
@ -2373,7 +2364,7 @@ PL_discard_foreign_frame(fid_t f)
|
||||
B = B->cp_b;
|
||||
backtrack();
|
||||
}
|
||||
LOCAL_CurSlot = IntOfTerm(cp_b->cp_a1);
|
||||
Yap_CloseSlots( IntOfTerm(cp_b->cp_a1) );
|
||||
B = cp_b->cp_b;
|
||||
CP = cp_b->cp_cp;
|
||||
ENV = cp_b->cp_env;
|
||||
@ -2382,13 +2373,7 @@ PL_discard_foreign_frame(fid_t f)
|
||||
DEPTH = cp_b->cp_depth;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
/* we can assume there was a slot before */
|
||||
if (LOCAL_CurSlot) {
|
||||
CELL *old_slot;
|
||||
old_slot = LCL0-(LOCAL_CurSlot);
|
||||
ASP = old_slot-(2+IntOfTerm(old_slot[-1]));
|
||||
} else {
|
||||
ASP = ((CELL *)(cp_b+1))+1;
|
||||
}
|
||||
ASP = ((CELL *)(cp_b+1))+1;
|
||||
}
|
||||
|
||||
X_API qid_t PL_open_query(module_t ctx, int flags, predicate_t p, term_t t0)
|
||||
|
@ -270,6 +270,8 @@ struct scan_atoms* search_atoms void
|
||||
|
||||
// Slots
|
||||
yhandle_t CurSlot =0
|
||||
yhandle_t NSlots =0
|
||||
CELL* SlotBase =InitHandles(wid)
|
||||
|
||||
// Mutexes
|
||||
struct swi_mutex* Mutexes =NULL
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit d0d1ee4d58373cc611676103e0a50a3ae451a023
|
||||
Subproject commit 9972458293415b2d72276bd67875767bfeed00df
|
@ -1 +1 @@
|
||||
Subproject commit 34d9f645721645aac9f4f40c815fe4fe2c6511e6
|
||||
Subproject commit 36f99e3c3c978fef25f899dc4fab1ffee334d73c
|
@ -1 +1 @@
|
||||
Subproject commit 9becd0f0619379d30b26b14df642872a373f3fa4
|
||||
Subproject commit 5e423b2d029c9dbf320649b08fc0253d64853257
|
Reference in New Issue
Block a user