This commit was generated by cvs2svn to compensate for changes in r4,
which included commits to RCS files with non-trunk default branches. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@5 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
96
C/modules.c
Normal file
96
C/modules.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
File: modules.c *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: module support *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "Heap.h"
|
||||
|
||||
STATIC_PROTO(Int p_current_module, (void));
|
||||
STATIC_PROTO(Int p_current_module1, (void));
|
||||
STD_PROTO(void InitModules, (void));
|
||||
|
||||
#define ByteAdr(X) ((char *) &(X))
|
||||
Term
|
||||
Module_Name(CODEADDR cap)
|
||||
{
|
||||
PredEntry *ap = (PredEntry *)cap;
|
||||
|
||||
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
|
||||
reachable from the current module anyway.
|
||||
|
||||
So I will return the current module in case the system
|
||||
predicate is a meta-call. Otherwise it will still work.
|
||||
*/
|
||||
return(ModuleName[CurrentModule]);
|
||||
else
|
||||
return (ModuleName[ap->ModuleOfPred]);
|
||||
}
|
||||
|
||||
int
|
||||
LookupModule(Term a)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < NoOfModules; ++i)
|
||||
if (ModuleName[i] == a)
|
||||
return (i);
|
||||
ModuleName[i = NoOfModules++] = a;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_current_module(void)
|
||||
{ /* $current_module(Old,New) */
|
||||
Term t;
|
||||
unsigned int i;
|
||||
|
||||
if (!unify_constant(ARG1, ModuleName[CurrentModule]))
|
||||
return (0);
|
||||
t = Deref(ARG2);
|
||||
if (IsVarTerm(t) || !IsAtomTerm(t))
|
||||
return (0);
|
||||
for (i = 0; i < NoOfModules; ++i)
|
||||
if (ModuleName[i] == t) {
|
||||
CurrentModule = i;
|
||||
return (1);
|
||||
}
|
||||
ModuleName[CurrentModule = NoOfModules++] = t;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_current_module1(void)
|
||||
{ /* $current_module(Old) */
|
||||
if (!unify_constant(ARG1, ModuleName[CurrentModule]))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
InitModules(void)
|
||||
{
|
||||
ModuleName[CurrentModule = PrimitivesModule = 0] =
|
||||
MkAtomTerm(LookupAtom("prolog"));
|
||||
ModuleName[1] = MkAtomTerm(LookupAtom("user"));
|
||||
InitCPred("$current_module", 2, p_current_module, SafePredFlag|SyncPredFlag);
|
||||
InitCPred("$current_module", 1, p_current_module1, SafePredFlag|SyncPredFlag);
|
||||
}
|
Reference in New Issue
Block a user