Upgrade to MicroPython 1.9.3

This commit is contained in:
Romain Goyet
2018-04-03 16:12:25 +02:00
committed by Ecco
parent 31f79c702a
commit 55e4c955f4
151 changed files with 1196 additions and 1026 deletions

View File

@@ -1,5 +1,5 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,10 +28,8 @@
#include <stdlib.h>
#include <string.h>
#include "py/nlr.h"
#include "py/smallint.h"
#include "py/objint.h"
#include "py/runtime0.h"
#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_FLOAT
@@ -94,31 +92,7 @@ int mp_obj_int_sign(mp_obj_t self_in) {
}
}
// This must handle int and bool types, and must raise a
// TypeError if the argument is not integral
mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
if (MP_OBJ_IS_TYPE(self_in, &mp_type_int)) {
mp_obj_int_t *self = self_in;
self = mp_obj_new_int_from_ll(self->val);
if (self->val < 0) {
// TODO could overflow long long
self->val = -self->val;
}
return self;
} else {
mp_int_t val = mp_obj_get_int(self_in);
if (val == MP_SMALL_INT_MIN) {
return mp_obj_new_int_from_ll(-val);
} else {
if (val < 0) {
val = -val;
}
return MP_OBJ_NEW_SMALL_INT(val);
}
}
}
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
mp_obj_int_t *o = o_in;
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->val != 0);
@@ -130,11 +104,21 @@ mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val);
case MP_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val);
case MP_UNARY_OP_ABS: {
mp_obj_int_t *self = MP_OBJ_TO_PTR(o_in);
if (self->val >= 0) {
return o_in;
}
self = mp_obj_new_int_from_ll(self->val);
// TODO could overflow long long
self->val = -self->val;
return MP_OBJ_FROM_PTR(self);
}
default: return MP_OBJ_NULL; // op not supported
}
}
mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
long long lhs_val;
long long rhs_val;