py: Make functions static where appropriate.

This commit is contained in:
Damien George 2014-12-10 22:07:04 +00:00
parent d51107927d
commit 969a6b37bf
22 changed files with 100 additions and 103 deletions

View File

@ -559,7 +559,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
/// \function addressof() /// \function addressof()
/// Return address of object's data (applies to object providing buffer /// Return address of object's data (applies to object providing buffer
/// interface). /// interface).
mp_obj_t uctypes_struct_addressof(mp_obj_t buf) { STATIC mp_obj_t uctypes_struct_addressof(mp_obj_t buf) {
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
return mp_obj_new_int((mp_int_t)bufinfo.buf); return mp_obj_new_int((mp_int_t)bufinfo.buf);
@ -570,7 +570,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof
/// Capture memory at given address of given size as bytearray. Memory is /// Capture memory at given address of given size as bytearray. Memory is
/// captured by reference (and thus memory pointed by bytearray may change /// captured by reference (and thus memory pointed by bytearray may change
/// or become invalid at later time). Use bytes_at() to capture by value. /// or become invalid at later time). Use bytes_at() to capture by value.
mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) { STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr)); return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr));
} }
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at); MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
@ -579,7 +579,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear
/// Capture memory at given address of given size as bytes. Memory is /// Capture memory at given address of given size as bytes. Memory is
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference /// captured by value, i.e. copied. Use bytearray_at() to capture by reference
/// ("zero copy"). /// ("zero copy").
mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) { STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
return mp_obj_new_bytes((void*)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size)); return mp_obj_new_bytes((void*)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
} }
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at); MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);

View File

@ -175,7 +175,7 @@ STATIC const mp_obj_type_t re_type = {
.locals_dict = (mp_obj_t)&re_locals_dict, .locals_dict = (mp_obj_t)&re_locals_dict,
}; };
mp_obj_t mod_re_compile(uint n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_re_compile(uint n_args, const mp_obj_t *args) {
const char *re_str = mp_obj_str_get_str(args[0]); const char *re_str = mp_obj_str_get_str(args[0]);
int size = re1_5_sizecode(re_str); int size = re1_5_sizecode(re_str);
mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size); mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size);

View File

@ -325,7 +325,7 @@ void asm_x86_add_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) {
asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_ADD_R32_TO_RM32); asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_ADD_R32_TO_RM32);
} }
void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) { STATIC void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) {
if (SIGNED_FIT8(src_i32)) { if (SIGNED_FIT8(src_i32)) {
asm_x86_write_byte_2(as, OPCODE_ADD_I8_TO_RM32, MODRM_R32(0) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); asm_x86_write_byte_2(as, OPCODE_ADD_I8_TO_RM32, MODRM_R32(0) | MODRM_RM_REG | MODRM_RM_R32(dest_r32));
asm_x86_write_byte_1(as, src_i32 & 0xff); asm_x86_write_byte_1(as, src_i32 & 0xff);

View File

@ -429,10 +429,7 @@ STATIC int list_get(mp_parse_node_t *pn, int pn_kind, mp_parse_node_t **nodes) {
} }
} }
void compile_do_nothing(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < num_nodes; i++) { for (int i = 0; i < num_nodes; i++) {
compile_node(comp, pns->nodes[i]); compile_node(comp, pns->nodes[i]);
@ -602,7 +599,7 @@ STATIC void c_tuple(compiler_t *comp, mp_parse_node_t pn, mp_parse_node_struct_t
#endif #endif
} }
void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) {
// a simple tuple expression // a simple tuple expression
c_tuple(comp, MP_PARSE_NODE_NULL, pns); c_tuple(comp, MP_PARSE_NODE_NULL, pns);
} }
@ -1100,7 +1097,7 @@ STATIC void compile_funcdef_param(compiler_t *comp, mp_parse_node_t pn) {
// leaves function object on stack // leaves function object on stack
// returns function name // returns function name
qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { STATIC qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) {
if (comp->pass == MP_PASS_SCOPE) { if (comp->pass == MP_PASS_SCOPE) {
// create a new scope for this function // create a new scope for this function
scope_t *s = scope_new_and_link(comp, SCOPE_FUNCTION, (mp_parse_node_t)pns, emit_options); scope_t *s = scope_new_and_link(comp, SCOPE_FUNCTION, (mp_parse_node_t)pns, emit_options);
@ -1149,7 +1146,7 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
// leaves class object on stack // leaves class object on stack
// returns class name // returns class name
qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { STATIC qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) {
if (comp->pass == MP_PASS_SCOPE) { if (comp->pass == MP_PASS_SCOPE) {
// create a new scope for this class // create a new scope for this class
scope_t *s = scope_new_and_link(comp, SCOPE_CLASS, (mp_parse_node_t)pns, emit_options); scope_t *s = scope_new_and_link(comp, SCOPE_CLASS, (mp_parse_node_t)pns, emit_options);
@ -1212,7 +1209,7 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
return true; return true;
} }
void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) {
// get the list of decorators // get the list of decorators
mp_parse_node_t *nodes; mp_parse_node_t *nodes;
int n = list_get(&pns->nodes[0], PN_decorators, &nodes); int n = list_get(&pns->nodes[0], PN_decorators, &nodes);
@ -1275,7 +1272,7 @@ void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(store_id, body_name); EMIT_ARG(store_id, body_name);
} }
void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
qstr fname = compile_funcdef_helper(comp, pns, comp->scope_cur->emit_options); qstr fname = compile_funcdef_helper(comp, pns, comp->scope_cur->emit_options);
// store function object into function name // store function object into function name
EMIT_ARG(store_id, fname); EMIT_ARG(store_id, fname);
@ -1365,11 +1362,11 @@ cannot_delete:
compile_syntax_error(comp, (mp_parse_node_t)pn, "can't delete expression"); compile_syntax_error(comp, (mp_parse_node_t)pn, "can't delete expression");
} }
void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
apply_to_single_or_list(comp, pns->nodes[0], PN_exprlist, c_del_stmt); apply_to_single_or_list(comp, pns->nodes[0], PN_exprlist, c_del_stmt);
} }
void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->break_label == 0) { if (comp->break_label == 0) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "'break' outside loop"); compile_syntax_error(comp, (mp_parse_node_t)pns, "'break' outside loop");
} }
@ -1377,7 +1374,7 @@ void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(break_loop, comp->break_label, comp->cur_except_level - comp->break_continue_except_level); EMIT_ARG(break_loop, comp->break_label, comp->cur_except_level - comp->break_continue_except_level);
} }
void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->continue_label == 0) { if (comp->continue_label == 0) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "'continue' outside loop"); compile_syntax_error(comp, (mp_parse_node_t)pns, "'continue' outside loop");
} }
@ -1385,7 +1382,7 @@ void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(continue_loop, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level); EMIT_ARG(continue_loop, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level);
} }
void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->scope_cur->kind != SCOPE_FUNCTION) { if (comp->scope_cur->kind != SCOPE_FUNCTION) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "'return' outside function"); compile_syntax_error(comp, (mp_parse_node_t)pns, "'return' outside function");
return; return;
@ -1410,12 +1407,12 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT(return_value); EMIT(return_value);
} }
void compile_yield_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_yield_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
EMIT(pop_top); EMIT(pop_top);
} }
void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
// raise // raise
EMIT_ARG(raise_varargs, 0); EMIT_ARG(raise_varargs, 0);
@ -1503,11 +1500,11 @@ STATIC void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) {
EMIT_ARG(store_id, q_base); EMIT_ARG(store_id, q_base);
} }
void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) {
apply_to_single_or_list(comp, pns->nodes[0], PN_dotted_as_names, compile_dotted_as_name); apply_to_single_or_list(comp, pns->nodes[0], PN_dotted_as_names, compile_dotted_as_name);
} }
void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_t pn_import_source = pns->nodes[0]; mp_parse_node_t pn_import_source = pns->nodes[0];
// extract the preceeding .'s (if any) for a relative import, to compute the import level // extract the preceeding .'s (if any) for a relative import, to compute the import level
@ -1618,7 +1615,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_global_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_global_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->pass == MP_PASS_SCOPE) { if (comp->pass == MP_PASS_SCOPE) {
if (MP_PARSE_NODE_IS_LEAF(pns->nodes[0])) { if (MP_PARSE_NODE_IS_LEAF(pns->nodes[0])) {
scope_declare_global(comp->scope_cur, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0])); scope_declare_global(comp->scope_cur, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]));
@ -1632,7 +1629,7 @@ void compile_global_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->pass == MP_PASS_SCOPE) { if (comp->pass == MP_PASS_SCOPE) {
if (MP_PARSE_NODE_IS_LEAF(pns->nodes[0])) { if (MP_PARSE_NODE_IS_LEAF(pns->nodes[0])) {
scope_declare_nonlocal(comp->scope_cur, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0])); scope_declare_nonlocal(comp->scope_cur, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]));
@ -1646,7 +1643,7 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
uint l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
c_if_cond(comp, pns->nodes[0], true, l_end); c_if_cond(comp, pns->nodes[0], true, l_end);
EMIT_ARG(load_global, MP_QSTR_AssertionError); // we load_global instead of load_id, to be consistent with CPython EMIT_ARG(load_global, MP_QSTR_AssertionError); // we load_global instead of load_id, to be consistent with CPython
@ -1659,7 +1656,7 @@ void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(label_assign, l_end); EMIT_ARG(label_assign, l_end);
} }
void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// TODO proper and/or short circuiting // TODO proper and/or short circuiting
uint l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
@ -1738,7 +1735,7 @@ done:
comp->continue_label = old_continue_label; \ comp->continue_label = old_continue_label; \
comp->break_continue_except_level = old_break_continue_except_level; comp->break_continue_except_level = old_break_continue_except_level;
void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
START_BREAK_CONTINUE_BLOCK START_BREAK_CONTINUE_BLOCK
// compared to CPython, we have an optimised version of while loops // compared to CPython, we have an optimised version of while loops
@ -1837,7 +1834,7 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
} }
#endif #endif
void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
#if !MICROPY_EMIT_CPYTHON #if !MICROPY_EMIT_CPYTHON
// this bit optimises: for <x> in range(...), turning it into an explicitly incremented variable // this bit optimises: for <x> in range(...), turning it into an explicitly incremented variable
// this is actually slower, but uses no heap memory // this is actually slower, but uses no heap memory
@ -2034,7 +2031,7 @@ STATIC void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n
EMIT(end_finally); EMIT(end_finally);
} }
void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])) { if (MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])) {
mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t*)pns->nodes[1]; mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t*)pns->nodes[1];
if (MP_PARSE_NODE_STRUCT_KIND(pns2) == PN_try_stmt_finally) { if (MP_PARSE_NODE_STRUCT_KIND(pns2) == PN_try_stmt_finally) {
@ -2094,7 +2091,7 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *n
} }
} }
void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// get the nodes for the pre-bit of the with (the a as b, c as d, ... bit) // get the nodes for the pre-bit of the with (the a as b, c as d, ... bit)
mp_parse_node_t *nodes; mp_parse_node_t *nodes;
int n = list_get(&pns->nodes[0], PN_with_stmt_list, &nodes); int n = list_get(&pns->nodes[0], PN_with_stmt_list, &nodes);
@ -2104,7 +2101,7 @@ void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_with_stmt_helper(comp, n, nodes, pns->nodes[1]); compile_with_stmt_helper(comp, n, nodes, pns->nodes[1]);
} }
void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_IS_NULL(pns->nodes[1])) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[1])) {
if (comp->is_repl && comp->scope_cur->kind == SCOPE_MODULE) { if (comp->is_repl && comp->scope_cur->kind == SCOPE_MODULE) {
// for REPL, evaluate then print the expression // for REPL, evaluate then print the expression
@ -2222,7 +2219,7 @@ STATIC void c_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns, mp_binary
} }
} }
void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_test_if_else)); assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_test_if_else));
mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns->nodes[1]; mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns->nodes[1];
@ -2237,7 +2234,7 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(label_assign, l_end); EMIT_ARG(label_assign, l_end);
} }
void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
// TODO default params etc for lambda; possibly just use funcdef code // TODO default params etc for lambda; possibly just use funcdef code
//mp_parse_node_t pn_params = pns->nodes[0]; //mp_parse_node_t pn_params = pns->nodes[0];
//mp_parse_node_t pn_body = pns->nodes[1]; //mp_parse_node_t pn_body = pns->nodes[1];
@ -2256,7 +2253,7 @@ void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
close_over_variables_etc(comp, this_scope, 0, 0); close_over_variables_etc(comp, this_scope, 0, 0);
} }
void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
uint l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) { for (int i = 0; i < n; i += 1) {
@ -2268,7 +2265,7 @@ void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(label_assign, l_end); EMIT_ARG(label_assign, l_end);
} }
void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
uint l_end = comp_next_label(comp); uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) { for (int i = 0; i < n; i += 1) {
@ -2280,12 +2277,12 @@ void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(label_assign, l_end); EMIT_ARG(label_assign, l_end);
} }
void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
EMIT_ARG(unary_op, MP_UNARY_OP_NOT); EMIT_ARG(unary_op, MP_UNARY_OP_NOT);
} }
void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
bool multi = (num_nodes > 3); bool multi = (num_nodes > 3);
@ -2346,23 +2343,23 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "*x must be assignment target"); compile_syntax_error(comp, (mp_parse_node_t)pns, "*x must be assignment target");
} }
void compile_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, MP_BINARY_OP_OR); c_binary_op(comp, pns, MP_BINARY_OP_OR);
} }
void compile_xor_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_xor_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, MP_BINARY_OP_XOR); c_binary_op(comp, pns, MP_BINARY_OP_XOR);
} }
void compile_and_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_and_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, MP_BINARY_OP_AND); c_binary_op(comp, pns, MP_BINARY_OP_AND);
} }
void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
for (int i = 1; i + 1 < num_nodes; i += 2) { for (int i = 1; i + 1 < num_nodes; i += 2) {
@ -2378,7 +2375,7 @@ void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_arith_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_arith_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
for (int i = 1; i + 1 < num_nodes; i += 2) { for (int i = 1; i + 1 < num_nodes; i += 2) {
@ -2394,7 +2391,7 @@ void compile_arith_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
for (int i = 1; i + 1 < num_nodes; i += 2) { for (int i = 1; i + 1 < num_nodes; i += 2) {
@ -2414,7 +2411,7 @@ void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[1]); compile_node(comp, pns->nodes[1]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_PLUS)) { if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_PLUS)) {
EMIT_ARG(unary_op, MP_UNARY_OP_POSITIVE); EMIT_ARG(unary_op, MP_UNARY_OP_POSITIVE);
@ -2428,7 +2425,7 @@ void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) {
// this is to handle special super() call // this is to handle special super() call
comp->func_arg_is_super = MP_PARSE_NODE_IS_ID(pns->nodes[0]) && MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]) == MP_QSTR_super; comp->func_arg_is_super = MP_PARSE_NODE_IS_ID(pns->nodes[0]) && MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]) == MP_QSTR_super;
@ -2526,7 +2523,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
} }
} }
void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < num_nodes; i++) { for (int i = 0; i < num_nodes; i++) {
if (i + 1 < num_nodes && MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[i], PN_trailer_period) && MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[i + 1], PN_trailer_paren)) { if (i + 1 < num_nodes && MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[i], PN_trailer_period) && MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[i + 1], PN_trailer_paren)) {
@ -2543,12 +2540,12 @@ void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_power_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_power_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]); compile_node(comp, pns->nodes[0]);
EMIT_ARG(binary_op, MP_BINARY_OP_POWER); EMIT_ARG(binary_op, MP_BINARY_OP_POWER);
} }
void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
// a list of strings // a list of strings
// check type of list (string or bytes) and count total number of bytes // check type of list (string or bytes) and count total number of bytes
@ -2620,7 +2617,7 @@ STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns,
EMIT_ARG(call_function, 1, 0, 0); EMIT_ARG(call_function, 1, 0, 0);
} }
void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
// an empty tuple // an empty tuple
c_tuple(comp, MP_PARSE_NODE_NULL, NULL); c_tuple(comp, MP_PARSE_NODE_NULL, NULL);
@ -2654,7 +2651,7 @@ void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
// empty list // empty list
EMIT_ARG(build_list, 0); EMIT_ARG(build_list, 0);
@ -2693,7 +2690,7 @@ void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_t pn = pns->nodes[0]; mp_parse_node_t pn = pns->nodes[0];
if (MP_PARSE_NODE_IS_NULL(pn)) { if (MP_PARSE_NODE_IS_NULL(pn)) {
// empty dict // empty dict
@ -2777,22 +2774,22 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_trailer_paren_helper(comp, pns->nodes[0], false, 0); compile_trailer_paren_helper(comp, pns->nodes[0], false, 0);
} }
void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) {
// object who's index we want is on top of stack // object who's index we want is on top of stack
compile_node(comp, pns->nodes[0]); // the index compile_node(comp, pns->nodes[0]); // the index
EMIT(load_subscr); EMIT(load_subscr);
} }
void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) {
// object who's attribute we want is on top of stack // object who's attribute we want is on top of stack
EMIT_ARG(load_attr, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0])); // attribute to get EMIT_ARG(load_attr, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0])); // attribute to get
} }
void compile_subscript_3_helper(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_subscript_3_helper(compiler_t *comp, mp_parse_node_struct_t *pns) {
assert(MP_PARSE_NODE_STRUCT_KIND(pns) == PN_subscript_3); // should always be assert(MP_PARSE_NODE_STRUCT_KIND(pns) == PN_subscript_3); // should always be
mp_parse_node_t pn = pns->nodes[0]; mp_parse_node_t pn = pns->nodes[0];
if (MP_PARSE_NODE_IS_NULL(pn)) { if (MP_PARSE_NODE_IS_NULL(pn)) {
@ -2837,30 +2834,30 @@ void compile_subscript_3_helper(compiler_t *comp, mp_parse_node_struct_t *pns) {
} }
} }
void compile_subscript_2(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_subscript_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]); // start of slice compile_node(comp, pns->nodes[0]); // start of slice
assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should always be assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should always be
compile_subscript_3_helper(comp, (mp_parse_node_struct_t*)pns->nodes[1]); compile_subscript_3_helper(comp, (mp_parse_node_struct_t*)pns->nodes[1]);
} }
void compile_subscript_3(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_subscript_3(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
compile_subscript_3_helper(comp, pns); compile_subscript_3_helper(comp, pns);
} }
void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) {
// if this is called then we are compiling a dict key:value pair // if this is called then we are compiling a dict key:value pair
compile_node(comp, pns->nodes[1]); // value compile_node(comp, pns->nodes[1]); // value
compile_node(comp, pns->nodes[0]); // key compile_node(comp, pns->nodes[0]); // key
} }
void compile_classdef(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_classdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
qstr cname = compile_classdef_helper(comp, pns, comp->scope_cur->emit_options); qstr cname = compile_classdef_helper(comp, pns, comp->scope_cur->emit_options);
// store class object into class name // store class object into class name
EMIT_ARG(store_id, cname); EMIT_ARG(store_id, cname);
} }
void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) { if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "'yield' outside function"); compile_syntax_error(comp, (mp_parse_node_t)pns, "'yield' outside function");
return; return;

View File

@ -61,7 +61,7 @@ struct _emit_inline_asm_t {
asm_thumb_t *as; asm_thumb_t *as;
}; };
void emit_inline_thumb_error(emit_inline_asm_t *emit, const char *fmt, ...) { STATIC void emit_inline_thumb_error(emit_inline_asm_t *emit, const char *fmt, ...) {
printf("SyntaxError: "); printf("SyntaxError: ");
emit->success = false; emit->success = false;
va_list ap; va_list ap;

View File

@ -47,7 +47,7 @@ extern const mp_obj_float_t mp_math_pi_obj;
/// \function phase(z) /// \function phase(z)
/// Returns the phase of the number `z`, in the range (-pi, +pi]. /// Returns the phase of the number `z`, in the range (-pi, +pi].
mp_obj_t mp_cmath_phase(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(atan2)(imag, real)); return mp_obj_new_float(MICROPY_FLOAT_C_FUN(atan2)(imag, real));
@ -56,7 +56,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase);
/// \function polar(z) /// \function polar(z)
/// Returns, as a tuple, the polar form of `z`. /// Returns, as a tuple, the polar form of `z`.
mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
mp_obj_t tuple[2] = { mp_obj_t tuple[2] = {
@ -69,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar);
/// \function rect(r, phi) /// \function rect(r, phi)
/// Returns the complex number with modulus `r` and phase `phi`. /// Returns the complex number with modulus `r` and phase `phi`.
mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) { STATIC mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) {
mp_float_t r = mp_obj_get_float(r_obj); mp_float_t r = mp_obj_get_float(r_obj);
mp_float_t phi = mp_obj_get_float(phi_obj); mp_float_t phi = mp_obj_get_float(phi_obj);
return mp_obj_new_complex(r * MICROPY_FLOAT_C_FUN(cos)(phi), r * MICROPY_FLOAT_C_FUN(sin)(phi)); return mp_obj_new_complex(r * MICROPY_FLOAT_C_FUN(cos)(phi), r * MICROPY_FLOAT_C_FUN(sin)(phi));
@ -78,7 +78,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect);
/// \function exp(z) /// \function exp(z)
/// Return the exponential of `z`. /// Return the exponential of `z`.
mp_obj_t mp_cmath_exp(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
mp_float_t exp_real = MICROPY_FLOAT_C_FUN(exp)(real); mp_float_t exp_real = MICROPY_FLOAT_C_FUN(exp)(real);
@ -89,7 +89,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp);
/// \function log(z) /// \function log(z)
/// Return the natural logarithm of `z`. The branch cut is along the negative real axis. /// Return the natural logarithm of `z`. The branch cut is along the negative real axis.
// TODO can take second argument, being the base // TODO can take second argument, being the base
mp_obj_t mp_cmath_log(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log)(real*real + imag*imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real)); return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log)(real*real + imag*imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real));
@ -98,7 +98,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log);
/// \function log10(z) /// \function log10(z)
/// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis. /// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log10)(real*real + imag*imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real)); return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log10)(real*real + imag*imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real));
@ -107,7 +107,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10);
/// \function sqrt(z) /// \function sqrt(z)
/// Return the square-root of `z`. /// Return the square-root of `z`.
mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
mp_float_t sqrt_abs = MICROPY_FLOAT_C_FUN(pow)(real*real + imag*imag, 0.25); mp_float_t sqrt_abs = MICROPY_FLOAT_C_FUN(pow)(real*real + imag*imag, 0.25);
@ -118,7 +118,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt);
/// \function cos(z) /// \function cos(z)
/// Return the cosine of `z`. /// Return the cosine of `z`.
mp_obj_t mp_cmath_cos(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_cos(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), -MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag)); return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), -MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag));
@ -127,7 +127,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos);
/// \function sin(z) /// \function sin(z)
/// Return the sine of `z`. /// Return the sine of `z`.
mp_obj_t mp_cmath_sin(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_sin(mp_obj_t z_obj) {
mp_float_t real, imag; mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag); mp_obj_get_complex(z_obj, &real, &imag);
return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag)); return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag));

View File

@ -41,19 +41,19 @@
//TODO: Change macros to check for overflow and raise OverflowError or RangeError //TODO: Change macros to check for overflow and raise OverflowError or RangeError
#define MATH_FUN_1(py_name, c_name) \ #define MATH_FUN_1(py_name, c_name) \
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#define MATH_FUN_2(py_name, c_name) \ #define MATH_FUN_2(py_name, c_name) \
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_float(y_obj))); } \ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_float(y_obj))); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#define MATH_FUN_1_TO_BOOL(py_name, c_name) \ #define MATH_FUN_1_TO_BOOL(py_name, c_name) \
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return MP_BOOL(c_name(mp_obj_get_float(x_obj))); } \ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return MP_BOOL(c_name(mp_obj_get_float(x_obj))); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#define MATH_FUN_1_TO_INT(py_name, c_name) \ #define MATH_FUN_1_TO_INT(py_name, c_name) \
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_int((mp_int_t)MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { mp_int_t x = MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj)); return mp_obj_new_int(x); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
// These are also used by cmath.c // These are also used by cmath.c
@ -142,7 +142,7 @@ MATH_FUN_1(lgamma, lgamma)
/// \function frexp(x) /// \function frexp(x)
/// Converts a floating-point number to fractional and integral components. /// Converts a floating-point number to fractional and integral components.
mp_obj_t mp_math_frexp(mp_obj_t x_obj) { STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
int int_exponent = 0; int int_exponent = 0;
mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent); mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent);
mp_obj_t tuple[2]; mp_obj_t tuple[2];
@ -153,7 +153,7 @@ mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp);
/// \function modf(x) /// \function modf(x)
mp_obj_t mp_math_modf(mp_obj_t x_obj) { STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) {
mp_float_t int_part = 0.0; mp_float_t int_part = 0.0;
mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(mp_obj_get_float(x_obj), &int_part); mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(mp_obj_get_float(x_obj), &int_part);
mp_obj_t tuple[2]; mp_obj_t tuple[2];
@ -166,13 +166,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf);
// Angular conversions // Angular conversions
/// \function radians(x) /// \function radians(x)
mp_obj_t mp_math_radians(mp_obj_t x_obj) { STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) {
return mp_obj_new_float(mp_obj_get_float(x_obj) * M_PI / 180.0); return mp_obj_new_float(mp_obj_get_float(x_obj) * M_PI / 180.0);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians);
/// \function degrees(x) /// \function degrees(x)
mp_obj_t mp_math_degrees(mp_obj_t x_obj) { STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) {
return mp_obj_new_float(mp_obj_get_float(x_obj) * 180.0 / M_PI); return mp_obj_new_float(mp_obj_get_float(x_obj) * 180.0 / M_PI);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees);

View File

@ -50,7 +50,7 @@ STATIC void bound_meth_print(void (*print)(void *env, const char *fmt, ...), voi
} }
#endif #endif
mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
mp_obj_bound_meth_t *self = self_in; mp_obj_bound_meth_t *self = self_in;
// need to insert self->self before all other args and then call self->meth // need to insert self->self before all other args and then call self->meth

View File

@ -41,7 +41,7 @@ typedef struct _mp_obj_closure_t {
mp_obj_t closed[]; mp_obj_t closed[];
} mp_obj_closure_t; } mp_obj_closure_t;
mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
mp_obj_closure_t *self = self_in; mp_obj_closure_t *self = self_in;
// need to concatenate closed-over-vars and args // need to concatenate closed-over-vars and args

View File

@ -491,7 +491,7 @@ STATIC const mp_obj_type_t dict_view_type = {
.getiter = dict_view_getiter, .getiter = dict_view_getiter,
}; };
mp_obj_t mp_obj_new_dict_view(mp_obj_dict_t *dict, mp_dict_view_kind_t kind) { STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_dict_t *dict, mp_dict_view_kind_t kind) {
mp_obj_dict_view_t *o = m_new_obj(mp_obj_dict_view_t); mp_obj_dict_view_t *o = m_new_obj(mp_obj_dict_view_t);
o->base.type = &dict_view_type; o->base.type = &dict_view_type;
o->dict = dict; o->dict = dict;

View File

@ -97,7 +97,7 @@ mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun) {
/******************************************************************************/ /******************************************************************************/
/* generator instance */ /* generator instance */
void gen_instance_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void gen_instance_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_gen_instance_t *self = self_in; mp_obj_gen_instance_t *self = self_in;
print(env, "<generator object '%s' at %p>", mp_obj_code_get_name(self->code_state.code_info), self_in); print(env, "<generator object '%s' at %p>", mp_obj_code_get_name(self->code_state.code_info), self_in);
} }
@ -183,7 +183,7 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
} }
} }
mp_obj_t gen_instance_iternext(mp_obj_t self_in) { STATIC mp_obj_t gen_instance_iternext(mp_obj_t self_in) {
return gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL); return gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL);
} }

View File

@ -497,7 +497,7 @@ typedef struct _mp_obj_list_it_t {
mp_uint_t cur; mp_uint_t cur;
} mp_obj_list_it_t; } mp_obj_list_it_t;
mp_obj_t list_it_iternext(mp_obj_t self_in) { STATIC mp_obj_t list_it_iternext(mp_obj_t self_in) {
mp_obj_list_it_t *self = self_in; mp_obj_list_it_t *self = self_in;
if (self->cur < self->list->len) { if (self->cur < self->list->len) {
mp_obj_t o_out = self->list->items[self->cur]; mp_obj_t o_out = self->list->items[self->cur];

View File

@ -150,7 +150,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_
STATIC const mp_obj_tuple_t namedtuple_base_tuple = {{&mp_type_tuple}, 1, {(mp_obj_t)&mp_type_tuple}}; STATIC const mp_obj_tuple_t namedtuple_base_tuple = {{&mp_type_tuple}, 1, {(mp_obj_t)&mp_type_tuple}};
mp_obj_t mp_obj_new_namedtuple_type(qstr name, const char *fields) { STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, const char *fields) {
mp_obj_namedtuple_type_t *o = m_new0(mp_obj_namedtuple_type_t, 1); mp_obj_namedtuple_type_t *o = m_new0(mp_obj_namedtuple_type_t, 1);
o->base.base.type = &mp_type_type; o->base.base.type = &mp_type_type;
o->base.name = name; o->base.name = name;

View File

@ -41,7 +41,7 @@ typedef struct _mp_obj_ellipsis_t {
mp_obj_base_t base; mp_obj_base_t base;
} mp_obj_ellipsis_t; } mp_obj_ellipsis_t;
void ellipsis_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void ellipsis_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
print(env, "Ellipsis"); print(env, "Ellipsis");
} }
@ -67,7 +67,7 @@ typedef struct _mp_obj_slice_t {
mp_obj_t step; mp_obj_t step;
} mp_obj_slice_t; } mp_obj_slice_t;
void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { STATIC void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
mp_obj_slice_t *o = o_in; mp_obj_slice_t *o = o_in;
print(env, "slice("); print(env, "slice(");
mp_obj_print_helper(print, env, o->start, PRINT_REPR); mp_obj_print_helper(print, env, o->start, PRINT_REPR);

View File

@ -95,7 +95,7 @@ STATIC mp_obj_t stringio_close(mp_obj_t self_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(stringio_close_obj, stringio_close); STATIC MP_DEFINE_CONST_FUN_OBJ_1(stringio_close_obj, stringio_close);
mp_obj_t stringio___exit__(mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t stringio___exit__(mp_uint_t n_args, const mp_obj_t *args) {
return stringio_close(args[0]); return stringio_close(args[0]);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stringio___exit___obj, 4, 4, stringio___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stringio___exit___obj, 4, 4, stringio___exit__);

View File

@ -40,7 +40,7 @@
#include "formatfloat.h" #include "formatfloat.h"
#endif #endif
int pfenv_vprintf(const pfenv_t *pfenv, const char *fmt, va_list args) { STATIC int pfenv_vprintf(const pfenv_t *pfenv, const char *fmt, va_list args) {
int chrs = 0; int chrs = 0;
for (;;) { for (;;) {
{ {

View File

@ -30,7 +30,7 @@
#if MICROPY_HELPER_REPL #if MICROPY_HELPER_REPL
bool str_startswith_word(const char *str, const char *head) { STATIC bool str_startswith_word(const char *str, const char *head) {
mp_uint_t i; mp_uint_t i;
for (i = 0; str[i] && head[i]; i++) { for (i = 0; str[i] && head[i]; i++) {
if (str[i] != head[i]) { if (str[i] != head[i]) {

View File

@ -263,7 +263,7 @@ copy:
vstr->buf[vstr->len] = 0; vstr->buf[vstr->len] = 0;
} }
char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) { STATIC char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) {
if (vstr->had_error) { if (vstr->had_error) {
return NULL; return NULL;
} }

View File

@ -49,7 +49,7 @@ typedef struct _mp_obj_fdfile_t {
} mp_obj_fdfile_t; } mp_obj_fdfile_t;
#ifdef MICROPY_CPYTHON_COMPAT #ifdef MICROPY_CPYTHON_COMPAT
void check_fd_is_open(const mp_obj_fdfile_t *o) { STATIC void check_fd_is_open(const mp_obj_fdfile_t *o) {
if (o->fd < 0) { if (o->fd < 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "I/O operation on closed file")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "I/O operation on closed file"));
} }
@ -123,7 +123,7 @@ STATIC mp_obj_t fdfile_close(mp_obj_t self_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_close_obj, fdfile_close); STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_close_obj, fdfile_close);
mp_obj_t fdfile___exit__(mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t fdfile___exit__(mp_uint_t n_args, const mp_obj_t *args) {
return fdfile_close(args[0]); return fdfile_close(args[0]);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___exit__);

View File

@ -40,7 +40,7 @@ extern char *stack_top;
typedef jmp_buf regs_t; typedef jmp_buf regs_t;
void gc_helper_get_regs(regs_t arr) { STATIC void gc_helper_get_regs(regs_t arr) {
setjmp(arr); setjmp(arr);
} }
@ -86,7 +86,7 @@ void gc_helper_get_regs(regs_t arr) {
#ifdef __i386__ #ifdef __i386__
typedef mp_uint_t regs_t[4]; typedef mp_uint_t regs_t[4];
void gc_helper_get_regs(regs_t arr) { STATIC void gc_helper_get_regs(regs_t arr) {
register long ebx asm ("ebx"); register long ebx asm ("ebx");
register long esi asm ("esi"); register long esi asm ("esi");
register long edi asm ("edi"); register long edi asm ("edi");
@ -101,7 +101,7 @@ void gc_helper_get_regs(regs_t arr) {
#if defined(__thumb2__) || defined(__thumb__) || defined(__arm__) #if defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
typedef mp_uint_t regs_t[10]; typedef mp_uint_t regs_t[10];
void gc_helper_get_regs(regs_t arr) { STATIC void gc_helper_get_regs(regs_t arr) {
register long r4 asm ("r4"); register long r4 asm ("r4");
register long r5 asm ("r5"); register long r5 asm ("r5");
register long r6 asm ("r6"); register long r6 asm ("r6");

View File

@ -239,7 +239,7 @@ STATIC int do_str(const char *str) {
return execute_from_lexer(lex, MP_PARSE_FILE_INPUT, false); return execute_from_lexer(lex, MP_PARSE_FILE_INPUT, false);
} }
int usage(char **argv) { STATIC int usage(char **argv) {
printf( printf(
"usage: %s [<opts>] [-X <implopt>] [-c <command>] [<filename>]\n" "usage: %s [<opts>] [-X <implopt>] [-c <command>] [<filename>]\n"
"Options:\n" "Options:\n"
@ -269,7 +269,7 @@ int usage(char **argv) {
} }
// Process options which set interpreter init options // Process options which set interpreter init options
void pre_process_options(int argc, char **argv) { STATIC void pre_process_options(int argc, char **argv) {
for (int a = 1; a < argc; a++) { for (int a = 1; a < argc; a++) {
if (argv[a][0] == '-') { if (argv[a][0] == '-') {
if (strcmp(argv[a], "-X") == 0) { if (strcmp(argv[a], "-X") == 0) {
@ -318,7 +318,7 @@ void pre_process_options(int argc, char **argv) {
} }
} }
void set_sys_argv(char *argv[], int argc, int start_arg) { STATIC void set_sys_argv(char *argv[], int argc, int start_arg) {
for (int i = start_arg; i < argc; i++) { for (int i = start_arg; i < argc; i++) {
mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
} }

View File

@ -300,7 +300,7 @@ STATIC void ffifunc_print(void (*print)(void *env, const char *fmt, ...), void *
print(env, "<ffifunc %p>", self->func); print(env, "<ffifunc %p>", self->func);
} }
mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
mp_obj_ffifunc_t *self = self_in; mp_obj_ffifunc_t *self = self_in;
assert(n_kw == 0); assert(n_kw == 0);
assert(n_args == self->cif.nargs); assert(n_args == self->cif.nargs);
@ -416,12 +416,12 @@ STATIC const mp_obj_type_t opaque_type = {
}; };
*/ */
mp_obj_t mod_ffi_open(mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_ffi_open(mp_uint_t n_args, const mp_obj_t *args) {
return ffimod_make_new((mp_obj_t)&ffimod_type, n_args, 0, args); return ffimod_make_new((mp_obj_t)&ffimod_type, n_args, 0, args);
} }
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open); MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open);
mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) { STATIC mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) {
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr)); return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr));
} }
MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray); MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray);