summaryrefslogtreecommitdiff
path: root/py/emitnative.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 99eac7925..d8f1640c0 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -567,6 +567,7 @@ struct _emit_t {
vtype_kind_t saved_stack_vtype;
int prelude_offset;
+ int const_table_offset;
int n_state;
int stack_start;
int stack_size;
@@ -828,7 +829,24 @@ STATIC void emit_native_end_pass(emit_t *emit) {
ASM_DATA(emit->as, 1, emit->scope->num_pos_args);
ASM_DATA(emit->as, 1, emit->scope->num_kwonly_args);
ASM_DATA(emit->as, 1, emit->scope->num_def_pos_args);
+
+ // write code info (just contains block name and source file)
+ ASM_DATA(emit->as, 1, 5);
+ ASM_DATA(emit->as, 2, emit->scope->simple_name);
+ ASM_DATA(emit->as, 2, emit->scope->source_file);
+
+ // bytecode prelude: initialise closed over variables
+ for (int i = 0; i < emit->scope->id_info_len; i++) {
+ id_info_t *id = &emit->scope->id_info[i];
+ if (id->kind == ID_INFO_KIND_CELL) {
+ assert(id->local_num < 255);
+ ASM_DATA(emit->as, 1, id->local_num); // write the local which should be converted to a cell
+ }
+ }
+ ASM_DATA(emit->as, 1, 255); // end of list sentinel
+
ASM_ALIGN(emit->as, ASM_WORD_SIZE);
+ emit->const_table_offset = ASM_GET_CODE_POS(emit->as);
// write argument names as qstr objects
// see comment in corresponding part of emitbc.c about the logic here
@@ -844,18 +862,6 @@ STATIC void emit_native_end_pass(emit_t *emit) {
ASM_DATA(emit->as, ASM_WORD_SIZE, (mp_uint_t)MP_OBJ_NEW_QSTR(qst));
}
- // write dummy code info (for mp_setup_code_state to parse)
- ASM_DATA(emit->as, 1, 1);
-
- // bytecode prelude: initialise closed over variables
- for (int i = 0; i < emit->scope->id_info_len; i++) {
- id_info_t *id = &emit->scope->id_info[i];
- if (id->kind == ID_INFO_KIND_CELL) {
- assert(id->local_num < 255);
- ASM_DATA(emit->as, 1, id->local_num); // write the local which should be converted to a cell
- }
- }
- ASM_DATA(emit->as, 1, 255); // end of list sentinel
}
ASM_END_PASS(emit->as);
@@ -878,7 +884,8 @@ STATIC void emit_native_end_pass(emit_t *emit) {
mp_emit_glue_assign_native(emit->scope->raw_code,
emit->do_viper_types ? MP_CODE_NATIVE_VIPER : MP_CODE_NATIVE_PY,
- f, f_len, emit->scope->num_pos_args, emit->scope->scope_flags, type_sig);
+ f, f_len, (mp_uint_t*)((byte*)f + emit->const_table_offset),
+ emit->scope->num_pos_args, emit->scope->scope_flags, type_sig);
}
}