py: Convert [u]int to mp_[u]int_t in emit.h and associated .c files.
Towards resolving issue #50.
This commit is contained in:
parent
377b80b624
commit
7ff996c237
10
py/compile.c
10
py/compile.c
@ -975,12 +975,12 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int
|
||||
if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
|
||||
for (int j = 0; j < this_scope->id_info_len; j++) {
|
||||
id_info_t *id2 = &this_scope->id_info[j];
|
||||
if (id2->kind == ID_INFO_KIND_FREE && id->qstr == id2->qstr) {
|
||||
if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) {
|
||||
#if MICROPY_EMIT_CPYTHON
|
||||
EMIT_ARG(load_closure, id->qstr, id->local_num);
|
||||
EMIT_ARG(load_closure, id->qst, id->local_num);
|
||||
#else
|
||||
// in Micro Python we load closures using LOAD_FAST
|
||||
EMIT_ARG(load_fast, id->qstr, id->flags, id->local_num);
|
||||
EMIT_ARG(load_fast, id->qst, id->flags, id->local_num);
|
||||
#endif
|
||||
nfree += 1;
|
||||
}
|
||||
@ -3446,7 +3446,7 @@ STATIC void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
|
||||
scope->num_locals = 0;
|
||||
for (int i = 0; i < scope->id_info_len; i++) {
|
||||
id_info_t *id = &scope->id_info[i];
|
||||
if (scope->kind == SCOPE_CLASS && id->qstr == MP_QSTR___class__) {
|
||||
if (scope->kind == SCOPE_CLASS && id->qst == MP_QSTR___class__) {
|
||||
// __class__ is not counted as a local; if it's used then it becomes a ID_INFO_KIND_CELL
|
||||
continue;
|
||||
}
|
||||
@ -3491,7 +3491,7 @@ STATIC void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
|
||||
if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
|
||||
for (int j = 0; j < scope->id_info_len; j++) {
|
||||
id_info_t *id2 = &scope->id_info[j];
|
||||
if (id2->kind == ID_INFO_KIND_FREE && id->qstr == id2->qstr) {
|
||||
if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) {
|
||||
assert(!(id2->flags & ID_FLAG_IS_PARAM)); // free vars should not be params
|
||||
#if MICROPY_EMIT_CPYTHON
|
||||
// in CPython the frees are numbered after the cells
|
||||
|
141
py/emit.h
141
py/emit.h
@ -57,84 +57,84 @@ typedef struct _emit_method_table_t {
|
||||
void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope);
|
||||
void (*end_pass)(emit_t *emit);
|
||||
bool (*last_emit_was_return_value)(emit_t *emit);
|
||||
void (*adjust_stack_size)(emit_t *emit, int delta);
|
||||
void (*set_line_number)(emit_t *emit, int line);
|
||||
void (*adjust_stack_size)(emit_t *emit, mp_int_t delta);
|
||||
void (*set_line_number)(emit_t *emit, mp_uint_t line);
|
||||
|
||||
void (*load_id)(emit_t *emit, qstr qstr);
|
||||
void (*store_id)(emit_t *emit, qstr qstr);
|
||||
void (*delete_id)(emit_t *emit, qstr qstr);
|
||||
void (*load_id)(emit_t *emit, qstr qst);
|
||||
void (*store_id)(emit_t *emit, qstr qst);
|
||||
void (*delete_id)(emit_t *emit, qstr qst);
|
||||
|
||||
void (*label_assign)(emit_t *emit, uint l);
|
||||
void (*import_name)(emit_t *emit, qstr qstr);
|
||||
void (*import_from)(emit_t *emit, qstr qstr);
|
||||
void (*label_assign)(emit_t *emit, mp_uint_t l);
|
||||
void (*import_name)(emit_t *emit, qstr qst);
|
||||
void (*import_from)(emit_t *emit, qstr qst);
|
||||
void (*import_star)(emit_t *emit);
|
||||
void (*load_const_tok)(emit_t *emit, mp_token_kind_t tok);
|
||||
void (*load_const_small_int)(emit_t *emit, mp_int_t arg);
|
||||
void (*load_const_int)(emit_t *emit, qstr qstr);
|
||||
void (*load_const_dec)(emit_t *emit, qstr qstr);
|
||||
void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes);
|
||||
void (*load_const_int)(emit_t *emit, qstr qst);
|
||||
void (*load_const_dec)(emit_t *emit, qstr qst);
|
||||
void (*load_const_str)(emit_t *emit, qstr qst, bool bytes);
|
||||
void (*load_null)(emit_t *emit);
|
||||
void (*load_fast)(emit_t *emit, qstr qstr, uint id_flags, int local_num);
|
||||
void (*load_deref)(emit_t *emit, qstr qstr, int local_num);
|
||||
void (*load_name)(emit_t *emit, qstr qstr);
|
||||
void (*load_global)(emit_t *emit, qstr qstr);
|
||||
void (*load_attr)(emit_t *emit, qstr qstr);
|
||||
void (*load_method)(emit_t *emit, qstr qstr);
|
||||
void (*load_fast)(emit_t *emit, qstr qst, mp_uint_t id_flags, mp_uint_t local_num);
|
||||
void (*load_deref)(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||
void (*load_name)(emit_t *emit, qstr qst);
|
||||
void (*load_global)(emit_t *emit, qstr qst);
|
||||
void (*load_attr)(emit_t *emit, qstr qst);
|
||||
void (*load_method)(emit_t *emit, qstr qst);
|
||||
void (*load_build_class)(emit_t *emit);
|
||||
void (*load_subscr)(emit_t *emit);
|
||||
void (*store_fast)(emit_t *emit, qstr qstr, int local_num);
|
||||
void (*store_deref)(emit_t *emit, qstr qstr, int local_num);
|
||||
void (*store_name)(emit_t *emit, qstr qstr);
|
||||
void (*store_global)(emit_t *emit, qstr qstr);
|
||||
void (*store_attr)(emit_t *emit, qstr qstr);
|
||||
void (*store_fast)(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||
void (*store_deref)(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||
void (*store_name)(emit_t *emit, qstr qst);
|
||||
void (*store_global)(emit_t *emit, qstr qst);
|
||||
void (*store_attr)(emit_t *emit, qstr qst);
|
||||
void (*store_subscr)(emit_t *emit);
|
||||
void (*delete_fast)(emit_t *emit, qstr qstr, int local_num);
|
||||
void (*delete_deref)(emit_t *emit, qstr qstr, int local_num);
|
||||
void (*delete_name)(emit_t *emit, qstr qstr);
|
||||
void (*delete_global)(emit_t *emit, qstr qstr);
|
||||
void (*delete_attr)(emit_t *emit, qstr qstr);
|
||||
void (*delete_fast)(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||
void (*delete_deref)(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||
void (*delete_name)(emit_t *emit, qstr qst);
|
||||
void (*delete_global)(emit_t *emit, qstr qst);
|
||||
void (*delete_attr)(emit_t *emit, qstr qst);
|
||||
void (*delete_subscr)(emit_t *emit);
|
||||
void (*dup_top)(emit_t *emit);
|
||||
void (*dup_top_two)(emit_t *emit);
|
||||
void (*pop_top)(emit_t *emit);
|
||||
void (*rot_two)(emit_t *emit);
|
||||
void (*rot_three)(emit_t *emit);
|
||||
void (*jump)(emit_t *emit, uint label);
|
||||
void (*pop_jump_if_true)(emit_t *emit, uint label);
|
||||
void (*pop_jump_if_false)(emit_t *emit, uint label);
|
||||
void (*jump_if_true_or_pop)(emit_t *emit, uint label);
|
||||
void (*jump_if_false_or_pop)(emit_t *emit, uint label);
|
||||
void (*break_loop)(emit_t *emit, uint label, int except_depth);
|
||||
void (*continue_loop)(emit_t *emit, uint label, int except_depth);
|
||||
void (*setup_with)(emit_t *emit, uint label);
|
||||
void (*jump)(emit_t *emit, mp_uint_t label);
|
||||
void (*pop_jump_if_true)(emit_t *emit, mp_uint_t label);
|
||||
void (*pop_jump_if_false)(emit_t *emit, mp_uint_t label);
|
||||
void (*jump_if_true_or_pop)(emit_t *emit, mp_uint_t label);
|
||||
void (*jump_if_false_or_pop)(emit_t *emit, mp_uint_t label);
|
||||
void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
|
||||
void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
|
||||
void (*setup_with)(emit_t *emit, mp_uint_t label);
|
||||
void (*with_cleanup)(emit_t *emit);
|
||||
void (*setup_except)(emit_t *emit, uint label);
|
||||
void (*setup_finally)(emit_t *emit, uint label);
|
||||
void (*setup_except)(emit_t *emit, mp_uint_t label);
|
||||
void (*setup_finally)(emit_t *emit, mp_uint_t label);
|
||||
void (*end_finally)(emit_t *emit);
|
||||
void (*get_iter)(emit_t *emit);
|
||||
void (*for_iter)(emit_t *emit, uint label);
|
||||
void (*for_iter)(emit_t *emit, mp_uint_t label);
|
||||
void (*for_iter_end)(emit_t *emit);
|
||||
void (*pop_block)(emit_t *emit);
|
||||
void (*pop_except)(emit_t *emit);
|
||||
void (*unary_op)(emit_t *emit, mp_unary_op_t op);
|
||||
void (*binary_op)(emit_t *emit, mp_binary_op_t op);
|
||||
void (*build_tuple)(emit_t *emit, int n_args);
|
||||
void (*build_list)(emit_t *emit, int n_args);
|
||||
void (*list_append)(emit_t *emit, int list_stack_index);
|
||||
void (*build_map)(emit_t *emit, int n_args);
|
||||
void (*build_tuple)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*build_list)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*list_append)(emit_t *emit, mp_uint_t list_stack_index);
|
||||
void (*build_map)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*store_map)(emit_t *emit);
|
||||
void (*map_add)(emit_t *emit, int map_stack_index);
|
||||
void (*build_set)(emit_t *emit, int n_args);
|
||||
void (*set_add)(emit_t *emit, int set_stack_index);
|
||||
void (*build_slice)(emit_t *emit, int n_args);
|
||||
void (*unpack_sequence)(emit_t *emit, int n_args);
|
||||
void (*unpack_ex)(emit_t *emit, int n_left, int n_right);
|
||||
void (*make_function)(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults);
|
||||
void (*make_closure)(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults);
|
||||
void (*call_function)(emit_t *emit, int n_positional, int n_keyword, uint star_flags);
|
||||
void (*call_method)(emit_t *emit, int n_positional, int n_keyword, uint star_flags);
|
||||
void (*map_add)(emit_t *emit, mp_uint_t map_stack_index);
|
||||
void (*build_set)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*set_add)(emit_t *emit, mp_uint_t set_stack_index);
|
||||
void (*build_slice)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*unpack_sequence)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*unpack_ex)(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right);
|
||||
void (*make_function)(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults);
|
||||
void (*make_closure)(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults);
|
||||
void (*call_function)(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags);
|
||||
void (*call_method)(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags);
|
||||
void (*return_value)(emit_t *emit);
|
||||
void (*raise_varargs)(emit_t *emit, int n_args);
|
||||
void (*raise_varargs)(emit_t *emit, mp_uint_t n_args);
|
||||
void (*yield_value)(emit_t *emit);
|
||||
void (*yield_from)(emit_t *emit);
|
||||
|
||||
@ -146,15 +146,15 @@ typedef struct _emit_method_table_t {
|
||||
#if MICROPY_EMIT_CPYTHON
|
||||
// these methods are only needed for emitcpy
|
||||
void (*load_const_verbatim_str)(emit_t *emit, const char *str);
|
||||
void (*load_closure)(emit_t *emit, qstr qstr, int local_num);
|
||||
void (*setup_loop)(emit_t *emit, uint label);
|
||||
void (*load_closure)(emit_t *emit, qstr qst, mp_uint_t local_num);
|
||||
void (*setup_loop)(emit_t *emit, mp_uint_t label);
|
||||
#endif
|
||||
|
||||
} emit_method_table_t;
|
||||
|
||||
void emit_common_load_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qstr);
|
||||
void emit_common_store_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qstr);
|
||||
void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qstr);
|
||||
void emit_common_load_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qst);
|
||||
void emit_common_store_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qst);
|
||||
void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qst);
|
||||
|
||||
extern const emit_method_table_t emit_pass1_method_table;
|
||||
extern const emit_method_table_t emit_cpython_method_table;
|
||||
@ -165,12 +165,12 @@ extern const emit_method_table_t emit_native_thumb_method_table;
|
||||
extern const emit_method_table_t emit_native_arm_method_table;
|
||||
|
||||
emit_t *emit_pass1_new(void);
|
||||
emit_t *emit_cpython_new(uint max_num_labels);
|
||||
emit_t *emit_bc_new(uint max_num_labels);
|
||||
emit_t *emit_native_x64_new(uint max_num_labels);
|
||||
emit_t *emit_native_x86_new(uint max_num_labels);
|
||||
emit_t *emit_native_thumb_new(uint max_num_labels);
|
||||
emit_t *emit_native_arm_new(uint max_num_labels);
|
||||
emit_t *emit_cpython_new(mp_uint_t max_num_labels);
|
||||
emit_t *emit_bc_new(mp_uint_t max_num_labels);
|
||||
emit_t *emit_native_x64_new(mp_uint_t max_num_labels);
|
||||
emit_t *emit_native_x86_new(mp_uint_t max_num_labels);
|
||||
emit_t *emit_native_thumb_new(mp_uint_t max_num_labels);
|
||||
emit_t *emit_native_arm_new(mp_uint_t max_num_labels);
|
||||
|
||||
void emit_pass1_free(emit_t *emit);
|
||||
void emit_bc_free(emit_t *emit);
|
||||
@ -184,15 +184,14 @@ typedef struct _emit_inline_asm_t emit_inline_asm_t;
|
||||
typedef struct _emit_inline_asm_method_table_t {
|
||||
void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope);
|
||||
bool (*end_pass)(emit_inline_asm_t *emit);
|
||||
int (*count_params)(emit_inline_asm_t *emit, int n_params, mp_parse_node_t *pn_params);
|
||||
void (*label)(emit_inline_asm_t *emit, uint label_num, qstr label_id);
|
||||
void (*align)(emit_inline_asm_t *emit, uint align);
|
||||
void (*data)(emit_inline_asm_t *emit, uint bytesize, uint val);
|
||||
void (*op)(emit_inline_asm_t *emit, qstr op, int n_args, mp_parse_node_t *pn_args);
|
||||
mp_uint_t (*count_params)(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params);
|
||||
void (*label)(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id);
|
||||
void (*align)(emit_inline_asm_t *emit, mp_uint_t align);
|
||||
void (*data)(emit_inline_asm_t *emit, mp_uint_t bytesize, mp_uint_t val);
|
||||
void (*op)(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args);
|
||||
} emit_inline_asm_method_table_t;
|
||||
|
||||
extern const emit_inline_asm_method_table_t emit_inline_thumb_method_table;
|
||||
|
||||
emit_inline_asm_t *emit_inline_thumb_new(uint max_num_labels);
|
||||
emit_inline_asm_t *emit_inline_thumb_new(mp_uint_t max_num_labels);
|
||||
void emit_inline_thumb_free(emit_inline_asm_t *emit);
|
||||
|
||||
|
214
py/emitbc.c
214
py/emitbc.c
@ -49,39 +49,39 @@
|
||||
|
||||
struct _emit_t {
|
||||
pass_kind_t pass : 8;
|
||||
uint last_emit_was_return_value : 8;
|
||||
mp_uint_t last_emit_was_return_value : 8;
|
||||
|
||||
int stack_size;
|
||||
|
||||
scope_t *scope;
|
||||
|
||||
uint last_source_line_offset;
|
||||
uint last_source_line;
|
||||
mp_uint_t last_source_line_offset;
|
||||
mp_uint_t last_source_line;
|
||||
|
||||
uint max_num_labels;
|
||||
uint *label_offsets;
|
||||
mp_uint_t max_num_labels;
|
||||
mp_uint_t *label_offsets;
|
||||
|
||||
uint code_info_offset;
|
||||
uint code_info_size;
|
||||
uint bytecode_offset;
|
||||
uint bytecode_size;
|
||||
mp_uint_t code_info_offset;
|
||||
mp_uint_t code_info_size;
|
||||
mp_uint_t bytecode_offset;
|
||||
mp_uint_t bytecode_size;
|
||||
byte *code_base; // stores both byte code and code info
|
||||
// Accessed as uint, so must be aligned as such
|
||||
// Accessed as mp_uint_t, so must be aligned as such
|
||||
byte dummy_data[DUMMY_DATA_SIZE];
|
||||
};
|
||||
|
||||
STATIC void emit_bc_rot_two(emit_t *emit);
|
||||
STATIC void emit_bc_rot_three(emit_t *emit);
|
||||
|
||||
emit_t *emit_bc_new(uint max_num_labels) {
|
||||
emit_t *emit_bc_new(mp_uint_t max_num_labels) {
|
||||
emit_t *emit = m_new0(emit_t, 1);
|
||||
emit->max_num_labels = max_num_labels;
|
||||
emit->label_offsets = m_new(uint, emit->max_num_labels);
|
||||
emit->label_offsets = m_new(mp_uint_t, emit->max_num_labels);
|
||||
return emit;
|
||||
}
|
||||
|
||||
void emit_bc_free(emit_t *emit) {
|
||||
m_del(uint, emit->label_offsets, emit->max_num_labels);
|
||||
m_del(mp_uint_t, emit->label_offsets, emit->max_num_labels);
|
||||
m_del_obj(emit_t, emit);
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ STATIC void emit_write_code_info_qstr(emit_t* emit, qstr qst) {
|
||||
}
|
||||
|
||||
#if MICROPY_ENABLE_SOURCE_LINE
|
||||
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, mp_uint_t bytes_to_skip, mp_uint_t lines_to_skip) {
|
||||
assert(bytes_to_skip > 0 || lines_to_skip > 0);
|
||||
//printf(" %d %d\n", bytes_to_skip, lines_to_skip);
|
||||
while (bytes_to_skip > 0 || lines_to_skip > 0) {
|
||||
@ -179,7 +179,7 @@ STATIC void emit_write_bytecode_uint(emit_t* emit, mp_uint_t val) {
|
||||
emit_write_uint(emit, emit_get_cur_to_write_bytecode, val);
|
||||
}
|
||||
|
||||
STATIC void emit_write_bytecode_byte_byte(emit_t* emit, byte b1, uint b2) {
|
||||
STATIC void emit_write_bytecode_byte_byte(emit_t* emit, byte b1, byte b2) {
|
||||
assert((b2 & (~0xff)) == 0);
|
||||
byte* c = emit_get_cur_to_write_bytecode(emit, 2);
|
||||
c[0] = b1;
|
||||
@ -229,20 +229,20 @@ STATIC void emit_write_bytecode_byte_ptr(emit_t* emit, byte b, void *ptr) {
|
||||
}
|
||||
|
||||
/* currently unused
|
||||
STATIC void emit_write_bytecode_byte_uint_uint(emit_t* emit, byte b, uint num1, uint num2) {
|
||||
STATIC void emit_write_bytecode_byte_uint_uint(emit_t* emit, byte b, mp_uint_t num1, mp_uint_t num2) {
|
||||
emit_write_bytecode_byte(emit, b);
|
||||
emit_write_bytecode_byte_uint(emit, num1);
|
||||
emit_write_bytecode_byte_uint(emit, num2);
|
||||
}
|
||||
*/
|
||||
|
||||
STATIC void emit_write_bytecode_byte_qstr(emit_t* emit, byte b, qstr qstr) {
|
||||
emit_write_bytecode_byte_uint(emit, b, qstr);
|
||||
STATIC void emit_write_bytecode_byte_qstr(emit_t* emit, byte b, qstr qst) {
|
||||
emit_write_bytecode_byte_uint(emit, b, qst);
|
||||
}
|
||||
|
||||
// unsigned labels are relative to ip following this instruction, stored as 16 bits
|
||||
STATIC void emit_write_bytecode_byte_unsigned_label(emit_t* emit, byte b1, uint label) {
|
||||
uint bytecode_offset;
|
||||
STATIC void emit_write_bytecode_byte_unsigned_label(emit_t* emit, byte b1, mp_uint_t label) {
|
||||
mp_uint_t bytecode_offset;
|
||||
if (emit->pass < MP_PASS_EMIT) {
|
||||
bytecode_offset = 0;
|
||||
} else {
|
||||
@ -255,7 +255,7 @@ STATIC void emit_write_bytecode_byte_unsigned_label(emit_t* emit, byte b1, uint
|
||||
}
|
||||
|
||||
// signed labels are relative to ip following this instruction, stored as 16 bits, in excess
|
||||
STATIC void emit_write_bytecode_byte_signed_label(emit_t* emit, byte b1, uint label) {
|
||||
STATIC void emit_write_bytecode_byte_signed_label(emit_t* emit, byte b1, mp_uint_t label) {
|
||||
int bytecode_offset;
|
||||
if (emit->pass < MP_PASS_EMIT) {
|
||||
bytecode_offset = 0;
|
||||
@ -279,7 +279,7 @@ STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
|
||||
emit->last_source_line_offset = 0;
|
||||
emit->last_source_line = 1;
|
||||
if (pass < MP_PASS_EMIT) {
|
||||
memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(uint));
|
||||
memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(mp_uint_t));
|
||||
}
|
||||
emit->bytecode_offset = 0;
|
||||
emit->code_info_offset = 0;
|
||||
@ -296,7 +296,7 @@ STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
|
||||
|
||||
// bytecode prelude: local state size and exception stack size; 16 bit uints for now
|
||||
{
|
||||
uint n_state = scope->num_locals + scope->stack_size;
|
||||
mp_uint_t n_state = scope->num_locals + scope->stack_size;
|
||||
if (n_state == 0) {
|
||||
// Need at least 1 entry in the state, in the case an exception is
|
||||
// propagated through this function, the exception is returned in
|
||||
@ -360,7 +360,7 @@ STATIC void emit_bc_end_pass(emit_t *emit) {
|
||||
} else if (emit->pass == MP_PASS_EMIT) {
|
||||
qstr *arg_names = m_new(qstr, emit->scope->num_pos_args + emit->scope->num_kwonly_args);
|
||||
for (int i = 0; i < emit->scope->num_pos_args + emit->scope->num_kwonly_args; i++) {
|
||||
arg_names[i] = emit->scope->id_info[i].qstr;
|
||||
arg_names[i] = emit->scope->id_info[i].qst;
|
||||
}
|
||||
mp_emit_glue_assign_bytecode(emit->scope->raw_code, emit->code_base,
|
||||
emit->code_info_size + emit->bytecode_size,
|
||||
@ -373,11 +373,11 @@ STATIC bool emit_bc_last_emit_was_return_value(emit_t *emit) {
|
||||
return emit->last_emit_was_return_value;
|
||||
}
|
||||
|
||||
STATIC void emit_bc_adjust_stack_size(emit_t *emit, int delta) {
|
||||
STATIC void emit_bc_adjust_stack_size(emit_t *emit, mp_int_t delta) {
|
||||
emit->stack_size += delta;
|
||||
}
|
||||
|
||||
STATIC void emit_bc_set_source_line(emit_t *emit, int source_line) {
|
||||
STATIC void emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
|
||||
//printf("source: line %d -> %d offset %d -> %d\n", emit->last_source_line, source_line, emit->last_source_line_offset, emit->bytecode_offset);
|
||||
#if MICROPY_ENABLE_SOURCE_LINE
|
||||
if (mp_optimise_value >= 3) {
|
||||
@ -385,8 +385,8 @@ STATIC void emit_bc_set_source_line(emit_t *emit, int source_line) {
|
||||
return;
|
||||
}
|
||||
if (source_line > emit->last_source_line) {
|
||||
uint bytes_to_skip = emit->bytecode_offset - emit->last_source_line_offset;
|
||||
uint lines_to_skip = source_line - emit->last_source_line;
|
||||
mp_uint_t bytes_to_skip = emit->bytecode_offset - emit->last_source_line_offset;
|
||||
mp_uint_t lines_to_skip = source_line - emit->last_source_line;
|
||||
emit_write_code_info_bytes_lines(emit, bytes_to_skip, lines_to_skip);
|
||||
emit->last_source_line_offset = emit->bytecode_offset;
|
||||
emit->last_source_line = source_line;
|
||||
@ -394,20 +394,20 @@ 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) {
|
||||
emit_common_load_id(emit, &emit_bc_method_table, emit->scope, qstr);
|
||||
STATIC void emit_bc_load_id(emit_t *emit, qstr qst) {
|
||||
emit_common_load_id(emit, &emit_bc_method_table, emit->scope, qst);
|
||||
}
|
||||
|
||||
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_store_id(emit_t *emit, qstr qst) {
|
||||
emit_common_store_id(emit, &emit_bc_method_table, emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_delete_id(emit_t *emit, qstr qstr) {
|
||||
emit_common_delete_id(emit, &emit_bc_method_table, emit->scope, qstr);
|
||||
STATIC void emit_bc_delete_id(emit_t *emit, qstr qst) {
|
||||
emit_common_delete_id(emit, &emit_bc_method_table, emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_pre(emit_t *emit, int stack_size_delta) {
|
||||
assert((int)emit->stack_size + stack_size_delta >= 0);
|
||||
STATIC void emit_bc_pre(emit_t *emit, mp_int_t stack_size_delta) {
|
||||
assert((mp_int_t)emit->stack_size + stack_size_delta >= 0);
|
||||
emit->stack_size += stack_size_delta;
|
||||
if (emit->stack_size > emit->scope->stack_size) {
|
||||
emit->scope->stack_size = emit->stack_size;
|
||||
@ -415,7 +415,7 @@ STATIC void emit_bc_pre(emit_t *emit, int stack_size_delta) {
|
||||
emit->last_emit_was_return_value = false;
|
||||
}
|
||||
|
||||
STATIC void emit_bc_label_assign(emit_t *emit, uint l) {
|
||||
STATIC void emit_bc_label_assign(emit_t *emit, mp_uint_t l) {
|
||||
emit_bc_pre(emit, 0);
|
||||
assert(l < emit->max_num_labels);
|
||||
if (emit->pass < MP_PASS_EMIT) {
|
||||
@ -429,14 +429,14 @@ STATIC void emit_bc_label_assign(emit_t *emit, uint l) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_import_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_import_name(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_IMPORT_NAME, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_IMPORT_NAME, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_import_from(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_import_from(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_IMPORT_FROM, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_IMPORT_FROM, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_import_star(emit_t *emit) {
|
||||
@ -460,22 +460,22 @@ STATIC void emit_bc_load_const_small_int(emit_t *emit, mp_int_t arg) {
|
||||
emit_write_bytecode_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 qst) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_INT, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_INT, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_const_dec(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_load_const_dec(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_DEC, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_DEC, qst);
|
||||
}
|
||||
|
||||
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 qst, bool bytes) {
|
||||
emit_bc_pre(emit, 1);
|
||||
if (bytes) {
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_BYTES, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_BYTES, qst);
|
||||
} else {
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_STRING, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_CONST_STRING, qst);
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,7 +484,7 @@ STATIC void emit_bc_load_null(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_NULL);
|
||||
};
|
||||
|
||||
STATIC void emit_bc_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) {
|
||||
STATIC void emit_bc_load_fast(emit_t *emit, qstr qst, mp_uint_t id_flags, mp_uint_t local_num) {
|
||||
assert(local_num >= 0);
|
||||
emit_bc_pre(emit, 1);
|
||||
switch (local_num) {
|
||||
@ -495,29 +495,29 @@ STATIC void emit_bc_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_deref(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_bc_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_LOAD_DEREF, local_num);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_load_name(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_NAME, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_NAME, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_load_global(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_GLOBAL, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_GLOBAL, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_load_attr(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_ATTR, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_ATTR, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_method(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_load_method(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_METHOD, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_LOAD_METHOD, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_build_class(emit_t *emit) {
|
||||
@ -530,7 +530,7 @@ STATIC void emit_bc_load_subscr(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_SUBSCR);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_store_fast(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_bc_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
assert(local_num >= 0);
|
||||
emit_bc_pre(emit, -1);
|
||||
switch (local_num) {
|
||||
@ -541,24 +541,24 @@ 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 qst, mp_uint_t local_num) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_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 qst) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_NAME, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_NAME, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_store_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_store_global(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_GLOBAL, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_GLOBAL, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_store_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_store_attr(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, -2);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_ATTR, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_ATTR, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_store_subscr(emit_t *emit) {
|
||||
@ -566,28 +566,28 @@ STATIC void emit_bc_store_subscr(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_STORE_SUBSCR);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_delete_fast(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_bc_delete_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_DELETE_FAST, 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 qst, mp_uint_t local_num) {
|
||||
emit_write_bytecode_byte_uint(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 qst) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_DELETE_NAME, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_DELETE_NAME, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_delete_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_delete_global(emit_t *emit, qstr qst) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_DELETE_GLOBAL, qstr);
|
||||
emit_write_bytecode_byte_qstr(emit, MP_BC_DELETE_GLOBAL, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_delete_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_bc_delete_attr(emit_t *emit, qstr qst) {
|
||||
emit_bc_load_null(emit);
|
||||
emit_bc_rot_two(emit);
|
||||
emit_bc_store_attr(emit, qstr);
|
||||
emit_bc_store_attr(emit, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_delete_subscr(emit_t *emit) {
|
||||
@ -621,32 +621,32 @@ STATIC void emit_bc_rot_three(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_ROT_THREE);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_jump(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_jump(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP, label);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_pop_jump_if_true(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_pop_jump_if_true(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_TRUE, label);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_pop_jump_if_false(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_pop_jump_if_false(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_FALSE, label);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_jump_if_true_or_pop(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_TRUE_OR_POP, label);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_unwind_jump(emit_t *emit, uint label, int except_depth) {
|
||||
STATIC void emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
||||
if (except_depth == 0) {
|
||||
emit_bc_pre(emit, 0);
|
||||
if (label & MP_EMIT_BREAK_FROM_FOR) {
|
||||
@ -660,7 +660,7 @@ STATIC void emit_bc_unwind_jump(emit_t *emit, uint label, int except_depth) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_setup_with(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_setup_with(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, 7);
|
||||
emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label);
|
||||
}
|
||||
@ -670,12 +670,12 @@ STATIC void emit_bc_with_cleanup(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_WITH_CLEANUP);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_setup_except(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_setup_except(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_EXCEPT, label);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_setup_finally(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_setup_finally(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_FINALLY, label);
|
||||
}
|
||||
@ -690,7 +690,7 @@ STATIC void emit_bc_get_iter(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_GET_ITER);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_for_iter(emit_t *emit, uint label) {
|
||||
STATIC void emit_bc_for_iter(emit_t *emit, mp_uint_t label) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_unsigned_label(emit, MP_BC_FOR_ITER, label);
|
||||
}
|
||||
@ -738,26 +738,22 @@ STATIC void emit_bc_binary_op(emit_t *emit, mp_binary_op_t op) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_build_tuple(emit_t *emit, int n_args) {
|
||||
assert(n_args >= 0);
|
||||
STATIC void emit_bc_build_tuple(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_bc_pre(emit, 1 - n_args);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_BUILD_TUPLE, n_args);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_build_list(emit_t *emit, int n_args) {
|
||||
assert(n_args >= 0);
|
||||
STATIC void emit_bc_build_list(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_bc_pre(emit, 1 - n_args);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_BUILD_LIST, n_args);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_list_append(emit_t *emit, int list_stack_index) {
|
||||
assert(list_stack_index >= 0);
|
||||
STATIC void emit_bc_list_append(emit_t *emit, mp_uint_t list_stack_index) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_LIST_APPEND, list_stack_index);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_build_map(emit_t *emit, int n_args) {
|
||||
assert(n_args >= 0);
|
||||
STATIC void emit_bc_build_map(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_BUILD_MAP, n_args);
|
||||
}
|
||||
@ -767,43 +763,37 @@ STATIC void emit_bc_store_map(emit_t *emit) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_STORE_MAP);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_map_add(emit_t *emit, int map_stack_index) {
|
||||
assert(map_stack_index >= 0);
|
||||
STATIC void emit_bc_map_add(emit_t *emit, mp_uint_t map_stack_index) {
|
||||
emit_bc_pre(emit, -2);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_MAP_ADD, map_stack_index);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_build_set(emit_t *emit, int n_args) {
|
||||
assert(n_args >= 0);
|
||||
STATIC void emit_bc_build_set(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_bc_pre(emit, 1 - n_args);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_BUILD_SET, n_args);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_set_add(emit_t *emit, int set_stack_index) {
|
||||
assert(set_stack_index >= 0);
|
||||
STATIC void emit_bc_set_add(emit_t *emit, mp_uint_t set_stack_index) {
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_SET_ADD, set_stack_index);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_build_slice(emit_t *emit, int n_args) {
|
||||
assert(n_args >= 0);
|
||||
STATIC void emit_bc_build_slice(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_bc_pre(emit, 1 - n_args);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_BUILD_SLICE, n_args);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_unpack_sequence(emit_t *emit, int n_args) {
|
||||
assert(n_args >= 0);
|
||||
STATIC void emit_bc_unpack_sequence(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_bc_pre(emit, -1 + n_args);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_UNPACK_SEQUENCE, n_args);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) {
|
||||
assert(n_left >=0 && n_right >= 0);
|
||||
STATIC void emit_bc_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right) {
|
||||
emit_bc_pre(emit, -1 + n_left + n_right + 1);
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_UNPACK_EX, n_left | (n_right << 8));
|
||||
}
|
||||
|
||||
STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
|
||||
STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) {
|
||||
if (n_pos_defaults == 0 && n_kw_defaults == 0) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_ptr(emit, MP_BC_MAKE_FUNCTION, scope->raw_code);
|
||||
@ -813,7 +803,7 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, uint n_pos_defau
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults) {
|
||||
STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) {
|
||||
if (n_pos_defaults == 0 && n_kw_defaults == 0) {
|
||||
emit_bc_pre(emit, -n_closed_over + 1);
|
||||
emit_write_bytecode_byte_ptr(emit, MP_BC_MAKE_CLOSURE, scope->raw_code);
|
||||
@ -826,7 +816,7 @@ STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, uint n_closed_ove
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, uint bytecode_base, int n_positional, int n_keyword, uint star_flags) {
|
||||
STATIC void emit_bc_call_function_method_helper(emit_t *emit, mp_int_t stack_adj, mp_uint_t bytecode_base, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
if (star_flags) {
|
||||
if (!(star_flags & MP_EMIT_STAR_FLAG_SINGLE)) {
|
||||
// load dummy entry for non-existent pos_seq
|
||||
@ -836,19 +826,19 @@ STATIC void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, uin
|
||||
// load dummy entry for non-existent kw_dict
|
||||
emit_bc_load_null(emit);
|
||||
}
|
||||
emit_bc_pre(emit, stack_adj - n_positional - 2 * n_keyword - 2);
|
||||
emit_bc_pre(emit, stack_adj - (mp_int_t)n_positional - 2 * (mp_int_t)n_keyword - 2);
|
||||
emit_write_bytecode_byte_uint(emit, bytecode_base + 1, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints?
|
||||
} else {
|
||||
emit_bc_pre(emit, stack_adj - n_positional - 2 * n_keyword);
|
||||
emit_bc_pre(emit, stack_adj - (mp_int_t)n_positional - 2 * (mp_int_t)n_keyword);
|
||||
emit_write_bytecode_byte_uint(emit, bytecode_base, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints?
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
|
||||
STATIC void emit_bc_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
emit_bc_call_function_method_helper(emit, 0, MP_BC_CALL_FUNCTION, n_positional, n_keyword, star_flags);
|
||||
}
|
||||
|
||||
STATIC void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
|
||||
STATIC void emit_bc_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
emit_bc_call_function_method_helper(emit, -1, MP_BC_CALL_METHOD, n_positional, n_keyword, star_flags);
|
||||
}
|
||||
|
||||
@ -858,7 +848,7 @@ STATIC void emit_bc_return_value(emit_t *emit) {
|
||||
emit_write_bytecode_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, mp_uint_t n_args) {
|
||||
assert(0 <= n_args && n_args <= 2);
|
||||
emit_bc_pre(emit, -n_args);
|
||||
emit_write_bytecode_byte_byte(emit, MP_BC_RAISE_VARARGS, n_args);
|
||||
|
@ -41,61 +41,61 @@
|
||||
|
||||
#define EMIT(fun, ...) (emit_method_table->fun(emit, __VA_ARGS__))
|
||||
|
||||
void emit_common_load_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qstr) {
|
||||
void emit_common_load_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qst) {
|
||||
// assumes pass is greater than 1, ie that all identifiers are defined in the scope
|
||||
|
||||
id_info_t *id = scope_find(scope, qstr);
|
||||
id_info_t *id = scope_find(scope, qst);
|
||||
assert(id != NULL); // TODO can this ever fail?
|
||||
|
||||
// call the emit backend with the correct code
|
||||
if (id == NULL || id->kind == ID_INFO_KIND_GLOBAL_IMPLICIT) {
|
||||
EMIT(load_name, qstr);
|
||||
EMIT(load_name, qst);
|
||||
} else if (id->kind == ID_INFO_KIND_GLOBAL_EXPLICIT) {
|
||||
EMIT(load_global, qstr);
|
||||
EMIT(load_global, qst);
|
||||
} else if (id->kind == ID_INFO_KIND_LOCAL) {
|
||||
EMIT(load_fast, qstr, id->flags, id->local_num);
|
||||
EMIT(load_fast, qst, id->flags, id->local_num);
|
||||
} else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
|
||||
EMIT(load_deref, qstr, id->local_num);
|
||||
EMIT(load_deref, qst, id->local_num);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
void emit_common_store_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qstr) {
|
||||
void emit_common_store_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qst) {
|
||||
// assumes pass is greater than 1, ie that all identifiers are defined in the scope
|
||||
|
||||
id_info_t *id = scope_find(scope, qstr);
|
||||
id_info_t *id = scope_find(scope, qst);
|
||||
assert(id != NULL); // TODO can this ever fail?
|
||||
|
||||
// call the emit backend with the correct code
|
||||
if (id == NULL || id->kind == ID_INFO_KIND_GLOBAL_IMPLICIT) {
|
||||
EMIT(store_name, qstr);
|
||||
EMIT(store_name, qst);
|
||||
} else if (id->kind == ID_INFO_KIND_GLOBAL_EXPLICIT) {
|
||||
EMIT(store_global, qstr);
|
||||
EMIT(store_global, qst);
|
||||
} else if (id->kind == ID_INFO_KIND_LOCAL) {
|
||||
EMIT(store_fast, qstr, id->local_num);
|
||||
EMIT(store_fast, qst, id->local_num);
|
||||
} else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
|
||||
EMIT(store_deref, qstr, id->local_num);
|
||||
EMIT(store_deref, qst, id->local_num);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qstr) {
|
||||
void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_table, scope_t *scope, qstr qst) {
|
||||
// assumes pass is greater than 1, ie that all identifiers are defined in the scope
|
||||
|
||||
id_info_t *id = scope_find(scope, qstr);
|
||||
id_info_t *id = scope_find(scope, qst);
|
||||
assert(id != NULL); // TODO can this ever fail?
|
||||
|
||||
// call the emit backend with the correct code
|
||||
if (id == NULL || id->kind == ID_INFO_KIND_GLOBAL_IMPLICIT) {
|
||||
EMIT(delete_name, qstr);
|
||||
EMIT(delete_name, qst);
|
||||
} else if (id->kind == ID_INFO_KIND_GLOBAL_EXPLICIT) {
|
||||
EMIT(delete_global, qstr);
|
||||
EMIT(delete_global, qst);
|
||||
} else if (id->kind == ID_INFO_KIND_LOCAL) {
|
||||
EMIT(delete_fast, qstr, id->local_num);
|
||||
EMIT(delete_fast, qst, id->local_num);
|
||||
} else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
|
||||
EMIT(delete_deref, qstr, id->local_num);
|
||||
EMIT(delete_deref, qst, id->local_num);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
236
py/emitcpy.c
236
py/emitcpy.c
@ -52,14 +52,14 @@ struct _emit_t {
|
||||
|
||||
scope_t *scope;
|
||||
|
||||
uint max_num_labels;
|
||||
int *label_offsets;
|
||||
mp_uint_t max_num_labels;
|
||||
mp_uint_t *label_offsets;
|
||||
};
|
||||
|
||||
emit_t *emit_cpython_new(uint max_num_labels) {
|
||||
emit_t *emit_cpython_new(mp_uint_t max_num_labels) {
|
||||
emit_t *emit = m_new(emit_t, 1);
|
||||
emit->max_num_labels = max_num_labels;
|
||||
emit->label_offsets = m_new(int, max_num_labels);
|
||||
emit->label_offsets = m_new(mp_uint_t, max_num_labels);
|
||||
return emit;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ STATIC void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope)
|
||||
emit->last_emit_was_return_value = false;
|
||||
emit->scope = scope;
|
||||
if (pass < MP_PASS_EMIT) {
|
||||
memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int));
|
||||
memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(mp_uint_t));
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,23 +88,23 @@ STATIC bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
|
||||
return emit->last_emit_was_return_value;
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_adjust_stack_size(emit_t *emit, int delta) {
|
||||
STATIC void emit_cpy_adjust_stack_size(emit_t *emit, mp_int_t delta) {
|
||||
emit->stack_size += delta;
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_set_source_line(emit_t *emit, int source_line) {
|
||||
STATIC void emit_cpy_set_source_line(emit_t *emit, mp_uint_t source_line) {
|
||||
}
|
||||
|
||||
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_load_id(emit_t *emit, qstr qst) {
|
||||
emit_common_load_id(emit, &emit_cpython_method_table, emit->scope, qst);
|
||||
}
|
||||
|
||||
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_store_id(emit_t *emit, qstr qst) {
|
||||
emit_common_store_id(emit, &emit_cpython_method_table, emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_delete_id(emit_t *emit, qstr qstr) {
|
||||
emit_common_delete_id(emit, &emit_cpython_method_table, emit->scope, qstr);
|
||||
STATIC void emit_cpy_delete_id(emit_t *emit, qstr qst) {
|
||||
emit_common_delete_id(emit, &emit_cpython_method_table, emit->scope, qst);
|
||||
}
|
||||
|
||||
// TODO: module-polymorphic function (read: name clash if made global)
|
||||
@ -124,7 +124,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta, int bytecode_size) {
|
||||
emit->bytecode_offset += bytecode_size;
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_label_assign(emit_t *emit, uint l) {
|
||||
STATIC void emit_cpy_label_assign(emit_t *emit, mp_uint_t l) {
|
||||
emit_pre(emit, 0, 0);
|
||||
assert(l < emit->max_num_labels);
|
||||
if (emit->pass < MP_PASS_EMIT) {
|
||||
@ -138,17 +138,17 @@ STATIC void emit_cpy_label_assign(emit_t *emit, uint l) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_import_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_import_name(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("IMPORT_NAME %s\n", qstr_str(qstr));
|
||||
printf("IMPORT_NAME %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_import_from(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_import_from(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("IMPORT_FROM %s\n", qstr_str(qstr));
|
||||
printf("IMPORT_FROM %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,22 +180,22 @@ STATIC void emit_cpy_load_const_small_int(emit_t *emit, mp_int_t arg) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_const_int(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_load_const_int(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_CONST %s\n", qstr_str(qstr));
|
||||
printf("LOAD_CONST %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_const_dec(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_load_const_dec(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_CONST %s\n", qstr_str(qstr));
|
||||
printf("LOAD_CONST %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void print_quoted_str(qstr qstr, bool bytes) {
|
||||
const char *str = qstr_str(qstr);
|
||||
STATIC void print_quoted_str(qstr qst, bool bytes) {
|
||||
const char *str = qstr_str(qst);
|
||||
int len = strlen(str);
|
||||
bool has_single_quote = false;
|
||||
bool has_double_quote = false;
|
||||
@ -231,11 +231,11 @@ 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 qst, bool bytes) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_CONST ");
|
||||
print_quoted_str(qstr, bytes);
|
||||
print_quoted_str(qst, bytes);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
@ -245,43 +245,43 @@ STATIC void emit_cpy_load_null(emit_t *emit) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) {
|
||||
STATIC void emit_cpy_load_fast(emit_t *emit, qstr qst, mp_uint_t id_flags, mp_uint_t local_num) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_FAST %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("LOAD_FAST " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_cpy_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_DEREF %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("LOAD_DEREF " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_load_name(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_NAME %s\n", qstr_str(qstr));
|
||||
printf("LOAD_NAME %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_load_global(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_GLOBAL %s\n", qstr_str(qstr));
|
||||
printf("LOAD_GLOBAL %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_load_attr(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_ATTR %s\n", qstr_str(qstr));
|
||||
printf("LOAD_ATTR %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_method(emit_t *emit, qstr qstr) {
|
||||
emit_cpy_load_attr(emit, qstr);
|
||||
STATIC void emit_cpy_load_method(emit_t *emit, qstr qst) {
|
||||
emit_cpy_load_attr(emit, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_build_class(emit_t *emit) {
|
||||
@ -298,38 +298,38 @@ STATIC void emit_cpy_load_subscr(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_store_fast(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_cpy_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("STORE_FAST %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("STORE_FAST " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_cpy_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("STORE_DEREF %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("STORE_DEREF " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_store_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_store_name(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("STORE_NAME %s\n", qstr_str(qstr));
|
||||
printf("STORE_NAME %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_store_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_store_global(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("STORE_GLOBAL %s\n", qstr_str(qstr));
|
||||
printf("STORE_GLOBAL %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_store_attr(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, -2, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("STORE_ATTR %s\n", qstr_str(qstr));
|
||||
printf("STORE_ATTR %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,38 +340,38 @@ STATIC void emit_cpy_store_subscr(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("DELETE_FAST %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("DELETE_FAST " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_cpy_delete_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("DELETE_DEREF %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("DELETE_DEREF " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_delete_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_delete_name(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("DELETE_NAME %s\n", qstr_str(qstr));
|
||||
printf("DELETE_NAME %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_delete_global(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("DELETE_GLOBAL %s\n", qstr_str(qstr));
|
||||
printf("DELETE_GLOBAL %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_delete_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_cpy_delete_attr(emit_t *emit, qstr qst) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("DELETE_ATTR %s\n", qstr_str(qstr));
|
||||
printf("DELETE_ATTR %s\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,68 +417,68 @@ STATIC void emit_cpy_rot_three(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_jump(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_jump(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
int dest = emit->label_offsets[label];
|
||||
if (dest < emit->bytecode_offset) {
|
||||
printf("JUMP_ABSOLUTE %d\n", emit->label_offsets[label]);
|
||||
printf("JUMP_ABSOLUTE " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
} else {
|
||||
printf("JUMP_FORWARD %d\n", emit->label_offsets[label]);
|
||||
printf("JUMP_FORWARD " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("POP_JUMP_IF_TRUE %d\n", emit->label_offsets[label]);
|
||||
printf("POP_JUMP_IF_TRUE " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("POP_JUMP_IF_FALSE %d\n", emit->label_offsets[label]);
|
||||
printf("POP_JUMP_IF_FALSE " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("JUMP_IF_TRUE_OR_POP %d\n", emit->label_offsets[label]);
|
||||
printf("JUMP_IF_TRUE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("JUMP_IF_FALSE_OR_POP %d\n", emit->label_offsets[label]);
|
||||
printf("JUMP_IF_FALSE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_break_loop(emit_t *emit, uint label, int except_depth) {
|
||||
STATIC void emit_cpy_break_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
||||
emit_pre(emit, 0, 1);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("BREAK_LOOP\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_continue_loop(emit_t *emit, uint label, int except_depth) {
|
||||
STATIC void emit_cpy_continue_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
||||
if (except_depth == 0) {
|
||||
emit_cpy_jump(emit, label);
|
||||
} else {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("CONTINUE_LOOP %d\n", emit->label_offsets[label]);
|
||||
printf("CONTINUE_LOOP " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_setup_with(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_setup_with(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, 7, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("SETUP_WITH %d\n", emit->label_offsets[label]);
|
||||
printf("SETUP_WITH " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -489,17 +489,17 @@ STATIC void emit_cpy_with_cleanup(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_setup_except(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_setup_except(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("SETUP_EXCEPT %d\n", emit->label_offsets[label]);
|
||||
printf("SETUP_EXCEPT " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_setup_finally(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_setup_finally(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("SETUP_FINALLY %d\n", emit->label_offsets[label]);
|
||||
printf("SETUP_FINALLY " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,10 +517,10 @@ STATIC void emit_cpy_get_iter(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_for_iter(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_for_iter(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("FOR_ITER %d\n", emit->label_offsets[label]);
|
||||
printf("FOR_ITER " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -605,31 +605,31 @@ STATIC void emit_cpy_binary_op(emit_t *emit, mp_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, mp_uint_t n_args) {
|
||||
emit_pre(emit, 1 - n_args, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("BUILD_TUPLE %d\n", n_args);
|
||||
printf("BUILD_TUPLE " UINT_FMT "\n", n_args);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_build_list(emit_t *emit, int n_args) {
|
||||
STATIC void emit_cpy_build_list(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_pre(emit, 1 - n_args, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("BUILD_LIST %d\n", n_args);
|
||||
printf("BUILD_LIST " UINT_FMT "\n", n_args);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_list_append(emit_t *emit, int list_index) {
|
||||
STATIC void emit_cpy_list_append(emit_t *emit, mp_uint_t list_index) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LIST_APPEND %d\n", list_index);
|
||||
printf("LIST_APPEND " UINT_FMT "\n", list_index);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_build_map(emit_t *emit, int n_args) {
|
||||
STATIC void emit_cpy_build_map(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("BUILD_MAP %d\n", n_args);
|
||||
printf("BUILD_MAP " UINT_FMT "\n", n_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -640,57 +640,57 @@ STATIC void emit_cpy_store_map(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_map_add(emit_t *emit, int map_index) {
|
||||
STATIC void emit_cpy_map_add(emit_t *emit, mp_uint_t map_index) {
|
||||
emit_pre(emit, -2, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("MAP_ADD %d\n", map_index);
|
||||
printf("MAP_ADD " UINT_FMT "\n", map_index);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_build_set(emit_t *emit, int n_args) {
|
||||
STATIC void emit_cpy_build_set(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_pre(emit, 1 - n_args, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("BUILD_SET %d\n", n_args);
|
||||
printf("BUILD_SET " UINT_FMT "\n", n_args);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_set_add(emit_t *emit, int set_index) {
|
||||
STATIC void emit_cpy_set_add(emit_t *emit, mp_uint_t set_index) {
|
||||
emit_pre(emit, -1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("SET_ADD %d\n", set_index);
|
||||
printf("SET_ADD " UINT_FMT "\n", set_index);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_build_slice(emit_t *emit, int n_args) {
|
||||
STATIC void emit_cpy_build_slice(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_pre(emit, 1 - n_args, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("BUILD_SLICE %d\n", n_args);
|
||||
printf("BUILD_SLICE " UINT_FMT "\n", n_args);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_unpack_sequence(emit_t *emit, int n_args) {
|
||||
STATIC void emit_cpy_unpack_sequence(emit_t *emit, mp_uint_t n_args) {
|
||||
emit_pre(emit, -1 + n_args, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("UNPACK_SEQUENCE %d\n", n_args);
|
||||
printf("UNPACK_SEQUENCE " UINT_FMT "\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, mp_uint_t n_left, mp_uint_t n_right) {
|
||||
emit_pre(emit, -1 + n_left + n_right + 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("UNPACK_EX %d\n", n_left | (n_right << 8));
|
||||
printf("UNPACK_EX " UINT_FMT "\n", n_left | (n_right << 8));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
|
||||
int s = 0;
|
||||
STATIC void emit_cpy_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
mp_int_t s = 0;
|
||||
if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
|
||||
s += 1;
|
||||
}
|
||||
if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
|
||||
s += 1;
|
||||
}
|
||||
emit_pre(emit, -n_positional - 2 * n_keyword - s, 3);
|
||||
emit_pre(emit, -(mp_int_t)n_positional - 2 * (mp_int_t)n_keyword - s, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
|
||||
if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
|
||||
@ -705,11 +705,11 @@ STATIC void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword
|
||||
printf("CALL_FUNCTION");
|
||||
}
|
||||
}
|
||||
printf(" %d, %d\n", n_positional, n_keyword);
|
||||
printf(" " UINT_FMT ", " UINT_FMT "\n", n_positional, n_keyword);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
|
||||
STATIC void emit_cpy_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
emit_cpy_call_function(emit, n_positional, n_keyword, star_flags);
|
||||
}
|
||||
|
||||
@ -721,17 +721,17 @@ 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, mp_uint_t n_args) {
|
||||
emit_pre(emit, -n_args, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("RAISE_VARARGS %d\n", n_args);
|
||||
printf("RAISE_VARARGS " UINT_FMT "\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 qst) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_CONST code %s\n", qstr_str(qstr));
|
||||
printf("LOAD_CONST code %s\n", qstr_str(qst));
|
||||
}
|
||||
// load qualified name
|
||||
emit_pre(emit, 1, 3);
|
||||
@ -755,24 +755,24 @@ STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s'\n", qstr_str(qstr));
|
||||
printf("%s'\n", qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
|
||||
STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) {
|
||||
load_cpy_const_code_and_name(emit, scope->simple_name);
|
||||
emit_pre(emit, -1 - n_pos_defaults - 2 * n_kw_defaults, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("MAKE_FUNCTION %d\n", (n_kw_defaults << 8) | n_pos_defaults);
|
||||
printf("MAKE_FUNCTION " UINT_FMT "\n", (n_kw_defaults << 8) | n_pos_defaults);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults) {
|
||||
STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) {
|
||||
emit_cpy_build_tuple(emit, n_closed_over);
|
||||
load_cpy_const_code_and_name(emit, scope->simple_name);
|
||||
emit_pre(emit, -2 - n_pos_defaults - 2 * n_kw_defaults, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("MAKE_CLOSURE %d\n", (n_kw_defaults << 8) | n_pos_defaults);
|
||||
printf("MAKE_CLOSURE " UINT_FMT "\n", (n_kw_defaults << 8) | n_pos_defaults);
|
||||
}
|
||||
}
|
||||
|
||||
@ -807,17 +807,17 @@ STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_cpy_load_closure(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
emit_pre(emit, 1, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr));
|
||||
printf("LOAD_CLOSURE " UINT_FMT " %s\n", local_num, qstr_str(qst));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_cpy_setup_loop(emit_t *emit, uint label) {
|
||||
STATIC void emit_cpy_setup_loop(emit_t *emit, mp_uint_t label) {
|
||||
emit_pre(emit, 0, 3);
|
||||
if (emit->pass == MP_PASS_EMIT) {
|
||||
printf("SETUP_LOOP %d\n", emit->label_offsets[label]);
|
||||
printf("SETUP_LOOP " UINT_FMT "\n", emit->label_offsets[label]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ struct _emit_inline_asm_t {
|
||||
uint16_t pass;
|
||||
uint16_t success;
|
||||
scope_t *scope;
|
||||
uint max_num_labels;
|
||||
mp_uint_t max_num_labels;
|
||||
qstr *label_lookup;
|
||||
asm_thumb_t *as;
|
||||
};
|
||||
@ -70,7 +70,7 @@ void emit_inline_thumb_error(emit_inline_asm_t *emit, const char *fmt, ...) {
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
emit_inline_asm_t *emit_inline_thumb_new(uint max_num_labels) {
|
||||
emit_inline_asm_t *emit_inline_thumb_new(mp_uint_t max_num_labels) {
|
||||
emit_inline_asm_t *emit = m_new_obj(emit_inline_asm_t);
|
||||
emit->max_num_labels = max_num_labels;
|
||||
emit->label_lookup = m_new(qstr, max_num_labels);
|
||||
@ -105,12 +105,12 @@ STATIC bool emit_inline_thumb_end_pass(emit_inline_asm_t *emit) {
|
||||
return emit->success;
|
||||
}
|
||||
|
||||
STATIC int emit_inline_thumb_count_params(emit_inline_asm_t *emit, int n_params, mp_parse_node_t *pn_params) {
|
||||
STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) {
|
||||
if (n_params > 4) {
|
||||
emit_inline_thumb_error(emit, "can only have up to 4 parameters to inline thumb assembly\n");
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < n_params; i++) {
|
||||
for (mp_uint_t i = 0; i < n_params; i++) {
|
||||
if (!MP_PARSE_NODE_IS_ID(pn_params[i])) {
|
||||
emit_inline_thumb_error(emit, "parameter to inline assembler must be an identifier\n");
|
||||
return 0;
|
||||
@ -124,17 +124,17 @@ 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, uint label_num, qstr label_id) {
|
||||
STATIC void emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t 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 void emit_inline_thumb_align(emit_inline_asm_t *emit, uint align) {
|
||||
STATIC void emit_inline_thumb_align(emit_inline_asm_t *emit, mp_uint_t align) {
|
||||
asm_thumb_align(emit->as, align);
|
||||
}
|
||||
|
||||
STATIC void emit_inline_thumb_data(emit_inline_asm_t *emit, uint bytesize, uint val) {
|
||||
STATIC void emit_inline_thumb_data(emit_inline_asm_t *emit, mp_uint_t bytesize, mp_uint_t val) {
|
||||
asm_thumb_data(emit->as, bytesize, val);
|
||||
}
|
||||
|
||||
@ -163,11 +163,11 @@ STATIC const reg_name_t reg_name_table[] = {
|
||||
{15, "pc\0"},
|
||||
};
|
||||
|
||||
STATIC uint get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, uint max_reg) {
|
||||
STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_uint_t max_reg) {
|
||||
if (MP_PARSE_NODE_IS_ID(pn)) {
|
||||
qstr reg_qstr = MP_PARSE_NODE_LEAF_ARG(pn);
|
||||
const char *reg_str = qstr_str(reg_qstr);
|
||||
for (uint i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) {
|
||||
for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) {
|
||||
const reg_name_t *r = ®_name_table[i];
|
||||
if (reg_str[0] == r->name[0] && reg_str[1] == r->name[1] && reg_str[2] == r->name[2] && (reg_str[2] == '\0' || reg_str[3] == '\0')) {
|
||||
if (r->reg > max_reg) {
|
||||
@ -254,7 +254,7 @@ STATIC const cc_name_t cc_name_table[] = {
|
||||
{THUMB_CC_LE, "le"},
|
||||
};
|
||||
|
||||
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, mp_uint_t n_args, mp_parse_node_t *pn_args) {
|
||||
// TODO perhaps make two tables:
|
||||
// one_args =
|
||||
// "b", LAB, asm_thumb_b_n,
|
||||
@ -266,7 +266,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, m
|
||||
// "subs", RLO, RLO, I3, asm_thumb_subs_reg_reg_i3
|
||||
|
||||
const char *op_str = qstr_str(op);
|
||||
uint op_len = strlen(op_str);
|
||||
mp_uint_t op_len = strlen(op_str);
|
||||
|
||||
if (n_args == 0) {
|
||||
if (strcmp(op_str, "nop") == 0) {
|
||||
@ -285,8 +285,8 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, m
|
||||
// TODO check that this succeeded, ie branch was within range
|
||||
asm_thumb_b_n(emit->as, label_num);
|
||||
} else if (op_str[0] == 'b' && op_len == 3) {
|
||||
uint cc = -1;
|
||||
for (uint i = 0; i < MP_ARRAY_SIZE(cc_name_table); i++) {
|
||||
mp_uint_t cc = -1;
|
||||
for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(cc_name_table); i++) {
|
||||
if (op_str[1] == cc_name_table[i].name[0] && op_str[2] == cc_name_table[i].name[1]) {
|
||||
cc = cc_name_table[i].cc;
|
||||
}
|
||||
@ -310,14 +310,14 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, m
|
||||
} else if (n_args == 2) {
|
||||
if (MP_PARSE_NODE_IS_ID(pn_args[1])) {
|
||||
// second arg is a register (or should be)
|
||||
uint op_code;
|
||||
mp_uint_t op_code;
|
||||
if (strcmp(op_str, "mov") == 0) {
|
||||
uint reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
uint reg_src = get_arg_reg(emit, op_str, pn_args[1], 15);
|
||||
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
mp_uint_t reg_src = get_arg_reg(emit, op_str, pn_args[1], 15);
|
||||
asm_thumb_mov_reg_reg(emit->as, reg_dest, reg_src);
|
||||
} else if (strcmp(op_str, "and_") == 0) {
|
||||
op_code = ASM_THUMB_FORMAT_4_AND;
|
||||
uint reg_dest, reg_src;
|
||||
mp_uint_t reg_dest, reg_src;
|
||||
op_format_4:
|
||||
reg_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
|
||||
reg_src = get_arg_reg(emit, op_str, pn_args[1], 7);
|
||||
@ -343,10 +343,10 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, m
|
||||
}
|
||||
} else {
|
||||
// second arg is not a register
|
||||
uint op_code;
|
||||
mp_uint_t op_code;
|
||||
if (strcmp(op_str, "mov") == 0) {
|
||||
op_code = ASM_THUMB_FORMAT_3_MOV;
|
||||
uint rlo_dest, i8_src;
|
||||
mp_uint_t rlo_dest, i8_src;
|
||||
op_format_3:
|
||||
rlo_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
|
||||
i8_src = get_arg_i(emit, op_str, pn_args[1], 0xff);
|
||||
@ -361,23 +361,23 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, m
|
||||
op_code = ASM_THUMB_FORMAT_3_SUB;
|
||||
goto op_format_3;
|
||||
} else if (strcmp(op_str, "movw") == 0) {
|
||||
uint reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff);
|
||||
asm_thumb_movw_reg_i16(emit->as, reg_dest, i_src);
|
||||
} else if (strcmp(op_str, "movt") == 0) {
|
||||
uint reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff);
|
||||
asm_thumb_movt_reg_i16(emit->as, reg_dest, i_src);
|
||||
} else if (strcmp(op_str, "movwt") == 0) {
|
||||
// this is a convenience instruction
|
||||
// we clear the MSB since it might be set from extracting the small int value
|
||||
uint reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
|
||||
int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffffffff);
|
||||
asm_thumb_movw_reg_i16(emit->as, reg_dest, i_src & 0xffff);
|
||||
asm_thumb_movt_reg_i16(emit->as, reg_dest, (i_src >> 16) & 0x7fff);
|
||||
} else if (strcmp(op_str, "ldr") == 0) {
|
||||
op_code = ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER;
|
||||
uint rlo_dest, rlo_base, i5;
|
||||
mp_uint_t rlo_dest, rlo_base, i5;
|
||||
mp_parse_node_t pn_base, pn_offset;
|
||||
op_format_9_10:
|
||||
rlo_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
|
||||
@ -413,10 +413,10 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, int n_args, m
|
||||
}
|
||||
|
||||
} else if (n_args == 3) {
|
||||
uint op_code;
|
||||
mp_uint_t op_code;
|
||||
if (strcmp(op_str, "add") == 0) {
|
||||
op_code = ASM_THUMB_FORMAT_2_ADD;
|
||||
uint rlo_dest, rlo_src;
|
||||
mp_uint_t rlo_dest, rlo_src;
|
||||
op_format_2:
|
||||
rlo_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
|
||||
rlo_src = get_arg_reg(emit, op_str, pn_args[1], 7);
|
||||
|
134
py/emitnative.c
134
py/emitnative.c
@ -432,10 +432,10 @@ struct _emit_t {
|
||||
|
||||
vtype_kind_t return_vtype;
|
||||
|
||||
uint local_vtype_alloc;
|
||||
mp_uint_t local_vtype_alloc;
|
||||
vtype_kind_t *local_vtype;
|
||||
|
||||
uint stack_info_alloc;
|
||||
mp_uint_t stack_info_alloc;
|
||||
stack_info_t *stack_info;
|
||||
|
||||
int stack_start;
|
||||
@ -448,7 +448,7 @@ struct _emit_t {
|
||||
ASM_T *as;
|
||||
};
|
||||
|
||||
emit_t *EXPORT_FUN(new)(uint max_num_labels) {
|
||||
emit_t *EXPORT_FUN(new)(mp_uint_t max_num_labels) {
|
||||
emit_t *emit = m_new0(emit_t, 1);
|
||||
emit->as = ASM_NEW(max_num_labels);
|
||||
return emit;
|
||||
@ -636,11 +636,11 @@ STATIC bool emit_native_last_emit_was_return_value(emit_t *emit) {
|
||||
return emit->last_emit_was_return_value;
|
||||
}
|
||||
|
||||
STATIC void emit_native_adjust_stack_size(emit_t *emit, int delta) {
|
||||
STATIC void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) {
|
||||
emit->stack_size += delta;
|
||||
}
|
||||
|
||||
STATIC void emit_native_set_source_line(emit_t *emit, int source_line) {
|
||||
STATIC void emit_native_set_source_line(emit_t *emit, mp_uint_t source_line) {
|
||||
}
|
||||
|
||||
STATIC void adjust_stack(emit_t *emit, int stack_size_delta) {
|
||||
@ -916,19 +916,19 @@ STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_d
|
||||
adjust_stack(emit, n_push);
|
||||
}
|
||||
|
||||
STATIC void emit_native_load_id(emit_t *emit, qstr qstr) {
|
||||
emit_common_load_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
|
||||
STATIC void emit_native_load_id(emit_t *emit, qstr qst) {
|
||||
emit_common_load_id(emit, &EXPORT_FUN(method_table), emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_native_store_id(emit_t *emit, qstr qstr) {
|
||||
emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
|
||||
STATIC void emit_native_store_id(emit_t *emit, qstr qst) {
|
||||
emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_native_delete_id(emit_t *emit, qstr qstr) {
|
||||
emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
|
||||
STATIC void emit_native_delete_id(emit_t *emit, qstr qst) {
|
||||
emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_native_label_assign(emit_t *emit, uint l) {
|
||||
STATIC void emit_native_label_assign(emit_t *emit, mp_uint_t l) {
|
||||
emit_native_pre(emit);
|
||||
// need to commit stack because we can jump here from elsewhere
|
||||
need_stack_settled(emit);
|
||||
@ -1008,25 +1008,25 @@ STATIC void emit_native_load_const_int(emit_t *emit, qstr qst) {
|
||||
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
|
||||
}
|
||||
|
||||
STATIC void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_native_load_const_dec(emit_t *emit, qstr qst) {
|
||||
// for viper, a float/complex is just a Python object
|
||||
emit_native_pre(emit);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_DEC, qstr, REG_ARG_1);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_DEC, qst, REG_ARG_1);
|
||||
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
|
||||
}
|
||||
|
||||
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 qst, bool bytes) {
|
||||
emit_native_pre(emit);
|
||||
if (emit->do_viper_types) {
|
||||
// not implemented properly
|
||||
// load a pointer to the asciiz string?
|
||||
assert(0);
|
||||
emit_post_push_imm(emit, VTYPE_PTR, (mp_uint_t)qstr_str(qstr));
|
||||
emit_post_push_imm(emit, VTYPE_PTR, (mp_uint_t)qstr_str(qst));
|
||||
} else {
|
||||
if (bytes) {
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_BYTES, qstr, REG_ARG_1);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_BYTES, qst, REG_ARG_1);
|
||||
} else {
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_STR, qstr, REG_ARG_1);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_STR, qst, REG_ARG_1);
|
||||
}
|
||||
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
|
||||
}
|
||||
@ -1037,10 +1037,10 @@ STATIC void emit_native_load_null(emit_t *emit) {
|
||||
emit_post_push_imm(emit, VTYPE_PYOBJ, 0);
|
||||
}
|
||||
|
||||
STATIC void emit_native_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) {
|
||||
STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t id_flags, mp_uint_t 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));
|
||||
printf("ViperTypeError: local %s used before type known\n", qstr_str(qst));
|
||||
}
|
||||
emit_native_pre(emit);
|
||||
#if N_X64
|
||||
@ -1096,25 +1096,25 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qstr, uint id_flags, int lo
|
||||
#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 qst, mp_uint_t 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_name(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_native_load_name(emit_t *emit, qstr qst) {
|
||||
emit_native_pre(emit);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_NAME, qstr, REG_ARG_1);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_NAME, qst, 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 qst) {
|
||||
emit_native_pre(emit);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_GLOBAL, qstr, REG_ARG_1);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_GLOBAL, qst, 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 qst) {
|
||||
// depends on type of subject:
|
||||
// - integer, function, pointer to integers: error
|
||||
// - pointer to structure: get member, quite easy
|
||||
@ -1122,16 +1122,16 @@ STATIC void emit_native_load_attr(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);
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_ATTR, qstr, REG_ARG_2); // arg2 = attribute name
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_ATTR, qst, REG_ARG_2); // arg2 = attribute name
|
||||
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 qst) {
|
||||
vtype_kind_t vtype_base;
|
||||
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
|
||||
assert(vtype_base == VTYPE_PYOBJ);
|
||||
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_METHOD, qstr, REG_ARG_2); // arg2 = method name
|
||||
emit_call_with_imm_arg(emit, MP_F_LOAD_METHOD, qst, REG_ARG_2); // arg2 = method name
|
||||
}
|
||||
|
||||
STATIC void emit_native_load_build_class(emit_t *emit) {
|
||||
@ -1151,7 +1151,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
vtype_kind_t vtype;
|
||||
#if N_X64
|
||||
if (local_num == 0) {
|
||||
@ -1209,25 +1209,25 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
|
||||
emit->local_vtype[local_num] = vtype;
|
||||
} else if (emit->local_vtype[local_num] != vtype) {
|
||||
// type of local is not the same as object stored in it
|
||||
printf("ViperTypeError: type mismatch, local %s has type %d but source object has type %d\n", qstr_str(qstr), emit->local_vtype[local_num], vtype);
|
||||
printf("ViperTypeError: type mismatch, local %s has type %d but source object has type %d\n", qstr_str(qst), emit->local_vtype[local_num], vtype);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
|
||||
STATIC void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t 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 qst) {
|
||||
// mp_store_name, but needs conversion of object (maybe have mp_viper_store_name(obj, type))
|
||||
vtype_kind_t vtype;
|
||||
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
|
||||
assert(vtype == VTYPE_PYOBJ);
|
||||
emit_call_with_imm_arg(emit, MP_F_STORE_NAME, qstr, REG_ARG_1); // arg1 = name
|
||||
emit_call_with_imm_arg(emit, MP_F_STORE_NAME, qst, REG_ARG_1); // arg1 = name
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_store_global(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_native_store_global(emit_t *emit, qstr qst) {
|
||||
vtype_kind_t vtype = peek_vtype(emit);
|
||||
if (vtype == VTYPE_PYOBJ) {
|
||||
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
|
||||
@ -1236,16 +1236,16 @@ STATIC void emit_native_store_global(emit_t *emit, qstr qstr) {
|
||||
emit_call_with_imm_arg(emit, MP_F_CONVERT_NATIVE_TO_OBJ, vtype, REG_ARG_2); // arg2 = type
|
||||
ASM_MOV_REG_TO_REG(emit->as, REG_RET, REG_ARG_2);
|
||||
}
|
||||
emit_call_with_imm_arg(emit, MP_F_STORE_GLOBAL, qstr, REG_ARG_1); // arg1 = name
|
||||
emit_call_with_imm_arg(emit, MP_F_STORE_GLOBAL, qst, REG_ARG_1); // arg1 = name
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_store_attr(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_native_store_attr(emit_t *emit, qstr qst) {
|
||||
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);
|
||||
assert(vtype_val == VTYPE_PYOBJ);
|
||||
emit_call_with_imm_arg(emit, MP_F_STORE_ATTR, qstr, REG_ARG_2); // arg2 = attribute name
|
||||
emit_call_with_imm_arg(emit, MP_F_STORE_ATTR, qst, REG_ARG_2); // arg2 = attribute name
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
@ -1262,12 +1262,12 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
|
||||
emit_call(emit, MP_F_OBJ_SUBSCR);
|
||||
}
|
||||
|
||||
STATIC void emit_native_delete_fast(emit_t *emit, qstr qst, int local_num) {
|
||||
STATIC void emit_native_delete_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
// TODO implement me!
|
||||
// could support for Python types, just set to None (so GC can reclaim it)
|
||||
}
|
||||
|
||||
STATIC void emit_native_delete_deref(emit_t *emit, qstr qst, int local_num) {
|
||||
STATIC void emit_native_delete_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
// TODO implement me!
|
||||
}
|
||||
|
||||
@ -1328,7 +1328,7 @@ STATIC void emit_native_rot_three(emit_t *emit) {
|
||||
emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1);
|
||||
}
|
||||
|
||||
STATIC void emit_native_jump(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_pre(emit);
|
||||
// need to commit stack because we are jumping elsewhere
|
||||
need_stack_settled(emit);
|
||||
@ -1336,7 +1336,7 @@ STATIC void emit_native_jump(emit_t *emit, uint label) {
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_jump_helper(emit_t *emit, uint label, bool pop) {
|
||||
STATIC void emit_native_jump_helper(emit_t *emit, mp_uint_t label, bool pop) {
|
||||
vtype_kind_t vtype = peek_vtype(emit);
|
||||
if (vtype == VTYPE_BOOL) {
|
||||
emit_pre_pop_reg(emit, &vtype, REG_RET);
|
||||
@ -1357,41 +1357,41 @@ STATIC void emit_native_jump_helper(emit_t *emit, uint label, bool pop) {
|
||||
need_stack_settled(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_pop_jump_if_true(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_pop_jump_if_true(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_jump_helper(emit, label, true);
|
||||
ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_pop_jump_if_false(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_pop_jump_if_false(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_jump_helper(emit, label, true);
|
||||
ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_jump_helper(emit, label, false);
|
||||
ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
|
||||
adjust_stack(emit, -1);
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_jump_helper(emit, label, false);
|
||||
ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
|
||||
adjust_stack(emit, -1);
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_break_loop(emit_t *emit, uint label, int except_depth) {
|
||||
STATIC void emit_native_break_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
||||
emit_native_jump(emit, label & ~MP_EMIT_BREAK_FROM_FOR); // TODO properly
|
||||
}
|
||||
|
||||
STATIC void emit_native_continue_loop(emit_t *emit, uint label, int except_depth) {
|
||||
STATIC void emit_native_continue_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
||||
emit_native_jump(emit, label); // TODO properly
|
||||
}
|
||||
|
||||
STATIC void emit_native_setup_with(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
|
||||
// not supported, or could be with runtime call
|
||||
assert(0);
|
||||
}
|
||||
@ -1400,7 +1400,7 @@ STATIC void emit_native_with_cleanup(emit_t *emit) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
STATIC void emit_native_setup_except(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_setup_except(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_pre(emit);
|
||||
// need to commit stack because we may jump elsewhere
|
||||
need_stack_settled(emit);
|
||||
@ -1410,7 +1410,7 @@ STATIC void emit_native_setup_except(emit_t *emit, uint label) {
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_setup_finally(emit_t *emit, uint label) {
|
||||
STATIC void emit_native_setup_finally(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_setup_except(emit, label);
|
||||
}
|
||||
|
||||
@ -1430,7 +1430,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, uint label) {
|
||||
STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_pre(emit);
|
||||
vtype_kind_t vtype;
|
||||
emit_access_stack(emit, 1, &vtype, REG_ARG_1);
|
||||
@ -1527,7 +1527,7 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_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, mp_uint_t n_args) {
|
||||
// for viper: call runtime, with types of args
|
||||
// if wrapped in byte_array, or something, allocates memory and fills it
|
||||
emit_native_pre(emit);
|
||||
@ -1536,14 +1536,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, mp_uint_t n_args) {
|
||||
emit_native_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, MP_F_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, mp_uint_t list_index) {
|
||||
// only used in list comprehension
|
||||
vtype_kind_t vtype_list, vtype_item;
|
||||
emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
|
||||
@ -1554,7 +1554,7 @@ 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, mp_uint_t n_args) {
|
||||
emit_native_pre(emit);
|
||||
emit_call_with_imm_arg(emit, MP_F_BUILD_MAP, n_args, REG_ARG_1);
|
||||
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
|
||||
@ -1570,7 +1570,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, mp_uint_t 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);
|
||||
@ -1582,14 +1582,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, mp_uint_t n_args) {
|
||||
emit_native_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, MP_F_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, mp_uint_t set_index) {
|
||||
// only used in set comprehension
|
||||
vtype_kind_t vtype_set, vtype_item;
|
||||
emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
|
||||
@ -1600,7 +1600,7 @@ 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, mp_uint_t n_args) {
|
||||
DEBUG_printf("build_slice %d\n", n_args);
|
||||
if (n_args == 2) {
|
||||
vtype_kind_t vtype_start, vtype_stop;
|
||||
@ -1621,7 +1621,7 @@ STATIC void emit_native_build_slice(emit_t *emit, int n_args) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_native_unpack_sequence(emit_t *emit, int n_args) {
|
||||
STATIC void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) {
|
||||
DEBUG_printf("unpack_sequence %d\n", n_args);
|
||||
vtype_kind_t vtype_base;
|
||||
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = seq
|
||||
@ -1630,7 +1630,7 @@ STATIC void emit_native_unpack_sequence(emit_t *emit, int n_args) {
|
||||
emit_call_with_imm_arg(emit, MP_F_UNPACK_SEQUENCE, n_args, REG_ARG_2); // arg2 = n_args
|
||||
}
|
||||
|
||||
STATIC void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
|
||||
STATIC void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right) {
|
||||
DEBUG_printf("unpack_ex %d %d\n", n_left, n_right);
|
||||
vtype_kind_t vtype_base;
|
||||
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = seq
|
||||
@ -1639,7 +1639,7 @@ STATIC void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
|
||||
emit_call_with_imm_arg(emit, MP_F_UNPACK_EX, n_left | (n_right << 8), REG_ARG_2); // arg2 = n_left + n_right
|
||||
}
|
||||
|
||||
STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
|
||||
STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) {
|
||||
// call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
|
||||
emit_native_pre(emit);
|
||||
if (n_pos_defaults == 0 && n_kw_defaults == 0) {
|
||||
@ -1654,11 +1654,11 @@ STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, uint n_pos_d
|
||||
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
|
||||
}
|
||||
|
||||
STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults) {
|
||||
STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
STATIC void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
|
||||
STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
// call special viper runtime routine with type info for args, and wanted type info for return
|
||||
assert(!star_flags);
|
||||
|
||||
@ -1697,7 +1697,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, uint star_flags) {
|
||||
STATIC void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
|
||||
assert(!star_flags);
|
||||
|
||||
/*
|
||||
@ -1743,7 +1743,7 @@ STATIC void emit_native_return_value(emit_t *emit) {
|
||||
ASM_EXIT(emit->as);
|
||||
}
|
||||
|
||||
STATIC void emit_native_raise_varargs(emit_t *emit, int n_args) {
|
||||
STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) {
|
||||
assert(n_args == 1);
|
||||
vtype_kind_t vtype_exc;
|
||||
emit_pre_pop_reg(emit, &vtype_exc, REG_ARG_1); // arg1 = object to raise
|
||||
|
@ -67,13 +67,13 @@ STATIC bool emit_pass1_last_emit_was_return_value(emit_t *emit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
STATIC void emit_pass1_load_id(emit_t *emit, qstr qstr) {
|
||||
STATIC void emit_pass1_load_id(emit_t *emit, qstr qst) {
|
||||
// name adding/lookup
|
||||
bool added;
|
||||
id_info_t *id = scope_find_or_add_id(emit->scope, qstr, &added);
|
||||
id_info_t *id = scope_find_or_add_id(emit->scope, qst, &added);
|
||||
if (added) {
|
||||
#if MICROPY_EMIT_CPYTHON
|
||||
if (qstr == MP_QSTR_super && emit->scope->kind == SCOPE_FUNCTION) {
|
||||
if (qst == MP_QSTR_super && emit->scope->kind == SCOPE_FUNCTION) {
|
||||
// special case, super is a global, and also counts as use of __class__
|
||||
id->kind = ID_INFO_KIND_GLOBAL_EXPLICIT;
|
||||
id_info_t *id2 = scope_find_local_in_parent(emit->scope, MP_QSTR___class__);
|
||||
@ -87,10 +87,10 @@ STATIC void emit_pass1_load_id(emit_t *emit, qstr qstr) {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
id_info_t *id2 = scope_find_local_in_parent(emit->scope, qstr);
|
||||
id_info_t *id2 = scope_find_local_in_parent(emit->scope, qst);
|
||||
if (id2 != NULL && (id2->kind == ID_INFO_KIND_LOCAL || id2->kind == ID_INFO_KIND_CELL || id2->kind == ID_INFO_KIND_FREE)) {
|
||||
id->kind = ID_INFO_KIND_FREE;
|
||||
scope_close_over_in_parents(emit->scope, qstr);
|
||||
scope_close_over_in_parents(emit->scope, qst);
|
||||
} else {
|
||||
id->kind = ID_INFO_KIND_GLOBAL_IMPLICIT;
|
||||
}
|
||||
@ -98,10 +98,10 @@ 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 qst) {
|
||||
// name adding/lookup
|
||||
bool added;
|
||||
id_info_t *id = scope_find_or_add_id(scope, qstr, &added);
|
||||
id_info_t *id = scope_find_or_add_id(scope, qst, &added);
|
||||
if (added) {
|
||||
if (scope->kind == SCOPE_MODULE || scope->kind == SCOPE_CLASS) {
|
||||
id->kind = ID_INFO_KIND_GLOBAL_IMPLICIT;
|
||||
@ -118,12 +118,12 @@ 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) {
|
||||
get_id_for_modification(emit->scope, qstr);
|
||||
STATIC void emit_pass1_store_id(emit_t *emit, qstr qst) {
|
||||
get_id_for_modification(emit->scope, qst);
|
||||
}
|
||||
|
||||
STATIC void emit_pass1_delete_id(emit_t *emit, qstr qstr) {
|
||||
id_info_t *id = get_id_for_modification(emit->scope, qstr);
|
||||
STATIC void emit_pass1_delete_id(emit_t *emit, qstr qst) {
|
||||
id_info_t *id = get_id_for_modification(emit->scope, qst);
|
||||
// this flag is unused
|
||||
//id->flags |= ID_FLAG_IS_DELETED;
|
||||
(void)id; // suppress compiler warning
|
||||
|
46
py/scope.c
46
py/scope.c
@ -82,8 +82,8 @@ void scope_free(scope_t *scope) {
|
||||
m_del(scope_t, scope, 1);
|
||||
}
|
||||
|
||||
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) {
|
||||
id_info_t *id_info = scope_find(scope, qstr);
|
||||
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qst, bool *added) {
|
||||
id_info_t *id_info = scope_find(scope, qst);
|
||||
if (id_info != NULL) {
|
||||
*added = false;
|
||||
return id_info;
|
||||
@ -103,33 +103,33 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) {
|
||||
id_info->kind = 0;
|
||||
id_info->flags = 0;
|
||||
id_info->local_num = 0;
|
||||
id_info->qstr = qstr;
|
||||
id_info->qst = qst;
|
||||
*added = true;
|
||||
return id_info;
|
||||
}
|
||||
|
||||
id_info_t *scope_find(scope_t *scope, qstr qstr) {
|
||||
id_info_t *scope_find(scope_t *scope, qstr qst) {
|
||||
for (mp_uint_t i = 0; i < scope->id_info_len; i++) {
|
||||
if (scope->id_info[i].qstr == qstr) {
|
||||
if (scope->id_info[i].qst == qst) {
|
||||
return &scope->id_info[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
id_info_t *scope_find_global(scope_t *scope, qstr qstr) {
|
||||
id_info_t *scope_find_global(scope_t *scope, qstr qst) {
|
||||
while (scope->parent != NULL) {
|
||||
scope = scope->parent;
|
||||
}
|
||||
return scope_find(scope, qstr);
|
||||
return scope_find(scope, qst);
|
||||
}
|
||||
|
||||
id_info_t *scope_find_local_in_parent(scope_t *scope, qstr qstr) {
|
||||
id_info_t *scope_find_local_in_parent(scope_t *scope, qstr qst) {
|
||||
if (scope->parent == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for (scope_t *s = scope->parent; s->parent != NULL; s = s->parent) {
|
||||
id_info_t *id = scope_find(s, qstr);
|
||||
id_info_t *id = scope_find(s, qst);
|
||||
if (id != NULL) {
|
||||
return id;
|
||||
}
|
||||
@ -137,11 +137,11 @@ id_info_t *scope_find_local_in_parent(scope_t *scope, qstr qstr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void scope_close_over_in_parents(scope_t *scope, qstr qstr) {
|
||||
void scope_close_over_in_parents(scope_t *scope, qstr qst) {
|
||||
assert(scope->parent != NULL); // we should have at least 1 parent
|
||||
for (scope_t *s = scope->parent; s->parent != NULL; s = s->parent) {
|
||||
bool added;
|
||||
id_info_t *id = scope_find_or_add_id(s, qstr, &added);
|
||||
id_info_t *id = scope_find_or_add_id(s, qst, &added);
|
||||
if (added) {
|
||||
// variable not previously declared in this scope, so declare it as free and keep searching parents
|
||||
id->kind = ID_INFO_KIND_FREE;
|
||||
@ -159,13 +159,13 @@ void scope_close_over_in_parents(scope_t *scope, qstr qstr) {
|
||||
assert(0); // we should have found the variable in one of the parents
|
||||
}
|
||||
|
||||
void scope_declare_global(scope_t *scope, qstr qstr) {
|
||||
void scope_declare_global(scope_t *scope, qstr qst) {
|
||||
if (scope->kind == SCOPE_MODULE) {
|
||||
printf("SyntaxError?: can't declare global in outer code\n");
|
||||
return;
|
||||
}
|
||||
bool added;
|
||||
id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added);
|
||||
id_info_t *id_info = scope_find_or_add_id(scope, qst, &added);
|
||||
if (!added) {
|
||||
printf("SyntaxError?: identifier already declared something\n");
|
||||
return;
|
||||
@ -173,30 +173,30 @@ void scope_declare_global(scope_t *scope, qstr qstr) {
|
||||
id_info->kind = ID_INFO_KIND_GLOBAL_EXPLICIT;
|
||||
|
||||
// if the id exists in the global scope, set its kind to EXPLICIT_GLOBAL
|
||||
id_info = scope_find_global(scope, qstr);
|
||||
id_info = scope_find_global(scope, qst);
|
||||
if (id_info != NULL) {
|
||||
id_info->kind = ID_INFO_KIND_GLOBAL_EXPLICIT;
|
||||
}
|
||||
}
|
||||
|
||||
void scope_declare_nonlocal(scope_t *scope, qstr qstr) {
|
||||
void scope_declare_nonlocal(scope_t *scope, qstr qst) {
|
||||
if (scope->kind == SCOPE_MODULE) {
|
||||
printf("SyntaxError?: can't declare nonlocal in outer code\n");
|
||||
return;
|
||||
}
|
||||
bool added;
|
||||
id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added);
|
||||
id_info_t *id_info = scope_find_or_add_id(scope, qst, &added);
|
||||
if (!added) {
|
||||
printf("SyntaxError?: identifier already declared something\n");
|
||||
return;
|
||||
}
|
||||
id_info_t *id_info2 = scope_find_local_in_parent(scope, qstr);
|
||||
id_info_t *id_info2 = scope_find_local_in_parent(scope, qst);
|
||||
if (id_info2 == NULL || !(id_info2->kind == ID_INFO_KIND_LOCAL || id_info2->kind == ID_INFO_KIND_CELL || id_info2->kind == ID_INFO_KIND_FREE)) {
|
||||
printf("SyntaxError: no binding for nonlocal '%s' found\n", qstr_str(qstr));
|
||||
printf("SyntaxError: no binding for nonlocal '%s' found\n", qstr_str(qst));
|
||||
return;
|
||||
}
|
||||
id_info->kind = ID_INFO_KIND_FREE;
|
||||
scope_close_over_in_parents(scope, qstr);
|
||||
scope_close_over_in_parents(scope, qst);
|
||||
}
|
||||
|
||||
#if MICROPY_EMIT_CPYTHON
|
||||
@ -220,28 +220,28 @@ void scope_print_info(scope_t *s) {
|
||||
printf("var global:");
|
||||
for (int i = 0; i < s->id_info_len; i++) {
|
||||
if (s->id_info[i].kind == ID_INFO_KIND_GLOBAL_EXPLICIT) {
|
||||
printf(" %s", qstr_str(s->id_info[i].qstr));
|
||||
printf(" %s", qstr_str(s->id_info[i].qst));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf("var name:");
|
||||
for (int i = 0; i < s->id_info_len; i++) {
|
||||
if (s->id_info[i].kind == ID_INFO_KIND_GLOBAL_IMPLICIT) {
|
||||
printf(" %s", qstr_str(s->id_info[i].qstr));
|
||||
printf(" %s", qstr_str(s->id_info[i].qst));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf("var local:");
|
||||
for (int i = 0; i < s->id_info_len; i++) {
|
||||
if (s->id_info[i].kind == ID_INFO_KIND_LOCAL) {
|
||||
printf(" %s", qstr_str(s->id_info[i].qstr));
|
||||
printf(" %s", qstr_str(s->id_info[i].qst));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf("var free:");
|
||||
for (int i = 0; i < s->id_info_len; i++) {
|
||||
if (s->id_info[i].kind == ID_INFO_KIND_FREE) {
|
||||
printf(" %s", qstr_str(s->id_info[i].qstr));
|
||||
printf(" %s", qstr_str(s->id_info[i].qst));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
@ -44,7 +44,7 @@ typedef struct _id_info_t {
|
||||
// when it's an ID_INFO_KIND_LOCAL this is the unique number of the local
|
||||
// whet it's an ID_INFO_KIND_CELL/FREE this is the unique number of the closed over variable
|
||||
uint16_t local_num;
|
||||
qstr qstr;
|
||||
qstr qst;
|
||||
} id_info_t;
|
||||
|
||||
// scope is a "block" in Python parlance
|
||||
|
Loading…
Reference in New Issue
Block a user