@@ -83,6 +83,17 @@ static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
8383#define MP_OBJ_QSTR_VALUE (o ) (((mp_uint_t)(o)) >> 2)
8484#define MP_OBJ_NEW_QSTR (qst ) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
8585
86+ #if MICROPY_PY_BUILTINS_FLOAT
87+ #define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
88+ #define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
89+ extern const struct _mp_obj_float_t mp_const_float_e_obj ;
90+ extern const struct _mp_obj_float_t mp_const_float_pi_obj ;
91+
92+ #define mp_obj_is_float (o ) MP_OBJ_IS_TYPE((o), &mp_type_float)
93+ mp_float_t mp_obj_float_get (mp_obj_t self_in );
94+ mp_obj_t mp_obj_new_float (mp_float_t value );
95+ #endif
96+
8697static inline bool MP_OBJ_IS_OBJ (mp_const_obj_t o )
8798 { return ((((mp_int_t )(o )) & 3 ) == 0 ); }
8899
@@ -98,9 +109,55 @@ static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
98109#define MP_OBJ_QSTR_VALUE (o ) (((mp_uint_t)(o)) >> 2)
99110#define MP_OBJ_NEW_QSTR (qst ) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 3))
100111
112+ #if MICROPY_PY_BUILTINS_FLOAT
113+ #define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
114+ #define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
115+ extern const struct _mp_obj_float_t mp_const_float_e_obj ;
116+ extern const struct _mp_obj_float_t mp_const_float_pi_obj ;
117+
118+ #define mp_obj_is_float (o ) MP_OBJ_IS_TYPE((o), &mp_type_float)
119+ mp_float_t mp_obj_float_get (mp_obj_t self_in );
120+ mp_obj_t mp_obj_new_float (mp_float_t value );
121+ #endif
122+
101123static inline bool MP_OBJ_IS_OBJ (mp_const_obj_t o )
102124 { return ((((mp_int_t )(o )) & 1 ) == 0 ); }
103125
126+ #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
127+
128+ static inline bool MP_OBJ_IS_SMALL_INT (mp_const_obj_t o )
129+ { return ((((mp_int_t )(o )) & 1 ) != 0 ); }
130+ #define MP_OBJ_SMALL_INT_VALUE (o ) (((mp_int_t)(o)) >> 1)
131+ #define MP_OBJ_NEW_SMALL_INT (small_int ) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
132+
133+ #define mp_const_float_e ((mp_obj_t)((0x402df854 & ~3) | 2))
134+ #define mp_const_float_pi ((mp_obj_t)((0x40490fdb & ~3) | 2))
135+
136+ static inline bool mp_obj_is_float (mp_const_obj_t o )
137+ { return (((mp_uint_t )(o )) & 3 ) == 2 && (((mp_uint_t )(o )) & 0x7f800004 ) != 0x7f800004 ; }
138+ static inline mp_float_t mp_obj_float_get (mp_const_obj_t o ) {
139+ union {
140+ mp_float_t f ;
141+ mp_uint_t u ;
142+ } num = {.u = (mp_uint_t )o & ~3 };
143+ return num .f ;
144+ }
145+ static inline mp_obj_t mp_obj_new_float (mp_float_t f ) {
146+ union {
147+ mp_float_t f ;
148+ mp_uint_t u ;
149+ } num = {.f = f };
150+ return (mp_obj_t )((num .u & ~0x3 ) | 2 );
151+ }
152+
153+ static inline bool MP_OBJ_IS_QSTR (mp_const_obj_t o )
154+ { return (((mp_uint_t )(o )) & 0x7f800007 ) == 0x7f800006 ; }
155+ #define MP_OBJ_QSTR_VALUE (o ) ((((mp_uint_t)(o)) >> 3) & 0xfffff)
156+ #define MP_OBJ_NEW_QSTR (qst ) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 0x7f800006))
157+
158+ static inline bool MP_OBJ_IS_OBJ (mp_const_obj_t o )
159+ { return ((((mp_int_t )(o )) & 3 ) == 0 ); }
160+
104161#endif
105162
106163// Macros to convert between mp_obj_t and concrete object types.
@@ -473,7 +530,6 @@ mp_obj_t mp_obj_new_bytearray(mp_uint_t n, void *items);
473530mp_obj_t mp_obj_new_bytearray_by_ref (mp_uint_t n , void * items );
474531#if MICROPY_PY_BUILTINS_FLOAT
475532mp_obj_t mp_obj_new_int_from_float (mp_float_t val );
476- mp_obj_t mp_obj_new_float (mp_float_t val );
477533mp_obj_t mp_obj_new_complex (mp_float_t real , mp_float_t imag );
478534#endif
479535mp_obj_t mp_obj_new_exception (const mp_obj_type_t * exc_type );
@@ -564,11 +620,6 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, mp_uint_
564620
565621#if MICROPY_PY_BUILTINS_FLOAT
566622// float
567- typedef struct _mp_obj_float_t {
568- mp_obj_base_t base ;
569- mp_float_t value ;
570- } mp_obj_float_t ;
571- mp_float_t mp_obj_float_get (mp_obj_t self_in );
572623mp_obj_t mp_obj_float_binary_op (mp_uint_t op , mp_float_t lhs_val , mp_obj_t rhs ); // can return MP_OBJ_NULL if op not supported
573624
574625// complex
0 commit comments