]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/naref.h
0599dd83a67c7d2c28122aa0491fc9386261a5ba
[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 /* Win64 and Irix should work with this too, but have not been
10  * tested */
11 #   define NASAL_NAN64
12 #elif defined(_M_IX86)   || defined(i386)    || defined(__x86_64) || \
13       defined(__ia64__) || defined(_M_IA64) || defined(__ARMEL__) 
14 # define NASAL_LE
15 #elif defined(__sparc) || defined(__ppc__) ||defined(__PPC) || \
16       defined(__mips) || defined(__ARMEB__)
17 # define NASAL_BE
18 #else
19 # error Unrecognized CPU architecture
20 #endif
21
22 typedef union {
23     struct naObj* obj;
24     struct naStr* str;
25     struct naVec* vec;
26     struct naHash* hash;
27     struct naCode* code;
28     struct naFunc* func;
29     struct naCCode* ccode;
30     struct naGhost* ghost;
31 } naPtr;
32
33 #if defined(NASAL_NAN64)
34
35 /* On suppoted 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. */
39 typedef union { double num; void* ptr; } naRef;
40
41 #elif defined(NASAL_LE) || defined(NASAL_BE)
42
43 /* 32 bit layouts (and 64 bit platforms where we haven't tested the
44    trick above) need endianness-dependent ordering to make sure that
45    the reftag lies in the top bits of the double */
46 #ifdef NASAL_LE
47 typedef struct { naPtr ptr; int reftag; } naRefPart;
48 #else /* NASAL_BE */
49 typedef struct { int reftag; naPtr ptr; } naRefPart;
50 #endif
51
52 typedef union {
53     double num;
54     naRefPart ref;
55 } naRef;
56
57 #endif
58
59 #endif // _NAREF_H