The check to see if an item was already on the heap was randomly hitting.
[jitcs.git] / include / jitcs_base.h
blob626d2f9b954203dbaf6f927d91719aac4df90126
1 //===-- jitcs_base.h C++ ------------------------------------------------*-===//
2 //
3 // Definition of basic types and basic macros.
4 //
5 //===----------------------------------------------------------------------===//
7 #ifndef _JITCS_BASE_H_
8 #define _JITCS_BASE_H_
10 #include <assert.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #ifdef _MSC_VER
14 // import nullptr, offsetof
15 #include <stddef.h>
16 #endif
18 // TODO: check the existence of nullptr
20 // first a few checks if the types are correctly defined,
21 // the architecture is 32 or 64 bit
22 static_assert(sizeof(int8_t) == 1 && sizeof(uint8_t) == 1,
23 "wrong size of int8_t");
24 static_assert(sizeof(int16_t) == 2 && sizeof(uint16_t) == 2,
25 "wrong size of int16_t");
26 static_assert(sizeof(int32_t) == 4 && sizeof(uint32_t) == 4,
27 "wrong size of int32_t");
28 static_assert(sizeof(int64_t) == 8 && sizeof(uint64_t) == 8,
29 "wrong size of int64_t");
31 static_assert(sizeof(float) == 4 && sizeof(double) == 8,
32 "wrong size of float or double");
34 static_assert(sizeof(intptr_t) == sizeof(void*), "wrong size of intptr_t");
35 static_assert(sizeof(uintptr_t) == sizeof(void*), "wrong size of uintptr_t");
37 static_assert(sizeof(int) == 4 || sizeof(int) == 8, "wrong size of int");
38 static_assert(sizeof(void*) == 4 || sizeof(void*) == 8, "wrong size of void*");
39 static_assert(sizeof(int) <= sizeof(void*), "wrong size of void* < int");
42 namespace jitcs {
43 // type shortcut alias
44 typedef unsigned int uint;
46 // type constructors for use in templates
47 template <unsigned N> struct Int {};
48 template <> struct Int<8> { typedef int8_t Type; };
49 template <> struct Int<16> { typedef int16_t Type; };
50 template <> struct Int<32> { typedef int32_t Type; };
51 template <> struct Int<64> { typedef int64_t Type; };
53 template <unsigned N> struct UInt {};
54 template <> struct UInt<8> { typedef uint8_t Type; };
55 template <> struct UInt<16> { typedef uint16_t Type; };
56 template <> struct UInt<32> { typedef uint32_t Type; };
57 template <> struct UInt<64> { typedef uint64_t Type; };
59 template <unsigned N> struct Float {};
60 template <> struct Float<32> { typedef float Type; };
61 template <> struct Float<64> { typedef double Type; };
63 // more type aliases
64 typedef int8_t i8;
65 typedef int16_t i16;
66 typedef int32_t i32;
67 typedef int64_t i64;
68 typedef uint8_t u8;
69 typedef uint16_t u16;
70 typedef uint32_t u32;
71 typedef uint64_t u64;
73 typedef intptr_t iptr;
74 typedef uintptr_t uptr;
77 } // end of namespace jitcs
79 // ------------------------------
80 // debug macros
81 #define _JITCS_ALWAYS_CHECK_(X) do { if (!(X)) throw ("Assertion failed in " __FILE__ ": " #X); } while (0)
83 #if defined(_DEBUG) && !defined(JITCS_DEBUG)
84 #define JITCS_DEBUG
85 #endif
87 #if defined(_NDEBUG) && defined(JITCS_DEBUG)
88 #undef JITCS_DEBUG
89 #endif
92 #ifdef JITCS_DEBUG
93 #define _JITCS_DBG_CHECK_(X) _JITCS_ALWAYS_CHECK_(X)
94 #define _JITCS_DBG_EXPR_(X) X
95 #define _JITCS_DBG_PARAM_(X) ,X
96 #else
97 #define _JITCS_DBG_CHECK_(X)
98 #define _JITCS_DBG_EXPR_(X)
99 #define _JITCS_DBG_PARAM_(X)
100 #endif
103 #ifdef _MSC_VER
104 #if defined(_M_IX86)
105 #define JITCS_X86
106 #define JITCS_X86_32
107 #define JITCS_32
108 #endif
109 #if defined(_M_X64)
110 #define JITCS_X86
111 #define JITCS_X86_64
112 #define JITCS_64
113 #endif
114 #if defined(_M_ARM)
115 #define JITCS_ARM
116 #endif
117 #if defined(_M_MIPS)
118 #define JITCS_MIPS
119 #endif
120 #endif
121 #ifdef __GNUC__
122 #if defined(__i386__)
123 #define JITCS_X86
124 #define JITCS_X86_32
125 #define JITCS_32
126 #endif
127 #if defined(__x86_64__)
128 #define JITCS_X86
129 #define JITCS_X86_64
130 #define JITCS_64
131 #endif
132 #if defined(__CC_ARM) || defined(__ARMCC__) \
133 || defined(__arm__) || defined(__thumb__)
134 #define JITCS_ARM
135 #endif
136 #endif
138 #if defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
139 #define JITCS_WINDOWS
140 #else
141 #define JITCS_POSIX
142 #endif
144 #endif
145 // _JITCS_BASE_H_