]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/naref.h
Add ppc64 to the list of supported platforms based on testing by Tom Callaway at...
[simgear.git] / simgear / nasal / naref.h
1 #ifndef _NAREF_H
2 #define _NAREF_H
3
4 /* Rather than play elaborate and complicated games with
5  * platform-dependent endianness headers, just detect the platforms we
6  * support.  This list is simpler and smaller, yet still quite
7  * complete. */
8 #if (defined(__x86_64) && defined(__linux__)) || defined(__sparcv9) || \
9     defined(__powerpc64__)
10 /* Win64 and Irix should work with this too, but have not been
11  * tested */
12 #   define NASAL_NAN64
13 #elif defined(_M_IX86)   || defined(i386)    || defined(__x86_64) || \
14       defined(__ia64__) || defined(_M_IA64) || defined(__ARMEL__) 
15 # define NASAL_LE
16 #elif defined(__sparc) || defined(__ppc__) ||defined(__PPC) || \
17       defined(__mips) || defined(__ARMEB__)
18 # define NASAL_BE
19 #else
20 # error Unrecognized CPU architecture
21 #endif
22
23 typedef union {
24     struct naObj* obj;
25     struct naStr* str;
26     struct naVec* vec;
27     struct naHash* hash;
28     struct naCode* code;
29     struct naFunc* func;
30     struct naCCode* ccode;
31     struct naGhost* ghost;
32 } naPtr;
33
34 #if defined(NASAL_NAN64)
35
36 /* On suppoted 64 bit platforms (those where all memory returned from
37  * naAlloc() is guaranteed to lie between 0 and 2^48-1) we union the
38  * double with the pointer, and use fancy tricks (see data.h) to make
39  * sure all pointers are stored as NaNs. */
40 typedef union { double num; void* ptr; } naRef;
41
42 #elif defined(NASAL_LE) || defined(NASAL_BE)
43
44 /* 32 bit layouts (and 64 bit platforms where we haven't tested the
45    trick above) need endianness-dependent ordering to make sure that
46    the reftag lies in the top bits of the double */
47 #ifdef NASAL_LE
48 typedef struct { naPtr ptr; int reftag; } naRefPart;
49 #else /* NASAL_BE */
50 typedef struct { int reftag; naPtr ptr; } naRefPart;
51 #endif
52
53 typedef union {
54     double num;
55     naRefPart ref;
56 } naRef;
57
58 #endif
59
60 #endif // _NAREF_H