Merge pull request #1104 from tannewt/more_strings

Fixes and translate more strings.
crypto-aes
Dan Halbert 5 years ago committed by GitHub
commit bbc034cd3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -40,6 +40,8 @@
#include "extmod/vfs_fat.h"
#include "lib/timeutils/timeutils.h"
#include "supervisor/shared/translate.h"
#if _MAX_SS == _MIN_SS
#define SECSIZE(fs) (_MIN_SS)
#else
@ -421,7 +423,7 @@ STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) {
FRESULT res = f_setlabel(&self->fatfs, label_str);
if (res != FR_OK) {
if(res == FR_WRITE_PROTECTED) {
mp_raise_msg(&mp_type_OSError, "Read-only filesystem");
mp_raise_msg(&mp_type_OSError, translate("Read-only filesystem"));
}
mp_raise_OSError(fresult_to_errno_table[res]);
}

@ -1,7 +1,9 @@
#include <py/runtime.h>
#include "supervisor/shared/translate.h"
NORETURN void abort_(void);
NORETURN void abort_(void) {
mp_raise_msg(&mp_type_RuntimeError, "abort() called");
mp_raise_msg(&mp_type_RuntimeError, translate("abort() called"));
}

@ -94,7 +94,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
// Clear the parse tree because it has a heap pointer we don't need anymore.
*((uint32_t volatile*) &parse_tree.chunk) = 0;
#else
mp_raise_msg(&mp_type_RuntimeError, "script compilation not supported");
mp_raise_msg(&mp_type_RuntimeError, translate("script compilation not supported"));
#endif
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,7 +1,3 @@
# Set default python interpreters
PYTHON2 ?= $(which python2 || which python2.7)
PYTHON3 ?= python3
# Select the board to build for.
ifeq ($(BOARD),)
$(error You must provide a BOARD parameter)

@ -89,6 +89,7 @@ SECTIONS
*common-hal/*.o*(.literal* .text*)
*shared-bindings/*.o*(.literal* .text*)
*shared-module/*.o*(.literal* .text*)
*supervisor/*.o*(.literal* .text*)
*py/argcheck.o*(.literal* .text*)
*py/asm*.o*(.literal* .text*)

@ -29,6 +29,8 @@
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw) {
// NOTE(tannewt): This prevents this function from being optimized away.
// Without it, functions can crash when reading invalid args.
@ -39,7 +41,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
#else
mp_raise_TypeError("function does not take keyword arguments");
mp_raise_TypeError(translate("function does not take keyword arguments"));
#endif
}
@ -49,7 +51,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
mp_arg_error_terse_mismatch();
#else
mp_raise_TypeError_varg(
"function takes %d positional arguments but %d were given",
translate("function takes %d positional arguments but %d were given"),
n_args_min, n_args);
#endif
}
@ -59,7 +61,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
mp_arg_error_terse_mismatch();
#else
mp_raise_TypeError_varg(
"function missing %d required positional arguments",
translate("function missing %d required positional arguments"),
n_args_min - n_args);
#endif
} else if (n_args > n_args_max) {
@ -67,7 +69,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
mp_arg_error_terse_mismatch();
#else
mp_raise_TypeError_varg(
"function expected at most %d arguments, got %d",
translate("function expected at most %d arguments, got %d"),
n_args_max, n_args);
#endif
}
@ -92,7 +94,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch();
} else {
mp_raise_TypeError_varg(
"'%q' argument required", allowed[i].qst);
translate("'%q' argument required"), allowed[i].qst);
}
}
out_vals[i] = allowed[i].defval;
@ -117,7 +119,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch();
} else {
// TODO better error message
mp_raise_TypeError("extra positional arguments given");
mp_raise_TypeError(translate("extra positional arguments given"));
}
}
if (kws_found < kws->used) {
@ -125,7 +127,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch();
} else {
// TODO better error message
mp_raise_TypeError("extra keyword arguments given");
mp_raise_TypeError(translate("extra keyword arguments given"));
}
}
}
@ -137,11 +139,11 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
}
NORETURN void mp_arg_error_terse_mismatch(void) {
mp_raise_TypeError("argument num/types mismatch");
mp_raise_TypeError(translate("argument num/types mismatch"));
}
#if MICROPY_CPYTHON_COMPAT
NORETURN void mp_arg_error_unimpl_kw(void) {
mp_raise_NotImplementedError("keyword argument(s) not yet implemented - use normal args instead");
mp_raise_NotImplementedError(translate("keyword argument(s) not yet implemented - use normal args instead"));
}
#endif

@ -33,6 +33,8 @@
#include "py/bc0.h"
#include "py/bc.h"
#include "supervisor/shared/translate.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#else // don't print debugging info
@ -80,10 +82,10 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected,
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
(void)f;
mp_raise_TypeError_varg(
"function takes %d positional arguments but %d were given", expected, given);
translate("function takes %d positional arguments but %d were given"), expected, given);
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
mp_raise_TypeError_varg(
"%q() takes %d positional arguments but %d were given",
translate("%q() takes %d positional arguments but %d were given"),
mp_obj_fun_get_name(MP_OBJ_FROM_PTR(f)), expected, given);
#endif
}
@ -192,16 +194,16 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
mp_obj_t wanted_arg_name = kwargs[2 * i];
if(MP_UNLIKELY(!MP_OBJ_IS_QSTR(wanted_arg_name))) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("unexpected keyword argument");
mp_raise_TypeError(translate("unexpected keyword argument"));
#else
mp_raise_TypeError("keywords must be strings");
mp_raise_TypeError(translate("keywords must be strings"));
#endif
}
for (size_t j = 0; j < n_pos_args + n_kwonly_args; j++) {
if (wanted_arg_name == arg_names[j]) {
if (code_state->state[n_state - 1 - j] != MP_OBJ_NULL) {
mp_raise_TypeError_varg(
"function got multiple values for argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name));
translate("function got multiple values for argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name));
}
code_state->state[n_state - 1 - j] = kwargs[2 * i + 1];
goto continue2;
@ -210,10 +212,10 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
// Didn't find name match with positional args
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("unexpected keyword argument");
mp_raise_TypeError(translate("unexpected keyword argument"));
#else
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"unexpected keyword argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name)));
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name)));
#endif
}
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
@ -239,7 +241,7 @@ continue2:;
while (d < &code_state->state[n_state]) {
if (*d++ == MP_OBJ_NULL) {
mp_raise_TypeError_varg(
"function missing required positional argument #%d", &code_state->state[n_state] - d);
translate("function missing required positional argument #%d"), &code_state->state[n_state] - d);
}
}
@ -255,7 +257,7 @@ continue2:;
code_state->state[n_state - 1 - n_pos_args - i] = elem->value;
} else {
mp_raise_TypeError_varg(
"function missing required keyword argument '%q'",
translate("function missing required keyword argument '%q'"),
MP_OBJ_QSTR_VALUE(arg_names[n_pos_args + i]));
}
}
@ -264,7 +266,7 @@ continue2:;
} else {
// no keyword arguments given
if (n_kwonly_args != 0) {
mp_raise_TypeError("function missing keyword-only argument");
mp_raise_TypeError(translate("function missing keyword-only argument"));
}
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) {
*var_pos_kw_args = mp_obj_new_dict(0);

@ -35,6 +35,8 @@
#include "py/objint.h"
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
// Helpers to work with binary-encoded data
#ifndef alignof
@ -107,7 +109,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
}
if (size == 0) {
mp_raise_ValueError("bad typecode");
mp_raise_ValueError(translate("bad typecode"));
}
if (palign != NULL) {

@ -31,6 +31,8 @@
#include "py/runtime.h"
#include "py/builtin.h"
#include "supervisor/shared/translate.h"
#if MICROPY_PY_BUILTINS_COMPILE
typedef struct _mp_obj_code_t {
@ -94,7 +96,7 @@ STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) {
case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break;
case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break;
default:
mp_raise_ValueError("bad compile mode");
mp_raise_ValueError(translate("bad compile mode"));
}
mp_obj_code_t *code = m_new_obj(mp_obj_code_t);

@ -38,6 +38,8 @@
#include "py/builtin.h"
#include "py/frozenmod.h"
#include "supervisor/shared/translate.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
@ -248,7 +250,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
#else
// If we get here then the file was not frozen and we can't compile scripts.
mp_raise_ImportError("script compilation not supported");
mp_raise_ImportError(translate("script compilation not supported"));
#endif
}
@ -333,7 +335,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
// We must have some component left over to import from
if (p == this_name) {
mp_raise_ValueError("cannot perform relative import");
mp_raise_ValueError(translate("cannot perform relative import"));
}
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
@ -417,10 +419,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
#endif
// couldn't find the file, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ImportError("module not found");
mp_raise_ImportError(translate("module not found"));
} else {
mp_raise_msg_varg(&mp_type_ImportError,
"no module named '%q'", mod_name);
translate("no module named '%q'"), mod_name);
}
}
} else {
@ -507,7 +509,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
// Check that it's not a relative import
if (n_args >= 5 && MP_OBJ_SMALL_INT_VALUE(args[4]) != 0) {
mp_raise_NotImplementedError("relative import");
mp_raise_NotImplementedError(translate("relative import"));
}
// Check if module already exists, and return it if it does
@ -529,10 +531,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
// Couldn't find the module, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ImportError, "module not found");
mp_raise_msg(&mp_type_ImportError, translate("module not found"));
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
"no module named '%q'", module_name_qstr));
translate("no module named '%q'"), module_name_qstr));
}
}

@ -36,6 +36,8 @@
#include "py/runtime.h"
#include "py/asmbase.h"
#include "supervisor/shared/translate.h"
#if MICROPY_ENABLE_COMPILER
// TODO need to mangle __attr names
@ -392,7 +394,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, translate("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)
@ -411,7 +413,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], translate("multiple *x in assignment"));
return;
}
}
@ -537,7 +539,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, translate("can't assign to expression"));
}
// stuff for lambda and comprehensions and generators:
@ -637,7 +639,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, translate("non-default argument follows default argument"));
return;
}
@ -766,7 +768,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], translate("invalid micropython decorator"));
return true;
}
@ -784,7 +786,7 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
*emit_options = MP_EMIT_OPT_ASM;
#endif
} else {
compile_syntax_error(comp, name_nodes[1], "invalid micropython decorator");
compile_syntax_error(comp, name_nodes[1], translate("invalid micropython decorator"));
}
return true;
@ -938,7 +940,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, translate("can't delete expression"));
}
STATIC void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
@ -950,10 +952,10 @@ STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pn
const char *error_msg;
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_break_stmt) {
label = comp->break_label;
error_msg = "'break' outside loop";
error_msg = translate("'break' outside loop");
} else {
label = comp->continue_label;
error_msg = "'continue' outside loop";
error_msg = translate("'continue' outside loop");
}
if (label == INVALID_LABEL) {
compile_syntax_error(comp, (mp_parse_node_t)pns, error_msg);
@ -964,7 +966,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 (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, translate("'return' outside function"));
return;
}
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
@ -1164,7 +1166,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, qstr qst, bool added, id_info_t *id_info) {
if (!added && id_info->kind != ID_INFO_KIND_GLOBAL_EXPLICIT) {
compile_syntax_error(comp, pn, "identifier redefined as global");
compile_syntax_error(comp, pn, translate("identifier redefined as global"));
return;
}
id_info->kind = ID_INFO_KIND_GLOBAL_EXPLICIT;
@ -1180,10 +1182,10 @@ STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, qstr
if (added) {
scope_find_local_and_close_over(comp->scope_cur, id_info, qst);
if (id_info->kind == ID_INFO_KIND_GLOBAL_IMPLICIT) {
compile_syntax_error(comp, pn, "no binding for nonlocal found");
compile_syntax_error(comp, pn, translate("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, translate("identifier redefined as nonlocal"));
}
}
@ -1192,7 +1194,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, translate("can't declare nonlocal in outer code"));
return;
}
@ -1537,7 +1539,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], translate("default 'except' must be last"));
compile_decrease_except_level(comp);
return;
}
@ -2090,7 +2092,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, translate("*x must be assignment target"));
}
STATIC void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) {
@ -2188,7 +2190,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
translate("super() can't find self")); // really a TypeError
return;
}
@ -2251,14 +2253,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, translate("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, translate("can't have multiple **x"));
return;
}
star_flags |= MP_EMIT_STAR_FLAG_DOUBLE;
@ -2266,7 +2268,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, translate("LHS of keyword arg must be an id"));
return;
}
EMIT_ARG(load_const_str, MP_PARSE_NODE_LEAF_ARG(pns_arg->nodes[0]));
@ -2282,11 +2284,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], translate("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], translate("non-keyword arg after keyword arg"));
return;
}
compile_node(comp, args[i]);
@ -2458,9 +2460,9 @@ STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
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, translate("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, translate("expecting key:value for dict"));
}
return;
}
@ -2468,9 +2470,9 @@ STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
} 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, translate("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, translate("expecting just a value for set"));
}
return;
}
@ -2595,7 +2597,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, translate("'yield' outside function"));
return;
}
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
@ -2614,7 +2616,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, translate("'await' outside function"));
return;
}
compile_atom_expr_normal(comp, pns);
@ -2707,7 +2709,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) {
// 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, translate("invalid syntax"));
return;
}
@ -2737,7 +2739,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, translate("invalid syntax"));
return;
}
comp->have_star = true;
@ -2769,7 +2771,7 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn
bool added;
id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, &added);
if (!added) {
compile_syntax_error(comp, pn, "name reused for argument");
compile_syntax_error(comp, pn, translate("name reused for argument"));
return;
}
id_info->kind = ID_INFO_KIND_LOCAL;
@ -2822,7 +2824,7 @@ STATIC void compile_scope_func_annotations(compiler_t *comp, mp_parse_node_t pn)
qstr arg_type = MP_PARSE_NODE_LEAF_ARG(pn_annotation);
EMIT_ARG(set_native_type, MP_EMIT_NATIVE_TYPE_ARG, id_info->local_num, arg_type);
} else {
compile_syntax_error(comp, pn_annotation, "parameter annotation must be an identifier");
compile_syntax_error(comp, pn_annotation, translate("parameter annotation must be an identifier"));
}
}
}
@ -2964,7 +2966,7 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
qstr ret_type = MP_PARSE_NODE_LEAF_ARG(pn_annotation);
EMIT_ARG(set_native_type, MP_EMIT_NATIVE_TYPE_RETURN, 0, ret_type);
} else {
compile_syntax_error(comp, pn_annotation, "return annotation must be an identifier");
compile_syntax_error(comp, pn_annotation, translate("return annotation must be an identifier"));
}
}
}
@ -3092,7 +3094,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, translate("inline assembler must be a function"));
return;
}
@ -3129,10 +3131,10 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
case MP_QSTR_bool: type_sig = MP_NATIVE_TYPE_BOOL; break;
case MP_QSTR_int: type_sig = MP_NATIVE_TYPE_INT; break;
case MP_QSTR_uint: type_sig = MP_NATIVE_TYPE_UINT; break;
default: compile_syntax_error(comp, pn_annotation, "unknown type"); return;
default: compile_syntax_error(comp, pn_annotation, translate("unknown type")); return;
}
} else {
compile_syntax_error(comp, pn_annotation, "return annotation must be an identifier");
compile_syntax_error(comp, pn_annotation, translate("return annotation must be an identifier"));
}
}
@ -3149,7 +3151,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], translate("expecting an assembler instruction"));
return;
}
@ -3179,19 +3181,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], translate("'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], translate("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], translate("'align' requires 1 argument"));
return;
}
if (pass > MP_PASS_SCOPE) {
@ -3200,14 +3202,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], translate("'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], translate("'data' requires integer arguments"));
return;
}
mp_asm_base_data((mp_asm_base_t*)comp->emit_inline_asm,

@ -49,6 +49,8 @@
#include "py/emit.h"
#include "py/bc.h"
#include "supervisor/shared/translate.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
@ -737,7 +739,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de
break;
default:
// not handled
mp_raise_NotImplementedError("conversion to object");
mp_raise_NotImplementedError(translate("conversion to object"));
}
}
@ -2121,7 +2123,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u
break;
default:
// this can happen when casting a cast: int(int)
mp_raise_NotImplementedError("casting");
mp_raise_NotImplementedError(translate("casting"));
}
} else {
assert(vtype_fun == VTYPE_PYOBJ);
@ -2196,7 +2198,7 @@ STATIC void emit_native_yield(emit_t *emit, int kind) {
// not supported (for now)
(void)emit;
(void)kind;
mp_raise_NotImplementedError("native yield");
mp_raise_NotImplementedError(translate("native yield"));
}
STATIC void emit_native_start_except_handler(emit_t *emit) {

@ -32,6 +32,8 @@
#include "py/lexer.h"
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
#if MICROPY_ENABLE_COMPILER
#define TAB_SIZE (8)
@ -340,7 +342,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
// 3MB of text; even gzip-compressed and with minimal structure, it'll take
// roughly half a meg of storage. This form of Unicode escape may be added
// later on, but it's definitely not a priority right now. -- CJA 20140607
mp_raise_NotImplementedError("unicode name escapes");
mp_raise_NotImplementedError(translate("unicode name escapes"));
break;
default:
if (c >= '0' && c <= '7') {

@ -54,6 +54,18 @@ codepoint2name[ord('^')] = 'caret'
codepoint2name[ord('|')] = 'pipe'
codepoint2name[ord('~')] = 'tilde'
C_ESCAPES = {
"\a": "\\a",
"\b": "\\b",
"\f": "\\f",
"\n": "\\r",
"\r": "\\r",
"\t": "\\t",
"\v": "\\v",
"\'": "\\'",
"\"": "\\\""
}
# this must match the equivalent function in qstr.c
def compute_hash(qstr, bytes_hash):
hash = 5381
@ -66,7 +78,13 @@ def translate(translation_file, i18ns):
with open(translation_file, "rb") as f:
table = gettext.GNUTranslations(f)
return [(x, table.gettext(x)) for x in i18ns]
translations = []
for original in i18ns:
unescaped = original
for s in C_ESCAPES:
unescaped = unescaped.replace(C_ESCAPES[s], s)
translations.append((original, table.gettext(unescaped)))
return translations
def qstr_escape(qst):
def esc_char(m):
@ -181,6 +199,10 @@ def print_qstr_data(qcfgs, qstrs, i18ns):
total_text_size = 0
for original, translation in i18ns:
# Add in carriage returns to work in terminals
translation = translation.replace("\n", "\r\n")
for s in C_ESCAPES:
translation = translation.replace(s, C_ESCAPES[s])
print("TRANSLATION(\"{}\", \"{}\")".format(original, translation))
total_text_size += len(translation)

@ -75,6 +75,7 @@ def qstr_unescape(qstr):
def process_file(f):
re_line = re.compile(r"#[line]*\s(\d+)\s\"([^\"]+)\"")
re_qstr = re.compile(r'MP_QSTR_[_a-zA-Z0-9]+')
re_translate = re.compile(r'translate\(\"((?:(?=(\\?))\2.)*?)\"\)')
output = []
last_fname = None
lineno = 0
@ -99,8 +100,8 @@ def process_file(f):
name = match.replace('MP_QSTR_', '')
if name not in QSTRING_BLACK_LIST:
output.append('Q(' + qstr_unescape(name) + ')')
for match in re.findall(r'translate\(\"([^\"]+)\"\)', line):
output.append('TRANSLATE("' + match + '")')
for match in re_translate.findall(line):
output.append('TRANSLATE("' + match[0] + '")')
lineno += 1
write_out(last_fname, output)

@ -49,6 +49,9 @@ CP = cp
FIND = find
MKDIR = mkdir
PYTHON = python
# Set default python interpreters
PYTHON2 ?= $(which python2 || which python2.7)
PYTHON3 ?= python3
RM = rm
RSYNC = rsync
SED = sed

@ -79,16 +79,16 @@ $(OBJ): | $(HEADER_BUILD)/qstrdefs.enum.h $(HEADER_BUILD)/mpversion.h
# - else, process all source files ($^) [this covers "make -B" which can set $? to empty]
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h
$(STEPECHO) "GEN $@"
$(Q)grep -lE "(MP_QSTR|i18n)" $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) | xargs $(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(SRC_QSTR_PREPROCESSOR) >$(HEADER_BUILD)/qstr.i.last;
$(Q)grep -lE "(MP_QSTR|translate)" $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) | xargs $(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(SRC_QSTR_PREPROCESSOR) >$(HEADER_BUILD)/qstr.i.last;
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last $(PY_SRC)/makeqstrdefs.py
$(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
$(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
$(Q)touch $@
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split $(PY_SRC)/makeqstrdefs.py
$(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
$(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
# $(sort $(var)) removes duplicates
#

@ -27,6 +27,8 @@
#include "py/builtin.h"
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH
#include <math.h>
@ -36,7 +38,7 @@
#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846)
STATIC NORETURN void math_error(void) {
mp_raise_ValueError("math domain error");
mp_raise_ValueError(translate("math domain error"));
}
STATIC mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) {
@ -191,7 +193,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
#pragma GCC diagnostic ignored "-Wfloat-equal"
} else if (base == (mp_float_t)1.0) {
#pragma GCC diagnostic pop
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero"));
}
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
}

@ -32,6 +32,8 @@
#include "py/gc.h"
#include "py/mphal.h"
#include "supervisor/shared/translate.h"
// Various builtins specific to MicroPython runtime,
// living in micropython module
@ -150,7 +152,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_micropython_kbd_intr_obj, mp_micropython_kbd
#if MICROPY_ENABLE_SCHEDULER
STATIC mp_obj_t mp_micropython_schedule(mp_obj_t function, mp_obj_t arg) {
if (!mp_sched_schedule(function, arg)) {
mp_raise_msg(&mp_type_RuntimeError, "schedule stack full");
mp_raise_msg(&mp_type_RuntimeError, translate("schedule stack full"));
}
return mp_const_none;
}

@ -30,6 +30,8 @@
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "supervisor/shared/translate.h"
#if MICROPY_PY_THREAD
#include "py/mpthread.h"
@ -235,7 +237,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
} else {
// positional and keyword arguments
if (mp_obj_get_type(args[2]) != &mp_type_dict) {
mp_raise_TypeError("expecting a dict for keyword args");
mp_raise_TypeError(translate("expecting a dict for keyword args"));
}
mp_map_t *map = &((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[2]))->map;
th_args = m_new_obj_var(thread_entry_args_t, mp_obj_t, pos_args_len + 2 * map->used);

@ -30,6 +30,8 @@
#include "py/obj.h"
#include "py/mperrno.h"
#include "supervisor/shared/translate.h"
// This list can be defined per port in mpconfigport.h to tailor it to a
// specific port's needs. If it's not defined then we provide a default.
#ifndef MICROPY_PY_UERRNO_LIST
@ -99,18 +101,18 @@ const mp_obj_module_t mp_module_uerrno = {
.globals = (mp_obj_dict_t*)&mp_module_uerrno_globals,
};
qstr mp_errno_to_str(mp_obj_t errno_val) {
const char* mp_errno_to_str(mp_obj_t errno_val) {
// For commonly encountered errors, return human readable strings
if (MP_OBJ_IS_SMALL_INT(errno_val)) {
switch (MP_OBJ_SMALL_INT_VALUE(errno_val)) {
case EPERM: return MP_QSTR_Permission_space_denied;
case ENOENT: return MP_QSTR_No_space_such_space_file_slash_directory;
case EIO: return MP_QSTR_Input_slash_output_space_error;
case EACCES: return MP_QSTR_Permission_space_denied;
case EEXIST: return MP_QSTR_File_space_exists;
case ENODEV: return MP_QSTR_Unsupported_space_operation;
case EINVAL: return MP_QSTR_Invalid_space_argument;
case EROFS: return MP_QSTR_Read_hyphen_only_space_filesystem;
case EPERM: return translate("Permission denied");
case ENOENT: return translate("No such file/directory");
case EIO: return translate("Input/output error");
case EACCES: return translate("Permission denied");
case EEXIST: return translate("File exists");
case ENODEV: return translate("Unsupported operation");
case EINVAL: return translate("Invalid argument");
case EROFS: return translate("Read-only filesystem");
}
}
@ -119,30 +121,30 @@ qstr mp_errno_to_str(mp_obj_t errno_val) {
// We have the errorcode dict so can do a lookup using the hash map
mp_map_elem_t *elem = mp_map_lookup((mp_map_t*)&errorcode_dict.map, errno_val, MP_MAP_LOOKUP);
if (elem == NULL) {
return MP_QSTR_NULL;
return "";
} else {
return MP_OBJ_QSTR_VALUE(elem->value);
return qstr_str(MP_OBJ_QSTR_VALUE(elem->value));
}
#else
// We don't have the errorcode dict so do a simple search in the modules dict
for (size_t i = 0; i < MP_ARRAY_SIZE(mp_module_uerrno_globals_table); ++i) {
if (errno_val == mp_module_uerrno_globals_table[i].value) {
return MP_OBJ_QSTR_VALUE(mp_module_uerrno_globals_table[i].key);
return qstr_str(MP_OBJ_QSTR_VALUE(mp_module_uerrno_globals_table[i].key));
}
}
return MP_QSTR_NULL;
return "";
#endif
}
#else //MICROPY_PY_UERRNO
qstr mp_errno_to_str(mp_obj_t errno_val) {
const char* mp_errno_to_str(mp_obj_t errno_val) {
int v = MP_OBJ_SMALL_INT_VALUE(errno_val);
#define X(e) if (v == e) return (MP_QSTR_ ## e);
#define X(e) if (v == e) return qstr_str(MP_QSTR_ ## e);
MICROPY_PY_UERRNO_LIST
#undef X
return MP_QSTR_;
return "";
}
#endif //MICROPY_PY_UERRNO

@ -140,6 +140,6 @@
#endif
qstr mp_errno_to_str(mp_obj_t errno_val);
const char* mp_errno_to_str(mp_obj_t errno_val);
#endif // MICROPY_INCLUDED_PY_MPERRNO_H

@ -37,6 +37,8 @@
#include "py/stackctrl.h"
#include "py/stream.h" // for mp_obj_print
#include "supervisor/shared/translate.h"
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
if (MP_OBJ_IS_SMALL_INT(o_in)) {
return (mp_obj_type_t*)&mp_type_int;
@ -84,19 +86,19 @@ void mp_obj_print_exception(const mp_print_t *print, mp_obj_t exc) {
mp_obj_exception_get_traceback(exc, &n, &values);
if (n > 0) {
assert(n % 3 == 0);
mp_print_str(print, "Traceback (most recent call last):\n");
mp_print_str(print, translate("Traceback (most recent call last):\n"));
for (int i = n - 3; i >= 0; i -= 3) {
#if MICROPY_ENABLE_SOURCE_LINE
mp_printf(print, " File \"%q\", line %d", values[i], (int)values[i + 1]);
mp_printf(print, translate(" File \"%q\", line %d"), values[i], (int)values[i + 1]);
#else
mp_printf(print, " File \"%q\"", values[i]);
mp_printf(print, translate(" File \"%q\""), values[i]);
#endif
// the block name can be NULL if it's unknown
qstr block = values[i + 2];
if (block == MP_QSTR_NULL) {
mp_print_str(print, "\n");
} else {
mp_printf(print, ", in %q\n", block);
mp_printf(print, translate(", in %q\n"), block);
}
}
}
@ -236,10 +238,10 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
return mp_obj_int_get_checked(arg);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to int");
mp_raise_TypeError(translate("can't convert to int"));
} else {
mp_raise_TypeError_varg(
"can't convert %s to int", mp_obj_get_type_str(arg));
translate("can't convert %s to int"), mp_obj_get_type_str(arg));
}
}
}
@ -299,10 +301,10 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
if (!mp_obj_get_float_maybe(arg, &val)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to float");
mp_raise_TypeError(translate("can't convert to float"));
} else {
mp_raise_TypeError_varg(
"can't convert %s to float", mp_obj_get_type_str(arg));
translate("can't convert %s to float"), mp_obj_get_type_str(arg));
}
}
@ -332,10 +334,10 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
mp_obj_complex_get(arg, real, imag);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to complex");
mp_raise_TypeError(translate("can't convert to complex"));
} else {
mp_raise_TypeError_varg(
"can't convert %s to complex", mp_obj_get_type_str(arg));
translate("can't convert %s to complex"), mp_obj_get_type_str(arg));
}
}
}
@ -350,10 +352,10 @@ void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
mp_obj_list_get(o, len, items);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("expected tuple/list");
mp_raise_TypeError(translate("expected tuple/list"));
} else {
mp_raise_TypeError_varg(
"object '%s' is not a tuple or list", mp_obj_get_type_str(o));
translate("object '%s' is not a tuple or list"), mp_obj_get_type_str(o));
}
}
}
@ -364,9 +366,9 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
mp_obj_get_array(o, &seq_len, items);
if (seq_len != len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ValueError("tuple/list has wrong length");
mp_raise_ValueError(translate("tuple/list has wrong length"));
} else {
mp_raise_ValueError_varg("requested length %d but object has length %d",
mp_raise_ValueError_varg(translate("requested length %d but object has length %d"),
(int)len, (int)seq_len);
}
}
@ -379,10 +381,10 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("indices must be integers");
mp_raise_TypeError(translate("indices must be integers"));
} else {
mp_raise_TypeError_varg(
"%q indices must be integers, not %s",
translate("%q indices must be integers, not %s"),
type->name, mp_obj_get_type_str(index));
}
}
@ -399,10 +401,10 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
} else {
if (i < 0 || (mp_uint_t)i >= len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_IndexError("index out of range");
mp_raise_IndexError(translate("index out of range"));
} else {
mp_raise_msg_varg(&mp_type_IndexError,
"%q index out of range", type->name);
translate("%q index out of range"), type->name);
}
}
}
@ -434,10 +436,10 @@ mp_obj_t mp_obj_len(mp_obj_t o_in) {
mp_obj_t len = mp_obj_len_maybe(o_in);
if (len == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object has no len");
mp_raise_TypeError(translate("object has no len"));
} else {
mp_raise_TypeError_varg(
"object of type '%s' has no len()", mp_obj_get_type_str(o_in));
translate("object of type '%s' has no len()"), mp_obj_get_type_str(o_in));
}
<