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/vm.c | |
parent | 8dcc0c79248a413f01f1d669b99d51e2519c5267 (diff) | |
download | micropython-bee17b00e38ffc005a4247cb00ab01eb40162a2d.tar.gz micropython-bee17b00e38ffc005a4247cb00ab01eb40162a2d.zip |
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/vm.c')
-rw-r--r-- | py/vm.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -44,16 +44,17 @@ typedef enum { #define TOP() (*sp) #define SET_TOP(val) *sp = (val) -mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, uint n_state, mp_obj_t *ret) { +mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret) { const byte *ip = code; // get code info size, and skip line number table machine_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24); ip += code_info_size; - // bytecode prelude: exception stack size; 16 bit uint for now - machine_uint_t n_exc_stack = ip[0] | (ip[1] << 8); - ip += 2; + // bytecode prelude: state size and exception stack size; 16 bit uints + machine_uint_t n_state = ip[0] | (ip[1] << 8); + machine_uint_t n_exc_stack = ip[2] | (ip[3] << 8); + ip += 4; // allocate state for locals and stack mp_obj_t temp_state[10]; |