2005-05-27 23:27:59 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog %W% %G% *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: Tags_32LowTag.h.m4 *
|
|
|
|
* Last rev: December 90 *
|
|
|
|
* mods: *
|
|
|
|
* comments: Original Tag Scheme for machines with 32 bits adresses *
|
2008-01-30 10:35:43 +00:00
|
|
|
* version: $Id: Tags_32LowTag.h,v 1.4 2008-01-30 10:35:43 vsc Exp $ *
|
2005-05-27 23:27:59 +01:00
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#define TAG_LOW_BITS_32 1
|
|
|
|
|
|
|
|
/* Version for 32 bit addresses machines,
|
|
|
|
Each term is represented internally as an unsigned 32 bit integer as
|
|
|
|
follows:
|
|
|
|
tag value
|
2005-05-31 09:21:43 +01:00
|
|
|
ints m.....110 numeric value
|
2005-05-27 23:27:59 +01:00
|
|
|
atoms m.....010 offset of atom entry
|
|
|
|
pairs mr.....11 ptr to pair
|
|
|
|
aplied functor mr.....01 ptr to functor followed by args
|
2005-05-31 09:21:43 +01:00
|
|
|
ref mr.....00 address of cell
|
|
|
|
undefined mr.....00 address of cell pointing to itself
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
functors are represented as ptrs to the functor entry in the atom
|
|
|
|
property list
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SHIFT_LOW_TAG 2
|
|
|
|
#define SHIFT_HIGH_TAG 2
|
|
|
|
|
|
|
|
#define MKTAG(HI,LO) ((((UInt) (HI))<<SHIFT_HIGH_TAG)|(LO))
|
|
|
|
|
|
|
|
#define TagBits /* 0x00000007L */ MKTAG(0x1,3)
|
|
|
|
#define LowTagBits /* 0x00000003L */ MKTAG(0x0,3)
|
|
|
|
#define LowBit /* 0x00000001L */ MKTAG(0x0,1)
|
|
|
|
#define HighTagBits /* 0x0000000cL */ MKTAG(0x1,0)
|
|
|
|
#define NumberTag /* 0x0000000dL */ MKTAG(0x1,2)
|
|
|
|
#define AtomTag /* 0x00000006L */ MKTAG(0x0,2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
subtract the total for tag bits, plus 1 bit for GC, plus another
|
|
|
|
for sign
|
|
|
|
*/
|
|
|
|
#define MAX_ABS_INT ((Int)0x04000000L)
|
|
|
|
|
|
|
|
/*
|
|
|
|
UNIQUE_TAG_FOR_PAIR gives the representation for pair an
|
|
|
|
unique tag
|
|
|
|
|
|
|
|
This allows optimisation of switch_list
|
|
|
|
|
|
|
|
*/
|
|
|
|
#define UNIQUE_TAG_FOR_PAIRS 1
|
|
|
|
|
|
|
|
#define PairBits /* 0x00000003L */ MKTAG(0x0,3)
|
|
|
|
#define ApplBit /* 0x00000001L */ MKTAG(0x0,1)
|
|
|
|
#define PrimiBits /* 0x00000002L */ MKTAG(0x0,2)
|
|
|
|
#define NumberBits /* 0x0000000aL */ MKTAG(0x2,2)
|
|
|
|
#define NumberMask /* 0x0000000bL */ MKTAG(0x2,3)
|
|
|
|
|
|
|
|
#define TagOf(V) (Unsigned(V) & LowTagBits)
|
2008-01-30 10:35:43 +00:00
|
|
|
#define LowTagOf(V) (Unsigned(V) & LowTagBits)
|
2005-05-27 23:27:59 +01:00
|
|
|
#define NonTagPart(V) ((Unsigned(V)>>1) & ~LowTagBits)
|
|
|
|
#define TAGGED(TAG,V) (((Unsigned(V)<<(SHIFT_HIGH_TAG+SHIFT_LOW_TAG+1))>>1)|(TAG))
|
|
|
|
#define NONTAGGED(TAG,V) ((Unsigned(V)<<(SHIFT_HIGH_TAG+SHIFT_LOW_TAG+1))>>1)
|
|
|
|
#define TAGGEDA(TAG,V) ((Unsigned(V) << 1)|(TAG))
|
|
|
|
#define CHKTAG(t,Tag) ((Unsigned(t)&TagBits)==Tag)
|
|
|
|
|
|
|
|
/* bits that should not be used by anyone but us */
|
|
|
|
#define YAP_PROTECTED_MASK 0xc0000000L
|
|
|
|
|
2012-06-29 22:44:08 +01:00
|
|
|
#include "inline-only.h"
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN int IsVarTerm (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN int
|
2005-05-27 23:27:59 +01:00
|
|
|
IsVarTerm (Term t)
|
|
|
|
{
|
|
|
|
return (int) (!((t) & LowTagBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN int IsNonVarTerm (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN int
|
2005-05-27 23:27:59 +01:00
|
|
|
IsNonVarTerm (Term t)
|
|
|
|
{
|
|
|
|
return (int) (((t) & LowTagBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term *RepPair (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term *
|
2005-05-27 23:27:59 +01:00
|
|
|
RepPair (Term t)
|
|
|
|
{
|
|
|
|
return (Term *) ((t) - PairBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term AbsPair (Term *);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term
|
2005-05-27 23:27:59 +01:00
|
|
|
AbsPair (Term * p)
|
|
|
|
{
|
|
|
|
return (Term) (Unsigned (p) + PairBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int IsPairTerm (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int
|
2005-05-27 23:27:59 +01:00
|
|
|
IsPairTerm (Term t)
|
|
|
|
{
|
|
|
|
return (Int) ((((t) & LowTagBits) == PairBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term *RepAppl (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term *
|
2005-05-27 23:27:59 +01:00
|
|
|
RepAppl (Term t)
|
|
|
|
{
|
|
|
|
return (Term *) (((t) - ApplBit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term AbsAppl (Term *);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term
|
2005-05-27 23:27:59 +01:00
|
|
|
AbsAppl (Term * p)
|
|
|
|
{
|
|
|
|
return (Term) (Unsigned (p) + ApplBit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int IsApplTerm (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int
|
2005-05-27 23:27:59 +01:00
|
|
|
IsApplTerm (Term t)
|
|
|
|
{
|
|
|
|
return (Int) ((((t) & LowTagBits) == ApplBit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int IsAtomOrIntTerm (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int
|
2005-05-27 23:27:59 +01:00
|
|
|
IsAtomOrIntTerm (Term t)
|
|
|
|
{
|
|
|
|
return (Int) ((((t) & LowTagBits) == 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term AdjustPtr (Term t, Term off);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term
|
2005-05-27 23:27:59 +01:00
|
|
|
AdjustPtr (Term t, Term off)
|
|
|
|
{
|
|
|
|
return (Term) ((t) + off);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term AdjustIDBPtr (Term t, Term off);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Term
|
2005-05-27 23:27:59 +01:00
|
|
|
AdjustIDBPtr (Term t, Term off)
|
|
|
|
{
|
|
|
|
return (Term) ((t) + off);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int IntOfTerm (Term);
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN Int
|
2005-05-27 23:27:59 +01:00
|
|
|
IntOfTerm (Term t)
|
|
|
|
{
|
|
|
|
return (Int) (((Int) (t << 1)) >> (SHIFT_LOW_TAG + SHIFT_HIGH_TAG + 1));
|
|
|
|
}
|