fix formt to include all predicates and add right arity to DB entries.

This commit is contained in:
Vitor Santos Costa 2011-09-07 08:03:46 +02:00
parent db0a7771ba
commit c47a7be2e8
2 changed files with 19 additions and 48 deletions

View File

@ -736,12 +736,18 @@ ReadHash(IOSTREAM *stream)
PredEntry *ope = (PredEntry *)read_uint(stream), *pe; PredEntry *ope = (PredEntry *)read_uint(stream), *pe;
UInt arity = read_uint(stream); UInt arity = read_uint(stream);
Atom omod = (Atom)read_uint(stream); Atom omod = (Atom)read_uint(stream);
Term mod = MkAtomTerm(AtomAdjust(omod)); Term mod;
if (omod) {
mod = MkAtomTerm(AtomAdjust(omod));
if (mod == TermProlog) mod = 0;
}
if (mod != IDB_MODULE) { if (mod != IDB_MODULE) {
if (arity) { if (arity) {
Functor of = (Functor)read_uint(stream); Functor of = (Functor)read_uint(stream);
Functor f = LookupFunctor(of); Functor f = LookupFunctor(of);
while(!(pe = RepPredProp(PredPropByFunc(f,mod)))) { while(!(pe = RepPredProp(PredPropByFuncAndMod(f,mod)))) {
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_growheap(FALSE, 0, NULL)) {
exit(1); exit(1);
} }
@ -749,7 +755,7 @@ ReadHash(IOSTREAM *stream)
} else { } else {
Atom oa = (Atom)read_uint(stream); Atom oa = (Atom)read_uint(stream);
Atom a = LookupAtom(oa); Atom a = LookupAtom(oa);
pe = RepPredProp(PredPropByAtom(a,mod)); pe = RepPredProp(PredPropByAtomAndMod(a,mod));
} }
} else { } else {
if (arity == (UInt)-1) { if (arity == (UInt)-1) {
@ -758,12 +764,13 @@ ReadHash(IOSTREAM *stream)
} else if (arity == (UInt)(-2)) { } else if (arity == (UInt)(-2)) {
Atom oa = (Atom)read_uint(stream); Atom oa = (Atom)read_uint(stream);
Atom a = LookupAtom(oa); Atom a = LookupAtom(oa);
pe = RepPredProp(PredPropByAtom(a,mod)); pe = RepPredProp(PredPropByAtomAndMod(a,mod));
} else { } else {
Functor of = (Functor)read_uint(stream); Functor of = (Functor)read_uint(stream);
Functor f = LookupFunctor(of); Functor f = LookupFunctor(of);
pe = RepPredProp(PredPropByFunc(f,mod)); pe = RepPredProp(PredPropByFuncAndMod(f,mod));
} }
pe->ArityOfPE = 3;
} }
InsertPredEntry(ope, pe); InsertPredEntry(ope, pe);
} }
@ -878,48 +885,12 @@ read_clauses(IOSTREAM *stream, PredEntry *pp, UInt nclauses, UInt flags) {
static void static void
read_pred(IOSTREAM *stream, Term mod) { read_pred(IOSTREAM *stream, Term mod) {
UInt flags = read_uint(stream); UInt flags;
UInt arity = read_uint(stream);
UInt nclauses, fl1; UInt nclauses, fl1;
PredEntry *ap; PredEntry *ap;
if (mod == IDB_MODULE) { ap = LookupPredEntry((PredEntry *)read_uint(stream));
if (flags & AtomDBPredFlag) { flags = read_uint(stream);
Atom a = LookupAtom((Atom)read_uint(stream));
if ((ap = RepPredProp(PredPropByAtomAndMod(a,mod))) == NULL) {
ERROR(OUT_OF_CODE_SPACE);
}
} else if (flags & NumberDBPredFlag) {
Int i = (Int)read_uint(stream);
if ((ap = Yap_FindLUIntKey(i)) == NULL) {
ERROR(OUT_OF_CODE_SPACE);
}
} else {
Functor f = LookupFunctor((Functor)read_uint(stream));
if ((ap = RepPredProp(PredPropByFuncAndMod(f,mod))) == NULL) {
ERROR(OUT_OF_CODE_SPACE);
}
}
} else {
if (mod == TermProlog)
mod = PROLOG_MODULE;
if (arity) {
Functor f;
f = LookupFunctor((Functor)read_uint(stream));
if ((ap = RepPredProp(PredPropByFuncAndMod(f,mod))) == NULL) {
ERROR(OUT_OF_CODE_SPACE);
}
} else {
Atom a;
a = LookupAtom((Atom)read_uint(stream));
if ((ap = RepPredProp(PredPropByAtomAndMod(a,mod))) == NULL) {
ERROR(OUT_OF_CODE_SPACE);
}
}
}
ap->ArityOfPE = arity;
nclauses = read_uint(stream); nclauses = read_uint(stream);
if (ap->PredFlags & IndexedPredFlag) { if (ap->PredFlags & IndexedPredFlag) {
Yap_RemoveIndexation(ap); Yap_RemoveIndexation(ap);

View File

@ -280,7 +280,6 @@ PtoPredAdjust(PredEntry *pe)
#define ExternalFunctionAdjust(P) (P) #define ExternalFunctionAdjust(P) (P)
#define DBRecordAdjust(P) (P) #define DBRecordAdjust(P) (P)
#define PredEntryAdjust(P) (P)
#define ModEntryPtrAdjust(P) (P) #define ModEntryPtrAdjust(P) (P)
#define AtomEntryAdjust(P) (P) #define AtomEntryAdjust(P) (P)
#define GlobalEntryAdjust(P) (P) #define GlobalEntryAdjust(P) (P)
@ -532,9 +531,8 @@ save_clauses(IOSTREAM *stream, PredEntry *pp) {
static size_t static size_t
save_pred(IOSTREAM *stream, PredEntry *ap) { save_pred(IOSTREAM *stream, PredEntry *ap) {
CHECK(save_uint(stream, (UInt)ap));
CHECK(save_uint(stream, ap->PredFlags)); CHECK(save_uint(stream, ap->PredFlags));
CHECK(save_uint(stream, ap->ArityOfPE));
CHECK(save_uint(stream, (UInt)(ap->FunctorOfPred)));
CHECK(save_uint(stream, ap->cs.p_code.NOfClauses)); CHECK(save_uint(stream, ap->cs.p_code.NOfClauses));
CHECK(save_uint(stream, ap->src.IndxId)); CHECK(save_uint(stream, ap->src.IndxId));
return save_clauses(stream, ap); return save_clauses(stream, ap);
@ -616,6 +614,7 @@ save_module(IOSTREAM *stream, Term mod) {
InitHash(); InitHash();
ModuleAdjust(mod); ModuleAdjust(mod);
while (ap) { while (ap) {
ap = PredEntryAdjust(ap);
CHECK(mark_pred(ap)); CHECK(mark_pred(ap));
ap = ap->NextPredOfModule; ap = ap->NextPredOfModule;
} }
@ -656,9 +655,10 @@ save_program(IOSTREAM *stream) {
/* should we allow the user to see hidden predicates? */ /* should we allow the user to see hidden predicates? */
while (me) { while (me) {
PredEntry *pp; PredEntry *pp;
AtomAdjust(me->AtomOfME);
pp = me->PredForME; pp = me->PredForME;
AtomAdjust(me->AtomOfME);
while (pp != NULL) { while (pp != NULL) {
pp = PredEntryAdjust(pp);
CHECK(mark_pred(pp)); CHECK(mark_pred(pp));
pp = pp->NextPredOfModule; pp = pp->NextPredOfModule;
} }