Merge branch 'master' of github.com:dpgeorge/micropython
This commit is contained in:
commit
632cf5710c
|
@ -32,6 +32,7 @@ Q(OSError)
|
||||||
Q(SyntaxError)
|
Q(SyntaxError)
|
||||||
Q(TypeError)
|
Q(TypeError)
|
||||||
Q(ValueError)
|
Q(ValueError)
|
||||||
|
Q(OverflowError)
|
||||||
|
|
||||||
Q(abs)
|
Q(abs)
|
||||||
Q(all)
|
Q(all)
|
||||||
|
|
2
py/obj.c
2
py/obj.c
|
@ -155,6 +155,8 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
||||||
return MP_OBJ_SMALL_INT_VALUE(arg);
|
return MP_OBJ_SMALL_INT_VALUE(arg);
|
||||||
|
} else if (MP_OBJ_IS_TYPE(arg, &int_type)) {
|
||||||
|
return mp_obj_int_get_checked(arg);
|
||||||
#if MICROPY_ENABLE_FLOAT
|
#if MICROPY_ENABLE_FLOAT
|
||||||
} else if (MP_OBJ_IS_TYPE(arg, &float_type)) {
|
} else if (MP_OBJ_IS_TYPE(arg, &float_type)) {
|
||||||
// TODO work out if this should be floor, ceil or trunc
|
// TODO work out if this should be floor, ceil or trunc
|
||||||
|
|
4
py/obj.h
4
py/obj.h
|
@ -261,6 +261,10 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
|
||||||
|
|
||||||
// int
|
// int
|
||||||
extern const mp_obj_type_t int_type;
|
extern const mp_obj_type_t int_type;
|
||||||
|
// For long int, returns value truncated to machine_int_t
|
||||||
|
machine_int_t mp_obj_int_get(mp_obj_t self_in);
|
||||||
|
// Will rains exception if value doesn't fit into machine_int_t
|
||||||
|
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in);
|
||||||
|
|
||||||
// exception
|
// exception
|
||||||
extern const mp_obj_type_t exception_type;
|
extern const mp_obj_type_t exception_type;
|
||||||
|
|
17
py/objint.c
17
py/objint.c
|
@ -58,7 +58,7 @@ mp_obj_t 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
|
// 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) {
|
mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
|
||||||
assert(0);
|
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_OverflowError, "long int not supported in this build"));
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +68,7 @@ mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) {
|
||||||
if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) {
|
if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(value);
|
return MP_OBJ_NEW_SMALL_INT(value);
|
||||||
}
|
}
|
||||||
// TODO: Raise exception
|
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_OverflowError, "small int overflow"));
|
||||||
assert(0);
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +76,16 @@ mp_obj_t mp_obj_new_int(machine_int_t value) {
|
||||||
if (MP_OBJ_FITS_SMALL_INT(value)) {
|
if (MP_OBJ_FITS_SMALL_INT(value)) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(value);
|
return MP_OBJ_NEW_SMALL_INT(value);
|
||||||
}
|
}
|
||||||
// TODO: Raise exception
|
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_OverflowError, "small int overflow"));
|
||||||
assert(0);
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
machine_int_t mp_obj_int_get(mp_obj_t self_in) {
|
||||||
|
return MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
|
||||||
|
return MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -120,9 +120,17 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
machine_int_t mp_obj_int_get_int(mp_obj_t self_in) {
|
machine_int_t mp_obj_int_get(mp_obj_t self_in) {
|
||||||
|
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
||||||
|
return MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||||
|
}
|
||||||
mp_obj_int_t *self = self_in;
|
mp_obj_int_t *self = self_in;
|
||||||
return self->val;
|
return self->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
|
||||||
|
// TODO: Check overflow
|
||||||
|
return mp_obj_int_get(self_in);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -89,6 +89,9 @@ void rt_init(void) {
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_TypeError, mp_obj_new_exception(MP_QSTR_TypeError));
|
mp_map_add_qstr(&map_builtins, MP_QSTR_TypeError, mp_obj_new_exception(MP_QSTR_TypeError));
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_SyntaxError, mp_obj_new_exception(MP_QSTR_SyntaxError));
|
mp_map_add_qstr(&map_builtins, MP_QSTR_SyntaxError, mp_obj_new_exception(MP_QSTR_SyntaxError));
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_ValueError, mp_obj_new_exception(MP_QSTR_ValueError));
|
mp_map_add_qstr(&map_builtins, MP_QSTR_ValueError, mp_obj_new_exception(MP_QSTR_ValueError));
|
||||||
|
// Somehow CPython managed to have OverflowError not inherit from ValueError ;-/
|
||||||
|
// TODO: For MICROPY_CPYTHON_COMPAT==0 use ValueError to avoid exc proliferation
|
||||||
|
mp_map_add_qstr(&map_builtins, MP_QSTR_OverflowError, mp_obj_new_exception(MP_QSTR_OverflowError));
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_OSError, mp_obj_new_exception(MP_QSTR_OSError));
|
mp_map_add_qstr(&map_builtins, MP_QSTR_OSError, mp_obj_new_exception(MP_QSTR_OSError));
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_AssertionError, mp_obj_new_exception(MP_QSTR_AssertionError));
|
mp_map_add_qstr(&map_builtins, MP_QSTR_AssertionError, mp_obj_new_exception(MP_QSTR_AssertionError));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue