Switch exception throwing to mp_raise helpers. It saves a little code space each time to share the call.

crypto-aes
Scott Shawcroft 6 years ago
parent efd429464e
commit 12fa5b3a66

@ -46,7 +46,7 @@ void common_hal_nativeio_analogin_construct(nativeio_analogin_obj_t* self,
const mcu_pin_obj_t *pin) {
if (!pin->has_adc) {
// No ADC function on that pin
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin does not have ADC capabilities"));
mp_raise_ValueError("Pin does not have ADC capabilities");
}
self->pin = pin;

@ -27,6 +27,7 @@
#include <stdint.h>
#include <string.h>
#include "py/mperrno.h"
#include "py/runtime.h"
#include "shared-bindings/nativeio/AnalogOut.h"
@ -37,8 +38,7 @@
void common_hal_nativeio_analogout_construct(nativeio_analogout_obj_t* self,
const mcu_pin_obj_t *pin) {
if (pin->pin != PIN_PA02) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
"AnalogOut not supported on given pin."));
mp_raise_ValueError("AnalogOut not supported on given pin");
return;
}
struct dac_config config_dac;
@ -46,8 +46,7 @@ void common_hal_nativeio_analogout_construct(nativeio_analogout_obj_t* self,
config_dac.reference = DAC_REFERENCE_AVCC;
enum status_code status = dac_init(&self->dac_instance, DAC, &config_dac);
if (status != STATUS_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"DAC init failed."));
mp_raise_OSError(MP_EIO);
return;
}

@ -171,8 +171,7 @@ enum digitalinout_pull_t common_hal_nativeio_digitalinout_get_pull(
PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
uint32_t pin_mask = (1UL << (pin % 32));
if (self->output) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"Cannot get pull while in output mode."));
mp_raise_AttributeError("Cannot get pull while in output mode");
return PULL_NONE;
} else {
if (port_base->PINCFG[pin % 32].bit.PULLEN == 0) {

@ -30,6 +30,7 @@
#include "shared-bindings/nativeio/I2C.h"
#include "py/mperrno.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "asf/sam0/drivers/sercom/i2c/i2c_master.h"
#include "samd21_pins.h"
@ -70,7 +71,7 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
}
}
if (sercom == NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid pins."));
mp_raise_ValueError("Invalid pins");
}
config_i2c_master.pinmux_pad0 = sda_pinmux; // SDA
@ -86,9 +87,9 @@ void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self,
if (status != STATUS_OK) {
common_hal_nativeio_i2c_deinit(self);
if (status == STATUS_ERR_BAUDRATE_UNAVAILABLE) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Unsupported baudrate"));
mp_raise_ValueError("Unsupported baudrate");
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "I2C bus init error"));
mp_raise_OSError(MP_EIO);
}
}

@ -79,13 +79,11 @@ void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self,
self->variable_frequency = variable_frequency;
if (pin->primary_timer.tc == 0 && pin->secondary_timer.tc == 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"Invalid pin"));
mp_raise_ValueError("Invalid pin");
}
if (frequency == 0 || frequency > 6000000) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"Invalid PWM frequency"));
mp_raise_ValueError("Invalid PWM frequency");
}
uint16_t primary_timer_index = 0xff;
@ -136,7 +134,7 @@ void common_hal_nativeio_pwmout_construct(nativeio_pwmout_obj_t* self,
index = primary_timer_index;
}
if (t == NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "All timers in use"));
mp_raise_RuntimeError("All timers in use");
return;
}
uint8_t resolution = 0;
@ -265,8 +263,7 @@ uint16_t common_hal_nativeio_pwmout_get_duty_cycle(nativeio_pwmout_obj_t* self)
void common_hal_nativeio_pwmout_set_frequency(nativeio_pwmout_obj_t* self,
uint32_t frequency) {
if (frequency == 0 || frequency > 6000000) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"Invalid PWM frequency"));
mp_raise_ValueError("Invalid PWM frequency");
}
const pin_timer_t* t = self->timer;
uint8_t resolution;

@ -29,6 +29,7 @@
#include "shared-bindings/nativeio/SPI.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "samd21_pins.h"
// We use ENABLE registers below we don't want to treat as a macro.
@ -92,7 +93,7 @@ void common_hal_nativeio_spi_construct(nativeio_spi_obj_t *self,
}
}
if (sercom == NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid pins"));
mp_raise_ValueError("Invalid pins");
}
// Depends on where MOSI and CLK are.
@ -111,7 +112,7 @@ void common_hal_nativeio_spi_construct(nativeio_spi_obj_t *self,
}
}
if (dopo == 8) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI MOSI and clock pins incompatible"));
mp_raise_ValueError("MOSI and clock pins incompatible");
}
config_spi_master.mux_setting = (dopo << SERCOM_SPI_CTRLA_DOPO_Pos) |

@ -27,6 +27,7 @@
#include <string.h>
#include "py/nlr.h"
#include "py/mperrno.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
@ -186,8 +187,7 @@ nativeio_touchin_obj_t *active_touchin_obj[DEF_SELFCAP_NUM_CHANNELS];
void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) {
if (!pin->has_touch) {
// No ADC function on that pin
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q does not have touch capabilities", pin->name));
mp_raise_ValueError("Invalid pin");
}
if (selfcap_config.num_channels > 0) {
@ -230,18 +230,18 @@ void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
PRIV_SELFCAP_RS_TABLE_INIT, PRIV_NM_TABLE_INIT,
PRIV_FREQ_AUTO_TUNE_CHK, PRIV_MOIS_TOLERANCE_CHK);
if (status != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Touch init failed (%d)", status));
mp_raise_OSError(MP_EIO);
}
for (int i = 0; i < selfcap_config.num_channels; i++) {
status = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, i, i,
NO_AKS_GROUP, 10u, HYST_25, RES_8_BIT, &active_touchin_obj[i]->sensor_id);
if (status != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Touch pad config failed (%d)", status));
mp_raise_OSError(MP_EIO);
}
}
status = touch_selfcap_sensors_calibrate(AUTO_TUNE_RSEL);
if (status != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Touch pad calibration failed (%d)", status));
mp_raise_OSError(MP_EIO);
}
// Run a measurement to get calibrated.
@ -275,7 +275,7 @@ void touch_selfcap_measure_complete_callback(void)
bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
if (p_selfcap_measure_data->acq_status & TOUCH_CC_CALIB_ERROR) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch calibration error"));
mp_raise_RuntimeError("Touch calibration error");
}
touch_acq_status = TOUCH_BURST_AGAIN;
uint64_t start_ticks = ticks_ms;
@ -287,7 +287,7 @@ bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
touch_selfcap_measure_complete_callback);
if (touch_ret != TOUCH_SUCCESS) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch measure failed"));
mp_raise_OSError(MP_EIO);
}
while(!touch_read_ready && ticks_ms - start_ticks < 1000) {
@ -299,7 +299,7 @@ bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
}
if (touch_acq_status & TOUCH_BURST_AGAIN) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch read failed"));
mp_raise_OSError(MP_EIO);
}
return (p_selfcap_measure_data->p_sensor_states[self->sensor_id / 8] & (1 << (self->sensor_id % 8))) != 0;

@ -34,8 +34,7 @@
void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"No room in flash for capacitive touch hardware support."));
mp_raise_NotImplementError("No capacitive touch support");
}
void common_hal_nativeio_touchin_deinit(nativeio_touchin_obj_t* self) {

@ -31,6 +31,7 @@
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "samd21_pins.h"
#include "tick.h"
@ -162,7 +163,7 @@ void common_hal_nativeio_uart_construct(nativeio_uart_obj_t *self,
}
}
if (sercom == NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid pins"));
mp_raise_ValueError("Invalid pins");
}
if (tx == NULL) {
tx_pad = 0;
@ -216,12 +217,11 @@ void common_hal_nativeio_uart_construct(nativeio_uart_obj_t *self,
self->buffer_length *= (bits + 7) / 8;
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false);
if (self->buffer == NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"Unable to allocate RX buffer."));
mp_raise_msg(&mp_type_MemoryError, "Failed to allocate RX buffer");
}
if (usart_init(&self->uart_instance, sercom, &config_usart) != STATUS_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unable to init UART"));
mp_raise_OSError(MP_EIO);
}
// We use our own interrupt handler because we want a circular buffer

@ -30,6 +30,7 @@
#include "py/mpstate.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/runtime.h"
#include "genhdr/mpversion.h"
#include "lib/fatfs/ff.h"
#include "lib/fatfs/diskio.h"
@ -103,7 +104,7 @@ STATIC mp_obj_t os_getcwd(void) {
FRESULT res = f_getcwd(buf, sizeof buf);
if (res != FR_OK) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
mp_raise_OSError(fresult_to_errno_table[res]);
}
return mp_obj_new_str(buf, strlen(buf), false);

@ -498,7 +498,7 @@ STATIC mp_obj_t os_unmount(mp_obj_t path_o) {
if ((mount_obj = osmount_find_by_path(path))) {
unmount (mount_obj);
} else {
mp_raise_msg(&mp_type_ValueError, mpexception_value_invalid_arguments);
mp_raise_ValueError(mpexception_value_invalid_arguments);
}
return mp_const_none;

@ -1025,7 +1025,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
break;
}
case MOD_NETWORK_SOCK_DGRAM:
mp_not_implemented("");
mp_raise_NotImplementError("");
break;
}

@ -153,7 +153,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
mp_obj_t s = mp_obj_new_str(subj.begin, caps[0] - subj.begin, false);
mp_obj_list_append(retval, s);
if (self->re.sub > 0) {
mp_not_implemented("Splitting with sub-captures");
mp_raise_NotImplementError("Splitting with sub-captures");
}
subj.begin = caps[1];
if (maxsplit > 0 && --maxsplit == 0) {

@ -126,7 +126,7 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
// Currently supports only blocking mode
(void)self_in;
if (!mp_obj_is_true(flag_in)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
return mp_const_none;
}

@ -219,7 +219,7 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
// Currently supports only blocking mode
(void)self_in;
if (!mp_obj_is_true(flag_in)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
return mp_const_none;
}

@ -121,7 +121,7 @@ STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
mp_obj_t heap_in = args[0];
mp_obj_utimeq_t *heap = get_heap(heap_in);
if (heap->len == heap->alloc) {
mp_raise_msg(&mp_type_IndexError, "queue overflow");
mp_raise_IndexError("queue overflow");
}
mp_uint_t l = heap->len;
heap->items[l].time = MP_OBJ_SMALL_INT_VALUE(args[1]);

@ -37,7 +37,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
mp_raise_msg(&mp_type_TypeError, "function does not take keyword arguments");
mp_raise_TypeError("function does not take keyword arguments");
}
}
@ -46,9 +46,9 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"function takes %d positional arguments but %d were given",
n_args_min, n_args));
n_args_min, n_args);
}
}
} else {
@ -56,17 +56,17 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"function missing %d required positional arguments",
n_args_min - n_args));
n_args_min - n_args);
}
} else if (n_args > n_args_max) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"function expected at most %d arguments, got %d",
n_args_max, n_args));
n_args_max, n_args);
}
}
}
@ -89,8 +89,8 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%q' argument required", allowed[i].qst));
mp_raise_TypeError_varg(
"'%q' argument required", allowed[i].qst);
}
}
out_vals[i] = allowed[i].defval;
@ -115,7 +115,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch();
} else {
// TODO better error message
mp_raise_msg(&mp_type_TypeError, "extra positional arguments given");
mp_raise_TypeError("extra positional arguments given");
}
}
if (kws_found < kws->used) {
@ -123,7 +123,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch();
} else {
// TODO better error message
mp_raise_msg(&mp_type_TypeError, "extra keyword arguments given");
mp_raise_TypeError("extra keyword arguments given");
}
}
}
@ -136,12 +136,12 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE || defined(_MSC_VER)
NORETURN void mp_arg_error_terse_mismatch(void) {
mp_raise_msg(&mp_type_TypeError, "argument num/types mismatch");
mp_raise_TypeError("argument num/types mismatch");
}
#endif
#if MICROPY_CPYTHON_COMPAT
NORETURN void mp_arg_error_unimpl_kw(void) {
mp_not_implemented("keyword argument(s) not yet implemented - use normal args instead");
mp_raise_NotImplementError("keyword argument(s) not yet implemented - use normal args instead");
}
#endif

@ -63,12 +63,12 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected,
mp_arg_error_terse_mismatch();
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
(void)f;
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function takes %d positional arguments but %d were given", expected, given));
mp_raise_TypeError_varg(
"function takes %d positional arguments but %d were given", expected, given);
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"%q() takes %d positional arguments but %d were given",
mp_obj_fun_get_name(MP_OBJ_FROM_PTR(f)), expected, given));
mp_obj_fun_get_name(MP_OBJ_FROM_PTR(f)), expected, given);
#endif
}
@ -176,8 +176,8 @@ void mp_setup_code_state(mp_code_state_t *code_state, mp_obj_fun_bc_t *self, siz
for (size_t j = 0; j < n_pos_args + n_kwonly_args; j++) {
if (wanted_arg_name == arg_names[j]) {
if (code_state->state[n_state - 1 - j] != MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function got multiple values for argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name)));
mp_raise_TypeError_varg(
"function got multiple values for argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name));
}
code_state->state[n_state - 1 - j] = kwargs[2 * i + 1];
goto continue2;
@ -185,7 +185,7 @@ void mp_setup_code_state(mp_code_state_t *code_state, mp_obj_fun_bc_t *self, siz
}
// Didn't find name match with positional args
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) {
mp_raise_msg(&mp_type_TypeError, "function does not take keyword arguments");
mp_raise_TypeError("function does not take keyword arguments");
}
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
continue2:;
@ -209,8 +209,8 @@ continue2:;
// Check that all mandatory positional args are specified
while (d < &code_state->state[n_state]) {
if (*d++ == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function missing required positional argument #%d", &code_state->state[n_state] - d));
mp_raise_TypeError_varg(
"function missing required positional argument #%d", &code_state->state[n_state] - d);
}
}
@ -225,8 +225,9 @@ continue2:;
if (elem != NULL) {
code_state->state[n_state - 1 - n_pos_args - i] = elem->value;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function missing required keyword argument '%q'", MP_OBJ_QSTR_VALUE(arg_names[n_pos_args + i])));
mp_raise_TypeError_varg(
"function missing required keyword argument '%q'",
MP_OBJ_QSTR_VALUE(arg_names[n_pos_args + i]));
}
}
}
@ -234,7 +235,7 @@ continue2:;
} else {
// no keyword arguments given
if (n_kwonly_args != 0) {
mp_raise_msg(&mp_type_TypeError, "function missing keyword-only argument");
mp_raise_TypeError("function missing keyword-only argument");
}
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) {
*var_pos_kw_args = mp_obj_new_dict(0);

@ -95,7 +95,7 @@ STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) {
case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break;
case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break;
default:
mp_raise_msg(&mp_type_ValueError, "bad compile mode");
mp_raise_ValueError("bad compile mode");
}
mp_obj_code_t *code = m_new_obj(mp_obj_code_t);
@ -137,7 +137,7 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
if (MICROPY_PY_BUILTINS_EXECFILE && parse_input_kind == MP_PARSE_SINGLE_INPUT) {
lex = mp_lexer_new_from_file(str);
if (lex == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "could not open file '%s'", str));
mp_raise_msg_varg(&mp_type_OSError, "could not open file '%s'", str);
}
parse_input_kind = MP_PARSE_FILE_INPUT;
} else {

@ -144,10 +144,9 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex, const char
if (lex == NULL) {
// we verified the file exists using stat, but lexer could still fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ImportError, "module not found");
mp_raise_ImportError("module not found");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
"no module named '%s'", fname));
mp_raise_msg_varg(&mp_type_ImportError, "no module named '%s'", fname);
}
}
@ -249,8 +248,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
#endif
// If we get here then the file was not frozen and we can't compile scripts.
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
"script compilation not supported"));
mp_raise_ImportError("script compilation not supported");
}
STATIC void chop_component(const char *start, const char **end) {
@ -346,7 +344,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
DEBUG_printf("Warning: no dots in current module name and level>0\n");
p = this_name + this_name_l;
} else if (level != -1) {
mp_raise_msg(&mp_type_ImportError, "invalid relative import");
mp_raise_ImportError("invalid relative import");
}
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
@ -361,7 +359,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
if (new_mod_q == MP_QSTR_) {
// CPython raises SystemError
mp_raise_msg(&mp_type_ImportError, "cannot perform relative import");
mp_raise_ImportError("cannot perform relative import");
}
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
mod_str = new_mod;
@ -431,10 +429,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
#endif
// couldn't find the file, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ImportError, "module not found");
mp_raise_ImportError("module not found");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
"no module named '%q'", mod_name));
mp_raise_msg_varg(&mp_type_ImportError,
"no module named '%q'", mod_name);
}
}
} else {

@ -463,7 +463,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, bool first_token) {
// 3MB of text; even gzip-compressed and with minimal structure, it'll take
// roughly half a meg of storage. This form of Unicode escape may be added
// later on, but it's definitely not a priority right now. -- CJA 20140607
mp_not_implemented("unicode name escapes");
mp_raise_NotImplementError("unicode name escapes");
break;
default:
if (c >= '0' && c <= '7') {

@ -178,7 +178,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
str[3] = (c & 0x3F) | 0x80;
len = 4;
} else {
mp_raise_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)");
mp_raise_ValueError("chr() arg not in range(0x110000)");
}
return mp_obj_new_str(str, len, true);
#else
@ -187,7 +187,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
char str[1] = {ord};
return mp_obj_new_str(str, 1, true);
} else {
mp_raise_msg(&mp_type_ValueError, "chr() arg not in range(256)");
mp_raise_ValueError("chr() arg not in range(256)");
}
#endif
}
@ -286,7 +286,7 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t
if (default_elem != NULL) {
best_obj = default_elem->value;
} else {
mp_raise_msg(&mp_type_ValueError, "arg is an empty sequence");
mp_raise_ValueError("arg is an empty sequence");
}
}
return best_obj;
@ -320,7 +320,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(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_STOP_ITERATION) {
nlr_raise(mp_obj_new_exception(&mp_type_StopIteration));
mp_raise_msg(&mp_type_StopIteration, "");
} else {
return ret;
}
@ -366,11 +366,10 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
#endif
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"ord expects a character"));
mp_raise_TypeError("ord expects a character");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"ord() expected a character, but string of length %d found", (int)len));
mp_raise_TypeError_varg(
"ord() expected a character, but string of length %d found", (int)len);
}
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
@ -499,7 +498,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum);
STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args > 1) {
mp_raise_msg(&mp_type_TypeError, "must use keyword argument for key function");
mp_raise_TypeError("must use keyword argument for key function");
}
mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args);
mp_obj_list_sort(1, &self, kwargs);

@ -26,6 +26,7 @@
#include "py/builtin.h"
#include "py/nlr.h"
#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH
@ -41,7 +42,7 @@
/// working with floating-point numbers.
STATIC NORETURN void math_error(void) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "math domain error"));
mp_raise_ValueError("math domain error");
}
#define MATH_FUN_1(py_name, c_name) \

@ -239,7 +239,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
} else {
// positional and keyword arguments
if (mp_obj_get_type(args[2]) != &mp_type_dict) {
mp_raise_msg(&mp_type_TypeError, "expecting a dict for keyword args");
mp_raise_TypeError("expecting a dict for keyword args");
}
mp_map_t *map = &((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[2]))->map;
th_args = m_new_obj_var(thread_entry_args_t, mp_obj_t, pos_args_len + 2 * map->used);

@ -229,10 +229,10 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
return mp_obj_int_get_checked(arg);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "can't convert to int");
mp_raise_TypeError("can't convert to int");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"can't convert %s to int", mp_obj_get_type_str(arg)));
mp_raise_TypeError_varg(
"can't convert %s to int", mp_obj_get_type_str(arg));
}
}
}
@ -279,10 +279,10 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
return mp_obj_float_get(arg);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "can't convert to float");
mp_raise_TypeError("can't convert to float");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"can't convert %s to float", mp_obj_get_type_str(arg)));
mp_raise_TypeError_varg(
"can't convert %s to float", mp_obj_get_type_str(arg));
}
}
}
@ -310,10 +310,10 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
mp_obj_complex_get(arg, real, imag);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "can't convert to complex");
mp_raise_TypeError("can't convert to complex");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"can't convert %s to complex", mp_obj_get_type_str(arg)));
mp_raise_TypeError_varg(
"can't convert %s to complex", mp_obj_get_type_str(arg));
}
}
}
@ -328,10 +328,10 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
mp_obj_list_get(o, len, items);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "expected tuple/list");
mp_raise_TypeError("expected tuple/list");
} else {
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)));
mp_raise_TypeError_varg(
"object '%s' is not a tuple or list", mp_obj_get_type_str(o));
}
}
}
@ -342,10 +342,10 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, mp_uint_t len, mp_obj_t **items) {
mp_obj_get_array(o, &seq_len, items);
if (seq_len != len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ValueError, "tuple/list has wrong length");
mp_raise_ValueError("tuple/list has wrong length");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"requested length %d but object has length %d", (int)len, (int)seq_len));
mp_raise_ValueError_varg("requested length %d but object has length %d",
(int)len, (int)seq_len);
}
}
}
@ -357,11 +357,11 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "indices must be integers");
mp_raise_TypeError("indices must be integers");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"%q indices must be integers, not %s",
type->name, mp_obj_get_type_str(index)));
type->name, mp_obj_get_type_str(index));
}
}
@ -377,10 +377,10 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
} else {
if (i < 0 || (mp_uint_t)i >= len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_IndexError, "index out of range");
mp_raise_IndexError("index out of range");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError,
"%q index out of range", type->name));
mp_raise_msg_varg(&mp_type_IndexError,
"%q index out of range", type->name);
}
}
}
@ -410,10 +410,10 @@ mp_obj_t mp_obj_len(mp_obj_t o_in) {
mp_obj_t len = mp_obj_len_maybe(o_in);
if (len == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object has no len");
mp_raise_TypeError("object has no len");
} else {
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)));
mp_raise_TypeError_varg(
"object of type '%s' has no len()", mp_obj_get_type_str(o_in));
}
} else {
return len;
@ -451,25 +451,24 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
}
if (value == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object does not support item deletion");
mp_raise_TypeError("object does not support item deletion");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object does not support item deletion", mp_obj_get_type_str(base)));
mp_raise_TypeError_varg(
"'%s' object does not support item deletion", mp_obj_get_type_str(base));
}
} else if (value == MP_OBJ_SENTINEL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"object is not subscriptable"));
mp_raise_TypeError("object is not subscriptable");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not subscriptable", mp_obj_get_type_str(base)));
mp_raise_TypeError_varg(
"'%s' object is not subscriptable", mp_obj_get_type_str(base));
}
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object does not support item assignment");
mp_raise_TypeError("object does not support item assignment");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object does not support item assignment", mp_obj_get_type_str(base)));
mp_raise_TypeError_varg(
"'%s' object does not support item assignment", mp_obj_get_type_str(base));
}
}
}
@ -495,7 +494,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
if (!mp_get_buffer(obj, bufinfo, flags)) {
mp_raise_msg(&mp_type_TypeError, "object with buffer protocol required");
mp_raise_TypeError("object with buffer protocol required");
}
}

@ -95,7 +95,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
int typecode_size = mp_binary_get_size('@', typecode, NULL);
if (typecode_size == 0) {
mp_raise_msg(&mp_type_ValueError, "bad typecode");
mp_raise_ValueError("bad typecode");
}
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
@ -292,7 +292,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
// Otherwise, can only look for a scalar numeric value in an array
if (MP_OBJ_IS_INT(rhs_in) || mp_obj_is_float(rhs_in)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
return mp_const_false;
@ -382,7 +382,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
} else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) {
mp_not_implemented("only slices with step=1 (aka None) are supported");
mp_raise_NotImplementError("only slices with step=1 (aka None) are supported");
}
if (value != MP_OBJ_SENTINEL) {
#if MICROPY_PY_ARRAY_SLICE_ASSIGN
@ -395,7 +395,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value);
if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) {
compat_error:
mp_raise_msg(&mp_type_ValueError, "lhs and rhs should be compatible");
mp_raise_ValueError("lhs and rhs should be compatible");
}
src_len = src_slice->len;
src_items = src_slice->items;
@ -413,7 +413,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
src_len = bufinfo.len;
src_items = bufinfo.buf;
} else {
mp_not_implemented("array/bytes required on right side");
mp_raise_NotImplementError("array/bytes required on right side");
}
// TODO: check src/dst compat

@ -194,7 +194,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
}
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't do truncated division of a complex number"));
mp_raise_TypeError("can't do truncated division of a complex number");
case MP_BINARY_OP_TRUE_DIVIDE:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:

@ -385,7 +385,7 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg
if (key == MP_OBJ_STOP_ITERATION
|| value == MP_OBJ_STOP_ITERATION
|| stop != MP_OBJ_STOP_ITERATION) {
mp_raise_msg(&mp_type_ValueError, "dictionary update sequence has the wrong length");
mp_raise_ValueError("dictionary update sequence has the wrong length");
} else {
mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
}

@ -105,7 +105,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
}
if (self->code_state.sp == self->code_state.state - 1) {
if (send_value != mp_const_none) {
mp_raise_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator");
mp_raise_TypeError("can't send non-None value to a just-started generator");
}
} else {
*self->code_state.sp = send_value;
@ -157,7 +157,7 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
case MP_VM_RETURN_YIELD:
if (throw_value != MP_OBJ_NULL && mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(mp_obj_get_type(throw_value)), MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) {
mp_raise_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit");
mp_raise_RuntimeError("generator ignored GeneratorExit");
}
return ret;
@ -209,7 +209,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_FROM_PTR(&mp_const_GeneratorExit_obj), &ret)) {
case MP_VM_RETURN_YIELD:
mp_raise_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit");
mp_raise_RuntimeError("generator ignored GeneratorExit");
// Swallow StopIteration & GeneratorExit (== successful close), and re-raise any other
case MP_VM_RETURN_EXCEPTION:

@ -322,15 +322,15 @@ mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
int cl = fpclassify(val);
if (cl == FP_INFINITE) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "can't convert inf to int"));
mp_raise_msg(&mp_type_OverflowError, "can't convert inf to int");
} else if (cl == FP_NAN) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "can't convert NaN to int"));
mp_raise_ValueError("can't convert NaN to int");
} else {
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
if (icl == MP_FP_CLASS_FIT_SMALLINT) {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)val);
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "float too big"));
mp_raise_ValueError("float too big");
}
}
}
@ -380,7 +380,7 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
(void)n_args;
if (args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
// get the buffer info
@ -405,7 +405,7 @@ STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
(void)n_args;
if (args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
mp_uint_t len = MP_OBJ_SMALL_INT_VALUE(args[1]);

@ -241,7 +241,7 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) {
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
// TODO raise an exception if the unsigned long long won't fit
if (val >> (sizeof(unsigned long long) * 8 - 1) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "ulonglong too large"));
mp_raise_msg(&mp_type_OverflowError, "ulonglong too large"));
}
mp_obj_int_t *o = m_new_obj(mp_obj_int_t);
o->base.type = &mp_type_int;
@ -253,9 +253,9 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
int cl = fpclassify(val);
if (cl == FP_INFINITE) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "can't convert inf to int"));
mp_raise_msg(&mp_type_OverflowError, "can't convert inf to int"));
} else if (cl == FP_NAN) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "can't convert NaN to int"));
mp_raise_ValueError("can't convert NaN to int");
} else {
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
if (icl == MP_FP_CLASS_FIT_SMALLINT) {
@ -263,7 +263,7 @@ mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
} else if (icl == MP_FP_CLASS_FIT_LONGINT) {
return mp_obj_new_int_from_ll((long long)val);
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "float too big"));
mp_raise_ValueError("float too big");
}
}
}

@ -271,7 +271,7 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_INPLACE_RSHIFT: {
mp_int_t irhs = mp_obj_int_get_checked(rhs_in);
if (irhs < 0) {
mp_raise_msg(&mp_type_ValueError, "negative shift count");
mp_raise_ValueError("negative shift count");
}
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
mpz_shl_inpl(&res->mpz, zlhs, irhs);
@ -354,9 +354,9 @@ mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
int cl = fpclassify(val);
if (cl == FP_INFINITE) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "can't convert inf to int"));
mp_raise_msg(&mp_type_OverflowError, "can't convert inf to int");
} else if (cl == FP_NAN) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "can't convert NaN to int"));
mp_raise_ValueError("can't convert NaN to int");
} else {
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
if (icl == MP_FP_CLASS_FIT_SMALLINT) {

@ -156,7 +156,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
mp_int_t len_adj = slice.start - slice.stop;
@ -196,7 +196,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_list_t *slice = MP_OBJ_TO_PTR(value);
mp_bound_slice_t slice_out;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
mp_not_implemented("");
mp_raise_NotImplementError("");
}
mp_int_t len_adj = slice->len - (slice_out.stop - slice_out.start);
//printf("Len adj: %d\n", len_adj);
@ -266,7 +266,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]);
if (self->len == 0) {
mp_raise_msg(&mp_type_IndexError, "pop from empty list");
mp_raise_IndexError("pop from empty list");
}
mp_uint_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
mp_obj_t ret = self->items[index];

@ -64,7 +64,7 @@ void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
} else {
// delete/store attribute
// provide more detailed error message than we'd get by just returning
mp_raise_msg(&mp_type_AttributeError, "can't set attribute");
mp_raise_AttributeError("can't set attribute");
}
}
@ -75,13 +75,13 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"function takes %d positional arguments but %d were given",
num_fields, n_args + n_kw));
num_fields, n_args + n_kw);
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
mp_raise_TypeError_varg(
"%q() takes %d positional arguments but %d were given",
type->base.name, num_fields, n_args + n_kw));
type->base.name, num_fields, n_args + n_kw);
}
}
@ -104,16 +104,16 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"unexpected keyword argument '%q'", kw));
mp_raise_TypeError_varg(
"unexpected keyword argument '%q'", kw);
}
}
if (arg_objects[id] != MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch();
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"function got multiple values for argument '%q'", kw));
mp_raise_TypeError_varg(
"function got multiple values for argument '%q'", kw);
}
}
arg_objects[id] = args[i + 1];

@ -50,7 +50,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__);
STATIC mp_obj_t object___new__(mp_obj_t cls) {
if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)MP_OBJ_TO_PTR(cls))) {
mp_raise_msg(&mp_type_TypeError, "__new__ arg must be a user-type");
mp_raise_TypeError("__new__ arg must be a user-type");
}
mp_obj_t o = MP_OBJ_SENTINEL;
mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o);