YAP 7.1.0
Tags_24bits.h
1
2
3
4
5
6
7
8/*************************************************************************
9* *
10* YAP Prolog %W% %G% *
11* Yap Prolog was developed at NCCUP - Universidade do Porto *
12* *
13* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
14* *
15**************************************************************************
16* *
17* File: Tags_24bits.h.m4 *
18* Last rev: December 90 *
19* mods: *
20* comments: Tag Scheme for machines with 24 bits adresses (m68000) *
21* version: $Id: Tags_24bits.h,v 1.2 2008-01-30 10:35:43 vsc Exp $ *
22*************************************************************************/
23
24 /* Version for 24 bit addresses (68000)
25 Each term is represented internally as an unsigned 32 bit integer as
26 follows:
27 tag value
28 ints 1m1000 numeric value
29 floats 1m1001 floating point value
30 pairs 1mr10. ptr to pair
31 aplied functor 1mr01. ptr to functor followed by args
32 ref 0mr000 address of cell
33 undefined 0mr000 pointing to itself
34
35 */
36
37#define AllTagBits 0xfc000000L
38#define TagBits 0xbc000000L
39#define MaskAdr 0x03ffffffL
40#define AdrHiBit 0x02000000L
41#define NumberTag 0xa0000000L
42#define FloatTag 0xa4000000L
43#define AtomTag 0x84000000L
44#define PairTag 0x90000000L
45#define ApplTag 0x88000000L
46#define RefTag 0x80000000L
47
48#define MaskBits 6
49
50#define PairBit 0x10000000L
51#define ApplBit 0x08000000L
52#define CompBits 0x18000000L
53#define NumberMask 0xb8000000L
54#define MAX_ABS_INT /* 0xfe00000LL */ ((((UInt)(1<<7))-1) << SHIFT_HIGH_TAG)
55
56#define TagOf(X) (Unsigned(X) & TagBits)
57#define LowTagOf(X) (Unsigned(X) & TagBits)
58#define NonTagPart(X) (Signed(X) & MaskAdr)
59#define TAGGEDA(TAG,V) (TAG | Unsigned(V))
60#define TAGGED(TAG,V) (TAG | NonTagPart(Unsigned(V)))
61#define NONTAGGED(TAG,V) NonTagPart(Unsigned(V))
62#define BitOn(Bit,V) (Bit & Unsigned(V))
63#define CHKTAG(t,Tag) ((Unsigned(t)&TagBits)==Tag)
64
65/* bits that should not be used by anyone but us */
66#define YAP_PROTECTED_MASK 0x00000000L
67
68#include "inline-only.h"
69
70INLINE_ONLY bool IsVarTerm (Term);
71
72INLINE_ONLY bool
73IsVarTerm (Term t)
74{
75 return Signed (t) >= 0;
76}
77
78
79
80INLINE_ONLY bool IsNonVarTerm (Term);
81
82INLINE_ONLY bool
83IsNonVarTerm (Term t)
84{
85 return Signed (t) < 0;
86}
87
88
89
90INLINE_ONLY Term *RepPair (Term);
91
92INLINE_ONLY Term *
93RepPair (Term t)
94{
95 return (Term *) (NonTagPart (t));
96}
97
98
99
100INLINE_ONLY Term AbsPair (Term *);
101
102INLINE_ONLY Term
103AbsPair (Term * p)
104{
105 return (Term) (TAGGEDA (PairTag, (p)));
106}
107
108
109
110INLINE_ONLY bool IsPairTerm (Term);
111
112INLINE_ONLY bool
113IsPairTerm (Term t)
114{
115 return BitOn (PairBit, (t));
116}
117
118
119
120INLINE_ONLY Term *RepAppl (Term);
121
122INLINE_ONLY Term *
123RepAppl (Term t)
124{
125 return (Term *) (NonTagPart (t));
126}
127
128
129
130INLINE_ONLY Term AbsAppl (Term *);
131
132INLINE_ONLY Term
133AbsAppl (Term * p)
134{
135 return (Term) (TAGGEDA (ApplTag, (p)));
136}
137
138
139
140INLINE_ONLY bool IsApplTerm (Term);
141
142INLINE_ONLY bool
143IsApplTerm (Term t)
144{
145 return BitOn (ApplBit, (t));
146}
147
148
149
150INLINE_ONLY bool IsAtomOrIntTerm (Term);
151
152INLINE_ONLY bool
153IsAtomOrIntTerm (Term t)
154{
155 return !(Unsigned (t) & CompBits);
156}
157
158
159
160
161INLINE_ONLY Term AdjustPtr (Term t, Term off);
162
163INLINE_ONLY Term
164AdjustPtr (Term t, Term off)
165{
166 return (Term) ((t) + off);
167}
168
169
170
171INLINE_ONLY Term AdjustIDBPtr (Term t, Term off);
172
173INLINE_ONLY Term
174AdjustIDBPtr (Term t, Term off)
175{
176 return (Term) ((t) + off);
177}
178
179
180
181static inline Int
182IntOfTerm (Term t)
183{
184 Int n;
185 n = (Unsigned (t) & MaskPrim) >> 2;
186
187 if (Unsigned (t) & AdrHiBit)
188 n |= 0xfc000000;
189 return (n);
190}