Browse Source

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

Labels should never be negative, and this modified type signature
reflects that.
pull/460/head
Damien George 11 years ago
parent
commit
6f355fd3b9
  1. 14
      py/asmthumb.c
  2. 10
      py/asmthumb.h
  3. 80
      py/compile.c
  4. 28
      py/emit.h
  5. 28
      py/emitbc.c
  6. 26
      py/emitcpy.c
  7. 2
      py/emitinlinethumb.c
  8. 28
      py/emitnative.c

14
py/asmthumb.c

@ -22,7 +22,7 @@ struct _asm_thumb_t {
byte *code_base;
byte dummy_data[8];
int max_num_labels;
uint max_num_labels;
int *label_offsets;
int num_locals;
uint push_reglist;
@ -212,7 +212,7 @@ void asm_thumb_exit(asm_thumb_t *as) {
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);
if (as->pass == ASM_THUMB_PASS_2) {
// assign label offset
@ -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);
return as->label_offsets[label];
}
@ -308,7 +308,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
#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 rel = dest - as->code_offset;
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) {
#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 rel = dest - as->code_offset;
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)
#define OP_BW_HI(byte_offset) (0xf000 | (((byte_offset) >> 12) & 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 rel = dest - as->code_offset;
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) {
#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))
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 rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction

10
py/asmthumb.h

@ -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_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
// 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
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_ite_ge(asm_thumb_t *as);
void asm_thumb_b_n(asm_thumb_t *as, int label);
void asm_thumb_bcc_n(asm_thumb_t *as, int cond, int label);
void asm_thumb_b_n(asm_thumb_t *as, uint 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_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);
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_b_label(asm_thumb_t *as, int label); // convenience ?
void asm_thumb_bcc_label(asm_thumb_t *as, int cc, int label); // convenience: picks narrow or wide branch
void asm_thumb_b_label(asm_thumb_t *as, uint label); // convenience ?
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 ?

80
py/compile.c

@ -43,10 +43,10 @@ typedef struct _compiler_t {
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
int next_label;
uint next_label;
int break_label;
int continue_label;
uint break_label;
uint continue_label;
int break_continue_except_level;
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) {
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 int comp_next_label(compiler_t *comp) {
STATIC uint comp_next_label(compiler_t *comp) {
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
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == false) {
int label2 = comp_next_label(comp);
uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
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
cpython_c_if_cond(comp, pns->nodes[i], false, label, true);
}
} else {
int label2 = comp_next_label(comp);
uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
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
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == false) {
int label2 = comp_next_label(comp);
uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
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
c_if_cond(comp, pns->nodes[i], false, label);
}
} else {
int label2 = comp_next_label(comp);
uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
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) {
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];
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
compile_node(comp, pns_test_if_expr->nodes[0]); // success value
EMIT(return_value);
@ -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) {
int l_end = comp_next_label(comp);
uint l_end = comp_next_label(comp);
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
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) {
void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// 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
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) {
}
#define START_BREAK_CONTINUE_BLOCK \
int old_break_label = comp->break_label; \
int old_continue_label = comp->continue_label; \
int break_label = comp_next_label(comp); \
int continue_label = comp_next_label(comp); \
uint old_break_label = comp->break_label; \
uint old_continue_label = comp->continue_label; \
uint break_label = comp_next_label(comp); \
uint continue_label = comp_next_label(comp); \
comp->break_label = break_label; \
comp->continue_label = continue_label; \
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) {
// compared to CPython, we have an optimised version of while loops
#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(label_assign, continue_label);
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) {
EMIT(pop_block);
}
#else
int top_label = comp_next_label(comp);
uint top_label = comp_next_label(comp);
EMIT_ARG(jump, continue_label);
EMIT_ARG(label_assign, top_label);
compile_node(comp, pns->nodes[1]); // body
@ -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) {
START_BREAK_CONTINUE_BLOCK
int top_label = comp_next_label(comp);
int entry_label = comp_next_label(comp);
uint top_label = comp_next_label(comp);
uint entry_label = comp_next_label(comp);
// compile: start, duplicated on stack
compile_node(comp, pn_start);
@ -1682,8 +1682,8 @@ void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
START_BREAK_CONTINUE_BLOCK
int pop_label = comp_next_label(comp);
int end_label = comp_next_label(comp);
uint pop_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
#if MICROPY_EMIT_CPYTHON
@ -1721,8 +1721,8 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
// setup code
int stack_size = EMIT(get_stack_size);
int l1 = comp_next_label(comp);
int success_label = comp_next_label(comp);
uint l1 = comp_next_label(comp);
uint success_label = comp_next_label(comp);
EMIT_ARG(setup_except, l1);
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,
EMIT(pop_block);
EMIT_ARG(jump, success_label);
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++) {
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];
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])) {
// 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,
EMIT(pop_top);
int l3 = 0;
uint l3 = 0;
if (qstr_exception_local != 0) {
l3 = comp_next_label(comp);
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,
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
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);
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
// no more pre-bits, compile the body of the with
compile_node(comp, body);
} 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)) {
// this pre-bit is of the form "a as b"
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) {
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 l_fail = comp_next_label(comp);
int l_end = comp_next_label(comp);
uint l_fail = 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
compile_node(comp, pns->nodes[0]); // success value
EMIT_ARG(jump, l_end);
@ -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) {
int l_end = comp_next_label(comp);
uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]);
@ -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) {
int l_end = comp_next_label(comp);
uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]);
@ -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);
compile_node(comp, pns->nodes[0]);
bool multi = (num_nodes > 3);
int l_fail = 0;
uint l_fail = 0;
if (multi) {
l_fail = comp_next_label(comp);
}
@ -2135,7 +2135,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
}
if (multi) {
int l_end = comp_next_label(comp);
uint l_end = comp_next_label(comp);
EMIT_ARG(jump, l_end);
EMIT_ARG(label_assign, l_fail);
EMIT(rot_two);
@ -2835,8 +2835,8 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse
// for loop
mp_parse_node_struct_t *pns_comp_for2 = (mp_parse_node_struct_t*)pn_iter;
compile_node(comp, pns_comp_for2->nodes[1]);
int l_end2 = comp_next_label(comp);
int l_top2 = comp_next_label(comp);
uint l_end2 = comp_next_label(comp);
uint l_top2 = comp_next_label(comp);
EMIT(get_iter);
EMIT_ARG(label_assign, l_top2);
EMIT_ARG(for_iter, l_end2);
@ -2982,8 +2982,8 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
EMIT_ARG(build_set, 0);
}
int l_end = comp_next_label(comp);
int l_top = comp_next_label(comp);
uint l_end = comp_next_label(comp);
uint l_top = comp_next_label(comp);
EMIT_ARG(load_id, qstr_arg);
EMIT_ARG(label_assign, l_top);
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
compile_syntax_error(comp, nodes[i], "inline assembler 'label' requires 1 argument");
return;
}
int lab = comp_next_label(comp);
uint lab = comp_next_label(comp);
if (pass > PASS_1) {
EMIT_INLINE_ASM_ARG(label, lab, MP_PARSE_NODE_LEAF_ARG(pn_arg[0]));
}

28
py/emit.h

@ -32,7 +32,7 @@ typedef struct _emit_method_table_t {
void (*store_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_from)(emit_t *emit, qstr qstr);
void (*import_star)(emit_t *emit);
@ -68,21 +68,21 @@ typedef struct _emit_method_table_t {
void (*pop_top)(emit_t *emit);
void (*rot_two)(emit_t *emit);
void (*rot_three)(emit_t *emit);
void (*jump)(emit_t *emit, int label);
void (*pop_jump_if_true)(emit_t *emit, int label);
void (*pop_jump_if_false)(emit_t *emit, int label);
void (*jump_if_true_or_pop)(emit_t *emit, int label);
void (*jump_if_false_or_pop)(emit_t *emit, int label);
void (*setup_loop)(emit_t *emit, int label);
void (*break_loop)(emit_t *emit, int label, int except_depth);
void (*continue_loop)(emit_t *emit, int label, int except_depth);
void (*setup_with)(emit_t *emit, int label);
void (*jump)(emit_t *emit, uint label);
void (*pop_jump_if_true)(emit_t *emit, uint label);
void (*pop_jump_if_false)(emit_t *emit, uint label);
void (*jump_if_true_or_pop)(emit_t *emit, uint label);
void (*jump_if_false_or_pop)(emit_t *emit, uint label);
void (*setup_loop)(emit_t *emit, uint label);
void (*break_loop)(emit_t *emit, uint label, int except_depth);
void (*continue_loop)(emit_t *emit, uint label, int except_depth);
void (*setup_with)(emit_t *emit, uint label);
void (*with_cleanup)(emit_t *emit);
void (*setup_except)(emit_t *emit, int label);
void (*setup_finally)(emit_t *emit, int label);
void (*setup_except)(emit_t *emit, uint label);
void (*setup_finally)(emit_t *emit, uint label);
void (*end_finally)(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 (*pop_block)(emit_t *emit);
void (*pop_except)(emit_t *emit);
@ -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 (*end_pass)(emit_inline_asm_t *emit);
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);
} emit_inline_asm_method_table_t;

28
py/emitbc.c

@ -171,7 +171,7 @@ STATIC void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) {
}
// unsigned labels are relative to ip following this instruction, stored as 16 bits
STATIC void emit_write_byte_code_byte_unsigned_label(emit_t* emit, byte b1, int label) {
STATIC void emit_write_byte_code_byte_unsigned_label(emit_t* emit, byte b1, uint label) {
uint byte_code_offset;
if (emit->pass < PASS_3) {
byte_code_offset = 0;
@ -185,7 +185,7 @@ STATIC void emit_write_byte_code_byte_unsigned_label(emit_t* emit, byte b1, int
}
// signed labels are relative to ip following this instruction, stored as 16 bits, in excess
STATIC void emit_write_byte_code_byte_signed_label(emit_t* emit, byte b1, int label) {
STATIC void emit_write_byte_code_byte_signed_label(emit_t* emit, byte b1, uint label) {
int byte_code_offset;
if (emit->pass < PASS_3) {
byte_code_offset = 0;
@ -329,7 +329,7 @@ STATIC void emit_bc_pre(emit_t *emit, int stack_size_delta) {
emit->last_emit_was_return_value = false;
}
STATIC void emit_bc_label_assign(emit_t *emit, int l) {
STATIC void emit_bc_label_assign(emit_t *emit, uint l) {
emit_bc_pre(emit, 0);
assert(l < emit->max_num_labels);
if (emit->pass == PASS_2) {
@ -551,37 +551,37 @@ STATIC void emit_bc_rot_three(emit_t *emit) {
emit_write_byte_code_byte(emit, MP_BC_ROT_THREE);
}
STATIC void emit_bc_jump(emit_t *emit, int label) {
STATIC void emit_bc_jump(emit_t *emit, uint label) {
emit_bc_pre(emit, 0);
emit_write_byte_code_byte_signed_label(emit, MP_BC_JUMP, label);
}
STATIC void emit_bc_pop_jump_if_true(emit_t *emit, int label) {
STATIC void emit_bc_pop_jump_if_true(emit_t *emit, uint label) {
emit_bc_pre(emit, -1);
emit_write_byte_code_byte_signed_label(emit, MP_BC_POP_JUMP_IF_TRUE, label);
}
STATIC void emit_bc_pop_jump_if_false(emit_t *emit, int label) {
STATIC void emit_bc_pop_jump_if_false(emit_t *emit, uint label) {
emit_bc_pre(emit, -1);
emit_write_byte_code_byte_signed_label(emit, MP_BC_POP_JUMP_IF_FALSE, label);
}
STATIC void emit_bc_jump_if_true_or_pop(emit_t *emit, int label) {
STATIC void emit_bc_jump_if_true_or_pop(emit_t *emit, uint label) {
emit_bc_pre(emit, -1);
emit_write_byte_code_byte_signed_label(emit, MP_BC_JUMP_IF_TRUE_OR_POP, label);
}
STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, int label) {
STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, uint label) {
emit_bc_pre(emit, -1);
emit_write_byte_code_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label);
}
STATIC void emit_bc_setup_loop(emit_t *emit, int label) {
STATIC void emit_bc_setup_loop(emit_t *emit, uint label) {
emit_bc_pre(emit, 0);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_LOOP, label);
}
STATIC void emit_bc_unwind_jump(emit_t *emit, int label, int except_depth) {
STATIC void emit_bc_unwind_jump(emit_t *emit, uint label, int except_depth) {
if (except_depth == 0) {
emit_bc_jump(emit, label);
} else {
@ -591,7 +591,7 @@ STATIC void emit_bc_unwind_jump(emit_t *emit, int label, int except_depth) {
}
}
STATIC void emit_bc_setup_with(emit_t *emit, int label) {
STATIC void emit_bc_setup_with(emit_t *emit, uint label) {
emit_bc_pre(emit, 7);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label);
}
@ -601,12 +601,12 @@ STATIC void emit_bc_with_cleanup(emit_t *emit) {
emit_write_byte_code_byte(emit, MP_BC_WITH_CLEANUP);
}
STATIC void emit_bc_setup_except(emit_t *emit, int label) {
STATIC void emit_bc_setup_except(emit_t *emit, uint label) {
emit_bc_pre(emit, 6);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_EXCEPT, label);
}
STATIC void emit_bc_setup_finally(emit_t *emit, int label) {
STATIC void emit_bc_setup_finally(emit_t *emit, uint label) {
emit_bc_pre(emit, 6);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_FINALLY, label);
}
@ -621,7 +621,7 @@ STATIC void emit_bc_get_iter(emit_t *emit) {
emit_write_byte_code_byte(emit, MP_BC_GET_ITER);
}
STATIC void emit_bc_for_iter(emit_t *emit, int label) {
STATIC void emit_bc_for_iter(emit_t *emit, uint label) {
emit_bc_pre(emit, 1);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_FOR_ITER, label);
}

26
py/emitcpy.c

@ -100,7 +100,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
emit->byte_code_offset += byte_code_size;
}
STATIC void emit_cpy_label_assign(emit_t *emit, int l) {
STATIC void emit_cpy_label_assign(emit_t *emit, uint l) {
emit_pre(emit, 0, 0);
assert(l < emit->max_num_labels);
if (emit->pass == PASS_2) {
@ -402,7 +402,7 @@ STATIC void emit_cpy_rot_three(emit_t *emit) {
}
}
STATIC void emit_cpy_jump(emit_t *emit, int label) {
STATIC void emit_cpy_jump(emit_t *emit, uint label) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
int dest = emit->label_offsets[label];
@ -414,49 +414,49 @@ STATIC void emit_cpy_jump(emit_t *emit, int label) {
}
}
STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, int label) {
STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, uint label) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("POP_JUMP_IF_TRUE %d\n", emit->label_offsets[label]);
}
}
STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, int label) {
STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, uint label) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("POP_JUMP_IF_FALSE %d\n", emit->label_offsets[label]);
}
}
STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, int label) {
STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, uint label) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("JUMP_IF_TRUE_OR_POP %d\n", emit->label_offsets[label]);
}
}
STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, int label) {
STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, uint label) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("JUMP_IF_FALSE_OR_POP %d\n", emit->label_offsets[label]);
}
}
STATIC void emit_cpy_setup_loop(emit_t *emit, int label) {
STATIC void emit_cpy_setup_loop(emit_t *emit, uint label) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
printf("SETUP_LOOP %d\n", emit->label_offsets[label]);
}
}
STATIC void emit_cpy_break_loop(emit_t *emit, int label, int except_depth) {
STATIC void emit_cpy_break_loop(emit_t *emit, uint label, int except_depth) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
printf("BREAK_LOOP\n");
}
}
STATIC void emit_cpy_continue_loop(emit_t *emit, int label, int except_depth) {
STATIC void emit_cpy_continue_loop(emit_t *emit, uint label, int except_depth) {
if (except_depth == 0) {
emit_cpy_jump(emit, label);
} else {
@ -467,7 +467,7 @@ STATIC void emit_cpy_continue_loop(emit_t *emit, int label, int except_depth) {
}
}
STATIC void emit_cpy_setup_with(emit_t *emit, int label) {
STATIC void emit_cpy_setup_with(emit_t *emit, uint label) {
emit_pre(emit, 7, 3);
if (emit->pass == PASS_3) {
printf("SETUP_WITH %d\n", emit->label_offsets[label]);
@ -481,14 +481,14 @@ STATIC void emit_cpy_with_cleanup(emit_t *emit) {
}
}
STATIC void emit_cpy_setup_except(emit_t *emit, int label) {
STATIC void emit_cpy_setup_except(emit_t *emit, uint label) {
emit_pre(emit, 6, 3);
if (emit->pass == PASS_3) {
printf("SETUP_EXCEPT %d\n", emit->label_offsets[label]);
}
}
STATIC void emit_cpy_setup_finally(emit_t *emit, int label) {
STATIC void emit_cpy_setup_finally(emit_t *emit, uint label) {
emit_pre(emit, 6, 3);
if (emit->pass == PASS_3) {
printf("SETUP_FINALLY %d\n", emit->label_offsets[label]);
@ -509,7 +509,7 @@ STATIC void emit_cpy_get_iter(emit_t *emit) {
}
}
STATIC void emit_cpy_for_iter(emit_t *emit, int label) {
STATIC void emit_cpy_for_iter(emit_t *emit, uint label) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("FOR_ITER %d\n", emit->label_offsets[label]);

2
py/emitinlinethumb.c

@ -75,7 +75,7 @@ STATIC int emit_inline_thumb_count_params(emit_inline_asm_t *emit, int n_params,
return n_params;
}
STATIC void emit_inline_thumb_label(emit_inline_asm_t *emit, int label_num, qstr label_id) {
STATIC void emit_inline_thumb_label(emit_inline_asm_t *emit, uint label_num, qstr label_id) {
assert(label_num < emit->max_num_labels);
emit->label_lookup[label_num] = label_id;
asm_thumb_label_assign(emit->as, label_num);

28
py/emitnative.c

@ -585,7 +585,7 @@ STATIC void emit_native_delete_id(emit_t *emit, qstr qstr) {
emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
}
STATIC void emit_native_label_assign(emit_t *emit, int l) {
STATIC void emit_native_label_assign(emit_t *emit, uint l) {
emit_native_pre(emit);
// need to commit stack because we can jump here from elsewhere
need_stack_settled(emit);
@ -920,7 +920,7 @@ STATIC void emit_native_rot_three(emit_t *emit) {
emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1);
}
STATIC void emit_native_jump(emit_t *emit, int label) {
STATIC void emit_native_jump(emit_t *emit, uint label) {
emit_native_pre(emit);
#if N_X64
asm_x64_jmp_label(emit->as, label);
@ -930,7 +930,7 @@ STATIC void emit_native_jump(emit_t *emit, int label) {
emit_post(emit);
}
STATIC void emit_native_pop_jump_pre_helper(emit_t *emit, int label) {
STATIC void emit_native_pop_jump_pre_helper(emit_t *emit, uint label) {
vtype_kind_t vtype = peek_vtype(emit);
if (vtype == VTYPE_BOOL) {
emit_pre_pop_reg(emit, &vtype, REG_RET);
@ -943,7 +943,7 @@ STATIC void emit_native_pop_jump_pre_helper(emit_t *emit, int label) {
}
}
STATIC void emit_native_pop_jump_if_false(emit_t *emit, int label) {
STATIC void emit_native_pop_jump_if_false(emit_t *emit, uint label) {
emit_native_pop_jump_pre_helper(emit, label);
#if N_X64
asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
@ -955,7 +955,7 @@ STATIC void emit_native_pop_jump_if_false(emit_t *emit, int label) {
emit_post(emit);
}
STATIC void emit_native_pop_jump_if_true(emit_t *emit, int label) {
STATIC void emit_native_pop_jump_if_true(emit_t *emit, uint label) {
emit_native_pop_jump_pre_helper(emit, label);
#if N_X64
asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
@ -967,35 +967,35 @@ STATIC void emit_native_pop_jump_if_true(emit_t *emit, int label) {
emit_post(emit);
}
STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, int label) {
STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, uint label) {
assert(0);
}
STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, int label) {
STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, uint label) {
assert(0);
}
STATIC void emit_native_setup_loop(emit_t *emit, int label) {
STATIC void emit_native_setup_loop(emit_t *emit, uint label) {
emit_native_pre(emit);
emit_post(emit);
}
STATIC void emit_native_break_loop(emit_t *emit, int label, int except_depth) {
STATIC void emit_native_break_loop(emit_t *emit, uint label, int except_depth) {
emit_native_jump(emit, label); // TODO properly
}
STATIC void emit_native_continue_loop(emit_t *emit, int label, int except_depth) {
STATIC void emit_native_continue_loop(emit_t *emit, uint label, int except_depth) {
assert(0);
}
STATIC void emit_native_setup_with(emit_t *emit, int label) {
STATIC void emit_native_setup_with(emit_t *emit, uint label) {
// not supported, or could be with runtime call
assert(0);
}
STATIC void emit_native_with_cleanup(emit_t *emit) {
assert(0);
}
STATIC void emit_native_setup_except(emit_t *emit, int label) {
STATIC void emit_native_setup_except(emit_t *emit, uint label) {
assert(0);
}
STATIC void emit_native_setup_finally(emit_t *emit, int label) {
STATIC void emit_native_setup_finally(emit_t *emit, uint label) {
assert(0);
}
STATIC void emit_native_end_finally(emit_t *emit) {
@ -1013,7 +1013,7 @@ STATIC void emit_native_get_iter(emit_t *emit) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
STATIC void emit_native_for_iter(emit_t *emit, int label) {
STATIC void emit_native_for_iter(emit_t *emit, uint label) {
emit_native_pre(emit);
vtype_kind_t vtype;
emit_access_stack(emit, 1, &vtype, REG_ARG_1);

Loading…
Cancel
Save