C-interface improvements
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@463 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
81c503970a
commit
b8b8dd6a45
@ -62,6 +62,7 @@ X_API Term STD_PROTO(YapMkPairTerm,(Term,Term));
|
||||
X_API Term STD_PROTO(YapHeadOfTerm,(Term));
|
||||
X_API Term STD_PROTO(YapTailOfTerm,(Term));
|
||||
X_API Term STD_PROTO(YapMkApplTerm,(Functor,unsigned int,Term *));
|
||||
X_API Term STD_PROTO(YapMkNewApplTerm,(Functor,unsigned int));
|
||||
X_API Functor STD_PROTO(YapFunctorOfTerm,(Term));
|
||||
X_API Term STD_PROTO(YapArgOfTerm,(Int,Term));
|
||||
X_API Functor STD_PROTO(YapMkFunctor,(Atom,Int));
|
||||
@ -101,6 +102,15 @@ X_API void STD_PROTO(YapSetOutputMessage, (void));
|
||||
X_API int STD_PROTO(YapStreamToFileNo, (Term));
|
||||
X_API void STD_PROTO(YapCloseAllOpenStreams,(void));
|
||||
X_API Term STD_PROTO(YapOpenStream,(void *, char *, Term, int));
|
||||
X_API Term *STD_PROTO(YapNewSlots,(int));
|
||||
X_API void STD_PROTO(YapRecoverSlots,(int));
|
||||
X_API void STD_PROTO(YapThrow,(Term));
|
||||
X_API int STD_PROTO(YapLookupModule,(Term));
|
||||
X_API Term STD_PROTO(YapModuleName,(int));
|
||||
X_API void STD_PROTO(YapHalt,(int));
|
||||
X_API Term *STD_PROTO(YapTopOfLocalStack,(void));
|
||||
X_API void *STD_PROTO(YapPredicate,(Atom,Int,Int));
|
||||
X_API void STD_PROTO(YapPredicateInfo,(void *,Atom *,Int *,Int *));
|
||||
|
||||
X_API Term
|
||||
YapA(int i)
|
||||
@ -284,6 +294,18 @@ YapMkApplTerm(Functor f,unsigned int arity, Term args[])
|
||||
return(t);
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YapMkNewApplTerm(Functor f,unsigned int arity)
|
||||
{
|
||||
Term t;
|
||||
BACKUP_H();
|
||||
|
||||
t = MkNewApplTerm(f, arity);
|
||||
|
||||
RECOVER_H();
|
||||
return(t);
|
||||
}
|
||||
|
||||
X_API Functor
|
||||
YapFunctorOfTerm(Term t)
|
||||
{
|
||||
@ -355,12 +377,12 @@ Yapcut_succeed(void)
|
||||
}
|
||||
|
||||
X_API Int
|
||||
YapUnify(Term pt1, Term pt2)
|
||||
YapUnify(Term t1, Term t2)
|
||||
{
|
||||
Int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = unify(pt1, pt2);
|
||||
out = unify(t1, t2);
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return(out);
|
||||
@ -825,3 +847,74 @@ YapOpenStream(void *fh, char *name, Term nm, int flags)
|
||||
return retv;
|
||||
}
|
||||
|
||||
X_API Term *
|
||||
YapNewSlots(int n)
|
||||
{
|
||||
Term *slot;
|
||||
ASP -= n;
|
||||
slot = ASP;
|
||||
return(slot);
|
||||
}
|
||||
|
||||
X_API void
|
||||
YapRecoverSlots(int n)
|
||||
{
|
||||
ASP += n;
|
||||
}
|
||||
|
||||
X_API void
|
||||
YapThrow(Term t)
|
||||
{
|
||||
BACKUP_MACHINE_REGS();
|
||||
JumpToEnv(t);
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
X_API int
|
||||
YapLookupModule(Term t)
|
||||
{
|
||||
return(LookupModule(t));
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YapModuleName(int i)
|
||||
{
|
||||
return(ModuleName[i]);
|
||||
}
|
||||
|
||||
X_API void
|
||||
YapHalt(int i)
|
||||
{
|
||||
exit_yap(i);
|
||||
}
|
||||
|
||||
X_API CELL *
|
||||
YapTopOfLocalStack(void)
|
||||
{
|
||||
return(ASP);
|
||||
}
|
||||
|
||||
X_API void *
|
||||
YapPredicate(Atom a, Int arity, Int m)
|
||||
{
|
||||
if (arity == 0) {
|
||||
return((void *)RepPredProp(PredPropByAtom(a,m)));
|
||||
} else {
|
||||
Functor f = MkFunctor(a, arity);
|
||||
return((void *)RepPredProp(PredPropByFunc(f,m)));
|
||||
}
|
||||
}
|
||||
|
||||
X_API void
|
||||
YapPredicateInfo(void *p, Atom* a, Int* arity, Int* m)
|
||||
{
|
||||
PredEntry *pd = (PredEntry *)p;
|
||||
if (pd->ArityOfPE) {
|
||||
*arity = pd->ArityOfPE;
|
||||
*a = NameOfFunctor(pd->FunctorOfPred);
|
||||
} else {
|
||||
*arity = 0;
|
||||
*a = (Atom)(pd->FunctorOfPred);
|
||||
}
|
||||
*m = pd->ModuleOfPred;
|
||||
}
|
||||
|
23
C/other.c
23
C/other.c
@ -50,3 +50,26 @@ MkApplTerm(Functor f, unsigned int n, register Term *a)
|
||||
*H++ = (CELL) * a++;
|
||||
return (AbsAppl(t));
|
||||
}
|
||||
|
||||
Term
|
||||
MkNewApplTerm(Functor f, unsigned int n)
|
||||
/* build compound term with functor f and n
|
||||
* args a */
|
||||
{
|
||||
CELL *t = H;
|
||||
|
||||
if (n == 0)
|
||||
return (MkAtomTerm(NameOfFunctor(f)));
|
||||
if (f == FunctorList) {
|
||||
RESET_VARIABLE(H);
|
||||
RESET_VARIABLE(H+1);
|
||||
H+=2;
|
||||
return (AbsPair(t));
|
||||
}
|
||||
*H++ = (CELL) f;
|
||||
while (n--) {
|
||||
RESET_VARIABLE(H);
|
||||
H++;
|
||||
}
|
||||
return (AbsAppl(t));
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: Yap.proto *
|
||||
* mods: *
|
||||
* comments: Function declarations for YAP *
|
||||
* version: $Id: Yapproto.h,v 1.15 2002-05-03 15:30:36 vsc Exp $ *
|
||||
* version: $Id: Yapproto.h,v 1.16 2002-05-06 15:33:04 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
/* prototype file for Yap */
|
||||
@ -36,6 +36,7 @@ Atom STD_PROTO(LookupAtom,(char *));
|
||||
Atom STD_PROTO(FullLookupAtom,(char *));
|
||||
void STD_PROTO(LookupAtomWithAddress,(char *,AtomEntry *));
|
||||
Term STD_PROTO(MkApplTerm,(Functor,unsigned int,Term *));
|
||||
Term STD_PROTO(MkNewApplTerm,(Functor,unsigned int));
|
||||
Prop STD_PROTO(NewPredPropByFunctor,(struct FunctorEntryStruct *, SMALLUNSGN));
|
||||
Prop STD_PROTO(NewPredPropByAtom,(struct AtomEntryStruct *, SMALLUNSGN));
|
||||
Functor STD_PROTO(UnlockedMkFunctor,(AtomEntry *,unsigned int));
|
||||
|
@ -263,6 +263,15 @@ static Term (*YapIMkApplTerm)() = YapMkApplTerm;
|
||||
#define MkApplTerm(F,N,As) YapMkApplTerm(F,N,As)
|
||||
#endif
|
||||
|
||||
/* Term MkNewApplTerm(Functor f, int n) */
|
||||
extern X_API Term PROTO(YapMkNewApplTerm,(Functor,int));
|
||||
#ifdef IndirectCalls
|
||||
static Term (*YapIMkNewApplTerm)() = YapMkNewApplTerm;
|
||||
#define MkNewApplTerm(F,N) (*YapIMkNewApplTerm)(F,N)
|
||||
#else
|
||||
#define MkNewApplTerm(F,N) YapMkNewApplTerm(F,N)
|
||||
#endif
|
||||
|
||||
|
||||
/* Functor FunctorOfTerm(Term) */
|
||||
extern X_API Functor PROTO(YapFunctorOfTerm,(Term));
|
||||
@ -575,13 +584,76 @@ static void (*YapICloseAllOpenStreams)() = YapCloseAllOpenStreams;
|
||||
#define YAP_BINARY_STREAM 0x40
|
||||
#define YAP_SEEKABLE_STREAM 0x80
|
||||
|
||||
/* Term YapP() */
|
||||
/* Term YapOpenStream() */
|
||||
extern X_API Term PROTO(YapOpenStream,(void *, char *, Term, int));
|
||||
#ifdef IndirectCalls
|
||||
static Term (*YapIOpenStream)() = YapOpenStream;
|
||||
#define YapOpenStream(FD,S,T,FL) (*YapIOpenStream)(FD,S,T,FL)
|
||||
#endif
|
||||
|
||||
/* Term *YapNewSlots() */
|
||||
extern X_API Term *PROTO(YapNewSlots,(int));
|
||||
#ifdef IndirectCalls
|
||||
static Term *(*YapINewSlots)(N) = YapNewSlots;
|
||||
#define YapNewSlots(N) (*YapINewSlots)(N)
|
||||
#endif
|
||||
|
||||
/* void YapRecoverSlots() */
|
||||
extern X_API void PROTO(YapRecoverSlots,(int));
|
||||
#ifdef IndirectCalls
|
||||
static void (*YapIRecoverSlots)(N) = YapRecoverSlots;
|
||||
#define YapRecoverSlots(N) (*YapIRecoverSlots)(N)
|
||||
#endif
|
||||
|
||||
/* void YapThrow() */
|
||||
extern X_API void PROTO(YapThrow,(Term));
|
||||
#ifdef IndirectCalls
|
||||
static void (*YapIThrow)(T) = YapThrow;
|
||||
#define YapThrow(T) (*YapIThrow)(T)
|
||||
#endif
|
||||
|
||||
/* int YapLookupModule() */
|
||||
extern X_API int PROTO(YapLookupModule,(Term));
|
||||
#ifdef IndirectCalls
|
||||
static int (*YapILookupModule)(T) = YapLookupModule;
|
||||
#define YapLookupModule(T) (*YapILookupModule)(T)
|
||||
#endif
|
||||
|
||||
/* int YapModuleName() */
|
||||
extern X_API Term PROTO(YapModuleName,(int));
|
||||
#ifdef IndirectCalls
|
||||
static int (*YapIModuleName)(I) = YapModuleName;
|
||||
#define YapModuleName(I) (*YapIModuleName)(I)
|
||||
#endif
|
||||
|
||||
/* int YapHalt() */
|
||||
extern X_API int PROTO(YapHalt,(int));
|
||||
#ifdef IndirectCalls
|
||||
static int (*YapIHalt)(E) = YapHalt;
|
||||
#define YapHalt(E) (*YapIHalt)(E)
|
||||
#endif
|
||||
|
||||
/* int YapTopOfLocalStack() */
|
||||
extern X_API Term *PROTO(YapTopOfLocalStack,(void));
|
||||
#ifdef IndirectCalls
|
||||
static Term *(*YapITopOfLocalStack)() = YapTopOfLocalStack;
|
||||
#define YapTopOfLocalStack() (*YapITopOfLocalStack)()
|
||||
#endif
|
||||
|
||||
/* int YapPredicate() */
|
||||
extern X_API void *PROTO(YapPredicate,(Atom,Int,Int));
|
||||
#ifdef IndirectCalls
|
||||
static Term *(*YapIPredicate)(N,A,M) = YapPredicate;
|
||||
#define YapPredicate(N,A,M) (*YapIPredicate)(N,A,M)
|
||||
#endif
|
||||
|
||||
/* int YapPredicate() */
|
||||
extern X_API void PROTO(YapPredicateInfo,(void *,Atom*,Int*,Int*));
|
||||
#ifdef IndirectCalls
|
||||
static void (*YapIPredicateInfo)(P,N,A,M) = YapPredicateInfo;
|
||||
#define YapPredicateInfo(P,N,A,M) (*YapIPredicateInfo)(P,N,A,M)
|
||||
#endif
|
||||
|
||||
|
||||
#define InitCPred(N,A,F) UserCPredicate(N,F,A)
|
||||
|
||||
|
10
misc/yap.def
10
misc/yap.def
@ -27,6 +27,7 @@ YapMkPairTerm
|
||||
YapHeadOfTerm
|
||||
YapTailOfTerm
|
||||
YapMkApplTerm
|
||||
YapMkNewApplTerm
|
||||
YapFunctorOfTerm
|
||||
YapArgOfTerm
|
||||
YapMkFunctor
|
||||
@ -63,3 +64,12 @@ YapEndConsult
|
||||
YapStreamToFileNo
|
||||
YapCloseAllOpenStreams
|
||||
YapOpenStream
|
||||
YapNewSlots
|
||||
YapRecoverSlots
|
||||
YapThrow
|
||||
YapLookupModule
|
||||
YapModuleName
|
||||
YapHalt
|
||||
YapTopOfLocalStack
|
||||
YapPredicate
|
||||
|
||||
|
Reference in New Issue
Block a user