mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py: Add constant table to bytecode.
Contains just argument names at the moment but makes it easy to add arbitrary constants.
This commit is contained in:
13
py/objfun.c
13
py/objfun.c
@@ -126,11 +126,9 @@ qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) {
|
||||
mp_decode_uint(&bc); // skip n_state
|
||||
mp_decode_uint(&bc); // skip n_exc_stack
|
||||
bc++; // skip scope_params
|
||||
mp_uint_t n_pos_args = *bc++;
|
||||
mp_uint_t n_kwonly_args = *bc++;
|
||||
bc++; // skip n_pos_args
|
||||
bc++; // skip n_kwonly_args
|
||||
bc++; // skip n_def_pos_args
|
||||
bc = MP_ALIGN(bc, sizeof(mp_uint_t)); // align
|
||||
bc += (n_pos_args + n_kwonly_args) * sizeof(mp_uint_t); // skip arg names
|
||||
return mp_obj_code_get_name(bc);
|
||||
}
|
||||
|
||||
@@ -320,7 +318,7 @@ const mp_obj_type_t mp_type_fun_bc = {
|
||||
#endif
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code) {
|
||||
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table) {
|
||||
mp_uint_t n_def_args = 0;
|
||||
mp_uint_t n_extra_args = 0;
|
||||
mp_obj_tuple_t *def_args = def_args_in;
|
||||
@@ -336,6 +334,7 @@ mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byt
|
||||
o->base.type = &mp_type_fun_bc;
|
||||
o->globals = mp_globals_get();
|
||||
o->bytecode = code;
|
||||
o->const_table = const_table;
|
||||
if (def_args != MP_OBJ_NULL) {
|
||||
memcpy(o->extra_args, def_args->items, n_def_args * sizeof(mp_obj_t));
|
||||
}
|
||||
@@ -364,8 +363,8 @@ STATIC const mp_obj_type_t mp_type_fun_native = {
|
||||
.unary_op = mp_generic_unary_op,
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data) {
|
||||
mp_obj_fun_bc_t *o = mp_obj_new_fun_bc(def_args_in, def_kw_args, (const byte*)fun_data);
|
||||
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table) {
|
||||
mp_obj_fun_bc_t *o = mp_obj_new_fun_bc(def_args_in, def_kw_args, (const byte*)fun_data, const_table);
|
||||
o->base.type = &mp_type_fun_native;
|
||||
return o;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user