Skip to content

Commit 2b00181

Browse files
committed
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.
1 parent d72370d commit 2b00181

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

py/objfun.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ STATIC void dump_args(const mp_obj_t *a, size_t sz) {
210210
state_size_out_var = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t); \
211211
}
212212

213+
#define INIT_CODESTATE(code_state, _fun_bc, n_args, n_kw, args) \
214+
code_state->fun_bc = _fun_bc; \
215+
code_state->ip = 0; \
216+
mp_setup_code_state(code_state, n_args, n_kw, args); \
217+
code_state->old_globals = mp_globals_get();
218+
213219
#if MICROPY_STACKLESS
214220
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) {
215221
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
229235
return NULL;
230236
}
231237

232-
code_state->fun_bc = self;
233-
code_state->ip = 0;
234-
mp_setup_code_state(code_state, n_args, n_kw, args);
238+
INIT_CODESTATE(code_state, self, n_args, n_kw, args);
235239

236240
// execute the byte code with the correct globals context
237-
code_state->old_globals = mp_globals_get();
238241
mp_globals_set(self->globals);
239242

240243
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
265268
state_size = 0; // indicate that we allocated using alloca
266269
}
267270

268-
code_state->fun_bc = self;
269-
code_state->ip = 0;
270-
mp_setup_code_state(code_state, n_args, n_kw, args);
271+
INIT_CODESTATE(code_state, self, n_args, n_kw, args);
271272

272273
// execute the byte code with the correct globals context
273-
code_state->old_globals = mp_globals_get();
274274
mp_globals_set(self->globals);
275275
mp_vm_return_kind_t vm_return_kind = mp_execute_bytecode(code_state, MP_OBJ_NULL);
276276
mp_globals_set(code_state->old_globals);

0 commit comments

Comments
 (0)