summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDavePutz <dwputz@gmail.com>2020-09-14 16:50:40 -0500
committerGitHub <noreply@github.com>2020-09-14 16:50:40 -0500
commit2a2a8d64571bf93e2a166626841555fe1753a565 (patch)
treea4b7ba795a6e17d4d0b32abd942af380b1c36e57 /py
parent4a3be4df91837a1c71fcbd62e041f7c45cd4dd4b (diff)
parent3d8bac50e41acc286cefbde9e052c5ccb335101e (diff)
Merge pull request #28 from adafruit/main
Merge from adafruit/main
Diffstat (limited to 'py')
-rw-r--r--py/binary.c9
-rw-r--r--py/builtinimport.c2
-rw-r--r--py/circuitpy_defns.mk68
-rw-r--r--py/circuitpy_mpconfig.h84
-rw-r--r--py/circuitpy_mpconfig.mk46
-rw-r--r--py/makeqstrdata.py47
-rw-r--r--py/misc.h2
-rw-r--r--py/mkrules.mk5
-rw-r--r--py/modbuiltins.c3
-rw-r--r--py/modstruct.c17
-rw-r--r--py/mpz.h3
-rw-r--r--py/obj.c30
-rw-r--r--py/obj.h28
-rw-r--r--py/objarray.c7
-rw-r--r--py/objdict.c2
-rw-r--r--py/objexcept.c10
-rw-r--r--py/objint.c29
-rw-r--r--py/objint.h1
-rw-r--r--py/objint_longlong.c11
-rw-r--r--py/objint_mpz.c6
-rw-r--r--py/objlist.c2
-rw-r--r--py/objset.c3
-rw-r--r--py/objstr.c18
-rw-r--r--py/objstrunicode.c6
-rw-r--r--py/objtype.c12
-rw-r--r--py/proto.c4
-rw-r--r--py/py.mk2
-rwxr-xr-xpy/qstr.c1
-rw-r--r--py/runtime.c66
-rw-r--r--py/runtime.h4
30 files changed, 410 insertions, 118 deletions
diff --git a/py/binary.c b/py/binary.c
index cd0f1aa4d..b85edba62 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -126,7 +126,6 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
break;
case BYTEARRAY_TYPECODE:
case 'B':
- case 'x': // value will be discarded
val = ((unsigned char*)p)[index];
break;
case 'h':
@@ -330,7 +329,11 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
}
}
- mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);
+ if (val_type == 'x') {
+ memset(p, 0, 1);
+ } else {
+ mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);
+ }
}
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in) {
@@ -379,8 +382,6 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
case 'B':
((unsigned char*)p)[index] = val;
break;
- case 'x':
- ((unsigned char*)p)[index] = 0;
case 'h':
((short*)p)[index] = val;
break;
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 597819f55..47ffab519 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -488,7 +488,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
// afterwards.
gc_collect();
}
- if (outer_module_obj != MP_OBJ_NULL) {
+ if (outer_module_obj != MP_OBJ_NULL && VERIFY_PTR(outer_module_obj) ) {
qstr s = qstr_from_strn(mod_str + last, i - last);
mp_store_attr(outer_module_obj, s, module_obj);
// The above store can cause a dictionary rehash and new allocation. So,
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index a39e0c9dd..0e87287c1 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -31,6 +31,7 @@ BASE_CFLAGS = \
-fsingle-precision-constant \
-fno-strict-aliasing \
-Wdouble-promotion \
+ -Wimplicit-fallthrough=2 \
-Wno-endif-labels \
-Wstrict-prototypes \
-Werror-implicit-function-declaration \
@@ -145,7 +146,7 @@ ifeq ($(CIRCUITPY_DIGITALIO),1)
SRC_PATTERNS += digitalio/%
endif
ifeq ($(CIRCUITPY_DISPLAYIO),1)
-SRC_PATTERNS += displayio/% terminalio/% fontio/%
+SRC_PATTERNS += displayio/%
endif
ifeq ($(CIRCUITPY_VECTORIO),1)
SRC_PATTERNS += vectorio/%
@@ -168,6 +169,9 @@ endif
ifeq ($(CIRCUITPY_I2CPERIPHERAL),1)
SRC_PATTERNS += i2cperipheral/%
endif
+ifeq ($(CIRCUITPY_IPADDRESS),1)
+SRC_PATTERNS += ipaddress/%
+endif
ifeq ($(CIRCUITPY_MATH),1)
SRC_PATTERNS += math/%
endif
@@ -198,11 +202,14 @@ endif
ifeq ($(CIRCUITPY_RGBMATRIX),1)
SRC_PATTERNS += rgbmatrix/%
endif
+ifeq ($(CIRCUITPY_PS2IO),1)
+SRC_PATTERNS += ps2io/%
+endif
ifeq ($(CIRCUITPY_PULSEIO),1)
SRC_PATTERNS += pulseio/%
endif
-ifeq ($(CIRCUITPY_PS2IO),1)
-SRC_PATTERNS += ps2io/%
+ifeq ($(CIRCUITPY_PWMIO),1)
+SRC_PATTERNS += pwmio/%
endif
ifeq ($(CIRCUITPY_RANDOM),1)
SRC_PATTERNS += random/%
@@ -222,6 +229,15 @@ endif
ifeq ($(CIRCUITPY_SDIOIO),1)
SRC_PATTERNS += sdioio/%
endif
+ifeq ($(CIRCUITPY_SHARPDISPLAY),1)
+SRC_PATTERNS += sharpdisplay/%
+endif
+ifeq ($(CIRCUITPY_SOCKETPOOL),1)
+SRC_PATTERNS += socketpool/%
+endif
+ifeq ($(CIRCUITPY_SSL),1)
+SRC_PATTERNS += ssl/%
+endif
ifeq ($(CIRCUITPY_STAGE),1)
SRC_PATTERNS += _stage/%
endif
@@ -234,6 +250,9 @@ endif
ifeq ($(CIRCUITPY_SUPERVISOR),1)
SRC_PATTERNS += supervisor/%
endif
+ifeq ($(CIRCUITPY_TERMINALIO),1)
+SRC_PATTERNS += terminalio/% fontio/%
+endif
ifeq ($(CIRCUITPY_TIME),1)
SRC_PATTERNS += time/%
endif
@@ -255,6 +274,9 @@ endif
ifeq ($(CIRCUITPY_WATCHDOG),1)
SRC_PATTERNS += watchdog/%
endif
+ifeq ($(CIRCUITPY_WIFI),1)
+SRC_PATTERNS += wifi/%
+endif
ifeq ($(CIRCUITPY_PEW),1)
SRC_PATTERNS += _pew/%
endif
@@ -310,10 +332,11 @@ SRC_COMMON_HAL_ALL = \
os/__init__.c \
ps2io/Ps2.c \
ps2io/__init__.c \
- pulseio/PWMOut.c \
pulseio/PulseIn.c \
pulseio/PulseOut.c \
pulseio/__init__.c \
+ pwmio/PWMOut.c \
+ pwmio/__init__.c \
rgbmatrix/RGBMatrix.c \
rgbmatrix/__init__.c \
rotaryio/IncrementalEncoder.c \
@@ -322,11 +345,29 @@ SRC_COMMON_HAL_ALL = \
rtc/__init__.c \
sdioio/SDCard.c \
sdioio/__init__.c \
+ socketpool/__init__.c \
+ socketpool/SocketPool.c \
+ socketpool/Socket.c \
+ ssl/__init__.c \
+ ssl/SSLContext.c \
supervisor/Runtime.c \
supervisor/__init__.c \
watchdog/WatchDogMode.c \
watchdog/WatchDogTimer.c \
watchdog/__init__.c \
+ wifi/Network.c \
+ wifi/Radio.c \
+ wifi/ScannedNetworks.c \
+ wifi/__init__.c \
+
+ifeq ($(CIRCUITPY_BLEIO_HCI),1)
+# Helper code for _bleio HCI.
+SRC_C += \
+ common-hal/_bleio/att.c \
+ common-hal/_bleio/hci.c \
+
+endif
+
SRC_COMMON_HAL = $(filter $(SRC_PATTERNS), $(SRC_COMMON_HAL_ALL))
@@ -395,6 +436,8 @@ SRC_SHARED_MODULE_ALL = \
fontio/__init__.c \
framebufferio/FramebufferDisplay.c \
framebufferio/__init__.c \
+ ipaddress/IPv4Address.c \
+ ipaddress/__init__.c \
sdcardio/SDCard.c \
sdcardio/__init__.c \
gamepad/GamePad.c \
@@ -409,6 +452,8 @@ SRC_SHARED_MODULE_ALL = \
random/__init__.c \
rgbmatrix/RGBMatrix.c \
rgbmatrix/__init__.c \
+ sharpdisplay/SharpMemoryFramebuffer.c \
+ sharpdisplay/__init__.c \
socket/__init__.c \
storage/__init__.c \
struct/__init__.c \
@@ -427,7 +472,7 @@ SRC_SHARED_MODULE_ALL = \
SRC_SHARED_MODULE = $(filter $(SRC_PATTERNS), $(SRC_SHARED_MODULE_ALL))
# Use the native touchio if requested. This flag is set conditionally in, say, mpconfigport.h.
-# The presence of common-hal/touchio/* # does not imply it's available for all chips in a port,
+# The presence of common-hal/touchio/* does not imply it's available for all chips in a port,
# so there is an explicit flag. For example, SAMD21 touchio is native, but SAMD51 is not.
ifeq ($(CIRCUITPY_TOUCHIO_USE_NATIVE),1)
SRC_COMMON_HAL_ALL += \
@@ -438,6 +483,14 @@ SRC_SHARED_MODULE_ALL += \
touchio/TouchIn.c \
touchio/__init__.c
endif
+
+# If supporting _bleio via HCI, make devices/ble_hci/common-hal/_bleio be includable,
+# and use C source files in devices/ble_hci/common-hal.
+ifeq ($(CIRCUITPY_BLEIO_HCI),1)
+INC += -I$(TOP)/devices/ble_hci
+DEVICES_MODULES += $(TOP)/devices/ble_hci
+endif
+
ifeq ($(CIRCUITPY_AUDIOMP3),1)
SRC_MOD += $(addprefix lib/mp3/src/, \
bitstream.c \
@@ -471,6 +524,11 @@ $(filter $(SRC_PATTERNS), \
displayio/display_core.c \
)
+SRC_COMMON_HAL_INTERNAL = \
+$(filter $(SRC_PATTERNS), \
+ _bleio/ \
+)
+
ifeq ($(INTERNAL_LIBM),1)
SRC_LIBM = \
$(addprefix lib/,\
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index 255ab99b9..0fafbe876 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -185,6 +185,7 @@ typedef long mp_off_t;
// Turning off FULL_BUILD removes some functionality to reduce flash size on tiny SAMD21s
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (CIRCUITPY_FULL_BUILD)
#define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD)
+#define MICROPY_PY_BUILTINS_POW3 (CIRCUITPY_FULL_BUILD)
#define MICROPY_COMP_FSTRING_LITERAL (MICROPY_CPYTHON_COMPAT)
#define MICROPY_MODULE_WEAK_LINKS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD)
@@ -347,16 +348,27 @@ extern const struct _mp_obj_module_t displayio_module;
extern const struct _mp_obj_module_t fontio_module;
extern const struct _mp_obj_module_t terminalio_module;
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
-#define FONTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_fontio), (mp_obj_t)&fontio_module },
-#define TERMINALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_terminalio), (mp_obj_t)&terminalio_module },
#ifndef CIRCUITPY_DISPLAY_LIMIT
#define CIRCUITPY_DISPLAY_LIMIT (1)
#endif
#else
#define DISPLAYIO_MODULE
+#define CIRCUITPY_DISPLAY_LIMIT (0)
+#endif
+
+#if CIRCUITPY_DISPLAYIO && CIRCUITPY_TERMINALIO
+#define FONTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_fontio), (mp_obj_t)&fontio_module },
+#define TERMINALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_terminalio), (mp_obj_t)&terminalio_module },
+#else
#define FONTIO_MODULE
#define TERMINALIO_MODULE
-#define CIRCUITPY_DISPLAY_LIMIT (0)
+#endif
+
+#if CIRCUITPY_ESPIDF
+extern const struct _mp_obj_module_t espidf_module;
+#define ESPIDF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_espidf),(mp_obj_t)&espidf_module },
+#else
+#define ESPIDF_MODULE
#endif
#if CIRCUITPY_FRAMEBUFFERIO
@@ -416,6 +428,13 @@ extern const struct _mp_obj_module_t i2cperipheral_module;
#define I2CPERIPHERAL_MODULE
#endif
+#if CIRCUITPY_IPADDRESS
+extern const struct _mp_obj_module_t ipaddress_module;
+#define IPADDRESS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ipaddress), (mp_obj_t)&ipaddress_module },
+#else
+#define IPADDRESS_MODULE
+#endif
+
#if CIRCUITPY_MATH
extern const struct _mp_obj_module_t math_module;
#define MATH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module },
@@ -499,11 +518,11 @@ extern const struct _mp_obj_module_t pixelbuf_module;
#define PIXELBUF_MODULE
#endif
-#if CIRCUITPY_RGBMATRIX
-extern const struct _mp_obj_module_t rgbmatrix_module;
-#define RGBMATRIX_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_rgbmatrix),(mp_obj_t)&rgbmatrix_module },
+#if CIRCUITPY_PS2IO
+extern const struct _mp_obj_module_t ps2io_module;
+#define PS2IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ps2io), (mp_obj_t)&ps2io_module },
#else
-#define RGBMATRIX_MODULE
+#define PS2IO_MODULE
#endif
#if CIRCUITPY_PULSEIO
@@ -513,11 +532,18 @@ extern const struct _mp_obj_module_t pulseio_module;
#define PULSEIO_MODULE
#endif
-#if CIRCUITPY_PS2IO
-extern const struct _mp_obj_module_t ps2io_module;
-#define PS2IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ps2io), (mp_obj_t)&ps2io_module },
+#if CIRCUITPY_PWMIO
+extern const struct _mp_obj_module_t pwmio_module;
+#define PWMIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_pwmio), (mp_obj_t)&pwmio_module },
#else
-#define PS2IO_MODULE
+#define PWMIO_MODULE
+#endif
+
+#if CIRCUITPY_RGBMATRIX
+extern const struct _mp_obj_module_t rgbmatrix_module;
+#define RGBMATRIX_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_rgbmatrix),(mp_obj_t)&rgbmatrix_module },
+#else
+#define RGBMATRIX_MODULE
#endif
#if CIRCUITPY_RANDOM
@@ -562,6 +588,28 @@ extern const struct _mp_obj_module_t sdioio_module;
#define SDIOIO_MODULE
#endif
+
+#if CIRCUITPY_SHARPDISPLAY
+extern const struct _mp_obj_module_t sharpdisplay_module;
+#define SHARPDISPLAY_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sharpdisplay),(mp_obj_t)&sharpdisplay_module },
+#else
+#define SHARPDISPLAY_MODULE
+#endif
+
+#if CIRCUITPY_SOCKETPOOL
+extern const struct _mp_obj_module_t socketpool_module;
+#define SOCKETPOOL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_socketpool), (mp_obj_t)&socketpool_module },
+#else
+#define SOCKETPOOL_MODULE
+#endif
+
+#if CIRCUITPY_SSL
+extern const struct _mp_obj_module_t ssl_module;
+#define SSL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ssl), (mp_obj_t)&ssl_module },
+#else
+#define SSL_MODULE
+#endif
+
#if CIRCUITPY_STAGE
extern const struct _mp_obj_module_t stage_module;
#define STAGE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__stage), (mp_obj_t)&stage_module },
@@ -672,6 +720,13 @@ extern const struct _mp_obj_module_t watchdog_module;
#define WATCHDOG_MODULE
#endif
+#if CIRCUITPY_WIFI
+extern const struct _mp_obj_module_t wifi_module;
+#define WIFI_MODULE { MP_ROM_QSTR(MP_QSTR_wifi), MP_ROM_PTR(&wifi_module) },
+#else
+#define WIFI_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 \
@@ -710,12 +765,14 @@ extern const struct _mp_obj_module_t watchdog_module;
TERMINALIO_MODULE \
VECTORIO_MODULE \
ERRNO_MODULE \
+ ESPIDF_MODULE \
FRAMEBUFFERIO_MODULE \
FREQUENCYIO_MODULE \
GAMEPAD_MODULE \
GAMEPADSHIFT_MODULE \
GNSS_MODULE \
I2CPERIPHERAL_MODULE \
+ IPADDRESS_MODULE \
JSON_MODULE \
MATH_MODULE \
_EVE_MODULE \
@@ -729,6 +786,7 @@ extern const struct _mp_obj_module_t watchdog_module;
PIXELBUF_MODULE \
PS2IO_MODULE \
PULSEIO_MODULE \
+ PWMIO_MODULE \
RANDOM_MODULE \
RE_MODULE \
RGBMATRIX_MODULE \
@@ -737,6 +795,9 @@ extern const struct _mp_obj_module_t watchdog_module;
SAMD_MODULE \
SDCARDIO_MODULE \
SDIOIO_MODULE \
+ SHARPDISPLAY_MODULE \
+ SOCKETPOOL_MODULE \
+ SSL_MODULE \
STAGE_MODULE \
STORAGE_MODULE \
STRUCT_MODULE \
@@ -747,6 +808,7 @@ extern const struct _mp_obj_module_t watchdog_module;
USB_MIDI_MODULE \
USTACK_MODULE \
WATCHDOG_MODULE \
+ WIFI_MODULE \
// If weak links are enabled, just include strong links in the main list of modules,
// and also include the underscore alternate names.
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index 2cf8426e5..a2da9c42f 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -80,6 +80,10 @@ CFLAGS += -DCIRCUITPY_BITBANGIO=$(CIRCUITPY_BITBANGIO)
CIRCUITPY_BLEIO ?= 0
CFLAGS += -DCIRCUITPY_BLEIO=$(CIRCUITPY_BLEIO)
+# _bleio can be supported on most any board via HCI
+CIRCUITPY_BLEIO_HCI ?= 0
+CFLAGS += -DCIRCUITPY_BLEIO_HCI=$(CIRCUITPY_BLEIO_HCI)
+
CIRCUITPY_BOARD ?= 1
CFLAGS += -DCIRCUITPY_BOARD=$(CIRCUITPY_BOARD)
@@ -95,7 +99,17 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
+# CIRCUITPY_ESPIDF is handled in the esp32s2 tree.
+# Only for ESP32S chips.
+# Assume not a ESP build.
+CIRCUITPY_ESPIDF ?= 0
+CFLAGS += -DCIRCUITPY_ESPIDF=$(CIRCUITPY_ESPIDF)
+
+ifeq ($(CIRCUITPY_DISPLAYIO),1)
+CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD)
+else
CIRCUITPY_FRAMEBUFFERIO ?= 0
+endif
CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO)
CIRCUITPY_VECTORIO ?= $(CIRCUITPY_DISPLAYIO)
@@ -116,6 +130,9 @@ CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS)
CIRCUITPY_I2CPERIPHERAL ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_I2CPERIPHERAL=$(CIRCUITPY_I2CPERIPHERAL)
+CIRCUITPY_IPADDRESS ?= $(CIRCUITPY_WIFI)
+CFLAGS += -DCIRCUITPY_IPADDRESS=$(CIRCUITPY_IPADDRESS)
+
CIRCUITPY_MATH ?= 1
CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH)
@@ -145,19 +162,23 @@ CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF)
# Only for SAMD boards for the moment
-CIRCUITPY_RGBMATRIX ?= 0
-CFLAGS += -DCIRCUITPY_RGBMATRIX=$(CIRCUITPY_RGBMATRIX)
+CIRCUITPY_PS2IO ?= 0
+CFLAGS += -DCIRCUITPY_PS2IO=$(CIRCUITPY_PS2IO)
CIRCUITPY_PULSEIO ?= 1
CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO)
-# Only for SAMD boards for the moment
-CIRCUITPY_PS2IO ?= 0
-CFLAGS += -DCIRCUITPY_PS2IO=$(CIRCUITPY_PS2IO)
+# For now we tie PWMIO to PULSEIO so they always both exist. In CircuitPython 7
+# we can enable and disable them separately once PWMOut is removed from `pulseio`.
+CIRCUITPY_PWMIO = $(CIRCUITPY_PULSEIO)
+CFLAGS += -DCIRCUITPY_PWMIO=$(CIRCUITPY_PWMIO)
CIRCUITPY_RANDOM ?= 1
CFLAGS += -DCIRCUITPY_RANDOM=$(CIRCUITPY_RANDOM)
+CIRCUITPY_RGBMATRIX ?= 0
+CFLAGS += -DCIRCUITPY_RGBMATRIX=$(CIRCUITPY_RGBMATRIX)
+
CIRCUITPY_ROTARYIO ?= 1
CFLAGS += -DCIRCUITPY_ROTARYIO=$(CIRCUITPY_ROTARYIO)
@@ -176,6 +197,15 @@ CFLAGS += -DCIRCUITPY_SDCARDIO=$(CIRCUITPY_SDCARDIO)
CIRCUITPY_SDIOIO ?= 0
CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO)
+CIRCUITPY_SHARPDISPLAY ?= $(CIRCUITPY_FRAMEBUFFERIO)
+CFLAGS += -DCIRCUITPY_SHARPDISPLAY=$(CIRCUITPY_SHARPDISPLAY)
+
+CIRCUITPY_SOCKETPOOL ?= $(CIRCUITPY_WIFI)
+CFLAGS += -DCIRCUITPY_SOCKETPOOL=$(CIRCUITPY_SOCKETPOOL)
+
+CIRCUITPY_SSL ?= $(CIRCUITPY_WIFI)
+CFLAGS += -DCIRCUITPY_SSL=$(CIRCUITPY_SSL)
+
# Currently always off.
CIRCUITPY_STAGE ?= 0
CFLAGS += -DCIRCUITPY_STAGE=$(CIRCUITPY_STAGE)
@@ -189,6 +219,9 @@ CFLAGS += -DCIRCUITPY_STRUCT=$(CIRCUITPY_STRUCT)
CIRCUITPY_SUPERVISOR ?= 1
CFLAGS += -DCIRCUITPY_SUPERVISOR=$(CIRCUITPY_SUPERVISOR)
+CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO)
+CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
+
CIRCUITPY_TIME ?= 1
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)
@@ -245,6 +278,9 @@ CFLAGS += -DCIRCUITPY_ULAB=$(CIRCUITPY_ULAB)
CIRCUITPY_WATCHDOG ?= 0
CFLAGS += -DCIRCUITPY_WATCHDOG=$(CIRCUITPY_WATCHDOG)
+CIRCUITPY_WIFI ?= 0
+CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
+
# Enabled micropython.native decorator (experimental)
CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index df2c687e5..721fa8320 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -100,13 +100,30 @@ def translate(translation_file, i18ns):
translations.append((original, translation))
return translations
+def frequent_ngrams(corpus, sz, n):
+ return collections.Counter(corpus[i:i+sz] for i in range(len(corpus)-sz)).most_common(n)
+
+def encode_ngrams(translation, ngrams):
+ if len(ngrams) > 32:
+ start = 0xe000
+ else:
+ start = 0x80
+ for i, g in enumerate(ngrams):
+ translation = translation.replace(g, chr(start + i))
+ return translation
+
+def decode_ngrams(compressed, ngrams):
+ if len(ngrams) > 32:
+ start, end = 0xe000, 0xf8ff
+ else:
+ start, end = 0x80, 0x9f
+ return "".join(ngrams[ord(c) - start] if (start <= ord(c) <= end) else c for c in compressed)
+
def compute_huffman_coding(translations, qstrs, compression_filename):
all_strings = [x[1] for x in translations]
-
- # go through each qstr and print it out
- for _, _, qstr in qstrs.values():
- all_strings.append(qstr)
all_strings_concat = "".join(all_strings)
+ ngrams = [i[0] for i in frequent_ngrams(all_strings_concat, 2, 32)]
+ all_strings_concat = encode_ngrams(all_strings_concat, ngrams)
counts = collections.Counter(all_strings_concat)
cb = huffman.codebook(counts.items())
values = []
@@ -129,10 +146,12 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
last_l = l
lengths = bytearray()
print("// length count", length_count)
+ print("// bigrams", ngrams)
for i in range(1, max(length_count) + 2):
lengths.append(length_count.get(i, 0))
print("// values", values, "lengths", len(lengths), lengths)
- print("// estimated total memory size", len(lengths) + 2*len(values) + sum(len(cb[u]) for u in all_strings_concat))
+ ngramdata = [ord(ni) for i in ngrams for ni in i]
+ print("// estimated total memory size", len(lengths) + 2*len(values) + 2 * len(ngramdata) + sum((len(cb[u]) + 7)//8 for u in all_strings_concat))
print("//", values, lengths)
values_type = "uint16_t" if max(ord(u) for u in values) > 255 else "uint8_t"
max_translation_encoded_length = max(len(translation.encode("utf-8")) for original,translation in translations)
@@ -140,10 +159,18 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths))))
f.write("const {} values[] = {{ {} }};\n".format(values_type, ", ".join(str(ord(u)) for u in values)))
f.write("#define compress_max_length_bits ({})\n".format(max_translation_encoded_length.bit_length()))
- return values, lengths
+ f.write("const {} bigrams[] = {{ {} }};\n".format(values_type, ", ".join(str(u) for u in ngramdata)))
+ if len(ngrams) > 32:
+ bigram_start = 0xe000
+ else:
+ bigram_start = 0x80
+ bigram_end = bigram_start + len(ngrams) - 1 # End is inclusive
+ f.write("#define bigram_start {}\n".format(bigram_start))
+ f.write("#define bigram_end {}\n".format(bigram_end))
+ return values, lengths, ngrams
def decompress(encoding_table, encoded, encoded_length_bits):
- values, lengths = encoding_table
+ values, lengths, ngrams = encoding_table
dec = []
this_byte = 0
this_bit = 7
@@ -191,6 +218,7 @@ def decompress(encoding_table, encoded, encoded_length_bits):
searched_length += lengths[bit_length]
v = values[searched_length + bits - max_code]
+ v = decode_ngrams(v, ngrams)
i += len(v.encode('utf-8'))
dec.append(v)
return ''.join(dec)
@@ -198,7 +226,8 @@ def decompress(encoding_table, encoded, encoded_length_bits):
def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded):
if not isinstance(decompressed, str):
raise TypeError()
- values, lengths = encoding_table
+ values, lengths, ngrams = encoding_table
+ decompressed = encode_ngrams(decompressed, ngrams)
enc = bytearray(len(decompressed) * 3)
#print(decompressed)
#print(lengths)
@@ -259,8 +288,6 @@ def compress(encoding_table, decompressed, encoded_length_bits, len_translation_
current_bit -= 1
if current_bit != 7:
current_byte += 1
- if current_byte > len(decompressed):
- print("Note: compression increased length", repr(decompressed), len(decompressed), current_byte, file=sys.stderr)
return enc[:current_byte]
def qstr_escape(qst):
diff --git a/py/misc.h b/py/misc.h
index 944c0a716..6ed256e70 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -120,6 +120,8 @@ size_t m_get_peak_bytes_allocated(void);
// align ptr to the nearest multiple of "alignment"
#define MP_ALIGN(ptr, alignment) (void*)(((uintptr_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))
+#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+
/** unichar / UTF-8 *********************************************/
#if MICROPY_PY_BUILTINS_STR_UNICODE
diff --git a/py/mkrules.mk b/py/mkrules.mk
index 13a73b90e..0b3ecc0e1 100644
--- a/py/mkrules.mk
+++ b/py/mkrules.mk
@@ -42,7 +42,7 @@ $(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
$(RM) -f $(@:.o=.d)
endef
-vpath %.c . $(TOP) $(USER_C_MODULES)
+vpath %.c . $(TOP) $(USER_C_MODULES) $(DEVICES_MODULES)
$(BUILD)/%.o: %.c
$(call compile_c)
@@ -56,8 +56,7 @@ $(BUILD)/%.o: %.c
QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp
-vpath %.c . $(TOP) $(USER_C_MODULES)
-
+vpath %.c . $(TOP) $(USER_C_MODULES) $(DEVICES_MODULES)
$(BUILD)/%.pp: %.c
$(STEPECHO) "PreProcess $<"
$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 905c3471f..41e1d4e48 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -726,6 +726,9 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_NameError), MP_ROM_PTR(&mp_type_NameError) },
{ MP_ROM_QSTR(MP_QSTR_NotImplementedError), MP_ROM_PTR(&mp_type_NotImplementedError) },
{ MP_ROM_QSTR(MP_QSTR_OSError), MP_ROM_PTR(&mp_type_OSError) },
+ { MP_ROM_QSTR(MP_QSTR_TimeoutError), MP_ROM_PTR(&mp_type_TimeoutError) },
+ { MP_ROM_QSTR(MP_QSTR_ConnectionError), MP_ROM_PTR(&mp_type_ConnectionError) },
+ { MP_ROM_QSTR(MP_QSTR_BrokenPipeError), MP_ROM_PTR(&mp_type_BrokenPipeError) },
{ MP_ROM_QSTR(MP_QSTR_OverflowError), MP_ROM_PTR(&mp_type_OverflowError) },
{ MP_ROM_QSTR(MP_QSTR_RuntimeError), MP_ROM_PTR(&mp_type_RuntimeError) },
#if MICROPY_PY_ASYNC_AWAIT
diff --git a/py/modstruct.c b/py/modstruct.c
index fe766a4de..7675de275 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -183,16 +183,21 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_from_obj, 2, 3, struct_unpack_
// This function assumes there is enough room in p to store all the values
STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) {
+ size_t size;
+ size_t count = calc_size_items(mp_obj_str_get_str(fmt_in), &size);
+ if (count != n_args) {
+#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
+ mp_raise_ValueError(NULL);
+#else
+ mp_raise_ValueError_varg(translate("pack expected %d items for packing (got %d)"), count, n_args);
+#endif
+ }
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
size_t i;
for (i = 0; i < n_args;) {
mp_uint_t cnt = 1;
- if (*fmt == '\0') {
- // more arguments given than used by format string; CPython raises struct.error here
- break;
- }
if (unichar_isdigit(*fmt)) {
cnt = get_fmt_num(&fmt);
}
@@ -208,8 +213,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
memset(p + to_copy, 0, cnt - to_copy);
p += cnt;
} else {
- // If we run out of args then we just finish; CPython would raise struct.error
- while (cnt-- && i < n_args) {
+ while (cnt--) {
mp_binary_set_val(fmt_type, *fmt, args[i], &p);
// Pad bytes don't have a corresponding argument.
if (*fmt != 'x') {
@@ -222,7 +226,6 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
}
STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) {
- // TODO: "The arguments must match the values required by the format exactly."
mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
vstr_t vstr;
vstr_init_len(&vstr, size);
diff --git a/py/mpz.h b/py/mpz.h
index e412f5cce..ade04a4f7 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -135,6 +135,9 @@ void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs);
static inline size_t mpz_max_num_bits(const mpz_t *z) { return z->len * MPZ_DIG_SIZE; }
+static inline size_t mpz_num_bits(const mpz_t *z) {
+ size_t last_bits = (8 * (sizeof(long) - sizeof(mpz_dig_t))) - __builtin_clzl(z->dig[z->len-1]);
+ return z->len * MPZ_DIG_SIZE + last_bits; }
mp_int_t mpz_hash(const mpz_t *z);
bool mpz_as_int_checked(const mpz_t *z, mp_int_t *value);
bool mpz_as_uint_checked(const mpz_t *z, mp_uint_t *value);
diff --git a/py/obj.c b/py/obj.c
index 7644b5de8..9dc0cf474 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -58,7 +58,7 @@ mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
}
const char *mp_obj_get_type_str(mp_const_obj_t o_in) {
- return qstr_str(mp_obj_get_type(o_in)->name);
+ return qstr_str(mp_obj_get_type_qstr(o_in));
}
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
@@ -67,6 +67,8 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#ifdef RUN_BACKGROUND_TASKS
RUN_BACKGROUND_TASKS;
#endif
+ mp_handle_pending();
+
#ifndef NDEBUG
if (o_in == MP_OBJ_NULL) {
mp_print_str(print, "(nil)");
@@ -260,10 +262,10 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
return mp_obj_int_get_checked(arg);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- mp_raise_TypeError(translate("can't convert to int"));
+ mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_int);
} else {
mp_raise_TypeError_varg(
- translate("can't convert %s to int"), mp_obj_get_type_str(arg));
+ translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
}
}
}
@@ -323,10 +325,10 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
if (!mp_obj_get_float_maybe(arg, &val)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- mp_raise_TypeError(translate("can't convert to float"));
+ mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_float);
} else {
mp_raise_TypeError_varg(
- translate("can't convert %s to float"), mp_obj_get_type_str(arg));
+ translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_float);
}
}
@@ -356,10 +358,10 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
mp_obj_complex_get(arg, real, imag);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- mp_raise_TypeError(translate("can't convert to complex"));
+ mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_complex);
} else {
mp_raise_TypeError_varg(
- translate("can't convert %s to complex"), mp_obj_get_type_str(arg));
+ translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_complex);
}
}
}
@@ -377,7 +379,7 @@ void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
mp_raise_TypeError(translate("expected tuple/list"));
} else {
mp_raise_TypeError_varg(
- translate("object '%s' is not a tuple or list"), mp_obj_get_type_str(o));
+ translate("object '%q' is not a tuple or list"), mp_obj_get_type_qstr(o));
}
}
}
@@ -406,8 +408,8 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
mp_raise_TypeError(translate("indices must be integers"));
} else {
mp_raise_TypeError_varg(
- translate("%q indices must be integers, not %s"),
- type->name, mp_obj_get_type_str(index));
+ translate("%q indices must be integers, not %q"),
+ type->name, mp_obj_get_type_qstr(index));
}
}
@@ -461,7 +463,7 @@ mp_obj_t mp_obj_len(mp_obj_t o_in) {
mp_raise_TypeError(translate("object has no len"));
} else {
mp_raise_TypeError_varg(
- translate("object of type '%s' has no len()"), mp_obj_get_type_str(o_in));
+ translate("object of type '%q' has no len()"), mp_obj_get_type_qstr(o_in));
}
} else {
return len;
@@ -504,21 +506,21 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
mp_raise_TypeError(translate("object does not support item deletion"));
} else {
mp_raise_TypeError_varg(
- translate("'%s' object does not support item deletion"), mp_obj_get_type_str(base));
+ translate("'%q' object does not support item deletion"), mp_obj_get_type_qstr(base));
}
} else if (value == MP_OBJ_SENTINEL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("object is not subscriptable"));
} else {
mp_raise_TypeError_varg(
- translate("'%s' object is not subscriptable"), mp_obj_get_type_str(base));
+ translate("'%q' object is not subscriptable"), mp_obj_get_type_qstr(base));
}
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("object does not support item assignment"));
} else {
mp_raise_TypeError_varg(
- translate("'%s' object does not support item assignment"), mp_obj_get_type_str(base));
+ translate("'%q' object does not support item assignment"), mp_obj_get_type_qstr(base));
}
}
}
diff --git a/py/obj.h b/py/obj.h
index e603d4a49..805b26e48 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -303,7 +303,7 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
(mp_obj_t)&mp_const_none_obj, \
(mp_obj_t)&mp_const_none_obj}, }
-// These macros are used to define constant map/dict objects
+// These macros are used to define constant or mutable map/dict objects
// You can put "static" in front of the definition to make it local
#define MP_DEFINE_CONST_MAP(map_name, table_name) \
@@ -329,6 +329,29 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
}, \
}
+#define MP_DEFINE_MUTABLE_MAP(map_name, table_name) \
+ mp_map_t map_name = { \
+ .all_keys_are_qstrs = 1, \
+ .is_fixed = 1, \
+ .is_ordered = 1, \
+ .used = MP_ARRAY_SIZE(table_name), \
+ .alloc = MP_ARRAY_SIZE(table_name), \
+ .table = table_name, \
+ }
+
+#define MP_DEFINE_MUTABLE_DICT(dict_name, table_name) \
+ mp_obj_dict_t dict_name = { \
+ .base = {&mp_type_dict}, \
+ .map = { \
+ .all_keys_are_qstrs = 1, \
+ .is_fixed = 1, \
+ .is_ordered = 1, \
+ .used = MP_ARRAY_SIZE(table_name), \
+ .alloc = MP_ARRAY_SIZE(table_name), \
+ .table = table_name, \
+ }, \
+ }
+
// These macros are used to declare and define constant staticmethond and classmethod objects
// You can put "static" in front of the definitions to make them local
@@ -604,6 +627,8 @@ extern const mp_obj_type_t mp_type_NameError;
extern const mp_obj_type_t mp_type_NotImplementedError;
extern const mp_obj_type_t mp_type_OSError;
extern const mp_obj_type_t mp_type_TimeoutError;
+extern const mp_obj_type_t mp_type_ConnectionError;
+extern const mp_obj_type_t mp_type_BrokenPipeError;
extern const mp_obj_type_t mp_type_OverflowError;
extern const mp_obj_type_t mp_type_RuntimeError;
extern const mp_obj_type_t mp_type_StopAsyncIteration;
@@ -680,6 +705,7 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in);
const char *mp_obj_get_type_str(mp_const_obj_t o_in);
+#define mp_obj_get_type_qstr(o_in) (mp_obj_get_type((o_in))->name)
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo); // arguments should be type objects
mp_obj_t mp_instance_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type);
diff --git a/py/objarray.c b/py/objarray.c
index 5d83f0697..e0b4cbd55 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -97,6 +97,9 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC mp_obj_array_t *array_new(char typecode, size_t n) {
+ if (typecode == 'x') {
+ mp_raise_ValueError(translate("bad typecode"));
+ }
int typecode_size = mp_binary_get_size('@', typecode, NULL);
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
@@ -126,8 +129,10 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
|| (MICROPY_PY_BUILTINS_BYTEARRAY && MP_OBJ_IS_TYPE(initializer, &mp_type_bytearray)))))
&& mp_get_buffer(initializer, &bufinfo, MP_BUFFER_READ)) {
// construct array from raw bytes
- // we round-down the len to make it a multiple of sz (CPython raises error)
size_t sz = mp_binary_get_size('@', typecode, NULL);
+ if (bufinfo.len % sz) {
+ mp_raise_ValueError(translate("bytes length not a multiple of item size"));
+ }
size_t len = bufinfo.len / sz;
mp_obj_array_t *o = array_new(typecode, len);
memcpy(o->items, bufinfo.buf, len * sz);
diff --git a/py/objdict.c b/py/objdict.c
index 39169fe1a..63fd86f35 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -313,7 +313,7 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
size_t cur = 0;
mp_map_elem_t *next = dict_iter_next(self, &cur);
if (next == NULL) {
- mp_raise_msg(&mp_type_KeyError, translate("popitem(): dictionary is empty"));
+ mp_raise_msg_varg(&mp_type_KeyError, translate("pop from empty %q"), MP_QSTR_dict);
}
self->map.used--;
mp_obj_t items[] = {next->key, next->value};
diff --git a/py/objexcept.c b/py/objexcept.c
index e3b953543..01ba6da9c 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -282,15 +282,17 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
*/
MP_DEFINE_EXCEPTION(OSError, Exception)
- MP_DEFINE_EXCEPTION(TimeoutError, OSError)
- /*
- MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
- MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
+ MP_DEFINE_EXCEPTION(TimeoutError, OSError)
MP_DEFINE_EXCEPTION(ConnectionError, OSError)
MP_DEFINE_EXCEPTION(BrokenPipeError, ConnectionError)
+ /*
MP_DEFINE_EXCEPTION(ConnectionAbortedError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionRefusedError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionResetError, ConnectionError)
+ */
+ /*
+ MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
+ MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
MP_DEFINE_EXCEPTION(InterruptedError, OSError)
MP_DEFINE_EXCEPTION(IsADirectoryError, OSError)
MP_DEFINE_EXCEPTION(NotADirectoryError, OSError)
diff --git a/py/objint.c b/py/objint.c
index 82f5aadd1..5a33ccbc0 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -141,9 +141,9 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
int cl = fpclassify(val);
if (cl == FP_INFINITE) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, translate("can't convert inf to int")));
+ mp_raise_OverflowError_varg(translate("can't convert %q to %q"), MP_QSTR_inf, MP_QSTR_int);
} else if (cl == FP_NAN) {
- mp_raise_ValueError(translate("can't convert NaN to int"));
+ mp_raise_ValueError_varg(translate("can't convert %q to %q"), MP_QSTR_NaN, MP_QSTR_int);
} else {
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
if (icl == MP_FP_CLASS_FIT_SMALLINT) {
@@ -457,6 +457,28 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp
return MP_OBJ_NULL; // op not supported
}
+#if MICROPY_CPYTHON_COMPAT
+STATIC mp_obj_t int_bit_length(mp_obj_t self_in) {
+ #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
+ if (!MP_OBJ_IS_SMALL_INT(self_in)) {
+ return mp_obj_int_bit_length_impl(self_in);
+ }
+ else
+ #endif
+ {
+ mp_int_t int_val = MP_OBJ_SMALL_INT_VALUE(self_in);
+ mp_uint_t value =
+ (int_val == 0) ? 0 :
+ (int_val == MP_SMALL_INT_MIN) ? 8 * sizeof(mp_int_t) :
+ (int_val < 0) ? 8 * sizeof(long) - __builtin_clzl(-int_val) :
+ 8 * sizeof(long) - __builtin_clzl(int_val);
+ return mp_obj_new_int_from_uint(value);
+ }
+
+}
+MP_DEFINE_CONST_FUN_OBJ_1(int_bit_length_obj, int_bit_length);
+#endif
+
// this is a classmethod
STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
// TODO: Support signed param (assumes signed=False at the moment)
@@ -537,6 +559,9 @@ STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 3, int_to_bytes);
STATIC const mp_rom_map_elem_t int_locals_dict_table[] = {
+#if MICROPY_CPYTHON_COMPAT
+ { MP_ROM_QSTR(MP_QSTR_bit_length), MP_ROM_PTR(&int_bit_length_obj) },
+#endif
{ MP_ROM_QSTR(MP_QSTR_from_bytes), MP_ROM_PTR(&int_from_bytes_obj) },
{ MP_ROM_QSTR(MP_QSTR_to_bytes), MP_ROM_PTR(&int_to_bytes_obj) },
};
diff --git a/py/objint.h b/py/objint.h
index bba9ff50a..68997ced2 100644
--- a/py/objint.h
+++ b/py/objint.h
@@ -60,6 +60,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s
void mp_small_int_buffer_overflow_check(mp_int_t val, size_t nbytes, bool is_signed);
mp_int_t mp_obj_int_hash(mp_obj_t self_in);
+mp_obj_t mp_obj_int_bit_length_impl(mp_obj_t self_in);
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf);
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf);
int mp_obj_int_sign(mp_obj_t self_in);
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index 189049630..0a65098c7 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -45,6 +45,17 @@
const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, MP_SSIZE_MAX};
#endif
+mp_obj_t mp_obj_int_bit_length_impl(mp_obj_t self_in) {
+ assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
+ mp_obj_int_t *self = self_in;
+ long long val = self->val;
+ return MP_OBJ_NEW_SMALL_INT(
+ (val == 0) ? 0 :
+ (val == MP_SMALL_INT_MIN) ? 8 * sizeof(long long) :
+ (val < 0) ? 8 * sizeof(long long) - __builtin_clzll(-val) :
+ 8 * sizeof(long long) - __builtin_clzll(val));
+}
+
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf) {
int delta = 1;
if (!big_endian) {
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 90060114e..d32fdfbe8 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -107,6 +107,12 @@ char *mp_obj_int_formatted_impl(char **buf, size_t *buf_size, size_t *fmt_size,
return str;
}
+mp_obj_t mp_obj_int_bit_length_impl(mp_obj_t self_in) {
+ assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
+ mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
+ return MP_OBJ_NEW_SMALL_INT(mpz_num_bits(&self->mpz));
+}
+
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf) {
mp_obj_int_t *o = mp_obj_int_new_mpz();
mpz_set_from_bytes(&o->mpz, big_endian, len, buf);
diff --git a/py/objlist.c b/py/objlist.c
index 9242020d4..51ec920be 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -274,7 +274,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list);
if (self->len == 0) {
- mp_raise_IndexError(translate("pop from empty list"));
+ mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_list);
}
size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
mp_obj_t ret = self->items[index];
diff --git a/py/objset.c b/py/objset.c
index d986c6dda..45b5c1260 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -368,7 +368,7 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) {
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t obj = mp_set_remove_first(&self->set);
if (obj == MP_OBJ_NULL) {
- mp_raise_msg(&mp_type_KeyError, translate("pop from an empty set"));
+ mp_raise_msg_varg(&mp_type_KeyError, translate("pop from empty %q"), MP_QSTR_set);
}
return obj;
}
@@ -450,6 +450,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
return MP_OBJ_NEW_SMALL_INT(hash);
}
#endif
+ /* FALLTHROUGH */
default: return MP_OBJ_NULL; // op not supported
}
}
diff --git a/py/objstr.c b/py/objstr.c
index 5e0c6fdfa..edb562df2 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -1076,7 +1076,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
field_name = str_to_int(field_name, field_name_top, &index);
if ((uint)index >= n_args - 1) {
- mp_raise_IndexError(translate("tuple index out of range"));
+ mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_tuple);
}
arg = args[index + 1];
*arg_i = -1;
@@ -1104,7 +1104,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
}
if ((uint)*arg_i >= n_args - 1) {
- mp_raise_IndexError(translate("tuple index out of range"));
+ mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_tuple);
}
arg = args[(*arg_i) + 1];
(*arg_i)++;
@@ -1280,8 +1280,8 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
terse_str_format_value_error();
} else {
mp_raise_ValueError_varg(
- translate("unknown format code '%c' for object of type '%s'"),
- type, mp_obj_get_type_str(arg));
+ translate("unknown format code '%c' for object of type '%q'"),
+ type, mp_obj_get_type_qstr(arg));
}
}
}
@@ -1352,8 +1352,8 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
terse_str_format_value_error();
} else {
mp_raise_ValueError_varg(
- translate("unknown format code '%c' for object of type '%s'"),
- type, mp_obj_get_type_str(arg));
+ translate("unknown format code '%c' for object of type '%q'"),
+ type, mp_obj_get_type_qstr(arg));
}
}
} else {
@@ -1388,8 +1388,8 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
terse_str_format_value_error();
} else {
mp_raise_ValueError_varg(
- translate("unknown format code '%c' for object of type '%s'"),
- type, mp_obj_get_type_str(arg));
+ translate("unknown format code '%c' for object of type '%q'"),
+ type, mp_obj_get_type_qstr(arg));
}
}
}
@@ -2133,7 +2133,7 @@ STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("can't convert to str implicitly"));
} else {
- const qstr src_name = mp_obj_get_type(self_in)->name;
+ const qstr src_name = mp_obj_get_type_qstr(self_in);
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
translate("can't convert '%q' object to %q implicitly"),
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str));
diff --git a/py/objstrunicode.c b/py/objstrunicode.c
index 351a67e91..50250abfa 100644
--- a/py/objstrunicode.c
+++ b/py/objstrunicode.c
@@ -151,7 +151,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (MP_OBJ_IS_SMALL_INT(index)) {
i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) {
- mp_raise_TypeError_varg(translate("string indices must be integers, not %s"), mp_obj_get_type_str(index));
+ mp_raise_TypeError_varg(translate("string indices must be integers, not %q"), mp_obj_get_type_qstr(index));
}
const byte *s, *top = self_data + self_len;
if (i < 0)
@@ -162,7 +162,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (is_slice) {
return self_data;
}
- mp_raise_IndexError(translate("string index out of range"));
+ mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_str);
}
if (!UTF8_IS_CONT(*s)) {
++i;
@@ -181,7 +181,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (is_slice) {
return top;
}
- mp_raise_IndexError(translate("string index out of range"));
+ mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_str);
}
// Then check completion
if (i-- == 0) {
diff --git a/py/objtype.c b/py/objtype.c
index fd51ce36b..ccd014c33 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -193,7 +193,7 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_
printf("mp_obj_class_lookup: Returning: ");
mp_obj_print(lookup->dest[0], PRINT_REPR); printf(" ");
// Don't try to repr() lookup->dest[1], as we can be called recursively
- printf("<%s @%p>\n", mp_obj_get_type_str(lookup->dest[1]), lookup->dest[1]);
+ printf("<%q @%p>\n", mp_obj_get_type_qstr(lookup->dest[1]), lookup->dest[1]);
#endif
return;
}
@@ -285,7 +285,7 @@ STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
}
// TODO: CPython prints fully-qualified type name
- mp_printf(print, "<%s object at %p>", mp_obj_get_type_str(self_in), self);
+ mp_printf(print, "<%q object at %p>", mp_obj_get_type_qstr(self_in), self);
}
mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
@@ -376,8 +376,8 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("__init__() should return None"));
} else {
- mp_raise_TypeError_varg(translate("__init__() should return None, not '%s'"),
- mp_obj_get_type_str(init_ret));
+ mp_raise_TypeError_varg(translate("__init__() should return None, not '%q'"),
+ mp_obj_get_type_qstr(init_ret));
}
}
@@ -891,8 +891,8 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("object not callable"));
} else {
- mp_raise_TypeError_varg(translate("'%s' object is not callable"),
- mp_obj_get_type_str(self_in));
+ mp_raise_TypeError_varg(translate("'%q' object is not callable"),
+ mp_obj_get_type_qstr(self_in));
}
}
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
diff --git a/py/proto.c b/py/proto.c
index e5053130b..e4da157f0 100644
--- a/py/proto.c
+++ b/py/proto.c
@@ -45,6 +45,6 @@ const void *mp_proto_get_or_throw(uint16_t name, mp_const_obj_t obj) {
if (proto) {
return proto;
}
- mp_raise_TypeError_varg(translate("'%s' object does not support '%q'"),
- mp_obj_get_type_str(obj), name);
+ mp_raise_TypeError_varg(translate("'%q' object does not support '%q'"),
+ mp_obj_get_type_qstr(obj), name);
}
diff --git a/py/py.mk b/py/py.mk
index c5073d0f0..49fb0acaf 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -19,7 +19,7 @@ endif
QSTR_GLOBAL_DEPENDENCIES += $(PY_SRC)/mpconfig.h mpconfigport.h
# some code is performance bottleneck and compiled with other optimization options
-CSUPEROPT = -O3
+_CSUPEROPT = -O3
# this sets the config file for FatFs
CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\"
diff --git a/py/qstr.c b/py/qstr.c
index 17d8517c9..c9ba298fb 100755
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -137,6 +137,7 @@ STATIC const byte *find_qstr(qstr q) {
while (q < pool->total_prev_len) {
pool = pool->prev;
}
+ assert(q - pool->total_prev_len < pool->len);
return pool->qstrs[q - pool->total_prev_len];
}
diff --git a/py/runtime.c b/py/runtime.c
index 91ead1fba..e63e2337d 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -279,8 +279,8 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
mp_raise_TypeError(translate("unsupported type for operator"));
} else {
mp_raise_TypeError_varg(
- translate("unsupported type for %q: '%s'"),
- mp_unary_op_method_name[op], mp_obj_get_type_str(arg));
+ translate("unsupported type for %q: '%q'"),
+ mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg));
}
}
}
@@ -586,8 +586,8 @@ unsupported_op:
mp_raise_TypeError(translate("unsupported type for operator"));
} else {
mp_raise_TypeError_varg(
- translate("unsupported types for %q: '%s', '%s'"),
- mp_binary_op_method_name[op], mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs));
+ translate("unsupported types for %q: '%q', '%q'"),
+ mp_binary_op_method_name[op], mp_obj_get_type_qstr(lhs), mp_obj_get_type_qstr(rhs));
}
zero_division:
@@ -627,7 +627,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("object not callable"));
} else {
- mp_raise_TypeError_varg(translate("'%s' object is not callable"), mp_obj_get_type_str(fun_in));
+ mp_raise_TypeError_varg(translate("'%q' object is not callable"), mp_obj_get_type_qstr(fun_in));
}
}
@@ -1104,8 +1104,8 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
((mp_obj_type_t*)MP_OBJ_TO_PTR(base))->name, attr));
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
- translate("'%s' object has no attribute '%q'"),
- mp_obj_get_type_str(base), attr));
+ translate("'%q' object has no attribute '%q'"),
+ mp_obj_get_type_qstr(base), attr));
}
}
}
@@ -1172,8 +1172,8 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
mp_raise_AttributeError(translate("no such attribute"));
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
- translate("'%s' object cannot assign attribute '%q'"),
- mp_obj_get_type_str(base), attr));
+ translate("'%q' object cannot assign attribute '%q'"),
+ mp_obj_get_type_qstr(base), attr));
}
}
@@ -1213,7 +1213,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
mp_raise_TypeError(translate("object not iterable"));
} else {
mp_raise_TypeError_varg(
- translate("'%s' object is not iterable"), mp_obj_get_type_str(o_in));
+ translate("'%q' object is not iterable"), mp_obj_get_type_qstr(o_in));
}
}
@@ -1234,8 +1234,8 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("object not an iterator"));
} else {
- mp_raise_TypeError_varg(translate("'%s' object is not an iterator"),
- mp_obj_get_type_str(o_in));
+ mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
+ mp_obj_get_type_qstr(o_in));
}
}
}
@@ -1270,8 +1270,8 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError(translate("object not an iterator"));
} else {
- mp_raise_TypeError_varg(translate("'%s' object is not an iterator"),
- mp_obj_get_type_str(o_in));
+ mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
+ mp_obj_get_type_qstr(o_in));
}
}
}
@@ -1522,12 +1522,16 @@ NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const compressed_strin
}
}
+NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, va_list argptr) {
+ mp_obj_t exception = mp_obj_new_exception_msg_vlist(exc_type, fmt, argptr);
+ nlr_raise(exception);
+}
+
NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(exc_type, fmt, argptr);
+ mp_raise_msg_vlist(exc_type, fmt, argptr);
va_end(argptr);
- nlr_raise(exception);
}
NORETURN void mp_raise_AttributeError(const compressed_string_t *msg) {
@@ -1546,6 +1550,13 @@ NORETURN void mp_raise_IndexError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_IndexError, msg);
}
+NORETURN void mp_raise_IndexError_varg(const compressed_string_t *fmt, ...) {
+ va_list argptr;
+ va_start(argptr,fmt);
+ mp_raise_msg_vlist(&mp_type_IndexError, fmt, argptr);
+ va_end(argptr);
+}
+
NORETURN void mp_raise_ValueError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_ValueError, msg);
}
@@ -1553,9 +1564,8 @@ NORETURN void mp_raise_ValueError(const compressed_string_t *msg) {
NORETURN void mp_raise_ValueError_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_ValueError, fmt, argptr);
+ mp_raise_msg_vlist(&mp_type_ValueError, fmt, argptr);
va_end(argptr);
- nlr_raise(exception);
}
NORETURN void mp_raise_TypeError(const compressed_string_t *msg) {
@@ -1565,9 +1575,8 @@ NORETURN void mp_raise_TypeError(const compressed_string_t *msg) {
NORETURN void mp_raise_TypeError_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_TypeError, fmt, argptr);
+ mp_raise_msg_vlist(&mp_type_TypeError, fmt, argptr);
va_end(argptr);
- nlr_raise(exception);
}
NORETURN void mp_raise_OSError(int errno_) {
@@ -1589,9 +1598,16 @@ NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str) {
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_OSError, fmt, argptr);
+ mp_raise_msg_vlist(&mp_type_OSError, fmt, argptr);
va_end(argptr);
- nlr_raise(exception);
+}
+
+NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg) {
+ mp_raise_msg(&mp_type_ConnectionError, msg);
+}
+
+NORETURN void mp_raise_BrokenPipeError(void) {
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)));
}
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) {
@@ -1601,17 +1617,15 @@ NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) {
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_NotImplementedError, fmt, argptr);
+ mp_raise_msg_vlist(&mp_type_NotImplementedError, fmt, argptr);
va_end(argptr);
- nlr_raise(exception);
}
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_OverflowError, fmt, argptr);
+ mp_raise_msg_vlist(&mp_type_OverflowError, fmt, argptr);
va_end(argptr);
- nlr_raise(exception);
}
NORETURN void mp_raise_MpyError(const compressed_string_t *msg) {
diff --git a/py/runtime.h b/py/runtime.h
index d3a82333e..ad7d0feab 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -152,6 +152,7 @@ void mp_import_all(mp_obj_t module);
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const compressed_string_t *msg);
NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, ...);
+NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, va_list argptr);
NORETURN void mp_raise_ValueError(const compressed_string_t *msg);
NORETURN void mp_raise_ValueError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_TypeError(const compressed_string_t *msg);
@@ -160,10 +161,13 @@ NORETURN void mp_raise_AttributeError(const compressed_string_t *msg);
NORETURN void mp_raise_RuntimeError(const compressed_string_t *msg);
NORETURN void mp_raise_ImportError(const compressed_string_t *msg);
NORETURN void mp_raise_IndexError(const compressed_string_t *msg);
+NORETURN void mp_raise_IndexError_varg(const compressed_string_t *msg, ...);
NORETURN void mp_raise_OSError(int errno_);
NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str);
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
+NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg);
+NORETURN void mp_raise_BrokenPipeError(void);
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);