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