Commit ea13f407 authored by Damien George's avatar Damien George
Browse files

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.
parent 2a037408
......@@ -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)));
}
......
......@@ -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
......@@ -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));
}
}
......
......@@ -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:
......
......@@ -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);
}
}
}
......
......@@ -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);