]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/naref.h
Removal of PLIB/SG from SimGear
[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       defined(_M_X64) 
16 # define NASAL_LE
17 #elif defined(__sparc) || defined(__ppc__) || defined(__PPC) || \
18       defined(__mips) || defined(__ARMEB__)
19 # define NASAL_BE
20 #else
21 # error Unrecognized CPU architecture
22 #endif
23
24 typedef union {
25     struct naObj* obj;
26     struct naStr* str;
27     struct naVec* vec;
28     struct naHash* hash;
29     struct naCode* code;
30     struct naFunc* func;
31     struct naCCode* ccode;
32     struct naGhost* ghost;
33 } naPtr;
34
35 /* On supported 64 bit platforms (those where all memory returned from
36  * naAlloc() is guaranteed to lie between 0 and 2^48-1) we union the
37  * double with the pointer, and use fancy tricks (see data.h) to make
38  * sure all pointers are stored as NaNs.  32 bit layouts (and 64 bit
39  * platforms where we haven't tested the trick above) need
40  * endianness-dependent ordering to make sure that the reftag lies in
41  * the top bits of the double */
42
43 #if defined(NASAL_LE)
44 typedef struct { naPtr ptr; int reftag; } naRefPart;
45 #elif defined(NASAL_BE)
46 typedef struct { int reftag; naPtr ptr; } naRefPart;
47 #endif
48
49 #if defined(NASAL_NAN64)
50 typedef union { double num; void* ptr; } naRef;
51 #else
52 typedef union { double num; naRefPart ref; } naRef;
53 #endif
54
55 #endif // _NAREF_H