summaryrefslogtreecommitdiff
path: root/py/compile.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-03-02 22:35:22 +1100
committerDamien George <damien.p.george@gmail.com>2020-04-05 15:02:06 +1000
commitdef76fe4d9bbc2c342594dc05861b24d7165d274 (patch)
treed04ad778e2421de0a85835227ba5bcb08562ec24 /py/compile.c
parent85858e72dfdc3e941c2e620e94de05ad663138b1 (diff)
all: Use MP_ERROR_TEXT for all error messages.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/py/compile.c b/py/compile.c
index 5daeb6e18..4ce69c415 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -449,7 +449,7 @@ STATIC void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, as
}
}
- compile_syntax_error(comp, (mp_parse_node_t)pns, "can't assign to expression");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("can't assign to expression"));
}
// we need to allow for a caller passing in 1 initial node (node_head) followed by an array of nodes (nodes_tail)
@@ -468,7 +468,7 @@ STATIC void c_assign_tuple(compiler_t *comp, mp_parse_node_t node_head, uint num
EMIT_ARG(unpack_ex, num_head + i, num_tail - i - 1);
have_star_index = num_head + i;
} else {
- compile_syntax_error(comp, nodes_tail[i], "multiple *x in assignment");
+ compile_syntax_error(comp, nodes_tail[i], MP_ERROR_TEXT("multiple *x in assignment"));
return;
}
}
@@ -594,7 +594,7 @@ STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_
return;
cannot_assign:
- compile_syntax_error(comp, pn, "can't assign to expression");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("can't assign to expression"));
}
// stuff for lambda and comprehensions and generators:
@@ -699,7 +699,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
// check for non-default parameters given after default parameters (allowed by parser, but not syntactically valid)
if (!comp->have_star && comp->num_default_params != 0) {
- compile_syntax_error(comp, pn, "non-default argument follows default argument");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("non-default argument follows default argument"));
return;
}
@@ -828,7 +828,7 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
}
if (name_len != 2) {
- compile_syntax_error(comp, name_nodes[0], "invalid micropython decorator");
+ compile_syntax_error(comp, name_nodes[0], MP_ERROR_TEXT("invalid micropython decorator"));
return true;
}
@@ -853,17 +853,17 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
#endif
#endif
} else {
- compile_syntax_error(comp, name_nodes[1], "invalid micropython decorator");
+ compile_syntax_error(comp, name_nodes[1], MP_ERROR_TEXT("invalid micropython decorator"));
}
#if MICROPY_DYNAMIC_COMPILER
if (*emit_options == MP_EMIT_OPT_NATIVE_PYTHON || *emit_options == MP_EMIT_OPT_VIPER) {
if (emit_native_table[mp_dynamic_compiler.native_arch] == NULL) {
- compile_syntax_error(comp, name_nodes[1], "invalid arch");
+ compile_syntax_error(comp, name_nodes[1], MP_ERROR_TEXT("invalid arch"));
}
} else if (*emit_options == MP_EMIT_OPT_ASM) {
if (emit_asm_table[mp_dynamic_compiler.native_arch] == NULL) {
- compile_syntax_error(comp, name_nodes[1], "invalid arch");
+ compile_syntax_error(comp, name_nodes[1], MP_ERROR_TEXT("invalid arch"));
}
}
#endif
@@ -1019,7 +1019,7 @@ STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) {
return;
cannot_delete:
- compile_syntax_error(comp, (mp_parse_node_t)pn, "can't delete expression");
+ compile_syntax_error(comp, (mp_parse_node_t)pn, MP_ERROR_TEXT("can't delete expression"));
}
STATIC void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
@@ -1034,7 +1034,7 @@ STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pn
label = comp->continue_label;
}
if (label == INVALID_LABEL) {
- compile_syntax_error(comp, (mp_parse_node_t)pns, "'break'/'continue' outside loop");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'break'/'continue' outside loop"));
}
assert(comp->cur_except_level >= comp->break_continue_except_level);
EMIT_ARG(unwind_jump, label, comp->cur_except_level - comp->break_continue_except_level);
@@ -1043,7 +1043,7 @@ STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pn
STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
#if MICROPY_CPYTHON_COMPAT
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, MP_ERROR_TEXT("'return' outside function"));
return;
}
#endif
@@ -1201,7 +1201,7 @@ STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_STAR)) {
#if MICROPY_CPYTHON_COMPAT
if (comp->scope_cur->kind != SCOPE_MODULE) {
- compile_syntax_error(comp, (mp_parse_node_t)pns, "import * not at module level");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("import * not at module level"));
return;
}
#endif
@@ -1251,7 +1251,7 @@ STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
STATIC void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) {
if (id_info->kind != ID_INFO_KIND_UNDECIDED && id_info->kind != ID_INFO_KIND_GLOBAL_EXPLICIT) {
- compile_syntax_error(comp, pn, "identifier redefined as global");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("identifier redefined as global"));
return;
}
id_info->kind = ID_INFO_KIND_GLOBAL_EXPLICIT;
@@ -1268,10 +1268,10 @@ STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_in
id_info->kind = ID_INFO_KIND_GLOBAL_IMPLICIT;
scope_check_to_close_over(comp->scope_cur, id_info);
if (id_info->kind == ID_INFO_KIND_GLOBAL_IMPLICIT) {
- compile_syntax_error(comp, pn, "no binding for nonlocal found");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("no binding for nonlocal found"));
}
} else if (id_info->kind != ID_INFO_KIND_FREE) {
- compile_syntax_error(comp, pn, "identifier redefined as nonlocal");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("identifier redefined as nonlocal"));
}
}
@@ -1280,7 +1280,7 @@ STATIC void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_
bool is_global = MP_PARSE_NODE_STRUCT_KIND(pns) == PN_global_stmt;
if (!is_global && comp->scope_cur->kind == SCOPE_MODULE) {
- compile_syntax_error(comp, (mp_parse_node_t)pns, "can't declare nonlocal in outer code");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("can't declare nonlocal in outer code"));
return;
}
@@ -1625,7 +1625,7 @@ STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_
if (MP_PARSE_NODE_IS_NULL(pns_except->nodes[0])) {
// this is a catch all exception handler
if (i + 1 != n_except) {
- compile_syntax_error(comp, pn_excepts[i], "default 'except' must be last");
+ compile_syntax_error(comp, pn_excepts[i], MP_ERROR_TEXT("default 'except' must be last"));
compile_decrease_except_level(comp);
return;
}
@@ -2180,7 +2180,7 @@ STATIC void compile_comparison(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, MP_ERROR_TEXT("*x must be assignment target"));
}
STATIC void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) {
@@ -2263,7 +2263,7 @@ STATIC void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *p
}
if (!found) {
compile_syntax_error(comp, (mp_parse_node_t)pns_trail[0],
- "super() can't find self"); // really a TypeError
+ MP_ERROR_TEXT("super() can't find self")); // really a TypeError
return;
}
@@ -2340,14 +2340,14 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
mp_parse_node_struct_t *pns_arg = (mp_parse_node_struct_t *)args[i];
if (MP_PARSE_NODE_STRUCT_KIND(pns_arg) == PN_arglist_star) {
if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
- compile_syntax_error(comp, (mp_parse_node_t)pns_arg, "can't have multiple *x");
+ compile_syntax_error(comp, (mp_parse_node_t)pns_arg, MP_ERROR_TEXT("can't have multiple *x"));
return;
}
star_flags |= MP_EMIT_STAR_FLAG_SINGLE;
star_args_node = pns_arg;
} else if (MP_PARSE_NODE_STRUCT_KIND(pns_arg) == PN_arglist_dbl_star) {
if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
- compile_syntax_error(comp, (mp_parse_node_t)pns_arg, "can't have multiple **x");
+ compile_syntax_error(comp, (mp_parse_node_t)pns_arg, MP_ERROR_TEXT("can't have multiple **x"));
return;
}
star_flags |= MP_EMIT_STAR_FLAG_DOUBLE;
@@ -2355,7 +2355,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
} else if (MP_PARSE_NODE_STRUCT_KIND(pns_arg) == PN_argument) {
if (!MP_PARSE_NODE_IS_STRUCT_KIND(pns_arg->nodes[1], PN_comp_for)) {
if (!MP_PARSE_NODE_IS_ID(pns_arg->nodes[0])) {
- compile_syntax_error(comp, (mp_parse_node_t)pns_arg, "LHS of keyword arg must be an id");
+ compile_syntax_error(comp, (mp_parse_node_t)pns_arg, MP_ERROR_TEXT("LHS of keyword arg must be an id"));
return;
}
EMIT_ARG(load_const_str, MP_PARSE_NODE_LEAF_ARG(pns_arg->nodes[0]));
@@ -2371,11 +2371,11 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
} else {
normal_argument:
if (star_flags) {
- compile_syntax_error(comp, args[i], "non-keyword arg after */**");
+ compile_syntax_error(comp, args[i], MP_ERROR_TEXT("non-keyword arg after */**"));
return;
}
if (n_keyword > 0) {
- compile_syntax_error(comp, args[i], "non-keyword arg after keyword arg");
+ compile_syntax_error(comp, args[i], MP_ERROR_TEXT("non-keyword arg after keyword arg"));
return;
}
compile_node(comp, args[i]);
@@ -2553,9 +2553,9 @@ STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *
if (is_dict) {
if (!is_key_value) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
- compile_syntax_error(comp, (mp_parse_node_t)pns, "invalid syntax");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("invalid syntax"));
#else
- compile_syntax_error(comp, (mp_parse_node_t)pns, "expecting key:value for dict");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("expecting key:value for dict"));
#endif
return;
}
@@ -2563,9 +2563,9 @@ STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *
} else {
if (is_key_value) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
- compile_syntax_error(comp, (mp_parse_node_t)pns, "invalid syntax");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("invalid syntax"));
#else
- compile_syntax_error(comp, (mp_parse_node_t)pns, "expecting just a value for set");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("expecting just a value for set"));
#endif
return;
}
@@ -2694,7 +2694,7 @@ STATIC void compile_classdef(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) {
- compile_syntax_error(comp, (mp_parse_node_t)pns, "'yield' outside function");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield' outside function"));
return;
}
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
@@ -2715,7 +2715,7 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
#if MICROPY_PY_ASYNC_AWAIT
STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) {
- compile_syntax_error(comp, (mp_parse_node_t)pns, "'await' outside function");
+ compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'await' outside function"));
return;
}
compile_atom_expr_normal(comp, pns);
@@ -2819,11 +2819,11 @@ STATIC int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_an
qstr type_name = MP_PARSE_NODE_LEAF_ARG(pn_annotation);
native_type = mp_native_type_from_qstr(type_name);
if (native_type < 0) {
- comp->compile_error = mp_obj_new_exception_msg_varg(&mp_type_ViperTypeError, "unknown type '%q'", type_name);
+ comp->compile_error = mp_obj_new_exception_msg_varg(&mp_type_ViperTypeError, MP_ERROR_TEXT("unknown type '%q'"), type_name);
native_type = 0;
}
} else {
- compile_syntax_error(comp, pn_annotation, "annotation must be an identifier");
+ compile_syntax_error(comp, pn_annotation, MP_ERROR_TEXT("annotation must be an identifier"));
}
return native_type;
}
@@ -2834,7 +2834,7 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn
// check that **kw is last
if ((comp->scope_cur->scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) {
- compile_syntax_error(comp, pn, "invalid syntax");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("invalid syntax"));
return;
}
@@ -2866,7 +2866,7 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn
} else if (MP_PARSE_NODE_STRUCT_KIND(pns) == pn_star) {
if (comp->have_star) {
// more than one star
- compile_syntax_error(comp, pn, "invalid syntax");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("invalid syntax"));
return;
}
comp->have_star = true;
@@ -2900,7 +2900,7 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn
if (param_name != MP_QSTRnull) {
id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, ID_INFO_KIND_UNDECIDED);
if (id_info->kind != ID_INFO_KIND_UNDECIDED) {
- compile_syntax_error(comp, pn, "argument name reused");
+ compile_syntax_error(comp, pn, MP_ERROR_TEXT("argument name reused"));
return;
}
id_info->kind = ID_INFO_KIND_LOCAL;
@@ -3179,7 +3179,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
comp->next_label = 0;
if (scope->kind != SCOPE_FUNCTION) {
- compile_syntax_error(comp, MP_PARSE_NODE_NULL, "inline assembler must be a function");
+ compile_syntax_error(comp, MP_PARSE_NODE_NULL, MP_ERROR_TEXT("inline assembler must be a function"));
return;
}
@@ -3225,11 +3225,11 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
type_sig = MP_NATIVE_TYPE_UINT;
break;
default:
- compile_syntax_error(comp, pn_annotation, "unknown type");
+ compile_syntax_error(comp, pn_annotation, MP_ERROR_TEXT("unknown type"));
return;
}
} else {
- compile_syntax_error(comp, pn_annotation, "return annotation must be an identifier");
+ compile_syntax_error(comp, pn_annotation, MP_ERROR_TEXT("return annotation must be an identifier"));
}
}
@@ -3246,7 +3246,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
} else if (MP_PARSE_NODE_STRUCT_KIND(pns2) != PN_expr_stmt) {
// not an instruction; error
not_an_instruction:
- compile_syntax_error(comp, nodes[i], "expecting an assembler instruction");
+ compile_syntax_error(comp, nodes[i], MP_ERROR_TEXT("expecting an assembler instruction"));
return;
}
@@ -3276,19 +3276,19 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
// emit instructions
if (op == MP_QSTR_label) {
if (!(n_args == 1 && MP_PARSE_NODE_IS_ID(pn_arg[0]))) {
- compile_syntax_error(comp, nodes[i], "'label' requires 1 argument");
+ compile_syntax_error(comp, nodes[i], MP_ERROR_TEXT("'label' requires 1 argument"));
return;
}
uint lab = comp_next_label(comp);
if (pass > MP_PASS_SCOPE) {
if (!EMIT_INLINE_ASM_ARG(label, lab, MP_PARSE_NODE_LEAF_ARG(pn_arg[0]))) {
- compile_syntax_error(comp, nodes[i], "label redefined");
+ compile_syntax_error(comp, nodes[i], MP_ERROR_TEXT("label redefined"));
return;
}
}
} else if (op == MP_QSTR_align) {
if (!(n_args == 1 && MP_PARSE_NODE_IS_SMALL_INT(pn_arg[0]))) {
- compile_syntax_error(comp, nodes[i], "'align' requires 1 argument");
+ compile_syntax_error(comp, nodes[i], MP_ERROR_TEXT("'align' requires 1 argument"));
return;
}
if (pass > MP_PASS_SCOPE) {
@@ -3297,14 +3297,14 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
}
} else if (op == MP_QSTR_data) {
if (!(n_args >= 2 && MP_PARSE_NODE_IS_SMALL_INT(pn_arg[0]))) {
- compile_syntax_error(comp, nodes[i], "'data' requires at least 2 arguments");
+ compile_syntax_error(comp, nodes[i], MP_ERROR_TEXT("'data' requires at least 2 arguments"));
return;
}
if (pass > MP_PASS_SCOPE) {
mp_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]);
for (uint j = 1; j < n_args; j++) {
if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[j])) {
- compile_syntax_error(comp, nodes[i], "'data' requires integer arguments");
+ compile_syntax_error(comp, nodes[i], MP_ERROR_TEXT("'data' requires integer arguments"));
return;
}
mp_asm_base_data((mp_asm_base_t *)comp->emit_inline_asm,