diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-14 00:20:28 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-14 00:20:28 +0000 |
commit | 1e1779eacf4da5cd8699bee26a02eed4eda10101 (patch) | |
tree | aac00790c5ae0b2fbd0848b595c3273c7c674fce /py/compile.c | |
parent | 2127e9a844ae46cb2149e7c38eb9f4345075f6e4 (diff) | |
download | micropython-1e1779eacf4da5cd8699bee26a02eed4eda10101.tar.gz micropython-1e1779eacf4da5cd8699bee26a02eed4eda10101.zip |
py: Reluctantly add an extra pass to bytecode compiler.
Bytecode also needs a pass to compute the stack size. This is because
the state size of the bytecode function is encoded as a variable uint,
so we must know the value of this uint before we encode it (otherwise
the size of the generated code changes from one pass to the next).
Having an entire pass for this seems wasteful (in time). Alternative is
to allocate fixed space for the state size (would need 3-4 bytes to be
general, when 1 byte is usually sufficient) which uses a bit of extra
RAM per bytecode function, and makes the code less elegant in places
where this uint is encoded/decoded.
So, for now, opt for an extra pass.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/py/compile.c b/py/compile.c index 2b56d83e74..48b1079a10 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3729,10 +3729,6 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is #endif comp->emit = emit_native; EMIT_ARG(set_native_type, MP_EMIT_NATIVE_TYPE_ENABLE, s->emit_options == MP_EMIT_OPT_VIPER, 0); - - // native emitters need an extra pass to compute stack size - compile_scope(comp, s, MP_PASS_STACK_SIZE); - break; #endif // MICROPY_EMIT_NATIVE @@ -3746,6 +3742,9 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is } #endif // !MICROPY_EMIT_CPYTHON + // need a pass to compute stack size + compile_scope(comp, s, MP_PASS_STACK_SIZE); + // second last pass: compute code size if (comp->compile_error == MP_OBJ_NULL) { compile_scope(comp, s, MP_PASS_CODE_SIZE); |