From 38a2da68c2e02b8fc5ae308ca9e3b667f8a0aedc Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 8 Jan 2014 17:33:12 +0000 Subject: py: Stuff qstr in object pointer; keys for mp_map_t are now always mp_obj_t. --- py/obj.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'py/obj.h') diff --git a/py/obj.h b/py/obj.h index 208b23442f..f8bc790121 100644 --- a/py/obj.h +++ b/py/obj.h @@ -29,13 +29,21 @@ typedef struct _mp_obj_base_t mp_obj_base_t; #define MP_OBJ_NULL ((mp_obj_t)NULL) -// These macros check for small int or object, and access small int values +// These macros check for small int, qstr or object, and access small int and qstr values +// - xxxx...xxx1: a small int, bits 1 and above are the value +// - xxxx...xx10: a qstr, bits 2 and above are the value +// - xxxx...xx00: a pointer to an mp_obj_base_t -#define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 1) == 0) #define MP_OBJ_IS_SMALL_INT(o) ((((mp_small_int_t)(o)) & 1) != 0) -#define MP_OBJ_IS_TYPE(o, t) (((((mp_small_int_t)(o)) & 1) == 0) && (((mp_obj_base_t*)(o))->type == (t))) +#define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2) +#define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 3) == 0) +#define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) + #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_small_int_t)(o)) >> 1) -#define MP_OBJ_NEW_SMALL_INT(o) ((mp_obj_t)(((o) << 1) | 1)) +#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1)) + +#define MP_OBJ_QSTR_VALUE(o) (((mp_small_int_t)(o)) >> 2) +#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((machine_uint_t)qstr) << 2) | 2)) // These macros are used to declare and define constant function objects // You can put "static" in front of the definitions to make them local -- cgit v1.2.3