diff options
| author | sommersoft <sommersoft@gmail.com> | 2019-02-22 23:12:11 +0000 |
|---|---|---|
| committer | sommersoft <sommersoft@gmail.com> | 2019-02-22 23:12:11 +0000 |
| commit | a1060747f866073dba4782d3067038cd7148cdb0 (patch) | |
| tree | 71b193e4a5f8217c619da7c59b6e6a70948d29bf /py | |
| parent | ea9200a042e4a0c5fe0e773498d7697a5ea1c07f (diff) | |
| parent | d33923942bfa69c9a9ae30d5ee62f86e402b1b48 (diff) | |
Merge branch 'new_master' into new_freq_in
Diffstat (limited to 'py')
| -rw-r--r-- | py/circuitpy_mpconfig.h | 89 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.mk | 7 | ||||
| -rw-r--r-- | py/moduerrno.c | 4 | ||||
| -rwxr-xr-x | py/mpconfig.h | 5 | ||||
| -rw-r--r-- | py/objmodule.c | 20 | ||||
| -rw-r--r-- | py/runtime.c | 25 |
6 files changed, 99 insertions, 51 deletions
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 721b3c538..6f9705485 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -33,6 +33,9 @@ #ifndef __INCLUDED_MPCONFIG_CIRCUITPY_H #define __INCLUDED_MPCONFIG_CIRCUITPY_H +// This is CircuitPython. +#define CIRCUITPY 1 + // REPR_C encodes qstrs, 31-bit ints, and 30-bit floats in a single 32-bit word. #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C) @@ -123,7 +126,6 @@ #define MICROPY_FATFS_USE_LABEL (1) #define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_MULTI_PARTITION (1) -#define MICROPY_FATFS_NUM_PERSISTENT (1) // Only enable this if you really need it. It allocates a byte cache of this size. // #define MICROPY_FATFS_MAX_SS (4096) @@ -168,7 +170,6 @@ typedef long mp_off_t; { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, - // board specific definitions #include "mpconfigboard.h" @@ -176,20 +177,21 @@ typedef long mp_off_t; // Remove some lesser-used functionality to make small builds fit. #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_BUILTINS_COMPLEX (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_BUILTINS_FROZENSET (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_BUILTINS_REVERSED (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_BUILTINS_STR_CENTER (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_BUILTINS_STR_PARTITION (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_BUILTINS_STR_SPLITLINES (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_UERRNO (CIRCUITPY_FULL_BUILD) +#define MICROPY_MODULE_WEAK_LINKS (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_BUILTINS_COMPLEX (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_BUILTINS_FROZENSET (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_BUILTINS_REVERSED (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_BUILTINS_STR_CENTER (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_BUILTINS_STR_PARTITION (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_BUILTINS_STR_SPLITLINES (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_UERRNO (CIRCUITPY_FULL_BUILD) // Opposite setting is deliberate. -#define MICROPY_PY_UERRNO_ERRORCODE (!CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_URE (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_URE_MATCH_GROUPS (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_URE_MATCH_SPAN_START_END (CIRCUITPY_FULL_BUILD) -#define MICROPY_PY_URE_SUB (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_UERRNO_ERRORCODE (!CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_URE (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_URE_MATCH_GROUPS (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_URE_MATCH_SPAN_START_END (CIRCUITPY_FULL_BUILD) +#define MICROPY_PY_URE_SUB (CIRCUITPY_FULL_BUILD) // LONGINT_IMPL_xxx are defined in the Makefile. // @@ -204,6 +206,7 @@ typedef long mp_off_t; #ifdef LONGINT_IMPL_LONGLONG #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG) +#define MP_SSIZE_MAX (0x7fffffff) #endif @@ -340,8 +343,10 @@ extern const struct _mp_obj_module_t nvm_module; #if CIRCUITPY_OS extern const struct _mp_obj_module_t os_module; #define OS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, +#define OS_MODULE_ALT_NAME { MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&os_module }, #else #define OS_MODULE +#define OS_MODULE_ALT_NAME #endif #if CIRCUITPY_PIXELBUF @@ -417,8 +422,10 @@ extern const struct _mp_obj_module_t supervisor_module; #if CIRCUITPY_TIME extern const struct _mp_obj_module_t time_module; #define TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, +#define TIME_MODULE_ALT_NAME { MP_OBJ_NEW_QSTR(MP_QSTR__time), (mp_obj_t)&time_module }, #else #define TIME_MODULE +#define TIME_MODULE_ALT_NAME #endif #if CIRCUITPY_TOUCHIO @@ -456,17 +463,44 @@ extern const struct _mp_obj_module_t ustack_module; #define USTACK_MODULE #endif +// These modules are not yet in shared-bindings, but we prefer the non-uxxx names. +#if MICROPY_PY_UERRNO +#define ERRNO_MODULE { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, +#else +#define ERRNO_MODULE +#endif + #if MICROPY_PY_UJSON -#define JSON_MODULE { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, +#define JSON_MODULE { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, #else #define JSON_MODULE #endif +#if MICROPY_PY_URE +#define RE_MODULE { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) }, +#else +#define RE_MODULE +#endif + +// Define certain native modules with weak links so they can be replaced with Python +// implementations. This list may grow over time. +#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ + OS_MODULE \ + TIME_MODULE \ + +// Native modules that are weak links can be accessed directly +// by prepending their name with an underscore. This list should correspond to +// MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS, assuming you want the native modules +// to be accessible when overriden. +#define MICROPY_PORT_BUILTIN_MODULE_ALT_NAMES \ + OS_MODULE_ALT_NAME \ + TIME_MODULE_ALT_NAME \ + // This is an inclusive list that should correspond to the CIRCUITPY_XXX list above, -// including dependendencies such as TERMINALIO depending on DISPLAYIO (shown by indentation). +// including dependencies such as TERMINALIO depending on DISPLAYIO (shown by indentation). // Some of these definitions will be blank depending on what is turned on and off. -// -#define MICROPY_PORT_BUILTIN_MODULES \ +// Some are omitted because they're in MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS above. +#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \ ANALOGIO_MODULE \ AUDIOBUSIO_MODULE \ AUDIOIO_MODULE \ @@ -477,6 +511,7 @@ extern const struct _mp_obj_module_t ustack_module; DIGITALIO_MODULE \ TERMINALIO_MODULE \ DISPLAYIO_MODULE \ + ERRNO_MODULE \ GAMEPAD_MODULE \ I2CSLAVE_MODULE \ JSON_MODULE \ @@ -486,23 +521,35 @@ extern const struct _mp_obj_module_t ustack_module; NETWORK_MODULE \ SOCKET_MODULE \ WIZNET_MODULE \ - OS_MODULE \ PIXELBUF_MODULE \ PULSEIO_MODULE \ RANDOM_MODULE \ + RE_MODULE \ RTC_MODULE \ SAMD_MODULE \ STAGE_MODULE \ STORAGE_MODULE \ STRUCT_MODULE \ SUPERVISOR_MODULE \ - TIME_MODULE \ TOUCHIO_MODULE \ UHEAP_MODULE \ USB_HID_MODULE \ USB_MIDI_MODULE \ USTACK_MODULE \ +// If weak links are enabled, just include strong links in the main list of modules, +// and also include the underscore alternate names. +#if MICROPY_MODULE_WEAK_LINKS +#define MICROPY_PORT_BUILTIN_MODULES \ + MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \ + MICROPY_PORT_BUILTIN_MODULE_ALT_NAMES +#else +// If weak links are disabled, included both strong and potentially weak lines +#define MICROPY_PORT_BUILTIN_MODULES \ + MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \ + MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS +#endif + // We need to provide a declaration/definition of alloca() #include <alloca.h> diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 30d5a7554..a4a59170f 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -158,15 +158,12 @@ CIRCUITPY_RTC = 1 endif CFLAGS += -DCIRCUITPY_RTC=$(CIRCUITPY_RTC) +# CIRCUITPY_SAMD is handled in the atmel-samd tree. # Only for SAMD chips. +# Assume not a SAMD build. ifndef CIRCUITPY_SAMD -ifneq ($(findstring sam,$(CHIP_FAMILY)),) -CIRCUITPY_SAMD = $(CIRCUITPY_FULL_BUILD) -else -# Not a SAMD build. CIRCUITPY_SAMD = 0 endif -endif CFLAGS += -DCIRCUITPY_SAMD=$(CIRCUITPY_SAMD) # Currently always off. diff --git a/py/moduerrno.c b/py/moduerrno.c index 7ec6699e7..7915603e4 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -84,7 +84,11 @@ STATIC const mp_obj_dict_t errorcode_dict = { #endif STATIC const mp_rom_map_elem_t mp_module_uerrno_globals_table[] = { +#if CIRCUITPY + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_errno) }, +#else { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uerrno) }, +#endif #if MICROPY_PY_UERRNO_ERRORCODE { MP_ROM_QSTR(MP_QSTR_errorcode), MP_ROM_PTR(&errorcode_dict) }, #endif diff --git a/py/mpconfig.h b/py/mpconfig.h index bb7952a8b..3ec383817 100755 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -45,6 +45,11 @@ #include <mpconfigport.h> #endif +// Is this a CircuitPython build? +#ifndef CIRCUITPY +#define CIRCUITPY 0 +#endif + // Any options not explicitly set in mpconfigport.h will get default // values below. diff --git a/py/objmodule.c b/py/objmodule.c index 828f556f3..469a95976 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -148,11 +148,16 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mp_module_array) }, #endif #if MICROPY_PY_IO +#if CIRCUITPY + { MP_ROM_QSTR(MP_QSTR_io), MP_ROM_PTR(&mp_module_io) }, +#else { MP_ROM_QSTR(MP_QSTR_uio), MP_ROM_PTR(&mp_module_io) }, #endif +#endif #if MICROPY_PY_COLLECTIONS { MP_ROM_QSTR(MP_QSTR_collections), MP_ROM_PTR(&mp_module_collections) }, #endif +// CircuitPython: Now in shared-bindings/, so not defined here. #if MICROPY_PY_STRUCT { MP_ROM_QSTR(MP_QSTR_ustruct), MP_ROM_PTR(&mp_module_ustruct) }, #endif @@ -178,8 +183,13 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { // extmod modules #if MICROPY_PY_UERRNO +#if CIRCUITPY +// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. +// TODO: move to shared-bindings/ +#else { MP_ROM_QSTR(MP_QSTR_uerrno), MP_ROM_PTR(&mp_module_uerrno) }, #endif +#endif #if MICROPY_PY_UCTYPES { MP_ROM_QSTR(MP_QSTR_uctypes), MP_ROM_PTR(&mp_module_uctypes) }, #endif @@ -187,11 +197,21 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { { MP_ROM_QSTR(MP_QSTR_uzlib), MP_ROM_PTR(&mp_module_uzlib) }, #endif #if MICROPY_PY_UJSON +#if CIRCUITPY +// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. +// TODO: move to shared-bindings/ +#else { MP_ROM_QSTR(MP_QSTR_ujson), MP_ROM_PTR(&mp_module_ujson) }, #endif +#endif #if MICROPY_PY_URE +#if CIRCUITPY +// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. +// TODO: move to shared-bindings/ +#else { MP_ROM_QSTR(MP_QSTR_ure), MP_ROM_PTR(&mp_module_ure) }, #endif +#endif #if MICROPY_PY_UHEAPQ { MP_ROM_QSTR(MP_QSTR_uheapq), MP_ROM_PTR(&mp_module_uheapq) }, #endif diff --git a/py/runtime.c b/py/runtime.c index fb62edf73..060748f1b 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -131,31 +131,6 @@ void mp_init(void) { sizeof(MP_STATE_VM(fs_user_mount)) - MICROPY_FATFS_NUM_PERSISTENT); #endif - #if MICROPY_VFS - #if MICROPY_FATFS_NUM_PERSISTENT > 0 - // We preserve the last MICROPY_FATFS_NUM_PERSISTENT mounts because newer - // mounts are put at the front of the list. - mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); - // Count how many mounts we have. - uint8_t count = 0; - while (vfs != NULL) { - vfs = vfs->next; - count++; - } - // Find the vfs MICROPY_FATFS_NUM_PERSISTENT mounts from the end. - vfs = MP_STATE_VM(vfs_mount_table); - for (uint8_t j = 0; j < count - MICROPY_FATFS_NUM_PERSISTENT; j++) { - vfs = vfs->next; - } - MP_STATE_VM(vfs_mount_table) = vfs; - MP_STATE_VM(vfs_cur) = vfs; - #else - // initialise the VFS sub-system - MP_STATE_VM(vfs_cur) = NULL; - MP_STATE_VM(vfs_mount_table) = NULL; - #endif - #endif - #if MICROPY_PY_THREAD_GIL mp_thread_mutex_init(&MP_STATE_VM(gil_mutex)); #endif |
