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/emitbc.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/emitbc.c')
-rw-r--r-- | py/emitbc.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index fcaa9b7fae..1516b41e5b 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -224,11 +224,14 @@ STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { emit_write_code_info_qstr(emit, scope->source_file); emit_write_code_info_qstr(emit, scope->simple_name); - // bytecode prelude: exception stack size; 16 bit uint for now + // bytecode prelude: local state size and exception stack size; 16 bit uints for now { - byte* c = emit_get_cur_to_write_byte_code(emit, 2); - c[0] = scope->exc_stack_size & 0xff; - c[1] = (scope->exc_stack_size >> 8) & 0xff; + byte* c = emit_get_cur_to_write_byte_code(emit, 4); + uint n_state = scope->num_locals + scope->stack_size; + c[0] = n_state & 0xff; + c[1] = (n_state >> 8) & 0xff; + c[2] = scope->exc_stack_size & 0xff; + c[3] = (scope->exc_stack_size >> 8) & 0xff; } // bytecode prelude: initialise closed over variables |