Commit 6f355fd3 authored by Damien George's avatar Damien George
Browse files

py: Make labels unsigned ints (converted from int).

Labels should never be negative, and this modified type signature
reflects that.
parent bf8ae4d9
...@@ -22,7 +22,7 @@ struct _asm_thumb_t { ...@@ -22,7 +22,7 @@ struct _asm_thumb_t {
byte *code_base; byte *code_base;
byte dummy_data[8]; byte dummy_data[8];
int max_num_labels; uint max_num_labels;
int *label_offsets; int *label_offsets;
int num_locals; int num_locals;
uint push_reglist; uint push_reglist;
...@@ -212,7 +212,7 @@ void asm_thumb_exit(asm_thumb_t *as) { ...@@ -212,7 +212,7 @@ void asm_thumb_exit(asm_thumb_t *as) {
asm_thumb_write_op16(as, OP_POP_RLIST_PC(as->push_reglist)); asm_thumb_write_op16(as, OP_POP_RLIST_PC(as->push_reglist));
} }
void asm_thumb_label_assign(asm_thumb_t *as, int label) { void asm_thumb_label_assign(asm_thumb_t *as, uint label) {
assert(label < as->max_num_labels); assert(label < as->max_num_labels);
if (as->pass == ASM_THUMB_PASS_2) { if (as->pass == ASM_THUMB_PASS_2) {
// assign label offset // assign label offset
...@@ -225,7 +225,7 @@ void asm_thumb_label_assign(asm_thumb_t *as, int label) { ...@@ -225,7 +225,7 @@ void asm_thumb_label_assign(asm_thumb_t *as, int label) {
} }
} }
STATIC int get_label_dest(asm_thumb_t *as, int label) { STATIC int get_label_dest(asm_thumb_t *as, uint label) {
assert(label < as->max_num_labels); assert(label < as->max_num_labels);
return as->label_offsets[label]; return as->label_offsets[label];
} }
...@@ -308,7 +308,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as) { ...@@ -308,7 +308,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
#define OP_B_N(byte_offset) (0xe000 | (((byte_offset) >> 1) & 0x07ff)) #define OP_B_N(byte_offset) (0xe000 | (((byte_offset) >> 1) & 0x07ff))
void asm_thumb_b_n(asm_thumb_t *as, int label) { void asm_thumb_b_n(asm_thumb_t *as, uint label) {
int dest = get_label_dest(as, label); int dest = get_label_dest(as, label);
int rel = dest - as->code_offset; int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
...@@ -321,7 +321,7 @@ void asm_thumb_b_n(asm_thumb_t *as, int label) { ...@@ -321,7 +321,7 @@ void asm_thumb_b_n(asm_thumb_t *as, int label) {
#define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff)) #define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff))
void asm_thumb_bcc_n(asm_thumb_t *as, int cond, int label) { void asm_thumb_bcc_n(asm_thumb_t *as, int cond, uint label) {
int dest = get_label_dest(as, label); int dest = get_label_dest(as, label);
int rel = dest - as->code_offset; int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
...@@ -380,7 +380,7 @@ void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num) ...@@ -380,7 +380,7 @@ void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num)
#define OP_BW_HI(byte_offset) (0xf000 | (((byte_offset) >> 12) & 0x07ff)) #define OP_BW_HI(byte_offset) (0xf000 | (((byte_offset) >> 12) & 0x07ff))
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff)) #define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
void asm_thumb_b_label(asm_thumb_t *as, int label) { void asm_thumb_b_label(asm_thumb_t *as, uint label) {
int dest = get_label_dest(as, label); int dest = get_label_dest(as, label);
int rel = dest - as->code_offset; int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
...@@ -403,7 +403,7 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) { ...@@ -403,7 +403,7 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) {
#define OP_BCC_W_HI(cond, byte_offset) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f)) #define OP_BCC_W_HI(cond, byte_offset) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f))
#define OP_BCC_W_LO(byte_offset) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff)) #define OP_BCC_W_LO(byte_offset) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff))
void asm_thumb_bcc_label(asm_thumb_t *as, int cond, int label) { void asm_thumb_bcc_label(asm_thumb_t *as, int cond, uint label) {
int dest = get_label_dest(as, label); int dest = get_label_dest(as, label);
int rel = dest - as->code_offset; int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
......
...@@ -53,7 +53,7 @@ void *asm_thumb_get_code(asm_thumb_t *as); ...@@ -53,7 +53,7 @@ void *asm_thumb_get_code(asm_thumb_t *as);
void asm_thumb_entry(asm_thumb_t *as, int num_locals); void asm_thumb_entry(asm_thumb_t *as, int num_locals);
void asm_thumb_exit(asm_thumb_t *as); void asm_thumb_exit(asm_thumb_t *as);
void asm_thumb_label_assign(asm_thumb_t *as, int label); void asm_thumb_label_assign(asm_thumb_t *as, uint label);
// argument order follows ARM, in general dest is first // argument order follows ARM, in general dest is first
// note there is a difference between movw and mov.w, and many others! // note there is a difference between movw and mov.w, and many others!
...@@ -67,8 +67,8 @@ void asm_thumb_subs_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src, int ...@@ -67,8 +67,8 @@ void asm_thumb_subs_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src, int
void asm_thumb_cmp_reg_reg(asm_thumb_t *as, uint rlo_a, uint rlo_b); void asm_thumb_cmp_reg_reg(asm_thumb_t *as, uint rlo_a, uint rlo_b);
void asm_thumb_cmp_rlo_i8(asm_thumb_t *as, uint rlo, int i8); void asm_thumb_cmp_rlo_i8(asm_thumb_t *as, uint rlo, int i8);
void asm_thumb_ite_ge(asm_thumb_t *as); void asm_thumb_ite_ge(asm_thumb_t *as);
void asm_thumb_b_n(asm_thumb_t *as, int label); void asm_thumb_b_n(asm_thumb_t *as, uint label);
void asm_thumb_bcc_n(asm_thumb_t *as, int cond, int label); void asm_thumb_bcc_n(asm_thumb_t *as, int cond, uint label);
void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, machine_uint_t i32_src); // convenience void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, machine_uint_t i32_src); // convenience
void asm_thumb_mov_reg_i32_optimised(asm_thumb_t *as, uint reg_dest, int i32_src); // convenience void asm_thumb_mov_reg_i32_optimised(asm_thumb_t *as, uint reg_dest, int i32_src); // convenience
...@@ -76,7 +76,7 @@ void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src); ...@@ -76,7 +76,7 @@ void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src);
void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience void asm_thumb_mov_reg_local(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience
void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num); // convenience
void asm_thumb_b_label(asm_thumb_t *as, int label); // convenience ? void asm_thumb_b_label(asm_thumb_t *as, uint label); // convenience ?
void asm_thumb_bcc_label(asm_thumb_t *as, int cc, int label); // convenience: picks narrow or wide branch void asm_thumb_bcc_label(asm_thumb_t *as, int cc, uint label); // convenience: picks narrow or wide branch
void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp); // convenience ? void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp); // convenience ?
...@@ -43,10 +43,10 @@ typedef struct _compiler_t { ...@@ -43,10 +43,10 @@ typedef struct _compiler_t {
uint8_t had_error; // try to keep compiler clean from nlr uint8_t had_error; // try to keep compiler clean from nlr
uint8_t func_arg_is_super; // used to compile special case of super() function call uint8_t func_arg_is_super; // used to compile special case of super() function call
int next_label; uint next_label;
int break_label; uint break_label;
int continue_label; uint continue_label;
int break_continue_except_level; int break_continue_except_level;
uint16_t cur_except_level; // increased for SETUP_EXCEPT, SETUP_FINALLY; decreased for POP_BLOCK, POP_EXCEPT uint16_t cur_except_level; // increased for SETUP_EXCEPT, SETUP_FINALLY; decreased for POP_BLOCK, POP_EXCEPT
...@@ -196,7 +196,7 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) { ...@@ -196,7 +196,7 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) {
STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra); STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra);
STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn); STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn);
STATIC int comp_next_label(compiler_t *comp) { STATIC uint comp_next_label(compiler_t *comp) {
return comp->next_label++; return comp->next_label++;
} }
...@@ -467,7 +467,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if ...@@ -467,7 +467,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) { if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == false) { if (jump_if == false) {
int label2 = comp_next_label(comp); uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) { for (int i = 0; i < n - 1; i++) {
cpython_c_if_cond(comp, pns->nodes[i], true, label2, true); cpython_c_if_cond(comp, pns->nodes[i], true, label2, true);
} }
...@@ -485,7 +485,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if ...@@ -485,7 +485,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if
cpython_c_if_cond(comp, pns->nodes[i], false, label, true); cpython_c_if_cond(comp, pns->nodes[i], false, label, true);
} }
} else { } else {
int label2 = comp_next_label(comp); uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) { for (int i = 0; i < n - 1; i++) {
cpython_c_if_cond(comp, pns->nodes[i], false, label2, true); cpython_c_if_cond(comp, pns->nodes[i], false, label2, true);
} }
...@@ -528,7 +528,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la ...@@ -528,7 +528,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) { if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == false) { if (jump_if == false) {
int label2 = comp_next_label(comp); uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) { for (int i = 0; i < n - 1; i++) {
c_if_cond(comp, pns->nodes[i], true, label2); c_if_cond(comp, pns->nodes[i], true, label2);
} }
...@@ -546,7 +546,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la ...@@ -546,7 +546,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la
c_if_cond(comp, pns->nodes[i], false, label); c_if_cond(comp, pns->nodes[i], false, label);
} }
} else { } else {
int label2 = comp_next_label(comp); uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) { for (int i = 0; i < n - 1; i++) {
c_if_cond(comp, pns->nodes[i], false, label2); c_if_cond(comp, pns->nodes[i], false, label2);
} }
...@@ -1202,7 +1202,7 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1202,7 +1202,7 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t *pns_test_if_expr = (mp_parse_node_struct_t*)pns->nodes[0]; mp_parse_node_struct_t *pns_test_if_expr = (mp_parse_node_struct_t*)pns->nodes[0];
mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns_test_if_expr->nodes[1]; mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns_test_if_expr->nodes[1];
int l_fail = comp_next_label(comp); uint l_fail = comp_next_label(comp);
c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition
compile_node(comp, pns_test_if_expr->nodes[0]); // success value compile_node(comp, pns_test_if_expr->nodes[0]); // success value
EMIT(return_value); EMIT(return_value);
...@@ -1451,7 +1451,7 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1451,7 +1451,7 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
c_if_cond(comp, pns->nodes[0], true, l_end); c_if_cond(comp, pns->nodes[0], true, l_end);
EMIT_ARG(load_global, MP_QSTR_AssertionError); // we load_global instead of load_id, to be consistent with CPython EMIT_ARG(load_global, MP_QSTR_AssertionError); // we load_global instead of load_id, to be consistent with CPython
if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) { if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) {
...@@ -1466,9 +1466,9 @@ void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1466,9 +1466,9 @@ void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// TODO proper and/or short circuiting // TODO proper and/or short circuiting
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
int l_fail = comp_next_label(comp); uint l_fail = comp_next_label(comp);
c_if_cond(comp, pns->nodes[0], false, l_fail); // if condition c_if_cond(comp, pns->nodes[0], false, l_fail); // if condition
compile_node(comp, pns->nodes[1]); // if block compile_node(comp, pns->nodes[1]); // if block
...@@ -1529,10 +1529,10 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1529,10 +1529,10 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
#define START_BREAK_CONTINUE_BLOCK \ #define START_BREAK_CONTINUE_BLOCK \
int old_break_label = comp->break_label; \ uint old_break_label = comp->break_label; \
int old_continue_label = comp->continue_label; \ uint old_continue_label = comp->continue_label; \
int break_label = comp_next_label(comp); \ uint break_label = comp_next_label(comp); \
int continue_label = comp_next_label(comp); \ uint continue_label = comp_next_label(comp); \
comp->break_label = break_label; \ comp->break_label = break_label; \
comp->continue_label = continue_label; \ comp->continue_label = continue_label; \
comp->break_continue_except_level = comp->cur_except_level; comp->break_continue_except_level = comp->cur_except_level;
...@@ -1547,7 +1547,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1547,7 +1547,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// compared to CPython, we have an optimised version of while loops // compared to CPython, we have an optimised version of while loops
#if MICROPY_EMIT_CPYTHON #if MICROPY_EMIT_CPYTHON
int done_label = comp_next_label(comp); uint done_label = comp_next_label(comp);
EMIT_ARG(setup_loop, break_label); EMIT_ARG(setup_loop, break_label);
EMIT_ARG(label_assign, continue_label); EMIT_ARG(label_assign, continue_label);
c_if_cond(comp, pns->nodes[0], false, done_label); // condition c_if_cond(comp, pns->nodes[0], false, done_label); // condition
...@@ -1562,7 +1562,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1562,7 +1562,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT(pop_block); EMIT(pop_block);
} }
#else #else
int top_label = comp_next_label(comp); uint top_label = comp_next_label(comp);
EMIT_ARG(jump, continue_label); EMIT_ARG(jump, continue_label);
EMIT_ARG(label_assign, top_label); EMIT_ARG(label_assign, top_label);
compile_node(comp, pns->nodes[1]); // body compile_node(comp, pns->nodes[1]); // body
...@@ -1584,8 +1584,8 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1584,8 +1584,8 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) { void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) {
START_BREAK_CONTINUE_BLOCK START_BREAK_CONTINUE_BLOCK
int top_label = comp_next_label(comp); uint top_label = comp_next_label(comp);
int entry_label = comp_next_label(comp); uint entry_label = comp_next_label(comp);
// compile: start, duplicated on stack // compile: start, duplicated on stack
compile_node(comp, pn_start); compile_node(comp, pn_start);
...@@ -1682,8 +1682,8 @@ void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -1682,8 +1682,8 @@ void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
START_BREAK_CONTINUE_BLOCK START_BREAK_CONTINUE_BLOCK
int pop_label = comp_next_label(comp); uint pop_label = comp_next_label(comp);
int end_label = comp_next_label(comp); uint end_label = comp_next_label(comp);
// I don't think our implementation needs SETUP_LOOP/POP_BLOCK for for-statements // I don't think our implementation needs SETUP_LOOP/POP_BLOCK for for-statements
#if MICROPY_EMIT_CPYTHON #if MICROPY_EMIT_CPYTHON
...@@ -1721,8 +1721,8 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, ...@@ -1721,8 +1721,8 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
// setup code // setup code
int stack_size = EMIT(get_stack_size); int stack_size = EMIT(get_stack_size);
int l1 = comp_next_label(comp); uint l1 = comp_next_label(comp);
int success_label = comp_next_label(comp); uint success_label = comp_next_label(comp);
EMIT_ARG(setup_except, l1); EMIT_ARG(setup_except, l1);
compile_increase_except_level(comp); compile_increase_except_level(comp);
...@@ -1731,14 +1731,14 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, ...@@ -1731,14 +1731,14 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
EMIT(pop_block); EMIT(pop_block);
EMIT_ARG(jump, success_label); EMIT_ARG(jump, success_label);
EMIT_ARG(label_assign, l1); EMIT_ARG(label_assign, l1);
int l2 = comp_next_label(comp); uint l2 = comp_next_label(comp);
for (int i = 0; i < n_except; i++) { for (int i = 0; i < n_except; i++) {
assert(MP_PARSE_NODE_IS_STRUCT_KIND(pn_excepts[i], PN_try_stmt_except)); // should be assert(MP_PARSE_NODE_IS_STRUCT_KIND(pn_excepts[i], PN_try_stmt_except)); // should be
mp_parse_node_struct_t *pns_except = (mp_parse_node_struct_t*)pn_excepts[i]; mp_parse_node_struct_t *pns_except = (mp_parse_node_struct_t*)pn_excepts[i];
qstr qstr_exception_local = 0; qstr qstr_exception_local = 0;
int end_finally_label = comp_next_label(comp); uint end_finally_label = comp_next_label(comp);
if (MP_PARSE_NODE_IS_NULL(pns_except->nodes[0])) { if (MP_PARSE_NODE_IS_NULL(pns_except->nodes[0])) {
// this is a catch all exception handler // this is a catch all exception handler
...@@ -1773,7 +1773,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, ...@@ -1773,7 +1773,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
EMIT(pop_top); EMIT(pop_top);
int l3 = 0; uint l3 = 0;
if (qstr_exception_local != 0) { if (qstr_exception_local != 0) {
l3 = comp_next_label(comp); l3 = comp_next_label(comp);
EMIT_ARG(setup_finally, l3); EMIT_ARG(setup_finally, l3);
...@@ -1810,7 +1810,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, ...@@ -1810,7 +1810,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_except, mp_parse_node_t pn_else, mp_parse_node_t pn_finally) { void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_except, mp_parse_node_t pn_else, mp_parse_node_t pn_finally) {
// don't understand how the stack works with exceptions, so we force it to return to the correct value // don't understand how the stack works with exceptions, so we force it to return to the correct value
int stack_size = EMIT(get_stack_size); int stack_size = EMIT(get_stack_size);
int l_finally_block = comp_next_label(comp); uint l_finally_block = comp_next_label(comp);
EMIT_ARG(setup_finally, l_finally_block); EMIT_ARG(setup_finally, l_finally_block);
compile_increase_except_level(comp); compile_increase_except_level(comp);
...@@ -1866,7 +1866,7 @@ void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *nodes, m ...@@ -1866,7 +1866,7 @@ void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *nodes, m
// no more pre-bits, compile the body of the with // no more pre-bits, compile the body of the with
compile_node(comp, body); compile_node(comp, body);
} else { } else {
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
if (MP_PARSE_NODE_IS_STRUCT_KIND(nodes[0], PN_with_item)) { if (MP_PARSE_NODE_IS_STRUCT_KIND(nodes[0], PN_with_item)) {
// this pre-bit is of the form "a as b" // this pre-bit is of the form "a as b"
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)nodes[0]; mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)nodes[0];
...@@ -2024,8 +2024,8 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -2024,8 +2024,8 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns->nodes[1]; mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns->nodes[1];
int stack_size = EMIT(get_stack_size); int stack_size = EMIT(get_stack_size);
int l_fail = comp_next_label(comp); uint l_fail = comp_next_label(comp);
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition
compile_node(comp, pns->nodes[0]); // success value compile_node(comp, pns->nodes[0]); // success value
EMIT_ARG(jump, l_end); EMIT_ARG(jump, l_end);
...@@ -2055,7 +2055,7 @@ void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -2055,7 +2055,7 @@ void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) { for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]); compile_node(comp, pns->nodes[i]);
...@@ -2067,7 +2067,7 @@ void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -2067,7 +2067,7 @@ void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) { for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]); compile_node(comp, pns->nodes[i]);
...@@ -2088,7 +2088,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -2088,7 +2088,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
bool multi = (num_nodes > 3); bool multi = (num_nodes > 3);
int l_fail = 0; uint l_fail = 0;
if (multi) { if (multi) {
l_fail = comp_next_label(comp); l_fail = comp_next_label(comp);
} }
...@@ -2135,7 +2135,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -2135,7 +2135,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
if (multi) { if (multi) {
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
EMIT_ARG(jump, l_end); EMIT_ARG(jump, l_end);
EMIT_ARG(label_assign, l_fail); EMIT_ARG(label_assign, l_fail);
EMIT(rot_two); EMIT(rot_two);
...@@ -2835,8 +2835,8 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse ...@@ -2835,8 +2835,8 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse
// for loop // for loop
mp_parse_node_struct_t *pns_comp_for2 = (mp_parse_node_struct_t*)pn_iter; mp_parse_node_struct_t *pns_comp_for2 = (mp_parse_node_struct_t*)pn_iter;
compile_node(comp, pns_comp_for2->nodes[1]); compile_node(comp, pns_comp_for2->nodes[1]);
int l_end2 = comp_next_label(comp); uint l_end2 = comp_next_label(comp);
int l_top2 = comp_next_label(comp); uint l_top2 = comp_next_label(comp);
EMIT(get_iter); EMIT(get_iter);
EMIT_ARG(label_assign, l_top2); EMIT_ARG(label_assign, l_top2);
EMIT_ARG(for_iter, l_end2); EMIT_ARG(for_iter, l_end2);
...@@ -2982,8 +2982,8 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { ...@@ -2982,8 +2982,8 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
EMIT_ARG(build_set, 0); EMIT_ARG(build_set, 0);
} }
int l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
int l_top = comp_next_label(comp); uint l_top = comp_next_label(comp);
EMIT_ARG(load_id, qstr_arg); EMIT_ARG(load_id, qstr_arg);
EMIT_ARG(label_assign, l_top); EMIT_ARG(label_assign, l_top);
EMIT_ARG(for_iter, l_end); EMIT_ARG(for_iter, l_end);
...@@ -3102,7 +3102,7 @@ void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass ...@@ -3102,7 +3102,7 @@ void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass
compile_syntax_error(comp, nodes[i], "inline assembler 'label' requires 1 argument"); compile_syntax_error(comp, nodes[i], "inline assembler 'label' requires 1 argument");
return; return;
} }
int lab = comp_next_label(comp); uint lab = comp_next_label(comp);
if (pass > PASS_1) { if (pass > PASS_1) {
EMIT_INLINE_ASM_ARG(label, lab, MP_PARSE_NODE_LEAF_ARG(pn_arg[0])); EMIT_INLINE_ASM_ARG(label, lab, MP_PARSE_NODE_LEAF_ARG(pn_arg[0]));
} }
......
...@@ -32,7 +32,7 @@ typedef struct _emit_method_table_t { ...@@ -32,7 +32,7 @@ typedef struct _emit_method_table_t {
void (*store_id)(emit_t *emit, qstr qstr); void (*store_id)(emit_t *emit, qstr qstr);
void (*delete_id)(emit_t *emit, qstr qstr); void (*delete_id)(emit_t *emit, qstr qstr);
void (*label_assign)(emit_t *emit, int l); void (*label_assign)(emit_t *emit, uint l);
void (*import_name)(emit_t *emit, qstr qstr); void (*import_name)(emit_t *emit, qstr qstr);
void (*import_from)(emit_t *emit, qstr qstr); void (*import_from)(emit_t *emit, qstr qstr);
void (*import_star)(emit_t *emit); void (*import_star)(emit_t *emit);
...@@ -68,21 +68,21 @@ typedef struct _emit_method_table_t { ...@@ -68,21 +68,21 @@ typedef struct _emit_method_table_t {
void (*pop_top)(emit_t *emit); void (*pop_top)(emit_t *emit);
void (*rot_two)(emit_t *emit); void (*rot_two)(emit_t *emit);
void (*rot_three)(emit_t *emit); void (*rot_three)(emit_t *emit);
void (*jump)(emit_t *emit, int label); void (*jump)(emit_t *emit, uint label);
void (*pop_jump_if_true)(emit_t *emit, int label); void (*pop_jump_if_true)(emit_t *emit, uint label);
void (*pop_jump_if_false)(emit_t *emit, int label); void (*pop_jump_if_false)(emit_t *emit, uint label);
void (*jump_if_true_or_pop)(emit_t *emit, int label); void (*jump_if_true_or_pop)(emit_t *emit, uint label);
void (*jump_if_false_or_pop)(emit_t *emit, int label); void (*jump_if_false_or_pop)(emit_t *emit, uint label);
void (*setup_loop)(emit_t *emit, int label); void (*setup_loop)(emit_t *emit, uint label);
void (*break_loop)(emit_t *emit, int label, int except_depth); void (*break_loop)(emit_t *emit, uint label, int except_depth);
void (*continue_loop)(emit_t *emit, int label, int except_depth); void (*continue_loop)(emit_t *emit, uint label, int except_depth);
void (*setup_with)(emit_t *emit, int label); void (*setup_with)(emit_t *emit, uint label);
void (*with_cleanup)(emit_t *emit); void (*with_cleanup)(emit_t *emit);
void (*setup_except)(emit_t *emit, int label); void (*setup_except)(emit_t *emit, uint label);
void (*setup_finally)(emit_t *emit, int label); void (*setup_finally)(emit_t *emit, uint label);
void (*end_finally)(emit_t *emit); void (*end_finally)(emit_t *emit);
void (*get_iter)(emit_t *emit); void (*get_iter)(emit_t *emit);
void (*for_iter)(emit_t *emit, int label); void (*for_iter)(emit_t *emit, uint label);
void (*for_iter_end)(emit_t *emit); void (*for_iter_end)(emit_t *emit);
void (*pop_block)(emit_t *emit); void (*pop_block)(emit_t *emit);
void (*pop_except)(emit_t *emit); void (*pop_except)(emit_t *emit);
...@@ -136,7 +136,7 @@ typedef struct _emit_inline_asm_method_table_t { ...@@ -136,7 +136,7 @@ typedef struct _emit_inline_asm_method_table_t {
void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope); void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope);
void (*end_pass)(emit_inline_asm_t *emit); void (*end_pass)(emit_inline_asm_t *emit);
int (*count_params)(emit_inline_asm_t *emit, int n_params, mp_parse_node_t *pn_params); int (*count_params)(emit_inline_asm_t *emit, int n_params, mp_parse_node_t *pn_params);
void (*label)(emit_inline_asm_t *emit, int label_num, qstr label_id); void (*label)(emit_inline_asm_t *emit, uint label_num, qstr label_id);
void (*op)(emit_inline_asm_t *emit, qstr op, int n_args, mp_parse_node_t *pn_args); void (*op)(emit_inline_asm_t *emit, qstr op, int n_args, mp_parse_node_t *pn_args);
} emit_inline_asm_method_table_t; } emit_inline_asm_method_table_t;
......
...@@ -171,7 +171,7 @@ STATIC void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) { ...@@ -171,7 +171,7 @@ STATIC void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) {
} }