py: Rename struct mp_code_state to mp_code_state_t.
Also at _t to mp_exc_stack pre-declaration in struct typedef.
This commit is contained in:
parent
531217a06b
commit
581a59a456
2
py/bc.c
2
py/bc.c
|
@ -89,7 +89,7 @@ STATIC void dump_args(const mp_obj_t *a, size_t sz) {
|
||||||
// - code_state->ip should contain the offset in bytes from the start of
|
// - code_state->ip should contain the offset in bytes from the start of
|
||||||
// the bytecode chunk to just after n_state and n_exc_stack
|
// the bytecode chunk to just after n_state and n_exc_stack
|
||||||
// - code_state->n_state should be set to the state size (locals plus stack)
|
// - 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_fun_bc_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
void mp_setup_code_state(mp_code_state_t *code_state, mp_obj_fun_bc_t *self, size_t n_args, size_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
|
// 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.
|
// usage for the common case of positional only args.
|
||||||
size_t n_state = code_state->n_state;
|
size_t n_state = code_state->n_state;
|
||||||
|
|
12
py/bc.h
12
py/bc.h
|
@ -60,7 +60,7 @@
|
||||||
// constN : obj
|
// constN : obj
|
||||||
|
|
||||||
// Exception stack entry
|
// Exception stack entry
|
||||||
typedef struct _mp_exc_stack {
|
typedef struct _mp_exc_stack_t {
|
||||||
const byte *handler;
|
const byte *handler;
|
||||||
// bit 0 is saved currently_in_except_block value
|
// bit 0 is saved currently_in_except_block value
|
||||||
// bit 1 is whether the opcode was SETUP_WITH or SETUP_FINALLY
|
// bit 1 is whether the opcode was SETUP_WITH or SETUP_FINALLY
|
||||||
|
@ -69,7 +69,7 @@ typedef struct _mp_exc_stack {
|
||||||
mp_obj_base_t *prev_exc;
|
mp_obj_base_t *prev_exc;
|
||||||
} mp_exc_stack_t;
|
} mp_exc_stack_t;
|
||||||
|
|
||||||
typedef struct _mp_code_state {
|
typedef struct _mp_code_state_t {
|
||||||
const byte *code_info;
|
const byte *code_info;
|
||||||
const byte *ip;
|
const byte *ip;
|
||||||
const mp_uint_t *const_table;
|
const mp_uint_t *const_table;
|
||||||
|
@ -85,14 +85,14 @@ typedef struct _mp_code_state {
|
||||||
mp_obj_t state[0];
|
mp_obj_t state[0];
|
||||||
// Variable-length, never accessed by name, only as (void*)(state + n_state)
|
// Variable-length, never accessed by name, only as (void*)(state + n_state)
|
||||||
//mp_exc_stack_t exc_state[0];
|
//mp_exc_stack_t exc_state[0];
|
||||||
} mp_code_state;
|
} mp_code_state_t;
|
||||||
|
|
||||||
mp_uint_t mp_decode_uint(const byte **ptr);
|
mp_uint_t mp_decode_uint(const byte **ptr);
|
||||||
|
|
||||||
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_obj_t inject_exc);
|
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc);
|
||||||
mp_code_state *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||||
struct _mp_obj_fun_bc_t;
|
struct _mp_obj_fun_bc_t;
|
||||||
void mp_setup_code_state(mp_code_state *code_state, struct _mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
void mp_setup_code_state(mp_code_state_t *code_state, struct _mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||||
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len, const mp_uint_t *const_table);
|
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len, const mp_uint_t *const_table);
|
||||||
void mp_bytecode_print2(const byte *code, mp_uint_t len);
|
void mp_bytecode_print2(const byte *code, mp_uint_t len);
|
||||||
const byte *mp_bytecode_print_str(const byte *ip);
|
const byte *mp_bytecode_print_str(const byte *ip);
|
||||||
|
|
|
@ -628,7 +628,7 @@ STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg);
|
||||||
STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num);
|
STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||||
STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num);
|
STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||||
|
|
||||||
#define STATE_START (sizeof(mp_code_state) / sizeof(mp_uint_t))
|
#define STATE_START (sizeof(mp_code_state_t) / sizeof(mp_uint_t))
|
||||||
|
|
||||||
STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
|
STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
|
||||||
DEBUG_printf("start_pass(pass=%u, scope=%p)\n", pass, scope);
|
DEBUG_printf("start_pass(pass=%u, scope=%p)\n", pass, scope);
|
||||||
|
@ -775,10 +775,10 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
|
||||||
|
|
||||||
// set code_state.ip (offset from start of this function to prelude info)
|
// set code_state.ip (offset from start of this function to prelude info)
|
||||||
// XXX this encoding may change size
|
// XXX this encoding may change size
|
||||||
ASM_MOV_IMM_TO_LOCAL_USING(emit->as, emit->prelude_offset, offsetof(mp_code_state, ip) / sizeof(mp_uint_t), REG_ARG_1);
|
ASM_MOV_IMM_TO_LOCAL_USING(emit->as, emit->prelude_offset, offsetof(mp_code_state_t, ip) / sizeof(mp_uint_t), REG_ARG_1);
|
||||||
|
|
||||||
// set code_state.n_state
|
// set code_state.n_state
|
||||||
ASM_MOV_IMM_TO_LOCAL_USING(emit->as, emit->n_state, offsetof(mp_code_state, n_state) / sizeof(mp_uint_t), REG_ARG_1);
|
ASM_MOV_IMM_TO_LOCAL_USING(emit->as, emit->n_state, offsetof(mp_code_state_t, n_state) / sizeof(mp_uint_t), REG_ARG_1);
|
||||||
|
|
||||||
// put address of code_state into first arg
|
// put address of code_state into first arg
|
||||||
ASM_MOV_LOCAL_ADDR_TO_REG(emit->as, 0, REG_ARG_1);
|
ASM_MOV_LOCAL_ADDR_TO_REG(emit->as, 0, REG_ARG_1);
|
||||||
|
|
14
py/objfun.c
14
py/objfun.c
|
@ -165,7 +165,7 @@ STATIC void dump_args(const mp_obj_t *a, mp_uint_t sz) {
|
||||||
#define VM_DETECT_STACK_OVERFLOW (0)
|
#define VM_DETECT_STACK_OVERFLOW (0)
|
||||||
|
|
||||||
#if MICROPY_STACKLESS
|
#if MICROPY_STACKLESS
|
||||||
mp_code_state *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_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();
|
MP_STACK_CHECK();
|
||||||
mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
@ -178,8 +178,8 @@ mp_code_state *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args,
|
||||||
|
|
||||||
// allocate state for locals and stack
|
// allocate state for locals and stack
|
||||||
size_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
|
size_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
|
||||||
mp_code_state *code_state;
|
mp_code_state_t *code_state;
|
||||||
code_state = m_new_obj_var_maybe(mp_code_state, byte, state_size);
|
code_state = m_new_obj_var_maybe(mp_code_state_t, byte, state_size);
|
||||||
if (!code_state) {
|
if (!code_state) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -220,12 +220,12 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
|
||||||
|
|
||||||
// allocate state for locals and stack
|
// allocate state for locals and stack
|
||||||
mp_uint_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
|
mp_uint_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
|
||||||
mp_code_state *code_state = NULL;
|
mp_code_state_t *code_state = NULL;
|
||||||
if (state_size > VM_MAX_STATE_ON_STACK) {
|
if (state_size > VM_MAX_STATE_ON_STACK) {
|
||||||
code_state = m_new_obj_var_maybe(mp_code_state, byte, state_size);
|
code_state = m_new_obj_var_maybe(mp_code_state_t, byte, state_size);
|
||||||
}
|
}
|
||||||
if (code_state == NULL) {
|
if (code_state == NULL) {
|
||||||
code_state = alloca(sizeof(mp_code_state) + state_size);
|
code_state = alloca(sizeof(mp_code_state_t) + state_size);
|
||||||
state_size = 0; // indicate that we allocated using alloca
|
state_size = 0; // indicate that we allocated using alloca
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
|
||||||
|
|
||||||
// free the state if it was allocated on the heap
|
// free the state if it was allocated on the heap
|
||||||
if (state_size != 0) {
|
if (state_size != 0) {
|
||||||
m_del_var(mp_code_state, byte, state_size, code_state);
|
m_del_var(mp_code_state_t, byte, state_size, code_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm_return_kind == MP_VM_RETURN_NORMAL) {
|
if (vm_return_kind == MP_VM_RETURN_NORMAL) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ typedef struct _mp_obj_gen_wrap_t {
|
||||||
typedef struct _mp_obj_gen_instance_t {
|
typedef struct _mp_obj_gen_instance_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
mp_obj_dict_t *globals;
|
mp_obj_dict_t *globals;
|
||||||
mp_code_state code_state;
|
mp_code_state_t code_state;
|
||||||
} mp_obj_gen_instance_t;
|
} mp_obj_gen_instance_t;
|
||||||
|
|
||||||
STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||||
|
|
10
py/vm.c
10
py/vm.c
|
@ -127,7 +127,7 @@ typedef enum {
|
||||||
// MP_VM_RETURN_NORMAL, sp valid, return value in *sp
|
// MP_VM_RETURN_NORMAL, sp valid, return value in *sp
|
||||||
// MP_VM_RETURN_YIELD, ip, sp valid, yielded value in *sp
|
// MP_VM_RETURN_YIELD, ip, sp valid, yielded value in *sp
|
||||||
// MP_VM_RETURN_EXCEPTION, exception in fastn[0]
|
// MP_VM_RETURN_EXCEPTION, exception in fastn[0]
|
||||||
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_obj_t inject_exc) {
|
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc) {
|
||||||
#define SELECTIVE_EXC_IP (0)
|
#define SELECTIVE_EXC_IP (0)
|
||||||
#if SELECTIVE_EXC_IP
|
#if SELECTIVE_EXC_IP
|
||||||
#define MARK_EXC_IP_SELECTIVE() { code_state->ip = ip; } /* stores ip 1 byte past last opcode */
|
#define MARK_EXC_IP_SELECTIVE() { code_state->ip = ip; } /* stores ip 1 byte past last opcode */
|
||||||
|
@ -904,7 +904,7 @@ unwind_jump:;
|
||||||
code_state->ip = ip;
|
code_state->ip = ip;
|
||||||
code_state->sp = sp;
|
code_state->sp = sp;
|
||||||
code_state->exc_sp = MP_TAGPTR_MAKE(exc_sp, currently_in_except_block);
|
code_state->exc_sp = MP_TAGPTR_MAKE(exc_sp, currently_in_except_block);
|
||||||
mp_code_state *new_state = mp_obj_fun_bc_prepare_codestate(*sp, unum & 0xff, (unum >> 8) & 0xff, sp + 1);
|
mp_code_state_t *new_state = mp_obj_fun_bc_prepare_codestate(*sp, unum & 0xff, (unum >> 8) & 0xff, sp + 1);
|
||||||
if (new_state) {
|
if (new_state) {
|
||||||
new_state->prev = code_state;
|
new_state->prev = code_state;
|
||||||
code_state = new_state;
|
code_state = new_state;
|
||||||
|
@ -940,7 +940,7 @@ unwind_jump:;
|
||||||
mp_call_args_t out_args;
|
mp_call_args_t out_args;
|
||||||
mp_call_prepare_args_n_kw_var(false, unum, sp, &out_args);
|
mp_call_prepare_args_n_kw_var(false, unum, sp, &out_args);
|
||||||
|
|
||||||
mp_code_state *new_state = mp_obj_fun_bc_prepare_codestate(out_args.fun,
|
mp_code_state_t *new_state = mp_obj_fun_bc_prepare_codestate(out_args.fun,
|
||||||
out_args.n_args, out_args.n_kw, out_args.args);
|
out_args.n_args, out_args.n_kw, out_args.args);
|
||||||
m_del(mp_obj_t, out_args.args, out_args.n_alloc);
|
m_del(mp_obj_t, out_args.args, out_args.n_alloc);
|
||||||
if (new_state) {
|
if (new_state) {
|
||||||
|
@ -976,7 +976,7 @@ unwind_jump:;
|
||||||
mp_uint_t n_kw = (unum >> 8) & 0xff;
|
mp_uint_t n_kw = (unum >> 8) & 0xff;
|
||||||
int adjust = (sp[1] == MP_OBJ_NULL) ? 0 : 1;
|
int adjust = (sp[1] == MP_OBJ_NULL) ? 0 : 1;
|
||||||
|
|
||||||
mp_code_state *new_state = mp_obj_fun_bc_prepare_codestate(*sp, n_args + adjust, n_kw, sp + 2 - adjust);
|
mp_code_state_t *new_state = mp_obj_fun_bc_prepare_codestate(*sp, n_args + adjust, n_kw, sp + 2 - adjust);
|
||||||
if (new_state) {
|
if (new_state) {
|
||||||
new_state->prev = code_state;
|
new_state->prev = code_state;
|
||||||
code_state = new_state;
|
code_state = new_state;
|
||||||
|
@ -1011,7 +1011,7 @@ unwind_jump:;
|
||||||
mp_call_args_t out_args;
|
mp_call_args_t out_args;
|
||||||
mp_call_prepare_args_n_kw_var(true, unum, sp, &out_args);
|
mp_call_prepare_args_n_kw_var(true, unum, sp, &out_args);
|
||||||
|
|
||||||
mp_code_state *new_state = mp_obj_fun_bc_prepare_codestate(out_args.fun,
|
mp_code_state_t *new_state = mp_obj_fun_bc_prepare_codestate(out_args.fun,
|
||||||
out_args.n_args, out_args.n_kw, out_args.args);
|
out_args.n_args, out_args.n_kw, out_args.args);
|
||||||
m_del(mp_obj_t, out_args.args, out_args.n_alloc);
|
m_del(mp_obj_t, out_args.args, out_args.n_alloc);
|
||||||
if (new_state) {
|
if (new_state) {
|
||||||
|
|
Loading…
Reference in New Issue