simplify module access

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@981 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2004-02-12 12:37:12 +00:00
parent 08fe01ad98
commit 6662ca157e
31 changed files with 391 additions and 416 deletions

View File

@@ -27,10 +27,9 @@ STATIC_PROTO(Int p_current_module1, (void));
#define ByteAdr(X) ((char *) &(X))
Term
Yap_Module_Name(CODEADDR cap)
Yap_Module_Name(PredEntry *ap)
{
PredEntry *ap = (PredEntry *)cap;
Term mod;
if (!ap->ModuleOfPred)
/* If the system predicate is a metacall I should return the
module for the metacall, which I will suppose has to be
@@ -39,20 +38,22 @@ Yap_Module_Name(CODEADDR cap)
So I will return the current module in case the system
predicate is a meta-call. Otherwise it will still work.
*/
return(ModuleName[CurrentModule]);
mod = CurrentModule;
else {
return (ModuleName[ap->ModuleOfPred]);
mod = ap->ModuleOfPred;
}
if (mod) return mod;
return TermProlog;
}
static SMALLUNSGN
static Term
LookupModule(Term a)
{
unsigned int i;
for (i = 0; i < NoOfModules; ++i) {
if (ModuleName[i] == a) {
return (i);
return i;
}
}
ModuleName[i = NoOfModules++] = a;
@@ -62,10 +63,18 @@ LookupModule(Term a)
return (i);
}
SMALLUNSGN
Yap_LookupModule(Term a)
struct pred_entry *
Yap_ModulePred(Term mod)
{
return(LookupModule(a));
return ModulePred[LookupModule(mod)];
}
void
Yap_NewModulePred(Term mod, struct pred_entry *ap)
{
Term imod = LookupModule(mod);
ap->NextPredOfModule = ModulePred[imod];
ModulePred[imod] = ap;
}
static Int
@@ -73,44 +82,40 @@ p_current_module(void)
{ /* $current_module(Old,New) */
Term t;
if (!Yap_unify_constant(ARG1, ModuleName[CurrentModule]))
return (0);
if (CurrentModule) {
if(!Yap_unify_constant(ARG1, CurrentModule))
return FALSE;
} else {
if (!Yap_unify_constant(ARG1, TermProlog))
return FALSE;
}
t = Deref(ARG2);
if (IsVarTerm(t) || !IsAtomTerm(t))
return (0);
CurrentModule = LookupModule(t);
return FALSE;
if (t == TermProlog) {
CurrentModule = 0;
} else {
CurrentModule = t;
LookupModule(CurrentModule);
}
return (TRUE);
}
static Int
p_current_module1(void)
{ /* $current_module(Old) */
if (!Yap_unify_constant(ARG1, ModuleName[CurrentModule]))
return (0);
return (1);
if (CurrentModule)
return Yap_unify_constant(ARG1, CurrentModule);
return Yap_unify_constant(ARG1, TermProlog);
}
static Int
p_change_module(void)
{ /* $change_module(New) */
SMALLUNSGN mod = LookupModule(Deref(ARG1));
Term mod = Deref(ARG1);
LookupModule(mod);
CurrentModule = mod;
return (TRUE);
}
static Int
p_module_number(void)
{ /* $module_number(Mod,Num) */
Term tname = Deref(ARG1);
Term t;
if (IsVarTerm(tname)) {
return(Yap_unify(tname, ModuleName[IntOfTerm(Deref(ARG2))]));
} else {
t = MkIntTerm(LookupModule(Deref(ARG1)));
Yap_unify(t,ARG2);
ARG2 = t;
}
return(TRUE);
return TRUE;
}
static Int
@@ -139,7 +144,6 @@ Yap_InitModulesC(void)
Yap_InitCPred("$current_module", 2, p_current_module, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$current_module", 1, p_current_module1, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$change_module", 1, p_change_module, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$module_number", 2, p_module_number, SafePredFlag);
Yap_InitCPredBack("$all_current_modules", 1, 1, init_current_module, cont_current_module,
SafePredFlag|SyncPredFlag);
}
@@ -148,18 +152,18 @@ Yap_InitModulesC(void)
void
Yap_InitModules(void)
{
ModuleName[PROLOG_MODULE] =
MkAtomTerm(Yap_LookupAtom("prolog"));
ModuleName[USER_MODULE] =
MkAtomTerm(Yap_LookupAtom("user"));
ModuleName[IDB_MODULE] =
MkAtomTerm(Yap_LookupAtom("idb"));
ModuleName[ATTRIBUTES_MODULE] =
MkAtomTerm(Yap_LookupAtom("attributes"));
ModuleName[CHARSIO_MODULE] =
MkAtomTerm(Yap_LookupAtom("charsio"));
ModuleName[TERMS_MODULE] =
MkAtomTerm(Yap_LookupAtom("terms"));
ModuleName[0] =
TermProlog;
ModuleName[1] =
USER_MODULE;
ModuleName[2] =
IDB_MODULE;
ModuleName[3] =
ATTRIBUTES_MODULE;
ModuleName[4] =
CHARSIO_MODULE;
ModuleName[5] =
TERMS_MODULE;
NoOfModules = 6;
CurrentModule = 0;
CurrentModule = PROLOG_MODULE;
}