Replace global "static" -> "STATIC", to allow "analysis builds". Part 2.

This commit is contained in:
Paul Sokolovsky 2014-02-12 18:31:30 +02:00
parent d5df6cd44a
commit 520e2f58a5
22 changed files with 451 additions and 446 deletions

View File

@ -93,7 +93,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
}
// all functions must go through this one to emit bytes
static byte *asm_thumb_get_cur_to_write_bytes(asm_thumb_t *as, int num_bytes_to_write) {
STATIC byte *asm_thumb_get_cur_to_write_bytes(asm_thumb_t *as, int num_bytes_to_write) {
//printf("emit %d\n", num_bytes_to_write);
if (as->pass < ASM_THUMB_PASS_3) {
as->code_offset += num_bytes_to_write;
@ -116,20 +116,20 @@ void *asm_thumb_get_code(asm_thumb_t *as) {
}
/*
static void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) {
STATIC void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) {
byte *c = asm_thumb_get_cur_to_write_bytes(as, 1);
c[0] = b1;
}
*/
static void asm_thumb_write_op16(asm_thumb_t *as, uint op) {
STATIC void asm_thumb_write_op16(asm_thumb_t *as, uint op) {
byte *c = asm_thumb_get_cur_to_write_bytes(as, 2);
// little endian
c[0] = op;
c[1] = op >> 8;
}
static void asm_thumb_write_op32(asm_thumb_t *as, uint op1, uint op2) {
STATIC void asm_thumb_write_op32(asm_thumb_t *as, uint op1, uint op2) {
byte *c = asm_thumb_get_cur_to_write_bytes(as, 4);
// little endian, op1 then op2
c[0] = op1;
@ -144,7 +144,7 @@ static void asm_thumb_write_op32(asm_thumb_t *as, uint op1, uint op2) {
#define IMM32_L2(x) (((x) >> 16) & 0xff)
#define IMM32_L3(x) (((x) >> 24) & 0xff)
static void asm_thumb_write_word32(asm_thumb_t *as, int w32) {
STATIC void asm_thumb_write_word32(asm_thumb_t *as, int w32) {
byte *c = asm_thumb_get_cur_to_write_bytes(as, 4);
c[0] = IMM32_L0(w32);
c[1] = IMM32_L1(w32);
@ -226,7 +226,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, int label) {
assert(label < as->max_num_labels);
return as->label_offsets[label];
}
@ -244,7 +244,7 @@ void asm_thumb_movs_rlo_i8(asm_thumb_t *as, uint rlo_dest, int i8_src) {
#define OP_MOVT (0xf2c0)
// if loading lo half with movw, the i16 value will be zero extended into the r32 register!
static void asm_thumb_mov_reg_i16(asm_thumb_t *as, uint mov_op, uint reg_dest, int i16_src) {
STATIC void asm_thumb_mov_reg_i16(asm_thumb_t *as, uint mov_op, uint reg_dest, int i16_src) {
assert(reg_dest < REG_R15);
// mov[wt] reg_dest, #i16_src
asm_thumb_write_op32(as, mov_op | ((i16_src >> 1) & 0x0400) | ((i16_src >> 12) & 0xf), ((i16_src << 4) & 0x7000) | (reg_dest << 8) | (i16_src & 0xff));

View File

@ -176,7 +176,7 @@ void asm_x64_end_pass(asm_x64_t *as) {
}
// all functions must go through this one to emit bytes
static byte *asm_x64_get_cur_to_write_bytes(asm_x64_t *as, int num_bytes_to_write) {
STATIC byte *asm_x64_get_cur_to_write_bytes(asm_x64_t *as, int num_bytes_to_write) {
//printf("emit %d\n", num_bytes_to_write);
if (as->pass < ASM_X64_PASS_3) {
as->code_offset += num_bytes_to_write;
@ -197,25 +197,25 @@ void *asm_x64_get_code(asm_x64_t *as) {
return as->code_base;
}
static void asm_x64_write_byte_1(asm_x64_t *as, byte b1) {
STATIC void asm_x64_write_byte_1(asm_x64_t *as, byte b1) {
byte* c = asm_x64_get_cur_to_write_bytes(as, 1);
c[0] = b1;
}
static void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) {
STATIC void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) {
byte* c = asm_x64_get_cur_to_write_bytes(as, 2);
c[0] = b1;
c[1] = b2;
}
static void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) {
STATIC void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) {
byte* c = asm_x64_get_cur_to_write_bytes(as, 3);
c[0] = b1;
c[1] = b2;
c[2] = b3;
}
static void asm_x64_write_word32(asm_x64_t *as, int w32) {
STATIC void asm_x64_write_word32(asm_x64_t *as, int w32) {
byte* c = asm_x64_get_cur_to_write_bytes(as, 4);
c[0] = IMM32_L0(w32);
c[1] = IMM32_L1(w32);
@ -223,7 +223,7 @@ static void asm_x64_write_word32(asm_x64_t *as, int w32) {
c[3] = IMM32_L3(w32);
}
static void asm_x64_write_word64(asm_x64_t *as, int64_t w64) {
STATIC void asm_x64_write_word64(asm_x64_t *as, int64_t w64) {
byte* c = asm_x64_get_cur_to_write_bytes(as, 8);
c[0] = IMM32_L0(w64);
c[1] = IMM32_L1(w64);
@ -236,7 +236,7 @@ static void asm_x64_write_word64(asm_x64_t *as, int64_t w64) {
}
/* unused
static void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) {
STATIC void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) {
byte* c;
assert(offset + 4 <= as->code_size);
c = as->code_base + offset;
@ -247,7 +247,7 @@ static void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) {
}
*/
static void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) {
STATIC void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) {
assert(disp_r64 != REG_RSP);
if (disp_offset == 0 && disp_r64 != REG_RBP) {
@ -282,7 +282,7 @@ void asm_x64_pop_r64(asm_x64_t *as, int dest_r64) {
asm_x64_write_byte_1(as, OPCODE_POP_R64 | dest_r64);
}
static void asm_x64_ret(asm_x64_t *as) {
STATIC void asm_x64_ret(asm_x64_t *as) {
asm_x64_write_byte_1(as, OPCODE_RET);
}
@ -472,7 +472,7 @@ void asm_x64_label_assign(asm_x64_t *as, int label) {
}
}
static int get_label_dest(asm_x64_t *as, int label) {
STATIC int get_label_dest(asm_x64_t *as, int label) {
assert(label < as->max_num_labels);
return as->label_offsets[label];
}
@ -565,7 +565,7 @@ void asm_x64_mov_r32_to_arg(asm_x64_t *as, int src_r32, int dest_arg_num) {
// ^ ^
// | low address | high address in RAM
//
static int asm_x64_local_offset_from_ebp(asm_x64_t *as, int local_num) {
STATIC int asm_x64_local_offset_from_ebp(asm_x64_t *as, int local_num) {
return (-as->num_locals + local_num) * WORD_SIZE;
}

View File

@ -18,7 +18,7 @@
// args[0] is function from class body
// args[1] is class name
// args[2:] are base objects
static mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args);
// we differ from CPython: we set the new __locals__ object here
@ -61,7 +61,7 @@ static mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
static mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
if (o != mp_const_none) {
mp_obj_print(o, PRINT_REPR);
printf("\n");
@ -100,7 +100,7 @@ mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
static mp_obj_t mp_builtin_all(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) {
mp_obj_t iterable = rt_getiter(o_in);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
@ -113,7 +113,7 @@ static mp_obj_t mp_builtin_all(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_all_obj, mp_builtin_all);
static mp_obj_t mp_builtin_any(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) {
mp_obj_t iterable = rt_getiter(o_in);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
@ -126,7 +126,7 @@ static mp_obj_t mp_builtin_any(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_any_obj, mp_builtin_any);
static mp_obj_t mp_builtin_callable(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_callable(mp_obj_t o_in) {
if (mp_obj_is_callable(o_in)) {
return mp_const_true;
} else {
@ -136,7 +136,7 @@ static mp_obj_t mp_builtin_callable(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
static mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
int ord = mp_obj_get_int(o_in);
if (0 <= ord && ord <= 0x10ffff) {
byte str[1] = {ord};
@ -148,7 +148,7 @@ static mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_chr_obj, mp_builtin_chr);
static mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
// TODO make this function more general and less of a hack
mp_map_t *map;
@ -178,7 +178,7 @@ static mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_dir_obj, 0, 1, mp_builtin_dir);
static mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
if (MP_OBJ_IS_SMALL_INT(o1_in) && MP_OBJ_IS_SMALL_INT(o2_in)) {
mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1_in);
mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2_in);
@ -193,20 +193,20 @@ static mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj, mp_builtin_divmod);
static mp_obj_t mp_builtin_hash(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) {
// TODO hash will generally overflow small integer; can we safely truncate it?
return mp_obj_new_int(mp_obj_hash(o_in));
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash);
static mp_obj_t mp_builtin_iter(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) {
return rt_getiter(o_in);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter);
static mp_obj_t mp_builtin_len(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_len(mp_obj_t o_in) {
mp_obj_t len = mp_obj_len_maybe(o_in);
if (len == NULL) {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
@ -217,7 +217,7 @@ static mp_obj_t mp_builtin_len(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_builtin_len);
static mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) {
if (n_args == 1) {
// given an iterable
mp_obj_t iterable = rt_getiter(args[0]);
@ -246,7 +246,7 @@ static mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_max_obj, 1, mp_builtin_max);
static mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) {
if (n_args == 1) {
// given an iterable
mp_obj_t iterable = rt_getiter(args[0]);
@ -275,7 +275,7 @@ static mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_min_obj, 1, mp_builtin_min);
static mp_obj_t mp_builtin_next(mp_obj_t o) {
STATIC mp_obj_t mp_builtin_next(mp_obj_t o) {
mp_obj_t ret = rt_iternext(o);
if (ret == mp_const_stop_iteration) {
nlr_jump(mp_obj_new_exception(MP_QSTR_StopIteration));
@ -286,7 +286,7 @@ static mp_obj_t mp_builtin_next(mp_obj_t o) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next);
static mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
uint len;
const char *str = mp_obj_str_get_data(o_in, &len);
if (len == 1) {
@ -300,7 +300,7 @@ static mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
static mp_obj_t mp_builtin_pow(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_pow(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 3);
switch (n_args) {
case 2: return rt_binary_op(RT_BINARY_OP_POWER, args[0], args[1]);
@ -310,7 +310,7 @@ static mp_obj_t mp_builtin_pow(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj, 2, 3, mp_builtin_pow);
static mp_obj_t mp_builtin_print(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_print(uint n_args, const mp_obj_t *args) {
for (int i = 0; i < n_args; i++) {
if (i > 0) {
printf(" ");
@ -323,7 +323,7 @@ static mp_obj_t mp_builtin_print(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_print_obj, 0, mp_builtin_print);
static mp_obj_t mp_builtin_range(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_range(uint n_args, const mp_obj_t *args) {
assert(1 <= n_args && n_args <= 3);
switch (n_args) {
case 1: return mp_obj_new_range(0, mp_obj_get_int(args[0]), 1);
@ -334,7 +334,7 @@ static mp_obj_t mp_builtin_range(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_range_obj, 1, 3, mp_builtin_range);
static mp_obj_t mp_builtin_repr(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) {
vstr_t *vstr = vstr_new();
mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, vstr, o_in, PRINT_REPR);
mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
@ -344,7 +344,7 @@ static mp_obj_t mp_builtin_repr(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr);
static mp_obj_t mp_builtin_sum(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_sum(uint n_args, const mp_obj_t *args) {
assert(1 <= n_args && n_args <= 2);
mp_obj_t value;
switch (n_args) {
@ -361,7 +361,7 @@ static mp_obj_t mp_builtin_sum(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum);
static mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
assert(n_args >= 1);
if (n_args > 1) {
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError,
@ -375,7 +375,7 @@ static mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *k
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj, 1, mp_builtin_sorted);
static mp_obj_t mp_builtin_str(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_str(mp_obj_t o_in) {
vstr_t *vstr = vstr_new();
mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, vstr, o_in, PRINT_STR);
mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
@ -386,7 +386,7 @@ static mp_obj_t mp_builtin_str(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_str_obj, mp_builtin_str);
// TODO: This should be type, this is just quick CPython compat hack
static mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) {
if (!MP_OBJ_IS_QSTR(args[0]) && !MP_OBJ_IS_TYPE(args[0], &str_type)) {
assert(0);
}
@ -397,7 +397,7 @@ static mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_bytes_obj, 1, 3, mp_builtin_bytes);
static mp_obj_t mp_builtin_id(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_id(mp_obj_t o_in) {
return mp_obj_new_int((machine_int_t)o_in);
}

View File

@ -19,7 +19,7 @@
#include "map.h"
#include "builtin.h"
static mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse_input_kind) {
STATIC mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse_input_kind) {
uint str_len;
const char *str = mp_obj_str_get_data(o_in, &str_len);
@ -51,13 +51,13 @@ static mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse
return rt_call_function_0(module_fun);
}
static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
return parse_compile_execute(o_in, MP_PARSE_EVAL_INPUT);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_eval_obj, mp_builtin_eval);
static mp_obj_t mp_builtin_exec(mp_obj_t o_in) {
STATIC mp_obj_t mp_builtin_exec(mp_obj_t o_in) {
return parse_compile_execute(o_in, MP_PARSE_FILE_INPUT);
}

View File

@ -16,15 +16,15 @@
// living in micropython module
#if MICROPY_MEM_STATS
static mp_obj_t mem_total() {
STATIC mp_obj_t mem_total() {
return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_total_bytes_allocated());
}
static mp_obj_t mem_current() {
STATIC mp_obj_t mem_current() {
return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_current_bytes_allocated());
}
static mp_obj_t mem_peak() {
STATIC mp_obj_t mem_peak() {
return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_peak_bytes_allocated());
}

View File

@ -188,14 +188,14 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) {
return 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);
void compile_node(compiler_t *comp, mp_parse_node_t pn);
static int comp_next_label(compiler_t *comp) {
STATIC int comp_next_label(compiler_t *comp) {
return comp->next_label++;
}
static scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) {
STATIC scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) {
scope_t *scope = scope_new(kind, pn, comp->source_file, rt_get_unique_code_id(), emit_options);
scope->parent = comp->scope_cur;
scope->next = NULL;
@ -211,7 +211,7 @@ static scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse
return scope;
}
static int list_len(mp_parse_node_t pn, int pn_kind) {
STATIC int list_len(mp_parse_node_t pn, int pn_kind) {
if (MP_PARSE_NODE_IS_NULL(pn)) {
return 0;
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
@ -226,7 +226,7 @@ static int list_len(mp_parse_node_t pn, int pn_kind) {
}
}
static void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, int pn_list_kind, void (*f)(compiler_t*, mp_parse_node_t)) {
STATIC void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, int pn_list_kind, void (*f)(compiler_t*, mp_parse_node_t)) {
if (MP_PARSE_NODE_IS_STRUCT(pn) && MP_PARSE_NODE_STRUCT_KIND((mp_parse_node_struct_t*)pn) == pn_list_kind) {
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
@ -238,7 +238,7 @@ static void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, int pn
}
}
static int list_get(mp_parse_node_t *pn, int pn_kind, mp_parse_node_t **nodes) {
STATIC int list_get(mp_parse_node_t *pn, int pn_kind, mp_parse_node_t **nodes) {
if (MP_PARSE_NODE_IS_NULL(*pn)) {
*nodes = NULL;
return 0;
@ -268,7 +268,7 @@ void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
#if MICROPY_EMIT_CPYTHON
static bool cpython_c_tuple_is_const(mp_parse_node_t pn) {
STATIC bool cpython_c_tuple_is_const(mp_parse_node_t pn) {
if (!MP_PARSE_NODE_IS_LEAF(pn)) {
return false;
}
@ -278,7 +278,7 @@ static bool cpython_c_tuple_is_const(mp_parse_node_t pn) {
return true;
}
static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, bool bytes) {
STATIC void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, bool bytes) {
uint len;
const byte *str = qstr_data(qstr, &len);
bool has_single_quote = false;
@ -318,7 +318,7 @@ static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, bool bytes) {
}
}
static void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vstr_t *vstr) {
STATIC void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vstr_t *vstr) {
assert(MP_PARSE_NODE_IS_LEAF(pn));
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
@ -340,7 +340,7 @@ static void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vst
}
}
static void cpython_c_tuple(compiler_t *comp, mp_parse_node_t pn, mp_parse_node_struct_t *pns_list) {
STATIC void cpython_c_tuple(compiler_t *comp, mp_parse_node_t pn, mp_parse_node_struct_t *pns_list) {
int n = 0;
if (pns_list != NULL) {
n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns_list);
@ -419,18 +419,18 @@ void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_tuple(comp, MP_PARSE_NODE_NULL, pns);
}
static bool node_is_const_false(mp_parse_node_t pn) {
STATIC bool node_is_const_false(mp_parse_node_t pn) {
return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_FALSE);
// untested: || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1);
}
static bool node_is_const_true(mp_parse_node_t pn) {
STATIC bool node_is_const_true(mp_parse_node_t pn) {
return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_TRUE) || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1);
}
#if MICROPY_EMIT_CPYTHON
// the is_nested variable is purely to match with CPython, which doesn't fully optimise not's
static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label, bool is_nested) {
STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label, bool is_nested) {
if (node_is_const_false(pn)) {
if (jump_if == false) {
EMIT_ARG(jump, label);
@ -488,7 +488,7 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if
}
#endif
static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) {
STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) {
#if MICROPY_EMIT_CPYTHON
cpython_c_if_cond(comp, pn, jump_if, label, false);
#else
@ -889,7 +889,7 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
}
// returns true if it was a built-in decorator (even if the built-in had an error)
static bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) {
STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) {
if (MP_PARSE_NODE_LEAF_ARG(name_nodes[0]) != MP_QSTR_micropython) {
return false;
}
@ -2066,7 +2066,7 @@ void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_generic_all_nodes(comp, pns);
}
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) {
// function to call is on top of stack
#if !MICROPY_EMIT_CPYTHON
@ -2498,7 +2498,7 @@ void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
typedef void (*compile_function_t)(compiler_t*, mp_parse_node_struct_t*);
static compile_function_t compile_function[] = {
STATIC compile_function_t compile_function[] = {
NULL,
#define nc NULL
#define c(f) compile_##f

View File

@ -49,7 +49,7 @@ void emit_bc_free(emit_t *emit) {
}
// all functions must go through this one to emit code info
static byte* emit_get_cur_to_write_code_info(emit_t* emit, int num_bytes_to_write) {
STATIC byte* emit_get_cur_to_write_code_info(emit_t* emit, int num_bytes_to_write) {
//printf("emit %d\n", num_bytes_to_write);
if (emit->pass < PASS_3) {
emit->code_info_offset += num_bytes_to_write;
@ -62,7 +62,7 @@ static byte* emit_get_cur_to_write_code_info(emit_t* emit, int num_bytes_to_writ
}
}
static void emit_write_code_info_qstr(emit_t* emit, qstr qstr) {
STATIC void emit_write_code_info_qstr(emit_t* emit, qstr qstr) {
byte* c = emit_get_cur_to_write_code_info(emit, 4);
// TODO variable length encoding for qstr
c[0] = qstr & 0xff;
@ -71,7 +71,7 @@ static void emit_write_code_info_qstr(emit_t* emit, qstr qstr) {
c[3] = (qstr >> 24) & 0xff;
}
static void emit_write_code_info_bytes_lines(emit_t* emit, uint bytes_to_skip, uint lines_to_skip) {
STATIC void emit_write_code_info_bytes_lines(emit_t* emit, uint bytes_to_skip, uint lines_to_skip) {
for (; bytes_to_skip > 31; bytes_to_skip -= 31) {
*emit_get_cur_to_write_code_info(emit, 1) = 31;
}
@ -82,7 +82,7 @@ static void emit_write_code_info_bytes_lines(emit_t* emit, uint bytes_to_skip, u
}
// all functions must go through this one to emit byte code
static byte* emit_get_cur_to_write_byte_code(emit_t* emit, int num_bytes_to_write) {
STATIC byte* emit_get_cur_to_write_byte_code(emit_t* emit, int num_bytes_to_write) {
//printf("emit %d\n", num_bytes_to_write);
if (emit->pass < PASS_3) {
emit->byte_code_offset += num_bytes_to_write;
@ -95,19 +95,19 @@ static byte* emit_get_cur_to_write_byte_code(emit_t* emit, int num_bytes_to_writ
}
}
static void emit_write_byte_code_byte(emit_t* emit, byte b1) {
STATIC void emit_write_byte_code_byte(emit_t* emit, byte b1) {
byte* c = emit_get_cur_to_write_byte_code(emit, 1);
c[0] = b1;
}
static void emit_write_byte_code_byte_byte(emit_t* emit, byte b1, uint b2) {
STATIC void emit_write_byte_code_byte_byte(emit_t* emit, byte b1, uint b2) {
assert((b2 & (~0xff)) == 0);
byte* c = emit_get_cur_to_write_byte_code(emit, 2);
c[0] = b1;
c[1] = b2;
}
static void emit_write_byte_code_uint(emit_t* emit, uint num) {
STATIC void emit_write_byte_code_uint(emit_t* emit, uint num) {
if (num <= 127) { // fits in 0x7f
// fit argument in single byte
byte* c = emit_get_cur_to_write_byte_code(emit, 1);
@ -124,7 +124,7 @@ static void emit_write_byte_code_uint(emit_t* emit, uint num) {
}
// integers (for small ints) are stored as 24 bits, in excess
static void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t num) {
STATIC void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t num) {
num += 0x800000;
assert(0 <= num && num <= 0xffffff);
byte* c = emit_get_cur_to_write_byte_code(emit, 4);
@ -134,25 +134,25 @@ static void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t n
c[3] = num >> 16;
}
static void emit_write_byte_code_byte_uint(emit_t* emit, byte b, uint num) {
STATIC void emit_write_byte_code_byte_uint(emit_t* emit, byte b, uint num) {
emit_write_byte_code_byte(emit, b);
emit_write_byte_code_uint(emit, num);
}
/* currently unused
static void emit_write_byte_code_byte_uint_uint(emit_t* emit, byte b, uint num1, uint num2) {
STATIC void emit_write_byte_code_byte_uint_uint(emit_t* emit, byte b, uint num1, uint num2) {
emit_write_byte_code_byte(emit, b);
emit_write_byte_code_byte_uint(emit, num1);
emit_write_byte_code_byte_uint(emit, num2);
}
*/
static void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) {
STATIC void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) {
emit_write_byte_code_byte_uint(emit, b, 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, int label) {
uint byte_code_offset;
if (emit->pass < PASS_3) {
byte_code_offset = 0;
@ -166,7 +166,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, int label) {
int byte_code_offset;
if (emit->pass < PASS_3) {
byte_code_offset = 0;
@ -179,10 +179,10 @@ static void emit_write_byte_code_byte_signed_label(emit_t* emit, byte b1, int la
c[2] = byte_code_offset >> 8;
}
static void emit_bc_set_native_types(emit_t *emit, bool do_native_types) {
STATIC void emit_bc_set_native_types(emit_t *emit, bool do_native_types) {
}
static void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
emit->pass = pass;
emit->stack_size = 0;
emit->last_emit_was_return_value = false;
@ -227,7 +227,7 @@ static void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
}
}
static void emit_bc_end_pass(emit_t *emit) {
STATIC void emit_bc_end_pass(emit_t *emit) {
// check stack is back to zero size
if (emit->stack_size != 0) {
printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
@ -254,11 +254,11 @@ int emit_bc_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
static void emit_bc_set_stack_size(emit_t *emit, int size) {
STATIC void emit_bc_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
}
static void emit_bc_set_source_line(emit_t *emit, int source_line) {
STATIC void emit_bc_set_source_line(emit_t *emit, int source_line) {
//printf("source: line %d -> %d offset %d -> %d\n", emit->last_source_line, source_line, emit->last_source_line_offset, emit->byte_code_offset);
#if MICROPY_ENABLE_SOURCE_LINE
if (source_line > emit->last_source_line) {
@ -272,18 +272,19 @@ static void emit_bc_set_source_line(emit_t *emit, int source_line) {
#endif
}
static void emit_bc_load_id(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_id(emit_t *emit, qstr qstr) {
emit_common_load_id(emit, &emit_bc_method_table, emit->scope, qstr);
}
static void emit_bc_store_id(emit_t *emit, qstr qstr) {
STATIC void emit_bc_store_id(emit_t *emit, qstr qstr) {
emit_common_store_id(emit, &emit_bc_method_table, emit->scope, qstr);
}
static void emit_bc_delete_id(emit_t *emit, qstr qstr) {
STATIC void emit_bc_delete_id(emit_t *emit, qstr qstr) {
emit_common_delete_id(emit, &emit_bc_method_table, emit->scope, qstr);
}
// TODO: module-polymorphic function (read: name clash if made global)
static void emit_pre(emit_t *emit, int stack_size_delta) {
emit->stack_size += stack_size_delta;
if (emit->stack_size > emit->scope->stack_size) {
@ -292,7 +293,7 @@ static void emit_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, int l) {
emit_pre(emit, 0);
assert(l < emit->max_num_labels);
if (emit->pass == PASS_2) {
@ -306,22 +307,22 @@ static void emit_bc_label_assign(emit_t *emit, int l) {
}
}
static void emit_bc_import_name(emit_t *emit, qstr qstr) {
STATIC void emit_bc_import_name(emit_t *emit, qstr qstr) {
emit_pre(emit, -1);
emit_write_byte_code_byte_qstr(emit, MP_BC_IMPORT_NAME, qstr);
}
static void emit_bc_import_from(emit_t *emit, qstr qstr) {
STATIC void emit_bc_import_from(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_IMPORT_FROM, qstr);
}
static void emit_bc_import_star(emit_t *emit) {
STATIC void emit_bc_import_star(emit_t *emit) {
emit_pre(emit, -1);
emit_write_byte_code_byte(emit, MP_BC_IMPORT_STAR);
}
static void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
STATIC void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
emit_pre(emit, 1);
switch (tok) {
case MP_TOKEN_KW_FALSE: emit_write_byte_code_byte(emit, MP_BC_LOAD_CONST_FALSE); break;
@ -332,27 +333,27 @@ static void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
}
}
static void emit_bc_load_const_small_int(emit_t *emit, machine_int_t arg) {
STATIC void emit_bc_load_const_small_int(emit_t *emit, machine_int_t arg) {
emit_pre(emit, 1);
emit_write_byte_code_byte_int(emit, MP_BC_LOAD_CONST_SMALL_INT, arg);
}
static void emit_bc_load_const_int(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_const_int(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_CONST_INT, qstr);
}
static void emit_bc_load_const_dec(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_const_dec(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_CONST_DEC, qstr);
}
static void emit_bc_load_const_id(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_const_id(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_CONST_ID, qstr);
}
static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
STATIC void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
emit_pre(emit, 1);
if (bytes) {
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_CONST_BYTES, qstr);
@ -361,12 +362,12 @@ static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
}
}
static void emit_bc_load_const_verbatim_str(emit_t *emit, const char *str) {
STATIC void emit_bc_load_const_verbatim_str(emit_t *emit, const char *str) {
// not needed/supported for BC
assert(0);
}
static void emit_bc_load_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_load_fast(emit_t *emit, qstr qstr, int local_num) {
assert(local_num >= 0);
emit_pre(emit, 1);
switch (local_num) {
@ -377,42 +378,42 @@ static void emit_bc_load_fast(emit_t *emit, qstr qstr, int local_num) {
}
}
static void emit_bc_load_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_load_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1);
emit_write_byte_code_byte_uint(emit, MP_BC_LOAD_DEREF, local_num);
}
static void emit_bc_load_closure(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_load_closure(emit_t *emit, qstr qstr, int local_num) {
// not needed/supported for BC
assert(0);
}
static void emit_bc_load_name(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_name(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_NAME, qstr);
}
static void emit_bc_load_global(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_global(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_GLOBAL, qstr);
}
static void emit_bc_load_attr(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_attr(emit_t *emit, qstr qstr) {
emit_pre(emit, 0);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_ATTR, qstr);
}
static void emit_bc_load_method(emit_t *emit, qstr qstr) {
STATIC void emit_bc_load_method(emit_t *emit, qstr qstr) {
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_METHOD, qstr);
}
static void emit_bc_load_build_class(emit_t *emit) {
STATIC void emit_bc_load_build_class(emit_t *emit) {
emit_pre(emit, 1);
emit_write_byte_code_byte(emit, MP_BC_LOAD_BUILD_CLASS);
}
static void emit_bc_store_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_store_fast(emit_t *emit, qstr qstr, int local_num) {
assert(local_num >= 0);
emit_pre(emit, -1);
switch (local_num) {
@ -423,124 +424,124 @@ static void emit_bc_store_fast(emit_t *emit, qstr qstr, int local_num) {
}
}
static void emit_bc_store_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_store_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, -1);
emit_write_byte_code_byte_uint(emit, MP_BC_STORE_DEREF, local_num);
}
static void emit_bc_store_name(emit_t *emit, qstr qstr) {
STATIC void emit_bc_store_name(emit_t *emit, qstr qstr) {
emit_pre(emit, -1);
emit_write_byte_code_byte_qstr(emit, MP_BC_STORE_NAME, qstr);
}
static void emit_bc_store_global(emit_t *emit, qstr qstr) {
STATIC void emit_bc_store_global(emit_t *emit, qstr qstr) {
emit_pre(emit, -1);
emit_write_byte_code_byte_qstr(emit, MP_BC_STORE_GLOBAL, qstr);
}
static void emit_bc_store_attr(emit_t *emit, qstr qstr) {
STATIC void emit_bc_store_attr(emit_t *emit, qstr qstr) {
emit_pre(emit, -2);
emit_write_byte_code_byte_qstr(emit, MP_BC_STORE_ATTR, qstr);
}
static void emit_bc_store_subscr(emit_t *emit) {
STATIC void emit_bc_store_subscr(emit_t *emit) {
emit_pre(emit, -3);
emit_write_byte_code_byte(emit, MP_BC_STORE_SUBSCR);
}
static void emit_bc_store_locals(emit_t *emit) {
STATIC void emit_bc_store_locals(emit_t *emit) {
// not needed
emit_pre(emit, -1);
emit_write_byte_code_byte(emit, MP_BC_POP_TOP);
}
static void emit_bc_delete_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_delete_fast(emit_t *emit, qstr qstr, int local_num) {
assert(local_num >= 0);
emit_pre(emit, 0);
emit_write_byte_code_byte_uint(emit, MP_BC_DELETE_FAST_N, local_num);
}
static void emit_bc_delete_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_bc_delete_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 0);
emit_write_byte_code_byte_qstr(emit, MP_BC_DELETE_DEREF, local_num);
}
static void emit_bc_delete_name(emit_t *emit, qstr qstr) {
STATIC void emit_bc_delete_name(emit_t *emit, qstr qstr) {
emit_pre(emit, 0);
emit_write_byte_code_byte_qstr(emit, MP_BC_DELETE_NAME, qstr);
}
static void emit_bc_delete_global(emit_t *emit, qstr qstr) {
STATIC void emit_bc_delete_global(emit_t *emit, qstr qstr) {
emit_pre(emit, 0);
emit_write_byte_code_byte_qstr(emit, MP_BC_DELETE_GLOBAL, qstr);
}
static void emit_bc_delete_attr(emit_t *emit, qstr qstr) {
STATIC void emit_bc_delete_attr(emit_t *emit, qstr qstr) {
emit_pre(emit, -1);
emit_write_byte_code_byte_qstr(emit, MP_BC_DELETE_ATTR, qstr);
}
static void emit_bc_delete_subscr(emit_t *emit) {
STATIC void emit_bc_delete_subscr(emit_t *emit) {
emit_pre(emit, -2);
emit_write_byte_code_byte(emit, MP_BC_DELETE_SUBSCR);
}
static void emit_bc_dup_top(emit_t *emit) {
STATIC void emit_bc_dup_top(emit_t *emit) {
emit_pre(emit, 1);
emit_write_byte_code_byte(emit, MP_BC_DUP_TOP);
}
static void emit_bc_dup_top_two(emit_t *emit) {
STATIC void emit_bc_dup_top_two(emit_t *emit) {
emit_pre(emit, 2);
emit_write_byte_code_byte(emit, MP_BC_DUP_TOP_TWO);
}
static void emit_bc_pop_top(emit_t *emit) {
STATIC void emit_bc_pop_top(emit_t *emit) {
emit_pre(emit, -1);
emit_write_byte_code_byte(emit, MP_BC_POP_TOP);
}
static void emit_bc_rot_two(emit_t *emit) {
STATIC void emit_bc_rot_two(emit_t *emit) {
emit_pre(emit, 0);
emit_write_byte_code_byte(emit, MP_BC_ROT_TWO);
}
static void emit_bc_rot_three(emit_t *emit) {
STATIC void emit_bc_rot_three(emit_t *emit) {
emit_pre(emit, 0);
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, int label) {
emit_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, int label) {
emit_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, int label) {
emit_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, int label) {
emit_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, int label) {
emit_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, int label) {
emit_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, int label, int except_depth) {
if (except_depth == 0) {
emit_bc_jump(emit, label);
} else {
@ -550,56 +551,56 @@ 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, int label) {
emit_pre(emit, 7);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label);
}
static void emit_bc_with_cleanup(emit_t *emit) {
STATIC void emit_bc_with_cleanup(emit_t *emit) {
emit_pre(emit, -7);
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, int label) {
emit_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, int label) {
emit_pre(emit, 6);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_FINALLY, label);
}
static void emit_bc_end_finally(emit_t *emit) {
STATIC void emit_bc_end_finally(emit_t *emit) {
emit_pre(emit, -1);
emit_write_byte_code_byte(emit, MP_BC_END_FINALLY);
}
static void emit_bc_get_iter(emit_t *emit) {
STATIC void emit_bc_get_iter(emit_t *emit) {
emit_pre(emit, 0);
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, int label) {
emit_pre(emit, 1);
emit_write_byte_code_byte_unsigned_label(emit, MP_BC_FOR_ITER, label);
}
static void emit_bc_for_iter_end(emit_t *emit) {
STATIC void emit_bc_for_iter_end(emit_t *emit) {
emit_pre(emit, -1);
}
static void emit_bc_pop_block(emit_t *emit) {
STATIC void emit_bc_pop_block(emit_t *emit) {
emit_pre(emit, 0);
emit_write_byte_code_byte(emit, MP_BC_POP_BLOCK);
}
static void emit_bc_pop_except(emit_t *emit) {
STATIC void emit_bc_pop_except(emit_t *emit) {
emit_pre(emit, 0);
emit_write_byte_code_byte(emit, MP_BC_POP_EXCEPT);
}
static void emit_bc_unary_op(emit_t *emit, rt_unary_op_t op) {
STATIC void emit_bc_unary_op(emit_t *emit, rt_unary_op_t op) {
if (op == RT_UNARY_OP_NOT) {
emit_pre(emit, 0);
emit_write_byte_code_byte_byte(emit, MP_BC_UNARY_OP, RT_UNARY_OP_BOOL);
@ -611,7 +612,7 @@ static void emit_bc_unary_op(emit_t *emit, rt_unary_op_t op) {
}
}
static void emit_bc_binary_op(emit_t *emit, rt_binary_op_t op) {
STATIC void emit_bc_binary_op(emit_t *emit, rt_binary_op_t op) {
bool invert = false;
if (op == RT_BINARY_OP_NOT_IN) {
invert = true;
@ -628,72 +629,72 @@ static void emit_bc_binary_op(emit_t *emit, rt_binary_op_t op) {
}
}
static void emit_bc_build_tuple(emit_t *emit, int n_args) {
STATIC void emit_bc_build_tuple(emit_t *emit, int n_args) {
assert(n_args >= 0);
emit_pre(emit, 1 - n_args);
emit_write_byte_code_byte_uint(emit, MP_BC_BUILD_TUPLE, n_args);
}
static void emit_bc_build_list(emit_t *emit, int n_args) {
STATIC void emit_bc_build_list(emit_t *emit, int n_args) {
assert(n_args >= 0);
emit_pre(emit, 1 - n_args);
emit_write_byte_code_byte_uint(emit, MP_BC_BUILD_LIST, n_args);
}
static void emit_bc_list_append(emit_t *emit, int list_stack_index) {
STATIC void emit_bc_list_append(emit_t *emit, int list_stack_index) {
assert(list_stack_index >= 0);
emit_pre(emit, -1);
emit_write_byte_code_byte_uint(emit, MP_BC_LIST_APPEND, list_stack_index);
}
static void emit_bc_build_map(emit_t *emit, int n_args) {
STATIC void emit_bc_build_map(emit_t *emit, int n_args) {
assert(n_args >= 0);
emit_pre(emit, 1);
emit_write_byte_code_byte_uint(emit, MP_BC_BUILD_MAP, n_args);
}
static void emit_bc_store_map(emit_t *emit) {
STATIC void emit_bc_store_map(emit_t *emit) {
emit_pre(emit, -2);
emit_write_byte_code_byte(emit, MP_BC_STORE_MAP);
}
static void emit_bc_map_add(emit_t *emit, int map_stack_index) {
STATIC void emit_bc_map_add(emit_t *emit, int map_stack_index) {
assert(map_stack_index >= 0);
emit_pre(emit, -2);
emit_write_byte_code_byte_uint(emit, MP_BC_MAP_ADD, map_stack_index);
}
static void emit_bc_build_set(emit_t *emit, int n_args) {
STATIC void emit_bc_build_set(emit_t *emit, int n_args) {
assert(n_args >= 0);
emit_pre(emit, 1 - n_args);
emit_write_byte_code_byte_uint(emit, MP_BC_BUILD_SET, n_args);
}
static void emit_bc_set_add(emit_t *emit, int set_stack_index) {
STATIC void emit_bc_set_add(emit_t *emit, int set_stack_index) {
assert(set_stack_index >= 0);
emit_pre(emit, -1);
emit_write_byte_code_byte_uint(emit, MP_BC_SET_ADD, set_stack_index);
}
static void emit_bc_build_slice(emit_t *emit, int n_args) {
STATIC void emit_bc_build_slice(emit_t *emit, int n_args) {
assert(n_args >= 0);
emit_pre(emit, 1 - n_args);
emit_write_byte_code_byte_uint(emit, MP_BC_BUILD_SLICE, n_args);
}
static void emit_bc_unpack_sequence(emit_t *emit, int n_args) {
STATIC void emit_bc_unpack_sequence(emit_t *emit, int n_args) {
assert(n_args >= 0);
emit_pre(emit, -1 + n_args);
emit_write_byte_code_byte_uint(emit, MP_BC_UNPACK_SEQUENCE, n_args);
}
static void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) {
STATIC void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) {
assert(n_left >=0 && n_right >= 0);
emit_pre(emit, -1 + n_left + n_right + 1);
emit_write_byte_code_byte_uint(emit, MP_BC_UNPACK_EX, n_left | (n_right << 8));
}
static void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
assert(n_dict_params == 0);
if (n_default_params == 0) {
emit_pre(emit, 1);
@ -705,13 +706,13 @@ static void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_param
}
}
static void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
assert(n_default_params == 0 && n_dict_params == 0);
emit_pre(emit, 0);
emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id);
}
static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
STATIC void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
int s = 0;
if (have_star_arg) {
s += 1;
@ -737,7 +738,7 @@ static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword,
emit_write_byte_code_byte_uint(emit, op, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints
}
static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
STATIC void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
int s = 0;
if (have_star_arg) {
s += 1;
@ -763,19 +764,19 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, b
emit_write_byte_code_byte_uint(emit, op, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints
}
static void emit_bc_return_value(emit_t *emit) {
STATIC void emit_bc_return_value(emit_t *emit) {
emit_pre(emit, -1);
emit->last_emit_was_return_value = true;
emit_write_byte_code_byte(emit, MP_BC_RETURN_VALUE);
}
static void emit_bc_raise_varargs(emit_t *emit, int n_args) {
STATIC void emit_bc_raise_varargs(emit_t *emit, int n_args) {
assert(0 <= n_args && n_args <= 2);
emit_pre(emit, -n_args);
emit_write_byte_code_byte_byte(emit, MP_BC_RAISE_VARARGS, n_args);
}
static void emit_bc_yield_value(emit_t *emit) {
STATIC void emit_bc_yield_value(emit_t *emit) {
emit_pre(emit, 0);
if (emit->pass == PASS_2) {
emit->scope->flags |= SCOPE_FLAG_GENERATOR;
@ -783,7 +784,7 @@ static void emit_bc_yield_value(emit_t *emit) {
emit_write_byte_code_byte(emit, MP_BC_YIELD_VALUE);
}
static void emit_bc_yield_from(emit_t *emit) {
STATIC void emit_bc_yield_from(emit_t *emit) {
emit_pre(emit, -1);
if (emit->pass == PASS_2) {
emit->scope->flags |= SCOPE_FLAG_GENERATOR;

View File

@ -36,10 +36,10 @@ emit_t *emit_cpython_new(uint max_num_labels) {
return emit;
}
static void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) {
STATIC void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) {
}
static void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
STATIC void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
emit->pass = pass;
emit->byte_code_offset = 0;
emit->stack_size = 0;
@ -50,40 +50,41 @@ static void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope)
}
}
static void emit_cpy_end_pass(emit_t *emit) {
STATIC void emit_cpy_end_pass(emit_t *emit) {
// check stack is back to zero size
if (emit->stack_size != 0) {
printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
}
}
static bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
STATIC bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value;
}
static int emit_cpy_get_stack_size(emit_t *emit) {
STATIC int emit_cpy_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
static void emit_cpy_set_stack_size(emit_t *emit, int size) {
STATIC void emit_cpy_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
}
static void emit_cpy_set_source_line(emit_t *emit, int source_line) {
STATIC void emit_cpy_set_source_line(emit_t *emit, int source_line) {
}
static void emit_cpy_load_id(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_id(emit_t *emit, qstr qstr) {
emit_common_load_id(emit, &emit_cpython_method_table, emit->scope, qstr);
}
static void emit_cpy_store_id(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_store_id(emit_t *emit, qstr qstr) {
emit_common_store_id(emit, &emit_cpython_method_table, emit->scope, qstr);
}
static void emit_cpy_delete_id(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_delete_id(emit_t *emit, qstr qstr) {
emit_common_delete_id(emit, &emit_cpython_method_table, emit->scope, qstr);
}
// TODO: module-polymorphic function (read: name clash if made global)
static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
emit->stack_size += stack_size_delta;
if (emit->stack_size > emit->scope->stack_size) {
@ -100,7 +101,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, int l) {
emit_pre(emit, 0, 0);
assert(l < emit->max_num_labels);
if (emit->pass == PASS_2) {
@ -114,28 +115,28 @@ static void emit_cpy_label_assign(emit_t *emit, int l) {
}
}
static void emit_cpy_import_name(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_import_name(emit_t *emit, qstr qstr) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("IMPORT_NAME %s\n", qstr_str(qstr));
}
}
static void emit_cpy_import_from(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_import_from(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("IMPORT_FROM %s\n", qstr_str(qstr));
}
}
static void emit_cpy_import_star(emit_t *emit) {
STATIC void emit_cpy_import_star(emit_t *emit) {
emit_pre(emit, -1, 1);
if (emit->pass == PASS_3) {
printf("IMPORT_STAR\n");
}
}
static void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
STATIC void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST ");
@ -149,35 +150,35 @@ static void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
}
}
static void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) {
STATIC void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST " INT_FMT "\n", arg);
}
}
static void emit_cpy_load_const_int(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_const_int(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST %s\n", qstr_str(qstr));
}
}
static void emit_cpy_load_const_dec(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_const_dec(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST %s\n", qstr_str(qstr));
}
}
static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST '%s'\n", qstr_str(qstr));
}
}
static void print_quoted_str(qstr qstr, bool bytes) {
STATIC void print_quoted_str(qstr qstr, bool bytes) {
const char *str = qstr_str(qstr);
int len = strlen(str);
bool has_single_quote = false;
@ -214,7 +215,7 @@ static void print_quoted_str(qstr qstr, bool bytes) {
printf("%c", quote_char);
}
static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
STATIC void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST ");
@ -223,193 +224,193 @@ static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
}
}
static void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST %s\n", str);
}
}
static void emit_cpy_load_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_FAST %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_DEREF %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_load_name(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_name(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_NAME %s\n", qstr_str(qstr));
}
}
static void emit_cpy_load_global(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_global(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_GLOBAL %s\n", qstr_str(qstr));
}
}
static void emit_cpy_load_attr(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_attr(emit_t *emit, qstr qstr) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
printf("LOAD_ATTR %s\n", qstr_str(qstr));
}
}
static void emit_cpy_load_method(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_load_method(emit_t *emit, qstr qstr) {
emit_cpy_load_attr(emit, qstr);
}
static void emit_cpy_load_build_class(emit_t *emit) {
STATIC void emit_cpy_load_build_class(emit_t *emit) {
emit_pre(emit, 1, 1);
if (emit->pass == PASS_3) {
printf("LOAD_BUILD_CLASS\n");
}
}
static void emit_cpy_store_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_store_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("STORE_FAST %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("STORE_DEREF %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_store_name(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_store_name(emit_t *emit, qstr qstr) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("STORE_NAME %s\n", qstr_str(qstr));
}
}
static void emit_cpy_store_global(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_store_global(emit_t *emit, qstr qstr) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("STORE_GLOBAL %s\n", qstr_str(qstr));
}
}
static void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
emit_pre(emit, -2, 3);
if (emit->pass == PASS_3) {
printf("STORE_ATTR %s\n", qstr_str(qstr));
}
}
static void emit_cpy_store_subscr(emit_t *emit) {
STATIC void emit_cpy_store_subscr(emit_t *emit) {
emit_pre(emit, -3, 1);
if (emit->pass == PASS_3) {
printf("STORE_SUBSCR\n");
}
}
static void emit_cpy_store_locals(emit_t *emit) {
STATIC void emit_cpy_store_locals(emit_t *emit) {
emit_pre(emit, -1, 1);
if (emit->pass == PASS_3) {
printf("STORE_LOCALS\n");
}
}
static void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
printf("DELETE_FAST %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
printf("DELETE_DEREF %d %s\n", local_num, qstr_str(qstr));
}
}
static void emit_cpy_delete_name(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_delete_name(emit_t *emit, qstr qstr) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
printf("DELETE_NAME %s\n", qstr_str(qstr));
}
}
static void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
printf("DELETE_GLOBAL %s\n", qstr_str(qstr));
}
}
static void emit_cpy_delete_attr(emit_t *emit, qstr qstr) {
STATIC void emit_cpy_delete_attr(emit_t *emit, qstr qstr) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("DELETE_ATTR %s\n", qstr_str(qstr));
}
}
static void emit_cpy_delete_subscr(emit_t *emit) {
STATIC void emit_cpy_delete_subscr(emit_t *emit) {
emit_pre(emit, -2, 1);
if (emit->pass == PASS_3) {
printf("DELETE_SUBSCR\n");
}
}
static void emit_cpy_dup_top(emit_t *emit) {
STATIC void emit_cpy_dup_top(emit_t *emit) {
emit_pre(emit, 1, 1);
if (emit->pass == PASS_3) {
printf("DUP_TOP\n");
}
}
static void emit_cpy_dup_top_two(emit_t *emit) {
STATIC void emit_cpy_dup_top_two(emit_t *emit) {
emit_pre(emit, 2, 1);
if (emit->pass == PASS_3) {
printf("DUP_TOP_TWO\n");
}
}
static void emit_cpy_pop_top(emit_t *emit) {
STATIC void emit_cpy_pop_top(emit_t *emit) {
emit_pre(emit, -1, 1);
if (emit->pass == PASS_3) {
printf("POP_TOP\n");
}
}
static void emit_cpy_rot_two(emit_t *emit) {
STATIC void emit_cpy_rot_two(emit_t *emit) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
printf("ROT_TWO\n");
}
}
static void emit_cpy_rot_three(emit_t *emit) {
STATIC void emit_cpy_rot_three(emit_t *emit) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
printf("ROT_THREE\n");
}
}
static void emit_cpy_jump(emit_t *emit, int label) {
STATIC void emit_cpy_jump(emit_t *emit, int label) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
int dest = emit->label_offsets[label];
@ -421,49 +422,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, int 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, int 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, int 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, int 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, int 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, int 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, int label, int except_depth) {
if (except_depth == 0) {
emit_cpy_jump(emit, label);
} else {
@ -474,74 +475,74 @@ 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, int label) {
emit_pre(emit, 7, 3);
if (emit->pass == PASS_3) {
printf("SETUP_WITH %d\n", emit->label_offsets[label]);
}
}
static void emit_cpy_with_cleanup(emit_t *emit) {
STATIC void emit_cpy_with_cleanup(emit_t *emit) {
emit_pre(emit, -7, 1);
if (emit->pass == PASS_3) {
printf("WITH_CLEANUP\n");
}
}
static void emit_cpy_setup_except(emit_t *emit, int label) {
STATIC void emit_cpy_setup_except(emit_t *emit, int 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, int label) {
emit_pre(emit, 6, 3);
if (emit->pass == PASS_3) {
printf("SETUP_FINALLY %d\n", emit->label_offsets[label]);
}
}
static void emit_cpy_end_finally(emit_t *emit) {
STATIC void emit_cpy_end_finally(emit_t *emit) {
emit_pre(emit, -1, 1);
if (emit->pass == PASS_3) {
printf("END_FINALLY\n");
}
}
static void emit_cpy_get_iter(emit_t *emit) {
STATIC void emit_cpy_get_iter(emit_t *emit) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
printf("GET_ITER\n");
}
}
static void emit_cpy_for_iter(emit_t *emit, int label) {
STATIC void emit_cpy_for_iter(emit_t *emit, int label) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("FOR_ITER %d\n", emit->label_offsets[label]);
}
}
static void emit_cpy_for_iter_end(emit_t *emit) {
STATIC void emit_cpy_for_iter_end(emit_t *emit) {
emit_pre(emit, -1, 0);
}
static void emit_cpy_pop_block(emit_t *emit) {
STATIC void emit_cpy_pop_block(emit_t *emit) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
printf("POP_BLOCK\n");
}
}
static void emit_cpy_pop_except(emit_t *emit) {
STATIC void emit_cpy_pop_except(emit_t *emit) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
printf("POP_EXCEPT\n");
}
}
static void emit_cpy_unary_op(emit_t *emit, rt_unary_op_t op) {
STATIC void emit_cpy_unary_op(emit_t *emit, rt_unary_op_t op) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
switch (op) {
@ -554,7 +555,7 @@ static void emit_cpy_unary_op(emit_t *emit, rt_unary_op_t op) {
}
}
static void emit_cpy_binary_op(emit_t *emit, rt_binary_op_t op) {
STATIC void emit_cpy_binary_op(emit_t *emit, rt_binary_op_t op) {
if (op <= RT_BINARY_OP_INPLACE_POWER) {
// CPython uses a byte code for each binary op
emit_pre(emit, -1, 1);
@ -605,84 +606,84 @@ static void emit_cpy_binary_op(emit_t *emit, rt_binary_op_t op) {
}
}
static void emit_cpy_build_tuple(emit_t *emit, int n_args) {
STATIC void emit_cpy_build_tuple(emit_t *emit, int n_args) {
emit_pre(emit, 1 - n_args, 3);
if (emit->pass == PASS_3) {
printf("BUILD_TUPLE %d\n", n_args);
}
}
static void emit_cpy_build_list(emit_t *emit, int n_args) {
STATIC void emit_cpy_build_list(emit_t *emit, int n_args) {
emit_pre(emit, 1 - n_args, 3);
if (emit->pass == PASS_3) {
printf("BUILD_LIST %d\n", n_args);
}
}
static void emit_cpy_list_append(emit_t *emit, int list_index) {
STATIC void emit_cpy_list_append(emit_t *emit, int list_index) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("LIST_APPEND %d\n", list_index);
}
}
static void emit_cpy_build_map(emit_t *emit, int n_args) {
STATIC void emit_cpy_build_map(emit_t *emit, int n_args) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("BUILD_MAP %d\n", n_args);
}
}
static void emit_cpy_store_map(emit_t *emit) {
STATIC void emit_cpy_store_map(emit_t *emit) {
emit_pre(emit, -2, 1);
if (emit->pass == PASS_3) {
printf("STORE_MAP\n");
}
}
static void emit_cpy_map_add(emit_t *emit, int map_index) {
STATIC void emit_cpy_map_add(emit_t *emit, int map_index) {
emit_pre(emit, -2, 3);
if (emit->pass == PASS_3) {
printf("MAP_ADD %d\n", map_index);
}
}
static void emit_cpy_build_set(emit_t *emit, int n_args) {
STATIC void emit_cpy_build_set(emit_t *emit, int n_args) {
emit_pre(emit, 1 - n_args, 3);
if (emit->pass == PASS_3) {
printf("BUILD_SET %d\n", n_args);
}
}
static void emit_cpy_set_add(emit_t *emit, int set_index) {
STATIC void emit_cpy_set_add(emit_t *emit, int set_index) {
emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) {
printf("SET_ADD %d\n", set_index);
}
}
static void emit_cpy_build_slice(emit_t *emit, int n_args) {
STATIC void emit_cpy_build_slice(emit_t *emit, int n_args) {
emit_pre(emit, 1 - n_args, 3);
if (emit->pass == PASS_3) {
printf("BUILD_SLICE %d\n", n_args);
}
}
static void emit_cpy_unpack_sequence(emit_t *emit, int n_args) {
STATIC void emit_cpy_unpack_sequence(emit_t *emit, int n_args) {
emit_pre(emit, -1 + n_args, 3);
if (emit->pass == PASS_3) {
printf("UNPACK_SEQUENCE %d\n", n_args);
}
}
static void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) {
STATIC void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) {
emit_pre(emit, -1 + n_left + n_right + 1, 3);
if (emit->pass == PASS_3) {
printf("UNPACK_EX %d\n", n_left | (n_right << 8));
}
}
static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
STATIC void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
int s = 0;
if (have_star_arg) {
s += 1;
@ -709,11 +710,11 @@ static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword
}
}
static void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
STATIC void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
emit_cpy_call_function(emit, n_positional, n_keyword, have_star_arg, have_dbl_star_arg);
}
static void emit_cpy_return_value(emit_t *emit) {
STATIC void emit_cpy_return_value(emit_t *emit) {
emit_pre(emit, -1, 1);
emit->last_emit_was_return_value = true;
if (emit->pass == PASS_3) {
@ -721,14 +722,14 @@ static void emit_cpy_return_value(emit_t *emit) {
}
}
static void emit_cpy_raise_varargs(emit_t *emit, int n_args) {
STATIC void emit_cpy_raise_varargs(emit_t *emit, int n_args) {
emit_pre(emit, -n_args, 3);
if (emit->pass == PASS_3) {
printf("RAISE_VARARGS %d\n", n_args);
}
}
static void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST code %s\n", qstr_str(qstr));
@ -759,7 +760,7 @@ static void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
}
}
static void emit_cpy_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
load_cpy_const_code_and_name(emit, scope->simple_name);
emit_pre(emit, -1 - n_default_params - 2 * n_dict_params, 3);
if (emit->pass == PASS_3) {
@ -767,7 +768,7 @@ static void emit_cpy_make_function(emit_t *emit, scope_t *scope, int n_dict_para
}
}
static void emit_cpy_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
load_cpy_const_code_and_name(emit, scope->simple_name);
emit_pre(emit, -2 - n_default_params - 2 * n_dict_params, 3);
if (emit->pass == PASS_3) {
@ -775,7 +776,7 @@ static void emit_cpy_make_closure(emit_t *emit, scope_t *scope, int n_dict_param
}
}
static void emit_cpy_yield_value(emit_t *emit) {
STATIC void emit_cpy_yield_value(emit_t *emit) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_2) {
emit->scope->flags |= SCOPE_FLAG_GENERATOR;
@ -785,7 +786,7 @@ static void emit_cpy_yield_value(emit_t *emit) {
}
}
static void emit_cpy_yield_from(emit_t *emit) {
STATIC void emit_cpy_yield_from(emit_t *emit) {
emit_pre(emit, -1, 1);
if (emit->pass == PASS_2) {
emit->scope->flags |= SCOPE_FLAG_GENERATOR;

View File

@ -40,14 +40,14 @@ void emit_inline_thumb_free(emit_inline_asm_t *emit) {
m_del_obj(emit_inline_asm_t, emit);
}
static void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope) {
STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope) {
emit->pass = pass;
emit->scope = scope;
asm_thumb_start_pass(emit->as, pass);
asm_thumb_entry(emit->as, 0);
}
static void emit_inline_thumb_end_pass(emit_inline_asm_t *emit) {
STATIC void emit_inline_thumb_end_pass(emit_inline_asm_t *emit) {
asm_thumb_exit(emit->as);
asm_thumb_end_pass(emit->as);
@ -57,7 +57,7 @@ static void emit_inline_thumb_end_pass(emit_inline_asm_t *emit) {
}
}
static int emit_inline_thumb_count_params(emit_inline_asm_t *emit, int n_params, mp_parse_node_t *pn_params) {
STATIC int emit_inline_thumb_count_params(emit_inline_asm_t *emit, int n_params, mp_parse_node_t *pn_params) {
if (n_params > 4) {
printf("SyntaxError: can only have up to 4 parameters to inline thumb assembly\n");
return 0;
@ -76,13 +76,13 @@ 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, int 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);
}
static bool check_n_arg(qstr op, int n_args, int wanted_n_args) {
STATIC bool check_n_arg(qstr op, int n_args, int wanted_n_args) {
if (wanted_n_args == n_args) {
return true;
} else {
@ -91,7 +91,7 @@ static bool check_n_arg(qstr op, int n_args, int wanted_n_args) {
}
}
static uint get_arg_rlo(qstr op, mp_parse_node_t *pn_args, int wanted_arg_num) {
STATIC uint get_arg_rlo(qstr op, mp_parse_node_t *pn_args, int wanted_arg_num) {
if (!MP_PARSE_NODE_IS_ID(pn_args[wanted_arg_num])) {
printf("SyntaxError: '%s' expects a register in position %d\n", qstr_str(op), wanted_arg_num);
return 0;
@ -105,7 +105,7 @@ static uint get_arg_rlo(qstr op, mp_parse_node_t *pn_args, int wanted_arg_num) {
return reg_str[1] - '0';
}
static int get_arg_i(qstr op, mp_parse_node_t *pn_args, int wanted_arg_num, int fit_mask) {
STATIC int get_arg_i(qstr op, mp_parse_node_t *pn_args, int wanted_arg_num, int fit_mask) {
if (!MP_PARSE_NODE_IS_SMALL_INT(pn_args[wanted_arg_num])) {
printf("SyntaxError: '%s' expects an integer in position %d\n", qstr_str(op), wanted_arg_num);
return 0;
@ -118,7 +118,7 @@ static int get_arg_i(qstr op, mp_parse_node_t *pn_args, int wanted_arg_num, int
return i;
}
static int get_arg_label(emit_inline_asm_t *emit, qstr op, mp_parse_node_t *pn_args, int wanted_arg_num) {
STATIC int get_arg_label(emit_inline_asm_t *emit, qstr op, mp_parse_node_t *pn_args, int wanted_arg_num) {
if (!MP_PARSE_NODE_IS_ID(pn_args[wanted_arg_num])) {
printf("SyntaxError: '%s' expects a label in position %d\n", qstr_str(op), wanted_arg_num);
return 0;
@ -136,7 +136,7 @@ static int get_arg_label(emit_inline_asm_t *emit, qstr op, mp_parse_node_t *pn_a
return 0;
}
static void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, mp_parse_node_t *pn_args) {
STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, mp_parse_node_t *pn_args) {
// TODO perhaps make two tables:
// one_args =
// "b", LAB, asm_thumb_b_n,

View File

@ -155,11 +155,11 @@ void EXPORT_FUN(free)(emit_t *emit) {
m_del_obj(emit_t, emit);
}
static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) {
STATIC void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) {
emit->do_viper_types = do_viper_types;
}
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) {
emit->pass = pass;
emit->stack_start = 0;
emit->stack_size = 0;
@ -255,7 +255,7 @@ static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
#endif
}
static void emit_native_end_pass(emit_t *emit) {
STATIC void emit_native_end_pass(emit_t *emit) {
#if N_X64
if (!emit->last_emit_was_return_value) {
asm_x64_exit(emit->as);
@ -284,22 +284,22 @@ static void emit_native_end_pass(emit_t *emit) {
}
}
static bool emit_native_last_emit_was_return_value(emit_t *emit) {
STATIC bool emit_native_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value;
}
static int emit_native_get_stack_size(emit_t *emit) {
STATIC int emit_native_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
static void emit_native_set_stack_size(emit_t *emit, int size) {
STATIC void emit_native_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
}
static void emit_native_set_source_line(emit_t *emit, int source_line) {
STATIC void emit_native_set_source_line(emit_t *emit, int source_line) {
}
static void adjust_stack(emit_t *emit, int stack_size_delta) {
STATIC void adjust_stack(emit_t *emit, int stack_size_delta) {
emit->stack_size += stack_size_delta;
assert(emit->stack_size >= 0);
if (emit->pass > PASS_1 && emit->stack_size > emit->scope->stack_size) {
@ -308,13 +308,14 @@ static void adjust_stack(emit_t *emit, int stack_size_delta) {
}
/*
static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
STATIC void emit_pre_raw(emit_t *emit, int stack_size_delta) {
adjust_stack(emit, stack_size_delta);
emit->last_emit_was_return_value = false;
}
*/
// this must be called at start of emit functions
// TODO: module-polymorphic function (read: name clash if made global)
static void emit_pre(emit_t *emit) {
emit->last_emit_was_return_value = false;
// settle the stack
@ -341,13 +342,13 @@ static void emit_pre(emit_t *emit) {
*/
}
static vtype_kind_t peek_vtype(emit_t *emit) {
STATIC vtype_kind_t peek_vtype(emit_t *emit) {
return emit->stack_info[emit->stack_size - 1].vtype;
}
// pos=1 is TOS, pos=2 is next, etc
// use pos=0 for no skipping
static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
STATIC void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
skip_stack_pos = emit->stack_size - skip_stack_pos;
for (int i = 0; i < emit->stack_size; i++) {
if (i != skip_stack_pos) {
@ -360,7 +361,7 @@ static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
}
}
static void need_reg_all(emit_t *emit) {
STATIC void need_reg_all(emit_t *emit) {
for (int i = 0; i < emit->stack_size; i++) {
stack_info_t *si = &emit->stack_info[i];
if (si->kind == STACK_REG) {
@ -370,7 +371,7 @@ static void need_reg_all(emit_t *emit) {
}
}
static void need_stack_settled(emit_t *emit) {
STATIC void need_stack_settled(emit_t *emit) {
for (int i = 0; i < emit->stack_size; i++) {
stack_info_t *si = &emit->stack_info[i];
if (si->kind == STACK_REG) {
@ -387,7 +388,7 @@ static void need_stack_settled(emit_t *emit) {
}
// pos=1 is TOS, pos=2 is next, etc
static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) {
STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) {
need_reg_single(emit, reg_dest, pos);
stack_info_t *si = &emit->stack_info[emit->stack_size - pos];
*vtype = si->vtype;
@ -408,27 +409,27 @@ static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re
}
}
static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) {
STATIC void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) {
emit->last_emit_was_return_value = false;
emit_access_stack(emit, 1, vtype, reg_dest);
adjust_stack(emit, -1);
}
static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) {
STATIC void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) {
emit_pre_pop_reg(emit, vtypea, rega);
emit_pre_pop_reg(emit, vtypeb, regb);
}
static void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) {
STATIC void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) {
emit_pre_pop_reg(emit, vtypea, rega);
emit_pre_pop_reg(emit, vtypeb, regb);
emit_pre_pop_reg(emit, vtypec, regc);
}
static void emit_post(emit_t *emit) {
STATIC void emit_post(emit_t *emit) {
}
static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
stack_info_t *si = &emit->stack_info[emit->stack_size];
si->vtype = vtype;
si->kind = STACK_REG;
@ -436,7 +437,7 @@ static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
adjust_stack(emit, 1);
}
static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) {
STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) {
stack_info_t *si = &emit->stack_info[emit->stack_size];
si->vtype = vtype;
si->kind = STACK_IMM;
@ -444,18 +445,18 @@ static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t i
adjust_stack(emit, 1);
}
static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) {
STATIC void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) {
emit_post_push_reg(emit, vtypea, rega);
emit_post_push_reg(emit, vtypeb, regb);
}
static void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) {
STATIC void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) {
emit_post_push_reg(emit, vtypea, rega);
emit_post_push_reg(emit, vtypeb, regb);
emit_post_push_reg(emit, vtypec, regc);
}
static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) {
STATIC void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) {
emit_post_push_reg(emit, vtypea, rega);
emit_post_push_reg(emit, vtypeb, regb);
emit_post_push_reg(emit, vtypec, regc);
@ -465,7 +466,7 @@ static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, in
// vtype of all n_pop objects is VTYPE_PYOBJ
// does not use any temporary registers (but may use reg_dest before loading it with stack pointer)
// TODO this needs some thinking for viper code
static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) {
STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) {
need_reg_all(emit);
for (int i = 0; i < n_pop; i++) {
stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i];
@ -502,7 +503,7 @@ static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, in
}
// vtype of all n_push objects is VTYPE_PYOBJ
static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) {
STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) {
need_reg_all(emit);
for (int i = 0; i < n_push; i++) {
emit->stack_info[emit->stack_size + i].kind = STACK_VALUE;
@ -512,7 +513,7 @@ static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, i
adjust_stack(emit, n_push);
}
static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
STATIC void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
need_reg_all(emit);
#if N_X64
asm_x64_call_ind(emit->as, fun, REG_RAX);
@ -521,7 +522,7 @@ static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
#endif
}
static void emit_call_with_imm_arg(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) {
STATIC void emit_call_with_imm_arg(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) {
need_reg_all(emit);
ASM_MOV_IMM_TO_REG(arg_val, arg_reg);
#if N_X64
@ -531,7 +532,7 @@ static void emit_call_with_imm_arg(emit_t *emit, rt_fun_kind_t fun_kind, void *f
#endif
}
static void emit_call_with_2_imm_args(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val1, int arg_reg1, machine_int_t arg_val2, int arg_reg2) {
STATIC void emit_call_with_2_imm_args(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val1, int arg_reg1, machine_int_t arg_val2, int arg_reg2) {
need_reg_all(emit);
ASM_MOV_IMM_TO_REG(arg_val1, arg_reg1);
ASM_MOV_IMM_TO_REG(arg_val2, arg_reg2);
@ -542,7 +543,7 @@ static void emit_call_with_2_imm_args(emit_t *emit, rt_fun_kind_t fun_kind, void
#endif
}
static void emit_native_load_id(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_id(emit_t *emit, qstr qstr) {
// check for built-ins
if (strcmp(qstr_str(qstr), "v_int") == 0) {
assert(0);
@ -555,17 +556,17 @@ static void emit_native_load_id(emit_t *emit, qstr qstr) {
}
}
static void emit_native_store_id(emit_t *emit, qstr qstr) {
STATIC void emit_native_store_id(emit_t *emit, qstr qstr) {
// TODO check for built-ins and disallow
emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
}
static void emit_native_delete_id(emit_t *emit, qstr qstr) {
STATIC void emit_native_delete_id(emit_t *emit, qstr qstr) {
// TODO check for built-ins and disallow
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, int l) {
emit_pre(emit);
// need to commit stack because we can jump here from elsewhere
need_stack_settled(emit);
@ -577,22 +578,22 @@ static void emit_native_label_assign(emit_t *emit, int l) {
emit_post(emit);
}
static void emit_native_import_name(emit_t *emit, qstr qstr) {
STATIC void emit_native_import_name(emit_t *emit, qstr qstr) {
// not implemented
assert(0);
}
static void emit_native_import_from(emit_t *emit, qstr qstr) {
STATIC void emit_native_import_from(emit_t *emit, qstr qstr) {
// not implemented
assert(0);
}
static void emit_native_import_star(emit_t *emit) {
STATIC void emit_native_import_star(emit_t *emit) {
// not implemented
assert(0);
}
static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
emit_pre(emit);
int vtype;
machine_uint_t val;
@ -615,7 +616,7 @@ static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
emit_post_push_imm(emit, vtype, val);
}
static void emit_native_load_const_small_int(emit_t *emit, machine_int_t arg) {
STATIC void emit_native_load_const_small_int(emit_t *emit, machine_int_t arg) {
emit_pre(emit);
if (emit->do_viper_types) {
emit_post_push_imm(emit, VTYPE_INT, arg);
@ -624,20 +625,20 @@ static void emit_native_load_const_small_int(emit_t *emit, machine_int_t arg) {
}
}
static void emit_native_load_const_int(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_const_int(emit_t *emit, qstr qstr) {
// not implemented
// load integer, check fits in 32 bits
assert(0);
}
static void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
// for viper, a float/complex is just a Python object
emit_pre(emit);
emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_DEC, rt_load_const_dec, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_load_const_id(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_const_id(emit_t *emit, qstr qstr) {
emit_pre(emit);
if (emit->do_viper_types) {
assert(0);
@ -647,7 +648,7 @@ static void emit_native_load_const_id(emit_t *emit, qstr qstr) {
}
}
static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
STATIC void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
emit_pre(emit);
if (emit->do_viper_types) {
// not implemented properly
@ -660,12 +661,12 @@ static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
}
}
static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) {
STATIC void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) {
// not supported/needed for viper
assert(0);
}
static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
vtype_kind_t vtype = emit->local_vtype[local_num];
if (vtype == VTYPE_UNBOUND) {
printf("ViperTypeError: local %s used before type known\n", qstr_str(qstr));
@ -694,30 +695,30 @@ static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
#endif
}
static void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) {
// not implemented
// in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables!
assert(0);
}
static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
// not implemented
assert(0);
}
static void emit_native_load_name(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_name(emit_t *emit, qstr qstr) {
emit_pre(emit);
emit_call_with_imm_arg(emit, RT_F_LOAD_NAME, rt_load_name, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_load_global(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_global(emit_t *emit, qstr qstr) {
emit_pre(emit);
emit_call_with_imm_arg(emit, RT_F_LOAD_GLOBAL, rt_load_global, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_load_attr(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_attr(emit_t *emit, qstr qstr) {
// depends on type of subject:
// - integer, function, pointer to integers: error
// - pointer to structure: get member, quite easy
@ -729,7 +730,7 @@ static void emit_native_load_attr(emit_t *emit, qstr qstr) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_load_method(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_method(emit_t *emit, qstr qstr) {
vtype_kind_t vtype_base;
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
assert(vtype_base == VTYPE_PYOBJ);
@ -737,13 +738,13 @@ static void emit_native_load_method(emit_t *emit, qstr qstr) {
emit_call_with_imm_arg(emit, RT_F_LOAD_METHOD, rt_load_method, qstr, REG_ARG_2); // arg2 = method name
}
static void emit_native_load_build_class(emit_t *emit) {
STATIC void emit_native_load_build_class(emit_t *emit) {
emit_pre(emit);
emit_call(emit, RT_F_LOAD_BUILD_CLASS, rt_load_build_class);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
vtype_kind_t vtype;
#if N_X64
if (local_num == 0) {
@ -777,12 +778,12 @@ static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
}
}
static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
// not implemented
assert(0);
}
static void emit_native_store_name(emit_t *emit, qstr qstr) {
STATIC void emit_native_store_name(emit_t *emit, qstr qstr) {
// rt_store_name, but needs conversion of object (maybe have rt_viper_store_name(obj, type))
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
@ -791,12 +792,12 @@ static void emit_native_store_name(emit_t *emit, qstr qstr) {
emit_post(emit);
}
static void emit_native_store_global(emit_t *emit, qstr qstr) {
STATIC void emit_native_store_global(emit_t *emit, qstr qstr) {
// not implemented
assert(0);
}
static void emit_native_store_attr(emit_t *emit, qstr qstr) {
STATIC void emit_native_store_attr(emit_t *emit, qstr qstr) {
vtype_kind_t vtype_base, vtype_val;
emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
assert(vtype_base == VTYPE_PYOBJ);
@ -805,7 +806,7 @@ static void emit_native_store_attr(emit_t *emit, qstr qstr) {
emit_post(emit);
}
static void emit_native_store_subscr(emit_t *emit) {
STATIC void emit_native_store_subscr(emit_t *emit) {
// depends on type of subject:
// - integer, function, pointer to structure: error
// - pointer to integers: store as per array
@ -818,77 +819,77 @@ static void emit_native_store_subscr(emit_t *emit) {
emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr);
}
static void emit_native_store_locals(emit_t *emit) {
STATIC void emit_native_store_locals(emit_t *emit) {
// not needed
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
emit_post(emit);
}
static void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
// not implemented
// could support for Python types, just set to None (so GC can reclaim it)
assert(0);
}
static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
// not supported
assert(0);
}
static void emit_native_delete_name(emit_t *emit, qstr qstr) {
STATIC void emit_native_delete_name(emit_t *emit, qstr qstr) {
// not implemented
// use rt_delete_name
assert(0);
}
static void emit_native_delete_global(emit_t *emit, qstr qstr) {
STATIC void emit_native_delete_global(emit_t *emit, qstr qstr) {
// not implemented
// use rt_delete_global
assert(0);
}
static void emit_native_delete_attr(emit_t *emit, qstr qstr) {
STATIC void emit_native_delete_attr(emit_t *emit, qstr qstr) {
// not supported
assert(0);
}
static void emit_native_delete_subscr(emit_t *emit) {
STATIC void emit_native_delete_subscr(emit_t *emit) {
// not supported
assert(0);
}
static void emit_native_dup_top(emit_t *emit) {
STATIC void emit_native_dup_top(emit_t *emit) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
emit_post_push_reg_reg(emit, vtype, REG_TEMP0, vtype, REG_TEMP0);
}
static void emit_native_dup_top_two(emit_t *emit) {
STATIC void emit_native_dup_top_two(emit_t *emit) {
vtype_kind_t vtype0, vtype1;
emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0);
}
static void emit_native_pop_top(emit_t *emit) {
STATIC void emit_native_pop_top(emit_t *emit) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
emit_post(emit);
}
static void emit_native_rot_two(emit_t *emit) {
STATIC void emit_native_rot_two(emit_t *emit) {
vtype_kind_t vtype0, vtype1;
emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1);
}
static void emit_native_rot_three(emit_t *emit) {
STATIC void emit_native_rot_three(emit_t *emit) {
vtype_kind_t vtype0, vtype1, vtype2;
emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2);
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, int label) {
emit_pre(emit);
#if N_X64
asm_x64_jmp_label(emit->as, label);
@ -898,7 +899,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, int label) {
vtype_kind_t vtype = peek_vtype(emit);
if (vtype == VTYPE_BOOL) {
emit_pre_pop_reg(emit, &vtype, REG_RET);
@ -911,7 +912,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, int label) {
emit_native_pop_jump_pre_helper(emit, label);
#if N_X64
asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
@ -923,7 +924,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, int label) {
emit_native_pop_jump_pre_helper(emit, label);
#if N_X64
asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
@ -935,42 +936,42 @@ 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, int 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, int label) {
assert(0);
}
static void emit_native_setup_loop(emit_t *emit, int label) {
STATIC void emit_native_setup_loop(emit_t *emit, int label) {
emit_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, int 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, int 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, int label) {
// not supported, or could be with runtime call
assert(0);
}
static void emit_native_with_cleanup(emit_t *emit) {
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, int label) {
assert(0);
}
static void emit_native_setup_finally(emit_t *emit, int label) {
STATIC void emit_native_setup_finally(emit_t *emit, int label) {
assert(0);
}
static void emit_native_end_finally(emit_t *emit) {
STATIC void emit_native_end_finally(emit_t *emit) {
assert(0);
}
static void emit_native_get_iter(emit_t *emit) {
STATIC void emit_native_get_iter(emit_t *emit) {
// perhaps the difficult one, as we want to rewrite for loops using native code
// in cases where we iterate over a Python object, can we use normal runtime calls?
@ -981,7 +982,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, int label) {
emit_pre(emit);
vtype_kind_t vtype;
emit_access_stack(emit, 1, &vtype, REG_ARG_1);
@ -998,23 +999,23 @@ static void emit_native_for_iter(emit_t *emit, int label) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_for_iter_end(emit_t *emit) {
STATIC void emit_native_for_iter_end(emit_t *emit) {
// adjust stack counter (we get here from for_iter ending, which popped the value for us)
emit_pre(emit);
adjust_stack(emit, -1);
emit_post(emit);
}
static void emit_native_pop_block(emit_t *emit) {
STATIC void emit_native_pop_block(emit_t *emit) {
emit_pre(emit);
emit_post(emit);
}
static void emit_native_pop_except(emit_t *emit) {
STATIC void emit_native_pop_except(emit_t *emit) {
assert(0);
}
static void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
STATIC void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
assert(vtype == VTYPE_PYOBJ);
@ -1022,7 +1023,7 @@ static void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
STATIC void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
vtype_kind_t vtype_lhs, vtype_rhs;
emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_3, &vtype_lhs, REG_ARG_2);
if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) {
@ -1058,7 +1059,7 @@ static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
}
}
static void emit_native_build_tuple(emit_t *emit, int n_args) {
STATIC void emit_native_build_tuple(emit_t *emit, int n_args) {
// for viper: call runtime, with types of args
// if wrapped in byte_array, or something, allocates memory and fills it
emit_pre(emit);
@ -1067,14 +1068,14 @@ static void emit_native_build_tuple(emit_t *emit, int n_args) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple
}
static void emit_native_build_list(emit_t *emit, int n_args) {
STATIC void emit_native_build_list(emit_t *emit, int n_args) {
emit_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, RT_F_BUILD_LIST, rt_build_list, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list
}
static void emit_native_list_append(emit_t *emit, int list_index) {
STATIC void emit_native_list_append(emit_t *emit, int list_index) {
// only used in list comprehension
vtype_kind_t vtype_list, vtype_item;
emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
@ -1085,13 +1086,13 @@ static void emit_native_list_append(emit_t *emit, int list_index) {
emit_post(emit);
}
static void emit_native_build_map(emit_t *emit, int n_args) {
STATIC void emit_native_build_map(emit_t *emit, int n_args) {
emit_pre(emit);
emit_call_with_imm_arg(emit, RT_F_BUILD_MAP, rt_build_map, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
}
static void emit_native_store_map(emit_t *emit) {
STATIC void emit_native_store_map(emit_t *emit) {
vtype_kind_t vtype_key, vtype_value, vtype_map;
emit_pre_pop_reg_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3, &vtype_map, REG_ARG_1); // key, value, map
assert(vtype_key == VTYPE_PYOBJ);
@ -1101,7 +1102,7 @@ static void emit_native_store_map(emit_t *emit) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
}
static void emit_native_map_add(emit_t *emit, int map_index) {
STATIC void emit_native_map_add(emit_t *emit, int map_index) {
// only used in list comprehension
vtype_kind_t vtype_map, vtype_key, vtype_value;
emit_pre_pop_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3);
@ -1113,14 +1114,14 @@ static void emit_native_map_add(emit_t *emit, int map_index) {
emit_post(emit);
}
static void emit_native_build_set(emit_t *emit, int n_args) {
STATIC void emit_native_build_set(emit_t *emit, int n_args) {
emit_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, RT_F_BUILD_SET, rt_build_set, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
}
static void emit_native_set_add(emit_t *emit, int set_index) {
STATIC void emit_native_set_add(emit_t *emit, int set_index) {
// only used in set comprehension
vtype_kind_t vtype_set, vtype_item;
emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
@ -1131,18 +1132,18 @@ static void emit_native_set_add(emit_t *emit, int set_index) {
emit_post(emit);
}
static void emit_native_build_slice(emit_t *emit, int n_args) {
STATIC void emit_native_build_slice(emit_t *emit, int n_args) {
assert(0);
}
static void emit_native_unpack_sequence(emit_t *emit, int n_args) {
STATIC void emit_native_unpack_sequence(emit_t *emit, int n_args) {
// call runtime, needs type decl
assert(0);
}
static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
STATIC void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
assert(0);
}
static void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
// call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
assert(n_default_params == 0 && n_dict_params == 0);
emit_pre(emit);
@ -1150,11 +1151,11 @@ static void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_p
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
assert(0);
}
static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
STATIC void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
// call special viper runtime routine with type info for args, and wanted type info for return
assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
@ -1193,7 +1194,7 @@ static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyw
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
STATIC void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
/*
@ -1219,7 +1220,7 @@ static void emit_native_call_method(emit_t *emit, int n_positional, int n_keywor
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
static void emit_native_return_value(emit_t *emit) {
STATIC void emit_native_return_value(emit_t *emit) {
// easy. since we don't know who we return to, just return the raw value.
// runtime needs then to know our type signature, but I think that's possible.
vtype_kind_t vtype;
@ -1239,15 +1240,15 @@ static void emit_native_return_value(emit_t *emit) {
#endif
}
static void emit_native_raise_varargs(emit_t *emit, int n_args) {
STATIC void emit_native_raise_varargs(emit_t *emit, int n_args) {
// call runtime
assert(0);
}
static void emit_native_yield_value(emit_t *emit) {
STATIC void emit_native_yield_value(emit_t *emit) {
// not supported (for now)
assert(0);
}
static void emit_native_yield_from(emit_t *emit) {
STATIC void emit_native_yield_from(emit_t *emit) {
// not supported (for now)
assert(0);
}

View File

@ -27,18 +27,18 @@ void emit_pass1_free(emit_t *emit) {
m_del_obj(emit_t, emit);
}
static void emit_pass1_dummy(emit_t *emit) {
STATIC void emit_pass1_dummy(emit_t *emit) {
}
static void emit_pass1_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
STATIC void emit_pass1_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
assert(pass == PASS_1);
emit->scope = scope;
}
static void emit_pass1_end_pass(emit_t *emit) {
STATIC void emit_pass1_end_pass(emit_t *emit) {
}
static void emit_pass1_load_id(emit_t *emit, qstr qstr) {
STATIC void emit_pass1_load_id(emit_t *emit, qstr qstr) {
// name adding/lookup
bool added;
id_info_t *id = scope_find_or_add_id(emit->scope, qstr, &added);
@ -69,7 +69,7 @@ static void emit_pass1_load_id(emit_t *emit, qstr qstr) {
}
}
static id_info_t *get_id_for_modification(scope_t *scope, qstr qstr) {
STATIC id_info_t *get_id_for_modification(scope_t *scope, qstr qstr) {
// name adding/lookup
bool added;
id_info_t *id = scope_find_or_add_id(scope, qstr, &added);
@ -89,11 +89,11 @@ static id_info_t *get_id_for_modification(scope_t *scope, qstr qstr) {
return id;
}
static void emit_pass1_store_id(emit_t *emit, qstr qstr) {
STATIC void emit_pass1_store_id(emit_t *emit, qstr qstr) {
get_id_for_modification(emit->scope, qstr);
}
static void emit_pass1_delete_id(emit_t *emit, qstr qstr) {
STATIC void emit_pass1_delete_id(emit_t *emit, qstr qstr) {
get_id_for_modification(emit->scope, qstr);
}

22
py/gc.c
View File

@ -21,14 +21,14 @@ typedef unsigned char byte;
#define BYTES_PER_BLOCK (WORDS_PER_BLOCK * BYTES_PER_WORD)
#define STACK_SIZE (64) // tunable; minimum is 1
static byte *gc_alloc_table_start;
static machine_uint_t gc_alloc_table_byte_len;
static machine_uint_t *gc_pool_start;
static machine_uint_t *gc_pool_end;
STATIC byte *gc_alloc_table_start;
STATIC machine_uint_t gc_alloc_table_byte_len;
STATIC machine_uint_t *gc_pool_start;
STATIC machine_uint_t *gc_pool_end;
static int gc_stack_overflow;
static machine_uint_t gc_stack[STACK_SIZE];
static machine_uint_t *gc_sp;
STATIC int gc_stack_overflow;
STATIC machine_uint_t gc_stack[STACK_SIZE];
STATIC machine_uint_t *gc_sp;
// ATB = allocation table byte
// 0b00 = FREE -- free block
@ -116,7 +116,7 @@ void gc_init(void *start, void *end) {
} \
} while (0)
static void gc_drain_stack(void) {
STATIC void gc_drain_stack(void) {
while (gc_sp > gc_stack) {
// pop the next block off the stack
machine_uint_t block = *--gc_sp;
@ -136,7 +136,7 @@ static void gc_drain_stack(void) {
}
}
static void gc_deal_with_stack_overflow(void) {
STATIC void gc_deal_with_stack_overflow(void) {
while (gc_stack_overflow) {
gc_stack_overflow = 0;
gc_sp = gc_stack;
@ -152,7 +152,7 @@ static void gc_deal_with_stack_overflow(void) {
}
}
static void gc_sweep(void) {
STATIC void gc_sweep(void) {
// free unmarked heads and their tails
int free_tail = 0;
for (machine_uint_t block = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) {
@ -351,7 +351,7 @@ void gc_dump_info() {
}
#if DEBUG_PRINT
static void gc_dump_at(void) {
STATIC void gc_dump_at(void) {
for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) {
printf("block %06u ", bl);
switch (ATB_GET_KIND(bl)) {

View File

@ -72,75 +72,75 @@ void mp_token_show(const mp_token_t *tok) {
#define CUR_CHAR(lex) ((lex)->chr0)
static bool is_end(mp_lexer_t *lex) {
STATIC bool is_end(mp_lexer_t *lex) {
return lex->chr0 == MP_LEXER_CHAR_EOF;
}
static bool is_physical_newline(mp_lexer_t *lex) {
STATIC bool is_physical_newline(mp_lexer_t *lex) {
return lex->chr0 == '\n' || lex->chr0 == '\r';
}
static bool is_char(mp_lexer_t *lex, char c) {
STATIC bool is_char(mp_lexer_t *lex, char c) {
return lex->chr0 == c;
}
static bool is_char_or(mp_lexer_t *lex, char c1, char c2) {
STATIC bool is_char_or(mp_lexer_t *lex, char c1, char c2) {
return lex->chr0 == c1 || lex->chr0 == c2;
}
static bool is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) {
STATIC bool is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) {
return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3;
}
/*
static bool is_char_following(mp_lexer_t *lex, char c) {
STATIC bool is_char_following(mp_lexer_t *lex, char c) {
return lex->chr1 == c;
}
*/
static bool is_char_following_or(mp_lexer_t *lex, char c1, char c2) {
STATIC bool is_char_following_or(mp_lexer_t *lex, char c1, char c2) {
return lex->chr1 == c1 || lex->chr1 == c2;
}
static bool is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) {
STATIC bool is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) {
return lex->chr2 == c1 || lex->chr2 == c2;
}
static bool is_char_and(mp_lexer_t *lex, char c1, char c2) {
STATIC bool is_char_and(mp_lexer_t *lex, char c1, char c2) {
return lex->chr0 == c1 && lex->chr1 == c2;
}
static bool is_whitespace(mp_lexer_t *lex) {
STATIC bool is_whitespace(mp_lexer_t *lex) {
return unichar_isspace(lex->chr0);
}
static bool is_letter(mp_lexer_t *lex) {
STATIC bool is_letter(mp_lexer_t *lex) {
return unichar_isalpha(lex->chr0);
}
static bool is_digit(mp_lexer_t *lex) {
STATIC bool is_digit(mp_lexer_t *lex) {
return unichar_isdigit(lex->chr0);
}
static bool is_following_digit(mp_lexer_t *lex) {
STATIC bool is_following_digit(mp_lexer_t *lex) {
return unichar_isdigit(lex->chr1);
}
static bool is_following_odigit(mp_lexer_t *lex) {
STATIC bool is_following_odigit(mp_lexer_t *lex) {
return lex->chr1 >= '0' && lex->chr1 <= '7';
}
// TODO UNICODE include unicode characters in definition of identifiers
static bool is_head_of_identifier(mp_lexer_t *lex) {
STATIC bool is_head_of_identifier(mp_lexer_t *lex) {
return is_letter(lex) || lex->chr0 == '_';
}
// TODO UNICODE include unicode characters in definition of identifiers
static bool is_tail_of_identifier(mp_lexer_t *lex) {
STATIC bool is_tail_of_identifier(mp_lexer_t *lex) {
return is_head_of_identifier(lex) || is_digit(lex);
}
static void next_char(mp_lexer_t *lex) {
STATIC void next_char(mp_lexer_t *lex) {
if (lex->chr0 == MP_LEXER_CHAR_EOF) {
return;
}
@ -203,7 +203,7 @@ void indent_pop(mp_lexer_t *lex) {
// c<op> = continue with <op>, if this opchar matches then continue matching
// this means if the start of two ops are the same then they are equal til the last char
static const char *tok_enc =
STATIC const char *tok_enc =
"()[]{},:;@~" // singles
"<e=c<e=" // < <= << <<=
">e=c>e=" // > >= >> >>=
@ -220,7 +220,7 @@ static const char *tok_enc =
".c.E."; // . ...
// TODO static assert that number of tokens is less than 256 so we can safely make this table with byte sized entries
static const uint8_t tok_enc_kind[] = {
STATIC const uint8_t tok_enc_kind[] = {
MP_TOKEN_DEL_PAREN_OPEN, MP_TOKEN_DEL_PAREN_CLOSE,
MP_TOKEN_DEL_BRACKET_OPEN, MP_TOKEN_DEL_BRACKET_CLOSE,
MP_TOKEN_DEL_BRACE_OPEN, MP_TOKEN_DEL_BRACE_CLOSE,
@ -242,7 +242,7 @@ static const uint8_t tok_enc_kind[] = {
};
// must have the same order as enum in lexer.h
static const char *tok_kw[] = {
STATIC const char *tok_kw[] = {
"False",
"None",
"True",
@ -279,7 +279,7 @@ static const char *tok_kw[] = {
NULL,
};
static int hex_digit(unichar c) {
STATIC int hex_digit(unichar c) {
// c is assumed to be hex digit
int n = c - '0';
if (n > 9) {
@ -291,7 +291,7 @@ static int hex_digit(unichar c) {
// This is called with CUR_CHAR() before first hex digit, and should return with
// it pointing to last hex digit
static bool get_hex(mp_lexer_t *lex, int num_digits, uint *result) {
STATIC bool get_hex(mp_lexer_t *lex, int num_digits, uint *result) {
uint num = 0;
while (num_digits-- != 0) {
next_char(lex);
@ -305,7 +305,7 @@ static bool get_hex(mp_lexer_t *lex, int num_digits, uint *result) {
return true;
}
static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool first_token) {
STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool first_token) {
// skip white space and comments
bool had_physical_newline = false;
while (!is_end(lex)) {

View File

@ -13,7 +13,7 @@ typedef struct _mp_lexer_str_buf_t {
const char *src_end; // end (exclusive) of source
} mp_lexer_str_buf_t;
static unichar str_buf_next_char(mp_lexer_str_buf_t *sb) {
STATIC unichar str_buf_next_char(mp_lexer_str_buf_t *sb) {
if (sb->src_cur < sb->src_end) {
return *sb->src_cur++;
} else {
@ -21,7 +21,7 @@ static unichar str_buf_next_char(mp_lexer_str_buf_t *sb) {
}
}
static void str_buf_free(mp_lexer_str_buf_t *sb) {
STATIC void str_buf_free(mp_lexer_str_buf_t *sb) {
if (sb->free_len > 0) {
m_free((char*)sb->src_beg, sb->free_len);
}

View File

@ -12,9 +12,9 @@
#endif
#if MICROPY_MEM_STATS
static int total_bytes_allocated = 0;
static int current_bytes_allocated = 0;
static int peak_bytes_allocated = 0;
STATIC int total_bytes_allocated = 0;
STATIC int current_bytes_allocated = 0;
STATIC int peak_bytes_allocated = 0;
#define UPDATE_PEAK() { if (current_bytes_allocated > peak_bytes_allocated) peak_bytes_allocated = current_bytes_allocated; }
#endif

View File

@ -11,7 +11,7 @@
// approximatelly doubling primes; made with Mathematica command: Table[Prime[Floor[(1.7)^n]], {n, 3, 24}]
// prefixed with zero for the empty case.
static int doubling_primes[] = {0, 7, 19, 43, 89, 179, 347, 647, 1229, 2297, 4243, 7829, 14347, 26017, 47149, 84947, 152443, 273253, 488399, 869927, 1547173, 2745121, 4861607};
STATIC int doubling_primes[] = {0, 7, 19, 43, 89, 179, 347, 647, 1229, 2297, 4243, 7829, 14347, 26017, 47149, 84947, 152443, 273253, 488399, 869927, 1547173, 2745121, 4861607};
int get_doubling_prime_greater_or_equal_to(int x) {
for (int i = 0; i < sizeof(doubling_primes) / sizeof(int); i++) {
@ -78,7 +78,7 @@ void mp_map_clear(mp_map_t *map) {
map->table = NULL;
}
static void mp_map_rehash(mp_map_t *map) {
STATIC void mp_map_rehash(mp_map_t *map) {
int old_alloc = map->alloc;
mp_map_elem_t *old_table = map->table;
map->alloc = get_doubling_prime_greater_or_equal_to(map->alloc + 1);
@ -175,7 +175,7 @@ void mp_set_init(mp_set_t *set, int n) {
set->table = m_new0(mp_obj_t, set->alloc);
}
static void mp_set_rehash(mp_set_t *set) {
STATIC void mp_set_rehash(mp_set_t *set) {
int old_alloc = set->alloc;
mp_obj_t *old_table = set->table;
set->alloc = get_doubling_prime_greater_or_equal_to(set->alloc + 1);

View File

@ -74,7 +74,7 @@ enum {
#undef one_or_more
#undef DEF_RULE
static const rule_t *rules[] = {
STATIC const rule_t *rules[] = {
NULL,
#define DEF_RULE(rule, comp, kind, ...) &rule_##rule,
#include "grammar.h"
@ -99,7 +99,7 @@ typedef struct _parser_t {
mp_lexer_t *lexer;
} parser_t;
static void push_rule(parser_t *parser, int src_line, const rule_t *rule, int arg_i) {
STATIC void push_rule(parser_t *parser, int src_line, const rule_t *rule, int arg_i) {
if (parser->rule_stack_top >= parser->rule_stack_alloc) {
parser->rule_stack = m_renew(rule_stack_t, parser->rule_stack, parser->rule_stack_alloc, parser->rule_stack_alloc * 2);
parser->rule_stack_alloc *= 2;
@ -110,14 +110,14 @@ static void push_rule(parser_t *parser, int src_line, const rule_t *rule, int ar
rs->arg_i = arg_i;
}
static void push_rule_from_arg(parser_t *parser, uint arg) {
STATIC void push_rule_from_arg(parser_t *parser, uint arg) {
assert((arg & RULE_ARG_KIND_MASK) == RULE_ARG_RULE || (arg & RULE_ARG_KIND_MASK) == RULE_ARG_OPT_RULE);
uint rule_id = arg & RULE_ARG_ARG_MASK;
assert(rule_id < RULE_maximum_number_of);
push_rule(parser, mp_lexer_cur(parser->lexer)->src_line, rules[rule_id], 0);
}
static void pop_rule(parser_t *parser, const rule_t **rule, uint *arg_i, uint *src_line) {
STATIC void pop_rule(parser_t *parser, const rule_t **rule, uint *arg_i, uint *src_line) {
parser->rule_stack_top -= 1;
*rule = rules[parser->rule_stack[parser->rule_stack_top].rule_id];
*arg_i = parser->rule_stack[parser->rule_stack_top].arg_i;
@ -199,7 +199,7 @@ void mp_parse_node_print(mp_parse_node_t pn, int indent) {
#endif // MICROPY_DEBUG_PRINTERS
/*
static void result_stack_show(parser_t *parser) {
STATIC void result_stack_show(parser_t *parser) {
printf("result stack, most recent first\n");
for (int i = parser->result_stack_top - 1; i >= 0; i--) {
mp_parse_node_print(parser->result_stack[i], 0);
@ -207,17 +207,17 @@ static void result_stack_show(parser_t *parser) {
}
*/
static mp_parse_node_t pop_result(parser_t *parser) {
STATIC mp_parse_node_t pop_result(parser_t *parser) {
assert(parser->result_stack_top > 0);
return parser->result_stack[--parser->result_stack_top];
}
static mp_parse_node_t peek_result(parser_t *parser, int pos) {
STATIC mp_parse_node_t peek_result(parser_t *parser, int pos) {
assert(parser->result_stack_top > pos);
return parser->result_stack[parser->result_stack_top - 1 - pos];
}
static void push_result_node(parser_t *parser, mp_parse_node_t pn) {
STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) {
if (parser->result_stack_top >= parser->result_stack_alloc) {
parser->result_stack = m_renew(mp_parse_node_t, parser->result_stack, parser->result_stack_alloc, parser->result_stack_alloc * 2);
parser->result_stack_alloc *= 2;
@ -225,7 +225,7 @@ static void push_result_node(parser_t *parser, mp_parse_node_t pn) {
parser->result_stack[parser->result_stack_top++] = pn;
}
static void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
STATIC void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
const mp_token_t *tok = mp_lexer_cur(lex);
mp_parse_node_t pn;
if (tok->kind == MP_TOKEN_NAME) {
@ -294,7 +294,7 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
push_result_node(parser, pn);
}
static void push_result_rule(parser_t *parser, int src_line, const rule_t *rule, int num_args) {
STATIC void push_result_rule(parser_t *parser, int src_line, const rule_t *rule, int num_args) {
mp_parse_node_struct_t *pn = parse_node_new_struct(src_line, rule->rule_id, num_args);
for (int i = num_args; i > 0; i--) {
pn->nodes[i - 1] = pop_result(parser);

View File

@ -60,13 +60,13 @@ const static qstr_pool_t const_pool = {
},
};
static qstr_pool_t *last_pool;
STATIC qstr_pool_t *last_pool;
void qstr_init(void) {
last_pool = (qstr_pool_t*)&const_pool; // we won't modify the const_pool since it has no allocated room left
}
static const byte *find_qstr(qstr q) {
STATIC const byte *find_qstr(qstr q) {
// search pool for this qstr
for (qstr_pool_t *pool = last_pool; pool != NULL; pool = pool->prev) {
if (q >= pool->total_prev_len) {
@ -78,7 +78,7 @@ static const byte *find_qstr(qstr q) {
return 0;
}
static qstr qstr_add(const byte *q_ptr) {
STATIC qstr qstr_add(const byte *q_ptr) {
DEBUG_printf("QSTR: add hash=%d len=%d data=%.*s\n", Q_GET_HASH(q_ptr), Q_GET_LENGTH(q_ptr), Q_GET_LENGTH(q_ptr), Q_GET_DATA(q_ptr));
// make sure we have room in the pool for a new qstr

View File

@ -31,10 +31,10 @@
#endif
// locals and globals need to be pointers because they can be the same in outer module scope
static mp_map_t *map_locals;
static mp_map_t *map_globals;
static mp_map_t map_builtins;
static mp_map_t map_loaded_modules; // TODO: expose as sys.modules
STATIC mp_map_t *map_locals;
STATIC mp_map_t *map_globals;
STATIC mp_map_t map_builtins;
STATIC mp_map_t map_loaded_modules; // TODO: expose as sys.modules
typedef enum {
MP_CODE_NONE,
@ -66,9 +66,9 @@ typedef struct _mp_code_t {
};
} mp_code_t;
static uint next_unique_code_id;
static machine_uint_t unique_codes_alloc = 0;
static mp_code_t *unique_codes = NULL;
STATIC uint next_unique_code_id;
STATIC machine_uint_t unique_codes_alloc = 0;
STATIC mp_code_t *unique_codes = NULL;
#ifdef WRITE_CODE
FILE *fp_write_code = NULL;
@ -85,7 +85,7 @@ typedef struct _mp_builtin_elem_t {
mp_obj_t fun;
} mp_builtin_elem_t;
static const mp_builtin_elem_t builtin_table[] = {
STATIC const mp_builtin_elem_t builtin_table[] = {
// built-in core functions
{ MP_QSTR___build_class__, (mp_obj_t)&mp_builtin___build_class___obj },
{ MP_QSTR___import__, (mp_obj_t)&mp_builtin___import___obj },
@ -148,7 +148,7 @@ static const mp_builtin_elem_t builtin_table[] = {
};
// a good optimising compiler will inline this if necessary
static void mp_map_add_qstr(mp_map_t *map, qstr qstr, mp_obj_t value) {
STATIC void mp_map_add_qstr(mp_map_t *map, qstr qstr, mp_obj_t value) {
mp_map_lookup(map, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
}
@ -225,7 +225,7 @@ uint rt_get_unique_code_id(void) {
return next_unique_code_id++;
}
static void alloc_unique_codes(void) {
STATIC void alloc_unique_codes(void) {
if (next_unique_code_id > unique_codes_alloc) {
DEBUG_printf("allocate more unique codes: " UINT_FMT " -> %u\n", unique_codes_alloc, next_unique_code_id);
// increase size of unique_codes table
@ -864,7 +864,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
// no attribute found, returns: dest[0] == MP_OBJ_NULL, dest[1] == MP_OBJ_NULL
// normal attribute found, returns: dest[0] == <attribute>, dest[1] == MP_OBJ_NULL
// method attribute found, returns: dest[0] == <method>, dest[1] == <self>
static void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
// clear output to indicate no attribute/method found yet
dest[0] = MP_OBJ_NULL;
dest[1] = MP_OBJ_NULL;

View File

@ -10,9 +10,9 @@
// This file defines generic Python stream read/write methods which
// dispatch to the underlying stream interface of an object.
static mp_obj_t stream_readall(mp_obj_t self_in);
STATIC mp_obj_t stream_readall(mp_obj_t self_in);
static mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0];
if (o->type->stream_p.read == NULL) {
// CPython: io.UnsupportedOperation, OSError subclass
@ -35,7 +35,7 @@ static mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
}
}
static mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)self_in;
if (o->type->stream_p.write == NULL) {
// CPython: io.UnsupportedOperation, OSError subclass
@ -58,7 +58,7 @@ static mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
// TODO: should be in mpconfig.h
#define READ_SIZE 256
static mp_obj_t stream_readall(mp_obj_t self_in) {
STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)self_in;
if (o->type->stream_p.read == NULL) {
// CPython: io.UnsupportedOperation, OSError subclass
@ -99,7 +99,7 @@ static mp_obj_t stream_readall(mp_obj_t self_in) {
}
// Unbuffered, inefficient implementation of readline() for raw I/O files.
static mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
STATIC mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0];
if (o->type->stream_p.read == NULL) {
// CPython: io.UnsupportedOperation, OSError subclass

View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include "misc.h"
#include "mpconfig.h"
// attribute flags
#define FL_PRINT (0x01)
@ -19,7 +20,7 @@
#define AT_LO (FL_LOWER | FL_ALPHA | FL_PRINT)
// table of attributes for ascii characters
static const uint8_t attr[] = {
STATIC const uint8_t attr[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, AT_SP, AT_SP, AT_SP, 0, AT_SP, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

View File

@ -3,6 +3,7 @@
#include <string.h>
#include <assert.h>
#include "misc.h"
#include "mpconfig.h"
// returned value is always at least 1 greater than argument
#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
@ -124,7 +125,7 @@ bool vstr_shrink(vstr_t *vstr) {
return vstr_set_size(vstr, vstr->len);
}
static bool vstr_ensure_extra(vstr_t *vstr, int size) {
STATIC bool vstr_ensure_extra(vstr_t *vstr, int size) {
if (vstr->len + size + 1 > vstr->alloc) {
if (vstr->fixed_buf) {
return false;