10 #ifndef KRK_NO_NAN_BOXING
18 KRK_VAL_BOOLEAN = 0xFFFC,
19 KRK_VAL_INTEGER = 0xFFFD,
20 KRK_VAL_HANDLER = 0xFFFE,
21 KRK_VAL_NONE = 0xFFFF,
22 KRK_VAL_KWARGS = 0x7FFC,
23 KRK_VAL_OBJECT = 0x7FFD,
24 KRK_VAL_NOTIMPL = 0x7FFE,
43 #define _krk_valuesSame(a,b) (a == b)
57 KRK_VAL_FLOATING = 64,
65 #define _krk_valuesSame(a,b) (memcmp(&(a),&(b),sizeof(KrkValue)) == 0)
153 extern KrkValue krk_parse_int(
const char * start,
size_t width,
unsigned int base);
156 #ifndef KRK_NO_NAN_BOXING
175 #define KRK_VAL_MASK_BOOLEAN ((uint64_t)0xFFFC000000000000)
176 #define KRK_VAL_MASK_INTEGER ((uint64_t)0xFFFD000000000000)
177 #define KRK_VAL_MASK_HANDLER ((uint64_t)0xFFFE000000000000)
178 #define KRK_VAL_MASK_NONE ((uint64_t)0xFFFF000000000000)
179 #define KRK_VAL_MASK_KWARGS ((uint64_t)0x7FFC000000000000)
180 #define KRK_VAL_MASK_OBJECT ((uint64_t)0x7FFD000000000000)
181 #define KRK_VAL_MASK_NOTIMPL ((uint64_t)0x7FFE000000000000)
182 #define KRK_VAL_MASK_NAN ((uint64_t)0x7FFC000000000000)
183 #define KRK_VAL_MASK_LOW ((uint64_t)0x0000FFFFFFFFFFFF)
185 #ifdef KRK_SANITIZE_OBJECT_POINTERS
191 static inline uintptr_t _krk_sanitize(uintptr_t input) {
196 #define _krk_sanitize(ptr) (ptr)
204 #ifdef KRK_HEAP_TAG_BYTE
205 #define KRK_HEAP_TAG ((uintptr_t)KRK_HEAP_TAG_BYTE << 56)
207 #define KRK_HEAP_TAG 0
210 #define NONE_VAL() ((KrkValue)(KRK_VAL_MASK_LOW | KRK_VAL_MASK_NONE))
211 #define NOTIMPL_VAL() ((KrkValue)(KRK_VAL_MASK_LOW | KRK_VAL_MASK_NOTIMPL))
212 #define BOOLEAN_VAL(value) ((KrkValue)(((uint64_t)(value) & KRK_VAL_MASK_LOW) | KRK_VAL_MASK_BOOLEAN))
213 #define INTEGER_VAL(value) ((KrkValue)(((uint64_t)(value) & KRK_VAL_MASK_LOW) | KRK_VAL_MASK_INTEGER))
214 #define KWARGS_VAL(value) ((KrkValue)((uint32_t)(value) | KRK_VAL_MASK_KWARGS))
215 #define OBJECT_VAL(value) ((KrkValue)((_krk_sanitize((uintptr_t)(value)) & KRK_VAL_MASK_LOW) | KRK_VAL_MASK_OBJECT))
216 #define HANDLER_VAL(ty,ta) ((KrkValue)((uint64_t)((((uint64_t)ty) << 32) | ((uint32_t)ta)) | KRK_VAL_MASK_HANDLER))
217 #define FLOATING_VAL(value) (((KrkValueDbl){.dbl = (value)}).val)
219 #define KRK_VAL_TYPE(value) ((value) >> 48)
221 #define KRK_IX(value) ((uint64_t)((value) & KRK_VAL_MASK_LOW))
222 #define KRK_SX(value) ((uint64_t)((value) & 0x800000000000))
223 #define AS_INTEGER(value) ((krk_integer_type)(KRK_SX(value) ? (KRK_IX(value) | KRK_VAL_MASK_NONE) : (KRK_IX(value))))
224 #define AS_BOOLEAN(value) AS_INTEGER(value)
226 #define AS_NOTIMPL(value) ((krk_integer_type)((value) & KRK_VAL_MASK_LOW))
227 #define AS_HANDLER(value) ((uint64_t)((value) & KRK_VAL_MASK_LOW))
228 #define AS_OBJECT(value) ((KrkObj*)(uintptr_t)(((value) & KRK_VAL_MASK_LOW) | KRK_HEAP_TAG))
229 #define AS_FLOATING(value) (((KrkValueDbl){.val = (value)}).dbl)
236 #define IS_INTEGER(value) ((((value) >> 48L) & (KRK_VAL_MASK_HANDLER >> 48L)) == (KRK_VAL_MASK_BOOLEAN >> 48L))
237 #define IS_BOOLEAN(value) (((value) >> 48L) == (KRK_VAL_MASK_BOOLEAN >> 48L))
238 #define IS_NONE(value) (((value) >> 48L) == (KRK_VAL_MASK_NONE >> 48L))
239 #define IS_HANDLER(value) (((value) >> 48L) == (KRK_VAL_MASK_HANDLER >> 48L))
240 #define IS_OBJECT(value) (((value) >> 48L) == (KRK_VAL_MASK_OBJECT >> 48L))
241 #define IS_KWARGS(value) (((value) >> 48L) == (KRK_VAL_MASK_KWARGS >> 48L))
242 #define IS_NOTIMPL(value) (((value) >> 48L) == (KRK_VAL_MASK_NOTIMPL >> 48L))
244 #define IS_FLOATING(value) (((value) & KRK_VAL_MASK_NAN) != KRK_VAL_MASK_NAN)
253 #define NONE_VAL() ((KrkValue){KRK_VAL_NONE,-1})
254 #define NOTIMPL_VAL() ((KrkValue){KRK_VAL_NOTIMPL,0})
255 #define BOOLEAN_VAL(value) ((KrkValue){KRK_VAL_BOOLEAN,!!(value)})
256 #define INTEGER_VAL(value) ((KrkValue){KRK_VAL_INTEGER,((uint64_t)(value)) & 0xFFFFffffFFFFULL})
257 #define KWARGS_VAL(value) ((KrkValue){KRK_VAL_KWARGS,((uint32_t)(value))})
258 #define OBJECT_VAL(value) ((KrkValue){KRK_VAL_OBJECT,((uintptr_t)(value))})
259 #define HANDLER_VAL(ty,ta) ((KrkValue){KRK_VAL_HANDLER,((uint64_t)((((uint64_t)ty) << 32) | ((uint32_t)ta)))})
260 #define FLOATING_VAL(value) ((KrkValue){KRK_VAL_FLOATING,(((KrkValueDbl){.dbl = (value)}).val)})
262 #define KRK_VAL_TYPE(value) ((value).tag)
264 #define KRK_VAL_MASK_NONE ((uint64_t)0xFFFF000000000000)
265 #define KRK_VAL_MASK_LOW ((uint64_t)0x0000FFFFFFFFFFFF)
266 #define KRK_IX(value) ((uint64_t)((value).val & KRK_VAL_MASK_LOW))
267 #define KRK_SX(value) ((uint64_t)((value).val & 0x800000000000))
268 #define AS_INTEGER(value) ((krk_integer_type)(KRK_SX(value) ? (KRK_IX(value) | KRK_VAL_MASK_NONE) : (KRK_IX(value))))
269 #define AS_BOOLEAN(value) AS_INTEGER(value)
271 #define AS_HANDLER(value) ((uint64_t)((value)).val)
272 #define AS_OBJECT(value) ((KrkObj*)((uintptr_t)((value).val)))
273 #define AS_FLOATING(value) (((KrkValueDbl){.val = ((value)).val}).dbl)
275 #define IS_INTEGER(value) (!!(((value)).tag & (KRK_VAL_INTEGER|KRK_VAL_BOOLEAN)))
276 #define IS_BOOLEAN(value) (((value)).tag == KRK_VAL_BOOLEAN)
277 #define IS_NONE(value) (((value)).tag == KRK_VAL_NONE)
278 #define IS_HANDLER(value) (((value)).tag == KRK_VAL_HANDLER)
279 #define IS_OBJECT(value) (((value)).tag == KRK_VAL_OBJECT)
280 #define IS_KWARGS(value) (((value)).tag == KRK_VAL_KWARGS)
281 #define IS_NOTIMPL(value) (((value)).tag == KRK_VAL_NOTIMPL)
282 #define IS_FLOATING(value) (((value)).tag == KRK_VAL_FLOATING)
287 #define AS_HANDLER_TYPE(value) (AS_HANDLER(value) >> 32)
288 #define AS_HANDLER_TARGET(value) (AS_HANDLER(value) & 0xFFFFFFFF)
289 #define IS_HANDLER_TYPE(value,type) (IS_HANDLER(value) && AS_HANDLER_TYPE(value) == type)
291 #define KWARGS_SINGLE (INT32_MAX)
292 #define KWARGS_LIST (INT32_MAX-1)
293 #define KWARGS_DICT (INT32_MAX-2)
294 #define KWARGS_NIL (INT32_MAX-3)
295 #define KWARGS_UNSET (0)
297 #define PRIkrk_int "%" PRId64
298 #define PRIkrk_hex "%" PRIx64
Top-level header with configuration macros.
Flexible vector of stack references.
void krk_initValueArray(KrkValueArray *array)
Initialize a value array.
void krk_freeValueArray(KrkValueArray *array)
Release relesources used by a value array.
void krk_writeValueArray(KrkValueArray *array, KrkValue value)
Add a value to a value array.
Stack reference or primative value.
int krk_valuesEqual(KrkValue a, KrkValue b)
Compare two values for equality.
static int krk_valuesSame(KrkValue a, KrkValue b)
Compare two values by identity.
int krk_valuesSameOrEqual(KrkValue a, KrkValue b)
Compare two values by identity, then by equality.
KrkValue krk_parse_float(const char *start, size_t width)
Parse a string into a float.
KrkValueType
Tag enum for basic value types.