1/* BEGIN LICENSE BLOCK
2 * Version: CMPL 1.1
3 *
4 * The contents of this file are subject to the Cisco-style Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file except
6 * in compliance with the License.  You may obtain a copy of the License
7 * at www.eclipse-clp.org/license.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11 * the License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is  The ECLiPSe Constraint Logic Programming System.
15 * The Initial Developer of the Original Code is  Cisco Systems, Inc.
16 * Portions created by the Initial Developer are
17 * Copyright (C) 1989-2006 Cisco Systems, Inc.  All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * END LICENSE BLOCK */
22
23/*
24 * ECLiPSe INCLUDE FILE
25 *
26 * $Id: ec_public.h,v 1.6 2011/05/05 07:49:36 jschimpf Exp $
27 *
28 * Macro definitions needed for the ECLiPSe embedding interface.
29 *
30 */
31
32/* To allow to compile external include files under C++ */
33
34#if defined(__cplusplus)
35#  define Dots	...
36#  define Extern extern "C"
37#  define ARGS(x) x
38#  ifdef const
39#    undef const
40#  endif
41#else
42#  define Dots
43#  define Extern extern
44#  ifdef __STDC__
45#    define ARGS(x) x
46#  else
47#    define ARGS(x) ()
48#  endif
49#endif
50
51/******************************************************************/
52/*		Machine-dependent definitions			 */
53/******************************************************************/
54
55/* A "word" is a pointer-sized integer.
56 * The following size/min/max definitions are all about "words",
57 * even when they say "int".
58 */
59#define SIZEOF_WORD	SIZEOF_CHAR_P
60
61/* suffix needed for word-sized constants */
62#if (SIZEOF_WORD == SIZEOF_INT)
63#define WSUF(X)  X
64#define UWSUF(X) X
65#define W_MOD ""
66#elif (SIZEOF_WORD == SIZEOF_LONG)
67#define WSUF(X) (X##L)
68#define UWSUF(X) (X##UL)
69#define W_MOD "l"
70#elif (defined(HAVE_LONG_LONG) || defined(__GNUC__)) && \
71     (SIZEOF_WORD == __SIZEOF_LONG_LONG__)
72#define WSUF(X) (X##LL)
73#define UWSUF(X) (X##ULL)
74# ifdef _WIN32
75/* MSVC did not support long long until V8 (2005). Cross-compiling with
76   MingGW can use long long, but as calling printf/scanf will use MS
77   rather than GNU libc, we need to use MS's 64 bit integer modifier
78*/
79# define W_MOD "I64"
80# else
81# define W_MOD "ll"
82# endif
83#elif (defined(HAVE___INT64) && SIZEOF_WORD == 8)
84#define WSUF(X) (X##I64)
85#define UWSUF(X) (X##UI64)
86#define W_MOD "I64"
87#else
88PROBLEM: word size do not correspond to size of common integer types
89#endif
90
91/* Important:  SIGN_BIT is unsigned! */
92#if (SIZEOF_WORD ==  8)
93#define SIGN_BIT	((uword) UWSUF(0x8000000000000000))
94#define MAX_NUMBER	"9223372036854775807"
95#elif (SIZEOF_WORD == 4)
96#define SIGN_BIT	((uword) UWSUF(0x80000000))
97#define MAX_NUMBER	"2147483647"
98#else
99PROBLEM: Cannot deal with word size SIZEOF_WORD.
100#endif
101
102
103#define MAX_U_WORD	((uword) -1)
104#define MAX_S_WORD	((word) ~SIGN_BIT)
105#define MIN_S_WORD      ((word) SIGN_BIT)
106
107/*
108 * Min/max words as doubles.
109 * These definitions are guaranteed to work fine regardless of word size as
110 * as long as MIN_S_WORD is a power of 2 and MAX_S_WORD is one less than a
111 * power of two --- assuming round-to-nearest during type conversion.
112 */
113
114#define MIN_S_WORD_DBL		((double)MIN_S_WORD)
115#define MAX_S_WORD_1_DBL	((double)MAX_S_WORD+1.0)
116
117
118/*
119 * If the word size is big enough, doubles are unboxed
120 */
121
122#define SIZEOF_DOUBLE	8
123
124#if SIZEOF_WORD >= SIZEOF_DOUBLE
125#define UNBOXED_DOUBLES
126#else
127#undef UNBOXED_DOUBLES
128#endif
129
130
131/*
132 * Sometimes it's useful to know how large an integer we can fit in a
133 * double.
134 * The following probably should be autoconf'ed.
135 * An IEEE double precision floating point number has a 52 bit significand,
136 * which coupled with an implicit 1, means we have 53 bits to play with.
137 * This means that 2^53 - 1 is the largest integer representable with all
138 * its bits stored explicitly, 2^53 works (the bit that drops off the end is
139 * a 0, which gets assumed), and 2^53 + 1 is the first one to really fail.
140 * Of course, these integers cannot be represented on a 32-bit machine, so
141 * we provide the same limit as a double, but in this case we don't know
142 * whether 2^53 really was 2^53 before conversion, or whether it's 2^53 + 1
143 * rounded down.
144 */
145#define DOUBLE_SIGNIFICANT_BITS	53
146#if (SIZEOF_WORD >= SIZEOF_DOUBLE)
147#define DOUBLE_INT_LIMIT	(WSUF(1) << DOUBLE_SIGNIFICANT_BITS)
148#endif
149#define DOUBLE_INT_LIMIT_AS_DOUBLE	9007199254740992.0
150
151/*
152 * Global array sizes
153 */
154
155#define MAXARITY		255	/* Max arity of a regular predicate */
156#define MAXSIMPLEARITY		8	/* Max arity of a simple predicate */
157#define NARGREGS		(1/*A0*/ + MAXARITY + MAXSIMPLEARITY + 3/*metacall*/)
158#define NTYPES			13	/* Number of types */
159#define ARITH_OPERATIONS	53	/* Number of arithmetic operations */
160
161
162/*
163 * The most common return values from C externals
164 * and from resumed Eclipse executions
165 */
166
167#define PSUCCEED		0	/* success			*/
168#define PFAIL			1	/* failure			*/
169#define PTHROW			2	/* exit_block, ball in A1	*/
170#define PYIELD			4	/* Eclipse engine suspended	*/
171#define PRUNNING		5	/* Eclipse engine running	*/
172#define PWAITIO			6	/* waiting for queue input	*/
173#define PFLUSHIO		7	/* request queue output		*/
174
175#define INSTANTIATION_FAULT	-4	/* variable instead of constant */
176#define TYPE_ERROR		-5	/* wrong type */
177#define RANGE_ERROR		-6	/* out of range */
178
179
180/*
181 * Initialisation
182 *
183 * init_flags indicates what parts of the system need to be
184 * initialised (bit-significant flags):
185 *
186 *	INIT_SHARED	shared/saveable heap
187 *	REINIT_SHARED	heap was restored, some info must be updated
188 *	INIT_PRIVATE	C variables, private heap
189 *	INIT_ENGINE	abstract machine
190 *	INIT_PROCESS	do initialisations that are needed once
191 *
192 * Initialisation is done in different situations:
193 *
194 * raw boot		INIT_SHARED|INIT_PRIVATE|INIT_ENGINE|INIT_PROCESS
195 * after -r		REINIT_SHARED|INIT_PROCESS|INIT_PRIVATE [|INIT_ENGINE]
196 * after -c		INIT_PROCESS|INIT_PRIVATE
197 * after restore/1	REINIT_SHARED|INIT_PRIVATE [|INIT_ENGINE]
198 * after reset	0 (maybe INIT_PRIVATE)
199 */
200
201#define	INIT_SHARED	1
202#define	INIT_PRIVATE	2
203#define	INIT_ENGINE	4
204#define	INIT_PROCESS	8
205#define	REINIT_SHARED	16
206
207
208