small fixes

indenting
This commit is contained in:
Vítor Santos Costa 2016-03-30 17:35:03 +01:00
parent 78ba5d01f2
commit 145ad73255
18 changed files with 693 additions and 445566 deletions

3
.gitignore vendored
View File

@ -16,6 +16,7 @@ tags
TGSautom4te.cache
cscope.*
GPATH
m32
GRTAGS
GTAGS
tmtags*
@ -149,5 +150,7 @@ yap-6.3.workspace
yap-6.3.geany
YAP.project
CBlocks
yPQ
*.tmp
YAP.sublime*
yap32/CMakeCache.txt

View File

@ -4447,18 +4447,18 @@ static bool pred_flag_clause(Functor f, Term mod, const char *name,
s[1] = MkIntegerTerm(val);
#elif USE_GMP
{
char s[64];
char text[64];
MP_INT rop;
#ifdef _WIN32
snprintf(s, 64, "%I64d", (long long int)val);
snprintf(text, 64, "%I64d", (long long int)val);
#elif HAVE_SNPRINTF
snprintf(s, 64, "%lld", (long long int)val);
snprintf(text, 64, "%lld", (long long int)val);
#else
sprintf(s, "%lld", (long long int)val);
sprintf(text, "%lld", (long long int)val);
#endif
mpz_init_set_str(&rop, s, 10);
s[1] = Yap_MkBigNumTerm((void *)&rop);
mpz_init_set_str(&rop, text, 10);
s[1] = Yap_MkBigIntTerm((void *)&rop);
}
#endif
tn = Yap_MkApplTerm(f, 2, s);

View File

@ -978,7 +978,6 @@ static Int setup_call_cleanup(USES_REGS1) {
yamop *oCP = CP, *oP = P;
bool rc;
Yap_DisableInterrupts(worker_id);
rc = Yap_RunTopGoal(Setup, false);
Yap_EnableInterrupts(worker_id);
@ -1982,20 +1981,20 @@ bool is_cleanup_cp(choiceptr cp_b) {
static Int JumpToEnv() {
choiceptr handler = B, oh = NULL;
/* just keep the thrown object away, we don't need to care about it
/* just keep the throwm object away, we don't need to care about it
*/
/* careful, previous step may have caused a stack shift,
so get pointers here */
/* find the first choicepoint that may be a catch */
// DBTerm *dbt = Yap_RefToException();
while (handler &&
Yap_PredForChoicePt(handler, NULL) != PredDollarCatch) {
while (handler && Yap_PredForChoicePt(handler, NULL) != PredDollarCatch) {
while (POP_CHOICE_POINT(handler)) {
POP_FAIL_EXECUTE(handler);
}
/* we are already doing a catch */
/* make sure we prune C-choicepoints */
if (handler->cp_ap == NOCODE && handler >= (choiceptr)(LCL0 - LOCAL_CBorder)) {
if (handler->cp_ap == NOCODE &&
handler >= (choiceptr)(LCL0 - LOCAL_CBorder)) {
break;
}
oh = handler;

View File

@ -16,12 +16,11 @@ include(disallow)
disallow_intree_builds()
# set(CMAKE_BUILD_TYPE Debug)
set (MACOSX_RPATH ON)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif(POLICY CMP0042)
if(POLICY CMP0043)
cmake_policy(SET CMP0043 NEW)

View File

@ -90,32 +90,34 @@
*/
#if defined(__APPLE__)
/* mmap on __APPLE__ is not the greatest idea. It overwrites memory allocated by malloc */
/* mmap on __APPLE__ is not the greatest idea. It overwrites memory allocated by
* malloc */
#undef USE_DL_MALLOC
#ifndef USE_SYSTEM_MALLOC
#define USE_SYSTEM_MALLOC 1
#endif
#endif
#if (defined(_AIX) || (defined(__APPLE__) && SIZEOF_INT_P==4) || defined(_WIN32) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__POWERPC__) || defined(__linux__) || defined(IN_SECOND_QUADRANT) || defined(__CYGWIN__)) || defined(__NetBSD__) || defined(__DragonFly__)
#if SIZEOF_INT_P == 4
#define USE_LOW32_TAGS 1
#endif
#if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS)
#if SIZEOF_INT_P == 4 && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS)
#include "Tags_32Ops.h"
#elif LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && defined(USE_LOW32_TAGS)
#elif LONG_ADDRESSES && SIZEOF_INT_P == 4 && !defined(OLD_TAG_SCHEME) && \
defined(USE_LOW32_TAGS)
#include "Tags_32LowTag.h"
#elif LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME)
#elif SIZEOF_INT_P == 8 && !defined(OLD_TAG_SCHEME)
#include "Tags_64bits.h"
#elif !LONG_ADDRESSES
#include "Tags_24bits.h"
// #elif !LONG_ADDRESSES
//
// #include "Tags_24bits.h"
#endif
@ -156,12 +158,7 @@
INLINE_ONLY inline EXTERN Term *VarOfTerm(Term t);
INLINE_ONLY inline EXTERN Term *
VarOfTerm (Term t)
{
return (Term *) (t);
}
INLINE_ONLY inline EXTERN Term *VarOfTerm(Term t) { return (Term *)(t); }
#ifdef YAPOR_SBA
@ -169,22 +166,13 @@ VarOfTerm (Term t)
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1);
INLINE_ONLY inline EXTERN Term
MkVarTerm__ ( USES_REGS1 )
{
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1) {
return (Term)((*HR = 0, HR++));
}
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *);
INLINE_ONLY inline EXTERN int
IsUnboundVar (Term * t)
{
return (int) (*(t) == 0);
}
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *t) { return (int)(*(t) == 0); }
#else
@ -192,108 +180,72 @@ IsUnboundVar (Term * t)
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1);
INLINE_ONLY inline EXTERN Term
MkVarTerm__ ( USES_REGS1 )
{
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1) {
return (Term)((*HR = (CELL)HR, HR++));
}
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *);
INLINE_ONLY inline EXTERN int
IsUnboundVar (Term * t)
{
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *t) {
return (int)(*(t) == (Term)(t));
}
#endif
INLINE_ONLY inline EXTERN CELL *PtrOfTerm(Term);
INLINE_ONLY inline EXTERN CELL *
PtrOfTerm (Term t)
{
INLINE_ONLY inline EXTERN CELL *PtrOfTerm(Term t) {
return (CELL *)(*(CELL *)(t));
}
INLINE_ONLY inline EXTERN Functor FunctorOfTerm(Term);
INLINE_ONLY inline EXTERN Functor
FunctorOfTerm (Term t)
{
INLINE_ONLY inline EXTERN Functor FunctorOfTerm(Term t) {
return (Functor)(*RepAppl(t));
}
#if USE_LOW32_TAGS
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom);
INLINE_ONLY inline EXTERN Term
MkAtomTerm (Atom a)
{
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom a) {
return (Term)(AtomTag | (CELL)(a));
}
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t);
INLINE_ONLY inline EXTERN Atom
AtomOfTerm (Term t)
{
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) {
return (Atom)((~AtomTag & (CELL)(t)));
}
#else
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom);
INLINE_ONLY inline EXTERN Term
MkAtomTerm (Atom at)
{
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom at) {
return (Term)(TAGGEDA((CELL)AtomTag, (CELL)(at)));
}
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t);
INLINE_ONLY inline EXTERN Atom
AtomOfTerm (Term t)
{
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) {
return (Atom)(NonTagPart(t));
}
#endif
INLINE_ONLY inline EXTERN int IsAtomTerm(Term);
INLINE_ONLY inline EXTERN int
IsAtomTerm (Term t)
{
INLINE_ONLY inline EXTERN int IsAtomTerm(Term t) {
return (int)(CHKTAG((t), AtomTag));
}
INLINE_ONLY inline EXTERN Term MkIntTerm(Int);
INLINE_ONLY inline EXTERN Term
MkIntTerm (Int n)
{
INLINE_ONLY inline EXTERN Term MkIntTerm(Int n) {
return (Term)(TAGGED(NumberTag, (n)));
}
/*
A constant to subtract or add to a well-known term, we assume no
overflow problems are possible
@ -301,28 +253,19 @@ MkIntTerm (Int n)
INLINE_ONLY inline EXTERN Term MkIntConstant(Int);
INLINE_ONLY inline EXTERN Term
MkIntConstant (Int n)
{
INLINE_ONLY inline EXTERN Term MkIntConstant(Int n) {
return (Term)(NONTAGGED(NumberTag, (n)));
}
INLINE_ONLY inline EXTERN int IsIntTerm(Term);
INLINE_ONLY inline EXTERN int
IsIntTerm (Term t)
{
INLINE_ONLY inline EXTERN int IsIntTerm(Term t) {
return (int)(CHKTAG((t), NumberTag));
}
INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS);
INLINE_ONLY EXTERN inline Term
MkPairTerm__ (Term head, Term tail USES_REGS)
{
INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS) {
CELL *p = HR;
HR[0] = head;
@ -331,8 +274,6 @@ MkPairTerm__ (Term head, Term tail USES_REGS)
return (AbsPair(p));
}
/* Needed to handle numbers:
these two macros are fundamental in the integer/float conversions */
@ -342,16 +283,9 @@ MkPairTerm__ (Term head, Term tail USES_REGS)
#ifdef TAGS_FAST_OPS
#define IntInBnd(X) (Unsigned(((Int)(X) >> (32 - 7)) + 1) <= 1)
#else
#define IntInBnd(X) ( (X) < MAX_ABS_INT && \
(X) > -MAX_ABS_INT-1L )
#define IntInBnd(X) ((X) < MAX_ABS_INT && (X) > -MAX_ABS_INT - 1L)
#endif
#endif
#ifdef C_PROLOG
#define FlIsInt(X) ( (X) == (Int)(X) && IntInBnd((X)) )
#else
#define FlIsInt(X) ( FALSE )
#endif
/*
There are two types of functors:
@ -373,27 +307,20 @@ MkPairTerm__ (Term head, Term tail USES_REGS)
INLINE_ONLY inline EXTERN Term __MkIntegerTerm(Int USES_REGS);
INLINE_ONLY inline EXTERN Term
__MkIntegerTerm (Int n USES_REGS)
{
INLINE_ONLY inline EXTERN Term __MkIntegerTerm(Int n USES_REGS) {
return (Term)(IntInBnd(n) ? MkIntTerm(n) : MkLongIntTerm(n));
}
#endif
INLINE_ONLY inline EXTERN int IsIntegerTerm(Term);
INLINE_ONLY inline EXTERN int
IsIntegerTerm (Term t)
{
INLINE_ONLY inline EXTERN int IsIntegerTerm(Term t) {
return (int)(IsIntTerm(t) || IsLongIntTerm(t));
}
INLINE_ONLY inline EXTERN Int IntegerOfTerm(Term);
INLINE_ONLY inline EXTERN Int
IntegerOfTerm (Term t)
{
INLINE_ONLY inline EXTERN Int IntegerOfTerm(Term t) {
return (Int)(IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t));
}
@ -404,9 +331,7 @@ IntegerOfTerm (Term t)
INLINE_ONLY inline EXTERN Term __MkAddressTerm(void *USES_REGS);
INLINE_ONLY inline EXTERN Term
__MkAddressTerm (void * n USES_REGS)
{
INLINE_ONLY inline EXTERN Term __MkAddressTerm(void *n USES_REGS) {
return __MkIntegerTerm((Int)n PASS_REGS);
}
@ -414,19 +339,14 @@ __MkAddressTerm (void * n USES_REGS)
INLINE_ONLY inline EXTERN bool IsAddressTerm(Term);
INLINE_ONLY inline EXTERN bool
IsAddressTerm (Term t)
{
INLINE_ONLY inline EXTERN bool IsAddressTerm(Term t) {
return (bool)IsIntegerTerm(t);
}
INLINE_ONLY inline EXTERN void *AddressOfTerm(Term);
INLINE_ONLY inline EXTERN void *
AddressOfTerm (Term t)
{
INLINE_ONLY inline EXTERN void *AddressOfTerm(Term t) {
return (void *)(IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t));
}
#endif

View File

@ -19,15 +19,11 @@
*
*/
inline static int
sub_overflow(Int x, Int i, Int j)
{
inline static int sub_overflow(Int x, Int i, Int j) {
return ((i & ~j & ~x) | (~i & j & x)) < 0;
}
inline static Term
sub_int(Int i, Int j USES_REGS)
{
inline static Term sub_int(Int i, Int j USES_REGS) {
Int x = i - j;
#if USE_GMP
Int overflow = ((i & ~j & ~x) | (~i & j & x)) < 0;
@ -44,89 +40,88 @@ sub_int(Int i, Int j USES_REGS)
#endif
}
inline static Int
SLR(Int i, Int shift)
{
inline static Int SLR(Int i, Int shift) {
return (shift < sizeof(Int) * 8 - 1 ? i >> shift : (i >= 0 ? 0 : -1));
}
#ifdef __GNUC__
#ifdef __i386__
#define DO_MULTI() { Int tmp1; \
__asm__ ("imull %3\n\t movl $0,%1\n\t jno 0f\n\t movl $1,%1\n\t 0:" \
: "=a" (z), \
"=d" (tmp1) \
: "a" (i1), \
"rm" (i2) \
: "cc" ); \
if (tmp1) goto overflow; \
}
#define OPTIMIZE_MULTIPLI 1
#endif
#endif
inline static int
mul_overflow(Int z, Int i1, Int i2)
{
inline static int mul_overflow(Int z, Int i1, Int i2) {
if (i1 == Int_MIN && i2 == -1)
return TRUE;
return (i2 && z / i2 != i1);
}
#if defined(_MSC_VER) && SIZEOF_DOUBLE == SIZEOF_INT_P
#define DO_MULTI() { \
#
#if defined(__GNUC__) && defined(__i386__)
#define DO_MULTI() \
{ \
Int tmp1; \
__asm__("imull %3\n\t movl $0,%1\n\t jno 0f\n\t movl $1,%1\n\t 0:" \
: "=a"(z), "=d"(tmp1) \
: "a"(i1), "rm"(i2) \
: "cc"); \
if (tmp1) \
goto overflow; \
}
#define OPTIMIZE_MULTIPLI 1
#elif defined(_MSC_VER) && SIZEOF_DOUBLE == SIZEOF_INT_P
#define DO_MULTI() \
{ \
uint64_t h1 = (11 > 0 ? i1 : -i1) >> 32; \
uint64_t h2 = (12 > 0 ? i2 : -12) >> 32; \
if (h1 != 0 && h2 != 0) goto overflow;\
if ((uint64_t)(i1 & 0xfffffff)*h2 + ((uint64_t)(i2 & 0xfffffff)*h1) > 0x7fffffff) goto overflow;\
if (h1 != 0 && h2 != 0) \
goto overflow; \
if ((uint64_t)(i1 & 0xfffffff) * h2 + ((uint64_t)(i2 & 0xfffffff) * h1) > \
0x7fffffff) \
goto overflow; \
z = i1 * i2; \
}
#elif __clang__ && FALSE /* not in OSX yet */
#define DO_MULTI() if (__builtin_smul_overflow( i1, i2, & z ) ) { goto overflow; }
#define DO_MULTI() \
if (__builtin_smul_overflow(i1, i2, &z)) { \
goto overflow; \
}
#elif SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
#define DO_MULTI() {\
#define DO_MULTI() \
{ \
int64_t w = (int64_t)i1 * i2; \
if (w >= 0) { \
if ((w | ((int64_t)(2^31)-1)) != ((int64_t)(2^31)-1)) goto overflow; \
if ((w | ((int64_t)(2 ^ 31) - 1)) != ((int64_t)(2 ^ 31) - 1)) \
goto overflow; \
} else { \
if ((-w | ((int64_t)(2^31)-1)) != ((int64_t)(2^31)-1)) goto overflow; \
if ((-w | ((int64_t)(2 ^ 31) - 1)) != ((int64_t)(2 ^ 31) - 1)) \
goto overflow; \
} \
z = w; \
}
#else
#define DO_MULTI() {\
#define DO_MULTI() \
{ \
__int128_t w = (__int128_t)i1 * i2; \
if (w >= 0) { \
if ((w | ((__int128_t)(2^63)-1)) != ((__int128_t)(2^63)-1)) goto overflow; \
if ((w | ((__int128_t)(2 ^ 63) - 1)) != ((__int128_t)(2 ^ 63) - 1)) \
goto overflow; \
} else { \
if ((-w | ((__int128_t)(2^63)-1)) != ((__int128_t)(2^63)-1)) goto overflow; \
if ((-w | ((__int128_t)(2 ^ 63) - 1)) != ((__int128_t)(2 ^ 63) - 1)) \
goto overflow; \
} \
z = (Int)w; \
}
#endif
inline static Term
times_int(Int i1, Int i2 USES_REGS) {
inline static Term times_int(Int i1, Int i2 USES_REGS) {
#ifdef USE_GMP
Int z;
DO_MULTI();
RINT(z);
overflow:
{
return(Yap_gmp_mul_ints(i1, i2));
}
overflow : { return (Yap_gmp_mul_ints(i1, i2)); }
#else
RINT(i1 * i2);
#endif
}
#ifdef USE_GMP
#ifndef __GNUC__X
static int
clrsb(Int i)
{
static int clrsb(Int i) {
Int j = 0;
if (i < 0) {
@ -135,25 +130,35 @@ clrsb(Int i)
i = -i;
}
#if SIZEOF_INT_P == 8
if (i < (Int)(0x100000000)) { j += 32;}
else i >>= 32;
if (i < (Int)(0x100000000)) {
j += 32;
} else
i >>= 32;
#endif
if (i < (Int)(0x10000)) {j += 16;}
else i >>= 16;
if (i < (Int)(0x100)) {j += 8;}
else i >>= 8;
if (i < (Int)(0x10)) {j += 4;}
else i >>= 4;
if (i < (Int)(0x4)) {j += 2;}
else i >>= 2;
if (i < (Int)(0x2)) j++;
if (i < (Int)(0x10000)) {
j += 16;
} else
i >>= 16;
if (i < (Int)(0x100)) {
j += 8;
} else
i >>= 8;
if (i < (Int)(0x10)) {
j += 4;
} else
i >>= 4;
if (i < (Int)(0x4)) {
j += 2;
} else
i >>= 2;
if (i < (Int)(0x2))
j++;
return j;
}
#endif
#endif
inline static Term
do_sll(Int i, Int j USES_REGS) /* j > 0 */
inline static Term do_sll(Int i, Int j USES_REGS) /* j > 0 */
{
#ifdef USE_GMP
if (
@ -174,17 +179,14 @@ do_sll(Int i, Int j USES_REGS) /* j > 0 */
#endif
}
static Term
p_minus(Term t1, Term t2 USES_REGS) {
static Term p_minus(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
case long_int_e:
/* two integers */
return sub_int(IntegerOfTerm(t1), IntegerOfTerm(t2) PASS_REGS);
case double_e:
{
case double_e: {
/* integer, double */
Float fl1 = (Float)IntegerOfTerm(t1);
Float fl2 = FloatOfTerm(t2);
@ -203,8 +205,7 @@ p_minus(Term t1, Term t2 USES_REGS) {
case long_int_e:
/* float * integer */
RFLOAT(FloatOfTerm(t1) - IntegerOfTerm(t2));
case double_e:
{
case double_e: {
RFLOAT(FloatOfTerm(t1) - FloatOfTerm(t2));
}
case big_int_e:
@ -234,17 +235,14 @@ p_minus(Term t1, Term t2 USES_REGS) {
RERROR();
}
static Term
p_times(Term t1, Term t2 USES_REGS) {
static Term p_times(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
case long_int_e:
/* two integers */
return (times_int(IntegerOfTerm(t1), IntegerOfTerm(t2) PASS_REGS));
case double_e:
{
case double_e: {
/* integer, double */
Float fl1 = (Float)IntegerOfTerm(t1);
Float fl2 = FloatOfTerm(t2);
@ -293,8 +291,7 @@ p_times(Term t1, Term t2 USES_REGS) {
RERROR();
}
static Term
p_div(Term t1, Term t2 USES_REGS) {
static Term p_div(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
@ -350,8 +347,7 @@ p_div(Term t1, Term t2 USES_REGS) {
RERROR();
}
static Term
p_and(Term t1, Term t2 USES_REGS) {
static Term p_and(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
@ -391,8 +387,7 @@ p_and(Term t1, Term t2 USES_REGS) {
RERROR();
}
static Term
p_or(Term t1, Term t2 USES_REGS) {
static Term p_or(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
@ -432,14 +427,14 @@ p_or(Term t1, Term t2 USES_REGS) {
RERROR();
}
static Term
p_sll(Term t1, Term t2 USES_REGS) {
static Term p_sll(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
case long_int_e:
/* two integers */
{ Int i2 = IntegerOfTerm(t2);
{
Int i2 = IntegerOfTerm(t2);
if (i2 <= 0) {
if (i2 == Int_MIN) {
@ -480,14 +475,14 @@ p_sll(Term t1, Term t2 USES_REGS) {
RERROR();
}
static Term
p_slr(Term t1, Term t2 USES_REGS) {
static Term p_slr(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
case long_int_e:
/* two integers */
{ Int i2 = IntegerOfTerm(t2);
{
Int i2 = IntegerOfTerm(t2);
if (i2 < 0) {
if (i2 == Int_MIN) {
@ -527,4 +522,3 @@ p_slr(Term t1, Term t2 USES_REGS) {
}
RERROR();
}

127
H/eval.h
View File

@ -27,7 +27,8 @@
+ See @ref arithmetic_cmps for the arithmetic comparisons supported in YAP
+ See @ref arithmetic_operators for what arithmetic operations are supported in YAP
+ See @ref arithmetic_operators for what arithmetic operations are supported
in YAP
YAP supports several different numeric types:
<ul>
@ -88,10 +89,13 @@ exceptions:
@exception "type_error(float( V ), Call)" if must be float
@exception "domain_error(out_of_range( V ), Call)" if argument invalid
@exception "domain_error(not_less_than_zero( V ), Call)" if argument must be positive or zero
@exception "domain_error(not_less_than_zero( V ), Call)" if argument must be
positive or zero
@exception "evaluation_error(undefined( V ), Call)" result is not defined (nan)
@exception "evaluation_error(overflow( V ), Call)" result is arithmetic overflow
@exception "evaluation_error(undefined( V ), Call)" result is not defined
(nan)
@exception "evaluation_error(overflow( V ), Call)" result is arithmetic
overflow
@tableofcontents
@ -132,7 +136,6 @@ exceptions:
#include <string.h>
#endif
#ifdef LONG_MAX
#define Int_MAX LONG_MAX
#else
@ -166,25 +169,30 @@ exceptions:
typedef enum {
/** pi [ISO]
An approximation to the value of <em>pi</em>, that is, the ratio of a circle's circumference to its diameter.
An approximation to the value of <em>pi</em>, that is, the ratio of a
circle's circumference to its diameter.
*
*/
op_pi,
/** e
Euler's number, the base of the natural logarithms (approximately 2.718281828).
Euler's number, the base of the natural logarithms (approximately
2.718281828).
*
*/
op_e,
/** epsilon
The difference between the float `1.0` and the next largest floating point number.
The difference between the float `1.0` and the next largest floating point
number.
*
*/
op_epsilon,
/** inf
Infinity according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode. Also note that
Infinity according to the IEEE Floating-Point standard. Note that
evaluating this term will generate a domain error in the `iso` language mode.
Also note that
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
* ?- +inf =:= -inf.
* false.
@ -230,7 +238,8 @@ typedef enum {
* \X /\ X =:= 0.
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Note that the number of bits of an integer is at least the size in bits of a Prolog term cell.
* Note that the number of bits of an integer is at least the size in bits of
* a Prolog term cell.
*/
op_unot,
/** exp( _X_ ), natural exponentiation of _X_ .
@ -254,7 +263,8 @@ typedef enum {
* Decimal logarithm.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
* ?- between(1, 10, I), Delta is log10(I*10) + log10(1/(I*10)), format('0 == ~3g~n',[Delta]), fail.
* ?- between(1, 10, I), Delta is log10(I*10) + log10(1/(I*10)), format('0
* == ~3g~n',[Delta]), fail.
* 0 == 0
* 0 == 0
* 0 == 0
@ -336,8 +346,7 @@ typedef enum {
op_rdiv
} arith2_op;
yap_error_number
Yap_MathException__(USES_REGS1);
yap_error_number Yap_MathException__(USES_REGS1);
Functor EvalArg(Term);
/* Needed to handle numbers:
@ -349,19 +358,25 @@ Functor EvalArg(Term);
#define FlIsInt(X) (FALSE)
#endif
#ifdef M_WILLIAMS
#define MkEvalFl(X) MkFloatTerm(X)
#else
#define MkEvalFl(X) (FlIsInt(X) ? MkIntTerm((Int)(X)) : MkFloatTerm(X))
#endif
/* Macros used by some of the eval functions */
#define REvalInt(I) { eval_int = (I); return(FInt); }
#define REvalFl(F) { eval_flt = (F); return(FFloat); }
#define REvalError() { return(FError); }
#define REvalInt(I) \
{ \
eval_int = (I); \
return (FInt); \
}
#define REvalFl(F) \
{ \
eval_flt = (F); \
return (FFloat); \
}
#define REvalError() \
{ return (FError); }
/* this macro, dependent on the particular implementation
is used to interface the arguments into the C libraries */
@ -385,13 +400,15 @@ Term Yap_eval_binary(Int,Term,Term);
Term Yap_InnerEval__(Term USES_REGS);
#define Yap_EvalError(id, t, ...) \
Yap_EvalError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
...);
#define Yap_EvalError( id, t, ...) Yap_EvalError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number,Term, ...);
#define Yap_ArithError( id, t, ...) Yap_ArithError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
Int Yap_ArithError__(const char *, const char *, int, yap_error_number,Term, ...);
#define Yap_ArithError(id, t, ...) \
Yap_ArithError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
Int Yap_ArithError__(const char *, const char *, int, yap_error_number, Term,
...);
#include "inline-only.h"
@ -403,35 +420,32 @@ Int Yap_ArithError__(const char *, const char *, int, yap_error_number,Term, ...
INLINE_ONLY inline EXTERN Term Yap_Eval__(Term t USES_REGS);
INLINE_ONLY inline EXTERN Term
Yap_Eval__(Term t USES_REGS)
{
INLINE_ONLY inline EXTERN Term Yap_Eval__(Term t USES_REGS) {
if (t == 0L || (!IsVarTerm(t) && IsNumTerm(t)))
return t;
return Yap_InnerEval(t);
}
inline static void
Yap_ClearExs(void)
{
feclearexcept(FE_ALL_EXCEPT);
}
inline static void Yap_ClearExs(void) { feclearexcept(FE_ALL_EXCEPT); }
inline static yap_error_number
Yap_FoundArithError__(USES_REGS1)
{
inline static yap_error_number Yap_FoundArithError__(USES_REGS1) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR)
return LOCAL_Error_TYPE;
if (trueGlobalPrologFlag( ARITHMETIC_EXCEPTIONS_FLAG ) ) // test support for exception
if (trueGlobalPrologFlag(
ARITHMETIC_EXCEPTIONS_FLAG)) // test support for exception
return Yap_MathException();
return YAP_NO_ERROR;
}
static inline Term takeIndicator(Term t) {
Term ts[2];
if (IsAtomTerm(t)) { ts[0] = t; ts[1] = MkIntTerm(0); }
else if (IsPairTerm(t)) { ts[0] = TermNil; ts[1] = MkIntTerm(2); }
else {
if (IsAtomTerm(t)) {
ts[0] = t;
ts[1] = MkIntTerm(0);
} else if (IsPairTerm(t)) {
ts[0] = TermNil;
ts[1] = MkIntTerm(2);
} else {
CACHE_REGS
ts[0] = MkAtomTerm(NameOfFunctor(FunctorOfTerm(t)));
ts[1] = MkIntegerTerm(ArityOfFunctor(FunctorOfTerm(t)));
@ -442,15 +456,12 @@ static inline Term takeIndicator(Term t) {
Atom Yap_NameOfUnaryOp(int i);
Atom Yap_NameOfBinaryOp(int i);
#define RINT(v) return (MkIntegerTerm(v))
#define RFLOAT(v) return (MkFloatTerm(v))
#define RBIG(v) return (Yap_MkBigIntTerm(v))
#define RERROR() return (0L)
static inline blob_type
ETypeOfTerm(Term t)
{
static inline blob_type ETypeOfTerm(Term t) {
if (IsIntTerm(t))
return long_int_e;
if (IsApplTerm(t)) {
@ -567,8 +578,7 @@ void Yap_gmp_set_bit(Int i, Term t);
INLINE_ONLY inline EXTERN Term __Yap_Mk64IntegerTerm(YAP_LONG_LONG USES_REGS);
INLINE_ONLY inline EXTERN Term
__Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS)
{
__Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS) {
if (i <= Int_MAX && i >= Int_MIN) {
return MkIntegerTerm((Int)i);
} else {
@ -580,20 +590,22 @@ __Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS)
}
}
#if __clang__ && FALSE /* not in OSX yet */
#define DO_ADD() if (__builtin_sadd_overflow( i1, i2, & z ) ) { goto overflow; }
#define DO_ADD() \
if (__builtin_sadd_overflow(i1, i2, &z)) { \
goto overflow; \
}
#endif
inline static Term
add_int(Int i, Int j USES_REGS)
{
inline static Term add_int(Int i, Int j USES_REGS) {
#if USE_GMP
UInt w = (UInt)i + (UInt)j;
if (i > 0) {
if (j > 0 && (Int)w < 0) goto overflow;
if (j > 0 && (Int)w < 0)
goto overflow;
} else {
if (j < 0 && (Int)w > 0) goto overflow;
if (j < 0 && (Int)w > 0)
goto overflow;
}
RINT((Int)w);
/* Integer overflow, we need to use big integers */
@ -605,19 +617,16 @@ add_int(Int i, Int j USES_REGS)
}
/* calculate the most significant bit for an integer */
Int
Yap_msb(Int inp USES_REGS);
Int Yap_msb(Int inp USES_REGS);
static inline Term
p_plus(Term t1, Term t2 USES_REGS) {
static inline Term p_plus(Term t1, Term t2 USES_REGS) {
switch (ETypeOfTerm(t1)) {
case long_int_e:
switch (ETypeOfTerm(t2)) {
case long_int_e:
/* two integers */
return add_int(IntegerOfTerm(t1), IntegerOfTerm(t2) PASS_REGS);
case double_e:
{
case double_e: {
/* integer, double */
Float fl1 = (Float)IntegerOfTerm(t1);
Float fl2 = FloatOfTerm(t2);

File diff suppressed because one or more lines are too long

39
cmake/FindCUDD.cmake Normal file
View File

@ -0,0 +1,39 @@
# Try to find CUDD headers and libraries.
#
# Usage of this module as follows:
#
# find_package(CUDD)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# CUDD_ROOT Set this variable to the root installation of
# libpapi if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# CUDD_FOUND System has CUDD libraries and headers
# CUDD_LIBRARIES The CUDD library
# CUDD_INCLUDE_DIRS The location of CUDD headers
# Get hint from environment variable (if any)
if(NOT CUDD_ROOT AND DEFINED ENV{CUDD_ROOT})
set(CUDD_ROOT "$ENV{CUDD_ROOT}" CACHE PATH "CUDD base directory location (optional, used for nonstandard installation paths)")
mark_as_advanced(CUDD_ROOT)
endif()
# Search path for nonstandard locations
if(CUDD_ROOT)
set(CUDD_INCLUDE_PATH PATHS "${CUDD_ROOT}/include" NO_DEFAULT_PATH)
set(CUDD_LIBRARY_PATH PATHS "${CUDD_ROOT}/lib" NO_DEFAULT_PATH)
endif()
find_path(CUDD_INCLUDE_DIRS NAMES cudd.h cudd/cudd.h HINTS ${CUDD_INCLUDE_PATH})
find_library(CUDD_LIBRARIES NAMES cudd CUDDVC-2.5.0 HINTS ${CUDD_LIBRARY_PATH})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CUDD DEFAULT_MSG CUDD_LIBRARIES CUDD_INCLUDE_DIRS)
mark_as_advanced(CUDD_ROOT CUDD_LIBRARIES CUDD_INCLUDE_DIRS)

View File

@ -9,7 +9,7 @@
# GMP_LIBRARIES_DIR - the directory the library we link with is found in.
find_path(GMP_INCLUDE_DIRS NAMES gmp.h
PATHS "$ENV{PROGRAMFILES}/mpir/include"
PATHS "${GMP_DIR}/include" "${GMP_DIR}" "$ENV{PROGRAMFILES}/mpir/include"
DOC "The gmp include directory"
)
@ -30,12 +30,20 @@ if(MVC)
)
else(MVC)
find_library(GMP_LIBRARIES NAMES gmp
PATHS "{CMAKE_INSTALL_PREFIX}/lib"
PATHS "${GMP_DIR}/lib"
DOC "The GMP library"
)
find_library(GMP_LIBRARIES NAMES gmp
PATHS "${GMP_DIR}"
DOC "The GMP library"
)
find_library(GMP_LIBRARIES NAMES gmp
PATHS "${CMAKE_INSTALL_PREFIX}/lib"
DOC "The GMP library"
)
if(WIN32)
find_library(GMP_LIBRARY_DLL NAMES gmp
PATHS "{CMAKE_INSTALL_PREFIX}/bin"
PATHS "${CMAKE_INSTALL_PREFIX}/bin" "${GMP_DIR}/bin" "${GMP_DIR}"
DOC "The GMP library DLL"
)
endif()

View File

@ -290,7 +290,7 @@ static Int time_file(USES_REGS1) {
snprintf(s, 64, "%I64d", (long long int)n);
mpz_init_set_str(&rop, s, 10);
rc = Yap_MkBigNumTerm((void *)&rop) PASS_REGS);
rc = Yap_MkBigIntTerm((void *)&rop) PASS_REGS);
#else
rc = MkIntegerTerm(ft.dwHighDateTime);
#endif

View File

@ -1022,7 +1022,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
int inp_stream) {
CACHE_REGS
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_END);
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
if (args == NULL) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
LOCAL_Error_TYPE = DOMAIN_ERROR_READ_OPTION;

View File

@ -7,6 +7,28 @@ set(SO_MAJOR 1)
set(SO_MINOR 0)
set(SO_PATCH 0)
find_package (CUDD)
macro_log_feature (CUDD_FOUND "CUDD"
"Use CUDD Library"
"http://vlsi.colorado.edu/~fabio/CUDD/" FALSE)
IF (CUDD_FOUND)
# CUDD_FOUND - system has Cudd
# CUDD_LIBRARIES - Link these to use Cudd
# CUDD_INCLUDE_DIR - Include directory for using Cudd
INCLUDE_DIRECTORIES(
${CUDD_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
check_include_files( util.h HAVE_UTIL_H )
check_include_files( cudd/util.h HAVE_CUDD_UTIL_H )
check_include_files( cudd.h HAVE_CUDD_H )
check_include_files( "stdio.h;cudd/cudd.h" HAVE_CUDD_CUDD_H )
check_include_files( cuddInt.h HAVE_CUDDINT_H )
check_include_files( "stdio.h;cudd/cudd.h;cudd/cuddInt.h" HAVE_CUDD_CUDDINT_H )
set( CPLINT_SOURCES
cplint.h
cplint_yap.c
@ -128,8 +150,6 @@ examples/win.uni
${CMAKE_CURRENT_BINARY_DIR}/../bdd
)
IF (CUDD_FOUND_EXPORT)
add_library (bddem SHARED
${BDDEM_SOURCES}
)

View File

@ -16,7 +16,7 @@ for the relative license.
#include "config.h"
#include "cudd_config.h"
#if HAVE_CUDD_CUDDINT_H
#include "cudd/cuddInt.h"
#include <cudd/cuddInt.h>
#elif HAVE_CUDDINT_H
#include "cuddInt.h"
#endif

View File

@ -1,5 +1,9 @@
cmake_minimum_required (VERSION 2.8)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif(POLICY CMP0042)
include (utils.cmake)
disallow_intree_builds()
@ -19,6 +23,9 @@ if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -std=c99 -pedantic -Wall")
endif ()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" )
add_library (utf8proc
utf8proc.c
utf8proc.h

View File

@ -328,7 +328,7 @@ pl_interface(F, Mod, Lev) :-
catch( open(PF, read, S, [script(true)]) , _, fail ),
repeat,
nb_getval( current_module, MR ),
catch( read_clause( S, T, [module( MR ),term_position(Pos),comment(Comment)] ), Throw, loop_error( MR:Throw)),
catch( read_clause( S, T, [module( MR ),term_position(Pos),comments(Comment)] ), Throw, loop_error( S, MR:Throw)),
( T == end_of_file
->
@ -382,7 +382,7 @@ get_interface( T, F, M0 , _Lev) :-
NT = term_expansion( _, _ )
),
!,
catch(directive(NT, F, M), Error, loop_error(Error)).
catch(directive(NT, F, M), Error, loop_error(c_file,Error)).
get_interface( ( M:H :- _B), F, _M , _Lev) :-
!,
functor( H, N, A),
@ -519,7 +519,7 @@ get_directive( record( Records ), F, M , _Lev) :-
handle_record( Records, F, M).
get_directive( set_prolog_flag(dollar_as_lower_case,On), F, M , _Lev) :-
!,
catch(directive(set_prolog_flag(dollar_as_lower_case,M:On), F), Msg, loop_error(585, Msg) ).
catch(directive(set_prolog_flag(dollar_as_lower_case,M:On), F), Msg, loop_error(c_file, Msg) ).
% support SWI package record
handle_record( (Records1, Records2), F, M ) :-
@ -665,7 +665,7 @@ pl_source(F, F0, Mod, Lev) :-
repeat,
nb_getval( current_module, MR ),
%( sub_atom(F,_,_,_,'examples/matrix.yap') -> spy get_interf ; nospyall ),
catch( read_clause( S, T, [module( MR ),term_position(Pos)] ), Throw, loop_error( Throw)),
catch( read_clause( S, T, [module( MR ),term_position(Pos)] ), Throw, loop_error( S, Throw)),
(
T == end_of_file
->

52
utils/analysis/undefs.yap Normal file
View File

@ -0,0 +1,52 @@
find_undefs :-
% check_args(undefs, boolean, true, true),
format('UNDEFINED procedure calls:~n===~n',[]),
pmodule(M),
findall(P, undef_in_m(M,P), Ps),
Ps = [_|_],
format(' * ~w~n', [M]),
member(P, Ps),
format(' + ~w:~n',[P]),
fail.
find_undefs.
pmodule(M) :-
findall(M, node(M, _,_,_), Ms),
sort(Ms, SMs),
member(M, SMs).
called_in_module(M, P) :-
findall(P, edge((_ :- _-M:P)), Ps),
sort(Ps, SPs),
member(P, SPs).
undef_in_m(M,P) :-
called_in_module(M, P),
\+ edge((_-M:P :- _)),
\+ is_private(_, M, P),
\+ is_public(_, M, P).
/*
setof(M, Target^F^Line^NA^undef( ( Target :- F-M:NA ), Line ), Ms ),
member( Mod, Ms ),
format(' module ~a:~n',[Mod]),
setof(NA, Target^F^Line^undef( ( Target :- F-Mod:NA ), Line ), Ns ),
member( NA, Ns ),
\+ node( Mod , NA , _File1, _ ),
\+ node( prolog , NA , _File2, _ ),
format(' predicate ~w:~n',[NA]),
(
setof(F-Line, Target^undef( ( Target :- F-Mod:NA ), Line ), FLs ),
member(F-L, FLs ),
format(' line ~w, file ~a~n',[L,F]),
fail
;
setof(F-M,Type^node( M, NA, F, Type ) , FMs ),
format(' same name at:~n',[]),
member((F-L)-M, FMs ),
format(' module ~a, file ~a, line ~d~n',[M,F,L]),
fail
).
undefs.
*/

View File

@ -15,6 +15,7 @@
:- use_module(library(analysis/graphs)).
:- use_module(library(analysis/load)).
:- use_module(library(analysis/undefs)).
:- initialization(main).