diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-08 15:24:39 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-08 15:24:39 +0000 |
commit | 0c36da0b59bd3d5aeb6f7bd7f75913695a1dd366 (patch) | |
tree | eb1d8e50037139646f935df99da56764fcafb4f1 /py/builtin.c | |
parent | 8fd7d7e102372a3fe067030aa0f2049f744b1567 (diff) |
Implement ROMable modules. Add math module.
mp_module_obj_t can now be put in ROM.
Configuration of float type is now similar to longint: can now choose
none, float or double as the implementation.
math module has basic math functions. For STM port, these are not yet
implemented (they are just stub functions).
Diffstat (limited to 'py/builtin.c')
-rw-r--r-- | py/builtin.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/py/builtin.c b/py/builtin.c index ef9e70c94..df488e054 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -15,6 +15,10 @@ #include "map.h" #include "builtin.h" +#if MICROPY_ENABLE_FLOAT +#include <math.h> +#endif + // args[0] is function from class body // args[1] is class name // args[2:] are base objects @@ -79,7 +83,7 @@ mp_obj_t mp_builtin_abs(mp_obj_t o_in) { } return MP_OBJ_NEW_SMALL_INT(val); #if MICROPY_ENABLE_FLOAT - } else if (MP_OBJ_IS_TYPE(o_in, &float_type)) { + } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_float)) { mp_float_t value = mp_obj_float_get(o_in); // TODO check for NaN etc if (value < 0) { @@ -87,10 +91,10 @@ mp_obj_t mp_builtin_abs(mp_obj_t o_in) { } else { return o_in; } - } else if (MP_OBJ_IS_TYPE(o_in, &complex_type)) { + } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) { mp_float_t real, imag; mp_obj_complex_get(o_in, &real, &imag); - return mp_obj_new_float(machine_sqrt(real*real + imag*imag)); + return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag)); #endif } else { assert(0); @@ -158,7 +162,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) { } else { // n_args == 1 // make a list of names in the given object mp_obj_type_t *type = mp_obj_get_type(args[0]); - if (type == &module_type) { + if (type == &mp_type_module) { map = mp_obj_module_get_globals(args[0]); } else if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)) { map = mp_obj_dict_get_map(type->locals_dict); |