ops & modules iii
This commit is contained in:
parent
0e50546005
commit
68633a9c34
52
C/init.c
52
C/init.c
|
@ -196,6 +196,52 @@ int Yap_IsOpType(char *type) {
|
||||||
return (i <= 7);
|
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) {
|
static int OpDec(int p, const char *type, Atom a, Term m) {
|
||||||
int i;
|
int i;
|
||||||
AtomEntry *ae = RepAtom(a);
|
AtomEntry *ae = RepAtom(a);
|
||||||
|
@ -203,8 +249,6 @@ static int OpDec(int p, const char *type, Atom a, Term m) {
|
||||||
|
|
||||||
if (m == TermProlog)
|
if (m == TermProlog)
|
||||||
m = PROLOG_MODULE;
|
m = PROLOG_MODULE;
|
||||||
else if (m == USER_MODULE)
|
|
||||||
m = PROLOG_MODULE;
|
|
||||||
for (i = 1; i <= 7; ++i)
|
for (i = 1; i <= 7; ++i)
|
||||||
if (strcmp(type, optypes[i]) == 0)
|
if (strcmp(type, optypes[i]) == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -220,7 +264,7 @@ static int OpDec(int p, const char *type, Atom a, Term m) {
|
||||||
p |= DcrrpFlag;
|
p |= DcrrpFlag;
|
||||||
}
|
}
|
||||||
WRITE_LOCK(ae->ARWLock);
|
WRITE_LOCK(ae->ARWLock);
|
||||||
info = Yap_GetOpPropForAModuleHavingALock(ae, m);
|
info = fetchOpForModule(ae, m);
|
||||||
if (EndOfPAEntr(info)) {
|
if (EndOfPAEntr(info)) {
|
||||||
info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry));
|
info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry));
|
||||||
info->KindOfPE = Ord(OpProperty);
|
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_LOCK(info->OpRWLock);
|
||||||
WRITE_UNLOCK(ae->ARWLock);
|
WRITE_UNLOCK(ae->ARWLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i <= 3) {
|
if (i <= 3) {
|
||||||
if (trueGlobalPrologFlag(ISO_FLAG) &&
|
if (trueGlobalPrologFlag(ISO_FLAG) &&
|
||||||
info->Posfix != 0) /* there is a posfix operator */ {
|
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;
|
info->Infix = p;
|
||||||
} else if (i <= 5) {
|
} else if (i <= 5) {
|
||||||
|
|
||||||
if (trueGlobalPrologFlag(ISO_FLAG) &&
|
if (trueGlobalPrologFlag(ISO_FLAG) &&
|
||||||
info->Infix != 0) /* there is an infix operator */ {
|
info->Infix != 0) /* there is an infix operator */ {
|
||||||
/* ISO dictates */
|
/* ISO dictates */
|
||||||
|
|
25
H/Yatom.h
25
H/Yatom.h
|
@ -266,16 +266,17 @@ INLINE_ONLY inline EXTERN int IsWideAtom(Atom at) {
|
||||||
|
|
||||||
/* Module property */
|
/* Module property */
|
||||||
typedef struct mod_entry {
|
typedef struct mod_entry {
|
||||||
Prop NextOfPE; /* used to chain properties */
|
Prop NextOfPE; /** used to chain properties */
|
||||||
PropFlags KindOfPE; /* kind of property */
|
PropFlags KindOfPE; /** kind of property */
|
||||||
struct pred_entry *PredForME; /* index in module table */
|
struct pred_entry *PredForME; /** list of predicates for that module */
|
||||||
Atom AtomOfME; /* module's name */
|
Atom AtomOfME; /** module's name */
|
||||||
Atom OwnerFile; /* module's owner file */
|
Atom OwnerFile; /** module's owner file */
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#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
|
#endif
|
||||||
unsigned int flags; /* Module local flags (from SWI compat) */
|
Term ParentForME; /** the module we wer created from */
|
||||||
struct mod_entry *NextME; /* next module */
|
unsigned int flags; /** Module local flags (from SWI compat): includes ops, strings */
|
||||||
|
struct mod_entry *NextME; /** next module */
|
||||||
} ModEntry;
|
} ModEntry;
|
||||||
|
|
||||||
#if USE_OFFSETS_IN_PROPS
|
#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;
|
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_IsOp(Atom);
|
||||||
int Yap_IsInfixOp(Atom, int *, int *, int *);
|
int Yap_IsInfixOp(Atom, int *, int *, int *, Term);
|
||||||
int Yap_IsPosfixOp(Atom, int *, int *);
|
int Yap_IsPosfixOp(Atom, int *, int *, Term);
|
||||||
|
|
||||||
/* defines related to operator specifications */
|
/* defines related to operator specifications */
|
||||||
#define MaskPrio 0x0fff
|
#define MaskPrio 0x0fff
|
||||||
|
|
Reference in New Issue