py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off. To address issue #420.
This commit is contained in:
parent
2a037408af
commit
ea13f407a3
16
py/builtin.c
16
py/builtin.c
@ -141,7 +141,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
||||
byte str[1] = {ord};
|
||||
return mp_obj_new_str(str, 1, true);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
|
||||
args[1] = MP_OBJ_NEW_SMALL_INT(i1 % i2);
|
||||
return mp_obj_new_tuple(2, args);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter);
|
||||
STATIC mp_obj_t mp_builtin_len(mp_obj_t o_in) {
|
||||
mp_obj_t len = mp_obj_len_maybe(o_in);
|
||||
if (len == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
|
||||
} else {
|
||||
return len;
|
||||
}
|
||||
@ -236,7 +236,7 @@ STATIC mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
if (max_obj == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "max() arg is an empty sequence"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "max() arg is an empty sequence"));
|
||||
}
|
||||
return max_obj;
|
||||
} else {
|
||||
@ -265,7 +265,7 @@ STATIC mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
if (min_obj == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "min() arg is an empty sequence"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "min() arg is an empty sequence"));
|
||||
}
|
||||
return min_obj;
|
||||
} else {
|
||||
@ -285,7 +285,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_min_obj, 1, mp_builtin_min);
|
||||
STATIC mp_obj_t mp_builtin_next(mp_obj_t o) {
|
||||
mp_obj_t ret = mp_iternext_allow_raise(o);
|
||||
if (ret == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception(&mp_type_StopIteration));
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_StopIteration));
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
@ -301,7 +301,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
|
||||
// TODO unicode
|
||||
return mp_obj_new_int(((const byte*)str)[0]);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "ord() expected a character, but string of length %d found", len));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "ord() expected a character, but string of length %d found", len));
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum);
|
||||
STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
assert(n_args >= 1);
|
||||
if (n_args > 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
"must use keyword argument for key function"));
|
||||
}
|
||||
mp_obj_t self = mp_type_list.make_new((mp_obj_t)&mp_type_list, 1, 0, args);
|
||||
|
@ -29,7 +29,7 @@ STATIC mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse
|
||||
|
||||
if (pn == MP_PARSE_NODE_NULL) {
|
||||
// parse error; raise exception
|
||||
nlr_jump(mp_parse_make_exception(parse_error_kind));
|
||||
nlr_raise(mp_parse_make_exception(parse_error_kind));
|
||||
}
|
||||
|
||||
// compile the string
|
||||
|
@ -77,7 +77,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {
|
||||
|
||||
if (lex == NULL) {
|
||||
// we verified the file exists using stat, but lexer could still fail
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ImportError, "ImportError: No module named '%s'", vstr_str(file)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError, "ImportError: No module named '%s'", vstr_str(file)));
|
||||
}
|
||||
|
||||
qstr source_name = mp_lexer_source_name(lex);
|
||||
@ -99,7 +99,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {
|
||||
// parse error; clean up and raise exception
|
||||
mp_locals_set(old_locals);
|
||||
mp_globals_set(old_globals);
|
||||
nlr_jump(mp_parse_make_exception(parse_error_kind));
|
||||
nlr_raise(mp_parse_make_exception(parse_error_kind));
|
||||
}
|
||||
|
||||
// compile the imported script
|
||||
@ -122,7 +122,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {
|
||||
// exception; restore context and re-raise same exception
|
||||
mp_locals_set(old_locals);
|
||||
mp_globals_set(old_globals);
|
||||
nlr_jump(nlr.ret_val);
|
||||
nlr_raise(nlr.ret_val);
|
||||
}
|
||||
mp_locals_set(old_locals);
|
||||
mp_globals_set(old_globals);
|
||||
@ -148,7 +148,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
|
||||
}
|
||||
|
||||
if (level != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_NotImplementedError,
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError,
|
||||
"Relative import is not implemented"));
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
|
||||
|
||||
// fail if we couldn't find the file
|
||||
if (stat == MP_IMPORT_STAT_NO_EXIST) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ImportError, "ImportError: No module named '%s'", qstr_str(mod_name)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError, "ImportError: No module named '%s'", qstr_str(mod_name)));
|
||||
}
|
||||
|
||||
module_obj = mp_module_get(mod_name);
|
||||
@ -211,7 +211,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
|
||||
vstr_add_str(&path, "__init__.py");
|
||||
if (mp_import_stat(vstr_str(&path)) != MP_IMPORT_STAT_FILE) {
|
||||
vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
||||
"Per PEP-420 a dir without __init__.py (%s) is a namespace package; "
|
||||
"namespace packages are not supported", vstr_str(&path)));
|
||||
}
|
||||
|
13
py/nlr.h
13
py/nlr.h
@ -26,3 +26,16 @@ struct _nlr_buf_t {
|
||||
unsigned int nlr_push(nlr_buf_t *);
|
||||
void nlr_pop(void);
|
||||
void nlr_jump(void *val) __attribute__((noreturn));
|
||||
|
||||
// use nlr_raise instead of nlr_jump so that debugging is easier
|
||||
#ifndef DEBUG
|
||||
#define nlr_raise(val) nlr_jump(val)
|
||||
#else
|
||||
#define nlr_raise(val) \
|
||||
do { \
|
||||
void *_val = val; \
|
||||
assert(_val != NULL); \
|
||||
assert(mp_obj_is_exception_instance(_val)); \
|
||||
nlr_jump(_val); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
20
py/obj.c
20
py/obj.c
@ -125,7 +125,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
|
||||
// TODO delegate to __hash__ method if it exists
|
||||
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unhashable type: '%s'", mp_obj_get_type_str(o_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unhashable type: '%s'", mp_obj_get_type_str(o_in)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
|
||||
}
|
||||
}
|
||||
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_NotImplementedError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NotImplementedError,
|
||||
"Equality for '%s' and '%s' types not yet implemented", mp_obj_get_type_str(o1), mp_obj_get_type_str(o2)));
|
||||
return false;
|
||||
}
|
||||
@ -193,7 +193,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) {
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
||||
return mp_obj_int_get_checked(arg);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to int", mp_obj_get_type_str(arg)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to int", mp_obj_get_type_str(arg)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) {
|
||||
return mp_obj_float_get(arg);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to float", mp_obj_get_type_str(arg)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to float", mp_obj_get_type_str(arg)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_complex)) {
|
||||
mp_obj_complex_get(arg, real, imag);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to complex", mp_obj_get_type_str(arg)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to complex", mp_obj_get_type_str(arg)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -262,7 +262,7 @@ void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) {
|
||||
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
|
||||
mp_obj_list_get(o, len, items);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,10 +275,10 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) {
|
||||
mp_obj_list_get(o, &seq_len, items);
|
||||
}
|
||||
if (seq_len != len) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", len, seq_len));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", len, seq_len));
|
||||
}
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index,
|
||||
} else if (MP_OBJ_IS_TYPE(index, &mp_type_bool)) {
|
||||
i = (index == mp_const_true ? 1 : 0);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "%s indices must be integers, not %s", qstr_str(type->name), mp_obj_get_type_str(index)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "%s indices must be integers, not %s", qstr_str(type->name), mp_obj_get_type_str(index)));
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
@ -304,7 +304,7 @@ uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index,
|
||||
}
|
||||
} else {
|
||||
if (i < 0 || i >= len) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "%s index out of range", qstr_str(type->name)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "%s index out of range", qstr_str(type->name)));
|
||||
}
|
||||
}
|
||||
return i;
|
||||
|
@ -76,7 +76,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
|
||||
|
||||
STATIC mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
if (n_args < 1 || n_args > 2) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unexpected # of arguments, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unexpected # of arguments, %d given", n_args));
|
||||
}
|
||||
// TODO check args
|
||||
uint l;
|
||||
|
@ -28,7 +28,7 @@ STATIC mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
|
||||
switch (n_args) {
|
||||
case 0: return mp_const_false;
|
||||
case 1: if (mp_obj_is_true(args[0])) { return mp_const_true; } else { return mp_const_false; }
|
||||
default: nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "bool takes at most 1 argument, %d given", n_args));
|
||||
default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "bool takes at most 1 argument, %d given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ STATIC mp_obj_t complex_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "complex takes at most 2 arguments, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "complex takes at most 2 arguments, %d given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
|
10
py/objdict.c
10
py/objdict.c
@ -43,7 +43,7 @@ STATIC mp_obj_t dict_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
|
||||
assert(false);
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "dict takes at most 1 argument"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "dict takes at most 1 argument"));
|
||||
}
|
||||
|
||||
// add to the new dict any keyword args
|
||||
@ -71,7 +71,7 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
// dict load
|
||||
mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
|
||||
if (elem == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
|
||||
} else {
|
||||
return elem->value;
|
||||
}
|
||||
@ -199,7 +199,7 @@ STATIC mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, mp
|
||||
if (elem == NULL || elem->value == NULL) {
|
||||
if (deflt == NULL) {
|
||||
if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
|
||||
} else {
|
||||
value = mp_const_none;
|
||||
}
|
||||
@ -258,7 +258,7 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
|
||||
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict));
|
||||
mp_obj_dict_t *self = self_in;
|
||||
if (self->map.used == 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "popitem(): dictionary is empty"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "popitem(): dictionary is empty"));
|
||||
}
|
||||
mp_obj_dict_it_t *iter = mp_obj_new_dict_iterator(self, 0);
|
||||
|
||||
@ -287,7 +287,7 @@ STATIC mp_obj_t dict_update(mp_obj_t self_in, mp_obj_t iterable) {
|
||||
if (key == MP_OBJ_NULL
|
||||
|| value == MP_OBJ_NULL
|
||||
|| stop != MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(
|
||||
nlr_raise(mp_obj_new_exception_msg(
|
||||
&mp_type_ValueError,
|
||||
"dictionary update sequence has the wrong length"));
|
||||
} else {
|
||||
|
@ -48,7 +48,7 @@ STATIC mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_
|
||||
mp_obj_type_t *type = type_in;
|
||||
|
||||
if (n_kw != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "%s does not take keyword arguments", mp_obj_get_type_str(type_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "%s does not take keyword arguments", mp_obj_get_type_str(type_in)));
|
||||
}
|
||||
|
||||
mp_obj_exception_t *o = m_new_obj_var(mp_obj_exception_t, mp_obj_t, n_args);
|
||||
|
@ -16,7 +16,7 @@ typedef struct _mp_obj_filter_t {
|
||||
|
||||
STATIC mp_obj_t filter_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
if (n_args != 2 || n_kw != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "filter expected 2 arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "filter expected 2 arguments"));
|
||||
}
|
||||
assert(n_args == 2);
|
||||
mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t);
|
||||
|
@ -57,7 +57,7 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "float takes at most 1 argument, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "float takes at most 1 argument, %d given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) {
|
||||
lhs_val /= rhs_val;
|
||||
check_zero_division:
|
||||
if (isinf(lhs_val)){ // check for division by zero
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "float division by zero"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "float division by zero"));
|
||||
}
|
||||
break;
|
||||
case MP_BINARY_OP_POWER:
|
||||
|
24
py/objfun.c
24
py/objfun.c
@ -30,23 +30,23 @@ STATIC void check_nargs(mp_obj_fun_native_t *self, int n_args, int n_kw) {
|
||||
|
||||
void mp_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw) {
|
||||
if (n_kw && !is_kw) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
"function does not take keyword arguments"));
|
||||
}
|
||||
|
||||
if (n_args_min == n_args_max) {
|
||||
if (n_args != n_args_min) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"function takes %d positional arguments but %d were given",
|
||||
n_args_min, n_args));
|
||||
}
|
||||
} else {
|
||||
if (n_args < n_args_min) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"<fun name>() missing %d required positional arguments: <list of names of params>",
|
||||
n_args_min - n_args));
|
||||
} else if (n_args > n_args_max) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"<fun name> expected at most %d arguments, got %d",
|
||||
n_args_max, n_args));
|
||||
}
|
||||
@ -207,7 +207,7 @@ bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, co
|
||||
return true;
|
||||
|
||||
arg_error:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
@ -275,7 +275,7 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_o
|
||||
for (uint j = 0; j < self->n_args; j++) {
|
||||
if (arg_name == self->args[j]) {
|
||||
if (flat_args[j] != MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"function got multiple values for argument '%s'", qstr_str(arg_name)));
|
||||
}
|
||||
flat_args[j] = kwargs[2 * i + 1];
|
||||
@ -284,7 +284,7 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_o
|
||||
}
|
||||
// Didn't find name match with positional args
|
||||
if (!self->takes_kw_args) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments"));
|
||||
}
|
||||
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
|
||||
continue2:;
|
||||
@ -306,7 +306,7 @@ continue2:;
|
||||
// Now check that all mandatory args specified
|
||||
while (d >= flat_args) {
|
||||
if (*d-- == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"function missing required positional argument #%d", d - flat_args));
|
||||
}
|
||||
}
|
||||
@ -338,11 +338,11 @@ continue2:;
|
||||
if (vm_return_kind == MP_VM_RETURN_NORMAL) {
|
||||
return result;
|
||||
} else { // MP_VM_RETURN_EXCEPTION
|
||||
nlr_jump(result);
|
||||
nlr_raise(result);
|
||||
}
|
||||
|
||||
arg_error:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
|
||||
}
|
||||
|
||||
const mp_obj_type_t mp_type_fun_bc = {
|
||||
@ -449,10 +449,10 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_
|
||||
mp_obj_fun_asm_t *self = self_in;
|
||||
|
||||
if (n_args != self->n_args) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args));
|
||||
}
|
||||
if (n_kw != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments"));
|
||||
}
|
||||
|
||||
machine_uint_t ret;
|
||||
|
@ -84,7 +84,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
|
||||
}
|
||||
if (self->sp == self->state - 1) {
|
||||
if (send_value != mp_const_none) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator"));
|
||||
}
|
||||
} else {
|
||||
*self->sp = send_value;
|
||||
@ -130,12 +130,12 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
|
||||
if (ret == mp_const_none || ret == MP_OBJ_NULL) {
|
||||
return MP_OBJ_NULL;
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_args(&mp_type_StopIteration, 1, &ret));
|
||||
nlr_raise(mp_obj_new_exception_args(&mp_type_StopIteration, 1, &ret));
|
||||
}
|
||||
|
||||
case MP_VM_RETURN_YIELD:
|
||||
if (throw_value != MP_OBJ_NULL && mp_obj_is_subclass_fast(mp_obj_get_type(throw_value), &mp_type_GeneratorExit)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit"));
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -146,7 +146,7 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
|
||||
if (mp_obj_is_subclass_fast(mp_obj_get_type(ret), &mp_type_StopIteration)) {
|
||||
return MP_OBJ_NULL;
|
||||
} else {
|
||||
nlr_jump(ret);
|
||||
nlr_raise(ret);
|
||||
}
|
||||
|
||||
default:
|
||||
@ -162,7 +162,7 @@ mp_obj_t gen_instance_iternext(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) {
|
||||
mp_obj_t ret = gen_resume_and_raise(self_in, send_value, MP_OBJ_NULL);
|
||||
if (ret == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception(&mp_type_StopIteration));
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_StopIteration));
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
@ -177,7 +177,7 @@ STATIC mp_obj_t gen_instance_throw(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
mp_obj_t ret = gen_resume_and_raise(args[0], mp_const_none, exc);
|
||||
if (ret == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception(&mp_type_StopIteration));
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_StopIteration));
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
@ -189,7 +189,7 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
|
||||
mp_obj_t ret;
|
||||
switch (mp_obj_gen_resume(self_in, mp_const_none, (mp_obj_t)&mp_const_GeneratorExit_obj, &ret)) {
|
||||
case MP_VM_RETURN_YIELD:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit"));
|
||||
|
||||
// Swallow StopIteration & GeneratorExit (== successful close), and re-raise any other
|
||||
case MP_VM_RETURN_EXCEPTION:
|
||||
@ -198,7 +198,7 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
|
||||
mp_obj_is_subclass_fast(mp_obj_get_type(ret), &mp_type_StopIteration)) {
|
||||
return mp_const_none;
|
||||
}
|
||||
nlr_jump(ret);
|
||||
nlr_raise(ret);
|
||||
|
||||
default:
|
||||
// The only choice left is MP_VM_RETURN_NORMAL which is successful close
|
||||
|
@ -30,7 +30,7 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
|
||||
return MP_OBJ_NULL;
|
||||
} else {
|
||||
// re-raise exception
|
||||
nlr_jump(nlr.ret_val);
|
||||
nlr_raise(nlr.ret_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
py/objint.c
10
py/objint.c
@ -49,7 +49,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "int takes at most 2 arguments, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "int takes at most 2 arguments, %d given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,13 +73,13 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
|
||||
// This is called only with strings whose value doesn't fit in SMALL_INT
|
||||
mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OverflowError, "long int not supported in this build"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "long int not supported in this build"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
|
||||
mp_obj_t mp_obj_new_int_from_ll(long long val) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) {
|
||||
if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) {
|
||||
return MP_OBJ_NEW_SMALL_INT(value);
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ mp_obj_t mp_obj_new_int(machine_int_t value) {
|
||||
if (MP_OBJ_FITS_SMALL_INT(value)) {
|
||||
return MP_OBJ_NEW_SMALL_INT(value);
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
|
||||
// TODO: this doesn't handle Python hacked 0o octal syntax
|
||||
v = strtoll(s, &end, 0);
|
||||
if (*end != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number"));
|
||||
}
|
||||
mp_obj_int_t *o = m_new_obj(mp_obj_int_t);
|
||||
o->base.type = &mp_type_int;
|
||||
|
@ -148,7 +148,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
// TODO check conversion overflow
|
||||
machine_int_t irhs = mpz_as_int(zrhs);
|
||||
if (irhs < 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
||||
}
|
||||
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
|
||||
mpz_shl_inpl(&res->mpz, zlhs, irhs);
|
||||
@ -222,7 +222,7 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *str) {
|
||||
len -= skip;
|
||||
uint n = mpz_set_from_str(&o->mpz, str, len, false, base);
|
||||
if (n != len) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number"));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
@ -246,7 +246,7 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
|
||||
return value;
|
||||
} else {
|
||||
// overflow
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OverflowError, "overflow converting long int to machine word"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "overflow converting long int to machine word"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ STATIC mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "list takes at most 1 argument, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "list takes at most 1 argument, %d given", n_args));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -184,7 +184,7 @@ STATIC mp_obj_t list_pop(uint n_args, const mp_obj_t *args) {
|
||||
assert(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
|
||||
mp_obj_list_t *self = args[0];
|
||||
if (self->len == 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_IndexError, "pop from empty list"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "pop from empty list"));
|
||||
}
|
||||
uint index = mp_get_index(self->base.type, self->len, n_args == 1 ? mp_obj_new_int(-1) : args[1], false);
|
||||
mp_obj_t ret = self->items[index];
|
||||
@ -224,7 +224,7 @@ mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
assert(n_args >= 1);
|
||||
assert(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
|
||||
if (n_args > 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
"list.sort takes no positional arguments"));
|
||||
}
|
||||
mp_obj_list_t *self = args[0];
|
||||
|
@ -17,7 +17,7 @@ typedef struct _mp_obj_map_t {
|
||||
|
||||
STATIC mp_obj_t map_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
if (n_args < 2 || n_kw != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "map must have at least 2 arguments and no keyword arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "map must have at least 2 arguments and no keyword arguments"));
|
||||
}
|
||||
assert(n_args >= 2);
|
||||
mp_obj_map_t *o = m_new_obj_var(mp_obj_map_t, mp_obj_t, n_args - 1);
|
||||
|
@ -102,7 +102,7 @@ STATIC void namedtuple_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
}
|
||||
|
||||
STATIC bool namedtuple_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_AttributeError, "can't set attribute"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError, "can't set attribute"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
@ -110,7 +110,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
|
||||
uint num_fields = namedtuple_count_fields(type->fields);
|
||||
if (n_args != num_fields) {
|
||||
// Counts include implicit "self"
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"__new__() takes %d positional arguments but %d were given",
|
||||
num_fields + 1, n_args + 1));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ const mp_obj_type_t mp_type_object;
|
||||
|
||||
STATIC mp_obj_t object_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
if (n_args != 0 || n_kw != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "object takes no arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "object takes no arguments"));
|
||||
}
|
||||
|
||||
mp_obj_object_t *o = m_new_obj(mp_obj_object_t);
|
||||
|
@ -65,7 +65,7 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "set takes at most 1 argument, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "set takes at most 1 argument, %d given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) {
|
||||
mp_obj_set_t *self = self_in;
|
||||
mp_obj_t obj = mp_set_remove_first(&self->set);
|
||||
if (obj == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "pop from an empty set"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "pop from an empty set"));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@ -319,7 +319,7 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) {
|
||||
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set));
|
||||
mp_obj_set_t *self = self_in;
|
||||
if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception(&mp_type_KeyError));
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
64
py/objstr.c
64
py/objstr.c
@ -102,7 +102,7 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
|
||||
{
|
||||
// TODO: validate 2nd/3rd args
|
||||
if (!MP_OBJ_IS_TYPE(args[0], &mp_type_bytes)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "bytes expected"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "bytes expected"));
|
||||
}
|
||||
GET_STR_DATA_LEN(args[0], str_data, str_len);
|
||||
GET_STR_HASH(args[0], str_hash);
|
||||
@ -113,7 +113,7 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "str takes at most 3 arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "str takes at most 3 arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
|
||||
return mp_obj_str_builder_end(o);
|
||||
|
||||
wrong_args:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "wrong number of arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "wrong number of arguments"));
|
||||
}
|
||||
|
||||
// like strstr but with specified length and allows \0 bytes
|
||||
@ -237,7 +237,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
} else {
|
||||
// Message doesn't match CPython, but we don't have so much bytes as they
|
||||
// to spend them on verbose wording
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "index must be int"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "index must be int"));
|
||||
}
|
||||
|
||||
case MP_BINARY_OP_ADD:
|
||||
@ -361,7 +361,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
|
||||
return mp_obj_str_builder_end(joined_str);
|
||||
|
||||
bad_arg:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "?str.join expecting a list of str's"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "?str.join expecting a list of str's"));
|
||||
}
|
||||
|
||||
#define is_ws(c) ((c) == ' ' || (c) == '\t')
|
||||
@ -554,7 +554,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
vstr_add_char(vstr, '}');
|
||||
continue;
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Single '}' encountered in format string"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Single '}' encountered in format string"));
|
||||
}
|
||||
if (*str != '{') {
|
||||
vstr_add_char(vstr, *str);
|
||||
@ -588,7 +588,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
if (str < top && (*str == 'r' || *str == 's')) {
|
||||
conversion = *str++;
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "end of format while looking for conversion specifier"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "end of format while looking for conversion specifier"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -608,24 +608,24 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
if (str >= top) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "unmatched '{' in format"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "unmatched '{' in format"));
|
||||
}
|
||||
if (*str != '}') {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "expected ':' after format specifier"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "expected ':' after format specifier"));
|
||||
}
|
||||
|
||||
mp_obj_t arg = mp_const_none;
|
||||
|
||||
if (field_name) {
|
||||
if (arg_i > 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot switch from automatic field numbering to manual field specification"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot switch from automatic field numbering to manual field specification"));
|
||||
}
|
||||
int index;
|
||||
if (str_to_int(vstr_str(field_name), &index) != vstr_len(field_name) - 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "attributes not supported yet"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "attributes not supported yet"));
|
||||
}
|
||||
if (index >= n_args - 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range"));
|
||||
}
|
||||
arg = args[index + 1];
|
||||
arg_i = -1;
|
||||
@ -633,10 +633,10 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
field_name = NULL;
|
||||
} else {
|
||||
if (arg_i < 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot switch from manual field specification to automatic field numbering"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot switch from manual field specification to automatic field numbering"));
|
||||
}
|
||||
if (arg_i >= n_args - 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range"));
|
||||
}
|
||||
arg = args[arg_i + 1];
|
||||
arg_i++;
|
||||
@ -651,7 +651,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
} else if (conversion == 'r') {
|
||||
print_kind = PRINT_REPR;
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Unknown conversion specifier %c", conversion));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Unknown conversion specifier %c", conversion));
|
||||
}
|
||||
vstr_t *arg_vstr = vstr_new();
|
||||
mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, arg_vstr, arg, print_kind);
|
||||
@ -718,7 +718,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
type = *s++;
|
||||
}
|
||||
if (*s) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "Invalid conversion specification"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "Invalid conversion specification"));
|
||||
}
|
||||
vstr_free(format_spec);
|
||||
format_spec = NULL;
|
||||
@ -736,10 +736,10 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
if (sign) {
|
||||
if (type == 's') {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Sign not allowed in string format specifier"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sign not allowed in string format specifier"));
|
||||
}
|
||||
if (type == 'c') {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Sign not allowed with integer format specifier 'c'"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sign not allowed with integer format specifier 'c'"));
|
||||
}
|
||||
} else {
|
||||
sign = '-';
|
||||
@ -794,7 +794,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
break;
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Unknown format code '%c' for object of type '%s'", type, mp_obj_get_type_str(arg)));
|
||||
}
|
||||
}
|
||||
@ -856,7 +856,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
#endif
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Unknown format code '%c' for object of type 'float'",
|
||||
type, mp_obj_get_type_str(arg)));
|
||||
}
|
||||
@ -864,7 +864,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
// arg doesn't look like a number
|
||||
|
||||
if (align == '=') {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "'=' alignment not allowed in string format specifier"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "'=' alignment not allowed in string format specifier"));
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@ -887,7 +887,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Unknown format code '%c' for object of type 'str'",
|
||||
type, mp_obj_get_type_str(arg)));
|
||||
}
|
||||
@ -923,7 +923,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
|
||||
continue;
|
||||
}
|
||||
if (arg_i >= n_args) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "not enough arguments for format string"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "not enough arguments for format string"));
|
||||
}
|
||||
int flags = 0;
|
||||
char fill = ' ';
|
||||
@ -967,7 +967,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
|
||||
}
|
||||
|
||||
if (str >= top) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "incomplete format"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "incomplete format"));
|
||||
}
|
||||
mp_obj_t arg = args[arg_i];
|
||||
switch (*str) {
|
||||
@ -976,7 +976,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
|
||||
uint len;
|
||||
const char *s = mp_obj_str_get_data(arg, &len);
|
||||
if (len != 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "%c requires int or char"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "%c requires int or char"));
|
||||
break;
|
||||
}
|
||||
pfenv_print_strn(&pfenv_vstr, s, 1, flags, ' ', width);
|
||||
@ -990,11 +990,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
|
||||
#if MICROPY_ENABLE_FLOAT
|
||||
// This is what CPython reports, so we report the same.
|
||||
if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "integer argument expected, got float"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "integer argument expected, got float"));
|
||||
|
||||
}
|
||||
#endif
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "an integer is required"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "an integer is required"));
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
@ -1054,7 +1054,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
|
||||
break;
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"unsupported format character '%c' (0x%x) at index %d",
|
||||
*str, *str, str - start_str));
|
||||
}
|
||||
@ -1062,7 +1062,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
|
||||
}
|
||||
|
||||
if (arg_i != n_args) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "not all arguments converted during string formatting"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "not all arguments converted during string formatting"));
|
||||
}
|
||||
|
||||
mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
|
||||
@ -1191,7 +1191,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, machine_int_t direction) {
|
||||
assert(MP_OBJ_IS_STR(self_in));
|
||||
if (!MP_OBJ_IS_STR(arg)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"Can't convert '%s' object to str implicitly", mp_obj_get_type_str(arg)));
|
||||
}
|
||||
|
||||
@ -1199,7 +1199,7 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, machine_int_t di
|
||||
GET_STR_DATA_LEN(arg, sep, sep_len);
|
||||
|
||||
if (sep_len == 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "empty separator"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "empty separator"));
|
||||
}
|
||||
|
||||
mp_obj_t result[] = {MP_OBJ_NEW_QSTR(MP_QSTR_), MP_OBJ_NEW_QSTR(MP_QSTR_), MP_OBJ_NEW_QSTR(MP_QSTR_)};
|
||||
@ -1367,7 +1367,7 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
|
||||
|
||||
void bad_implicit_conversion(mp_obj_t self_in) __attribute__((noreturn));
|
||||
void bad_implicit_conversion(mp_obj_t self_in) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Can't convert '%s' object to str implicitly", mp_obj_get_type_str(self_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Can't convert '%s' object to str implicitly", mp_obj_get_type_str(self_in)));
|
||||
}
|
||||
|
||||
uint mp_obj_str_get_hash(mp_obj_t self_in) {
|
||||
|
@ -67,7 +67,7 @@ mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
|
||||
}
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "tuple takes at most 1 argument, %d given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "tuple takes at most 1 argument, %d given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
|
16
py/objtype.c
16
py/objtype.c
@ -107,13 +107,13 @@ STATIC mp_obj_t class_make_new(mp_obj_t self_in, uint n_args, uint n_kw, const m
|
||||
m_del(mp_obj_t, args2, 1 + n_args + 2 * n_kw);
|
||||
}
|
||||
if (init_ret != mp_const_none) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)));
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO
|
||||
if (n_args != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes 0 positional arguments but %d were given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes 0 positional arguments but %d were given", n_args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,7 +298,7 @@ STATIC mp_obj_t type_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
|
||||
return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]);
|
||||
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "type takes 1 or 3 arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "type takes 1 or 3 arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj
|
||||
mp_obj_type_t *self = self_in;
|
||||
|
||||
if (self->make_new == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "cannot create '%s' instances", qstr_str(self->name)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "cannot create '%s' instances", qstr_str(self->name)));
|
||||
}
|
||||
|
||||
// make new instance
|
||||
@ -428,7 +428,7 @@ STATIC mp_obj_t super_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
|
||||
if (n_args != 2 || n_kw != 0) {
|
||||
// 0 arguments are turned into 2 in the compiler
|
||||
// 1 argument is not yet implemented
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "super() requires 2 arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "super() requires 2 arguments"));
|
||||
}
|
||||
return mp_obj_new_super(args[0], args[1]);
|
||||
}
|
||||
@ -528,7 +528,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
} else if (MP_OBJ_IS_TYPE(classinfo, &mp_type_tuple)) {
|
||||
mp_obj_tuple_get(classinfo, &len, &items);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class or a tuple of classes"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class or a tuple of classes"));
|
||||
}
|
||||
|
||||
for (uint i = 0; i < len; i++) {
|
||||
@ -541,7 +541,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
|
||||
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class"));
|
||||
}
|
||||
return mp_obj_is_subclass(object, classinfo);
|
||||
}
|
||||
@ -561,7 +561,7 @@ STATIC mp_obj_t static_class_method_make_new(mp_obj_t self_in, uint n_args, uint
|
||||
assert(self_in == &mp_type_staticmethod || self_in == &mp_type_classmethod);
|
||||
|
||||
if (n_args != 1 || n_kw != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes 1 positional argument but %d were given", n_args));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes 1 positional argument but %d were given", n_args));
|
||||
}
|
||||
|
||||
mp_obj_static_class_method_t *o = m_new_obj(mp_obj_static_class_method_t);
|
||||
|
@ -19,7 +19,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str, uint len, int base) {
|
||||
|
||||
// check radix base
|
||||
if ((base != 0 && base < 2) || base > 36) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "ValueError: int() arg 2 must be >=2 and <= 36"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "ValueError: int() arg 2 must be >=2 and <= 36"));
|
||||
}
|
||||
|
||||
// skip leading space
|
||||
@ -93,11 +93,11 @@ mp_obj_t mp_parse_num_integer(const char *restrict str, uint len, int base) {
|
||||
return MP_OBJ_NEW_SMALL_INT(int_val);
|
||||
|
||||
value_error:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid literal for int() with base %d: '%s'", base, str));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid literal for int() with base %d: '%s'", base, str));
|
||||
|
||||
overflow:
|
||||
// TODO reparse using bignum
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "overflow parsing integer"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "overflow parsing integer"));
|
||||
}
|
||||
|
||||
#define PARSE_DEC_IN_INTG (1)
|
||||
@ -208,7 +208,7 @@ mp_obj_t mp_parse_num_decimal(const char *str, uint len, bool allow_imag, bool f
|
||||
|
||||
// check we reached the end of the string
|
||||
if (str != top) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number"));
|
||||
}
|
||||
|
||||
// return the object
|
||||
@ -221,6 +221,6 @@ mp_obj_t mp_parse_num_decimal(const char *str, uint len, bool allow_imag, bool f
|
||||
}
|
||||
|
||||
#else
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_SyntaxError, "decimal numbers not supported"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_SyntaxError, "decimal numbers not supported"));
|
||||
#endif
|
||||
}
|
||||
|
44
py/runtime.c
44
py/runtime.c
@ -124,7 +124,7 @@ mp_obj_t mp_load_global(qstr qstr) {
|
||||
if (o != MP_OBJ_NULL) {
|
||||
return o;
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_NameError, "name '%s' is not defined", qstr_str(qstr)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NameError, "name '%s' is not defined", qstr_str(qstr)));
|
||||
}
|
||||
}
|
||||
return elem->value;
|
||||
@ -191,7 +191,7 @@ mp_obj_t mp_unary_op(int op, mp_obj_t arg) {
|
||||
}
|
||||
}
|
||||
// TODO specify in error message what the operator is
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "bad operand type for unary operator: '%s'", mp_obj_get_type_str(arg)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "bad operand type for unary operator: '%s'", mp_obj_get_type_str(arg)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
case MP_BINARY_OP_INPLACE_LSHIFT: {
|
||||
if (rhs_val < 0) {
|
||||
// negative shift not allowed
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
||||
} else if (rhs_val >= BITS_PER_WORD || lhs_val > (MP_SMALL_INT_MAX >> rhs_val) || lhs_val < (MP_SMALL_INT_MIN >> rhs_val)) {
|
||||
// left-shift will overflow, so use higher precision integer
|
||||
lhs = mp_obj_new_int_from_ll(lhs_val);
|
||||
@ -286,7 +286,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
case MP_BINARY_OP_INPLACE_RSHIFT:
|
||||
if (rhs_val < 0) {
|
||||
// negative shift not allowed
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
||||
} else {
|
||||
// standard precision is enough for right-shift
|
||||
lhs_val >>= rhs_val;
|
||||
@ -354,7 +354,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
lhs = mp_obj_new_float(lhs_val);
|
||||
goto generic_binary_op;
|
||||
#else
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative power with no float support"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative power with no float support"));
|
||||
#endif
|
||||
} else {
|
||||
machine_int_t ans = 1;
|
||||
@ -430,7 +430,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
return mp_const_false;
|
||||
}
|
||||
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(
|
||||
&mp_type_TypeError, "'%s' object is not iterable",
|
||||
mp_obj_get_type_str(rhs)));
|
||||
return mp_const_none;
|
||||
@ -450,13 +450,13 @@ generic_binary_op:
|
||||
// TODO implement dispatch for reverse binary ops
|
||||
|
||||
// TODO specify in error message what the operator is
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"unsupported operand types for binary operator: '%s', '%s'",
|
||||
mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs)));
|
||||
return mp_const_none;
|
||||
|
||||
zero_division:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
|
||||
}
|
||||
|
||||
mp_obj_t mp_call_function_0(mp_obj_t fun) {
|
||||
@ -494,7 +494,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp
|
||||
if (type->call != NULL) {
|
||||
return type->call(fun_in, n_args, n_kw, args);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -685,9 +685,9 @@ void mp_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
|
||||
return;
|
||||
|
||||
too_short:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "need more than %d values to unpack", seq_len));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "need more than %d values to unpack", seq_len));
|
||||
too_long:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", num));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", num));
|
||||
}
|
||||
|
||||
mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
|
||||
@ -774,10 +774,10 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
|
||||
// no attribute/method called attr
|
||||
// following CPython, we give a more detailed error message for type objects
|
||||
if (MP_OBJ_IS_TYPE(base, &mp_type_type)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
||||
"type object '%s' has no attribute '%s'", qstr_str(((mp_obj_type_t*)base)->name), qstr_str(attr)));
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -790,7 +790,7 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
|
||||
}
|
||||
|
||||
void mp_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
||||
@ -810,7 +810,7 @@ void mp_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
||||
}
|
||||
// TODO: call base classes here?
|
||||
}
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object does not support item assignment", mp_obj_get_type_str(base)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object does not support item assignment", mp_obj_get_type_str(base)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -825,7 +825,7 @@ void mp_delete_subscr(mp_obj_t base, mp_obj_t index) {
|
||||
// dict delete
|
||||
mp_obj_dict_delete(base, index);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object does not support item deletion", mp_obj_get_type_str(base)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object does not support item deletion", mp_obj_get_type_str(base)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -847,7 +847,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in) {
|
||||
return mp_obj_new_getitem_iter(dest);
|
||||
} else {
|
||||
// object not iterable
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not iterable", mp_obj_get_type_str(o_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not iterable", mp_obj_get_type_str(o_in)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -867,7 +867,7 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
|
||||
// __next__ exists, call it and return its result
|
||||
return mp_call_method_n_kw(0, 0, dest);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -893,11 +893,11 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
|
||||
if (mp_obj_is_subclass_fast(mp_obj_get_type(nlr.ret_val), &mp_type_StopIteration)) {
|
||||
return MP_OBJ_NULL;
|
||||
} else {
|
||||
nlr_jump(nlr.ret_val);
|
||||
nlr_raise(nlr.ret_val);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -954,7 +954,7 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th
|
||||
if (dest[0] != MP_OBJ_NULL) {
|
||||
*ret_val = mp_call_method_n_kw(1, 0, &throw_value);
|
||||
// If .throw() method returned, we assume it's value to yield
|
||||
// - any exception would be thrown with nlr_jump().
|
||||
// - any exception would be thrown with nlr_raise().
|
||||
return MP_VM_RETURN_YIELD;
|
||||
}
|
||||
// If there's nowhere to throw exception into, then we assume that object
|
||||
@ -1045,7 +1045,7 @@ void mp_globals_set(mp_map_t *m) {
|
||||
|
||||
void *m_malloc_fail(int num_bytes) {
|
||||
DEBUG_printf("memory allocation failed, allocating %d bytes\n", num_bytes);
|
||||
nlr_jump((mp_obj_t)&mp_const_MemoryError_obj);
|
||||
nlr_raise((mp_obj_t)&mp_const_MemoryError_obj);
|
||||
}
|
||||
|
||||
// these must correspond to the respective enum
|
||||
|
@ -159,7 +159,7 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, uint len, uint n_args, const mp
|
||||
}
|
||||
}
|
||||
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "object not in sequence"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "object not in sequence"));
|
||||
}
|
||||
|
||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, uint len, mp_obj_t value) {
|
||||
|
20
py/stream.c
20
py/stream.c
@ -16,7 +16,7 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
|
||||
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0];
|
||||
if (o->type->stream_p.read == NULL) {
|
||||
// CPython: io.UnsupportedOperation, OSError subclass
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
}
|
||||
|
||||
machine_int_t sz;
|
||||
@ -27,7 +27,7 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
|
||||
int error;
|
||||
machine_int_t out_sz = o->type->stream_p.read(o, buf, sz, &error);
|
||||
if (out_sz == -1) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
} else {
|
||||
mp_obj_t s = mp_obj_new_str(buf, out_sz, false); // will reallocate to use exact size
|
||||
m_free(buf, sz);
|
||||
@ -39,7 +39,7 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
|
||||
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)self_in;
|
||||
if (o->type->stream_p.write == NULL) {
|
||||
// CPython: io.UnsupportedOperation, OSError subclass
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
}
|
||||
|
||||
uint sz;
|
||||
@ -47,7 +47,7 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
|
||||
int error;
|
||||
machine_int_t out_sz = o->type->stream_p.write(self_in, buf, sz, &error);
|
||||
if (out_sz == -1) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
} else {
|
||||
// http://docs.python.org/3/library/io.html#io.RawIOBase.write
|
||||
// "None is returned if the raw stream is set not to block and no single byte could be readily written to it."
|
||||
@ -62,7 +62,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
|
||||
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)self_in;
|
||||
if (o->type->stream_p.read == NULL) {
|
||||
// CPython: io.UnsupportedOperation, OSError subclass
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
}
|
||||
|
||||
int total_size = 0;
|
||||
@ -74,7 +74,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
|
||||
while (true) {
|
||||
machine_int_t out_sz = o->type->stream_p.read(self_in, p, current_read, &error);
|
||||
if (out_sz == -1) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
}
|
||||
if (out_sz == 0) {
|
||||
break;
|
||||
@ -88,7 +88,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
|
||||
p = vstr_extend(vstr, current_read);
|
||||
if (p == NULL) {
|
||||
// TODO
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError/*&mp_type_RuntimeError*/, "Out of memory"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError/*&mp_type_RuntimeError*/, "Out of memory"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ STATIC mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
|
||||
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0];
|
||||
if (o->type->stream_p.read == NULL) {
|
||||
// CPython: io.UnsupportedOperation, OSError subclass
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
|
||||
}
|
||||
|
||||
machine_int_t max_size = -1;
|
||||
@ -123,12 +123,12 @@ STATIC mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
|
||||
char *p = vstr_add_len(vstr, 1);
|
||||
if (p == NULL) {
|
||||
// TODO
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError/*&mp_type_RuntimeError*/, "Out of memory"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError/*&mp_type_RuntimeError*/, "Out of memory"));
|
||||
}
|
||||
|
||||
machine_int_t out_sz = o->type->stream_p.read(o, p, 1, &error);
|
||||
if (out_sz == -1) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
|
||||
}
|
||||
if (out_sz == 0) {
|
||||
// Back out previously added byte
|
||||
|
12
py/vm.c
12
py/vm.c
@ -158,7 +158,7 @@ outer_dispatch_loop:
|
||||
if (inject_exc != MP_OBJ_NULL && *ip != MP_BC_YIELD_FROM) {
|
||||
mp_obj_t t = inject_exc;
|
||||
inject_exc = MP_OBJ_NULL;
|
||||
nlr_jump(mp_make_raise_obj(t));
|
||||
nlr_raise(mp_make_raise_obj(t));
|
||||
}
|
||||
// loop to execute byte code
|
||||
for (;;) {
|
||||
@ -508,7 +508,7 @@ unwind_jump:
|
||||
// if TOS is an integer, does something else
|
||||
// else error
|
||||
if (mp_obj_is_exception_type(TOP())) {
|
||||
nlr_jump(sp[-1]);
|
||||
nlr_raise(sp[-1]);
|
||||
}
|
||||
if (TOP() == mp_const_none) {
|
||||
sp--;
|
||||
@ -749,12 +749,12 @@ unwind_return:
|
||||
}
|
||||
}
|
||||
if (obj1 == MP_OBJ_NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_RuntimeError, "No active exception to reraise"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "No active exception to reraise"));
|
||||
}
|
||||
} else {
|
||||
obj1 = POP();
|
||||
}
|
||||
nlr_jump(mp_make_raise_obj(obj1));
|
||||
nlr_raise(mp_make_raise_obj(obj1));
|
||||
|
||||
case MP_BC_YIELD_VALUE:
|
||||
yield:
|
||||
@ -767,7 +767,7 @@ yield:
|
||||
case MP_BC_YIELD_FROM: {
|
||||
//#define EXC_MATCH(exc, type) MP_OBJ_IS_TYPE(exc, type)
|
||||
#define EXC_MATCH(exc, type) mp_obj_exception_match(exc, type)
|
||||
#define GENERATOR_EXIT_IF_NEEDED(t) if (t != MP_OBJ_NULL && EXC_MATCH(t, &mp_type_GeneratorExit)) { nlr_jump(t); }
|
||||
#define GENERATOR_EXIT_IF_NEEDED(t) if (t != MP_OBJ_NULL && EXC_MATCH(t, &mp_type_GeneratorExit)) { nlr_raise(t); }
|
||||
mp_vm_return_kind_t ret_kind;
|
||||
obj1 = POP();
|
||||
mp_obj_t t_exc = MP_OBJ_NULL;
|
||||
@ -810,7 +810,7 @@ yield:
|
||||
GENERATOR_EXIT_IF_NEEDED(t_exc);
|
||||
break;
|
||||
} else {
|
||||
nlr_jump(obj2);
|
||||
nlr_raise(obj2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ mp_obj_t pyb_ADC(mp_obj_t pin_name_obj) {
|
||||
}
|
||||
|
||||
if (i == ADC_NUM_CHANNELS) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not have ADC capabilities", pin_name));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not have ADC capabilities", pin_name));
|
||||
}
|
||||
|
||||
// init ADC just for this channel
|
||||
@ -440,7 +440,7 @@ mp_obj_t pyb_ADC(mp_obj_t pin_name_obj) {
|
||||
return o;
|
||||
|
||||
pin_error:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not exist", pin_name));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not exist", pin_name));
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(pyb_ADC_obj, pyb_ADC);
|
||||
|
@ -125,7 +125,7 @@ mp_obj_t pyb_audio_dma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
||||
mp_obj_type_t *type = mp_obj_get_type(args[1]);
|
||||
if (type->buffer_p.get_buffer == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "buffer argument must support buffer protocol"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "buffer argument must support buffer protocol"));
|
||||
}
|
||||
buffer_info_t bufinfo;
|
||||
type->buffer_p.get_buffer(args[1], &bufinfo, BUFFER_READ);
|
||||
|
10
stm/exti.c
10
stm/exti.c
@ -110,10 +110,10 @@ uint exti_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t trigger_obj, mp
|
||||
// get both the port number and line number.
|
||||
v_line = mp_obj_get_int(pin_obj);
|
||||
if (v_line < 16) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d < 16, use a Pin object", v_line));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d < 16, use a Pin object", v_line));
|
||||
}
|
||||
if (v_line >= EXTI_NUM_VECTORS) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d >= max of %d", v_line, EXTI_NUM_VECTORS));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d >= max of %d", v_line, EXTI_NUM_VECTORS));
|
||||
}
|
||||
} else {
|
||||
pin = pin_map_user_obj(pin_obj);
|
||||
@ -121,16 +121,16 @@ uint exti_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t trigger_obj, mp
|
||||
}
|
||||
int mode = mp_obj_get_int(mode_obj);
|
||||
if (!IS_EXTI_MODE(mode)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Mode: %d", mode));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Mode: %d", mode));
|
||||
}
|
||||
int trigger = mp_obj_get_int(trigger_obj);
|
||||
if (!IS_EXTI_TRIGGER(trigger)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Trigger: %d", trigger));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Trigger: %d", trigger));
|
||||
}
|
||||
|
||||
exti_vector_t *v = &exti_vector[v_line];
|
||||
if (v->callback_obj != mp_const_none && callback_obj != mp_const_none) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d is already in use", v_line));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d is already in use", v_line));
|
||||
}
|
||||
|
||||
// We need to update callback and param atomically, so we disable the line
|
||||
|
@ -164,7 +164,7 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) {
|
||||
pin_obj = mp_call_function_1(pin_map_obj.mapper, user_obj);
|
||||
if (pin_obj != mp_const_none) {
|
||||
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_obj_type)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));
|
||||
}
|
||||
if (pin_map_obj.debug) {
|
||||
printf("Pin.mapper maps ");
|
||||
@ -222,5 +222,5 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) {
|
||||
return pin_obj;
|
||||
}
|
||||
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", pin_name));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", pin_name));
|
||||
}
|
||||
|
@ -123,12 +123,12 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
||||
last_ip = (192 << 24) | (168 << 16) | (0 << 8) | (3);
|
||||
} else {
|
||||
if (pyb_wlan_get_host(host_name) == mp_const_none) {
|
||||
nlr_jump(mp_obj_new_exception_msg(QSTR_FROM_STR_STATIC("WlanError"), "unknown host"));
|
||||
nlr_raise(mp_obj_new_exception_msg(QSTR_FROM_STR_STATIC("WlanError"), "unknown host"));
|
||||
}
|
||||
}
|
||||
int sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sd < 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "socket failed: %d", sd));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "socket failed: %d", sd));
|
||||
}
|
||||
//printf("socket seemed to work\n");
|
||||
//sys_tick_delay_ms(200);
|
||||
@ -139,7 +139,7 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
||||
remote.sin_addr.s_addr = htonl(last_ip);
|
||||
int ret = connect(sd, (sockaddr*)&remote, sizeof(sockaddr));
|
||||
if (ret != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "connect failed: %d", ret));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "connect failed: %d", ret));
|
||||
}
|
||||
//printf("connect seemed to work\n");
|
||||
//sys_tick_delay_ms(200);
|
||||
@ -160,7 +160,7 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
||||
ret = send(sd, query + sent, strlen(query + sent), 0);
|
||||
//printf("sent %d bytes\n", ret);
|
||||
if (ret < 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg(QSTR_FROM_STR_STATIC("WlanError"), "send failed"));
|
||||
nlr_raise(mp_obj_new_exception_msg(QSTR_FROM_STR_STATIC("WlanError"), "send failed"));
|
||||
}
|
||||
sent += ret;
|
||||
//sys_tick_delay_ms(200);
|
||||
@ -197,7 +197,7 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
||||
// read data
|
||||
ret = recv(sd, buf, 64, 0);
|
||||
if (ret < 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "recv failed %d", ret));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "recv failed %d", ret));
|
||||
}
|
||||
vstr_add_strn(vstr, buf, ret);
|
||||
}
|
||||
@ -217,7 +217,7 @@ mp_obj_t pyb_wlan_serve(void) {
|
||||
sys_tick_delay_ms(500);
|
||||
if (sd < 0) {
|
||||
printf("socket fail\n");
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "socket failed: %d", sd));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "socket failed: %d", sd));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -238,7 +238,7 @@ mp_obj_t pyb_wlan_serve(void) {
|
||||
sys_tick_delay_ms(100);
|
||||
if (ret != 0) {
|
||||
printf("bind fail\n");
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "bind failed: %d", ret));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(QSTR_FROM_STR_STATIC("WlanError"), "bind failed: %d", ret));
|
||||
}
|
||||
printf("bind seemed to work\n");
|
||||
|
||||
|
@ -131,16 +131,16 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
|
||||
const pin_obj_t *pin = pin_map_user_obj(pin_obj);
|
||||
if ((pin->adc_num & PIN_ADC1) == 0) {
|
||||
// No ADC1 function on that pin
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not have ADC capabilities", pin->name));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %s does not have ADC capabilities", pin->name));
|
||||
}
|
||||
channel = pin->adc_channel;
|
||||
}
|
||||
|
||||
if (!IS_ADC_CHANNEL(channel)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Not a valid ADC Channel: %d", channel));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Not a valid ADC Channel: %d", channel));
|
||||
}
|
||||
if (pin_adc1[channel] == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Channel %d not available on this board", channel));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Channel %d not available on this board", channel));
|
||||
}
|
||||
|
||||
pyb_obj_adc_t *o = m_new_obj(pyb_obj_adc_t);
|
||||
@ -192,7 +192,7 @@ void adc_init_all(pyb_obj_adc_all_t *adc_all, uint32_t resolution) {
|
||||
case 10: resolution = ADC_RESOLUTION10b; break;
|
||||
case 12: resolution = ADC_RESOLUTION12b; break;
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"resolution %d not supported", resolution));
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
pin = GPIO_PIN_5;
|
||||
dac_obj = &pyb_dac_channel_2;
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Dac %d does not exist", dac_id));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Dac %d does not exist", dac_id));
|
||||
}
|
||||
|
||||
// GPIO configuration
|
||||
@ -182,7 +182,7 @@ mp_obj_t pyb_dac_dma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
||||
mp_obj_type_t *type = mp_obj_get_type(args[1]);
|
||||
if (type->buffer_p.get_buffer == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "buffer argument must support buffer protocol"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "buffer argument must support buffer protocol"));
|
||||
}
|
||||
buffer_info_t bufinfo;
|
||||
type->buffer_p.get_buffer(args[1], &bufinfo, BUFFER_READ);
|
||||
|
@ -116,10 +116,10 @@ uint exti_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_ob
|
||||
// get both the port number and line number.
|
||||
v_line = mp_obj_get_int(pin_obj);
|
||||
if (v_line < 16) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d < 16, use a Pin object", v_line));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d < 16, use a Pin object", v_line));
|
||||
}
|
||||
if (v_line >= EXTI_NUM_VECTORS) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d >= max of %d", v_line, EXTI_NUM_VECTORS));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d >= max of %d", v_line, EXTI_NUM_VECTORS));
|
||||
}
|
||||
} else {
|
||||
pin = pin_map_user_obj(pin_obj);
|
||||
@ -132,18 +132,18 @@ uint exti_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_ob
|
||||
mode != GPIO_MODE_EVT_RISING &&
|
||||
mode != GPIO_MODE_EVT_FALLING &&
|
||||
mode != GPIO_MODE_EVT_RISING_FALLING) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Mode: %d", mode));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Mode: %d", mode));
|
||||
}
|
||||
int pull = mp_obj_get_int(pull_obj);
|
||||
if (pull != GPIO_NOPULL &&
|
||||
pull != GPIO_PULLUP &&
|
||||
pull != GPIO_PULLDOWN) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Pull: %d", pull));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid EXTI Pull: %d", pull));
|
||||
}
|
||||
|
||||
exti_vector_t *v = &exti_vector[v_line];
|
||||
if (v->callback_obj != mp_const_none && callback_obj != mp_const_none) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d is already in use", v_line));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "EXTI vector %d is already in use", v_line));
|
||||
}
|
||||
|
||||
// We need to update callback and param atomically, so we disable the line
|
||||
|
@ -86,7 +86,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
|
||||
// check i2c number
|
||||
if (!(0 <= i2c_id && i2c_id < PYB_NUM_I2C)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C bus %d does not exist", i2c_id + 1));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C bus %d does not exist", i2c_id + 1));
|
||||
}
|
||||
|
||||
// get i2c object
|
||||
@ -130,7 +130,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
if (status != HAL_OK) {
|
||||
// TODO really need a HardwareError object, or something
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Read failed with code %d", status));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Read failed with code %d", status));
|
||||
}
|
||||
|
||||
return mp_obj_str_builder_end(o);
|
||||
@ -152,14 +152,14 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args) {
|
||||
uint8_t data[1] = {mp_obj_get_int(args[3])};
|
||||
status = HAL_I2C_Mem_Write(self->i2c_handle, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, data, 1, 200);
|
||||
} else {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "data argument must be an integer or support the buffer protocol"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "data argument must be an integer or support the buffer protocol"));
|
||||
}
|
||||
|
||||
//printf("Write got %d\n", status);
|
||||
|
||||
if (status != HAL_OK) {
|
||||
// TODO really need a HardwareError object, or something
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Write failed with code %d", status));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_Mem_Write failed with code %d", status));
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
|
@ -14,7 +14,7 @@ STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) {
|
||||
vstr_init(&line, 16);
|
||||
int ret = readline(&line, "");
|
||||
if (line.len == 0 && ret == VCP_CHAR_CTRL_D) {
|
||||
nlr_jump(mp_obj_new_exception(&mp_type_EOFError));
|
||||
nlr_raise(mp_obj_new_exception(&mp_type_EOFError));
|
||||
}
|
||||
mp_obj_t o = mp_obj_new_str((const byte*)line.buf, line.len, false);
|
||||
vstr_clear(&line);
|
||||
|
@ -204,7 +204,7 @@ STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
|
||||
// check led number
|
||||
if (!(0 <= led_id && led_id < NUM_LEDS)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Led %d does not exist", led_id));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Led %d does not exist", led_id));
|
||||
}
|
||||
|
||||
// return static led object
|
||||
|
@ -38,7 +38,7 @@ STATIC mp_obj_t os_listdir(uint n_args, const mp_obj_t *args) {
|
||||
res = f_opendir(&dir, path); /* Open the directory */
|
||||
if (res != FR_OK) {
|
||||
// TODO should be mp_type_FileNotFoundError
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "No such file or directory: '%s'", path));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "No such file or directory: '%s'", path));
|
||||
}
|
||||
|
||||
mp_obj_t dir_list = mp_obj_new_list(0, NULL);
|
||||
@ -91,9 +91,9 @@ STATIC mp_obj_t os_mkdir(mp_obj_t path_o) {
|
||||
return mp_const_none;
|
||||
case FR_EXIST:
|
||||
// TODO should be FileExistsError
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "File exists: '%s'", path));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "File exists: '%s'", path));
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error creating directory '%s'", path));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error creating directory '%s'", path));
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ STATIC mp_obj_t os_remove(mp_obj_t path_o) {
|
||||
case FR_OK:
|
||||
return mp_const_none;
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing file '%s'", path));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing file '%s'", path));
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ STATIC mp_obj_t os_rmdir(mp_obj_t path_o) {
|
||||
case FR_OK:
|
||||
return mp_const_none;
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing directory '%s'", path));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing directory '%s'", path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) {
|
||||
pin_obj = mp_call_function_1(pin_map_obj.mapper, user_obj);
|
||||
if (pin_obj != mp_const_none) {
|
||||
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_obj_type)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));
|
||||
}
|
||||
if (pin_map_obj.debug) {
|
||||
printf("Pin.mapper maps ");
|
||||
@ -222,5 +222,5 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) {
|
||||
return pin_obj;
|
||||
}
|
||||
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", pin_name));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", pin_name));
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con
|
||||
|
||||
// check servo number
|
||||
if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1));
|
||||
}
|
||||
|
||||
// get and init servo object
|
||||
|
@ -174,7 +174,7 @@ void timer_interrupt(void) {
|
||||
mp_obj_t pyb_Timer(mp_obj_t timx_in) {
|
||||
TIM_TypeDef *TIMx = (TIM_TypeDef*)mp_obj_get_int(timx_in);
|
||||
if (!IS_TIM_INSTANCE(TIMx)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "argument 1 is not a TIM instance"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "argument 1 is not a TIM instance"));
|
||||
}
|
||||
pyb_hal_tim_t *tim = m_new_obj(pyb_hal_tim_t);
|
||||
tim->htim.Instance = TIMx;
|
||||
|
@ -145,7 +145,7 @@ STATIC void usart_obj_print(void (*print)(void *env, const char *fmt, ...), void
|
||||
STATIC mp_obj_t usart_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
if (!(n_args == 2 && n_kw == 0)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Usart accepts 2 arguments"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Usart accepts 2 arguments"));
|
||||
}
|
||||
|
||||
if (mp_obj_get_int(args[0]) > PYB_USART_MAX) {
|
||||
|
@ -190,7 +190,7 @@ mp_obj_t pyb_gpio(int n_args, mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
|
||||
pin_error:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "pin %d does not exist", pin));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "pin %d does not exist", pin));
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_gpio_obj, 1, 2, pyb_gpio);
|
||||
|
@ -70,7 +70,7 @@ static mp_obj_t servo_obj_attach(mp_obj_t self_in, mp_obj_t pin_obj) {
|
||||
return mp_const_none;
|
||||
|
||||
pin_error:
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "pin %d does not exist", pin));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "pin %d does not exist", pin));
|
||||
}
|
||||
|
||||
static mp_obj_t servo_obj_detach(mp_obj_t self_in) {
|
||||
@ -217,7 +217,7 @@ mp_obj_t pyb_Servo(void) {
|
||||
self->servo_id++;
|
||||
}
|
||||
m_del_obj(pyb_servo_obj_t, self);
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "No available servo ids"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "No available servo ids"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
|
||||
int fd = open(fname, mode, 0644);
|
||||
if (fd == -1) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
}
|
||||
return fdfile_new(fd);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ STATIC ffi_type *get_ffi_type(mp_obj_t o_in)
|
||||
}
|
||||
// TODO: Support actual libffi type objects
|
||||
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Unknown type"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Unknown type"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
|
||||
@ -118,7 +118,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
void *sym = dlsym(self->handle, symname);
|
||||
if (sym == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
}
|
||||
int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3]));
|
||||
mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams);
|
||||
@ -136,7 +136,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
int res = ffi_prep_cif(&o->cif, FFI_DEFAULT_ABI, nparams, char2ffi_type(*rettype), o->params);
|
||||
if (res != FFI_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error in ffi_prep_cif"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error in ffi_prep_cif"));
|
||||
}
|
||||
|
||||
return o;
|
||||
@ -173,12 +173,12 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
|
||||
|
||||
int res = ffi_prep_cif(&o->cif, FFI_DEFAULT_ABI, nparams, char2ffi_type(*rettype), o->params);
|
||||
if (res != FFI_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error in ffi_prep_cif"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error in ffi_prep_cif"));
|
||||
}
|
||||
|
||||
res = ffi_prep_closure_loc(o->clo, &o->cif, call_py_func, func_in, o->func);
|
||||
if (res != FFI_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "ffi_prep_closure_loc"));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "ffi_prep_closure_loc"));
|
||||
}
|
||||
|
||||
return o;
|
||||
@ -192,7 +192,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna
|
||||
|
||||
void *sym = dlsym(self->handle, symname);
|
||||
if (sym == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
}
|
||||
mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t);
|
||||
o->base.type = &ffivar_type;
|
||||
@ -208,7 +208,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
|
||||
|
||||
if (mod == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
}
|
||||
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
|
||||
o->base.type = type_in;
|
||||
|
@ -32,7 +32,7 @@ STATIC const mp_obj_type_t microsocket_type;
|
||||
// Helper functions
|
||||
#define RAISE_ERRNO(err_flag, error_val) \
|
||||
{ if (err_flag == -1) \
|
||||
{ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error_val)); } }
|
||||
{ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error_val)); } }
|
||||
|
||||
STATIC void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) {
|
||||
mp_obj_base_t *o = (mp_obj_base_t *)obj;
|
||||
@ -46,7 +46,7 @@ STATIC void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) {
|
||||
return;
|
||||
|
||||
error:
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "Operation not supported"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Operation not supported"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_socket_t *socket_new(int fd) {
|
||||
@ -264,7 +264,7 @@ STATIC mp_obj_t mod_socket_inet_aton(mp_obj_t arg) {
|
||||
const char *s = mp_obj_str_get_str(arg);
|
||||
struct in_addr addr;
|
||||
if (!inet_aton(s, &addr)) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, "Invalid IP address"));
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Invalid IP address"));
|
||||
}
|
||||
|
||||
return mp_obj_new_int(addr.s_addr);
|
||||
@ -277,7 +277,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
|
||||
const char *s = mp_obj_str_get_str(arg);
|
||||
struct hostent *h = gethostbyname(s);
|
||||
if (h == NULL) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
|
||||
}
|
||||
assert(h->h_length == 4);
|
||||
return mp_obj_new_int(*(int*)*h->h_addr_list);
|
||||
@ -309,7 +309,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
|
||||
int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr);
|
||||
|
||||
if (res != 0) {
|
||||
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[addrinfo error %d]", res));
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[addrinfo error %d]", res));
|
||||
}
|
||||
assert(addr);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user