new slot implementation
This commit is contained in:
parent
bf215e68a2
commit
5a668febd9
@ -1230,14 +1230,14 @@ X_API Term *
|
|||||||
YAP_AddressFromSlot(Int slot)
|
YAP_AddressFromSlot(Int slot)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return Yap_AddressFromSlot(slot PASS_REGS);
|
return Yap_AddressFromSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API Term *
|
X_API Term *
|
||||||
YAP_AddressOfTermInSlot(Int slot)
|
YAP_AddressOfTermInSlot(Int slot)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term *b = Yap_AddressFromSlot(slot PASS_REGS);
|
Term *b = Yap_AddressFromSlot(slot);
|
||||||
Term a = *b;
|
Term a = *b;
|
||||||
restart:
|
restart:
|
||||||
if (!IsVarTerm(a)) {
|
if (!IsVarTerm(a)) {
|
||||||
@ -1512,7 +1512,7 @@ YAP_Execute(PredEntry *pe, CPredicate exec_code)
|
|||||||
}
|
}
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
// check for junk: open frames, etc */
|
// check for junk: open frames, etc */
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
if (ret)
|
if (ret)
|
||||||
complete_exit(((choiceptr)(LCL0-OASP)), FALSE, FALSE PASS_REGS);
|
complete_exit(((choiceptr)(LCL0-OASP)), FALSE, FALSE PASS_REGS);
|
||||||
else
|
else
|
||||||
@ -1542,7 +1542,7 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code)
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
CELL ocp = LCL0-(CELL *)B;
|
CELL ocp = LCL0-(CELL *)B;
|
||||||
/* for slots to work */
|
/* for slots to work */
|
||||||
Int CurSlot = Yap_StartSlots( PASS_REGS1 );
|
Int CurSlot = Yap_StartSlots( );
|
||||||
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag|ModuleTransparentPredFlag)) {
|
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag|ModuleTransparentPredFlag)) {
|
||||||
uintptr_t val;
|
uintptr_t val;
|
||||||
CPredicateV codev = (CPredicateV)exec_code;
|
CPredicateV codev = (CPredicateV)exec_code;
|
||||||
@ -1557,7 +1557,7 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code)
|
|||||||
} else {
|
} else {
|
||||||
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1),0,ctx);
|
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1),0,ctx);
|
||||||
}
|
}
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
if (val == 0) {
|
if (val == 0) {
|
||||||
Term t;
|
Term t;
|
||||||
@ -1583,7 +1583,7 @@ YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Int ret = (exec_code)( PASS_REGS1 );
|
Int ret = (exec_code)( PASS_REGS1 );
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
Term t;
|
Term t;
|
||||||
|
|
||||||
@ -1622,7 +1622,7 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
|||||||
} else {
|
} else {
|
||||||
val = codev(Yap_InitSlots(pe->ArityOfPE, args),0,ctx);
|
val = codev(Yap_InitSlots(pe->ArityOfPE, args),0,ctx);
|
||||||
}
|
}
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
|
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
// B = LCL0-(CELL*)oB;
|
// B = LCL0-(CELL*)oB;
|
||||||
@ -1644,9 +1644,9 @@ YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
|
|||||||
Int ret, CurSlot;
|
Int ret, CurSlot;
|
||||||
B = oB;
|
B = oB;
|
||||||
/* for slots to work */
|
/* for slots to work */
|
||||||
CurSlot = Yap_StartSlots( PASS_REGS1 );
|
CurSlot = Yap_StartSlots( );
|
||||||
ret = (exec_code)( PASS_REGS1 );
|
ret = (exec_code)( PASS_REGS1 );
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
Term t;
|
Term t;
|
||||||
|
|
||||||
@ -1667,7 +1667,7 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code)
|
|||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
/* for slots to work */
|
/* for slots to work */
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
UInt ocp = LCL0-(CELL *)B;
|
UInt ocp = LCL0-(CELL *)B;
|
||||||
yhandle_t CurSlot = Yap_StartSlots();
|
yhandle_t CurSlot = Yap_StartSlots();
|
||||||
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) {
|
if (pe->PredFlags & (SWIEnvPredFlag|CArgsPredFlag)) {
|
||||||
@ -1682,7 +1682,7 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code)
|
|||||||
} else {
|
} else {
|
||||||
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1),0,ctx);
|
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1),0,ctx);
|
||||||
}
|
}
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
/* we are below the original choice point ?? */
|
/* we are below the original choice point ?? */
|
||||||
/* make sure we clean up the frames left by the user */
|
/* make sure we clean up the frames left by the user */
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
@ -1711,7 +1711,7 @@ YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code)
|
|||||||
return complete_exit(((choiceptr)(LCL0-ocp)), FALSE, FALSE PASS_REGS);
|
return complete_exit(((choiceptr)(LCL0-ocp)), FALSE, FALSE PASS_REGS);
|
||||||
} else {
|
} else {
|
||||||
Int ret = (exec_code)( PASS_REGS1 );
|
Int ret = (exec_code)( PASS_REGS1 );
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
Term t;
|
Term t;
|
||||||
|
|
||||||
@ -2214,7 +2214,7 @@ YAP_EnterGoal(PredEntry *pe, Term *ptr, YAP_dogoalinfo *dgi)
|
|||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
if (out) {
|
if (out) {
|
||||||
dgi->EndSlot = LOCAL_CurSlot;
|
dgi->EndSlot = LOCAL_CurSlot;
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
} else {
|
} else {
|
||||||
LOCAL_CurSlot = dgi->CurSlot; // ignore any slots created within the called goal
|
LOCAL_CurSlot = dgi->CurSlot; // ignore any slots created within the called goal
|
||||||
}
|
}
|
||||||
@ -2243,7 +2243,7 @@ YAP_RetryGoal(YAP_dogoalinfo *dgi)
|
|||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
if (out) {
|
if (out) {
|
||||||
LOCAL_CurSlot = dgi->CurSlot;
|
LOCAL_CurSlot = dgi->CurSlot;
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -2324,7 +2324,7 @@ YAP_RunGoal(Term t)
|
|||||||
CP = old_CP;
|
CP = old_CP;
|
||||||
LOCAL_AllowRestart = TRUE;
|
LOCAL_AllowRestart = TRUE;
|
||||||
// we are back to user code again, need slots */
|
// we are back to user code again, need slots */
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
} else {
|
} else {
|
||||||
ENV = B->cp_env;
|
ENV = B->cp_env;
|
||||||
ENV = (CELL *)ENV[E_E];
|
ENV = (CELL *)ENV[E_E];
|
||||||
@ -2784,7 +2784,7 @@ static char BootFile[] = "boot.yap";
|
|||||||
|
|
||||||
/* do initial boot by consulting the file boot.yap */
|
/* do initial boot by consulting the file boot.yap */
|
||||||
static void
|
static void
|
||||||
do_bootfile (char *bootfilename)
|
do_bootfile (char *bootfilename USES_REGS)
|
||||||
{
|
{
|
||||||
Term t;
|
Term t;
|
||||||
Term term_end_of_file = MkAtomTerm(AtomEof);
|
Term term_end_of_file = MkAtomTerm(AtomEof);
|
||||||
@ -2807,9 +2807,9 @@ do_bootfile (char *bootfilename)
|
|||||||
while (!eof_found)
|
while (!eof_found)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
t = YAP_Read(bootfile);
|
t = YAP_Read(bootfile);
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
if (eof_found) {
|
if (eof_found) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3076,7 +3076,7 @@ YAP_Init(YAP_init_args *yap_init)
|
|||||||
construct_init_file(boot_file, BootFile);
|
construct_init_file(boot_file, BootFile);
|
||||||
yap_init->YapPrologBootFile = boot_file;
|
yap_init->YapPrologBootFile = boot_file;
|
||||||
}
|
}
|
||||||
do_bootfile (yap_init->YapPrologBootFile ? yap_init->YapPrologBootFile : BootFile);
|
do_bootfile (yap_init->YapPrologBootFile ? yap_init->YapPrologBootFile : BootFile PASS_REGS);
|
||||||
/* initialise the top-level */
|
/* initialise the top-level */
|
||||||
if (!do_bootstrap) {
|
if (!do_bootstrap) {
|
||||||
char init_file[256];
|
char init_file[256];
|
||||||
@ -3201,7 +3201,7 @@ YAP_Reset(yap_reset_t mode)
|
|||||||
/* always have an empty slots for people to use */
|
/* always have an empty slots for people to use */
|
||||||
P = CP = YESCODE;
|
P = CP = YESCODE;
|
||||||
// ensure that we have slots where we need them
|
// ensure that we have slots where we need them
|
||||||
Yap_CloseSlots(1 PASS_REGS);
|
Yap_CloseSlots(1);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -3802,7 +3802,7 @@ X_API void
|
|||||||
YAP_SlotsToArgs(int n, yhandle_t slot)
|
YAP_SlotsToArgs(int n, yhandle_t slot)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
CELL *ptr0 = Yap_AddressFromSlot(slot PASS_REGS), *ptr1=&ARG1;
|
CELL *ptr0 = Yap_AddressFromSlot(slot), *ptr1=&ARG1;
|
||||||
while (n--) {
|
while (n--) {
|
||||||
*ptr1++ = *ptr0++;
|
*ptr1++ = *ptr0++;
|
||||||
}
|
}
|
||||||
|
@ -6516,7 +6516,7 @@ p_nth_instance( USES_REGS1 )
|
|||||||
UNLOCK(pe->PELock);
|
UNLOCK(pe->PELock);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
CurSlot = Yap_StartSlots( PASS_REGS1 );
|
CurSlot = Yap_StartSlots( );
|
||||||
/* I have pe and n */
|
/* I have pe and n */
|
||||||
sl4 = Yap_InitSlot( ARG4 PASS_REGS );
|
sl4 = Yap_InitSlot( ARG4 PASS_REGS );
|
||||||
/* in case we have to index or to expand code */
|
/* in case we have to index or to expand code */
|
||||||
|
@ -1581,7 +1581,7 @@ mark_environments(CELL_PTR gc_ENV, size_t size, CELL *pvbmap USES_REGS)
|
|||||||
|
|
||||||
//fprintf(stderr,"ENV %p %ld\n", gc_ENV, size);
|
//fprintf(stderr,"ENV %p %ld\n", gc_ENV, size);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (size < 0 || size > 512)
|
if (/* size < 0 || */ size > 512)
|
||||||
fprintf(stderr,"OOPS in GC: env size for %p is " UInt_FORMAT "\n", gc_ENV, (CELL)size);
|
fprintf(stderr,"OOPS in GC: env size for %p is " UInt_FORMAT "\n", gc_ENV, (CELL)size);
|
||||||
#endif
|
#endif
|
||||||
mark_db_fixed((CELL *)gc_ENV[E_CP] PASS_REGS);
|
mark_db_fixed((CELL *)gc_ENV[E_CP] PASS_REGS);
|
||||||
|
120
C/init.c
120
C/init.c
@ -19,7 +19,7 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The code from this file is used to initialize the environment for prolog
|
* The code from this file is used to initialize the environment for prolog
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ int Yap_Portray_delays = FALSE;
|
|||||||
@ingroup Syntax
|
@ingroup Syntax
|
||||||
@{
|
@{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The Prolog syntax caters for operators of three main kinds:
|
The Prolog syntax caters for operators of three main kinds:
|
||||||
|
|
||||||
@ -117,23 +117,23 @@ The Prolog syntax caters for operators of three main kinds:
|
|||||||
+ postfix.
|
+ postfix.
|
||||||
|
|
||||||
|
|
||||||
Each operator has precedence in the range 1 to 1200, and this
|
Each operator has precedence in the range 1 to 1200, and this
|
||||||
precedence is used to disambiguate expressions where the structure of the
|
precedence is used to disambiguate expressions where the structure of the
|
||||||
term denoted is not made explicit using brackets. The operator of higher
|
term denoted is not made explicit using brackets. The operator of higher
|
||||||
precedence is the main functor.
|
precedence is the main functor.
|
||||||
|
|
||||||
If there are two operators with the highest precedence, the ambiguity
|
If there are two operators with the highest precedence, the ambiguity
|
||||||
is solved analyzing the types of the operators. The possible infix types are:
|
is solved analyzing the types of the operators. The possible infix types are:
|
||||||
_xfx_, _xfy_, and _yfx_.
|
_xfx_, _xfy_, and _yfx_.
|
||||||
|
|
||||||
With an operator of type _xfx_ both sub-expressions must have lower
|
With an operator of type _xfx_ both sub-expressions must have lower
|
||||||
precedence than the operator itself, unless they are bracketed (which
|
precedence than the operator itself, unless they are bracketed (which
|
||||||
assigns to them zero precedence). With an operator type _xfy_ only the
|
assigns to them zero precedence). With an operator type _xfy_ only the
|
||||||
left-hand sub-expression must have lower precedence. The opposite happens
|
left-hand sub-expression must have lower precedence. The opposite happens
|
||||||
for _yfx_ type.
|
for _yfx_ type.
|
||||||
|
|
||||||
A prefix operator can be of type _fx_ or _fy_.
|
A prefix operator can be of type _fx_ or _fy_.
|
||||||
A postfix operator can be of type _xf_ or _yf_.
|
A postfix operator can be of type _xf_ or _yf_.
|
||||||
The meaning of the notation is analogous to the above.
|
The meaning of the notation is analogous to the above.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -207,7 +207,7 @@ Yap_IsOpType(char *type)
|
|||||||
return (i <= 7);
|
return (i <= 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
OpDec(int p, const char *type, Atom a, Term m)
|
OpDec(int p, const char *type, Atom a, Term m)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -253,7 +253,7 @@ OpDec(int p, const char *type, Atom a, Term m)
|
|||||||
}
|
}
|
||||||
if (i <= 3) {
|
if (i <= 3) {
|
||||||
GET_LD
|
GET_LD
|
||||||
if (truePrologFlag(PLFLAG_ISO) &&
|
if (truePrologFlag(PLFLAG_ISO) &&
|
||||||
info->Posfix != 0) /* there is a posfix operator */ {
|
info->Posfix != 0) /* there is a posfix operator */ {
|
||||||
/* ISO dictates */
|
/* ISO dictates */
|
||||||
WRITE_UNLOCK(info->OpRWLock);
|
WRITE_UNLOCK(info->OpRWLock);
|
||||||
@ -263,7 +263,7 @@ OpDec(int p, const char *type, Atom a, Term m)
|
|||||||
info->Infix = p;
|
info->Infix = p;
|
||||||
} else if (i <= 5) {
|
} else if (i <= 5) {
|
||||||
GET_LD
|
GET_LD
|
||||||
if (truePrologFlag(PLFLAG_ISO) &&
|
if (truePrologFlag(PLFLAG_ISO) &&
|
||||||
info->Infix != 0) /* there is an infix operator */ {
|
info->Infix != 0) /* there is an infix operator */ {
|
||||||
/* ISO dictates */
|
/* ISO dictates */
|
||||||
WRITE_UNLOCK(info->OpRWLock);
|
WRITE_UNLOCK(info->OpRWLock);
|
||||||
@ -278,13 +278,13 @@ OpDec(int p, const char *type, Atom a, Term m)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Yap_OpDec(int p, char *type, Atom a, Term m)
|
Yap_OpDec(int p, char *type, Atom a, Term m)
|
||||||
{
|
{
|
||||||
return(OpDec(p,type,a,m));
|
return(OpDec(p,type,a,m));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SetOp(int p, int type, char *at, Term m)
|
SetOp(int p, int type, char *at, Term m)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -295,7 +295,7 @@ SetOp(int p, int type, char *at, Term m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Gets the info about an operator in a prop */
|
/* Gets the info about an operator in a prop */
|
||||||
Atom
|
Atom
|
||||||
Yap_GetOp(OpEntry *pp, int *prio, int fix)
|
Yap_GetOp(OpEntry *pp, int *prio, int fix)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
@ -409,7 +409,7 @@ static Opdef Ops[] = {
|
|||||||
{"^", xfy, 200}
|
{"^", xfy, 200}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitOps(void)
|
InitOps(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -425,7 +425,7 @@ InitOps(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitDebug(void)
|
InitDebug(void)
|
||||||
{
|
{
|
||||||
Atom At;
|
Atom At;
|
||||||
@ -471,7 +471,7 @@ InitDebug(void)
|
|||||||
Yap_PutValue(At, MkIntTerm(15));
|
Yap_PutValue(At, MkIntTerm(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
static UInt
|
static UInt
|
||||||
update_flags_from_prolog(UInt flags, PredEntry *pe)
|
update_flags_from_prolog(UInt flags, PredEntry *pe)
|
||||||
{
|
{
|
||||||
if (pe->PredFlags & MetaPredFlag)
|
if (pe->PredFlags & MetaPredFlag)
|
||||||
@ -487,7 +487,7 @@ update_flags_from_prolog(UInt flags, PredEntry *pe)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
|
Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -525,7 +525,7 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
|
|||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pe->PredFlags & CPredFlag) {
|
if (pe->PredFlags & CPredFlag) {
|
||||||
/* already exists */
|
/* already exists */
|
||||||
flags = update_flags_from_prolog(flags, pe);
|
flags = update_flags_from_prolog(flags, pe);
|
||||||
@ -591,14 +591,14 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
|
|||||||
pe->OpcodeOfPred = pe->CodeOfPred->opc;
|
pe->OpcodeOfPred = pe->CodeOfPred->opc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_t flags)
|
Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_t flags)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Atom atom = NIL;
|
Atom atom = NIL;
|
||||||
PredEntry *pe = NULL;
|
PredEntry *pe = NULL;
|
||||||
yamop *p_code = NULL;
|
yamop *p_code = NULL;
|
||||||
StaticClause *cl = NULL;
|
StaticClause *cl = NULL;
|
||||||
Functor f = NULL;
|
Functor f = NULL;
|
||||||
|
|
||||||
while (atom == NIL) {
|
while (atom == NIL) {
|
||||||
@ -626,7 +626,7 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
|
|||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pe->PredFlags & BinaryPredFlag) {
|
if (pe->PredFlags & BinaryPredFlag) {
|
||||||
flags = update_flags_from_prolog(flags, pe);
|
flags = update_flags_from_prolog(flags, pe);
|
||||||
p_code = pe->CodeOfPred;
|
p_code = pe->CodeOfPred;
|
||||||
@ -634,7 +634,7 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
|
|||||||
} else {
|
} else {
|
||||||
while (!cl) {
|
while (!cl) {
|
||||||
UInt sz = sizeof(StaticClause)+(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL),plxxs),p),l);
|
UInt sz = sizeof(StaticClause)+(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL),plxxs),p),l);
|
||||||
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
||||||
if (!cl) {
|
if (!cl) {
|
||||||
if (!Yap_growheap(FALSE, sz, NULL)) {
|
if (!Yap_growheap(FALSE, sz, NULL)) {
|
||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
||||||
@ -669,14 +669,14 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
|
|||||||
p_code->y_u.l.l = cl->ClCode;
|
p_code->y_u.l.l = cl->ClCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_flags_t flags)
|
Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_flags_t flags)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Atom atom = NIL;
|
Atom atom = NIL;
|
||||||
PredEntry *pe = NULL;
|
PredEntry *pe = NULL;
|
||||||
Functor f = NULL;
|
Functor f = NULL;
|
||||||
|
|
||||||
while (atom == NIL) {
|
while (atom == NIL) {
|
||||||
atom = Yap_FullLookupAtom(Name);
|
atom = Yap_FullLookupAtom(Name);
|
||||||
if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
|
if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
|
||||||
@ -702,7 +702,7 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
|
|||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flags |= AsmPredFlag | StandardPredFlag | (code);
|
flags |= AsmPredFlag | StandardPredFlag | (code);
|
||||||
if (pe->PredFlags & AsmPredFlag) {
|
if (pe->PredFlags & AsmPredFlag) {
|
||||||
flags = update_flags_from_prolog(flags, pe);
|
flags = update_flags_from_prolog(flags, pe);
|
||||||
@ -720,7 +720,7 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
|
|||||||
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l));
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l));
|
||||||
} else {
|
} else {
|
||||||
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),p),l));
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),p),l));
|
||||||
}
|
}
|
||||||
if (!cl) {
|
if (!cl) {
|
||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred");
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred");
|
||||||
return;
|
return;
|
||||||
@ -761,12 +761,12 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
|
|||||||
pe->OpcodeOfPred = pe->CodeOfPred->opc;
|
pe->OpcodeOfPred = pe->CodeOfPred->opc;
|
||||||
} else {
|
} else {
|
||||||
pe->OpcodeOfPred = Yap_opcode(_undef_p);
|
pe->OpcodeOfPred = Yap_opcode(_undef_p);
|
||||||
pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
|
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
|
||||||
{
|
{
|
||||||
yamop *code;
|
yamop *code;
|
||||||
@ -807,7 +807,7 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
|
|||||||
code->y_u.OtapFs.f = Cut;
|
code->y_u.OtapFs.f = Cut;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitCPredBack(const char *Name, UInt Arity,
|
Yap_InitCPredBack(const char *Name, UInt Arity,
|
||||||
unsigned int Extra, CPredicate Start,
|
unsigned int Extra, CPredicate Start,
|
||||||
CPredicate Cont, pred_flags_t flags){
|
CPredicate Cont, pred_flags_t flags){
|
||||||
@ -856,17 +856,17 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
|
|||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pe->cs.p_code.FirstClause != NIL)
|
if (pe->cs.p_code.FirstClause != NIL)
|
||||||
{
|
{
|
||||||
flags = update_flags_from_prolog(flags, pe);
|
flags = update_flags_from_prolog(flags, pe);
|
||||||
CleanBack(pe, Start, Cont, Cut);
|
CleanBack(pe, Start, Cont, Cut);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StaticClause *cl;
|
StaticClause *cl;
|
||||||
yamop *code = ((StaticClause *)NULL)->ClCode;
|
yamop *code = ((StaticClause *)NULL)->ClCode;
|
||||||
UInt sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),l);
|
UInt sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),l);
|
||||||
if (flags & UserCPredFlag)
|
if (flags & UserCPredFlag)
|
||||||
pe->PredFlags = UserCPredFlag | BackCPredFlag| CompiledPredFlag | StandardPredFlag | flags;
|
pe->PredFlags = UserCPredFlag | BackCPredFlag| CompiledPredFlag | StandardPredFlag | flags;
|
||||||
else
|
else
|
||||||
pe->PredFlags = CompiledPredFlag | StandardPredFlag | BackCPredFlag;
|
pe->PredFlags = CompiledPredFlag | StandardPredFlag | BackCPredFlag;
|
||||||
@ -874,9 +874,9 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
|
|||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
pe->PredFlags |= SequentialPredFlag;
|
pe->PredFlags |= SequentialPredFlag;
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
|
|
||||||
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
||||||
|
|
||||||
if (cl == NULL) {
|
if (cl == NULL) {
|
||||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCPredBack");
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCPredBack");
|
||||||
return;
|
return;
|
||||||
@ -884,7 +884,7 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
|
|||||||
cl->ClFlags = StaticMask;
|
cl->ClFlags = StaticMask;
|
||||||
cl->ClNext = NULL;
|
cl->ClNext = NULL;
|
||||||
Yap_ClauseSpace += sz;
|
Yap_ClauseSpace += sz;
|
||||||
cl->ClSize =
|
cl->ClSize =
|
||||||
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),e);
|
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),e);
|
||||||
cl->usc.ClLine = Yap_source_line_no();
|
cl->usc.ClLine = Yap_source_line_no();
|
||||||
|
|
||||||
@ -932,11 +932,11 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitStdPreds(void)
|
InitStdPreds(void)
|
||||||
{
|
{
|
||||||
void initIO(void);
|
void initIO(void);
|
||||||
|
|
||||||
Yap_InitCPreds();
|
Yap_InitCPreds();
|
||||||
Yap_InitBackCPreds();
|
Yap_InitBackCPreds();
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
@ -1016,7 +1016,7 @@ InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe)
|
|||||||
#endif /* TABLING */
|
#endif /* TABLING */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitDBErasedMarker(void)
|
InitDBErasedMarker(void)
|
||||||
{
|
{
|
||||||
Yap_heap_regs->db_erased_marker =
|
Yap_heap_regs->db_erased_marker =
|
||||||
@ -1029,7 +1029,7 @@ InitDBErasedMarker(void)
|
|||||||
Yap_heap_regs->db_erased_marker->Parent = NULL;
|
Yap_heap_regs->db_erased_marker->Parent = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitLogDBErasedMarker(void)
|
InitLogDBErasedMarker(void)
|
||||||
{
|
{
|
||||||
Yap_heap_regs->logdb_erased_marker =
|
Yap_heap_regs->logdb_erased_marker =
|
||||||
@ -1047,7 +1047,7 @@ InitLogDBErasedMarker(void)
|
|||||||
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
|
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitSWIAtoms(void)
|
InitSWIAtoms(void)
|
||||||
{
|
{
|
||||||
extern atom_t ATOM_;
|
extern atom_t ATOM_;
|
||||||
@ -1061,12 +1061,12 @@ InitSWIAtoms(void)
|
|||||||
ATOM_ = PL_new_atom("");
|
ATOM_ = PL_new_atom("");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitEmptyWakeups(void)
|
InitEmptyWakeups(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitAtoms(void)
|
InitAtoms(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -1097,7 +1097,7 @@ InitAtoms(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitWideAtoms(void)
|
InitWideAtoms(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -1114,7 +1114,7 @@ InitWideAtoms(void)
|
|||||||
NOfWideAtoms = 0;
|
NOfWideAtoms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitInvisibleAtoms(void)
|
InitInvisibleAtoms(void)
|
||||||
{
|
{
|
||||||
/* initialise invisible chain */
|
/* initialise invisible chain */
|
||||||
@ -1155,7 +1155,7 @@ void Yap_init_yapor_workers(void) {
|
|||||||
son = fork();
|
son = fork();
|
||||||
if (son == -1)
|
if (son == -1)
|
||||||
Yap_Error(FATAL_ERROR, TermNil, "fork error (Yap_init_yapor_workers)");
|
Yap_Error(FATAL_ERROR, TermNil, "fork error (Yap_init_yapor_workers)");
|
||||||
if (son == 0) {
|
if (son == 0) {
|
||||||
/* new worker */
|
/* new worker */
|
||||||
worker_id = proc;
|
worker_id = proc;
|
||||||
Yap_remap_yapor_memory();
|
Yap_remap_yapor_memory();
|
||||||
@ -1180,8 +1180,8 @@ InitThreadHandle(int wid)
|
|||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
REMOTE_ThreadHandle(wid).thread_inst_count = 0LL;
|
REMOTE_ThreadHandle(wid).thread_inst_count = 0LL;
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_init(&(REMOTE_ThreadHandle(wid).tlock), NULL);
|
pthread_mutex_init(&(REMOTE_ThreadHandle(wid).tlock), NULL);
|
||||||
pthread_mutex_init(&(REMOTE_ThreadHandle(wid).tlock_status), NULL);
|
pthread_mutex_init(&(REMOTE_ThreadHandle(wid).tlock_status), NULL);
|
||||||
REMOTE_ThreadHandle(wid).tdetach = (CELL)0;
|
REMOTE_ThreadHandle(wid).tdetach = (CELL)0;
|
||||||
REMOTE_ThreadHandle(wid).cmod = (CELL)0;
|
REMOTE_ThreadHandle(wid).cmod = (CELL)0;
|
||||||
{
|
{
|
||||||
@ -1234,19 +1234,19 @@ InitScratchPad(int wid)
|
|||||||
REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE;
|
REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELL *
|
static CELL *
|
||||||
InitHandles(int wid) {
|
InitHandles(int wid) {
|
||||||
size_t initial_slots = 1024;
|
size_t initial_slots = 1024;
|
||||||
CELL *handles;
|
CELL *handles;
|
||||||
|
|
||||||
REMOTE_CurSlot(wid) = 1;
|
REMOTE_CurSlot(wid) = 1;
|
||||||
REMOTE_NSlots(wid) = initial_slots;
|
REMOTE_NSlots(wid) = initial_slots;
|
||||||
handles = malloc(initial_slots * sizeof(CELL));
|
handles = malloc(initial_slots * sizeof(CELL));
|
||||||
|
|
||||||
if(handles == NULL) {
|
if(handles == NULL) {
|
||||||
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "No space for handles at " __FILE__ " : %d", __LINE__);
|
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "No space for handles at " __FILE__ " : %d", __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
RESET_VARIABLE(handles);
|
RESET_VARIABLE(handles);
|
||||||
return handles;
|
return handles;
|
||||||
}
|
}
|
||||||
@ -1279,7 +1279,7 @@ struct worker_local *Yap_local;
|
|||||||
struct worker_local Yap_local;
|
struct worker_local Yap_local;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitCodes(void)
|
InitCodes(void)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1316,7 +1316,7 @@ InitCodes(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitVersion(void)
|
InitVersion(void)
|
||||||
{
|
{
|
||||||
Yap_PutValue(AtomVersionNumber,
|
Yap_PutValue(AtomVersionNumber,
|
||||||
@ -1324,7 +1324,7 @@ InitVersion(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_size,
|
Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_size,
|
||||||
int n_workers, int sch_loop, int delay_load)
|
int n_workers, int sch_loop, int delay_load)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
@ -82,9 +82,9 @@ p_load_foreign( USES_REGS1 )
|
|||||||
|
|
||||||
/* call the OS specific function for dynamic loading */
|
/* call the OS specific function for dynamic loading */
|
||||||
if(Yap_LoadForeign(ofiles,libs,InitProcName,&InitProc)==LOAD_SUCCEEDED) {
|
if(Yap_LoadForeign(ofiles,libs,InitProcName,&InitProc)==LOAD_SUCCEEDED) {
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
(*InitProc)();
|
(*InitProc)();
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
returncode = TRUE;
|
returncode = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,7 +862,7 @@ Yap_TermToString(Term t, char *s, size_t sz, size_t *length, int *encoding, int
|
|||||||
Int myASP = LCL0-ASP;
|
Int myASP = LCL0-ASP;
|
||||||
yhandle_t CurSlot = Yap_StartSlots();
|
yhandle_t CurSlot = Yap_StartSlots();
|
||||||
|
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
Yap_StartSlots( );
|
||||||
l = Yap_InitSlot(t PASS_REGS );
|
l = Yap_InitSlot(t PASS_REGS );
|
||||||
|
|
||||||
{ IOENC encodings[3];
|
{ IOENC encodings[3];
|
||||||
@ -901,14 +901,14 @@ Yap_TermToString(Term t, char *s, size_t sz, size_t *length, int *encoding, int
|
|||||||
if (r == buf) {
|
if (r == buf) {
|
||||||
char *bf = malloc(*length+1);
|
char *bf = malloc(*length+1);
|
||||||
if (!bf) {
|
if (!bf) {
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
ASP = LCL0-myASP;
|
ASP = LCL0-myASP;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strncpy(bf,buf,*length+1);
|
strncpy(bf,buf,*length+1);
|
||||||
r = bf;
|
r = bf;
|
||||||
}
|
}
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
ASP = LCL0-myASP;
|
ASP = LCL0-myASP;
|
||||||
return r;
|
return r;
|
||||||
} else
|
} else
|
||||||
@ -920,7 +920,7 @@ Yap_TermToString(Term t, char *s, size_t sz, size_t *length, int *encoding, int
|
|||||||
Sfree(r);
|
Sfree(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
ASP = LCL0-myASP;
|
ASP = LCL0-myASP;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
4
C/save.c
4
C/save.c
@ -657,9 +657,9 @@ p_save2( USES_REGS1 )
|
|||||||
if (!Yap_unify(ARG2,MkIntTerm(1)))
|
if (!Yap_unify(ARG2,MkIntTerm(1)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
which_save = 2;
|
which_save = 2;
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
CurSlot = Yap_StartSlots();
|
||||||
res = do_save(DO_EVERYTHING PASS_REGS);
|
res = do_save(DO_EVERYTHING PASS_REGS);
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
Yap_CloseSlots(CurSlot);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
C/stdpreds.c
24
C/stdpreds.c
@ -457,7 +457,7 @@ Int show_time(USES_REGS1) /* MORE PRECISION */
|
|||||||
|
|
||||||
Maintain a light-weight map where the key is an atom, and the value can be any constant.
|
Maintain a light-weight map where the key is an atom, and the value can be any constant.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @pred set_value(+ _A_,+ _C_)
|
/** @pred set_value(+ _A_,+ _C_)
|
||||||
|
|
||||||
|
|
||||||
@ -869,7 +869,7 @@ static Int
|
|||||||
shutdown_llvm();
|
shutdown_llvm();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Yap_exit(out);
|
Yap_exit(out);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -1742,6 +1742,15 @@ static Int p_has_eam(USES_REGS1) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int p_has_jit(USES_REGS1) {
|
||||||
|
#ifdef HAS_JIT
|
||||||
|
return (TRUE);
|
||||||
|
#else
|
||||||
|
return (FALSE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int p_set_yap_flags(USES_REGS1) {
|
static Int p_set_yap_flags(USES_REGS1) {
|
||||||
Term tflag = Deref(ARG1);
|
Term tflag = Deref(ARG1);
|
||||||
Term tvalue = Deref(ARG2);
|
Term tvalue = Deref(ARG2);
|
||||||
@ -1996,7 +2005,7 @@ typedef void (*Proc)(void);
|
|||||||
|
|
||||||
Proc E_Modules[] = {/* init_fc,*/ (Proc)0};
|
Proc E_Modules[] = {/* init_fc,*/ (Proc)0};
|
||||||
|
|
||||||
#ifndef YAPOR
|
#ifdef YAPOR
|
||||||
static Int p_parallel_mode(USES_REGS1) { return FALSE; }
|
static Int p_parallel_mode(USES_REGS1) { return FALSE; }
|
||||||
|
|
||||||
static Int p_yapor_workers(USES_REGS1) { return FALSE; }
|
static Int p_yapor_workers(USES_REGS1) { return FALSE; }
|
||||||
@ -2084,18 +2093,17 @@ void Yap_InitCPreds(void) {
|
|||||||
Yap_InitCPred("$set_flag", 4, p_set_flag, SyncPredFlag);
|
Yap_InitCPred("$set_flag", 4, p_set_flag, SyncPredFlag);
|
||||||
Yap_InitCPred("$has_yap_or", 0, p_has_yap_or, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("$has_yap_or", 0, p_has_yap_or, SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("$has_eam", 0, p_has_eam, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("$has_eam", 0, p_has_eam, SafePredFlag | SyncPredFlag);
|
||||||
|
Yap_InitCPred("$has_jit", 0, p_has_jit, SafePredFlag | SyncPredFlag);
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
Yap_InitCPred("parallel_mode", 1, p_parallel_mode,
|
Yap_InitCPred("parallel_mode", 1, p_parallel_mode,
|
||||||
SafePredFlag | SyncPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers,
|
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers,
|
||||||
SafePredFlag | SyncPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
#endif /* YAPOR */
|
#endif
|
||||||
#ifdef YAP_JIT
|
#ifdef YAP_JIT
|
||||||
Yap_InitCPred("init", 1, p_parallel_mode,
|
Yap_InitCPred("$jit_init", 1, p_jit,
|
||||||
SafePredFlag | SyncPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers,
|
#endif /* YAPOR */
|
||||||
SafePredFlag | SyncPredFlag);
|
|
||||||
#endif /* YAPOR */
|
|
||||||
#ifdef INES
|
#ifdef INES
|
||||||
Yap_InitCPred("euc_dist", 3, p_euc_dist, SafePredFlag);
|
Yap_InitCPred("euc_dist", 3, p_euc_dist, SafePredFlag);
|
||||||
Yap_InitCPred("loop", 0, p_loop, SafePredFlag);
|
Yap_InitCPred("loop", 0, p_loop, SafePredFlag);
|
||||||
|
23
C/text.c
23
C/text.c
@ -395,7 +395,6 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
wchar_t *ws;
|
wchar_t *ws;
|
||||||
yhandle_t CurSlot = Yap_StartSlots();
|
|
||||||
|
|
||||||
/* we know what the term is */
|
/* we know what the term is */
|
||||||
switch (inp->type & YAP_TYPE_MASK) {
|
switch (inp->type & YAP_TYPE_MASK) {
|
||||||
@ -412,8 +411,9 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
s = StringOfTerm( inp->val.t );
|
s = StringOfTerm( inp->val.t );
|
||||||
if ( s == NULL )
|
if ( s == NULL ) {
|
||||||
return 0L;
|
return 0L;
|
||||||
|
}
|
||||||
// this is a term, extract the UTF8 representation
|
// this is a term, extract the UTF8 representation
|
||||||
*enc = YAP_UTF8;
|
*enc = YAP_UTF8;
|
||||||
*minimal = FALSE;
|
*minimal = FALSE;
|
||||||
@ -426,7 +426,9 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
{
|
{
|
||||||
int wide = FALSE;
|
int wide = FALSE;
|
||||||
s = Yap_ListOfCodesToBuffer( buf, inp->val.t, inp, &wide, lengp PASS_REGS);
|
s = Yap_ListOfCodesToBuffer( buf, inp->val.t, inp, &wide, lengp PASS_REGS);
|
||||||
if (!s) return NULL;
|
if (!s) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
*enc = ( wide ? YAP_WCHAR : YAP_CHAR );
|
*enc = ( wide ? YAP_WCHAR : YAP_CHAR );
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@ -447,7 +449,9 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
{
|
{
|
||||||
int wide = FALSE;
|
int wide = FALSE;
|
||||||
s = Yap_ListToBuffer( buf, inp->val.t, inp, &wide, lengp PASS_REGS);
|
s = Yap_ListToBuffer( buf, inp->val.t, inp, &wide, lengp PASS_REGS);
|
||||||
if (!s) return NULL;
|
if (!s) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
*enc = ( wide ? YAP_WCHAR : YAP_CHAR );
|
*enc = ( wide ? YAP_WCHAR : YAP_CHAR );
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@ -496,7 +500,7 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
}
|
}
|
||||||
*lengp = strlen(s);
|
*lengp = strlen(s);
|
||||||
*enc = YAP_CHAR;
|
*enc = YAP_CHAR;
|
||||||
return s;
|
return s;
|
||||||
#if USE_GMP
|
#if USE_GMP
|
||||||
case YAP_STRING_BIG:
|
case YAP_STRING_BIG:
|
||||||
if (buf) s = buf;
|
if (buf) s = buf;
|
||||||
@ -524,24 +528,23 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
return (void *)inp->val.w;
|
return (void *)inp->val.w;
|
||||||
case YAP_STRING_LITERAL:
|
case YAP_STRING_LITERAL:
|
||||||
{
|
{
|
||||||
Yap_StartSlots( PASS_REGS1 );
|
yhandle_t CurSlot = Yap_StartSlots( );
|
||||||
if (buf) s = buf;
|
if (buf) s = buf;
|
||||||
else s = Yap_PreAllocCodeSpace();
|
else s = Yap_PreAllocCodeSpace();
|
||||||
size_t sz = LOCAL_MAX_SIZE-1;
|
size_t sz = LOCAL_MAX_SIZE-1;
|
||||||
IOSTREAM *fd;
|
IOSTREAM *fd;
|
||||||
AUX_ERROR( inp->val.t, LOCAL_MAX_SIZE, s, char);
|
AUX_ERROR( inp->val.t, LOCAL_MAX_SIZE, s, char);
|
||||||
|
CurSlot = Yap_StartSlots();
|
||||||
fd = Sopenmem(&s, &sz, "w");
|
fd = Sopenmem(&s, &sz, "w");
|
||||||
fd->encoding = ENC_UTF8;
|
fd->encoding = ENC_UTF8;
|
||||||
if ( ! PL_write_term(fd, Yap_InitSlot(inp->val.t PASS_REGS), 1200, 0) ||
|
if ( ! PL_write_term(fd, Yap_InitSlot(inp->val.t PASS_REGS), 1200, 0) ||
|
||||||
Sputcode(EOS, fd) < 0 ||
|
Sputcode(EOS, fd) < 0 ||
|
||||||
Sflush(fd) < 0 ) {
|
Sflush(fd) < 0 ) {
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
|
||||||
AUX_ERROR( inp->val.t, LOCAL_MAX_SIZE, s, char);
|
AUX_ERROR( inp->val.t, LOCAL_MAX_SIZE, s, char);
|
||||||
} else {
|
|
||||||
Yap_CloseSlots(CurSlot PASS_REGS);
|
|
||||||
}
|
}
|
||||||
*enc = YAP_UTF8;
|
*enc = YAP_UTF8;
|
||||||
*lengp = strlen(s);
|
*lengp = strlen(s);
|
||||||
|
Yap_CloseSlots(CurSlot);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -552,7 +555,7 @@ read_Text( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *leng
|
|||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
|
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
|
||||||
LOCAL_Error_Term = t;
|
LOCAL_Error_Term = t;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (IsStringTerm(t)) {
|
} else if (IsStringTerm(t)) {
|
||||||
if (inp->type & (YAP_STRING_STRING)) {
|
if (inp->type & (YAP_STRING_STRING)) {
|
||||||
inp->type &= (YAP_STRING_STRING);
|
inp->type &= (YAP_STRING_STRING);
|
||||||
|
@ -401,7 +401,11 @@ IsStringTerm (Term t)
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <gmpxx.h>
|
||||||
|
#else
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
Also known as term handles, slots are offsets to entries in the local stack. YAP never compresses the local stack, so slots are respected by the garbage collector,
|
Also known as term handles, slots are offsets to entries in the local stack. YAP never compresses the local stack, so slots are respected by the garbage collector,
|
||||||
hence providing a way to access terms without being exposed to stack shifts or garbage-collection.
|
hence providing a way to access terms without being exposed to stack shifts or garbage-collection.
|
||||||
|
|
||||||
Space is released when the function terminataes. Thus, slots will be automatically released at the end
|
Space is released when the function terminates. Thus, slots will be automatically released at the end
|
||||||
of a function. Hence, slots should always be used as local variables.
|
of a function. Hence, slots should always be used as local variables.
|
||||||
|
|
||||||
Slots are organized as follows:
|
Slots are organized as follows:
|
||||||
@ -44,15 +44,16 @@ Slots are not known to the yaam. Instead, A new set of slots is created when the
|
|||||||
- by the YAP_RunGoal() routines and friends, when they exit successfully. Notice that all handles created by c-goals within
|
- by the YAP_RunGoal() routines and friends, when they exit successfully. Notice that all handles created by c-goals within
|
||||||
a `Goal` execution should not be used afterwards.
|
a `Goal` execution should not be used afterwards.
|
||||||
|
|
||||||
This section lists the main internal functions for slot management. These functions are then exported through corresponding FLI C-functions
|
This section lists the main internal functions for slot management. These functions are then exported through corresponding FLI C-functions
|
||||||
|
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
/// @brief start a new set of slots, linking them to the last active slots (who may, or not, be active).
|
/// @brief declares a new set of slots.
|
||||||
/// Also states how many slots we had when we entered a segment of code.
|
/// Used to tell how many slots we had when we entered a segment of code.
|
||||||
static inline yhandle_t
|
#define Yap_StartSlots() Yap_StartSlots__( PASS_REGS1 )
|
||||||
|
|
||||||
Yap_StartSlots( USES_REGS1 ) {
|
static inline yhandle_t
|
||||||
|
Yap_StartSlots__( USES_REGS1 ) {
|
||||||
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
|
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
|
||||||
if (LOCAL_CurSlot < 0) {
|
if (LOCAL_CurSlot < 0) {
|
||||||
Yap_Error( SYSTEM_ERROR, 0L, " StartSlots = %ld", LOCAL_CurSlot);
|
Yap_Error( SYSTEM_ERROR, 0L, " StartSlots = %ld", LOCAL_CurSlot);
|
||||||
@ -62,8 +63,10 @@ if (LOCAL_CurSlot < 0) {
|
|||||||
|
|
||||||
|
|
||||||
/// @brief reset slots to a well-known position in the stack
|
/// @brief reset slots to a well-known position in the stack
|
||||||
|
#define Yap_CloseSlots( slot ) Yap_CloseSlots__( slot PASS_REGS )
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
Yap_CloseSlots( yhandle_t slot USES_REGS ) {
|
Yap_CloseSlots__( yhandle_t slot USES_REGS ) {
|
||||||
LOCAL_CurSlot = slot;
|
LOCAL_CurSlot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,9 +97,12 @@ Yap_GetPtrFromSlot(yhandle_t slot USES_REGS)
|
|||||||
return LOCAL_SlotBase[slot];
|
return LOCAL_SlotBase[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define Yap_AddressFromSlot( slot ) Yap_AddressFromSlot__(slot PASS_REGS)
|
||||||
|
|
||||||
|
|
||||||
/// @brief get the memory address of a slot
|
/// @brief get the memory address of a slot
|
||||||
static inline Term *
|
static inline Term *
|
||||||
Yap_AddressFromSlot(yhandle_t slot USES_REGS)
|
Yap_AddressFromSlot__(yhandle_t slot USES_REGS)
|
||||||
{
|
{
|
||||||
return LOCAL_SlotBase+slot;
|
return LOCAL_SlotBase+slot;
|
||||||
}
|
}
|
||||||
@ -111,7 +117,7 @@ Yap_PutInSlot(yhandle_t slot, Term t USES_REGS)
|
|||||||
#define max(X,Y) ( X > Y ? X : Y )
|
#define max(X,Y) ( X > Y ? X : Y )
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
ensure_slots(int N)
|
ensure_slots(int N USES_REGS)
|
||||||
{
|
{
|
||||||
if (LOCAL_CurSlot+N >= LOCAL_NSlots) {
|
if (LOCAL_CurSlot+N >= LOCAL_NSlots) {
|
||||||
size_t inc = max(16*1024, LOCAL_NSlots/2); // measured in cells
|
size_t inc = max(16*1024, LOCAL_NSlots/2); // measured in cells
|
||||||
@ -129,7 +135,7 @@ Yap_InitSlot(Term t USES_REGS)
|
|||||||
{
|
{
|
||||||
yhandle_t old_slots = LOCAL_CurSlot;
|
yhandle_t old_slots = LOCAL_CurSlot;
|
||||||
|
|
||||||
ensure_slots( 1 );
|
ensure_slots( 1 PASS_REGS);
|
||||||
LOCAL_SlotBase[old_slots] = t;
|
LOCAL_SlotBase[old_slots] = t;
|
||||||
LOCAL_CurSlot++;
|
LOCAL_CurSlot++;
|
||||||
return old_slots;
|
return old_slots;
|
||||||
@ -142,7 +148,7 @@ Yap_NewSlots(int n USES_REGS)
|
|||||||
yhandle_t old_slots = LOCAL_CurSlot;
|
yhandle_t old_slots = LOCAL_CurSlot;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
ensure_slots(n);
|
ensure_slots(n PASS_REGS);
|
||||||
for (i = 0; i< n; i++) {
|
for (i = 0; i< n; i++) {
|
||||||
RESET_VARIABLE(Yap_AddressFromSlot(old_slots+i) );
|
RESET_VARIABLE(Yap_AddressFromSlot(old_slots+i) );
|
||||||
}
|
}
|
||||||
@ -159,7 +165,7 @@ Yap_InitSlots__(int n, Term *ts USES_REGS)
|
|||||||
yhandle_t old_slots = LOCAL_CurSlot;
|
yhandle_t old_slots = LOCAL_CurSlot;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
ensure_slots( n );
|
ensure_slots( n PASS_REGS);
|
||||||
for (i=0; i< n; i++)
|
for (i=0; i< n; i++)
|
||||||
LOCAL_SlotBase[old_slots+i] = ts[i];
|
LOCAL_SlotBase[old_slots+i] = ts[i];
|
||||||
LOCAL_CurSlot += n;
|
LOCAL_CurSlot += n;
|
||||||
|
@ -40,7 +40,7 @@ extern void Yap_WriteAtom(IOSTREAM *s, Atom atom);
|
|||||||
|
|
||||||
extern atom_t codeToAtom(int chrcode);
|
extern atom_t codeToAtom(int chrcode);
|
||||||
|
|
||||||
#define valTermRef(t) ((Word)Yap_AddressFromSlot(t PASS_REGS))
|
#define valTermRef(t) ((Word)Yap_AddressFromSlot(t))
|
||||||
|
|
||||||
#include "pl-codelist.h"
|
#include "pl-codelist.h"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user