From 91d457a27752fa125e9c6107bf51c918e021dc95 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 20 Jan 2014 10:30:24 +0000 Subject: [PATCH] py: Put micropython module init code in builtinmp.c. --- py/builtin.h | 4 +--- py/builtinmp.c | 19 ++++++++++++++++--- py/runtime.c | 8 +------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/py/builtin.h b/py/builtin.h index ca5c8a52d8..050a2161c1 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -27,6 +27,4 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sorted_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sum_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_str_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_mem_total_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_mem_current_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_mem_peak_obj); +void mp_module_micropython_init(void); diff --git a/py/builtinmp.c b/py/builtinmp.c index bbfdab0d57..f72a80f1a8 100644 --- a/py/builtinmp.c +++ b/py/builtinmp.c @@ -7,7 +7,9 @@ #include "misc.h" #include "mpconfig.h" +#include "mpqstr.h" #include "obj.h" +#include "runtime.h" #include "builtin.h" // Various builtins specific to MicroPython runtime, @@ -15,18 +17,29 @@ #if MICROPY_MEM_STATS static mp_obj_t mem_total() { - return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated()); + return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_total_bytes_allocated()); } static mp_obj_t mem_current() { - return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated()); + return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_current_bytes_allocated()); } static mp_obj_t mem_peak() { - return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated()); + return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_peak_bytes_allocated()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_mem_total_obj, mem_total); MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_mem_current_obj, mem_current); MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_mem_peak_obj, mem_peak); #endif + +void mp_module_micropython_init(void) { + mp_obj_t m_mp = mp_obj_new_module(MP_QSTR_micropython); + rt_store_name(MP_QSTR_micropython, m_mp); + +#if MICROPY_MEM_STATS + rt_store_attr(m_mp, qstr_from_str_static("mem_total"), (mp_obj_t)&mp_builtin_mem_total_obj); + rt_store_attr(m_mp, qstr_from_str_static("mem_current"), (mp_obj_t)&mp_builtin_mem_current_obj); + rt_store_attr(m_mp, qstr_from_str_static("mem_peak"), (mp_obj_t)&mp_builtin_mem_peak_obj); +#endif +} diff --git a/py/runtime.c b/py/runtime.c index 09e4237aff..d8fc3ff6e4 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -157,13 +157,7 @@ void rt_init(void) { mp_obj_new_module(qstr_from_str_static("sys")); #endif - mp_obj_t m_mp = mp_obj_new_module(qstr_from_str_static("micropython")); - rt_store_name(qstr_from_str_static("micropython"), m_mp); -#if MICROPY_MEM_STATS - rt_store_attr(m_mp, qstr_from_str_static("mem_total"), (mp_obj_t)&mp_builtin_mem_total_obj); - rt_store_attr(m_mp, qstr_from_str_static("mem_current"), (mp_obj_t)&mp_builtin_mem_current_obj); - rt_store_attr(m_mp, qstr_from_str_static("mem_peak"), (mp_obj_t)&mp_builtin_mem_peak_obj); -#endif + mp_module_micropython_init(); next_unique_code_id = 1; // 0 indicates "no code" unique_codes_alloc = 0;