diff options
| -rw-r--r-- | py/mpconfig.h | 4 | ||||
| -rw-r--r-- | py/runtime.c | 14 | ||||
| -rw-r--r-- | py/runtime.h | 1 | ||||
| -rw-r--r-- | py/showbc.c | 4 | ||||
| -rw-r--r-- | py/vm.c | 4 | ||||
| -rw-r--r-- | tests/basics/import2a.py | 2 | ||||
| -rw-r--r-- | tests/basics/import3a.py | 2 | ||||
| -rw-r--r-- | unix/file.c | 2 | ||||
| -rw-r--r-- | unix/main.c | 1 | ||||
| -rw-r--r-- | unix/mpconfigport.h | 5 |
10 files changed, 36 insertions, 3 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 1eb2acf53..6ff069291 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -107,6 +107,10 @@ typedef long long mp_longint_impl_t; #define MICROPY_PATH_MAX (512) #endif +// Additional builtin function definitions - see runtime.c:builtin_table for format. +#ifndef MICROPY_EXTRA_BUILTINS +#define MICROPY_EXTRA_BUILTINS +#endif /*****************************************************************************/ /* Miscellaneous settings */ diff --git a/py/runtime.c b/py/runtime.c index f12b3e612..b473a951f 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -144,6 +144,9 @@ STATIC const mp_builtin_elem_t builtin_table[] = { { MP_QSTR_str, (mp_obj_t)&mp_builtin_str_obj }, { MP_QSTR_bytearray, (mp_obj_t)&mp_builtin_bytearray_obj }, + // Extra builtins as defined by a port + MICROPY_EXTRA_BUILTINS + { MP_QSTR_, MP_OBJ_NULL }, // end of list sentinel }; @@ -1016,6 +1019,17 @@ mp_obj_t rt_import_from(mp_obj_t module, qstr name) { return x; } +void rt_import_all(mp_obj_t module) { + DEBUG_printf("import all %p\n", module); + + mp_map_t *map = mp_obj_module_get_globals(module); + for (uint i = 0; i < map->alloc; i++) { + if (map->table[i].key != MP_OBJ_NULL) { + rt_store_name(MP_OBJ_QSTR_VALUE(map->table[i].key), map->table[i].value); + } + } +} + mp_map_t *rt_locals_get(void) { return map_locals; } diff --git a/py/runtime.h b/py/runtime.h index 20595c6a5..f5a9f2abc 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -39,6 +39,7 @@ mp_obj_t rt_getiter(mp_obj_t o); mp_obj_t rt_iternext(mp_obj_t o); mp_obj_t rt_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level); mp_obj_t rt_import_from(mp_obj_t module, qstr name); +void rt_import_all(mp_obj_t module); struct _mp_map_t; struct _mp_map_t *rt_locals_get(void); diff --git a/py/showbc.c b/py/showbc.c index 9dfbc8872..e3387dbe2 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -390,6 +390,10 @@ void mp_byte_code_print(const byte *ip, int len) { printf("IMPORT_FROM %s", qstr_str(qstr)); break; + case MP_BC_IMPORT_STAR: + printf("IMPORT_STAR"); + break; + default: printf("code %p, byte code 0x%02x not implemented\n", ip, op); assert(0); @@ -595,6 +595,10 @@ unwind_return: PUSH(obj1); break; + case MP_BC_IMPORT_STAR: + rt_import_all(POP()); + break; + default: printf("code %p, byte code 0x%02x not implemented\n", ip, op); assert(0); diff --git a/tests/basics/import2a.py b/tests/basics/import2a.py new file mode 100644 index 000000000..ce32b10b1 --- /dev/null +++ b/tests/basics/import2a.py @@ -0,0 +1,2 @@ +from import1b import var +print(var) diff --git a/tests/basics/import3a.py b/tests/basics/import3a.py new file mode 100644 index 000000000..2e9d41f71 --- /dev/null +++ b/tests/basics/import3a.py @@ -0,0 +1,2 @@ +from import1b import * +print(var) diff --git a/unix/file.c b/unix/file.c index 0d11de633..21dd76474 100644 --- a/unix/file.c +++ b/unix/file.c @@ -136,8 +136,6 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open); void file_init() { - rt_store_name(MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj); - mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys); rt_store_attr(m_sys, MP_QSTR_stdin, fdfile_new(STDIN_FILENO)); rt_store_attr(m_sys, MP_QSTR_stdout, fdfile_new(STDOUT_FILENO)); diff --git a/unix/main.c b/unix/main.c index 192a0e6e8..716c7b114 100644 --- a/unix/main.c +++ b/unix/main.c @@ -29,7 +29,6 @@ // Stack top at the start of program void *stack_top; -extern const mp_obj_fun_native_t mp_builtin_open_obj; void file_init(); void microsocket_init(); void time_init(); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index dc9297010..5b2503f4d 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -36,3 +36,8 @@ typedef const void *machine_const_ptr_t; // must be of pointer size typedef double machine_float_t; machine_float_t machine_sqrt(machine_float_t x); + +struct _mp_obj_fun_native_t; +extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; +#define MICROPY_EXTRA_BUILTINS \ + { MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj }, |
