py/emitglue: Remove union in mp_raw_code_t to combine bytecode & native.

This commit is contained in:
Damien George
2019-02-19 14:15:39 +11:00
parent 3986820912
commit 636ed0ff8d
4 changed files with 39 additions and 47 deletions

View File

@@ -67,12 +67,12 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
rc->kind = MP_CODE_BYTECODE;
rc->scope_flags = scope_flags;
rc->data.u_byte.bytecode = code;
rc->data.u_byte.const_table = const_table;
rc->fun_data = code;
rc->const_table = const_table;
#if MICROPY_PERSISTENT_CODE_SAVE
rc->data.u_byte.bc_len = len;
rc->data.u_byte.n_obj = n_obj;
rc->data.u_byte.n_raw_code = n_raw_code;
rc->fun_data_len = len;
rc->n_obj = n_obj;
rc->n_raw_code = n_raw_code;
#endif
#ifdef DEBUG_PRINT
@@ -94,9 +94,9 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
rc->kind = kind;
rc->scope_flags = scope_flags;
rc->n_pos_args = n_pos_args;
rc->data.u_native.fun_data = fun_data;
rc->data.u_native.const_table = const_table;
rc->data.u_native.type_sig = type_sig;
rc->fun_data = fun_data;
rc->const_table = const_table;
rc->type_sig = type_sig;
#ifdef DEBUG_PRINT
DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, n_pos_args, (uint)scope_flags);
@@ -135,7 +135,7 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
#if MICROPY_EMIT_NATIVE
case MP_CODE_NATIVE_PY:
case MP_CODE_NATIVE_VIPER:
fun = mp_obj_new_fun_native(def_args, def_kw_args, rc->data.u_native.fun_data, rc->data.u_native.const_table);
fun = mp_obj_new_fun_native(def_args, def_kw_args, rc->fun_data, rc->const_table);
// Check for a generator function, and if so change the type of the object
if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) {
((mp_obj_base_t*)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_gen_wrap;
@@ -144,13 +144,13 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
#endif
#if MICROPY_EMIT_INLINE_ASM
case MP_CODE_NATIVE_ASM:
fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->data.u_native.fun_data, rc->data.u_native.type_sig);
fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->fun_data, rc->type_sig);
break;
#endif
default:
// rc->kind should always be set and BYTECODE is the only remaining case
assert(rc->kind == MP_CODE_BYTECODE);
fun = mp_obj_new_fun_bc(def_args, def_kw_args, rc->data.u_byte.bytecode, rc->data.u_byte.const_table);
fun = mp_obj_new_fun_bc(def_args, def_kw_args, rc->fun_data, rc->const_table);
// check for generator functions and if so change the type of the object
if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) {
((mp_obj_base_t*)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap;