Skip to content

Commit 1b86e5f

Browse files
committed
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__ <function> >>> object.__new__ <function> >>> object.__class__ <class 'type'> >>> object().__class__ <class 'object'> >>> object.__name__ 'object' >>> 'Hello'.encode() b'Hello' >>> b'Hello'.decode() 'Hello' Named tuple field names from string: namedtuple('Point', 'x y')
1 parent cec9a69 commit 1b86e5f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ports/atmel-samd/mpconfigport.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#define MICROPY_COMP_CONST (1)
2121
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
2222
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
23-
// Turn off for consistency
24-
#define MICROPY_CPYTHON_COMPAT (0)
2523
#define MICROPY_MEM_STATS (0)
2624
#define MICROPY_DEBUG_PRINTERS (0)
2725
#define MICROPY_ENABLE_GC (1)
@@ -57,7 +55,6 @@
5755
#define MICROPY_PY_DESCRIPTORS (1)
5856
#define MICROPY_PY_MATH (0)
5957
#define MICROPY_PY_CMATH (0)
60-
#define MICROPY_PY_IO (0)
6158
#define MICROPY_PY_URANDOM (0)
6259
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
6360
#define MICROPY_PY_STRUCT (0)
@@ -142,14 +139,28 @@ typedef long mp_off_t;
142139
#define CIRCUITPY_MCU_FAMILY samd21
143140
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
144141
#define PORT_HEAP_SIZE (16384 + 4096)
142+
#define MICROPY_CPYTHON_COMPAT (0)
145143
#define MICROPY_MODULE_WEAK_LINKS (0)
144+
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
145+
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
146+
#define MICROPY_PY_FUNCTION_ATTRS (0)
147+
#define MICROPY_PY_IO (0)
148+
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
149+
#define MICROPY_PY_SYS_EXC_INFO (0)
146150
#endif
147151

148152
#ifdef SAMD51
149153
#define CIRCUITPY_MCU_FAMILY samd51
150154
#define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51"
151155
#define PORT_HEAP_SIZE (0x20000) // 128KiB
156+
#define MICROPY_CPYTHON_COMPAT (1)
152157
#define MICROPY_MODULE_WEAK_LINKS (1)
158+
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
159+
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
160+
#define MICROPY_PY_FUNCTION_ATTRS (1)
161+
#define MICROPY_PY_IO (1)
162+
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
163+
#define MICROPY_PY_SYS_EXC_INFO (1)
153164
#endif
154165

155166
#ifdef LONGINT_IMPL_NONE
@@ -315,6 +326,7 @@ extern const struct _mp_obj_module_t usb_hid_module;
315326

316327
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
317328
{ MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
329+
{ MP_ROM_QSTR(MP_QSTR_io), MP_ROM_PTR(&mp_module_io) }, \
318330
{ MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&os_module) }, \
319331
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
320332

0 commit comments

Comments
 (0)