tagged release 0.7.1
[parrot.git] / include / parrot / parrot.h
blobb137b7e595f57278387f218012c19b242956d246
1 /* parrot.h
2 * Copyright (C) 2001-2008, The Perl Foundation.
3 * SVN Info
4 * $Id$
5 * Overview:
6 * General header file includes for the parrot interpreter
7 * Data Structure and Algorithms:
8 * History:
9 * Notes:
10 * References:
13 /* Only parrot core files should include this file.
14 Extensions should include <parrot/extend.h>.
15 Programs embedding parrot should include <parrot/embed.h>.
18 #ifndef PARROT_PARROT_H_GUARD
19 #define PARROT_PARROT_H_GUARD
21 #if defined(INSIDE_GLOBAL_SETUP)
22 # define VAR_SCOPE
23 #else
24 # define VAR_SCOPE extern
25 #endif /* INSIDE_GLOBAL_SETUP */
27 #define PARROT_IN_CORE
29 #include "parrot/config.h"
31 /* ANSI C89 headers */
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <stdarg.h>
35 #include <errno.h>
36 #include <string.h>
37 #include <ctype.h>
39 /* Other headers, where available */
41 /* FreeBSD wants this order:
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
48 as netinet/in.h relies on things defined earlier
51 #ifdef PARROT_HAS_HEADER_SYSTYPES
52 # include <sys/types.h>
53 #endif /* PARROT_HAS_HEADER_SYSTYPES */
55 #ifdef PARROT_HAS_HEADER_SYSSOCKET
56 # include <sys/socket.h>
57 #endif /* PARROT_HAS_HEADER_SYSSOCKET */
59 #ifdef PARROT_HAS_HEADER_NETINETIN
60 # include <netinet/in.h>
61 #endif /* PARROT_HAS_HEADER_NETINETIN */
63 #ifdef PARROT_HAS_HEADER_ARPAINET
64 # include <arpa/inet.h>
65 #endif /* PARROT_HAS_HEADER_ARPAINET */
67 #ifdef PARROT_HAS_HEADER_UNISTD
68 # include <unistd.h>
69 #endif /* PARROT_HAS_HEADER_UNISTD */
71 #ifdef PARROT_HAS_HEADER_SYSMMAN
72 # include <sys/mman.h>
73 # ifndef MAP_FAILED
74 # define MAP_FAILED -1
75 # endif
76 #endif /* PARROT_HAS_HEADER_SYSMMAN */
78 #ifdef PARROT_HAS_HEADER_SYSTIME
79 # include <sys/time.h>
80 #endif /* PARROT_HAS_HEADER_SYSTIME */
82 #ifdef PARROT_HAS_HEADER_TIME
83 # include <time.h>
84 #endif /* PARROT_HAS_HEADER_TIME */
86 #ifdef PARROT_HAS_HEADER_FCNTL
87 # include <fcntl.h>
88 #endif /* PARROT_HAS_HEADER_FCNTL */
90 #ifdef PARROT_HAS_HEADER_NETDB
91 # include <netdb.h>
92 #endif /* PARROT_HAS_HEADER_NETDB */
94 #ifdef PARROT_HAS_HEADER_SYSSTAT
95 # include <sys/stat.h>
96 #endif /* PARROT_HAS_HEADER_SYSSTAT */
98 #ifdef PARROT_HAS_HEADER_SETJMP
99 # include <setjmp.h>
100 typedef jmp_buf Parrot_jump_buff;
101 #endif /* PARROT_HAS_HEADER_SETJMP */
103 #ifdef PARROT_HAS_HEADER_PTHREAD
104 # include <pthread.h>
105 #endif /* PARROT_HAS_HEADER_PTHREAD */
107 #ifdef PARROT_HAS_HEADER_LIMITS
108 # include <limits.h>
109 #endif /* PARROT_HAS_HEADER_LIMITS */
111 #define NUM_REGISTERS 32
112 #define PARROT_MAGIC 0x13155a1
114 #define OPCODE_TYPE_PERL 0x5045524c
115 #define OPCODE_TYPE_PYTHON 0x5045524b
116 #define OPCODE_TYPE_JAVA 4871757
117 #define OPCODE_TYPE_MSNET 0x2e4e4554
119 typedef struct PMC PMC;
120 typedef void STRING_FUNCS;
121 typedef void BIGNUM;
122 typedef struct parrot_interp_t Interp;
124 /* weird architectures might need this, s. C-FAQ 5.17
126 * the SET_NULL macros are only for system, where a NULL pointer
127 * isn't represented by zeroes, so don't use these, for resetting
128 * non-null pointers
131 /* Casting between pointers and integers: If pointers and integers
132 are the same size, then direct casting is fine. If pointers and
133 integers are not the same size, then the compiler might complain.
134 Also, there's a possible loss of information in going from (for
135 example) a 64-bit integer to a 32-bit pointer.
137 These casts silence the warnings but do no limits checks.
138 Perhaps a different set should be defined (and only compiled if
139 explicitly Configured in) which do limits checks?
140 A. D. Aug. 6, 2002.
142 #if PTR_SIZE == INTVAL_SIZE
143 # define INTVAL2PTR(any, d) (any)(d)
144 # define UINTVAL2PTR(any, d) (any)(d)
145 #else
146 # if PTR_SIZE == LONG_SIZE
147 # define INTVAL2PTR(any, d) (any)(unsigned long)(d)
148 # define UINTVAL2PTR(any, d) (any)(unsigned long)(d)
149 # else
150 # define INTVAL2PTR(any, d) (any)(unsigned int)(d)
151 # define UINTVAL2PTR(any, d) (any)(unsigned int)(d)
152 # endif /* PTR_SIZE == LONG_SIZE */
153 #endif /* PTR_SIZE == INTVAL_SIZE */
154 #define PTR2INTVAL(p) INTVAL2PTR(INTVAL, (p))
155 #define PTR2UINTVAL(p) UINTVAL2PTR(UINTVAL, (p))
157 /* Use similar macros for casting between pointers and opcode_t.
158 (We can't assume that sizeof (opcode_t) == sizeof (intval).
160 #if (OPCODE_T_SIZE == PTR_SIZE)
161 # define OPCODE_T2PTR(any, d) (any)(d)
162 #else
163 # if PTR_SIZE == LONG_SIZE
164 # define OPCODE_T2PTR(any, d) (any)(unsigned long)(d)
165 # else
166 # define OPCODE_T2PTR(any, d) (any)(unsigned int)(d)
167 # endif /* PTR_SIZE == LONG_SIZE */
168 #endif /* OPCODE_T_SIZE == PTR_SIZE */
169 #define PTR2OPCODE_T(p) OPCODE_T2PTR(opcode_t, (p))
172 * some compilers don't like lvalue casts, so macroize them
174 * NOTE: Under no circumstances is it permitted to use this macro on types
175 * that are not effectivly guaranteed to be compatible.
176 * Good: int->unsigned; long->unsigned long; struct*->struct*; char*->void*
177 * Bad: integral->pointer; struct*->char*
180 #ifdef __GCC__
181 # define LVALUE_CAST(type, val) ((type)(val))
182 #else
183 # define LVALUE_CAST(type, val) (*((type *)&(val)))
184 #endif /* __GCC__ */
186 /* some SGI compilers have an offsetof()
187 * definition that doesn't work for us. */
188 #if defined(__sgi) && defined(_COMPILER_VERSION) && (_COMPILER_VERSION >= 400)
189 # undef offsetof
190 # define offsetof(s, m) (size_t)(&((((s) *)0)->(m)))
191 #endif
193 /* work around warning:
194 * cast discards qualifiers from pointer target type
195 * for usage grep e.g. in string.c
196 * The casted to type must differ only in constness,
197 * to allow a stricter compiler check in C++ builds.
200 #ifndef __cplusplus
202 #define DECL_CONST_CAST_OF(CCTYPE) \
203 union { const CCTYPE *__c_ptr; CCTYPE *__ptr; } __ptr_u
205 #define DECL_CONST_CAST \
206 DECL_CONST_CAST_OF(void)
208 #define PARROT_const_cast(t, b) ((t)(__ptr_u.__c_ptr = (b), __ptr_u.__ptr))
210 #else
212 #define DECL_CONST_CAST_OF(CCTYPE)
213 #define DECL_CONST_CAST
214 #define PARROT_const_cast(t, b) (const_cast<t>(b))
216 #endif
218 /* define some shortcuts for dealing with function pointers */
219 /* according to ANSI C, casting between function and non-function pointers is
220 * no good. So we should use "funcptr_t" in place of void* when dealing with
221 * function pointers and NULLfunc in place of NULL */
222 typedef void (*funcptr_t)(void);
223 #define NULLfunc (funcptr_t)NULL
225 /* define macros for converting between data and function pointers. As it
226 * turns out, ANSI C does appear to permit you to do this conversion if you
227 * convert the value to an integer (well, a value type large enough to hold
228 * a pointer) in between. Believe it or not, this even works on TenDRA (tcc).
230 * NOTE! UINTVAL is incorrect below. It should be UINTPTR or something like
231 * that. The equivalent of C99's uintptr_t- a non-pointer data type that can
232 * hold a pointer.
234 #define D2FPTR(x) UINTVAL2PTR(funcptr_t, PTR2UINTVAL(x))
235 #define F2DPTR(x) UINTVAL2PTR(void *, PTR2UINTVAL((funcptr_t) (x)))
237 /* On Win32 we need the constant O_BINARY for open() (at least for Borland C),
238 but on UNIX it doesn't exist, so set it to 0 if it's not defined
240 #ifndef O_BINARY
241 # define O_BINARY 0
242 #endif /* O_BINARY */
244 /* Hide our struct copying behind macros */
245 /* Copying to struct pointer from struct pointer */
246 #define STRUCT_COPY(d, s) (PARROT_ASSERT(d), PARROT_ASSERT(s), *(d)=*(s))
247 #define STRUCT_COPY_N(d, s, n) (PARROT_ASSERT(d), PARROT_ASSERT(s), PARROT_ASSERT(sizeof (*(d))==sizeof (*(s))), memcpy((d), (s), sizeof (*(d))*(n)))
248 /* Copying to struct pointer from struct */
249 #define STRUCT_COPY_FROM_STRUCT(d, s) (PARROT_ASSERT(d), *(d)=(s))
251 /* internationalization settings */
252 #ifdef PARROT_HAS_GETTEXT
253 # include <libintl.h>
254 # define _(s) gettext(s)
255 # define gettext_noop(s) (s)
256 # define N_(s) gettext_noop(s)
257 # define PARROT_TEXTDOMAIN(d) textdomain(d)
258 # define PARROT_BINDTEXTDOMAIN(p, d) bindtextdomain((p), (d))
259 #else
260 # define _(s) (s)
261 # define N_(s) (s)
262 # define PARROT_TEXTDOMAIN(d)
263 # define PARROT_BINDTEXTDOMAIN(p, d)
264 #endif /* PARROT_HAS_GETTEXT */
266 #define PACKAGE "parrot"
267 #define LOCALEDIR "."
269 typedef struct _hash Hash;
271 #include "parrot/settings.h"
272 #include "parrot/enums.h"
273 #include "parrot/platform.h"
274 #include "parrot/platform_interface.h"
275 #include "parrot/global_setup.h"
276 #include "parrot/caches.h"
277 #include "parrot/interpreter.h"
278 #include "parrot/datatypes.h"
279 #include "parrot/encoding.h"
280 #include "parrot/charset.h"
281 #include "parrot/string.h"
282 #include "parrot/string_primitives.h"
283 #include "parrot/hash.h"
284 #include "parrot/list.h"
285 #include "parrot/pmc_freeze.h"
286 #include "parrot/vtable.h"
287 #include "parrot/stacks.h"
288 #include "parrot/register.h"
289 #include "parrot/exceptions.h"
290 #include "parrot/warnings.h"
291 #include "parrot/memory.h"
292 #include "parrot/pic.h"
293 #include "parrot/packfile.h"
294 #include "parrot/io.h"
295 #include "parrot/op.h"
296 #include "parrot/pmc.h"
297 #include "parrot/events.h"
298 #include "parrot/intlist.h"
299 #include "parrot/smallobject.h"
300 #include "parrot/headers.h"
301 #include "parrot/dod.h"
302 #include "parrot/resources.h"
303 #include "parrot/string_funcs.h"
304 #include "parrot/misc.h"
305 #include "parrot/sub.h"
306 #include "parrot/inter_call.h"
307 #include "parrot/key.h"
308 #include "parrot/exit.h"
309 #include "parrot/nci.h"
310 #include "parrot/thread.h"
311 #include "parrot/scheduler.h"
312 #include "parrot/tsq.h"
313 #include "parrot/longopt.h"
314 #include "parrot/oo.h"
315 #include "parrot/vtables.h"
316 #include "parrot/mmd.h"
317 #include "parrot/library.h"
318 #include "parrot/global.h"
319 #include "parrot/stat.h"
320 #include "parrot/slice.h"
321 #include "parrot/hll.h"
322 #include "parrot/stm/backend.h"
323 #include "parrot/pbcversion.h"
325 #endif /* PARROT_PARROT_H_GUARD */
328 * Local variables:
329 * c-file-style: "parrot"
330 * End:
331 * vim: expandtab shiftwidth=4: