support BigNums in interface
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1066 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
a21656eebd
commit
874758e936
@ -10,8 +10,11 @@
|
||||
* File: c_interface.c *
|
||||
* comments: c_interface primitives definition *
|
||||
* *
|
||||
* Last rev: $Date: 2004-05-14 16:33:44 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $ *
|
||||
* Last rev: $Date: 2004-05-14 17:11:30 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.44 2004/05/14 16:33:44 vsc
|
||||
* add Yap_ReadBuffer
|
||||
* *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
@ -49,13 +52,16 @@ X_API Term STD_PROTO(YAP_MkVarTerm,(void));
|
||||
X_API Bool STD_PROTO(YAP_IsVarTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsNonVarTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsIntTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsBigNumTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsFloatTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsDbRefTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsAtomTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsPairTerm,(Term));
|
||||
X_API Bool STD_PROTO(YAP_IsApplTerm,(Term));
|
||||
X_API Term STD_PROTO(YAP_MkIntTerm,(Int));
|
||||
X_API Term STD_PROTO(YAP_MkBigNumTerm,(void *));
|
||||
X_API Int STD_PROTO(YAP_IntOfTerm,(Term));
|
||||
X_API void *STD_PROTO(YAP_BigNumOfTerm,(Term));
|
||||
X_API Term STD_PROTO(YAP_MkFloatTerm,(flt));
|
||||
X_API flt STD_PROTO(YAP_FloatOfTerm,(Term));
|
||||
X_API Term STD_PROTO(YAP_MkAtomTerm,(Atom));
|
||||
@ -153,7 +159,17 @@ YAP_Deref(Term t)
|
||||
X_API Bool
|
||||
YAP_IsIntTerm(Term t)
|
||||
{
|
||||
return (IsIntegerTerm(t));
|
||||
return IsIntegerTerm(t);
|
||||
}
|
||||
|
||||
X_API Bool
|
||||
YAP_IsBigNumTerm(Term t)
|
||||
{
|
||||
#if USE_GMP
|
||||
return IsIntegerTerm(t);
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
X_API Bool
|
||||
@ -214,9 +230,39 @@ X_API Int
|
||||
YAP_IntOfTerm(Term t)
|
||||
{
|
||||
if (!IsApplTerm(t))
|
||||
return (IntOfTerm(t));
|
||||
else
|
||||
return(LongIntOfTerm(t));
|
||||
return IntOfTerm(t);
|
||||
else {
|
||||
return LongIntOfTerm(t);
|
||||
}
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YAP_MkBigNumTerm(void *big)
|
||||
{
|
||||
#if USE_GMP
|
||||
Term I;
|
||||
BACKUP_H();
|
||||
|
||||
I = Yap_MkBigIntTerm((MP_INT *)big);
|
||||
RECOVER_H();
|
||||
return I;
|
||||
#else
|
||||
return TermNil;
|
||||
#endif /* USE_GMP */
|
||||
}
|
||||
|
||||
X_API void *
|
||||
YAP_BigNumOfTerm(Term t)
|
||||
{
|
||||
#if USE_GMP
|
||||
if (IsVarTerm(t))
|
||||
return NULL;
|
||||
if (!IsBigIntTerm(t))
|
||||
return NULL;
|
||||
return (void *)Yap_BigIntOfTerm(t);
|
||||
#else
|
||||
return NULL;
|
||||
#endif /* USE_GMP */
|
||||
}
|
||||
|
||||
X_API Term
|
||||
|
@ -11,8 +11,11 @@
|
||||
* File: stdpreds.c *
|
||||
* comments: General-purpose C implemented system predicates *
|
||||
* *
|
||||
* Last rev: $Date: 2004-05-14 16:33:45 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2004-05-14 17:11:30 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.67 2004/05/14 16:33:45 vsc
|
||||
* add Yap_ReadBuffer
|
||||
*
|
||||
* Revision 1.66 2004/05/13 20:54:58 vsc
|
||||
* debugger fixes
|
||||
* make sure we always go back to current module, even during initizlization.
|
||||
@ -56,8 +59,6 @@ static char SccsId[] = "%W% %G%";
|
||||
STD_PROTO(static Int p_setval, (void));
|
||||
STD_PROTO(static Int p_value, (void));
|
||||
STD_PROTO(static Int p_values, (void));
|
||||
STD_PROTO(static Int p_flipflop, (void));
|
||||
STD_PROTO(static Int p_setflop, (void));
|
||||
#ifdef undefined
|
||||
STD_PROTO(static CODEADDR *FindAtom, (CODEADDR, int *));
|
||||
#endif /* undefined */
|
||||
|
23
docs/yap.tex
23
docs/yap.tex
@ -13434,7 +13434,7 @@ The following primitives are provided for creating an integer term from an
|
||||
integer and to access the value of an integer term.
|
||||
@example
|
||||
YAP_Term YAP_MkIntTerm(YAP_Int @var{i})
|
||||
YAP_Int YAP_IntOfTerm(YAP_YAP_Term @var{t})
|
||||
YAP_Int YAP_IntOfTerm(YAP_Term @var{t})
|
||||
@end example
|
||||
@noindent
|
||||
where @code{YAP_Int} is a typedef for the C integer type appropriate for
|
||||
@ -13448,12 +13448,27 @@ on 64 bit machines.
|
||||
The two following primitives play a similar role for floating-point terms
|
||||
@example
|
||||
YAP_Term YAP_MkFloatTerm(YAP_flt @var{double})
|
||||
YAP_flt YAP_FloatOfTerm(YAP_YAP_Term @var{t})
|
||||
YAP_flt YAP_FloatOfTerm(YAP_Term @var{t})
|
||||
@end example
|
||||
@noindent
|
||||
where @code{flt} is a typedef for the appropriate C floating point type,
|
||||
nowadays a @code{double}
|
||||
|
||||
@findex YAP_IsBigNumTerm (C-Interface function)
|
||||
@findex YAP_MkBigNumTerm (C-Interface function)
|
||||
@findex YAP_BigNumOfTerm (C-Interface function)
|
||||
The following primitives are provided for verifying whether a term is
|
||||
a big int, creating a term from a big integer and to access the value
|
||||
of a big int from a term.
|
||||
@example
|
||||
YAP_Term YAP_MkBigNumTerm(YAP_Int @var{i})
|
||||
YAP_Int YAP_BigNumOfTerm(YAP_Term @var{t})
|
||||
@end example
|
||||
@noindent
|
||||
YAP must support bignum for the configuration you are using (check
|
||||
the YAP configuration and setup). For now, Yap only supports the GNU
|
||||
GMP library and the @code{MP_INT *} type.
|
||||
|
||||
Currently, no primitives are supplied to users for manipulating data base
|
||||
references.
|
||||
|
||||
@ -13464,7 +13479,7 @@ A special typedef @code{YAP_Atom} is provided to describe prolog
|
||||
to manipulate atom terms
|
||||
@example
|
||||
YAP_Term YAP_MkAtomTerm(YAP_Atom at)
|
||||
YAP_Atom YAP_AtomOfTerm(YAP_YAP_Term @var{t})
|
||||
YAP_Atom YAP_AtomOfTerm(YAP_Term @var{t})
|
||||
@end example
|
||||
@noindent
|
||||
@findex YAP_LookupAtom (C-Interface function)
|
||||
@ -13514,7 +13529,7 @@ functors
|
||||
YAP_Term YAP_MkApplTerm(YAP_Functor @var{f}, unsigned long int @var{n}, YAP_Term[] @var{args})
|
||||
YAP_Term YAP_MkNewApplTerm(YAP_Functor @var{f}, int @var{n})
|
||||
YAP_Term YAP_ArgOfTerm(int argno,YAP_Term @var{ts})
|
||||
YAP_Functor YAP_FunctorOfTerm(YAP_YAP_Term @var{ts})
|
||||
YAP_Functor YAP_FunctorOfTerm(YAP_Term @var{ts})
|
||||
@end example
|
||||
@noindent
|
||||
The @code{YAP_MkApplTerm} function constructs a new term, with functor
|
||||
|
@ -84,6 +84,9 @@ extern X_API YAP_Term PROTO(YAP_MkVarTerm,(void));
|
||||
/* YAP_Bool IsIntTerm(YAP_Term) */
|
||||
extern X_API YAP_Bool PROTO(YAP_IsIntTerm,(YAP_Term));
|
||||
|
||||
/* YAP_Bool IsBigNumTerm(YAP_Term) */
|
||||
extern X_API YAP_Bool PROTO(YAP_IsBigNumTerm,(YAP_Term));
|
||||
|
||||
/* YAP_Bool IsFloatTerm(YAP_Term) */
|
||||
extern X_API YAP_Bool PROTO(YAP_IsFloatTerm,(YAP_Term));
|
||||
|
||||
@ -102,9 +105,15 @@ extern X_API YAP_Bool PROTO(YAP_IsApplTerm,(YAP_Term));
|
||||
/* Term MkIntTerm(long int) */
|
||||
extern X_API YAP_Term PROTO(YAP_MkIntTerm,(long int));
|
||||
|
||||
/* Term MkBigNumTerm(void *) */
|
||||
extern X_API YAP_Term PROTO(YAP_MkBigNumTerm,(void *));
|
||||
|
||||
/* long int IntOfTerm(Term) */
|
||||
extern X_API long int PROTO(YAP_IntOfTerm,(YAP_Term));
|
||||
|
||||
/* long int BigNumOfTerm(Term) */
|
||||
extern X_API void *PROTO(YAP_BigNumOfTerm,(YAP_Term));
|
||||
|
||||
/* Term MkFloatTerm(double) */
|
||||
extern X_API YAP_Term PROTO(YAP_MkFloatTerm,(double));
|
||||
|
||||
|
@ -5,13 +5,16 @@ YAP_MkVarTerm
|
||||
YAP_IsVarTerm
|
||||
YAP_IsNonVarTerm
|
||||
YAP_IsIntTerm
|
||||
YAP_IsBigNumTerm
|
||||
YAP_IsFloatTerm
|
||||
YAP_IsDbRefTerm
|
||||
YAP_IsAtomTerm
|
||||
YAP_IsPairTerm
|
||||
YAP_IsApplTerm
|
||||
YAP_MkIntTerm
|
||||
YAP_MkBigNumTerm
|
||||
YAP_IntOfTerm
|
||||
YAP_BigNumOfTerm
|
||||
YAP_MkFloatTerm
|
||||
YAP_FloatOfTerm
|
||||
YAP_AtomOfTerm
|
||||
|
Reference in New Issue
Block a user