|
34 | 34 | #include "py/mphal.h" |
35 | 35 | #include "py/objmodule.h" |
36 | 36 | #include "py/persistentcode.h" |
| 37 | +#include "py/reader.h" |
37 | 38 | #include "py/repl.h" |
38 | 39 | #include "py/runtime.h" |
39 | 40 | #include "py/stackctrl.h" |
@@ -74,35 +75,6 @@ bool pbsys_main_stdin_event(uint8_t c) { |
74 | 75 | return false; |
75 | 76 | } |
76 | 77 |
|
77 | | -// The following defines a reader for use by micropython/py/persistentcode.c. |
78 | | -typedef struct _mp_vfs_map_minimal_t { |
79 | | - const byte *cur; |
80 | | - const byte *end; |
81 | | -} mp_vfs_map_minimal_t; |
82 | | - |
83 | | -mp_uint_t mp_vfs_map_minimal_readbyte(void *data) { |
84 | | - mp_vfs_map_minimal_t *blob = (mp_vfs_map_minimal_t *)data; |
85 | | - return (blob->cur < blob->end) ? *blob->cur++ : MP_READER_EOF; |
86 | | -} |
87 | | - |
88 | | -const uint8_t *mp_vfs_map_minimal_read_bytes(mp_reader_t *reader, size_t len) { |
89 | | - mp_vfs_map_minimal_t *blob = (mp_vfs_map_minimal_t *)reader->data; |
90 | | - const uint8_t *ptr = blob->cur; |
91 | | - blob->cur += len; |
92 | | - return ptr; |
93 | | -} |
94 | | - |
95 | | -static void mp_vfs_map_minimal_close(void *data) { |
96 | | -} |
97 | | - |
98 | | -static void mp_vfs_map_minimal_new_reader(mp_reader_t *reader, mp_vfs_map_minimal_t *data, const byte *buf, size_t len) { |
99 | | - data->cur = buf; |
100 | | - data->end = buf + len; |
101 | | - reader->data = data; |
102 | | - reader->readbyte = mp_vfs_map_minimal_readbyte; |
103 | | - reader->close = mp_vfs_map_minimal_close; |
104 | | -} |
105 | | - |
106 | 78 | // Prints the exception that ended the program. |
107 | 79 | static void print_final_exception(mp_obj_t exc, int ret) { |
108 | 80 | nlr_buf_t nlr; |
@@ -270,8 +242,7 @@ static void run_user_program(void) { |
270 | 242 |
|
271 | 243 | // This is similar to __import__ except we don't push/pop globals |
272 | 244 | mp_reader_t reader; |
273 | | - mp_vfs_map_minimal_t data; |
274 | | - mp_vfs_map_minimal_new_reader(&reader, &data, mpy_data_get_buf(info), pbio_get_uint32_le(info->mpy_size)); |
| 245 | + mp_reader_new_mem(&reader, mpy_data_get_buf(info), pbio_get_uint32_le(info->mpy_size), MP_READER_IS_ROM); |
275 | 246 | mp_module_context_t *context = m_new_obj(mp_module_context_t); |
276 | 247 | context->module.globals = mp_globals_get(); |
277 | 248 | mp_compiled_module_t compiled_module; |
@@ -472,8 +443,7 @@ mp_obj_t pb_builtin_import(size_t n_args, const mp_obj_t *args) { |
472 | 443 | if (info) { |
473 | 444 | // Parse the static script data. |
474 | 445 | mp_reader_t reader; |
475 | | - mp_vfs_map_minimal_t data; |
476 | | - mp_vfs_map_minimal_new_reader(&reader, &data, mpy_data_get_buf(info), pbio_get_uint32_le(info->mpy_size)); |
| 446 | + mp_reader_new_mem(&reader, mpy_data_get_buf(info), pbio_get_uint32_le(info->mpy_size), MP_READER_IS_ROM); |
477 | 447 |
|
478 | 448 | // Create new module and execute in its own context. |
479 | 449 | mp_obj_t module_obj = mp_obj_new_module(module_name_qstr); |
|
0 commit comments