Commit dcac8809 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

Add empty "micropython" module to allow more seamless CPython portability.

Implicit "micropython" module contains (at least) codegeneration decorators.
Make it explicit, so an app could have "import micropython". On MicroPython,
that will be no-op. On CPython, that will give a chance to have a module
with placeholder decorators.
parent c8742a06
......@@ -85,6 +85,14 @@ typedef long long mp_longint_impl_t;
#define MICROPY_ENABLE_SLICE (1)
#endif
// Enable features which improve CPython compatibility
// but may lead to more code size/memory usage.
// TODO: Originally intended as generic category to not
// add bunch of once-off options. May need refactoring later
#ifndef MICROPY_CPYTHON_COMPAT
#define MICROPY_CPYTHON_COMPAT (1)
#endif
/*****************************************************************************/
/* Miscellaneous settings */
......
......@@ -143,6 +143,13 @@ void rt_init(void) {
mp_map_add_qstr(&map_builtins, MP_QSTR_sum, (mp_obj_t)&mp_builtin_sum_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_str, (mp_obj_t)&mp_builtin_str_obj);
#if MICROPY_CPYTHON_COMPAT
// Add (empty) micropython module, so it was possible to "import micropython",
// which can be a placeholder module on CPython.
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("micropython"));
rt_store_name(qstr_from_str_static("micropython"), m);
#endif
next_unique_code_id = 1; // 0 indicates "no code"
unique_codes_alloc = 0;
unique_codes = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment