diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-27 11:07:04 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-27 11:07:04 +0000 |
commit | bee17b00e38ffc005a4247cb00ab01eb40162a2d (patch) | |
tree | 856c12181e8b16a9d0e40868623f5932b9bb8df7 /py/objgenerator.c | |
parent | 8dcc0c79248a413f01f1d669b99d51e2519c5267 (diff) |
py: Put n_state for bytecode in the bytecode prelude.
Rationale: setting up the stack (state for locals and exceptions) is
really part of the "code", it's the prelude of the function. For
example, native code adjusts the stack pointer on entry to the function.
Native code doesn't need to know n_state for any other reason. So
putting the state size in the bytecode prelude is sensible.
It reduced ROM usage on STM by about 30 bytes :) And makes it easier to
pass information about the bytecode between functions.
Diffstat (limited to 'py/objgenerator.c')
-rw-r--r-- | py/objgenerator.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/py/objgenerator.c b/py/objgenerator.c index 29ef4e235..aeb5f6219 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -24,9 +24,8 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp mp_obj_t self_fun = self->fun; assert(MP_OBJ_IS_TYPE(self_fun, &fun_bc_type)); int bc_n_args; - uint bc_n_state; const byte *bc_code; - mp_obj_fun_bc_get(self_fun, &bc_n_args, &bc_n_state, &bc_code); + mp_obj_fun_bc_get(self_fun, &bc_n_args, &bc_code); if (n_args != bc_n_args) { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", bc_n_args, n_args)); } @@ -34,7 +33,7 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments")); } - return mp_obj_new_gen_instance(bc_code, bc_n_state, n_args, args); + return mp_obj_new_gen_instance(bc_code, n_args, args); } const mp_obj_type_t gen_wrap_type = { @@ -210,14 +209,15 @@ const mp_obj_type_t gen_instance_type = { .locals_dict = (mp_obj_t)&gen_instance_locals_dict, }; -mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, uint n_state, int n_args, const mp_obj_t *args) { +mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, int n_args, const mp_obj_t *args) { // get code info size, and skip the line number table machine_uint_t code_info_size = bytecode[0] | (bytecode[1] << 8) | (bytecode[2] << 16) | (bytecode[3] << 24); bytecode += code_info_size; - // bytecode prelude: get exception stack size - machine_uint_t n_exc_stack = bytecode[0] | (bytecode[1] << 8); - bytecode += 2; + // bytecode prelude: get state size and exception stack size + machine_uint_t n_state = bytecode[0] | (bytecode[1] << 8); + machine_uint_t n_exc_stack = bytecode[2] | (bytecode[3] << 8); + bytecode += 4; // bytecode prelude: initialise closed over variables // TODO |