@@ -88,14 +88,6 @@ mp_obj_t mp_builtin_any(mp_obj_t o_in) {
8888 return mp_const_false ;
8989}
9090
91- mp_obj_t mp_builtin_bool (int n_args , const mp_obj_t * args ) {
92- switch (n_args ) {
93- case 0 : return mp_const_false ;
94- case 1 : if (rt_is_true (args [0 ])) { return mp_const_true ; } else { return mp_const_false ; }
95- default : nlr_jump (mp_obj_new_exception_msg_1_arg (MP_QSTR_TypeError , "bool() takes at most 1 argument (%d given)" , (void * )(machine_int_t )n_args ));
96- }
97- }
98-
9991mp_obj_t mp_builtin_callable (mp_obj_t o_in ) {
10092 if (mp_obj_is_callable (o_in )) {
10193 return mp_const_true ;
@@ -104,42 +96,6 @@ mp_obj_t mp_builtin_callable(mp_obj_t o_in) {
10496 }
10597}
10698
107- #if MICROPY_ENABLE_FLOAT
108- mp_obj_t mp_builtin_complex (int n_args , const mp_obj_t * args ) {
109- assert (0 <= n_args && n_args <= 2 );
110-
111- if (n_args == 0 ) {
112- return mp_obj_new_complex (0 , 0 );
113- } else if (n_args == 1 ) {
114- // TODO allow string as first arg and parse it
115- if (MP_OBJ_IS_TYPE (args [0 ], & complex_type )) {
116- return args [0 ];
117- } else {
118- return mp_obj_new_complex (mp_obj_get_float (args [0 ]), 0 );
119- }
120- } else {
121- mp_float_t real , imag ;
122- if (MP_OBJ_IS_TYPE (args [0 ], & complex_type )) {
123- mp_obj_get_complex (args [0 ], & real , & imag );
124- } else {
125- real = mp_obj_get_float (args [0 ]);
126- imag = 0 ;
127- }
128- if (MP_OBJ_IS_TYPE (args [1 ], & complex_type )) {
129- mp_float_t real2 , imag2 ;
130- mp_obj_get_complex (args [1 ], & real2 , & imag2 );
131- real -= imag2 ;
132- imag += real2 ;
133- } else {
134- imag += mp_obj_get_float (args [1 ]);
135- }
136- return mp_obj_new_complex (real , imag );
137- }
138- }
139-
140- MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mp_builtin_complex_obj , 0 , 2 , mp_builtin_complex );
141- #endif
142-
14399mp_obj_t mp_builtin_chr (mp_obj_t o_in ) {
144100 int ord = mp_obj_get_int (o_in );
145101 if (0 <= ord && ord <= 0x10ffff ) {
@@ -152,11 +108,6 @@ mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
152108 }
153109}
154110
155- mp_obj_t mp_builtin_dict (void ) {
156- // TODO create from an iterable!
157- return rt_build_map (0 );
158- }
159-
160111mp_obj_t mp_builtin_divmod (mp_obj_t o1_in , mp_obj_t o2_in ) {
161112 if (MP_OBJ_IS_SMALL_INT (o1_in ) && MP_OBJ_IS_SMALL_INT (o2_in )) {
162113 mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE (o1_in );
@@ -170,49 +121,13 @@ mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
170121 }
171122}
172123
173- #if MICROPY_ENABLE_FLOAT
174- static mp_obj_t mp_builtin_float (int n_args , const mp_obj_t * args ) {
175- assert (0 <= n_args && n_args <= 1 );
176-
177- if (n_args == 0 ) {
178- return mp_obj_new_float (0 );
179- } else {
180- // TODO allow string as arg and parse it
181- if (MP_OBJ_IS_TYPE (args [0 ], & float_type )) {
182- return args [0 ];
183- } else {
184- return mp_obj_new_float (mp_obj_get_float (args [0 ]));
185- }
186- }
187- }
188-
189- MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mp_builtin_float_obj , 0 , 1 , mp_builtin_float );
190- #endif
191-
192124static mp_obj_t mp_builtin_hash (mp_obj_t o_in ) {
193125 // TODO hash will generally overflow small integer; can we safely truncate it?
194126 return mp_obj_new_int (mp_obj_hash (o_in ));
195127}
196128
197129MP_DEFINE_CONST_FUN_OBJ_1 (mp_builtin_hash_obj , mp_builtin_hash );
198130
199- static mp_obj_t mp_builtin_int (int n_args , const mp_obj_t * args ) {
200- assert (0 <= n_args && n_args <= 2 );
201-
202- if (n_args == 0 ) {
203- return MP_OBJ_NEW_SMALL_INT (0 );
204- } else if (n_args == 1 ) {
205- // TODO if arg is a string then parse it
206- return mp_obj_new_int (mp_obj_get_int (args [0 ]));
207- } else { // n_args == 2
208- // TODO, parse with given base
209- assert (0 );
210- return MP_OBJ_NEW_SMALL_INT (0 );
211- }
212- }
213-
214- MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mp_builtin_int_obj , 0 , 2 , mp_builtin_int );
215-
216131static mp_obj_t mp_builtin_iter (mp_obj_t o_in ) {
217132 return rt_getiter (o_in );
218133}
@@ -241,24 +156,6 @@ mp_obj_t mp_builtin_len(mp_obj_t o_in) {
241156 return MP_OBJ_NEW_SMALL_INT (len );
242157}
243158
244- mp_obj_t mp_builtin_list (int n_args , const mp_obj_t * args ) {
245- switch (n_args ) {
246- case 0 : return rt_build_list (0 , NULL );
247- case 1 :
248- {
249- // make list from iterable
250- mp_obj_t iterable = rt_getiter (args [0 ]);
251- mp_obj_t list = rt_build_list (0 , NULL );
252- mp_obj_t item ;
253- while ((item = rt_iternext (iterable )) != mp_const_stop_iteration ) {
254- rt_list_append (list , item );
255- }
256- return list ;
257- }
258- default : nlr_jump (mp_obj_new_exception_msg_1_arg (MP_QSTR_TypeError , "list() takes at most 1 argument (%d given)" , (void * )(machine_int_t )n_args ));
259- }
260- }
261-
262159mp_obj_t mp_builtin_max (int n_args , const mp_obj_t * args ) {
263160 if (n_args == 1 ) {
264161 // given an iterable
@@ -367,26 +264,6 @@ mp_obj_t mp_builtin_range(int n_args, const mp_obj_t *args) {
367264 }
368265}
369266
370- static mp_obj_t mp_builtin_set (int n_args , const mp_obj_t * args ) {
371- assert (0 <= n_args && n_args <= 1 );
372-
373- if (n_args == 0 ) {
374- // return a new, empty set
375- return mp_obj_new_set (0 , NULL );
376- } else {
377- // 1 argument, an iterable from which we make a new set
378- mp_obj_t set = mp_obj_new_set (0 , NULL );
379- mp_obj_t iterable = rt_getiter (args [0 ]);
380- mp_obj_t item ;
381- while ((item = rt_iternext (iterable )) != mp_const_stop_iteration ) {
382- mp_obj_set_store (set , item );
383- }
384- return set ;
385- }
386- }
387-
388- MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mp_builtin_set_obj , 0 , 1 , mp_builtin_set );
389-
390267mp_obj_t mp_builtin_sum (int n_args , const mp_obj_t * args ) {
391268 mp_obj_t value ;
392269 switch (n_args ) {
@@ -405,8 +282,7 @@ mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) {
405282static mp_obj_t mp_builtin_type (mp_obj_t o_in ) {
406283 // TODO implement the 3 argument version of type()
407284 if (MP_OBJ_IS_SMALL_INT (o_in )) {
408- // TODO implement int-type
409- return mp_const_none ;
285+ return (mp_obj_t )& int_type ;
410286 } else {
411287 mp_obj_base_t * o = o_in ;
412288 return (mp_obj_t )o -> type ;
0 commit comments