From 1b86e5fc8362a913a0ef7de01cce68c980238fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Date: Sun, 7 Oct 2018 20:43:39 +0200 Subject: [PATCH] samd51: Enable functionality to support CPython stdlib This enables various things in order to support the CPython standard library. MICROPY_PY_BUILTINS_NOTIMPLEMENTED: Support NotImplemented for easy conversion of stdlib. It doesn't do fallbacks though, only raises TypeError. MICROPY_PY_COLLECTIONS_ORDEREDDICT: collections.OrderedDict MICROPY_PY_FUNCTION_ATTRS: Support function.__name__ for use as key in the function attribute workaround. MICROPY_PY_IO: uio module: BytesIO, FileIO, StringIO, TextIOWrapper Also add 'io' alias. MICROPY_PY_REVERSE_SPECIAL_METHODS: Support the __r*__ special methods. MICROPY_PY_SYS_EXC_INFO: sys.exc_info() used by unittest when collecting exceptions. MICROPY_CPYTHON_COMPAT: Some of the things it adds: >>> object.__init__ >>> object.__new__ >>> object.__class__ >>> object().__class__ >>> object.__name__ 'object' >>> 'Hello'.encode() b'Hello' >>> b'Hello'.decode() 'Hello' Named tuple field names from string: namedtuple('Point', 'x y') --- ports/atmel-samd/mpconfigport.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index afdbf0cd82..38eabf7480 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -20,8 +20,6 @@ #define MICROPY_COMP_CONST (1) #define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1) #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1) -// Turn off for consistency -#define MICROPY_CPYTHON_COMPAT (0) #define MICROPY_MEM_STATS (0) #define MICROPY_DEBUG_PRINTERS (0) #define MICROPY_ENABLE_GC (1) @@ -57,7 +55,6 @@ #define MICROPY_PY_DESCRIPTORS (1) #define MICROPY_PY_MATH (0) #define MICROPY_PY_CMATH (0) -#define MICROPY_PY_IO (0) #define MICROPY_PY_URANDOM (0) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (0) #define MICROPY_PY_STRUCT (0) @@ -142,14 +139,28 @@ typedef long mp_off_t; #define CIRCUITPY_MCU_FAMILY samd21 #define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21" #define PORT_HEAP_SIZE (16384 + 4096) +#define MICROPY_CPYTHON_COMPAT (0) #define MICROPY_MODULE_WEAK_LINKS (0) +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0) +#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0) +#define MICROPY_PY_FUNCTION_ATTRS (0) +#define MICROPY_PY_IO (0) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) +#define MICROPY_PY_SYS_EXC_INFO (0) #endif #ifdef SAMD51 #define CIRCUITPY_MCU_FAMILY samd51 #define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51" #define PORT_HEAP_SIZE (0x20000) // 128KiB +#define MICROPY_CPYTHON_COMPAT (1) #define MICROPY_MODULE_WEAK_LINKS (1) +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1) +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_IO (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) +#define MICROPY_PY_SYS_EXC_INFO (1) #endif #ifdef LONGINT_IMPL_NONE @@ -315,6 +326,7 @@ extern const struct _mp_obj_module_t usb_hid_module; #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \ + { MP_ROM_QSTR(MP_QSTR_io), MP_ROM_PTR(&mp_module_io) }, \ { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&os_module) }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \