diff --git a/C/init.c b/C/init.c index 95ab88b4c..2b7fb45b2 100755 --- a/C/init.c +++ b/C/init.c @@ -196,6 +196,52 @@ int Yap_IsOpType(char *type) { return (i <= 7); } +static OpEntry * +fetchOpForModule(AtomEntry *ae, Term tmod ) +{ + OpEntry *oinfo = NULL; + PropEntry **prev = &ae->PropsOfAE; + PropEntry *pp = ae->PropsOfAE; + + while (!EndOfPAEntr(pp)) { + OpEntry *info = RepOpProp(pp); + if (!info) + return NULL; + if (pp->KindOfPE == OpProperty) { + if (tmod == PROLOG_MODULE) { + if (info->OpModule != PROLOG_MODULE) { + info->Infix = info->Prefix = info->Posfix = 0; + info->OpModule = tmod; + if (oinfo == NULL) + oinfo = info; + else { + pp = RepProp(pp->NextOfPE); + *prev = pp; + //Yap_FreeCodeSpace( oinfo ); + continue; + } + } else{ + if (oinfo) { + // should never happen? + oinfo->Infix = info->Infix; + oinfo->Prefix = info->Prefix; + oinfo->Posfix = info->Posfix; + pp = RepProp(pp->NextOfPE); + *prev = pp; + // Yap_FreeCodeSpace( oinfo ); + continue; + } + return info; + } + } else if (info->OpModule == tmod) + return info; + } + prev = & pp->NextOfPE; + pp = RepProp(pp->NextOfPE); + } + return oinfo; +} + static int OpDec(int p, const char *type, Atom a, Term m) { int i; AtomEntry *ae = RepAtom(a); @@ -203,8 +249,6 @@ static int OpDec(int p, const char *type, Atom a, Term m) { if (m == TermProlog) m = PROLOG_MODULE; - else if (m == USER_MODULE) - m = PROLOG_MODULE; for (i = 1; i <= 7; ++i) if (strcmp(type, optypes[i]) == 0) break; @@ -220,7 +264,7 @@ static int OpDec(int p, const char *type, Atom a, Term m) { p |= DcrrpFlag; } WRITE_LOCK(ae->ARWLock); - info = Yap_GetOpPropForAModuleHavingALock(ae, m); + info = fetchOpForModule(ae, m); if (EndOfPAEntr(info)) { info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry)); info->KindOfPE = Ord(OpProperty); @@ -239,6 +283,7 @@ static int OpDec(int p, const char *type, Atom a, Term m) { WRITE_LOCK(info->OpRWLock); WRITE_UNLOCK(ae->ARWLock); } + if (i <= 3) { if (trueGlobalPrologFlag(ISO_FLAG) && info->Posfix != 0) /* there is a posfix operator */ { @@ -249,7 +294,6 @@ static int OpDec(int p, const char *type, Atom a, Term m) { } info->Infix = p; } else if (i <= 5) { - if (trueGlobalPrologFlag(ISO_FLAG) && info->Infix != 0) /* there is an infix operator */ { /* ISO dictates */ diff --git a/H/Yatom.h b/H/Yatom.h index 08d1dfb9b..5c7a3231c 100755 --- a/H/Yatom.h +++ b/H/Yatom.h @@ -266,16 +266,17 @@ INLINE_ONLY inline EXTERN int IsWideAtom(Atom at) { /* Module property */ typedef struct mod_entry { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - struct pred_entry *PredForME; /* index in module table */ - Atom AtomOfME; /* module's name */ - Atom OwnerFile; /* module's owner file */ + Prop NextOfPE; /** used to chain properties */ + PropFlags KindOfPE; /** kind of property */ + struct pred_entry *PredForME; /** list of predicates for that module */ + Atom AtomOfME; /** module's name */ + Atom OwnerFile; /** module's owner file */ #if defined(YAPOR) || defined(THREADS) - rwlock_t ModRWLock; /* a read-write lock to protect the entry */ + rwlock_t ModRWLock; /** a read-write lock to protect the entry */ #endif - unsigned int flags; /* Module local flags (from SWI compat) */ - struct mod_entry *NextME; /* next module */ + Term ParentForME; /** the module we wer created from */ + unsigned int flags; /** Module local flags (from SWI compat): includes ops, strings */ + struct mod_entry *NextME; /** next module */ } ModEntry; #if USE_OFFSETS_IN_PROPS @@ -391,12 +392,12 @@ INLINE_ONLY inline EXTERN PropFlags IsOpProperty(int flags) { typedef enum { INFIX_OP = 0, POSFIX_OP = 1, PREFIX_OP = 2 } op_type; -OpEntry *Yap_GetOpProp(Atom, op_type CACHE_TYPE); + OpEntry *Yap_GetOpProp(Atom, op_type, Term CACHE_TYPE); -int Yap_IsPrefixOp(Atom, int *, int *); +int Yap_IsPrefixOp(Atom, int *, int *, Term); int Yap_IsOp(Atom); -int Yap_IsInfixOp(Atom, int *, int *, int *); -int Yap_IsPosfixOp(Atom, int *, int *); +int Yap_IsInfixOp(Atom, int *, int *, int *, Term); +int Yap_IsPosfixOp(Atom, int *, int *, Term); /* defines related to operator specifications */ #define MaskPrio 0x0fff