diff options
author | Damien George <damien.p.george@gmail.com> | 2015-04-06 22:38:53 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-04-07 22:43:28 +0100 |
commit | 9988618e0e0f5c319e31b135d993e22efb593093 (patch) | |
tree | d89d8df392ce2669c9e516a05b11742e72dc8cf2 /py/bc.c | |
parent | 18bd51707c218137005cd73cb5a35ebfe2bccd6e (diff) |
py: Implement full func arg passing for native emitter.
This patch gets full function argument passing working with native
emitter. Includes named args, keyword args, default args, var args
and var keyword args. Fully Python compliant.
It reuses the bytecode mp_setup_code_state function to do all the hard
work. This function is slightly adjusted to accommodate native calls,
and the native emitter is forced a bit to emit similar prelude and
code-info as bytecode.
Diffstat (limited to 'py/bc.c')
-rw-r--r-- | py/bc.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -78,8 +78,13 @@ STATIC void dump_args(const mp_obj_t *a, mp_uint_t sz) { #define dump_args(...) (void)0 #endif -// code_state should have ->ip filled in (pointing past code info block), -// as well as ->n_state. +// On entry code_state should be allocated somewhere (stack/heap) and +// contain the following valid entries: +// - code_state->code_info should be the offset in bytes from the start of +// the bytecode chunk to the start of the code-info within the bytecode +// - code_state->ip should contain the offset in bytes from the start of +// the bytecode chunk to the start of the prelude within the bytecode +// - code_state->n_state should be set to the state size (locals plus stack) void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // This function is pretty complicated. It's main aim is to be efficient in speed and RAM // usage for the common case of positional only args. @@ -89,7 +94,7 @@ void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, mp_uint_t #if MICROPY_STACKLESS code_state->prev = NULL; #endif - code_state->code_info = self->bytecode; + code_state->code_info = self->bytecode + (mp_uint_t)code_state->code_info; code_state->sp = &code_state->state[0] - 1; code_state->exc_sp = (mp_exc_stack_t*)(code_state->state + n_state) - 1; @@ -227,7 +232,7 @@ continue2:; } // bytecode prelude: initialise closed over variables - const byte *ip = code_state->ip; + const byte *ip = self->bytecode + (mp_uint_t)code_state->ip; mp_uint_t local_num; while ((local_num = *ip++) != 255) { code_state->state[n_state - 1 - local_num] = |