py: Rename mp_exc_stack to mp_exc_stack_t.

This commit is contained in:
Damien George 2014-03-30 00:57:09 +00:00
parent d7592a1c3f
commit 89f94b51ab
3 changed files with 14 additions and 14 deletions

View File

@ -14,10 +14,10 @@ typedef struct _mp_exc_stack {
// We might only have 2 interesting cases here: SETUP_EXCEPT & SETUP_FINALLY,
// consider storing it in bit 1 of val_sp. TODO: SETUP_WITH?
byte opcode;
} mp_exc_stack;
} mp_exc_stack_t;
mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret);
mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out, mp_exc_stack *exc_stack, mp_exc_stack **exc_sp_in_out, volatile mp_obj_t inject_exc);
mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out, mp_exc_stack_t *exc_stack, mp_exc_stack_t **exc_sp_in_out, volatile mp_obj_t inject_exc);
void mp_byte_code_print(const byte *code, int len);
// Helper macros to access pointer with least significant bit holding a flag

View File

@ -58,12 +58,12 @@ typedef struct _mp_obj_gen_instance_t {
const byte *ip;
mp_obj_t *sp;
// bit 0 is saved currently_in_except_block value
mp_exc_stack *exc_sp;
mp_exc_stack_t *exc_sp;
uint n_state;
// Variable-length
mp_obj_t state[0];
// Variable-length, never accessed by name, only as (void*)(state + n_state)
mp_exc_stack exc_state[0];
mp_exc_stack_t exc_state[0];
} mp_obj_gen_instance_t;
void gen_instance_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
@ -88,7 +88,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
*self->sp = send_value;
}
mp_vm_return_kind_t ret_kind = mp_execute_byte_code_2(self->code_info, &self->ip,
&self->state[self->n_state - 1], &self->sp, (mp_exc_stack*)(self->state + self->n_state),
&self->state[self->n_state - 1], &self->sp, (mp_exc_stack_t*)(self->state + self->n_state),
&self->exc_sp, throw_value);
switch (ret_kind) {
@ -226,12 +226,12 @@ mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, int n_args, const mp_obj_
assert(bytecode[0] == 0);
bytecode += 1;
mp_obj_gen_instance_t *o = m_new_obj_var(mp_obj_gen_instance_t, byte, n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack));
mp_obj_gen_instance_t *o = m_new_obj_var(mp_obj_gen_instance_t, byte, n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t));
o->base.type = &mp_type_gen_instance;
o->code_info = bytecode;
o->ip = bytecode;
o->sp = &o->state[0] - 1; // sp points to top of stack, which starts off 1 below the state
o->exc_sp = (mp_exc_stack*)(o->state + n_state) - 1;
o->exc_sp = (mp_exc_stack_t*)(o->state + n_state) - 1;
o->n_state = n_state;
// copy args to end of state array, in reverse (that's how mp_execute_byte_code_2 needs it)

14
py/vm.c
View File

@ -79,12 +79,12 @@ mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args,
mp_obj_t *sp = &state[0] - 1;
// allocate state for exceptions
mp_exc_stack exc_state[4];
mp_exc_stack *exc_stack = &exc_state[0];
mp_exc_stack_t exc_state[4];
mp_exc_stack_t *exc_stack = &exc_state[0];
if (n_exc_stack > 4) {
exc_stack = m_new(mp_exc_stack, n_exc_stack);
exc_stack = m_new(mp_exc_stack_t, n_exc_stack);
}
mp_exc_stack *exc_sp = &exc_stack[0] - 1;
mp_exc_stack_t *exc_sp = &exc_stack[0] - 1;
// init args
for (uint i = 0; i < n_args; i++) {
@ -130,7 +130,7 @@ mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args,
// MP_VM_RETURN_EXCEPTION, exception in fastn[0]
mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out,
mp_obj_t *fastn, mp_obj_t **sp_in_out,
mp_exc_stack *exc_stack, mp_exc_stack **exc_sp_in_out,
mp_exc_stack_t *exc_stack, mp_exc_stack_t **exc_sp_in_out,
volatile mp_obj_t inject_exc) {
// careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think)
@ -142,7 +142,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
nlr_buf_t nlr;
volatile bool currently_in_except_block = MP_TAGPTR_TAG(*exc_sp_in_out); // 0 or 1, to detect nested exceptions
mp_exc_stack *volatile exc_sp = MP_TAGPTR_PTR(*exc_sp_in_out); // stack grows up, exc_sp points to top of stack
mp_exc_stack_t *volatile exc_sp = MP_TAGPTR_PTR(*exc_sp_in_out); // stack grows up, exc_sp points to top of stack
const byte *volatile save_ip = ip; // this is so we can access ip in the exception handler without making ip volatile (which means the compiler can't keep it in a register in the main loop)
// outer exception handling loop
@ -702,7 +702,7 @@ unwind_return:
if (unum == 0) {
// search for the inner-most previous exception, to reraise it
obj1 = MP_OBJ_NULL;
for (mp_exc_stack *e = exc_sp; e >= exc_stack; e--) {
for (mp_exc_stack_t *e = exc_sp; e >= exc_stack; e--) {
if (e->prev_exc != MP_OBJ_NULL) {
obj1 = e->prev_exc;
break;