aboutsummaryrefslogtreecommitdiff
path: root/py/objfun.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-12-09 12:45:28 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-12-09 12:49:00 +0200
commit2b00181592b23e5ca97464791c1ffa56e9495489 (patch)
treeb0405994c26026d04faf1d20a70db9dd8b8231e6 /py/objfun.c
parentd72370def72c74ca98c1ec4eb7b58ba0fbcc9629 (diff)
py/objfun: Factor out macro for initializing codestate.
This is second part of fun_bc_call() vs mp_obj_fun_bc_prepare_codestate() common code refactor. This factors out code to initialize codestate object. After this patch, mp_obj_fun_bc_prepare_codestate() is effectively DECODE_CODESTATE_SIZE() followed by allocation followed by INIT_CODESTATE(), and fun_bc_call() starts with that too.
Diffstat (limited to 'py/objfun.c')
-rw-r--r--py/objfun.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/py/objfun.c b/py/objfun.c
index e27413e40..8fb3ec6fa 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -210,6 +210,12 @@ STATIC void dump_args(const mp_obj_t *a, size_t sz) {
state_size_out_var = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t); \
}
+#define INIT_CODESTATE(code_state, _fun_bc, n_args, n_kw, args) \
+ code_state->fun_bc = _fun_bc; \
+ code_state->ip = 0; \
+ mp_setup_code_state(code_state, n_args, n_kw, args); \
+ code_state->old_globals = mp_globals_get();
+
#if MICROPY_STACKLESS
mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
MP_STACK_CHECK();
@@ -229,12 +235,9 @@ mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args
return NULL;
}
- code_state->fun_bc = self;
- code_state->ip = 0;
- mp_setup_code_state(code_state, n_args, n_kw, args);
+ INIT_CODESTATE(code_state, self, n_args, n_kw, args);
// execute the byte code with the correct globals context
- code_state->old_globals = mp_globals_get();
mp_globals_set(self->globals);
return code_state;
@@ -265,12 +268,9 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
state_size = 0; // indicate that we allocated using alloca
}
- code_state->fun_bc = self;
- code_state->ip = 0;
- mp_setup_code_state(code_state, n_args, n_kw, args);
+ INIT_CODESTATE(code_state, self, n_args, n_kw, args);
// execute the byte code with the correct globals context
- code_state->old_globals = mp_globals_get();
mp_globals_set(self->globals);
mp_vm_return_kind_t vm_return_kind = mp_execute_bytecode(code_state, MP_OBJ_NULL);
mp_globals_set(code_state->old_globals);