summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/bc.h2
-rw-r--r--py/builtinimport.c4
-rw-r--r--py/compile.c29
-rw-r--r--py/compile.h2
-rw-r--r--py/persistentcode.c28
-rw-r--r--py/persistentcode.h6
6 files changed, 33 insertions, 38 deletions
diff --git a/py/bc.h b/py/bc.h
index 6350eee52e..0e23255f76 100644
--- a/py/bc.h
+++ b/py/bc.h
@@ -214,7 +214,7 @@ typedef struct _mp_module_context_t {
// Outer level struct defining a compiled module.
typedef struct _mp_compiled_module_t {
- const mp_module_context_t *context;
+ mp_module_context_t *context;
const struct _mp_raw_code_t *rc;
#if MICROPY_PERSISTENT_CODE_SAVE
bool has_native;
diff --git a/py/builtinimport.c b/py/builtinimport.c
index aa31b69db9..6f1f7b485f 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -245,7 +245,9 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) {
// the correct format and, if so, load and execute the file.
#if MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD
if (file_str[file->len - 3] == 'm') {
- mp_compiled_module_t cm = mp_raw_code_load_file(file_str, module_obj);
+ mp_compiled_module_t cm;
+ cm.context = module_obj;
+ mp_raw_code_load_file(file_str, &cm);
do_execute_raw_code(cm.context, cm.rc, file_str);
return;
}
diff --git a/py/compile.c b/py/compile.c
index 8aaf885327..76d4c1bf5a 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -3427,7 +3427,7 @@ STATIC void scope_compute_things(scope_t *scope) {
#if !MICROPY_PERSISTENT_CODE_SAVE
STATIC
#endif
-mp_compiled_module_t mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_module_context_t *context) {
+void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_compiled_module_t *cm) {
// put compiler state on the stack, it's relatively small
compiler_t comp_state = {0};
compiler_t *comp = &comp_state;
@@ -3568,26 +3568,24 @@ mp_compiled_module_t mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr so
}
// construct the global qstr/const table for this module
- mp_compiled_module_t cm;
- cm.rc = module_scope->raw_code;
- cm.context = context;
+ cm->rc = module_scope->raw_code;
#if MICROPY_PERSISTENT_CODE_SAVE
- cm.has_native = false;
+ cm->has_native = false;
#if MICROPY_EMIT_NATIVE
if (emit_native != NULL) {
- cm.has_native = true;
+ cm->has_native = true;
}
#endif
#if MICROPY_EMIT_INLINE_ASM
if (comp->emit_inline_asm != NULL) {
- cm.has_native = true;
+ cm->has_native = true;
}
#endif
- cm.n_qstr = comp->emit_common.qstr_map.used;
- cm.n_obj = comp->emit_common.const_obj_list.len;
+ cm->n_qstr = comp->emit_common.qstr_map.used;
+ cm->n_obj = comp->emit_common.const_obj_list.len;
#endif
if (comp->compile_error == MP_OBJ_NULL) {
- mp_emit_common_populate_module_context(&comp->emit_common, source_file, context);
+ mp_emit_common_populate_module_context(&comp->emit_common, source_file, cm->context);
#if MICROPY_DEBUG_PRINTERS
// now that the module context is valid, the raw codes can be printed
@@ -3595,7 +3593,7 @@ mp_compiled_module_t mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr so
for (scope_t *s = comp->scope_head; s != NULL; s = s->next) {
mp_raw_code_t *rc = s->raw_code;
if (rc->kind == MP_CODE_BYTECODE) {
- mp_bytecode_print(&mp_plat_print, rc, &cm.context->constants);
+ mp_bytecode_print(&mp_plat_print, rc, &cm->context->constants);
}
}
}
@@ -3629,14 +3627,13 @@ mp_compiled_module_t mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr so
if (comp->compile_error != MP_OBJ_NULL) {
nlr_raise(comp->compile_error);
}
-
- return cm;
}
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) {
- mp_module_context_t *context = m_new_obj(mp_module_context_t);
- context->module.globals = mp_globals_get();
- mp_compiled_module_t cm = mp_compile_to_raw_code(parse_tree, source_file, is_repl, context);
+ mp_compiled_module_t cm;
+ cm.context = m_new_obj(mp_module_context_t);
+ cm.context->module.globals = mp_globals_get();
+ mp_compile_to_raw_code(parse_tree, source_file, is_repl, &cm);
// return function that executes the outer module
return mp_make_function_from_raw_code(cm.rc, cm.context, NULL);
}
diff --git a/py/compile.h b/py/compile.h
index ae87bf2a04..5e0fd8b31c 100644
--- a/py/compile.h
+++ b/py/compile.h
@@ -37,7 +37,7 @@ mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl)
#if MICROPY_PERSISTENT_CODE_SAVE
// this has the same semantics as mp_compile
-mp_compiled_module_t mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_module_context_t *globals);
+void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_compiled_module_t *cm);
#endif
// this is implemented in runtime.c
diff --git a/py/persistentcode.c b/py/persistentcode.c
index 5408f756cf..fdc87d5cc8 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -390,7 +390,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *co
return rc;
}
-mp_compiled_module_t mp_raw_code_load(mp_reader_t *reader, mp_module_context_t *context) {
+void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) {
byte header[4];
read_bytes(reader, header, sizeof(header));
byte arch = MPY_FEATURE_DECODE_ARCH(header[2]);
@@ -414,46 +414,42 @@ mp_compiled_module_t mp_raw_code_load(mp_reader_t *reader, mp_module_context_t *
size_t n_qstr = read_uint(reader);
size_t n_obj = read_uint(reader);
- mp_module_context_alloc_tables(context, n_qstr, n_obj);
+ mp_module_context_alloc_tables(cm->context, n_qstr, n_obj);
// Load qstrs.
for (size_t i = 0; i < n_qstr; ++i) {
- context->constants.qstr_table[i] = load_qstr(reader);
+ cm->context->constants.qstr_table[i] = load_qstr(reader);
}
// Load constant objects.
for (size_t i = 0; i < n_obj; ++i) {
- context->constants.obj_table[i] = load_obj(reader);
+ cm->context->constants.obj_table[i] = load_obj(reader);
}
// Load top-level module.
- mp_compiled_module_t cm2;
- cm2.rc = load_raw_code(reader, context);
- cm2.context = context;
+ cm->rc = load_raw_code(reader, cm->context);
#if MICROPY_PERSISTENT_CODE_SAVE
- cm2.has_native = MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE;
- cm2.n_qstr = n_qstr;
- cm2.n_obj = n_obj;
+ cm->has_native = MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE;
+ cm->n_qstr = n_qstr;
+ cm->n_obj = n_obj;
#endif
reader->close(reader->data);
-
- return cm2;
}
-mp_compiled_module_t mp_raw_code_load_mem(const byte *buf, size_t len, mp_module_context_t *context) {
+void mp_raw_code_load_mem(const byte *buf, size_t len, mp_compiled_module_t *context) {
mp_reader_t reader;
mp_reader_new_mem(&reader, buf, len, 0);
- return mp_raw_code_load(&reader, context);
+ mp_raw_code_load(&reader, context);
}
#if MICROPY_HAS_FILE_READER
-mp_compiled_module_t mp_raw_code_load_file(const char *filename, mp_module_context_t *context) {
+void mp_raw_code_load_file(const char *filename, mp_compiled_module_t *context) {
mp_reader_t reader;
mp_reader_new_file(&reader, filename);
- return mp_raw_code_load(&reader, context);
+ mp_raw_code_load(&reader, context);
}
#endif // MICROPY_HAS_FILE_READER
diff --git a/py/persistentcode.h b/py/persistentcode.h
index e664358737..d363f544ad 100644
--- a/py/persistentcode.h
+++ b/py/persistentcode.h
@@ -111,9 +111,9 @@ enum {
MP_PERSISTENT_OBJ_TUPLE,
};
-mp_compiled_module_t mp_raw_code_load(mp_reader_t *reader, mp_module_context_t *ctx);
-mp_compiled_module_t mp_raw_code_load_mem(const byte *buf, size_t len, mp_module_context_t *ctx);
-mp_compiled_module_t mp_raw_code_load_file(const char *filename, mp_module_context_t *ctx);
+void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *ctx);
+void mp_raw_code_load_mem(const byte *buf, size_t len, mp_compiled_module_t *ctx);
+void mp_raw_code_load_file(const char *filename, mp_compiled_module_t *ctx);
void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print);
void mp_raw_code_save_file(mp_compiled_module_t *cm, const char *filename);