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);
|
||||||
|
|
2
C/init.c
2
C/init.c
|
@ -1234,7 +1234,7 @@ 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;
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
C/stdpreds.c
18
C/stdpreds.c
|
@ -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,16 +2093,15 @@ 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);
|
|
||||||
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers,
|
|
||||||
SafePredFlag | SyncPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
#ifdef INES
|
#ifdef INES
|
||||||
|
|
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