@@ -517,28 +517,6 @@ typedef mp_uint_t (*viper_fun_1_t)(mp_uint_t);
517517typedef mp_uint_t (* viper_fun_2_t )(mp_uint_t , mp_uint_t );
518518typedef mp_uint_t (* viper_fun_3_t )(mp_uint_t , mp_uint_t , mp_uint_t );
519519
520- // convert a Micro Python object to a valid value for viper, based on wanted type
521- STATIC mp_uint_t convert_obj_for_viper (mp_obj_t obj , mp_uint_t type ) {
522- switch (type & 3 ) {
523- case MP_NATIVE_TYPE_OBJ : return (mp_uint_t )obj ;
524- case MP_NATIVE_TYPE_BOOL :
525- case MP_NATIVE_TYPE_INT :
526- case MP_NATIVE_TYPE_UINT : return mp_obj_get_int (obj );
527- default : assert (0 ); return 0 ;
528- }
529- }
530-
531- // convert a return value from viper to a Micro Python object based on viper return type
532- STATIC mp_obj_t convert_val_from_viper (mp_uint_t val , mp_uint_t type ) {
533- switch (type & 3 ) {
534- case MP_NATIVE_TYPE_OBJ : return (mp_obj_t )val ;
535- case MP_NATIVE_TYPE_BOOL : return MP_BOOL (val );
536- case MP_NATIVE_TYPE_INT : return mp_obj_new_int (val );
537- case MP_NATIVE_TYPE_UINT : return mp_obj_new_int_from_uint (val );
538- default : assert (0 ); return mp_const_none ;
539- }
540- }
541-
542520STATIC mp_obj_t fun_viper_call (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
543521 mp_obj_fun_viper_t * self = self_in ;
544522
@@ -548,17 +526,17 @@ STATIC mp_obj_t fun_viper_call(mp_obj_t self_in, uint n_args, uint n_kw, const m
548526 if (n_args == 0 ) {
549527 ret = ((viper_fun_0_t )self -> fun )();
550528 } else if (n_args == 1 ) {
551- ret = ((viper_fun_1_t )self -> fun )(convert_obj_for_viper (args [0 ], self -> type_sig >> 2 ));
529+ ret = ((viper_fun_1_t )self -> fun )(mp_convert_obj_to_native (args [0 ], self -> type_sig >> 2 ));
552530 } else if (n_args == 2 ) {
553- ret = ((viper_fun_2_t )self -> fun )(convert_obj_for_viper (args [0 ], self -> type_sig >> 2 ), convert_obj_for_viper (args [1 ], self -> type_sig >> 4 ));
531+ ret = ((viper_fun_2_t )self -> fun )(mp_convert_obj_to_native (args [0 ], self -> type_sig >> 2 ), mp_convert_obj_to_native (args [1 ], self -> type_sig >> 4 ));
554532 } else if (n_args == 3 ) {
555- ret = ((viper_fun_3_t )self -> fun )(convert_obj_for_viper (args [0 ], self -> type_sig >> 2 ), convert_obj_for_viper (args [1 ], self -> type_sig >> 4 ), convert_obj_for_viper (args [2 ], self -> type_sig >> 6 ));
533+ ret = ((viper_fun_3_t )self -> fun )(mp_convert_obj_to_native (args [0 ], self -> type_sig >> 2 ), mp_convert_obj_to_native (args [1 ], self -> type_sig >> 4 ), mp_convert_obj_to_native (args [2 ], self -> type_sig >> 6 ));
556534 } else {
557535 assert (0 );
558536 ret = 0 ;
559537 }
560538
561- return convert_val_from_viper (ret , self -> type_sig );
539+ return mp_convert_native_to_obj (ret , self -> type_sig );
562540}
563541
564542STATIC const mp_obj_type_t mp_type_fun_viper = {
0 commit comments