qly fixes
This commit is contained in:
parent
0f80358ca7
commit
26e3f2cea0
43
C/qlyr.c
43
C/qlyr.c
@ -127,7 +127,7 @@ LookupPredEntry(PredEntry *op)
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
ERROR(UNKNOWN_FUNCTOR);
|
||||
ERROR(UNKNOWN_PRED_ENTRY);
|
||||
return NIL;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ InsertPredEntry(PredEntry *op, PredEntry *pe)
|
||||
static OPCODE
|
||||
LookupOPCODE(OPCODE op)
|
||||
{
|
||||
CELL hash = (CELL)(op) % LOCAL_ImportFunctorHashTableSize;
|
||||
CELL hash = (CELL)(op) % LOCAL_ImportOPCODEHashTableSize;
|
||||
import_opcode_hash_entry_t *f;
|
||||
|
||||
f = LOCAL_ImportOPCODEHashChain[hash];
|
||||
@ -174,7 +174,7 @@ LookupOPCODE(OPCODE op)
|
||||
static int
|
||||
OpcodeID(OPCODE op)
|
||||
{
|
||||
CELL hash = (CELL)(op) % LOCAL_ImportFunctorHashTableSize;
|
||||
CELL hash = (CELL)(op) % LOCAL_ImportOPCODEHashTableSize;
|
||||
import_opcode_hash_entry_t *f;
|
||||
|
||||
f = LOCAL_ImportOPCODEHashChain[hash];
|
||||
@ -189,14 +189,13 @@ OpcodeID(OPCODE op)
|
||||
}
|
||||
|
||||
static void
|
||||
InsertOPCODE(OPCODE op, int i, OPCODE o)
|
||||
InsertOPCODE(OPCODE op0, int i, OPCODE op)
|
||||
{
|
||||
CELL hash = (CELL)(op) % LOCAL_ImportFunctorHashTableSize;
|
||||
CELL hash = (CELL)(op0) % LOCAL_ImportOPCODEHashTableSize;
|
||||
import_opcode_hash_entry_t *f;
|
||||
|
||||
f = LOCAL_ImportOPCODEHashChain[hash];
|
||||
while (f) {
|
||||
if (f->oval == op) {
|
||||
if (f->oval == op0) {
|
||||
return;
|
||||
}
|
||||
f = f->next;
|
||||
@ -205,8 +204,8 @@ InsertOPCODE(OPCODE op, int i, OPCODE o)
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
f->val = o;
|
||||
f->oval = op;
|
||||
f->val = op;
|
||||
f->oval = op0;
|
||||
f->id = i;
|
||||
f->next = LOCAL_ImportOPCODEHashChain[hash];
|
||||
LOCAL_ImportOPCODEHashChain[hash] = f;
|
||||
@ -337,6 +336,12 @@ PtoPredAdjust(PredEntry *p)
|
||||
return LookupPredEntry(p);
|
||||
}
|
||||
|
||||
static inline PredEntry *
|
||||
PredEntryAdjust(PredEntry *p)
|
||||
{
|
||||
return LookupPredEntry(p);
|
||||
}
|
||||
|
||||
static inline OPCODE
|
||||
OpcodeAdjust(OPCODE OP) {
|
||||
return LookupOPCODE(OP);
|
||||
@ -351,7 +356,6 @@ ModuleAdjust(Term M) {
|
||||
|
||||
#define ExternalFunctionAdjust(P) (P)
|
||||
#define DBRecordAdjust(P) (P)
|
||||
#define PredEntryAdjust(P) (P)
|
||||
#define ModEntryPtrAdjust(P) (P)
|
||||
#define AtomEntryAdjust(P) (P)
|
||||
#define GlobalEntryAdjust(P) (P)
|
||||
@ -628,6 +632,7 @@ read_pred(IOSTREAM *stream, Term mod) {
|
||||
}
|
||||
} else {
|
||||
Atom a = LookupAtom((Atom)read_uint(stream));
|
||||
|
||||
if ((ap = RepPredProp(PredPropByAtom(a,mod))) == NULL) {
|
||||
ERROR(OUT_OF_CODE_SPACE);
|
||||
}
|
||||
@ -640,12 +645,15 @@ read_pred(IOSTREAM *stream, Term mod) {
|
||||
}
|
||||
|
||||
static void
|
||||
save_module(IOSTREAM *stream, Term mod) {
|
||||
read_module(IOSTREAM *stream) {
|
||||
CACHE_REGS
|
||||
Term mod;
|
||||
|
||||
InitHash();
|
||||
ReadHash(stream);
|
||||
RCHECK(read_tag(stream) == QLY_START_MODULE);
|
||||
mod = (Term)read_uint(stream);
|
||||
mod = MkAtomTerm(AtomAdjust(AtomOfTerm(mod)));
|
||||
while (read_tag(stream) == QLY_START_PREDICATE) {
|
||||
read_pred(stream, mod);
|
||||
}
|
||||
@ -657,20 +665,11 @@ static Int
|
||||
p_read_module_preds( USES_REGS1 )
|
||||
{
|
||||
IOSTREAM *stream;
|
||||
Term tmod = Deref(ARG2);
|
||||
|
||||
if (!Yap_getInputStream(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;
|
||||
}
|
||||
save_module(stream, tmod);
|
||||
read_module(stream);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -679,7 +678,7 @@ p_read_module_preds( USES_REGS1 )
|
||||
void Yap_InitQLYR(void)
|
||||
{
|
||||
#if DEBUG
|
||||
Yap_InitCPred("$read_module_preds", 2, p_read_module_preds, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred("$read_module_preds", 1, p_read_module_preds, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
20
C/qlyw.c
20
C/qlyw.c
@ -89,7 +89,7 @@ LookupFunctor(Functor fun)
|
||||
static void
|
||||
LookupPredEntry(PredEntry *pe)
|
||||
{
|
||||
CELL hash = (CELL)(pe) % LOCAL_ExportFunctorHashTableSize;
|
||||
CELL hash = (CELL)(pe) % LOCAL_ExportPredEntryHashTableSize;
|
||||
export_pred_entry_hash_entry_t *p;
|
||||
UInt arity = pe->ArityOfPE;
|
||||
|
||||
@ -105,6 +105,7 @@ LookupPredEntry(PredEntry *pe)
|
||||
return;
|
||||
}
|
||||
p->arity = arity;
|
||||
p->val = pe;
|
||||
if (arity) {
|
||||
p->u.f = pe->FunctorOfPred;
|
||||
LookupFunctor(pe->FunctorOfPred);
|
||||
@ -117,6 +118,7 @@ LookupPredEntry(PredEntry *pe)
|
||||
} else {
|
||||
p->module = AtomProlog;
|
||||
}
|
||||
LookupAtom(p->module);
|
||||
p->next = LOCAL_ExportPredEntryHashChain[hash];
|
||||
LOCAL_ExportPredEntryHashChain[hash] = p;
|
||||
LOCAL_ExportPredEntryHashTableNum++;
|
||||
@ -125,10 +127,13 @@ LookupPredEntry(PredEntry *pe)
|
||||
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);
|
||||
}
|
||||
@ -136,10 +141,13 @@ InitHash(void)
|
||||
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);
|
||||
}
|
||||
@ -218,6 +226,13 @@ PredEntryAdjust(PredEntry *pe)
|
||||
return pe;
|
||||
}
|
||||
|
||||
static inline PredEntry *
|
||||
PtoPredAdjust(PredEntry *pe)
|
||||
{
|
||||
LookupPredEntry(pe);
|
||||
return pe;
|
||||
}
|
||||
|
||||
|
||||
#define ExternalFunctionAdjust(P) (P)
|
||||
#define DBRecordAdjust(P) (P)
|
||||
@ -257,7 +272,6 @@ PredEntryAdjust(PredEntry *pe)
|
||||
#define PtoLUClauseAdjust(P) (P)
|
||||
#define PtoLUIndexAdjust(P) (P)
|
||||
#define PtoDBTLAdjust(P) (P)
|
||||
#define PtoPredAdjust(P) (P)
|
||||
#define PtoPtoPredAdjust(P) (P)
|
||||
#define OpRTableAdjust(P) (P)
|
||||
#define OpEntryAdjust(P) (P)
|
||||
@ -331,7 +345,6 @@ SaveHash(IOSTREAM *stream)
|
||||
}
|
||||
CHECK(save_tag(stream, QLY_START_ATOMS));
|
||||
CHECK(save_uint(stream, LOCAL_ExportAtomHashTableNum));
|
||||
fprintf(stderr,"num=%ld\n",LOCAL_ExportAtomHashTableNum);
|
||||
for (i = 0; i < LOCAL_ExportAtomHashTableSize; i++) {
|
||||
export_atom_hash_entry_t *a = LOCAL_ExportAtomHashChain[i];
|
||||
while (a) {
|
||||
@ -463,6 +476,7 @@ save_module(IOSTREAM *stream, Term mod) {
|
||||
CACHE_REGS
|
||||
PredEntry *ap = Yap_ModulePred(mod);
|
||||
InitHash();
|
||||
ModuleAdjust(mod);
|
||||
while (ap) {
|
||||
if (ap->ArityOfPE) {
|
||||
FuncAdjust(ap->FunctorOfPred);
|
||||
|
@ -25,6 +25,6 @@ save_module(Mod) :-
|
||||
read_module(Mod) :-
|
||||
atom_concat(Mod,'.qly',F),
|
||||
open(F, read, S, [type(binary)]),
|
||||
'$read_module_preds'(S, Mod),
|
||||
'$read_module_preds'(S),
|
||||
close(S).
|
||||
|
||||
|
Reference in New Issue
Block a user