diff options
author | Damien George <damien.p.george@gmail.com> | 2015-04-24 01:52:28 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-04-24 01:52:28 +0100 |
commit | 8c1d23a0e20da2903f363448e8042e5d08caabe7 (patch) | |
tree | 0d7713088c7ebec74030b8d1f4e02dcb4d484138 /py/emitbc.c | |
parent | ede0f3ab3dfcc4ab1a5799b312395703bf942517 (diff) | |
download | micropython-8c1d23a0e20da2903f363448e8042e5d08caabe7.tar.gz micropython-8c1d23a0e20da2903f363448e8042e5d08caabe7.zip |
py: Modify bytecode "with" behaviour so it doesn't use any heap.
Before this patch a "with" block needed to create a bound method object
on the heap for the __exit__ call. Now it doesn't because we use
load_method instead of load_attr, and save the method+self on the stack.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r-- | py/emitbc.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index 8d482afe52..b9304fd82d 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -680,12 +680,15 @@ void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_dept } void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label) { - emit_bc_pre(emit, 7); + // TODO We can probably optimise the amount of needed stack space, since + // we don't actually need 4 slots during the entire with block, only in + // the cleanup handler in certain cases. It needs some thinking. + emit_bc_pre(emit, 4); emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label); } void mp_emit_bc_with_cleanup(emit_t *emit) { - emit_bc_pre(emit, -7); + emit_bc_pre(emit, -4); emit_write_bytecode_byte(emit, MP_BC_WITH_CLEANUP); } |