@ -62,9 +62,6 @@ struct _emit_t {
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 ( void ) {
emit_t * emit = m_new0 ( emit_t , 1 ) ;
return emit ;
@ -270,14 +267,16 @@ STATIC void emit_write_bytecode_byte_signed_label(emit_t* emit, byte b1, mp_uint
c [ 2 ] = bytecode_offset > > 8 ;
}
STATIC void emit_bc_set_native_type ( emit_t * emit , mp_uint_t op , mp_uint_t arg1 , qstr arg2 ) {
# if MICROPY_EMIT_NATIVE
STATIC void mp_emit_bc_set_native_type ( emit_t * emit , mp_uint_t op , mp_uint_t arg1 , qstr arg2 ) {
( void ) emit ;
( void ) op ;
( void ) arg1 ;
( void ) arg2 ;
}
# endif
STATIC void emit_bc_start_pass ( emit_t * emit , pass_kind_t pass , scope_t * scope ) {
void mp_ emit_bc_start_pass( emit_t * emit , pass_kind_t pass , scope_t * scope ) {
emit - > pass = pass ;
emit - > stack_size = 0 ;
emit - > last_emit_was_return_value = false ;
@ -340,7 +339,7 @@ STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
}
}
STATIC void emit_bc_end_pass ( emit_t * emit ) {
void mp_ emit_bc_end_pass( emit_t * emit ) {
if ( emit - > pass = = MP_PASS_SCOPE ) {
return ;
}
@ -384,15 +383,15 @@ STATIC void emit_bc_end_pass(emit_t *emit) {
}
}
STATIC bool emit_bc_last_emit_was_return_value ( emit_t * emit ) {
bool mp_ 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 , mp_int_t delta ) {
void mp_ 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 , mp_uint_t source_line ) {
void mp_ 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_STATE_VM ( mp_optimise_value ) > = 3 ) {
@ -421,7 +420,7 @@ STATIC void emit_bc_pre(emit_t *emit, mp_int_t stack_size_delta) {
emit - > last_emit_was_return_value = false ;
}
STATIC void emit_bc_label_assign ( emit_t * emit , mp_uint_t l ) {
void mp_ emit_bc_label_assign( emit_t * emit , mp_uint_t l ) {
emit_bc_pre ( emit , 0 ) ;
if ( emit - > pass = = MP_PASS_SCOPE ) {
return ;
@ -438,22 +437,22 @@ STATIC void emit_bc_label_assign(emit_t *emit, mp_uint_t l) {
}
}
STATIC void emit_bc_import_name ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_import_name( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_IMPORT_NAME , qst ) ;
}
STATIC void emit_bc_import_from ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_import_from( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_IMPORT_FROM , qst ) ;
}
STATIC void emit_bc_import_star ( emit_t * emit ) {
void mp_ emit_bc_import_star( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_IMPORT_STAR ) ;
}
STATIC void emit_bc_load_const_tok ( emit_t * emit , mp_token_kind_t tok ) {
void mp_ emit_bc_load_const_tok( emit_t * emit , mp_token_kind_t tok ) {
emit_bc_pre ( emit , 1 ) ;
switch ( tok ) {
case MP_TOKEN_KW_FALSE : emit_write_bytecode_byte ( emit , MP_BC_LOAD_CONST_FALSE ) ; break ;
@ -465,7 +464,7 @@ STATIC void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
}
}
STATIC void emit_bc_load_const_small_int ( emit_t * emit , mp_int_t arg ) {
void mp_ emit_bc_load_const_small_int( emit_t * emit , mp_int_t arg ) {
emit_bc_pre ( emit , 1 ) ;
if ( - 16 < = arg & & arg < = 47 ) {
emit_write_bytecode_byte ( emit , MP_BC_LOAD_CONST_SMALL_INT_MULTI + 16 + arg ) ;
@ -474,7 +473,7 @@ STATIC void emit_bc_load_const_small_int(emit_t *emit, mp_int_t arg) {
}
}
STATIC void emit_bc_load_const_str ( emit_t * emit , qstr qst , bool bytes ) {
void mp_ 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 , qst ) ;
@ -483,17 +482,17 @@ STATIC void emit_bc_load_const_str(emit_t *emit, qstr qst, bool bytes) {
}
}
STATIC void emit_bc_load_const_obj ( emit_t * emit , void * obj ) {
void mp_ emit_bc_load_const_obj( emit_t * emit , void * obj ) {
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte_ptr ( emit , MP_BC_LOAD_CONST_OBJ , obj ) ;
}
STATIC void emit_bc_load_null ( emit_t * emit ) {
void mp_ emit_bc_load_null( emit_t * emit ) {
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_LOAD_NULL ) ;
} ;
STATIC void emit_bc_load_fast ( emit_t * emit , qstr qst , mp_uint_t local_num ) {
void mp_ emit_bc_load_fast( emit_t * emit , qstr qst , mp_uint_t local_num ) {
( void ) qst ;
assert ( local_num > = 0 ) ;
emit_bc_pre ( emit , 1 ) ;
@ -504,13 +503,13 @@ STATIC void emit_bc_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
}
}
STATIC void emit_bc_load_deref ( emit_t * emit , qstr qst , mp_uint_t local_num ) {
void mp_ emit_bc_load_deref( emit_t * emit , qstr qst , mp_uint_t local_num ) {
( void ) qst ;
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 qst ) {
void mp_ emit_bc_load_name( emit_t * emit , qstr qst ) {
( void ) qst ;
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_LOAD_NAME , qst ) ;
@ -519,7 +518,7 @@ STATIC void emit_bc_load_name(emit_t *emit, qstr qst) {
}
}
STATIC void emit_bc_load_global ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_load_global( emit_t * emit , qstr qst ) {
( void ) qst ;
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_LOAD_GLOBAL , qst ) ;
@ -528,7 +527,7 @@ STATIC void emit_bc_load_global(emit_t *emit, qstr qst) {
}
}
STATIC void emit_bc_load_attr ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_load_attr( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_LOAD_ATTR , qst ) ;
if ( MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE ) {
@ -536,22 +535,22 @@ STATIC void emit_bc_load_attr(emit_t *emit, qstr qst) {
}
}
STATIC void emit_bc_load_method ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_load_method( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_LOAD_METHOD , qst ) ;
}
STATIC void emit_bc_load_build_class ( emit_t * emit ) {
void mp_ emit_bc_load_build_class( emit_t * emit ) {
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_LOAD_BUILD_CLASS ) ;
}
STATIC void emit_bc_load_subscr ( emit_t * emit ) {
void mp_ emit_bc_load_subscr( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_LOAD_SUBSCR ) ;
}
STATIC void emit_bc_store_fast ( emit_t * emit , qstr qst , mp_uint_t local_num ) {
void mp_ emit_bc_store_fast( emit_t * emit , qstr qst , mp_uint_t local_num ) {
( void ) qst ;
assert ( local_num > = 0 ) ;
emit_bc_pre ( emit , - 1 ) ;
@ -562,23 +561,23 @@ STATIC void emit_bc_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
}
}
STATIC void emit_bc_store_deref ( emit_t * emit , qstr qst , mp_uint_t local_num ) {
void mp_ emit_bc_store_deref( emit_t * emit , qstr qst , mp_uint_t local_num ) {
( void ) qst ;
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 qst ) {
void mp_ emit_bc_store_name( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_STORE_NAME , qst ) ;
}
STATIC void emit_bc_store_global ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_store_global( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_STORE_GLOBAL , qst ) ;
}
STATIC void emit_bc_store_attr ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_store_attr( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , - 2 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_STORE_ATTR , qst ) ;
if ( MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE ) {
@ -586,74 +585,74 @@ STATIC void emit_bc_store_attr(emit_t *emit, qstr qst) {
}
}
STATIC void emit_bc_store_subscr ( emit_t * emit ) {
void mp_ emit_bc_store_subscr( emit_t * emit ) {
emit_bc_pre ( emit , - 3 ) ;
emit_write_bytecode_byte ( emit , MP_BC_STORE_SUBSCR ) ;
}
STATIC void emit_bc_delete_fast ( emit_t * emit , qstr qst , mp_uint_t local_num ) {
void mp_ emit_bc_delete_fast( emit_t * emit , qstr qst , mp_uint_t local_num ) {
( void ) qst ;
emit_write_bytecode_byte_uint ( emit , MP_BC_DELETE_FAST , local_num ) ;
}
STATIC void emit_bc_delete_deref ( emit_t * emit , qstr qst , mp_uint_t local_num ) {
void mp_ emit_bc_delete_deref( emit_t * emit , qstr qst , mp_uint_t local_num ) {
( void ) qst ;
emit_write_bytecode_byte_uint ( emit , MP_BC_DELETE_DEREF , local_num ) ;
}
STATIC void emit_bc_delete_name ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_delete_name( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_DELETE_NAME , qst ) ;
}
STATIC void emit_bc_delete_global ( emit_t * emit , qstr qst ) {
void mp_ emit_bc_delete_global( emit_t * emit , qstr qst ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte_qstr ( emit , MP_BC_DELETE_GLOBAL , qst ) ;
}
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 , qst ) ;
void mp_ emit_bc_delete_attr( emit_t * emit , qstr qst ) {
mp_ emit_bc_load_null( emit ) ;
mp_ emit_bc_rot_two( emit ) ;
mp_ emit_bc_store_attr( emit , qst ) ;
}
STATIC void emit_bc_delete_subscr ( emit_t * emit ) {
emit_bc_load_null ( emit ) ;
emit_bc_rot_three ( emit ) ;
emit_bc_store_subscr ( emit ) ;
void mp_ emit_bc_delete_subscr( emit_t * emit ) {
mp_ emit_bc_load_null( emit ) ;
mp_ emit_bc_rot_three( emit ) ;
mp_ emit_bc_store_subscr( emit ) ;
}
STATIC void emit_bc_dup_top ( emit_t * emit ) {
void mp_ emit_bc_dup_top( emit_t * emit ) {
emit_bc_pre ( emit , 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_DUP_TOP ) ;
}
STATIC void emit_bc_dup_top_two ( emit_t * emit ) {
void mp_ emit_bc_dup_top_two( emit_t * emit ) {
emit_bc_pre ( emit , 2 ) ;
emit_write_bytecode_byte ( emit , MP_BC_DUP_TOP_TWO ) ;
}
STATIC void emit_bc_pop_top ( emit_t * emit ) {
void mp_ emit_bc_pop_top( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_POP_TOP ) ;
}
STATIC void emit_bc_rot_two ( emit_t * emit ) {
void mp_ emit_bc_rot_two( emit_t * emit ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte ( emit , MP_BC_ROT_TWO ) ;
}
STATIC void emit_bc_rot_three ( emit_t * emit ) {
void mp_ emit_bc_rot_three( emit_t * emit ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte ( emit , MP_BC_ROT_THREE ) ;
}
STATIC void emit_bc_jump ( emit_t * emit , mp_uint_t label ) {
void mp_ 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 ( emit_t * emit , bool cond , mp_uint_t label ) {
void mp_ emit_bc_pop_jump_if( emit_t * emit , bool cond , mp_uint_t label ) {
emit_bc_pre ( emit , - 1 ) ;
if ( cond ) {
emit_write_bytecode_byte_signed_label ( emit , MP_BC_POP_JUMP_IF_TRUE , label ) ;
@ -662,7 +661,7 @@ STATIC void emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) {
}
}
STATIC void emit_bc_jump_if_or_pop ( emit_t * emit , bool cond , mp_uint_t label ) {
void mp_ emit_bc_jump_if_or_pop( emit_t * emit , bool cond , mp_uint_t label ) {
emit_bc_pre ( emit , - 1 ) ;
if ( cond ) {
emit_write_bytecode_byte_signed_label ( emit , MP_BC_JUMP_IF_TRUE_OR_POP , label ) ;
@ -671,7 +670,7 @@ STATIC void emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) {
}
}
STATIC void emit_bc_unwind_jump ( emit_t * emit , mp_uint_t label , mp_uint_t except_depth ) {
void mp_ 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 ) {
@ -685,56 +684,56 @@ STATIC void emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_
}
}
STATIC void emit_bc_setup_with ( emit_t * emit , mp_uint_t label ) {
void mp_ 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 ) ;
}
STATIC void emit_bc_with_cleanup ( emit_t * emit ) {
void mp_ emit_bc_with_cleanup( emit_t * emit ) {
emit_bc_pre ( emit , - 7 ) ;
emit_write_bytecode_byte ( emit , MP_BC_WITH_CLEANUP ) ;
}
STATIC void emit_bc_setup_except ( emit_t * emit , mp_uint_t label ) {
void mp_ 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 , mp_uint_t label ) {
void mp_ 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 ) ;
}
STATIC void emit_bc_end_finally ( emit_t * emit ) {
void mp_ emit_bc_end_finally( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
emit_write_bytecode_byte ( emit , MP_BC_END_FINALLY ) ;
}
STATIC void emit_bc_get_iter ( emit_t * emit ) {
void mp_ emit_bc_get_iter( emit_t * emit ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte ( emit , MP_BC_GET_ITER ) ;
}
STATIC void emit_bc_for_iter ( emit_t * emit , mp_uint_t label ) {
void mp_ 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 ) ;
}
STATIC void emit_bc_for_iter_end ( emit_t * emit ) {
void mp_ emit_bc_for_iter_end( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
}
STATIC void emit_bc_pop_block ( emit_t * emit ) {
void mp_ emit_bc_pop_block( emit_t * emit ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte ( emit , MP_BC_POP_BLOCK ) ;
}
STATIC void emit_bc_pop_except ( emit_t * emit ) {
void mp_ emit_bc_pop_except( emit_t * emit ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte ( emit , MP_BC_POP_EXCEPT ) ;
}
STATIC void emit_bc_unary_op ( emit_t * emit , mp_unary_op_t op ) {
void mp_ emit_bc_unary_op( emit_t * emit , mp_unary_op_t op ) {
if ( op = = MP_UNARY_OP_NOT ) {
emit_bc_pre ( emit , 0 ) ;
emit_write_bytecode_byte ( emit , MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_BOOL ) ;
@ -746,7 +745,7 @@ STATIC void emit_bc_unary_op(emit_t *emit, mp_unary_op_t op) {
}
}
STATIC void emit_bc_binary_op ( emit_t * emit , mp_binary_op_t op ) {
void mp_ emit_bc_binary_op( emit_t * emit , mp_binary_op_t op ) {
bool invert = false ;
if ( op = = MP_BINARY_OP_NOT_IN ) {
invert = true ;
@ -763,66 +762,66 @@ STATIC void emit_bc_binary_op(emit_t *emit, mp_binary_op_t op) {
}
}
STATIC void emit_bc_build_tuple ( emit_t * emit , mp_uint_t n_args ) {
void mp_ 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 , mp_uint_t n_args ) {
void mp_ 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 , mp_uint_t list_stack_index ) {
void mp_ 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 , mp_uint_t n_args ) {
void mp_ 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 ) ;
}
STATIC void emit_bc_store_map ( emit_t * emit ) {
void mp_ emit_bc_store_map( emit_t * emit ) {
emit_bc_pre ( emit , - 2 ) ;
emit_write_bytecode_byte ( emit , MP_BC_STORE_MAP ) ;
}
STATIC void emit_bc_map_add ( emit_t * emit , mp_uint_t map_stack_index ) {
void mp_ 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 ) ;
}
# if MICROPY_PY_BUILTINS_SET
STATIC void emit_bc_build_set ( emit_t * emit , mp_uint_t n_args ) {
void mp_ 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 , mp_uint_t set_stack_index ) {
void mp_ 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 ) ;
}
# endif
# if MICROPY_PY_BUILTINS_SLICE
STATIC void emit_bc_build_slice ( emit_t * emit , mp_uint_t n_args ) {
void mp_ 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 ) ;
}
# endif
STATIC void emit_bc_unpack_sequence ( emit_t * emit , mp_uint_t n_args ) {
void mp_ 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 , mp_uint_t n_left , mp_uint_t n_right ) {
void mp_ 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 , mp_uint_t n_pos_defaults , mp_uint_t n_kw_defaults ) {
void mp_ 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 ) ;
@ -832,7 +831,7 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_
}
}
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 ) {
void mp_ 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 ) ;
@ -849,11 +848,11 @@ STATIC void emit_bc_call_function_method_helper(emit_t *emit, mp_int_t stack_adj
if ( star_flags ) {
if ( ! ( star_flags & MP_EMIT_STAR_FLAG_SINGLE ) ) {
// load dummy entry for non-existent pos_seq
emit_bc_load_null ( emit ) ;
emit_bc_rot_two ( emit ) ;
mp_ emit_bc_load_null( emit ) ;
mp_ emit_bc_rot_two( emit ) ;
} else if ( ! ( star_flags & MP_EMIT_STAR_FLAG_DOUBLE ) ) {
// load dummy entry for non-existent kw_dict
emit_bc_load_null ( emit ) ;
mp_ emit_bc_load_null( emit ) ;
}
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?
@ -863,138 +862,161 @@ STATIC void emit_bc_call_function_method_helper(emit_t *emit, mp_int_t stack_adj
}
}
STATIC void emit_bc_call_function ( emit_t * emit , mp_uint_t n_positional , mp_uint_t n_keyword , mp_uint_t star_flags ) {
void mp_ 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 , mp_uint_t n_positional , mp_uint_t n_keyword , mp_uint_t star_flags ) {
void mp_ 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 ) ;
}
STATIC void emit_bc_return_value ( emit_t * emit ) {
void mp_ emit_bc_return_value( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
emit - > last_emit_was_return_value = true ;
emit_write_bytecode_byte ( emit , MP_BC_RETURN_VALUE ) ;
}
STATIC void emit_bc_raise_varargs ( emit_t * emit , mp_uint_t n_args ) {
void mp_ 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 ) ;
}
STATIC void emit_bc_yield_value ( emit_t * emit ) {
void mp_ emit_bc_yield_value( emit_t * emit ) {
emit_bc_pre ( emit , 0 ) ;
emit - > scope - > scope_flags | = MP_SCOPE_FLAG_GENERATOR ;
emit_write_bytecode_byte ( emit , MP_BC_YIELD_VALUE ) ;
}
STATIC void emit_bc_yield_from ( emit_t * emit ) {
void mp_ emit_bc_yield_from( emit_t * emit ) {
emit_bc_pre ( emit , - 1 ) ;
emit - > scope - > scope_flags | = MP_SCOPE_FLAG_GENERATOR ;
emit_write_bytecode_byte ( emit , MP_BC_YIELD_FROM ) ;
}
STATIC void emit_bc_start_except_handler ( emit_t * emit ) {
emit_bc_adjust_stack_size ( emit , 6 ) ; // stack adjust for the 3 exception items, +3 for possible UNWIND_JUMP state
void mp_ emit_bc_start_except_handler( emit_t * emit ) {
mp_ emit_bc_adjust_stack_size( emit , 6 ) ; // stack adjust for the 3 exception items, +3 for possible UNWIND_JUMP state
}
STATIC void emit_bc_end_except_handler ( emit_t * emit ) {
emit_bc_adjust_stack_size ( emit , - 5 ) ; // stack adjust
void mp_ emit_bc_end_except_handler( emit_t * emit ) {
mp_ emit_bc_adjust_stack_size( emit , - 5 ) ; // stack adjust
}
# if MICROPY_EMIT_NATIVE
const emit_method_table_t emit_bc_method_table = {
emit_bc_set_native_type ,
emit_bc_start_pass ,
emit_bc_end_pass ,
emit_bc_last_emit_was_return_value ,
emit_bc_adjust_stack_size ,
emit_bc_set_source_line ,
mp_ emit_bc_set_native_type,
mp_ emit_bc_start_pass,
mp_ emit_bc_end_pass,
mp_ emit_bc_last_emit_was_return_value,
mp_ emit_bc_adjust_stack_size,
mp_ emit_bc_set_source_line,
{
emit_bc_load_fast ,
emit_bc_load_deref ,
emit_bc_load_name ,
emit_bc_load_global ,
mp_ emit_bc_load_fast,
mp_ emit_bc_load_deref,
mp_ emit_bc_load_name,
mp_ emit_bc_load_global,
} ,
{
emit_bc_store_fast ,
emit_bc_store_deref ,
emit_bc_store_name ,
emit_bc_store_global ,
mp_ emit_bc_store_fast,
mp_ emit_bc_store_deref,
mp_ emit_bc_store_name,
mp_ emit_bc_store_global,
} ,
{
emit_bc_delete_fast ,
emit_bc_delete_deref ,
emit_bc_delete_name ,
emit_bc_delete_global ,
mp_ emit_bc_delete_fast,
mp_ emit_bc_delete_deref,
mp_ emit_bc_delete_name,
mp_ emit_bc_delete_global,
} ,
emit_bc_label_assign ,
emit_bc_import_name ,
emit_bc_import_from ,
emit_bc_import_star ,
emit_bc_load_const_tok ,
emit_bc_load_const_small_int ,
emit_bc_load_const_str ,
emit_bc_load_const_obj ,
emit_bc_load_null ,
emit_bc_load_attr ,
emit_bc_load_method ,
emit_bc_load_build_class ,
emit_bc_load_subscr ,
emit_bc_store_attr ,
emit_bc_store_subscr ,
emit_bc_delete_attr ,
emit_bc_delete_subscr ,
emit_bc_dup_top ,
emit_bc_dup_top_two ,
emit_bc_pop_top ,
emit_bc_rot_two ,
emit_bc_rot_three ,
emit_bc_jump ,
emit_bc_pop_jump_if ,
emit_bc_jump_if_or_pop ,
emit_bc_unwind_jump ,
emit_bc_unwind_jump ,
emit_bc_setup_with ,
emit_bc_with_cleanup ,
emit_bc_setup_except ,
emit_bc_setup_finally ,
emit_bc_end_finally ,
emit_bc_get_iter ,
emit_bc_for_iter ,
emit_bc_for_iter_end ,
emit_bc_pop_block ,
emit_bc_pop_except ,
emit_bc_unary_op ,
emit_bc_binary_op ,
emit_bc_build_tuple ,
emit_bc_build_list ,
emit_bc_list_append ,
emit_bc_build_map ,
emit_bc_store_map ,
emit_bc_map_add ,
mp_ emit_bc_label_assign,
mp_ emit_bc_import_name,
mp_ emit_bc_import_from,
mp_ emit_bc_import_star,
mp_ emit_bc_load_const_tok,
mp_ emit_bc_load_const_small_int,
mp_ emit_bc_load_const_str,
mp_ emit_bc_load_const_obj,
mp_ emit_bc_load_null,
mp_ emit_bc_load_attr,
mp_ emit_bc_load_method,
mp_ emit_bc_load_build_class,
mp_ emit_bc_load_subscr,
mp_ emit_bc_store_attr,
mp_ emit_bc_store_subscr,
mp_ emit_bc_delete_attr,
mp_ emit_bc_delete_subscr,
mp_ emit_bc_dup_top,
mp_ emit_bc_dup_top_two,
mp_ emit_bc_pop_top,
mp_ emit_bc_rot_two,
mp_ emit_bc_rot_three,
mp_ emit_bc_jump,
mp_ emit_bc_pop_jump_if,
mp_ emit_bc_jump_if_or_pop,
mp_ emit_bc_unwind_jump,
mp_ emit_bc_unwind_jump,
mp_ emit_bc_setup_with,
mp_ emit_bc_with_cleanup,
mp_ emit_bc_setup_except,
mp_ emit_bc_setup_finally,
mp_ emit_bc_end_finally,
mp_ emit_bc_get_iter,
mp_ emit_bc_for_iter,
mp_ emit_bc_for_iter_end,
mp_ emit_bc_pop_block,
mp_ emit_bc_pop_except,
mp_ emit_bc_unary_op,
mp_ emit_bc_binary_op,
mp_ emit_bc_build_tuple,
mp_ emit_bc_build_list,
mp_ emit_bc_list_append,
mp_ emit_bc_build_map,
mp_ emit_bc_store_map,
mp_ emit_bc_map_add,
# if MICROPY_PY_BUILTINS_SET
emit_bc_build_set ,
emit_bc_set_add ,
mp_ emit_bc_build_set,
mp_ emit_bc_set_add,
# endif
# if MICROPY_PY_BUILTINS_SLICE
emit_bc_build_slice ,
mp_ emit_bc_build_slice,
# endif
emit_bc_unpack_sequence ,
emit_bc_unpack_ex ,
emit_bc_make_function ,
emit_bc_make_closure ,
emit_bc_call_function ,
emit_bc_call_method ,
emit_bc_return_value ,
emit_bc_raise_varargs ,
emit_bc_yield_value ,
emit_bc_yield_from ,
emit_bc_start_except_handler ,
emit_bc_end_except_handler ,
mp_emit_bc_unpack_sequence ,
mp_emit_bc_unpack_ex ,
mp_emit_bc_make_function ,
mp_emit_bc_make_closure ,
mp_emit_bc_call_function ,
mp_emit_bc_call_method ,
mp_emit_bc_return_value ,
mp_emit_bc_raise_varargs ,
mp_emit_bc_yield_value ,
mp_emit_bc_yield_from ,
mp_emit_bc_start_except_handler ,
mp_emit_bc_end_except_handler ,
} ;
# else
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_load_id_ops = {
mp_emit_bc_load_fast ,
mp_emit_bc_load_deref ,
mp_emit_bc_load_name ,
mp_emit_bc_load_global ,
} ;
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_store_id_ops = {
mp_emit_bc_store_fast ,
mp_emit_bc_store_deref ,
mp_emit_bc_store_name ,
mp_emit_bc_store_global ,
} ;
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_delete_id_ops = {
mp_emit_bc_delete_fast ,
mp_emit_bc_delete_deref ,
mp_emit_bc_delete_name ,
mp_emit_bc_delete_global ,
} ;
# endif
# endif // !MICROPY_EMIT_CPYTHON