summaryrefslogtreecommitdiffstatshomepage
path: root/py/objfun.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-10-23 01:23:11 +0100
committerDamien George <damien.p.george@gmail.com>2015-11-13 12:49:18 +0000
commit713ea1800d1f0c82a0c75885ad034705556ab5ef (patch)
treeac865eaf1d258007dbd6718d972967886d9a39e8 /py/objfun.c
parent3a3db4dcf0400cffef860f61a84979cb1f7a7541 (diff)
downloadmicropython-713ea1800d1f0c82a0c75885ad034705556ab5ef.tar.gz
micropython-713ea1800d1f0c82a0c75885ad034705556ab5ef.zip
py: Add constant table to bytecode.
Contains just argument names at the moment but makes it easy to add arbitrary constants.
Diffstat (limited to 'py/objfun.c')
-rw-r--r--py/objfun.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/py/objfun.c b/py/objfun.c
index a54e50d2cd..f55d44ca29 100644
--- a/py/objfun.c
+++ b/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;
}