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.
diff --git a/py/runtime.c b/py/runtime.c
index 5c9df06..c7b34c1 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -124,7 +124,7 @@
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 @@
}
}
// 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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
// 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 @@
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 @@
}
// 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 @@
// 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 @@
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 @@
// __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 @@
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 @@
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 *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