Merge branch 'master' of git://yap.git.sourceforge.net/gitroot/yap/yap-6.3
This commit is contained in:
12
C/absmi.c
Executable file → Normal file
12
C/absmi.c
Executable file → Normal file
@@ -1679,18 +1679,18 @@ Yap_absmi(int inp)
|
||||
*****************************************************************/
|
||||
|
||||
/* ensure_space */
|
||||
BOp(ensure_space, Osbpi);
|
||||
BOp(ensure_space, Osbpa);
|
||||
{
|
||||
Int sz = PREG->u.Osbpi.i;
|
||||
UInt arity = PREG->u.Osbpi.p->ArityOfPE;
|
||||
Int sz = PREG->u.Osbpa.i;
|
||||
UInt arity = PREG->u.Osbpa.p->ArityOfPE;
|
||||
if (Unsigned(H) + sz > Unsigned(YREG)-CreepFlag) {
|
||||
YENV[E_CP] = (CELL) CPREG;
|
||||
YENV[E_E] = (CELL) ENV;
|
||||
#ifdef DEPTH_LIMIT
|
||||
YENV[E_DEPTH] = DEPTH;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
SET_ASP(YREG, PREG->u.Osbpi.s);
|
||||
PREG = NEXTOP(PREG,Osbpi);
|
||||
SET_ASP(YREG, PREG->u.Osbpa.s);
|
||||
PREG = NEXTOP(PREG,Osbpa);
|
||||
saveregs();
|
||||
if (!Yap_gcl(sz, arity, YENV, PREG)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
|
||||
@@ -1700,7 +1700,7 @@ Yap_absmi(int inp)
|
||||
setregs();
|
||||
}
|
||||
} else {
|
||||
PREG = NEXTOP(PREG,Osbpi);
|
||||
PREG = NEXTOP(PREG,Osbpa);
|
||||
}
|
||||
}
|
||||
JMPNext();
|
||||
|
90
C/adtdefs.c
Executable file → Normal file
90
C/adtdefs.c
Executable file → Normal file
@@ -69,9 +69,9 @@ InlinedUnlockedMkFunctor(AtomEntry *ae, unsigned int arity)
|
||||
p->NameOfFE = AbsAtom(ae);
|
||||
p->ArityOfFE = arity;
|
||||
p->PropsOfFE = NIL;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
INIT_RWLOCK(p->FRWLock);
|
||||
ae->PropsOfAE = AbsProp((PropEntry *) p);
|
||||
/* respect the first property, in case this is a wide atom */
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
return ((Functor) p);
|
||||
}
|
||||
|
||||
@@ -104,8 +104,7 @@ Yap_MkFunctorWithAddress(Atom ap, unsigned int arity, FunctorEntry *p)
|
||||
p->KindOfPE = FunctorProperty;
|
||||
p->NameOfFE = ap;
|
||||
p->ArityOfFE = arity;
|
||||
p->NextOfPE = RepAtom(ap)->PropsOfAE;
|
||||
ae->PropsOfAE = AbsProp((PropEntry *) p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
|
||||
@@ -488,11 +487,51 @@ Yap_HasOp(Atom a)
|
||||
}
|
||||
}
|
||||
|
||||
OpEntry *
|
||||
Yap_OpPropForModule(Atom a, Term mod)
|
||||
{ /* look property list of atom a for kind */
|
||||
CACHE_REGS
|
||||
AtomEntry *ae = RepAtom(a);
|
||||
PropEntry *pp;
|
||||
OpEntry *info = NULL;
|
||||
|
||||
if (mod == TermProlog)
|
||||
mod = PROLOG_MODULE;
|
||||
WRITE_LOCK(ae->ARWLock);
|
||||
pp = RepProp(ae->PropsOfAE);
|
||||
while (!EndOfPAEntr(pp)) {
|
||||
if ( pp->KindOfPE == OpProperty) {
|
||||
info = (OpEntry *)pp;
|
||||
if (info->OpModule == mod) {
|
||||
WRITE_LOCK(info->OpRWLock);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
pp = pp->NextOfPE;
|
||||
}
|
||||
info = (OpEntry *) Yap_AllocAtomSpace(sizeof(OpEntry));
|
||||
info->KindOfPE = Ord(OpProperty);
|
||||
info->OpModule = mod;
|
||||
info->OpName = a;
|
||||
LOCK(OpListLock);
|
||||
info->OpNext = OpList;
|
||||
OpList = info;
|
||||
UNLOCK(OpListLock);
|
||||
AddPropToAtom(ae, (PropEntry *)info);
|
||||
INIT_RWLOCK(info->OpRWLock);
|
||||
WRITE_LOCK(info->OpRWLock);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
info->Prefix = info->Infix = info->Posfix = 0;
|
||||
return info;
|
||||
}
|
||||
|
||||
OpEntry *
|
||||
Yap_GetOpProp(Atom a, op_type type USES_REGS)
|
||||
{ /* look property list of atom a for kind */
|
||||
AtomEntry *ae = RepAtom(a);
|
||||
PropEntry *pp;
|
||||
OpEntry *oinfo = NULL;
|
||||
|
||||
READ_LOCK(ae->ARWLock);
|
||||
pp = RepProp(ae->PropsOfAE);
|
||||
@@ -524,9 +563,21 @@ Yap_GetOpProp(Atom a, op_type type USES_REGS)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
READ_LOCK(info->OpRWLock);
|
||||
/* if it is not the latest module */
|
||||
if (info->OpModule == PROLOG_MODULE) {
|
||||
/* cannot commit now */
|
||||
oinfo = info;
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
} else {
|
||||
READ_LOCK(info->OpRWLock);
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
if (oinfo) {
|
||||
READ_LOCK(oinfo->OpRWLock);
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return info;
|
||||
return oinfo;
|
||||
}
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return NULL;
|
||||
@@ -898,7 +949,6 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
|
||||
p->beamTable = NULL;
|
||||
#endif
|
||||
/* careful that they don't cross MkFunctor */
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
if (PRED_GOAL_EXPANSION_FUNC) {
|
||||
Prop p1 = ae->PropsOfAE;
|
||||
|
||||
@@ -914,7 +964,8 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
|
||||
p1 = pe->NextOfPE;
|
||||
}
|
||||
}
|
||||
ae->PropsOfAE = p0 = AbsPredProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
p0 = AbsPredProp(p);
|
||||
p->FunctorOfPred = (Functor)AbsAtom(ae);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
#ifdef LOW_PROF
|
||||
@@ -940,8 +991,14 @@ Yap_PredPropByFunctorNonThreadLocal(Functor f, Term cur_mod)
|
||||
return Yap_NewPredPropByFunctor(f,cur_mod);
|
||||
|
||||
if ((p->ModuleOfPred == cur_mod || !(p->ModuleOfPred))) {
|
||||
WRITE_UNLOCK(f->FRWLock);
|
||||
return AbsPredProp(p);
|
||||
/* don't match multi-files */
|
||||
if (!(p->PredFlags & MultiFileFlag) ||
|
||||
p->ModuleOfPred ||
|
||||
!cur_mod ||
|
||||
cur_mod == TermProlog) {
|
||||
WRITE_UNLOCK(f->FRWLock);
|
||||
return AbsPredProp(p);
|
||||
}
|
||||
}
|
||||
if (p->NextOfPE) {
|
||||
UInt hash = PRED_HASH(f,cur_mod,PredHashTableSize);
|
||||
@@ -976,8 +1033,14 @@ Yap_PredPropByAtomNonThreadLocal(Atom at, Term cur_mod)
|
||||
PredEntry *pe = RepPredProp(p0);
|
||||
if ( pe->KindOfPE == PEProp &&
|
||||
(pe->ModuleOfPred == cur_mod || !pe->ModuleOfPred)) {
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return(p0);
|
||||
/* don't match multi-files */
|
||||
if (!(pe->PredFlags & MultiFileFlag) ||
|
||||
pe->ModuleOfPred ||
|
||||
!cur_mod ||
|
||||
cur_mod == TermProlog) {
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return(p0);
|
||||
}
|
||||
}
|
||||
p0 = pe->NextOfPE;
|
||||
}
|
||||
@@ -1033,10 +1096,9 @@ Yap_PutValue(Atom a, Term v)
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return;
|
||||
}
|
||||
p->NextOfPE = RepAtom(a)->PropsOfAE;
|
||||
RepAtom(a)->PropsOfAE = AbsValProp(p);
|
||||
p->KindOfPE = ValProperty;
|
||||
p->ValueOfVE = TermNil;
|
||||
AddPropToAtom(RepAtom(a), (PropEntry *)p);
|
||||
/* take care that the lock for the property will be inited even
|
||||
if someone else searches for the property */
|
||||
INIT_RWLOCK(p->VRWLock);
|
||||
|
2
C/alloc.c
Executable file → Normal file
2
C/alloc.c
Executable file → Normal file
@@ -1065,7 +1065,7 @@ mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
|
||||
#else
|
||||
char file[YAP_FILENAME_MAX];
|
||||
strcpy(file,"/tmp/mapfile");
|
||||
itos(getpid(), &file[12]);
|
||||
itos(getpid(), &file[12]);
|
||||
#endif /* HAVE_TMPNAM */
|
||||
#endif /* HAVE_MKSTEMP */
|
||||
fd = open(file, O_CREAT|O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
|
13
C/amasm.c
Executable file → Normal file
13
C/amasm.c
Executable file → Normal file
@@ -1104,12 +1104,12 @@ a_ensure_space(op_numbers opcode, yamop *code_p, int pass_no, struct intermediat
|
||||
if (cip->cpc->rnd1 > 4096) {
|
||||
if (pass_no) {
|
||||
code_p->opc = emit_op(opcode);
|
||||
code_p->u.Osbpi.i = sizeof(CELL) * cip->cpc->rnd1;
|
||||
code_p->u.Osbpi.p = clinfo->CurrentPred;
|
||||
code_p->u.Osbpi.bmap = NULL;
|
||||
code_p->u.Osbpi.s = emit_count(-Signed(RealEnvSize));
|
||||
code_p->u.Osbpa.i = sizeof(CELL) * cip->cpc->rnd1;
|
||||
code_p->u.Osbpa.p = clinfo->CurrentPred;
|
||||
code_p->u.Osbpa.bmap = NULL;
|
||||
code_p->u.Osbpa.s = emit_count(-Signed(RealEnvSize));
|
||||
}
|
||||
GONEXT(Osbpi);
|
||||
GONEXT(Osbpa);
|
||||
}
|
||||
return code_p;
|
||||
}
|
||||
@@ -3037,7 +3037,6 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp
|
||||
cl_u->luc.ClFlags |= HasCutMask;
|
||||
cl_u->luc.ClRefCount = 0;
|
||||
cl_u->luc.ClPred = cip->CurrentPred;
|
||||
cl_u->luc.ClSize = size;
|
||||
/* Support for timestamps */
|
||||
if (cip->CurrentPred->LastCallOfPred != LUCALL_ASSERT) {
|
||||
if (cip->CurrentPred->TimeStampOfPred >= TIMESTAMP_RESET)
|
||||
@@ -3948,8 +3947,10 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
|
||||
}
|
||||
if (mode == ASSEMBLING_CLAUSE) {
|
||||
if (ap->PredFlags & LogUpdatePredFlag) {
|
||||
((LogUpdClause *)(cip->code_addr))->ClSize = size;
|
||||
Yap_LUClauseSpace += size;
|
||||
} else
|
||||
((StaticClause *)(cip->code_addr))->ClSize = size;
|
||||
Yap_ClauseSpace += size;
|
||||
} else {
|
||||
if (ap->PredFlags & LogUpdatePredFlag) {
|
||||
|
@@ -198,8 +198,7 @@ Yap_InitConstExps(void)
|
||||
p->ArityOfEE = 0;
|
||||
p->ENoOfEE = 0;
|
||||
p->FOfEE = InitConstTab[i].f;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsExpProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
}
|
||||
|
3
C/arith1.c
Executable file → Normal file
3
C/arith1.c
Executable file → Normal file
@@ -835,8 +835,7 @@ Yap_InitUnaryExps(void)
|
||||
p->ArityOfEE = 1;
|
||||
p->ENoOfEE = 1;
|
||||
p->FOfEE = InitUnTab[i].f;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsExpProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
Yap_InitCPred("is", 3, p_unary_is, TestPredFlag | SafePredFlag);
|
||||
|
3
C/arith2.c
Executable file → Normal file
3
C/arith2.c
Executable file → Normal file
@@ -1217,8 +1217,7 @@ Yap_InitBinaryExps(void)
|
||||
p->ArityOfEE = 2;
|
||||
p->ENoOfEE = 2;
|
||||
p->FOfEE = InitBinTab[i].f;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsExpProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
Yap_InitCPred("is", 4, p_binary_is, TestPredFlag | SafePredFlag);
|
||||
|
@@ -566,9 +566,8 @@ CreateNamedArray(PropEntry * pp, Int dim, AtomEntry *ae USES_REGS)
|
||||
|
||||
p = (ArrayEntry *) Yap_AllocAtomSpace(sizeof(*p));
|
||||
p->KindOfPE = ArrayProperty;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
INIT_RWLOCK(p->ArRWLock);
|
||||
ae->PropsOfAE = AbsArrayProp(p);
|
||||
#if THREADS
|
||||
p->owner_id = worker_id;
|
||||
#endif
|
||||
@@ -629,15 +628,14 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
|
||||
}
|
||||
}
|
||||
p->KindOfPE = ArrayProperty;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
INIT_RWLOCK(p->ArRWLock);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
p->NextAE = LOCAL_StaticArrays;
|
||||
LOCAL_StaticArrays = p;
|
||||
}
|
||||
WRITE_LOCK(p->ArRWLock);
|
||||
p->ArrayEArity = -dim;
|
||||
p->ArrayType = type;
|
||||
ae->PropsOfAE = AbsArrayProp((ArrayEntry *)p);
|
||||
if (start_addr == NULL) {
|
||||
int i;
|
||||
|
||||
|
3
C/bb.c
3
C/bb.c
@@ -43,8 +43,7 @@ PutBBProp(AtomEntry *ae, Term mod USES_REGS) /* get BBentry for at; */
|
||||
Yap_Error(OUT_OF_HEAP_ERROR,ARG1,"could not allocate space in bb_put/2");
|
||||
return(NULL);
|
||||
}
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsBBProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
p->ModuleOfBB = mod;
|
||||
p->Element = 0L;
|
||||
p->KeyOfBB = AbsAtom(ae);
|
||||
|
0
C/bignum.c
Executable file → Normal file
0
C/bignum.c
Executable file → Normal file
27
C/c_interface.c
Executable file → Normal file
27
C/c_interface.c
Executable file → Normal file
@@ -2378,10 +2378,18 @@ YAP_RunGoalOnce(Term t)
|
||||
CACHE_REGS
|
||||
Term out;
|
||||
yamop *old_CP = CP;
|
||||
Int oldPrologMode = LOCAL_PrologMode;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
LOCAL_PrologMode = UserMode;
|
||||
out = Yap_RunTopGoal(t);
|
||||
LOCAL_PrologMode = UserCCallMode;
|
||||
LOCAL_PrologMode = oldPrologMode;
|
||||
if (!(oldPrologMode & UserCCallMode)) {
|
||||
/* called from top-level */
|
||||
LOCAL_AllowRestart = FALSE;
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
if (out) {
|
||||
choiceptr cut_pt, ob;
|
||||
|
||||
@@ -2810,7 +2818,7 @@ construct_init_file(char *boot_file, char *BootFile)
|
||||
/* this routine is supposed to be called from an external program
|
||||
that wants to control Yap */
|
||||
|
||||
#if defined(USE_SYSTEM_MALLOC)
|
||||
#if defined(USE_SYSTEM_MALLOC) && FALSE
|
||||
#define BOOT_FROM_SAVED_STATE FALSE
|
||||
#else
|
||||
#define BOOT_FROM_SAVED_STATE TRUE
|
||||
@@ -2840,8 +2848,8 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
yap_init->SavedState = NULL;
|
||||
}
|
||||
#endif
|
||||
if (BOOT_FROM_SAVED_STATE && !do_bootstrap) {
|
||||
if (Yap_SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap) != 1) {
|
||||
if (FALSE && BOOT_FROM_SAVED_STATE && !do_bootstrap) {
|
||||
if (Yap_SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap)) {
|
||||
yap_init->ErrorNo = LOCAL_Error_TYPE;
|
||||
yap_init->ErrorCause = LOCAL_ErrorMessage;
|
||||
return YAP_BOOT_ERROR;
|
||||
@@ -3146,9 +3154,14 @@ YAP_Reset(void)
|
||||
if (B != NULL) {
|
||||
while (B->cp_b != NULL)
|
||||
B = B->cp_b;
|
||||
P = (yamop *)FAILCODE;
|
||||
if (Yap_exec_absmi(0) != 0)
|
||||
return(FALSE);
|
||||
P = FAILCODE;
|
||||
if (Yap_exec_absmi(0) != 0) {
|
||||
GLOBAL_Initialised = TRUE;
|
||||
|
||||
Yap_InitYaamRegs();
|
||||
RECOVER_MACHINE_REGS();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/* reinitialise the engine */
|
||||
Yap_InitYaamRegs();
|
||||
|
49
C/cdmgr.c
49
C/cdmgr.c
@@ -838,7 +838,9 @@ Yap_BuildMegaClause(PredEntry *ap)
|
||||
required = sz*ap->cs.p_code.NOfClauses+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l);
|
||||
#ifdef DEBUG
|
||||
total_megaclause += required;
|
||||
total_released += ap->cs.p_code.NOfClauses*(sz+sizeof(StaticClause));
|
||||
cl =
|
||||
ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
|
||||
total_released += ap->cs.p_code.NOfClauses*cl->ClSize;
|
||||
nof_megaclauses++;
|
||||
#endif
|
||||
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
|
||||
@@ -850,7 +852,7 @@ Yap_BuildMegaClause(PredEntry *ap)
|
||||
Yap_ClauseSpace += required;
|
||||
/* cool, it's our turn to do the conversion */
|
||||
mcl->ClFlags = MegaMask | has_blobs;
|
||||
mcl->ClSize = sz*ap->cs.p_code.NOfClauses;
|
||||
mcl->ClSize = required;
|
||||
mcl->ClPred = ap;
|
||||
mcl->ClItemSize = sz;
|
||||
mcl->ClNext = NULL;
|
||||
@@ -1603,7 +1605,7 @@ retract_all(PredEntry *p, int in_use)
|
||||
}
|
||||
p->cs.p_code.FirstClause = NULL;
|
||||
p->cs.p_code.LastClause = NULL;
|
||||
if (p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag)) {
|
||||
if (p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|MultiFileFlag)) {
|
||||
p->OpcodeOfPred = FAIL_OPCODE;
|
||||
} else {
|
||||
p->OpcodeOfPred = UNDEF_OPCODE;
|
||||
@@ -1631,6 +1633,19 @@ retract_all(PredEntry *p, int in_use)
|
||||
Yap_PutValue(AtomAbol, MkAtomTerm(AtomTrue));
|
||||
}
|
||||
|
||||
static int
|
||||
source_pred(PredEntry *p, yamop *q)
|
||||
{
|
||||
if (p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))
|
||||
return FALSE;
|
||||
if (p->PredFlags & MultiFileFlag)
|
||||
return TRUE;
|
||||
if (yap_flags[SOURCE_MODE_FLAG]) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* p is already locked */
|
||||
static void
|
||||
add_first_static(PredEntry *p, yamop *cp, int spy_flag)
|
||||
@@ -1682,12 +1697,8 @@ add_first_static(PredEntry *p, yamop *cp, int spy_flag)
|
||||
p->OpcodeOfPred = Yap_opcode(_spy_pred);
|
||||
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
||||
}
|
||||
if ((yap_flags[SOURCE_MODE_FLAG] ||
|
||||
(p->PredFlags & MultiFileFlag)) &&
|
||||
!(p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
||||
if (source_pred(p, cp)) {
|
||||
p->PredFlags |= SourcePredFlag;
|
||||
} else {
|
||||
p->PredFlags &= ~SourcePredFlag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1938,6 +1949,24 @@ assertz_dynam_clause(PredEntry *p, yamop *cp)
|
||||
p->cs.p_code.NOfClauses++;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_AssertzClause(PredEntry *p, yamop *cp)
|
||||
{
|
||||
if (p->PredFlags & DynamicPredFlag) {
|
||||
if (p->cs.p_code.FirstClause == NULL) {
|
||||
add_first_dynamic(p, cp, FALSE);
|
||||
} else {
|
||||
assertz_dynam_clause(p, cp);
|
||||
}
|
||||
} else {
|
||||
if (p->cs.p_code.FirstClause == NULL) {
|
||||
add_first_static(p, cp, FALSE);
|
||||
} else {
|
||||
assertz_stat_clause(p, cp, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void expand_consult( void )
|
||||
{
|
||||
CACHE_REGS
|
||||
@@ -2070,7 +2099,6 @@ mark_preds_with_this_func(Functor f, Prop p0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref)
|
||||
/*
|
||||
@@ -2609,8 +2637,6 @@ purge_clauses(PredEntry *pred)
|
||||
retract_all(pred, static_in_use(pred,TRUE));
|
||||
}
|
||||
pred->src.OwnerFile = AtomNil;
|
||||
if (pred->PredFlags & MultiFileFlag)
|
||||
pred->PredFlags ^= MultiFileFlag;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2856,6 +2882,7 @@ p_new_multifile( USES_REGS1 )
|
||||
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, arity),mod));
|
||||
PELOCK(26,pe);
|
||||
pe->PredFlags |= MultiFileFlag;
|
||||
/* mutifile-predicates are weird, they do not seat really on the default module */
|
||||
if (pe->ModuleOfPred == PROLOG_MODULE)
|
||||
pe->ModuleOfPred = TermProlog;
|
||||
if (!(pe->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
||||
|
2
C/compiler.c
Executable file → Normal file
2
C/compiler.c
Executable file → Normal file
@@ -737,7 +737,7 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct
|
||||
if (optimizer_on && level < 6) {
|
||||
#if !defined(THREADS) && !defined(YAPOR)
|
||||
/* discard code sharing because we cannot write on shared stuff */
|
||||
if (!(cglobs->cint.CurrentPred->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
||||
if (FALSE && !(cglobs->cint.CurrentPred->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) {
|
||||
if (try_store_as_dbterm(t, argno, arity, level, cglobs))
|
||||
return;
|
||||
}
|
||||
|
0
C/computils.c
Executable file → Normal file
0
C/computils.c
Executable file → Normal file
64
C/dbase.c
Executable file → Normal file
64
C/dbase.c
Executable file → Normal file
@@ -1221,19 +1221,22 @@ CreateDBWithDBRef(Term Tm, DBProp p, struct db_globs *dbg)
|
||||
DBTerm *ppt;
|
||||
|
||||
if (p == NULL) {
|
||||
ppt = (DBTerm *)AllocDBSpace(sizeof(DBTerm)+2*sizeof(CELL));
|
||||
UInt sz = sizeof(DBTerm)+2*sizeof(CELL);
|
||||
ppt = (DBTerm *)AllocDBSpace(sz);
|
||||
if (ppt == NULL) {
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, TermNil, "could not allocate space");
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, TermNil, "could not allocate heap");
|
||||
}
|
||||
dbg->sz = sizeof(DBTerm)+2*sizeof(CELL);
|
||||
Yap_LUClauseSpace += sizeof(DBTerm)+2*sizeof(CELL);
|
||||
dbg->sz = sz;
|
||||
Yap_LUClauseSpace += sz;
|
||||
pp = (DBRef)ppt;
|
||||
} else {
|
||||
pp = AllocDBSpace(DBLength(2*sizeof(DBRef)));
|
||||
UInt sz = DBLength(2*sizeof(DBRef));
|
||||
pp = AllocDBSpace(sz);
|
||||
if (pp == NULL) {
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, 0, "could not allocate space");
|
||||
}
|
||||
Yap_LUClauseSpace += DBLength(2*sizeof(DBRef));
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
pp->id = FunctorDBRef;
|
||||
pp->Flags = DBNoVars|DBComplex|DBWithRefs;
|
||||
INIT_LOCK(pp->lock);
|
||||
@@ -1261,13 +1264,14 @@ static DBTerm *
|
||||
CreateDBTermForAtom(Term Tm, UInt extra_size, struct db_globs *dbg) {
|
||||
DBTerm *ppt;
|
||||
ADDR ptr;
|
||||
UInt sz = extra_size+sizeof(DBTerm);
|
||||
|
||||
ptr = (ADDR)AllocDBSpace(extra_size+sizeof(DBTerm));
|
||||
ptr = (ADDR)AllocDBSpace(sz);
|
||||
if (ptr == NULL) {
|
||||
return (DBTerm *)generate_dberror_msg(OUT_OF_HEAP_ERROR, 0, "could not allocate space");
|
||||
}
|
||||
Yap_LUClauseSpace += extra_size+sizeof(DBTerm);
|
||||
dbg->sz = extra_size+sizeof(DBTerm);
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
ppt = (DBTerm *)(ptr+extra_size);
|
||||
ppt->NOfCells = 0;
|
||||
ppt->DBRefs = NULL;
|
||||
@@ -1284,13 +1288,14 @@ CreateDBTermForVar(UInt extra_size, struct db_globs *dbg)
|
||||
{
|
||||
DBTerm *ppt;
|
||||
ADDR ptr;
|
||||
UInt sz = extra_size+sizeof(DBTerm);
|
||||
|
||||
ptr = (ADDR)AllocDBSpace(extra_size+sizeof(DBTerm));
|
||||
ptr = (ADDR)AllocDBSpace(sz);
|
||||
if (ptr == NULL) {
|
||||
return (DBTerm *)generate_dberror_msg(OUT_OF_HEAP_ERROR, 0, "could not allocate space");
|
||||
}
|
||||
Yap_LUClauseSpace += extra_size+sizeof(DBTerm);
|
||||
dbg->sz = extra_size+sizeof(DBTerm);
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
ppt = (DBTerm *)(ptr+extra_size);
|
||||
ppt->NOfCells = 0;
|
||||
ppt->DBRefs = NULL;
|
||||
@@ -1306,16 +1311,17 @@ static DBRef
|
||||
CreateDBRefForAtom(Term Tm, DBProp p, int InFlag, struct db_globs *dbg) {
|
||||
Register DBRef pp;
|
||||
SMALLUNSGN flag;
|
||||
UInt sz = DBLength(NIL);
|
||||
|
||||
flag = DBAtomic;
|
||||
if (InFlag & MkIfNot && (dbg->found_one = check_if_cons(p->First, Tm)))
|
||||
return dbg->found_one;
|
||||
pp = AllocDBSpace(DBLength(NIL));
|
||||
pp = AllocDBSpace(sz);
|
||||
if (pp == NIL) {
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, 0, "could not allocate space");
|
||||
}
|
||||
Yap_LUClauseSpace += DBLength(NIL);
|
||||
dbg->sz = DBLength(NIL);
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
pp->id = FunctorDBRef;
|
||||
INIT_LOCK(pp->lock);
|
||||
INIT_DBREF_COUNT(pp);
|
||||
@@ -1333,15 +1339,16 @@ CreateDBRefForAtom(Term Tm, DBProp p, int InFlag, struct db_globs *dbg) {
|
||||
static DBRef
|
||||
CreateDBRefForVar(Term Tm, DBProp p, int InFlag, struct db_globs *dbg) {
|
||||
Register DBRef pp;
|
||||
UInt sz = DBLength(NULL);
|
||||
|
||||
if (InFlag & MkIfNot && (dbg->found_one = check_if_var(p->First)))
|
||||
return dbg->found_one;
|
||||
pp = AllocDBSpace(DBLength(NULL));
|
||||
pp = AllocDBSpace(sz);
|
||||
if (pp == NULL) {
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, 0, "could not allocate space");
|
||||
}
|
||||
Yap_LUClauseSpace += DBLength(NULL);
|
||||
dbg->sz = DBLength(NULL);
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
pp->id = FunctorDBRef;
|
||||
pp->Flags = DBVar;
|
||||
pp->DBT.Entry = (CELL) Tm;
|
||||
@@ -1549,23 +1556,25 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc
|
||||
}
|
||||
#endif
|
||||
if (p == NULL) {
|
||||
ADDR ptr = Yap_AllocCodeSpace((CELL)CodeAbs+extra_size+sizeof(DBTerm));
|
||||
UInt sz = (CELL)CodeAbs+extra_size+sizeof(DBTerm);
|
||||
ADDR ptr = Yap_AllocCodeSpace(sz);
|
||||
ppt = (DBTerm *)(ptr+extra_size);
|
||||
if (ptr == NULL) {
|
||||
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, (UInt)DBLength(CodeAbs), "heap crashed against stacks");
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, sz, "heap crashed against stacks");
|
||||
}
|
||||
Yap_LUClauseSpace += (CELL)CodeAbs+extra_size+sizeof(DBTerm);
|
||||
dbg->sz = (CELL)CodeAbs+extra_size+sizeof(DBTerm);
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
pp = (DBRef)ppt;
|
||||
} else {
|
||||
pp = AllocDBSpace(DBLength(CodeAbs));
|
||||
UInt sz = DBLength(CodeAbs);
|
||||
pp = AllocDBSpace(sz);
|
||||
if (pp == NULL) {
|
||||
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, (UInt)DBLength(CodeAbs), "heap crashed against stacks");
|
||||
return generate_dberror_msg(OUT_OF_HEAP_ERROR, sz, "heap crashed against stacks");
|
||||
}
|
||||
Yap_LUClauseSpace += DBLength(CodeAbs);
|
||||
dbg->sz = DBLength(CodeAbs);
|
||||
Yap_LUClauseSpace += sz;
|
||||
dbg->sz = sz;
|
||||
pp->id = FunctorDBRef;
|
||||
pp->Flags = flag;
|
||||
INIT_LOCK(pp->lock);
|
||||
@@ -2896,8 +2905,7 @@ FetchDBPropFromKey(Term twork, int flag, int new, char *error_mssg)
|
||||
p->FunctorOfDB = (Functor) At;
|
||||
else
|
||||
p->FunctorOfDB = Yap_UnlockedMkFunctor(ae,arity);
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsDBProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
}
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return
|
||||
|
0
C/dlmalloc.c
Executable file → Normal file
0
C/dlmalloc.c
Executable file → Normal file
0
C/errors.c
Executable file → Normal file
0
C/errors.c
Executable file → Normal file
2
C/exec.c
2
C/exec.c
@@ -984,7 +984,7 @@ exec_absmi(int top USES_REGS)
|
||||
break;
|
||||
case 3:
|
||||
{ /* saved state */
|
||||
return(FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
default:
|
||||
/* do nothing */
|
||||
|
@@ -858,8 +858,7 @@ GetGlobalEntry(Atom at USES_REGS)
|
||||
new->NextGE = LOCAL_GlobalVariables;
|
||||
LOCAL_GlobalVariables = new;
|
||||
new->AtomOfGE = ae;
|
||||
new->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsGlobalProp(new);
|
||||
AddPropToAtom(ae, (PropEntry *)new);
|
||||
RESET_VARIABLE(&new->global);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return new;
|
||||
|
0
C/gmp_support.c
Executable file → Normal file
0
C/gmp_support.c
Executable file → Normal file
9
C/grow.c
Executable file → Normal file
9
C/grow.c
Executable file → Normal file
@@ -1216,13 +1216,16 @@ fix_tabling_info( USES_REGS1 )
|
||||
while (df) {
|
||||
if (DepFr_backchain_cp(df))
|
||||
DepFr_backchain_cp(df) = ChoicePtrAdjust(DepFr_backchain_cp(df));
|
||||
DepFr_leader_cp(df) = ChoicePtrAdjust(DepFr_leader_cp(df));
|
||||
DepFr_cons_cp(df) = ConsumerChoicePtrAdjust(DepFr_cons_cp(df));
|
||||
if (DepFr_leader_cp(df))
|
||||
DepFr_leader_cp(df) = ChoicePtrAdjust(DepFr_leader_cp(df));
|
||||
if (DepFr_cons_cp(df))
|
||||
DepFr_cons_cp(df) = ConsumerChoicePtrAdjust(DepFr_cons_cp(df));
|
||||
df = DepFr_next(df);
|
||||
}
|
||||
sg = LOCAL_top_sg_fr;
|
||||
while (sg) {
|
||||
SgFr_gen_cp(sg) = GeneratorChoicePtrAdjust(SgFr_gen_cp(sg));
|
||||
if (SgFr_gen_cp(sg))
|
||||
SgFr_gen_cp(sg) = GeneratorChoicePtrAdjust(SgFr_gen_cp(sg));
|
||||
sg = SgFr_next(sg);
|
||||
}
|
||||
}
|
||||
|
2
C/heapgc.c
Executable file → Normal file
2
C/heapgc.c
Executable file → Normal file
@@ -1915,7 +1915,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
|
||||
if (pe == NULL) {
|
||||
fprintf(GLOBAL_stderr,"%% marked " UInt_FORMAT " (%s)\n", LOCAL_total_marked, Yap_op_names[opnum]);
|
||||
} else if (pe->ArityOfPE) {
|
||||
fprintf(GLOBAL_stderr,"%% %s/%d marked " UInt_FORMAT " (%s)\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, LOCAL_total_marked, Yap_op_names[opnum]);
|
||||
fprintf(GLOBAL_stderr,"%% %s/" UInt_FORMAT " marked " UInt_FORMAT " (%s)\n", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, LOCAL_total_marked, Yap_op_names[opnum]);
|
||||
} else {
|
||||
fprintf(GLOBAL_stderr,"%% %s marked " UInt_FORMAT " (%s)\n", RepAtom((Atom)(pe->FunctorOfPred))->StrOfAE, LOCAL_total_marked, Yap_op_names[opnum]);
|
||||
}
|
||||
|
10
C/index.c
10
C/index.c
@@ -2671,7 +2671,8 @@ init_clauses(ClauseDef *cl, PredEntry *ap)
|
||||
{
|
||||
if (ap->PredFlags & MegaClausePredFlag) {
|
||||
MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
|
||||
yamop *end = (yamop *)((char *)mcl->ClCode+mcl->ClSize);
|
||||
UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses;
|
||||
yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize);
|
||||
yamop *cd = mcl->ClCode;
|
||||
while (cd < end) {
|
||||
cl->Code = cl->CurrentCode = cd;
|
||||
@@ -2926,7 +2927,8 @@ install_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg,
|
||||
istack_entry *sp = stack;
|
||||
if (ap->PredFlags & MegaClausePredFlag) {
|
||||
MegaClause *mcl = ClauseCodeToMegaClause(beg);
|
||||
yamop *end = (yamop *)((char *)mcl->ClCode+mcl->ClSize);
|
||||
UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses;
|
||||
yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize);
|
||||
yamop *cd = mcl->ClCode;
|
||||
|
||||
if (stack[0].pos == 0) {
|
||||
@@ -3211,7 +3213,7 @@ count_clauses_left(yamop *cl, PredEntry *ap)
|
||||
return i;
|
||||
} else if (ap->PredFlags & MegaClausePredFlag) {
|
||||
MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
|
||||
UInt ncls = mcl->ClSize/mcl->ClItemSize;
|
||||
UInt ncls = mcl->ClPred->cs.p_code.NOfClauses;
|
||||
|
||||
return (ncls-1)-((char *)cl-(char *)mcl->ClCode)/mcl->ClItemSize;
|
||||
} else {
|
||||
@@ -5979,7 +5981,7 @@ Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) {
|
||||
}
|
||||
#endif
|
||||
ap->OpcodeOfPred = Yap_opcode(_op_fail);
|
||||
} else {
|
||||
} else if (ap->PredFlags & IndexedPredFlag) {
|
||||
remove_from_index(ap, sp, &cl, beg, last, &cint);
|
||||
}
|
||||
}
|
||||
|
9
C/init.c
Executable file → Normal file
9
C/init.c
Executable file → Normal file
@@ -151,14 +151,13 @@ OpDec(int p, char *type, Atom a, Term m)
|
||||
if (EndOfPAEntr(info)) {
|
||||
info = (OpEntry *) Yap_AllocAtomSpace(sizeof(OpEntry));
|
||||
info->KindOfPE = Ord(OpProperty);
|
||||
info->NextOfPE = RepAtom(a)->PropsOfAE;
|
||||
info->OpModule = m;
|
||||
info->OpName = a;
|
||||
LOCK(OpListLock);
|
||||
info->OpNext = OpList;
|
||||
OpList = info;
|
||||
UNLOCK(OpListLock);
|
||||
RepAtom(a)->PropsOfAE = AbsOpProp(info);
|
||||
AddPropToAtom(ae, (PropEntry *)info);
|
||||
INIT_RWLOCK(info->OpRWLock);
|
||||
WRITE_LOCK(info->OpRWLock);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
@@ -391,8 +390,6 @@ update_flags_from_prolog(UInt flags, PredEntry *pe)
|
||||
flags |= SourcePredFlag;
|
||||
if (pe->PredFlags & SequentialPredFlag)
|
||||
flags |= SequentialPredFlag;
|
||||
if (pe->PredFlags & MyddasPredFlag)
|
||||
flags |= MyddasPredFlag;
|
||||
if (pe->PredFlags & UDIPredFlag)
|
||||
flags |= UDIPredFlag;
|
||||
if (pe->PredFlags & ModuleTransparentPredFlag)
|
||||
@@ -799,9 +796,9 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
|
||||
StaticClause *cl;
|
||||
yamop *code = ((StaticClause *)NULL)->ClCode;
|
||||
if (flags & UserCPredFlag)
|
||||
pe->PredFlags = UserCPredFlag | CompiledPredFlag | StandardPredFlag | flags;
|
||||
pe->PredFlags = UserCPredFlag | BackCPredFlag| CompiledPredFlag | StandardPredFlag | flags;
|
||||
else
|
||||
pe->PredFlags = CompiledPredFlag | StandardPredFlag;
|
||||
pe->PredFlags = CompiledPredFlag | StandardPredFlag | BackCPredFlag;
|
||||
|
||||
#ifdef YAPOR
|
||||
pe->PredFlags |= SequentialPredFlag;
|
||||
|
0
C/inlines.c
Executable file → Normal file
0
C/inlines.c
Executable file → Normal file
31
C/iopreds.c
31
C/iopreds.c
@@ -754,8 +754,10 @@ p_read2 ( USES_REGS1 )
|
||||
Int out;
|
||||
|
||||
if (!Yap_getInputStream(Yap_InitSlot(Deref(ARG8) PASS_REGS), &inp_stream)) {
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
return(FALSE);
|
||||
}
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
out = do_read(inp_stream, 8 PASS_REGS);
|
||||
return out;
|
||||
}
|
||||
@@ -1077,33 +1079,6 @@ p_float_format( USES_REGS1 )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern IOENC Yap_DefaultEncoding(void);
|
||||
extern void Yap_SetDefaultEncoding(IOENC);
|
||||
extern int PL_get_stream_handle(Int, IOSTREAM **);
|
||||
|
||||
static Int
|
||||
p_get_default_encoding( USES_REGS1 )
|
||||
{
|
||||
Term out = MkIntegerTerm(Yap_DefaultEncoding());
|
||||
return Yap_unify(ARG1, out);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_encoding ( USES_REGS1 )
|
||||
{ /* '$encoding'(Stream,N) */
|
||||
IOSTREAM *st;
|
||||
Term t = Deref(ARG2);
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &st)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (IsVarTerm(t)) {
|
||||
return Yap_unify(ARG2, MkIntegerTerm(st->encoding));
|
||||
}
|
||||
st->encoding = IntegerOfTerm(Deref(ARG2));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Yap_InitBackIO (void)
|
||||
{
|
||||
@@ -1128,8 +1103,6 @@ Yap_InitIOPreds(void)
|
||||
Yap_InitCPred ("$all_char_conversions", 1, p_all_char_conversions, SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$force_char_conversion", 0, p_force_char_conversion, SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$disable_char_conversion", 0, p_disable_char_conversion, SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$get_default_encoding", 1, p_get_default_encoding, SafePredFlag|TestPredFlag);
|
||||
Yap_InitCPred ("$encoding", 2, p_encoding, SafePredFlag|SyncPredFlag),
|
||||
#if HAVE_SELECT
|
||||
// Yap_InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
|
||||
#endif
|
||||
|
2
C/load_dl.c
Executable file → Normal file
2
C/load_dl.c
Executable file → Normal file
@@ -168,7 +168,7 @@ Yap_ShutdownLoadForeign(void)
|
||||
objs = f_code->objs;
|
||||
while (objs != NULL) {
|
||||
if (dlclose(objs->handle) != 0)
|
||||
return; /* ERROR */
|
||||
return; /* ERROR */
|
||||
objs = objs->next;
|
||||
}
|
||||
libs = f_code->libs;
|
||||
|
0
C/load_dll.c
Executable file → Normal file
0
C/load_dll.c
Executable file → Normal file
0
C/load_foreign.c
Executable file → Normal file
0
C/load_foreign.c
Executable file → Normal file
@@ -72,8 +72,7 @@ GetModuleEntry(Atom at)
|
||||
new->NextME = CurrentModules;
|
||||
CurrentModules = new;
|
||||
new->AtomOfME = ae;
|
||||
new->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsModProp(new);
|
||||
AddPropToAtom(ae, (PropEntry *)new);
|
||||
return new;
|
||||
}
|
||||
|
||||
|
1268
C/pl-yap.c
Normal file
1268
C/pl-yap.c
Normal file
File diff suppressed because it is too large
Load Diff
730
C/qlyw.c
Normal file
730
C/qlyw.c
Normal file
@@ -0,0 +1,730 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: qlyw.c *
|
||||
* comments: quick saver/loader *
|
||||
* *
|
||||
* Last rev: $Date: 2011-08-29$,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $ *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#include <SWI-Stream.h>
|
||||
#include "absmi.h"
|
||||
#include "Foreign.h"
|
||||
#include "alloc.h"
|
||||
#include "yapio.h"
|
||||
#include "iopreds.h"
|
||||
#include "attvar.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include "qly.h"
|
||||
|
||||
STATIC_PROTO(void RestoreEntries, (PropEntry *, int USES_REGS));
|
||||
STATIC_PROTO(void CleanCode, (PredEntry * USES_REGS));
|
||||
|
||||
static void
|
||||
LookupAtom(Atom at)
|
||||
{
|
||||
char *p = RepAtom(at)->StrOfAE;
|
||||
CELL hash = HashFunction((unsigned char *)p) % LOCAL_ExportAtomHashTableSize;
|
||||
export_atom_hash_entry_t *a;
|
||||
|
||||
a = LOCAL_ExportAtomHashChain[hash];
|
||||
while (a) {
|
||||
if (a->val == at) {
|
||||
return;
|
||||
}
|
||||
a = a->next;
|
||||
}
|
||||
a = (export_atom_hash_entry_t *)malloc(sizeof(export_atom_hash_entry_t));
|
||||
if (!a) {
|
||||
return;
|
||||
}
|
||||
a->val = at;
|
||||
a->next = LOCAL_ExportAtomHashChain[hash];
|
||||
LOCAL_ExportAtomHashChain[hash] = a;
|
||||
LOCAL_ExportAtomHashTableNum++;
|
||||
}
|
||||
|
||||
static void
|
||||
LookupFunctor(Functor fun)
|
||||
{
|
||||
CELL hash = (CELL)(fun) % LOCAL_ExportFunctorHashTableSize;
|
||||
export_functor_hash_entry_t *f;
|
||||
Atom name = NameOfFunctor(fun);
|
||||
UInt arity = ArityOfFunctor(fun);
|
||||
|
||||
f = LOCAL_ExportFunctorHashChain[hash];
|
||||
while (f) {
|
||||
if (f->name == name && f->arity == arity) {
|
||||
return;
|
||||
}
|
||||
f = f->next;
|
||||
}
|
||||
f = (export_functor_hash_entry_t *)malloc(sizeof(export_functor_hash_entry_t));
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
LookupAtom(name);
|
||||
f->val = fun;
|
||||
f->name = name;
|
||||
f->arity = arity;
|
||||
f->next = LOCAL_ExportFunctorHashChain[hash];
|
||||
LOCAL_ExportFunctorHashChain[hash] = f;
|
||||
LOCAL_ExportFunctorHashTableNum++;
|
||||
}
|
||||
|
||||
static void
|
||||
LookupPredEntry(PredEntry *pe)
|
||||
{
|
||||
CELL hash = (CELL)(pe) % LOCAL_ExportPredEntryHashTableSize;
|
||||
export_pred_entry_hash_entry_t *p;
|
||||
UInt arity = pe->ArityOfPE;
|
||||
|
||||
p = LOCAL_ExportPredEntryHashChain[hash];
|
||||
while (p) {
|
||||
if (p->val == pe) {
|
||||
return;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
p = (export_pred_entry_hash_entry_t *)malloc(sizeof(export_pred_entry_hash_entry_t));
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
p->arity = arity;
|
||||
p->val = pe;
|
||||
if (pe->ModuleOfPred != IDB_MODULE) {
|
||||
if (arity) {
|
||||
p->u.f = pe->FunctorOfPred;
|
||||
LookupFunctor(pe->FunctorOfPred);
|
||||
} else {
|
||||
p->u.a = (Atom)(pe->FunctorOfPred);
|
||||
LookupAtom((Atom)(pe->FunctorOfPred));
|
||||
}
|
||||
} else {
|
||||
if (pe->PredFlags & AtomDBPredFlag) {
|
||||
p->u.a = (Atom)(pe->FunctorOfPred);
|
||||
p->arity = (CELL)(-2);
|
||||
LookupAtom((Atom)(pe->FunctorOfPred));
|
||||
} else if (!(pe->PredFlags & NumberDBPredFlag)) {
|
||||
p->u.f = pe->FunctorOfPred;
|
||||
p->arity = (CELL)(-1);
|
||||
LookupFunctor(pe->FunctorOfPred);
|
||||
} else {
|
||||
p->u.f = pe->FunctorOfPred;
|
||||
}
|
||||
}
|
||||
if (pe->ModuleOfPred) {
|
||||
p->module = AtomOfTerm(pe->ModuleOfPred);
|
||||
} else {
|
||||
p->module = AtomProlog;
|
||||
}
|
||||
LookupAtom(p->module);
|
||||
p->next = LOCAL_ExportPredEntryHashChain[hash];
|
||||
LOCAL_ExportPredEntryHashChain[hash] = p;
|
||||
LOCAL_ExportPredEntryHashTableNum++;
|
||||
}
|
||||
|
||||
static void
|
||||
LookupDBRef(DBRef ref)
|
||||
{
|
||||
CELL hash = Unsigned(ref) % LOCAL_ExportDBRefHashTableSize;
|
||||
export_dbref_hash_entry_t *a;
|
||||
|
||||
a = LOCAL_ExportDBRefHashChain[hash];
|
||||
while (a) {
|
||||
if (a->val == ref) {
|
||||
a->refs++;
|
||||
return;
|
||||
}
|
||||
a = a->next;
|
||||
}
|
||||
a = (export_dbref_hash_entry_t *)malloc(sizeof(export_dbref_hash_entry_t));
|
||||
if (!a) {
|
||||
return;
|
||||
}
|
||||
a->val = ref;
|
||||
a->sz = ((LogUpdClause *)ref)->ClSize;
|
||||
a->refs = 1;
|
||||
a->next = LOCAL_ExportDBRefHashChain[hash];
|
||||
LOCAL_ExportDBRefHashChain[hash] = a;
|
||||
LOCAL_ExportDBRefHashTableNum++;
|
||||
}
|
||||
|
||||
static void
|
||||
InitHash(void)
|
||||
{
|
||||
LOCAL_ExportFunctorHashTableNum = 0;
|
||||
LOCAL_ExportFunctorHashTableSize = EXPORT_FUNCTOR_TABLE_SIZE;
|
||||
LOCAL_ExportFunctorHashChain = (export_functor_hash_entry_t **)calloc(1, sizeof(export_functor_hash_entry_t *)* LOCAL_ExportFunctorHashTableSize);
|
||||
LOCAL_ExportAtomHashTableNum = 0;
|
||||
LOCAL_ExportAtomHashTableSize = EXPORT_ATOM_TABLE_SIZE;
|
||||
LOCAL_ExportAtomHashChain = (export_atom_hash_entry_t **)calloc(1, sizeof(export_atom_hash_entry_t *)* LOCAL_ExportAtomHashTableSize);
|
||||
LOCAL_ExportPredEntryHashTableNum = 0;
|
||||
LOCAL_ExportPredEntryHashTableSize = EXPORT_PRED_ENTRY_TABLE_SIZE;
|
||||
LOCAL_ExportPredEntryHashChain = (export_pred_entry_hash_entry_t **)calloc(1, sizeof(export_pred_entry_hash_entry_t *)* LOCAL_ExportPredEntryHashTableSize);
|
||||
LOCAL_ExportDBRefHashTableNum = 0;
|
||||
LOCAL_ExportDBRefHashTableSize = EXPORT_DBREF_TABLE_SIZE;
|
||||
LOCAL_ExportDBRefHashChain = (export_dbref_hash_entry_t **)calloc(1, sizeof(export_dbref_hash_entry_t *)* LOCAL_ExportDBRefHashTableSize);
|
||||
}
|
||||
|
||||
static void
|
||||
CloseHash(void)
|
||||
{
|
||||
LOCAL_ExportFunctorHashTableNum = 0;
|
||||
LOCAL_ExportFunctorHashTableSize = 0L;
|
||||
free(LOCAL_ExportFunctorHashChain);
|
||||
LOCAL_ExportAtomHashTableNum = 0;
|
||||
LOCAL_ExportAtomHashTableSize = 0L;
|
||||
free(LOCAL_ExportAtomHashChain);
|
||||
LOCAL_ExportPredEntryHashTableNum = 0;
|
||||
LOCAL_ExportPredEntryHashTableSize = 0L;
|
||||
free(LOCAL_ExportPredEntryHashChain);
|
||||
LOCAL_ExportDBRefHashTableNum = 0;
|
||||
LOCAL_ExportDBRefHashTableSize = 0L;
|
||||
free(LOCAL_ExportDBRefHashChain);
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
AtomAdjust(Atom a)
|
||||
{
|
||||
LookupAtom(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline Functor
|
||||
FuncAdjust(Functor f)
|
||||
{
|
||||
LookupFunctor(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
static inline Term
|
||||
AtomTermAdjust(Term t)
|
||||
{
|
||||
LookupAtom(AtomOfTerm(t));
|
||||
return t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
TermToGlobalOrAtomAdjust(Term t)
|
||||
{
|
||||
if (t && IsAtomTerm(t))
|
||||
return AtomTermAdjust(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
#define IsOldCode(P) FALSE
|
||||
#define IsOldCodeCellPtr(P) FALSE
|
||||
#define IsOldDelay(P) FALSE
|
||||
#define IsOldDelayPtr(P) FALSE
|
||||
#define IsOldLocalInTR(P) FALSE
|
||||
#define IsOldLocalInTRPtr(P) FALSE
|
||||
#define IsOldGlobal(P) FALSE
|
||||
#define IsOldGlobalPtr(P) FALSE
|
||||
#define IsOldTrail(P) FALSE
|
||||
#define IsOldTrailPtr(P) FALSE
|
||||
|
||||
#define CharP(X) ((char *)(X))
|
||||
|
||||
#define REINIT_LOCK(P)
|
||||
#define REINIT_RWLOCK(P)
|
||||
#define BlobTypeAdjust(P) (P)
|
||||
#define NoAGCAtomAdjust(P) (P)
|
||||
#define OrArgAdjust(P)
|
||||
#define TabEntryAdjust(P)
|
||||
#define IntegerAdjust(D) (D)
|
||||
#define AddrAdjust(P) (P)
|
||||
#define MFileAdjust(P) (P)
|
||||
#define CodeVarAdjust(P) (P)
|
||||
#define ConstantAdjust(P) (P)
|
||||
#define ArityAdjust(P) (P)
|
||||
#define DoubleInCodeAdjust(P)
|
||||
#define IntegerInCodeAdjust(P)
|
||||
#define OpcodeAdjust(P) (P)
|
||||
|
||||
static inline Term
|
||||
ModuleAdjust(Term t)
|
||||
{
|
||||
if (!t) return t;
|
||||
return AtomTermAdjust(t);
|
||||
}
|
||||
|
||||
static inline PredEntry *
|
||||
PredEntryAdjust(PredEntry *pe)
|
||||
{
|
||||
LookupPredEntry(pe);
|
||||
return pe;
|
||||
}
|
||||
|
||||
static inline PredEntry *
|
||||
PtoPredAdjust(PredEntry *pe)
|
||||
{
|
||||
LookupPredEntry(pe);
|
||||
return pe;
|
||||
}
|
||||
|
||||
|
||||
#define ExternalFunctionAdjust(P) (P)
|
||||
#define DBRecordAdjust(P) (P)
|
||||
#define ModEntryPtrAdjust(P) (P)
|
||||
#define AtomEntryAdjust(P) (P)
|
||||
#define GlobalEntryAdjust(P) (P)
|
||||
#define BlobTermInCodeAdjust(P) (P)
|
||||
#define CellPtoHeapAdjust(P) (P)
|
||||
#define PtoAtomHashEntryAdjust(P) (P)
|
||||
#define CellPtoHeapCellAdjust(P) (P)
|
||||
#define CellPtoTRAdjust(P) (P)
|
||||
#define CodeAddrAdjust(P) (P)
|
||||
#define ConsultObjAdjust(P) (P)
|
||||
#define DelayAddrAdjust(P) (P)
|
||||
#define DelayAdjust(P) (P)
|
||||
#define GlobalAdjust(P) (P)
|
||||
|
||||
#define DBRefAdjust(P) DBRefAdjust__(P PASS_REGS)
|
||||
static inline DBRef
|
||||
DBRefAdjust__ (DBRef dbt USES_REGS)
|
||||
{
|
||||
LookupDBRef(dbt);
|
||||
return dbt;
|
||||
}
|
||||
|
||||
#define DBRefPAdjust(P) (P)
|
||||
#define DBTermAdjust(P) (P)
|
||||
#define LUIndexAdjust(P) (P)
|
||||
#define SIndexAdjust(P) (P)
|
||||
#define LocalAddrAdjust(P) (P)
|
||||
#define GlobalAddrAdjust(P) (P)
|
||||
#define OpListAdjust(P) (P)
|
||||
#define PtoLUCAdjust(P) (P)
|
||||
#define PtoStCAdjust(P) (P)
|
||||
#define PtoArrayEAdjust(P) (P)
|
||||
#define PtoArraySAdjust(P) (P)
|
||||
#define PtoGlobalEAdjust(P) (P)
|
||||
#define PtoDelayAdjust(P) (P)
|
||||
#define PtoGloAdjust(P) (P)
|
||||
#define PtoLocAdjust(P) (P)
|
||||
#define PtoHeapCellAdjust(P) (P)
|
||||
#define TermToGlobalAdjust(P) (P)
|
||||
#define PtoOpAdjust(P) (P)
|
||||
#define PtoLUClauseAdjust(P) (P)
|
||||
#define PtoLUIndexAdjust(P) (P)
|
||||
#define PtoDBTLAdjust(P) (P)
|
||||
#define PtoPtoPredAdjust(P) (P)
|
||||
#define OpRTableAdjust(P) (P)
|
||||
#define OpEntryAdjust(P) (P)
|
||||
#define PropAdjust(P) (P)
|
||||
#define TrailAddrAdjust(P) (P)
|
||||
#define XAdjust(P) (P)
|
||||
#define YAdjust(P) (P)
|
||||
#define HoldEntryAdjust(P) (P)
|
||||
#define CodeCharPAdjust(P) (P)
|
||||
#define CodeVoidPAdjust(P) (P)
|
||||
#define HaltHookAdjust(P) (P)
|
||||
|
||||
#define recompute_mask(dbr)
|
||||
|
||||
#define rehash(oldcode, NOfE, KindOfEntries)
|
||||
|
||||
#define RestoreSWIHash()
|
||||
|
||||
#include "rheap.h"
|
||||
|
||||
static void
|
||||
RestoreHashPreds( USES_REGS1 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
RestoreAtomList(Atom atm USES_REGS)
|
||||
{
|
||||
}
|
||||
|
||||
static size_t save_bytes(IOSTREAM *stream, void *ptr, size_t sz)
|
||||
{
|
||||
return Sfwrite(ptr, sz, 1, stream);
|
||||
}
|
||||
|
||||
static size_t save_byte(IOSTREAM *stream, int byte)
|
||||
{
|
||||
Sputc(byte, stream);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t save_bits16(IOSTREAM *stream, BITS16 val)
|
||||
{
|
||||
BITS16 v = val;
|
||||
return save_bytes(stream, &v, sizeof(BITS16));
|
||||
}
|
||||
|
||||
static size_t save_uint(IOSTREAM *stream, UInt val)
|
||||
{
|
||||
UInt v = val;
|
||||
return save_bytes(stream, &v, sizeof(UInt));
|
||||
}
|
||||
|
||||
static size_t save_int(IOSTREAM *stream, int val)
|
||||
{
|
||||
UInt v = val;
|
||||
return save_bytes(stream, &v, sizeof(int));
|
||||
}
|
||||
|
||||
static size_t save_tag(IOSTREAM *stream, qlf_tag_t tag)
|
||||
{
|
||||
return save_byte(stream, tag);
|
||||
}
|
||||
|
||||
static int
|
||||
SaveHash(IOSTREAM *stream)
|
||||
{
|
||||
UInt i;
|
||||
/* first, current opcodes */
|
||||
CHECK(save_tag(stream, QLY_START_X));
|
||||
save_uint(stream, (UInt)&ARG1);
|
||||
CHECK(save_tag(stream, QLY_START_OPCODES));
|
||||
save_int(stream, _std_top);
|
||||
for (i= 0; i <= _std_top; i++) {
|
||||
save_uint(stream, (UInt)Yap_opcode(i));
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_START_ATOMS));
|
||||
CHECK(save_uint(stream, LOCAL_ExportAtomHashTableNum));
|
||||
for (i = 0; i < LOCAL_ExportAtomHashTableSize; i++) {
|
||||
export_atom_hash_entry_t *a = LOCAL_ExportAtomHashChain[i];
|
||||
while (a) {
|
||||
export_atom_hash_entry_t *a0 = a;
|
||||
Atom at = a->val;
|
||||
CHECK(save_uint(stream, (UInt)at));
|
||||
if (IsWideAtom(at)) {
|
||||
CHECK(save_tag(stream, QLY_ATOM_WIDE));
|
||||
CHECK(save_uint(stream, wcslen(RepAtom(at)->WStrOfAE)));
|
||||
CHECK(save_bytes(stream, at->WStrOfAE, (wcslen(at->WStrOfAE)+1)*sizeof(wchar_t)));
|
||||
} else {
|
||||
CHECK(save_tag(stream, QLY_ATOM));
|
||||
CHECK(save_uint(stream, strlen(RepAtom(at)->StrOfAE)));
|
||||
CHECK(save_bytes(stream, at->StrOfAE, (strlen(at->StrOfAE)+1)*sizeof(char)));
|
||||
}
|
||||
a = a->next;
|
||||
free(a0);
|
||||
}
|
||||
}
|
||||
save_tag(stream, QLY_START_FUNCTORS);
|
||||
save_uint(stream, LOCAL_ExportFunctorHashTableNum);
|
||||
for (i = 0; i < LOCAL_ExportFunctorHashTableSize; i++) {
|
||||
export_functor_hash_entry_t *f = LOCAL_ExportFunctorHashChain[i];
|
||||
while (f) {
|
||||
export_functor_hash_entry_t *f0 = f;
|
||||
CHECK(save_uint(stream, (UInt)(f->val)));
|
||||
CHECK(save_uint(stream, f->arity));
|
||||
CHECK(save_uint(stream, (CELL)(f->name)));
|
||||
f = f->next;
|
||||
free(f0);
|
||||
}
|
||||
}
|
||||
save_tag(stream, QLY_START_PRED_ENTRIES);
|
||||
save_uint(stream, LOCAL_ExportPredEntryHashTableNum);
|
||||
for (i = 0; i < LOCAL_ExportPredEntryHashTableSize; i++) {
|
||||
export_pred_entry_hash_entry_t *p = LOCAL_ExportPredEntryHashChain[i];
|
||||
while (p) {
|
||||
export_pred_entry_hash_entry_t *p0 = p;
|
||||
CHECK(save_uint(stream, (UInt)(p->val)));
|
||||
CHECK(save_uint(stream, p->arity));
|
||||
CHECK(save_uint(stream, (UInt)p->module));
|
||||
CHECK(save_uint(stream, (UInt)p->u.f));
|
||||
p = p->next;
|
||||
free(p0);
|
||||
}
|
||||
}
|
||||
save_tag(stream, QLY_START_DBREFS);
|
||||
save_uint(stream, LOCAL_ExportDBRefHashTableNum);
|
||||
for (i = 0; i < LOCAL_ExportDBRefHashTableSize; i++) {
|
||||
export_dbref_hash_entry_t *p = LOCAL_ExportDBRefHashChain[i];
|
||||
while (p) {
|
||||
export_dbref_hash_entry_t *p0 = p;
|
||||
CHECK(save_uint(stream, (UInt)(p->val)));
|
||||
CHECK(save_uint(stream, p->sz));
|
||||
CHECK(save_uint(stream, p->refs));
|
||||
p = p->next;
|
||||
free(p0);
|
||||
}
|
||||
}
|
||||
save_tag(stream, QLY_FAILCODE);
|
||||
save_uint(stream, (UInt)FAILCODE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_clauses(IOSTREAM *stream, PredEntry *pp) {
|
||||
yamop *FirstC, *LastC;
|
||||
|
||||
FirstC = pp->cs.p_code.FirstClause;
|
||||
LastC = pp->cs.p_code.LastClause;
|
||||
if (FirstC == NULL && LastC == NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (pp->PredFlags & LogUpdatePredFlag) {
|
||||
LogUpdClause *cl = ClauseCodeToLogUpdClause(FirstC);
|
||||
|
||||
while (cl != NULL) {
|
||||
if (pp->TimeStampOfPred >= cl->ClTimeStart &&
|
||||
pp->TimeStampOfPred <= cl->ClTimeEnd) {
|
||||
UInt size = cl->ClSize;
|
||||
CHECK(save_tag(stream, QLY_START_LU_CLAUSE));
|
||||
CHECK(save_uint(stream, (UInt)cl));
|
||||
CHECK(save_uint(stream, size));
|
||||
CHECK(save_bytes(stream, cl, size));
|
||||
}
|
||||
cl = cl->ClNext;
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_END_LU_CLAUSES));
|
||||
} else if (pp->PredFlags & MegaClausePredFlag) {
|
||||
MegaClause *cl = ClauseCodeToMegaClause(FirstC);
|
||||
UInt size = cl->ClSize;
|
||||
|
||||
CHECK(save_uint(stream, (UInt)cl));
|
||||
CHECK(save_uint(stream, size));
|
||||
CHECK(save_bytes(stream, cl, size));
|
||||
} else if (pp->PredFlags & DynamicPredFlag) {
|
||||
yamop *cl = FirstC;
|
||||
|
||||
do {
|
||||
DynamicClause *dcl = ClauseCodeToDynamicClause(cl);
|
||||
UInt size = dcl->ClSize;
|
||||
|
||||
CHECK(save_uint(stream, (UInt)cl));
|
||||
CHECK(save_uint(stream, size));
|
||||
CHECK(save_bytes(stream, dcl, size));
|
||||
if (cl == LastC) return 1;
|
||||
cl = NextDynamicClause(cl);
|
||||
} while (TRUE);
|
||||
} else {
|
||||
StaticClause *cl = ClauseCodeToStaticClause(FirstC);
|
||||
|
||||
if (pp->PredFlags & SYSTEM_PRED_FLAGS) {
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
UInt size = cl->ClSize;
|
||||
|
||||
CHECK(save_uint(stream, (UInt)cl));
|
||||
CHECK(save_uint(stream, size));
|
||||
CHECK(save_bytes(stream, cl, size));
|
||||
if (cl->ClCode == LastC) return 1;
|
||||
cl = cl->ClNext;
|
||||
} while (TRUE);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_pred(IOSTREAM *stream, PredEntry *ap) {
|
||||
CHECK(save_uint(stream, (UInt)ap));
|
||||
CHECK(save_uint(stream, ap->PredFlags));
|
||||
CHECK(save_uint(stream, ap->cs.p_code.NOfClauses));
|
||||
CHECK(save_uint(stream, ap->src.IndxId));
|
||||
return save_clauses(stream, ap);
|
||||
}
|
||||
|
||||
static int
|
||||
clean_pred(PredEntry *pp USES_REGS) {
|
||||
if (pp->PredFlags & (AsmPredFlag|CPredFlag)) {
|
||||
/* assembly */
|
||||
if (pp->CodeOfPred) {
|
||||
CleanClauses(pp->CodeOfPred, pp->CodeOfPred, pp PASS_REGS);
|
||||
}
|
||||
} else {
|
||||
CleanClauses(pp->cs.p_code.FirstClause, pp->cs.p_code.LastClause, pp PASS_REGS);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static size_t
|
||||
mark_pred(PredEntry *ap)
|
||||
{
|
||||
if (ap->ModuleOfPred != IDB_MODULE) {
|
||||
if (ap->ArityOfPE) {
|
||||
FuncAdjust(ap->FunctorOfPred);
|
||||
} else {
|
||||
AtomAdjust((Atom)(ap->FunctorOfPred));
|
||||
}
|
||||
} else {
|
||||
if (ap->PredFlags & AtomDBPredFlag) {
|
||||
AtomAdjust((Atom)(ap->FunctorOfPred));
|
||||
} else if (!(ap->PredFlags & NumberDBPredFlag)) {
|
||||
FuncAdjust(ap->FunctorOfPred);
|
||||
}
|
||||
}
|
||||
if (!(ap->PredFlags & (MultiFileFlag|NumberDBPredFlag)) &&
|
||||
ap->src.OwnerFile) {
|
||||
AtomAdjust(ap->src.OwnerFile);
|
||||
}
|
||||
CHECK(clean_pred(ap PASS_REGS));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t
|
||||
mark_ops(IOSTREAM *stream, Term mod) {
|
||||
OpEntry *op = OpList;
|
||||
while (op) {
|
||||
if (!mod || op->OpModule == mod) {
|
||||
AtomAdjust(op->OpName);
|
||||
if (op->OpModule)
|
||||
AtomTermAdjust(op->OpModule);
|
||||
}
|
||||
op = op->OpNext;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_ops(IOSTREAM *stream, Term mod) {
|
||||
OpEntry *op = OpList;
|
||||
while (op) {
|
||||
if (!mod || op->OpModule == mod) {
|
||||
CHECK(save_tag(stream, QLY_NEW_OP));
|
||||
save_uint(stream, (UInt)op->OpName);
|
||||
save_uint(stream, (UInt)op->OpModule);
|
||||
save_bits16(stream, op->Prefix);
|
||||
save_bits16(stream, op->Infix);
|
||||
save_bits16(stream, op->Posfix);
|
||||
}
|
||||
op = op->OpNext;
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_END_OPS));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_module(IOSTREAM *stream, Term mod) {
|
||||
CACHE_REGS
|
||||
PredEntry *ap = Yap_ModulePred(mod);
|
||||
InitHash();
|
||||
ModuleAdjust(mod);
|
||||
while (ap) {
|
||||
ap = PredEntryAdjust(ap);
|
||||
CHECK(mark_pred(ap));
|
||||
ap = ap->NextPredOfModule;
|
||||
}
|
||||
/* just to make sure */
|
||||
mark_ops(stream, mod);
|
||||
SaveHash(stream);
|
||||
CHECK(save_tag(stream, QLY_START_MODULE));
|
||||
CHECK(save_uint(stream, (UInt)mod));
|
||||
ap = Yap_ModulePred(mod);
|
||||
while (ap) {
|
||||
CHECK(save_tag(stream, QLY_START_PREDICATE));
|
||||
CHECK(save_pred(stream, ap));
|
||||
ap = ap->NextPredOfModule;
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_END_PREDICATES));
|
||||
CHECK(save_tag(stream, QLY_END_MODULES));
|
||||
save_ops(stream, mod);
|
||||
CloseHash();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
save_header(IOSTREAM *stream)
|
||||
{
|
||||
char msg[256];
|
||||
|
||||
sprintf(msg, "#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 \"$@\"\n%s", YAP_BINDIR, YAP_SVERSION);
|
||||
return save_bytes(stream, msg, strlen(msg)+1);
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_program(IOSTREAM *stream) {
|
||||
CACHE_REGS
|
||||
ModEntry *me = CurrentModules;
|
||||
|
||||
InitHash();
|
||||
save_header( stream );
|
||||
/* should we allow the user to see hidden predicates? */
|
||||
while (me) {
|
||||
PredEntry *pp;
|
||||
pp = me->PredForME;
|
||||
AtomAdjust(me->AtomOfME);
|
||||
while (pp != NULL) {
|
||||
pp = PredEntryAdjust(pp);
|
||||
CHECK(mark_pred(pp));
|
||||
pp = pp->NextPredOfModule;
|
||||
}
|
||||
me = me->NextME;
|
||||
}
|
||||
|
||||
/* just to make sure */
|
||||
mark_ops(stream, 0);
|
||||
SaveHash(stream);
|
||||
me = CurrentModules;
|
||||
while (me) {
|
||||
PredEntry *pp;
|
||||
pp = me->PredForME;
|
||||
CHECK(save_tag(stream, QLY_START_MODULE));
|
||||
CHECK(save_uint(stream, (UInt)MkAtomTerm(me->AtomOfME)));
|
||||
while (pp != NULL) {
|
||||
CHECK(save_tag(stream, QLY_START_PREDICATE));
|
||||
CHECK(save_pred(stream, pp));
|
||||
pp = pp->NextPredOfModule;
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_END_PREDICATES));
|
||||
me = me->NextME;
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_END_MODULES));
|
||||
save_ops(stream, 0);
|
||||
CloseHash();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_save_module_preds( USES_REGS1 )
|
||||
{
|
||||
IOSTREAM *stream;
|
||||
Term tmod = Deref(ARG2);
|
||||
|
||||
if (!Yap_getOutputStream(Yap_InitSlot(Deref(ARG1) PASS_REGS), &stream)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (IsVarTerm(tmod)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,tmod,"save_module/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsAtomTerm(tmod)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM,tmod,"save_module/2");
|
||||
return FALSE;
|
||||
}
|
||||
return save_module(stream, tmod) != 0;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_save_program( USES_REGS1 )
|
||||
{
|
||||
IOSTREAM *stream;
|
||||
|
||||
if (!Yap_getOutputStream(Yap_InitSlot(Deref(ARG1) PASS_REGS), &stream)) {
|
||||
return FALSE;
|
||||
}
|
||||
return save_program(stream) != 0;
|
||||
}
|
||||
|
||||
void Yap_InitQLY(void)
|
||||
{
|
||||
Yap_InitCPred("$qsave_module_preds", 2, p_save_module_preds, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred("$qsave_program", 1, p_save_program, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
if (FALSE) {
|
||||
restore_codes();
|
||||
}
|
||||
}
|
||||
|
45
C/save.c
Executable file → Normal file
45
C/save.c
Executable file → Normal file
@@ -18,6 +18,7 @@
|
||||
static char SccsId[] = "@(#)save.c 1.3 3/15/90";
|
||||
#endif
|
||||
|
||||
#include "SWI-Stream.h"
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
@@ -122,7 +123,7 @@ STATIC_PROTO(void restore_heap, (void));
|
||||
STATIC_PROTO(void ShowAtoms, (void));
|
||||
STATIC_PROTO(void ShowEntries, (PropEntry *));
|
||||
#endif
|
||||
STATIC_PROTO(int OpenRestore, (char *, char *, CELL *, CELL *, CELL *, CELL *));
|
||||
STATIC_PROTO(int OpenRestore, (char *, char *, CELL *, CELL *, CELL *, CELL *, IOSTREAM **));
|
||||
STATIC_PROTO(void CloseRestore, (void));
|
||||
#ifndef _WIN32
|
||||
STATIC_PROTO(int check_opcodes, (OPCODE []));
|
||||
@@ -1414,10 +1415,15 @@ cat_file_name(char *s, char *prefix, char *name, unsigned int max_length)
|
||||
strncat(s, name, max_length-1);
|
||||
}
|
||||
|
||||
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, char *buf) {
|
||||
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, char *buf, IOSTREAM **streamp) {
|
||||
int mode;
|
||||
|
||||
|
||||
if (streamp) {
|
||||
if ((*streamp = Sopen_file(inpf, "rb"))) {
|
||||
return DO_ONLY_CODE;
|
||||
}
|
||||
return FAIL_RESTORE;
|
||||
}
|
||||
if ((splfild = open_file(inpf, O_RDONLY)) < 0) {
|
||||
return FAIL_RESTORE;
|
||||
}
|
||||
@@ -1432,11 +1438,13 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *
|
||||
}
|
||||
|
||||
static int
|
||||
OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
||||
OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, IOSTREAM **streamp)
|
||||
{
|
||||
CACHE_REGS
|
||||
int mode = FAIL_RESTORE;
|
||||
char save_buffer[YAP_FILENAME_MAX+1];
|
||||
|
||||
save_buffer[0] = '\0';
|
||||
// LOCAL_ErrorMessage = NULL;
|
||||
if (inpf == NULL) {
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
@@ -1462,7 +1470,7 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
strncat(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||
}
|
||||
if (inpf != NULL && (splfild = open_file(inpf, O_RDONLY)) > 0) {
|
||||
if ((mode = try_open(inpf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||
if ((mode = try_open(inpf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -1473,11 +1481,11 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
*/
|
||||
if (YapLibDir != NULL) {
|
||||
cat_file_name(LOCAL_FileNameBuf, Yap_LibDir, inpf, YAP_FILENAME_MAX);
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
} else {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -1486,7 +1494,7 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
char *yap_env = getenv("YAPLIBDIR");
|
||||
if (yap_env != NULL) {
|
||||
cat_file_name(LOCAL_FileNameBuf, yap_env, inpf, YAP_FILENAME_MAX);
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -1495,7 +1503,7 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
if (YAP_LIBDIR != NULL) {
|
||||
cat_file_name(LOCAL_FileNameBuf, YAP_LIBDIR, inpf, YAP_FILENAME_MAX);
|
||||
if ((splfild = open_file(LOCAL_FileNameBuf, O_RDONLY)) > 0) {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -1535,7 +1543,7 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
pt[1] = '\0';
|
||||
strncat(LOCAL_FileNameBuf,"lib/Yap/startup.yss",YAP_FILENAME_MAX);
|
||||
}
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer)) != FAIL_RESTORE) {
|
||||
if ((mode = try_open(LOCAL_FileNameBuf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -1555,6 +1563,15 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
return FAIL_RESTORE;
|
||||
}
|
||||
|
||||
IOSTREAM *
|
||||
Yap_OpenRestore(char *inpf, char *YapLibDir)
|
||||
{
|
||||
IOSTREAM *stream = NULL;
|
||||
|
||||
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
static void
|
||||
CloseRestore(void)
|
||||
{
|
||||
@@ -1634,10 +1651,12 @@ RestoreHeap(OPCODE old_ops[] USES_REGS)
|
||||
int
|
||||
Yap_SavedInfo(char *FileName, char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
||||
{
|
||||
return DO_ONLY_CODE;
|
||||
|
||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||
int mode;
|
||||
|
||||
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap);
|
||||
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap, NULL);
|
||||
if (mode == FAIL_RESTORE) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1728,7 +1747,7 @@ Restore(char *s, char *lib_dir USES_REGS)
|
||||
OPCODE old_ops[_std_top+1];
|
||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||
|
||||
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, &MyHeap)) == FAIL_RESTORE)
|
||||
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, &MyHeap, NULL)) == FAIL_RESTORE)
|
||||
return(FALSE);
|
||||
Yap_ShutdownLoadForeign();
|
||||
in_limbo = TRUE;
|
||||
@@ -1782,7 +1801,7 @@ Restore(char *s, char *lib_dir USES_REGS)
|
||||
}
|
||||
|
||||
int
|
||||
Yap_Restore(char *s, char *lib_dir)
|
||||
Yap_SavedStateRestore(char *s, char *lib_dir)
|
||||
{
|
||||
CACHE_REGS
|
||||
return Restore(s, lib_dir PASS_REGS);
|
||||
|
29
C/scanner.c
Executable file → Normal file
29
C/scanner.c
Executable file → Normal file
@@ -1260,13 +1260,32 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp)
|
||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF);
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
} else {
|
||||
Atom ae;
|
||||
TokImage = ((AtomEntry *) ( Yap_PreAllocCodeSpace()))->StrOfAE;
|
||||
charp = TokImage;
|
||||
*charp++ = och;
|
||||
for (; chtype(ch) == SY; ch = getchr(inp_stream))
|
||||
*charp++ = ch;
|
||||
*charp = '\0';
|
||||
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
|
||||
wcharp = NULL;
|
||||
add_ch_to_buff(och);
|
||||
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
||||
if (charp == (char *)AuxSp-1024) {
|
||||
goto huge_var_error;
|
||||
}
|
||||
add_ch_to_buff(ch);
|
||||
}
|
||||
add_ch_to_buff('\0');
|
||||
if (wcharp) {
|
||||
ae = Yap_LookupWideAtom((wchar_t *)TokImage);
|
||||
} else {
|
||||
ae = Yap_LookupAtom(TokImage);
|
||||
}
|
||||
if (ae == NIL) {
|
||||
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
|
||||
LOCAL_ErrorMessage = "Code Space Overflow";
|
||||
if (p)
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
t->TokInfo = Unsigned(ae);
|
||||
if (t->TokInfo == (CELL)NIL) {
|
||||
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
|
||||
LOCAL_ErrorMessage = "Code Space Overflow";
|
||||
|
2
C/stdpreds.c
Executable file → Normal file
2
C/stdpreds.c
Executable file → Normal file
@@ -4481,6 +4481,8 @@ Yap_InitCPreds(void)
|
||||
Yap_InitSavePreds();
|
||||
Yap_InitSysPreds();
|
||||
Yap_InitUnify();
|
||||
Yap_InitQLY();
|
||||
Yap_InitQLYR();
|
||||
#if defined CUT_C && defined MYDDAS_MYSQL
|
||||
Yap_InitMYDDAS_MySQLPreds();
|
||||
#endif
|
||||
|
0
C/sysbits.c
Executable file → Normal file
0
C/sysbits.c
Executable file → Normal file
0
C/threads.c
Executable file → Normal file
0
C/threads.c
Executable file → Normal file
8
C/tracer.c
Executable file → Normal file
8
C/tracer.c
Executable file → Normal file
@@ -23,6 +23,7 @@
|
||||
#include "YapHeap.h"
|
||||
#include "attvar.h"
|
||||
#include "yapio.h"
|
||||
#include "clause.h"
|
||||
#include "tracer.h"
|
||||
|
||||
STATIC_PROTO(int TracePutchar, (int, int));
|
||||
@@ -167,6 +168,13 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
LOCAL_ThreadHandle.thread_inst_count++;
|
||||
#endif
|
||||
#ifdef COMMENTED
|
||||
{
|
||||
choiceptr b_p = B;
|
||||
while (b_p) {
|
||||
fprintf(stderr,"%p %ld\n",b_p,Yap_op_from_opcode(b_p->cp_ap->opc));
|
||||
b_p = b_p->cp_b;
|
||||
}
|
||||
}
|
||||
{ choiceptr myB = B;
|
||||
while (myB) myB = myB->cp_b;
|
||||
}
|
||||
|
@@ -686,9 +686,8 @@ p_softfunctor()
|
||||
WRITE_LOCK(RepAtom(a)->ARWLock);
|
||||
if ((p0 = Yap_GetAProp(a, SFProperty)) == NIL) {
|
||||
pe = (SFEntry *) Yap_AllocAtomSpace(sizeof(*pe));
|
||||
pe->NextOfPE = RepAtom(a)->PropsOfAE;
|
||||
pe->KindOfPE = SFProperty;
|
||||
RepAtom(a)->PropsOfAE = AbsSFProp(pe);
|
||||
AddPropToAtom(RepAtom(a), (PropEntry *)pe);
|
||||
} else
|
||||
pe = RepSFProp(p0);
|
||||
WRITE_UNLOCK(RepAtom(a)->ARWLock);
|
||||
|
Reference in New Issue
Block a user