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,7 @@
#include <stdio.h>
#include <assert.h>
#include "py/nlr.h"
#include "py/obj.h"
#include "py/parsenum.h"
#include "py/runtime0.h"
#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_COMPLEX
@@ -117,18 +114,20 @@ STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, si
}
}
STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->real != 0 || o->imag != 0);
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mp_float_hash(o->real) ^ mp_float_hash(o->imag));
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
case MP_UNARY_OP_ABS:
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(o->real*o->real + o->imag*o->imag));
default: return MP_OBJ_NULL; // op not supported
}
}
STATIC mp_obj_t complex_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
STATIC mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_complex_t *lhs = MP_OBJ_TO_PTR(lhs_in);
return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in);
}
@@ -171,7 +170,7 @@ void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag) {
*imag = self->imag;
}
mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) {
mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) {
mp_float_t rhs_real, rhs_imag;
mp_obj_get_complex(rhs_in, &rhs_real, &rhs_imag); // can be any type, this function will convert to float (if possible)
switch (op) {
@@ -229,7 +228,6 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
if (abs1 == 0) {
if (rhs_imag == 0 && rhs_real >= 0) {
lhs_real = (rhs_real == 0);
rhs_real = 0;
} else {
mp_raise_msg(&mp_type_ZeroDivisionError, "0.0 to a complex power");
}