summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-30 11:04:47 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-30 11:04:47 +1000
commitc7d334e047ce5a36bd6d4979a5331719dd480a2b (patch)
tree3dbb206e3075eb5f1778389f1399c28d3fd88d34 /py
parent25e24b2c3c63e035b4c145f743f5cd7b02a23fc0 (diff)
parent1f78e7a43130acfa4bedf16c1007a1b0f37c75c3 (diff)
downloadmicropython-c7d334e047ce5a36bd6d4979a5331719dd480a2b.tar.gz
micropython-c7d334e047ce5a36bd6d4979a5331719dd480a2b.zip
Merge tag 'v1.9.2' into parse-bytecode
Double precision math library and support on pyboard, and improved ussl This release brings general improvements and bug fixes to the core and various ports, as well as documentation additions, clean-ups and better consistency. And effort has been made to clean up the source code to make it more consistent across the core and all ports. There is a new tool "mpy_bin2res.py" to convert arbitrary (binary) files to Python resources for inclusion in source code (frozen or otherwise). The ussl module has seen improvements, including implementation of server_hostname (for axtls) and server_side mode (for mbedtls). There is now a double-precision float math library and stmhal has support to build firmware with software or hardware double-precision. A detailed list of changes follows. py core: - formatfloat: fix number of digits and exponent sign when rounding - modthread: raise RuntimeError in release() if lock is not acquired - compile: raise SyntaxError if positional args are given after */** - objint: support "big" byte-order in int.to_bytes() - objint: in to_bytes(), allow length arg to be any int and check sign - compile: fix bug with break/continue in else of optimised for-range - compile: optimise emitter label indices to save a word of heap - builtinimport: remove unreachable code for relative imports - objnamedtuple: simplify and remove use of alloca building namedtuple - mpprint: remove unreachable check for neg return of mp_format_float - binary: add missing "break" statements - runtime: mark m_malloc_fail() as NORETURN - objstr: remove unnecessary "sign" variable in formatting code - vm: make "if" control flow more obvious in YIELD_FROM opcode - modmath: check for zero division in log with 2 args - makeversionhdr.py: update to parse new release line in docs/conf.py - objdict: factorise dict accessor helper to reduce code size - change mp_uint_t to size_t in builtins code - repl: change mp_uint_t to size_t in repl helpers - compile: combine arith and bit-shift ops into 1 compile routine - compile: use switch-case to match token and operator - objgenerator: allow to hash generators and generator instances - gc: refactor assertions in gc_free function - vm: make n_state variable local to just set-up part of VM - asmx64: support moving a 64-bit immediate to one of top 8 registers - modmicropython: cast stack_limit value so it prints correctly - builtinevex: add typechecking of globals/locals args to eval/exec - py.mk: make berkeley-db C-defs apply only to relevant source files - mperrno: allow mperrno.h to be correctly included before other hdrs - mpz: make mpz_is_zero() an inline function - implement raising a big-int to a negative power - mkrules.mk: show frozen modules sizes together with executable size - objtuple: allow to use inplace-multiplication operator on tuples - objstr: raise an exception for wrong type on RHS of str binary op - modsys: initial implementation of sys.getsizeof() - binary.c: fix bug when packing big-endian 'Q' values - add verbose debug compile-time flag MICROPY_DEBUG_VERBOSE - binary: change internal bytearray typecode from 0 to 1 - objstringio: prevent offset wraparound for io.BytesIO objects - objstringio: fix regression with handling SEEK_SET - stream: seek: Consistently handle negative offset for SEEK_SET - mkrules.mk: use "find -path" when searching for frozen obj files - compile: remove unused pn_colon code when compiling func params - objcomplex: remove unnecessary assignment of variable - formatfloat: don't post-increment variable that won't be used again - use "static inline" for funcs that should be inline - asmthumb: use existing macro to properly clear the D-cache extmod: - modussl_axtls: update for axTLS 2.1.3 - modussl_axtls: implement server_hostname arg to wrap_socket() - move modonewire.c from esp8266 to extmod directory - modure: if input string is bytes, return bytes results too - modubinascii: add check for empty buffer passed to hexlify - modussl_axtls: allow to close ssl stream multiple times - modussl_mbedtls: support server_side mode - modussl_mbedtls: when reading and peer wants to close, return 0 - modframebuf: fix invalid stride for odd widths in GS4_HMSB fmt - modussl_mbedtls: make socket.close() free all TLS resources - modframebuf: consistently use "col" as name for colour variables - modussl_mbedtls: implement non-blocking SSL sockets - machine_signal: fix parsing of invert arg when Pin is first arg - modframebuf: use correct initialization for .locals_dict - modlwip: implement setsockopt(IP_ADD_MEMBERSHIP) - modussl_mbedtls.c: add ussl.getpeercert() method - modubinascii: rewrite mod_binascii_a2b_base64 - modubinascii: don't post-increment variable that won't be used - modonewire: rename public module to mp_module_onewire - for uos.stat interpret st_size member as an unsigned int - use "static inline" for funcs that should be inline lib: - axtls: upgrade to axTLS 2.1.3 + MicroPython patchset - libm/math: remove implementations of float conversion functions - add libm_dbl, a double-precision math library, from musl-1.1.16 drivers: - onewire: move onewire.py, ds18x20.py from esp8266 to drivers - onewire: enable pull-up when init'ing the 1-wire pin tools: - gen-cpydiff: use case description as 3rd-level heading - pyboard: add license header - mpy_bin2res: tools to convert binary resources to Python module - mpy-tool.py: don't generate const_table if it's empty - mpy-tool.py: fix missing argument in dump() function tests: - net_inet/test_tls_sites.py: integration test for SSL connections - net_inet: add tests for accept and connect in nonblocking mode - basics: add tests for for-else statement - net_inet: move tests which don't require full Internet to net_hosted - connect_nonblock: refactor towards real net_hosted test - auto detect floating point capabilites of the target - import: add a test for the builtin __import__ function - import: update comment now that uPy raises correct exception - basics/namedtuple1: add test for creating with pos and kw args - unix/extra_coverage: add test for mp_vprintf with bad fmt spec - basics: add tests for arithmetic operators precedence - cpydiff/modules_deque: elaborate workaround - cpydiff/core_class_mro: move under Classes, add workaround - cpydiff/core_arguments: move under Functions subsection - cpydiff/core_class_supermultiple: same cause as core_class_mro - cpydiff: improve wording, add more workarounds - cpydiff: add case for str.ljust/rjust - rename exec1.py to builtin_exec.py - basics/builtin_exec: test various globals/locals args to exec() minimal port: - Makefile: enable gc-sections to remove unused code - remove unused stmhal include from Makefile - use size_t for mp_builtin_open argument unix port: - modtime: replace strftime() with localtime() - mpconfigport.mk: update descriptions of readline and TLS options - Makefile: disable assertions in the standard unix executable - modjni: convert to mp_rom_map_elem_t - for uos.stat interpret st_size member as an unsigned int stmhal port: - mpconfigport.h: remove config of PY_THREAD_GIL to use default - make error messages more consistent across peripherals - add initial implementation of Pin.irq() method - add .value() method to Switch object, to mirror Pin and Signal - move pybstdio.c to lib/utils/sys_stdio_mphal.c for common use - add "quiet timing" enter/exit functions - make available the _onewire module, for low-level bus control - modules: provide sym-link to onewire.py driver - boards/stm32f405.ld: increase FLASH_TEXT to end of 1MiB flash - sdcard: allow a board to customise the SDIO pins - add possibility to build with double-precision floating point - boards: enable double-prec FP on F76x boards - Makefile: use hardware double-prec FP for MCUs that support it - Makefile: rename FLOAT_IMPL to MICROPY_FLOAT_IMPL to match C name - Makefile: add CFLAGS_EXTRA to CFLAGS so cmdline can add options - mpconfigport.h: allow MICROPY_PY_THREAD to be overridden - boards: add configuration files for NUCLEO_F429ZI - boards/NUCLEO_F429ZI: change USB config from HS to FS peripheral - reduce size of ESPRUINO_PICO build so it fits in flash - servo: make pyb.Servo(n) map to Pin('Xn') on all MCUs - servo: don't compile servo code when it's not enabled - use "static inline" for funcs that should be inline cc3200 port: - modusocket: simplify socket.makefile() function - make non-zero socket timeout work with connect/accept/send - modusocket: fix connect() when in non-blocking or timeout mode - use the name MicroPython consistently in code esp8266 port: - Makefile: bump axTLS TLS record buffer size to 5K - Makefile: allow FROZEN_DIR,FROZEN_MPY_DIR to be overridden - Makefile: add LIB_SRC_C variable to qstr auto-extraction list - make onewire module and support code usable by other ports - modonewire: move low-level 1-wire bus code to modonewire.c - modonewire: make timings static and remove onewire.timings func - reinstate 1-wire scripts by sym-linking to drivers/onewire/ - move mp_hal_pin_open_drain from esp_mphal.c to machine_pin.c - enable MICROPY_ENABLE_FINALISER - README: make "Documentation" a top-level section - machine_rtc: use correct arithmetic for aligning RTC mem len - mpconfigport_512k: use terse error messages to get 512k to fit - mpconfigport.h: make socket a weak link - modesp: remove unused constants: STA_MODE, etc - general: add known issue of WiFi RX buffers overflow - use size_t for mp_builtin_open argument - fix UART stop bit constants zephyr port: - Makefile: rework dependencies and "clean" target - Makefile: revert prj.conf construction rule to the previous state - remove long-obsolete machine_ptr_t typedef's - Makefile: explicitly define default target as "all" - modusocket: allow to use socketized net_context in upstream - modusocket: socket, close: switch to native Zephyr socket calls - modusocket: bind, connect, listen, accept: Swtich to native sockets - modusocket: send: switch to native sockets - modusocket: recv: switch to native sockets - modusocket: fully switch to native Zephyr sockets - modzephyr: add current_tid() and stacks_analyze() functions - prj_base.conf: enable CONFIG_INIT_STACKS - modusocket: update struct sockaddr family field name - prj_96b_carbon.conf: re-enable networking on Carbon - modzephyr: add shell_net_iface() function docs: - btree: add hints about opening db file and need to flush db - select: rename to uselect, to match the actual module name - license: update copyright year - esp8266/tutorial/intro: discourage use of 512kb firmwares - esp8266/tutorial/intro: Sphinx requires blank lines around literal blocks - conf.py: include 3 levels of ToC in latexpdf output - gc: mark mem_alloc()/mem_free() as uPy-specific - gc: document gc.threshold() function - builtins: list builtin exceptions - conf.py: set default_role = 'any' - lcd160cr: group related constants together and use full sentences - ref/speed_python: update and make more hardware-neutral - library/gc: fix grammar and improve readability of gc.threshold() - move all ports docs to the single ToC - topindex.html: remove link to wipy.io, it's no longer available - conf.py: add .venv dir to exclude_patterns - move topindex.html to templates/ subdir - differences/index_template: use consistent heading casing - builtins: add AssertionError, SyntaxError, ZeroDivisionError - add glossary - conf.py: switch to "new" format of intersphinx_mapping - conf.py: add file for global replacements definition - library: add CPython docs xref to each pertinent module - replace.inc: add |see_cpython|, to xref individual symbols from CPython - conf.py: set "version" and "release" to the same value - *_index: drop "Indices and tables" pseudo-section - pyboard: move hardware info into General Info chapter - uerrno: document "uerrno" module - esp8266/general.rst: fix name of NTP module - pyboard: move info about using Windows from topindex to general - uzlib: update description of decompress() and mention DecompIO - pyboard/tutorial/amp_skin: add example for playing large WAV files - library/ubinascii: update base64 docs - library/usocket: move socket.error to its own section - library/usocket: describe complete information on address formats - glossary: elaborate on possible MicroPython port differences - glossary: fix typos in micropython-lib paragraph - index: rewrite introduction paragraph to avoid confusion - use the name MicroPython consistently in documentation - consistently link to micropython-lib in glossary all: - make more use of mp_raise_{msg,TypeError,ValueError} helpers - unify header guard usage - remove trailing spaces, per coding conventions - don't include system errno.h when it's not needed - use the name MicroPython consistently in comments - make use of $(TOP) variable in Makefiles, instead of ".." - raise exceptions via mp_raise_XXX - make static dicts use mp_rom_map_elem_t type and MP_ROM_xxx macros README: - mention support for bytecode and frozen bytecode - improve description of precompiled bytecode; mention mpy-cross CODECONVENTIONS: - clarify MicroPython changes sign-off process - start to describe docs conventions - describe docs use of markup for None/True/False travis: - build STM32F769DISC board instead of F7DISC to test dbl-prec FP - pin cpp-coveralls at 0.3.12
Diffstat (limited to 'py')
-rw-r--r--py/argcheck.c4
-rw-r--r--py/asmarm.c4
-rw-r--r--py/asmarm.h8
-rw-r--r--py/asmthumb.c5
-rw-r--r--py/asmthumb.h8
-rw-r--r--py/asmx64.c7
-rw-r--r--py/asmx64.h8
-rw-r--r--py/asmx86.c2
-rw-r--r--py/asmx86.h8
-rw-r--r--py/bc.c4
-rw-r--r--py/bc.h8
-rw-r--r--py/bc0.h10
-rw-r--r--py/binary.c9
-rw-r--r--py/binary.h13
-rw-r--r--py/builtin.h8
-rw-r--r--py/builtinevex.c17
-rw-r--r--py/builtinimport.c41
-rw-r--r--py/compile.c131
-rw-r--r--py/compile.h8
-rw-r--r--py/emit.h9
-rw-r--r--py/emitbc.c4
-rw-r--r--py/emitcommon.c2
-rw-r--r--py/emitglue.c4
-rw-r--r--py/emitglue.h8
-rw-r--r--py/emitinlinethumb.c2
-rw-r--r--py/emitnative.c12
-rw-r--r--py/formatfloat.c29
-rw-r--r--py/formatfloat.h8
-rw-r--r--py/frozenmod.c2
-rw-r--r--py/frozenmod.h6
-rw-r--r--py/gc.c53
-rw-r--r--py/gc.h8
-rw-r--r--py/grammar.h8
-rw-r--r--py/lexer.c6
-rw-r--r--py/lexer.h10
-rw-r--r--py/makeversionhdr.py4
-rw-r--r--py/malloc.c6
-rw-r--r--py/map.c2
-rw-r--r--py/misc.h10
-rw-r--r--py/mkrules.mk6
-rw-r--r--py/modarray.c2
-rw-r--r--py/modbuiltins.c33
-rw-r--r--py/modcmath.c2
-rw-r--r--py/modcollections.c2
-rw-r--r--py/modgc.c2
-rw-r--r--py/modio.c10
-rw-r--r--py/modmath.c8
-rw-r--r--py/modmicropython.c5
-rw-r--r--py/modstruct.c2
-rw-r--r--py/modsys.c18
-rw-r--r--py/modthread.c6
-rw-r--r--py/mpconfig.h25
-rw-r--r--py/mperrno.h11
-rw-r--r--py/mphal.h8
-rw-r--r--py/mpprint.c5
-rw-r--r--py/mpprint.h8
-rw-r--r--py/mpstate.c2
-rw-r--r--py/mpstate.h10
-rw-r--r--py/mpthread.h6
-rw-r--r--py/mpz.c10
-rw-r--r--py/mpz.h11
-rw-r--r--py/nativeglue.c8
-rw-r--r--py/nlr.h8
-rw-r--r--py/nlrsetjmp.c2
-rw-r--r--py/obj.c5
-rw-r--r--py/obj.h8
-rw-r--r--py/objarray.c8
-rw-r--r--py/objarray.h7
-rw-r--r--py/objattrtuple.c2
-rw-r--r--py/objbool.c2
-rw-r--r--py/objboundmeth.c2
-rw-r--r--py/objcell.c2
-rw-r--r--py/objclosure.c2
-rw-r--r--py/objcomplex.c5
-rw-r--r--py/objdict.c51
-rw-r--r--py/objenumerate.c2
-rw-r--r--py/objexcept.c2
-rw-r--r--py/objexcept.h8
-rw-r--r--py/objfilter.c2
-rw-r--r--py/objfloat.c2
-rw-r--r--py/objfun.c6
-rw-r--r--py/objfun.h8
-rw-r--r--py/objgenerator.c4
-rw-r--r--py/objgenerator.h8
-rw-r--r--py/objgetitemiter.c2
-rw-r--r--py/objint.c18
-rw-r--r--py/objint.h8
-rw-r--r--py/objint_longlong.c11
-rw-r--r--py/objint_mpz.c9
-rw-r--r--py/objlist.c12
-rw-r--r--py/objlist.h8
-rw-r--r--py/objmap.c2
-rw-r--r--py/objmodule.c2
-rw-r--r--py/objmodule.h8
-rw-r--r--py/objnamedtuple.c56
-rw-r--r--py/objnone.c2
-rw-r--r--py/objobject.c2
-rw-r--r--py/objproperty.c2
-rw-r--r--py/objrange.c2
-rw-r--r--py/objreversed.c2
-rw-r--r--py/objset.c2
-rw-r--r--py/objsingleton.c2
-rw-r--r--py/objslice.c2
-rw-r--r--py/objstr.c87
-rw-r--r--py/objstr.h8
-rw-r--r--py/objstringio.c23
-rw-r--r--py/objstrunicode.c8
-rw-r--r--py/objtuple.c7
-rw-r--r--py/objtuple.h8
-rw-r--r--py/objtype.c26
-rw-r--r--py/objtype.h8
-rw-r--r--py/objzip.c2
-rw-r--r--py/opmethods.c2
-rw-r--r--py/parse.c2
-rw-r--r--py/parse.h8
-rw-r--r--py/parsenum.c2
-rw-r--r--py/parsenum.h8
-rw-r--r--py/parsenumbase.c2
-rw-r--r--py/parsenumbase.h8
-rw-r--r--py/py.mk16
-rw-r--r--py/qstr.c4
-rw-r--r--py/qstr.h8
-rw-r--r--py/qstrdefs.h2
-rw-r--r--py/reader.c1
-rw-r--r--py/repl.c20
-rw-r--r--py/repl.h10
-rw-r--r--py/ringbuf.h6
-rw-r--r--py/runtime.c23
-rw-r--r--py/runtime.h10
-rw-r--r--py/runtime0.h9
-rw-r--r--py/runtime_utils.c2
-rw-r--r--py/scope.c2
-rw-r--r--py/scope.h8
-rw-r--r--py/sequence.c2
-rw-r--r--py/showbc.c2
-rw-r--r--py/smallint.c2
-rw-r--r--py/smallint.h8
-rw-r--r--py/stackctrl.c2
-rw-r--r--py/stackctrl.h8
-rw-r--r--py/stream.c13
-rw-r--r--py/stream.h16
-rw-r--r--py/unicode.c2
-rw-r--r--py/unicode.h8
-rw-r--r--py/vm.c19
-rw-r--r--py/vmentrytable.h2
-rw-r--r--py/vstr.c4
-rw-r--r--py/warning.c2
147 files changed, 734 insertions, 680 deletions
diff --git a/py/argcheck.c b/py/argcheck.c
index 9f225345d5..0c5c5ca954 100644
--- a/py/argcheck.c
+++ b/py/argcheck.c
@@ -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)
*
@@ -142,6 +142,6 @@ NORETURN void mp_arg_error_terse_mismatch(void) {
#if MICROPY_CPYTHON_COMPAT
NORETURN void mp_arg_error_unimpl_kw(void) {
- mp_not_implemented("keyword argument(s) not yet implemented - use normal args instead");
+ mp_raise_NotImplementedError("keyword argument(s) not yet implemented - use normal args instead");
}
#endif
diff --git a/py/asmarm.c b/py/asmarm.c
index da07680e31..552fdfb344 100644
--- a/py/asmarm.c
+++ b/py/asmarm.c
@@ -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)
*
@@ -135,7 +135,7 @@ STATIC uint asm_arm_op_orr_reg(uint rd, uint rn, uint rm) {
void asm_arm_bkpt(asm_arm_t *as) {
// bkpt #0
- emit_al(as, 0x1200070);
+ emit_al(as, 0x1200070);
}
// locals:
diff --git a/py/asmarm.h b/py/asmarm.h
index e273b98d73..a302b15905 100644
--- a/py/asmarm.h
+++ b/py/asmarm.h
@@ -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)
*
@@ -24,8 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_ASMARM_H__
-#define __MICROPY_INCLUDED_PY_ASMARM_H__
+#ifndef MICROPY_INCLUDED_PY_ASMARM_H
+#define MICROPY_INCLUDED_PY_ASMARM_H
#include "py/misc.h"
#include "py/asmbase.h"
@@ -202,4 +202,4 @@ void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp);
#endif // GENERIC_ASM_API
-#endif // __MICROPY_INCLUDED_PY_ASMARM_H__
+#endif // MICROPY_INCLUDED_PY_ASMARM_H
diff --git a/py/asmthumb.c b/py/asmthumb.c
index 7e92e4de41..5316a7efb2 100644
--- a/py/asmthumb.c
+++ b/py/asmthumb.c
@@ -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)
*
@@ -33,6 +33,7 @@
// wrapper around everything in this file
#if MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB
+#include "py/mphal.h"
#include "py/asmthumb.h"
#define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0)
@@ -53,7 +54,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
#if defined(MCU_SERIES_F7)
if (as->base.pass == MP_ASM_PASS_EMIT) {
// flush D-cache, so the code emitted is stored in memory
- SCB_CleanDCache_by_Addr((uint32_t*)as->base.code_base, as->base.code_size);
+ MP_HAL_CLEAN_DCACHE(as->base.code_base, as->base.code_size);
// invalidate I-cache
SCB_InvalidateICache();
}
diff --git a/py/asmthumb.h b/py/asmthumb.h
index 52e663b3bd..7070e03ac2 100644
--- a/py/asmthumb.h
+++ b/py/asmthumb.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_ASMTHUMB_H__
-#define __MICROPY_INCLUDED_PY_ASMTHUMB_H__
+#ifndef MICROPY_INCLUDED_PY_ASMTHUMB_H
+#define MICROPY_INCLUDED_PY_ASMTHUMB_H
#include "py/misc.h"
#include "py/asmbase.h"
@@ -318,4 +318,4 @@ void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp
#endif // GENERIC_ASM_API
-#endif // __MICROPY_INCLUDED_PY_ASMTHUMB_H__
+#endif // MICROPY_INCLUDED_PY_ASMTHUMB_H
diff --git a/py/asmx64.c b/py/asmx64.c
index cf1a86b3f0..aa2a8ec7cc 100644
--- a/py/asmx64.c
+++ b/py/asmx64.c
@@ -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)
*
@@ -344,8 +344,9 @@ STATIC void asm_x64_mov_i32_to_r64(asm_x64_t *as, int src_i32, int dest_r64) {
void asm_x64_mov_i64_to_r64(asm_x64_t *as, int64_t src_i64, int dest_r64) {
// cpu defaults to i32 to r64
// to mov i64 to r64 need to use REX prefix
- assert(dest_r64 < 8);
- asm_x64_write_byte_2(as, REX_PREFIX | REX_W, OPCODE_MOV_I64_TO_R64 | dest_r64);
+ asm_x64_write_byte_2(as,
+ REX_PREFIX | REX_W | (dest_r64 < 8 ? 0 : REX_B),
+ OPCODE_MOV_I64_TO_R64 | (dest_r64 & 7));
asm_x64_write_word64(as, src_i64);
}
diff --git a/py/asmx64.h b/py/asmx64.h
index 4499c53c32..425bdf2d39 100644
--- a/py/asmx64.h
+++ b/py/asmx64.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_ASMX64_H__
-#define __MICROPY_INCLUDED_PY_ASMX64_H__
+#ifndef MICROPY_INCLUDED_PY_ASMX64_H
+#define MICROPY_INCLUDED_PY_ASMX64_H
#include "py/mpconfig.h"
#include "py/misc.h"
@@ -197,4 +197,4 @@ void asm_x64_call_ind(asm_x64_t* as, void* ptr, int temp_r32);
#endif // GENERIC_ASM_API
-#endif // __MICROPY_INCLUDED_PY_ASMX64_H__
+#endif // MICROPY_INCLUDED_PY_ASMX64_H
diff --git a/py/asmx86.c b/py/asmx86.c
index dd3ad02242..6a78fbd5ea 100644
--- a/py/asmx86.c
+++ b/py/asmx86.c
@@ -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)
*
diff --git a/py/asmx86.h b/py/asmx86.h
index 0b44af6639..0a00e2e7c2 100644
--- a/py/asmx86.h
+++ b/py/asmx86.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_ASMX86_H__
-#define __MICROPY_INCLUDED_PY_ASMX86_H__
+#ifndef MICROPY_INCLUDED_PY_ASMX86_H
+#define MICROPY_INCLUDED_PY_ASMX86_H
#include "py/mpconfig.h"
#include "py/misc.h"
@@ -195,4 +195,4 @@ void asm_x86_call_ind(asm_x86_t* as, void* ptr, mp_uint_t n_args, int temp_r32);
#endif // GENERIC_ASM_API
-#endif // __MICROPY_INCLUDED_PY_ASMX86_H__
+#endif // MICROPY_INCLUDED_PY_ASMX86_H
diff --git a/py/bc.c b/py/bc.c
index 2e481bce77..917eba57d9 100644
--- a/py/bc.c
+++ b/py/bc.c
@@ -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)
*
@@ -35,7 +35,7 @@
#include "py/bc0.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#else // don't print debugging info
#define DEBUG_PRINT (0)
diff --git a/py/bc.h b/py/bc.h
index 88045dc55b..69e213e422 100644
--- a/py/bc.h
+++ b/py/bc.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_BC_H__
-#define __MICROPY_INCLUDED_PY_BC_H__
+#ifndef MICROPY_INCLUDED_PY_BC_H
+#define MICROPY_INCLUDED_PY_BC_H
#include "py/runtime.h"
#include "py/obj.h"
@@ -119,4 +119,4 @@ uint mp_opcode_format(const byte *ip, size_t *opcode_size);
#endif
-#endif // __MICROPY_INCLUDED_PY_BC_H__
+#endif // MICROPY_INCLUDED_PY_BC_H
diff --git a/py/bc0.h b/py/bc0.h
index b5650abe41..f671c5b5a7 100644
--- a/py/bc0.h
+++ b/py/bc0.h
@@ -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)
*
@@ -23,10 +23,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_BC0_H__
-#define __MICROPY_INCLUDED_PY_BC0_H__
+#ifndef MICROPY_INCLUDED_PY_BC0_H
+#define MICROPY_INCLUDED_PY_BC0_H
-// Micro Python byte-codes.
+// MicroPython byte-codes.
// The comment at the end of the line (if it exists) tells the arguments to the byte-code.
#define MP_BC_LOAD_CONST_FALSE (0x10)
@@ -116,4 +116,4 @@
#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7)
#define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36)
-#endif // __MICROPY_INCLUDED_PY_BC0_H__
+#endif // MICROPY_INCLUDED_PY_BC0_H
diff --git a/py/binary.c b/py/binary.c
index 34feb384ea..870a0942ba 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -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)
*
@@ -303,7 +303,10 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
// zero/sign extend if needed
if (BYTES_PER_WORD < 8 && size > sizeof(val)) {
int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00;
- memset(p + sizeof(val), c, size - sizeof(val));
+ memset(p, c, size);
+ if (struct_type == '>') {
+ p += size - sizeof(val);
+ }
}
}
}
@@ -368,6 +371,7 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
case 'q':
((long long*)p)[index] = val;
+ break;
case 'Q':
((unsigned long long*)p)[index] = val;
break;
@@ -383,5 +387,6 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
// Extension to CPython: array of pointers
case 'P':
((void**)p)[index] = (void*)(uintptr_t)val;
+ break;
}
}
diff --git a/py/binary.h b/py/binary.h
index 997d878c81..0dae6a29e6 100644
--- a/py/binary.h
+++ b/py/binary.h
@@ -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)
*
@@ -23,14 +23,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_BINARY_H__
-#define __MICROPY_INCLUDED_PY_BINARY_H__
+#ifndef MICROPY_INCLUDED_PY_BINARY_H
+#define MICROPY_INCLUDED_PY_BINARY_H
#include "py/obj.h"
// Use special typecode to differentiate repr() of bytearray vs array.array('B')
-// (underlyingly they're same).
-#define BYTEARRAY_TYPECODE 0
+// (underlyingly they're same). Can't use 0 here because that's used to detect
+// type-specification errors due to end-of-string.
+#define BYTEARRAY_TYPECODE 1
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
@@ -41,4 +42,4 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src);
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val);
-#endif // __MICROPY_INCLUDED_PY_BINARY_H__
+#endif // MICROPY_INCLUDED_PY_BINARY_H
diff --git a/py/builtin.h b/py/builtin.h
index ec326d037b..a637b6e222 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_BUILTIN_H__
-#define __MICROPY_INCLUDED_PY_BUILTIN_H__
+#ifndef MICROPY_INCLUDED_PY_BUILTIN_H
+#define MICROPY_INCLUDED_PY_BUILTIN_H
#include "py/obj.h"
@@ -120,4 +120,4 @@ extern const mp_obj_module_t mp_module_btree;
extern const char *MICROPY_PY_BUILTINS_HELP_TEXT;
-#endif // __MICROPY_INCLUDED_PY_BUILTIN_H__
+#endif // MICROPY_INCLUDED_PY_BUILTIN_H
diff --git a/py/builtinevex.c b/py/builtinevex.c
index d9a3833ccc..ba8048f702 100644
--- a/py/builtinevex.c
+++ b/py/builtinevex.c
@@ -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)
*
@@ -113,12 +113,15 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
// work out the context
mp_obj_dict_t *globals = mp_globals_get();
mp_obj_dict_t *locals = mp_locals_get();
- if (n_args > 1) {
- globals = MP_OBJ_TO_PTR(args[1]);
- if (n_args > 2) {
- locals = MP_OBJ_TO_PTR(args[2]);
- } else {
- locals = globals;
+ for (size_t i = 1; i < 3 && i < n_args; ++i) {
+ if (args[i] != mp_const_none) {
+ if (!MP_OBJ_IS_TYPE(args[i], &mp_type_dict)) {
+ mp_raise_TypeError(NULL);
+ }
+ locals = MP_OBJ_TO_PTR(args[i]);
+ if (i == 1) {
+ globals = locals;
+ }
}
}
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 6994fc48f4..f5bfb0d982 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -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)
*
@@ -37,7 +37,7 @@
#include "py/builtin.h"
#include "py/frozenmod.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -109,7 +109,7 @@ STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *d
#if MICROPY_PY_SYS
} else {
// go through each path looking for a directory or file
- for (mp_uint_t i = 0; i < path_num; i++) {
+ for (size_t i = 0; i < path_num; i++) {
vstr_reset(dest);
size_t p_len;
const char *p = mp_obj_str_get_data(path_items[i], &p_len);
@@ -227,11 +227,11 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
do_load_from_lexer(module_obj, lex);
return;
}
- #endif
+ #else
// If we get here then the file was not frozen and we can't compile scripts.
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
- "script compilation not supported"));
+ mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
+ #endif
}
STATIC void chop_component(const char *start, const char **end) {
@@ -248,7 +248,7 @@ STATIC void chop_component(const char *start, const char **end) {
mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
#if DEBUG_PRINT
DEBUG_printf("__import__:\n");
- for (mp_uint_t i = 0; i < n_args; i++) {
+ for (size_t i = 0; i < n_args; i++) {
DEBUG_printf(" ");
mp_obj_print(args[i], PRINT_REPR);
DEBUG_printf("\n");
@@ -262,6 +262,9 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
fromtuple = args[3];
if (n_args >= 5) {
level = MP_OBJ_SMALL_INT_VALUE(args[4]);
+ if (level < 0) {
+ mp_raise_ValueError(NULL);
+ }
}
}
@@ -306,28 +309,13 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
chop_component(this_name, &p);
}
-
- uint dots_seen = 0;
while (level--) {
chop_component(this_name, &p);
- dots_seen++;
}
- if (dots_seen == 0 && level >= 1) {
- // http://legacy.python.org/dev/peps/pep-0328/#relative-imports-and-name
- // "If the module's name does not contain any package information
- // (e.g. it is set to '__main__') then relative imports are
- // resolved as if the module were a top level module, regardless
- // of where the module is actually located on the file system."
- // Supposedly this if catches this condition and resolve it properly
- // TODO: But nobody knows for sure. This condition happens when
- // package's __init__.py does something like "import .submod". So,
- // maybe we should check for package here? But quote above doesn't
- // talk about packages, it talks about dot-less module names.
- DEBUG_printf("Warning: no dots in current module name and level>0\n");
- p = this_name + this_name_l;
- } else if (level != -1) {
- mp_raise_msg(&mp_type_ImportError, "invalid relative import");
+ // We must have some component left over to import from
+ if (p == this_name) {
+ mp_raise_ValueError("cannot perform relative import");
}
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
@@ -340,9 +328,6 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l);
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
- if (new_mod_q == MP_QSTR_) {
- mp_raise_ValueError("cannot perform relative import");
- }
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
mod_str = new_mod;
mod_len = new_mod_l;
diff --git a/py/compile.c b/py/compile.c
index 3b6a264d61..4e704abfbb 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -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)
*
@@ -40,6 +40,8 @@
// TODO need to mangle __attr names
+#define INVALID_LABEL (0xffff)
+
typedef enum {
// define rules with a compile function
#define DEF_RULE(rule, comp, kind, ...) PN_##rule,
@@ -567,7 +569,7 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int
for (int j = 0; j < this_scope->id_info_len; j++) {
id_info_t *id2 = &this_scope->id_info[j];
if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) {
- // in Micro Python we load closures using LOAD_FAST
+ // in MicroPython we load closures using LOAD_FAST
EMIT_LOAD_FAST(id->qst, id->local_num);
nfree += 1;
}
@@ -611,13 +613,11 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
} else {
mp_parse_node_t pn_id;
- mp_parse_node_t pn_colon;
mp_parse_node_t pn_equal;
if (pn_kind == -1) {
// this parameter is just an id
pn_id = pn;
- pn_colon = MP_PARSE_NODE_NULL;
pn_equal = MP_PARSE_NODE_NULL;
} else if (pn_kind == PN_typedargslist_name) {
@@ -625,7 +625,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
pn_id = pns->nodes[0];
- pn_colon = pns->nodes[1];
+ //pn_colon = pns->nodes[1]; // unused
pn_equal = pns->nodes[2];
} else {
@@ -652,9 +652,9 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
if (comp->have_star) {
comp->num_dict_params += 1;
- // in Micro Python we put the default dict parameters into a dictionary using the bytecode
+ // in MicroPython we put the default dict parameters into a dictionary using the bytecode
if (comp->num_dict_params == 1) {
- // in Micro Python we put the default positional parameters into a tuple using the bytecode
+ // in MicroPython we put the default positional parameters into a tuple using the bytecode
// we need to do this here before we start building the map for the default keywords
if (comp->num_default_params > 0) {
EMIT_ARG(build_tuple, comp->num_default_params);
@@ -674,9 +674,6 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
compile_node(comp, pn_equal);
}
}
-
- // TODO pn_colon not implemented
- (void)pn_colon;
}
}
@@ -698,7 +695,7 @@ STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_n
return;
}
- // in Micro Python we put the default positional parameters into a tuple using the bytecode
+ // in MicroPython we put the default positional parameters into a tuple using the bytecode
// the default keywords args may have already made the tuple; if not, do it now
if (comp->num_default_params > 0 && comp->num_dict_params == 0) {
EMIT_ARG(build_tuple, comp->num_default_params);
@@ -954,7 +951,7 @@ STATIC void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
STATIC void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
- if (comp->break_label == 0) {
+ if (comp->break_label == INVALID_LABEL) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "'break' outside loop");
}
assert(comp->cur_except_level >= comp->break_continue_except_level);
@@ -962,7 +959,7 @@ STATIC void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
STATIC void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
- if (comp->continue_label == 0) {
+ if (comp->continue_label == INVALID_LABEL) {
compile_syntax_error(comp, (mp_parse_node_t)pns, "'continue' outside loop");
}
assert(comp->cur_except_level >= comp->break_continue_except_level);
@@ -1406,7 +1403,20 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
// break/continue apply to outer loop (if any) in the else block
END_BREAK_CONTINUE_BLOCK
- compile_node(comp, pn_else);
+ // Compile the else block. We must pop the iterator variables before
+ // executing the else code because it may contain break/continue statements.
+ uint end_label = 0;
+ if (!MP_PARSE_NODE_IS_NULL(pn_else)) {
+ // discard final value of "var", and possible "end" value
+ EMIT(pop_top);
+ if (end_on_stack) {
+ EMIT(pop_top);
+ }
+ compile_node(comp, pn_else);
+ end_label = comp_next_label(comp);
+ EMIT_ARG(jump, end_label);
+ EMIT_ARG(adjust_stack_size, 1 + end_on_stack);
+ }
EMIT_ARG(label_assign, break_label);
@@ -1417,6 +1427,10 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
if (end_on_stack) {
EMIT(pop_top);
}
+
+ if (!MP_PARSE_NODE_IS_NULL(pn_else)) {
+ EMIT_ARG(label_assign, end_label);
+ }
}
STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
@@ -1496,7 +1510,7 @@ STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// break/continue apply to outer loop (if any) in the else block
END_BREAK_CONTINUE_BLOCK
- compile_node(comp, pns->nodes[3]); // else (not tested)
+ compile_node(comp, pns->nodes[3]); // else (may be empty)
EMIT_ARG(label_assign, break_label);
}
@@ -2113,62 +2127,43 @@ STATIC void compile_and_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, MP_BINARY_OP_AND);
}
-STATIC void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
- int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
- compile_node(comp, pns->nodes[0]);
- for (int i = 1; i + 1 < num_nodes; i += 2) {
- compile_node(comp, pns->nodes[i + 1]);
- if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_LESS)) {
- EMIT_ARG(binary_op, MP_BINARY_OP_LSHIFT);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_MORE)); // should be
- EMIT_ARG(binary_op, MP_BINARY_OP_RSHIFT);
- }
- }
-}
-
-STATIC void compile_arith_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
- int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
- compile_node(comp, pns->nodes[0]);
- for (int i = 1; i + 1 < num_nodes; i += 2) {
- compile_node(comp, pns->nodes[i + 1]);
- if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PLUS)) {
- EMIT_ARG(binary_op, MP_BINARY_OP_ADD);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_MINUS)); // should be
- EMIT_ARG(binary_op, MP_BINARY_OP_SUBTRACT);
- }
- }
-}
-
STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]);
for (int i = 1; i + 1 < num_nodes; i += 2) {
compile_node(comp, pns->nodes[i + 1]);
- if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_STAR)) {
- EMIT_ARG(binary_op, MP_BINARY_OP_MULTIPLY);
- } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_SLASH)) {
- EMIT_ARG(binary_op, MP_BINARY_OP_FLOOR_DIVIDE);
- } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_SLASH)) {
- EMIT_ARG(binary_op, MP_BINARY_OP_TRUE_DIVIDE);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PERCENT)); // should be
- EMIT_ARG(binary_op, MP_BINARY_OP_MODULO);
+ mp_binary_op_t op;
+ mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]);
+ switch (tok) {
+ case MP_TOKEN_OP_PLUS: op = MP_BINARY_OP_ADD; break;
+ case MP_TOKEN_OP_MINUS: op = MP_BINARY_OP_SUBTRACT; break;
+ case MP_TOKEN_OP_STAR: op = MP_BINARY_OP_MULTIPLY; break;
+ case MP_TOKEN_OP_DBL_SLASH: op = MP_BINARY_OP_FLOOR_DIVIDE; break;
+ case MP_TOKEN_OP_SLASH: op = MP_BINARY_OP_TRUE_DIVIDE; break;
+ case MP_TOKEN_OP_PERCENT: op = MP_BINARY_OP_MODULO; break;
+ case MP_TOKEN_OP_DBL_LESS: op = MP_BINARY_OP_LSHIFT; break;
+ default:
+ assert(tok == MP_TOKEN_OP_DBL_MORE);
+ op = MP_BINARY_OP_RSHIFT;
+ break;
}
+ EMIT_ARG(binary_op, op);
}
}
STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[1]);
- if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_PLUS)) {
- EMIT_ARG(unary_op, MP_UNARY_OP_POSITIVE);
- } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_MINUS)) {
- EMIT_ARG(unary_op, MP_UNARY_OP_NEGATIVE);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_TILDE)); // should be
- EMIT_ARG(unary_op, MP_UNARY_OP_INVERT);
+ mp_unary_op_t op;
+ mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]);
+ switch (tok) {
+ case MP_TOKEN_OP_PLUS: op = MP_UNARY_OP_POSITIVE; break;
+ case MP_TOKEN_OP_MINUS: op = MP_UNARY_OP_NEGATIVE; break;
+ default:
+ assert(tok == MP_TOKEN_OP_TILDE);
+ op = MP_UNARY_OP_INVERT;
+ break;
}
+ EMIT_ARG(unary_op, op);
}
STATIC void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *pns) {
@@ -2308,6 +2303,10 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
}
} else {
normal_argument:
+ if (star_flags) {
+ compile_syntax_error(comp, args[i], "non-keyword arg after */**");
+ return;
+ }
if (n_keyword > 0) {
compile_syntax_error(comp, args[i], "non-keyword arg after keyword arg");
return;
@@ -2939,7 +2938,7 @@ STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) {
STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
comp->pass = pass;
comp->scope_cur = scope;
- comp->next_label = 1;
+ comp->next_label = 0;
EMIT_ARG(start_pass, pass, scope);
if (comp->pass == MP_PASS_SCOPE) {
@@ -3114,7 +3113,7 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
comp->pass = pass;
comp->scope_cur = scope;
- comp->next_label = 1;
+ comp->next_label = 0;
if (scope->kind != SCOPE_FUNCTION) {
compile_syntax_error(comp, MP_PARSE_NODE_NULL, "inline assembler must be a function");
@@ -3271,7 +3270,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
#endif
STATIC void scope_compute_things(scope_t *scope) {
- // in Micro Python we put the *x parameter after all other parameters (except **y)
+ // in MicroPython we put the *x parameter after all other parameters (except **y)
if (scope->scope_flags & MP_SCOPE_FLAG_VARARGS) {
id_info_t *id_param = NULL;
for (int i = scope->id_info_len - 1; i >= 0; i--) {
@@ -3309,7 +3308,7 @@ STATIC void scope_compute_things(scope_t *scope) {
// compute the index of cell vars
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
- // in Micro Python the cells come right after the fast locals
+ // in MicroPython the cells come right after the fast locals
// parameters are not counted here, since they remain at the start
// of the locals, even if they are cell vars
if (id->kind == ID_INFO_KIND_CELL && !(id->flags & ID_FLAG_IS_PARAM)) {
@@ -3329,14 +3328,14 @@ STATIC void scope_compute_things(scope_t *scope) {
id_info_t *id2 = &scope->id_info[j];
if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) {
assert(!(id2->flags & ID_FLAG_IS_PARAM)); // free vars should not be params
- // in Micro Python the frees come first, before the params
+ // in MicroPython the frees come first, before the params
id2->local_num = num_free;
num_free += 1;
}
}
}
}
- // in Micro Python shift all other locals after the free locals
+ // in MicroPython shift all other locals after the free locals
if (num_free > 0) {
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
@@ -3360,6 +3359,8 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
comp->source_file = source_file;
comp->is_repl = is_repl;
+ comp->break_label = INVALID_LABEL;
+ comp->continue_label = INVALID_LABEL;
// create the module scope
scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, parse_tree->root, emit_opt);
diff --git a/py/compile.h b/py/compile.h
index 45a98588d8..3297e83aeb 100644
--- a/py/compile.h
+++ b/py/compile.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_COMPILE_H__
-#define __MICROPY_INCLUDED_PY_COMPILE_H__
+#ifndef MICROPY_INCLUDED_PY_COMPILE_H
+#define MICROPY_INCLUDED_PY_COMPILE_H
#include "py/lexer.h"
#include "py/parse.h"
@@ -51,4 +51,4 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
// this is implemented in runtime.c
mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_input_kind, mp_obj_dict_t *globals, mp_obj_dict_t *locals);
-#endif // __MICROPY_INCLUDED_PY_COMPILE_H__
+#endif // MICROPY_INCLUDED_PY_COMPILE_H
diff --git a/py/emit.h b/py/emit.h
index b935409561..9d5726e6ef 100644
--- a/py/emit.h
+++ b/py/emit.h
@@ -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)
*
@@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-#ifndef __MICROPY_INCLUDED_PY_EMIT_H__
-#define __MICROPY_INCLUDED_PY_EMIT_H__
+#ifndef MICROPY_INCLUDED_PY_EMIT_H
+#define MICROPY_INCLUDED_PY_EMIT_H
#include "py/lexer.h"
#include "py/scope.h"
@@ -284,4 +283,4 @@ void mp_emitter_warning(pass_kind_t pass, const char *msg);
#define mp_emitter_warning(pass, msg)
#endif
-#endif // __MICROPY_INCLUDED_PY_EMIT_H__
+#endif // MICROPY_INCLUDED_PY_EMIT_H
diff --git a/py/emitbc.c b/py/emitbc.c
index ec12a62c6c..6770209257 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -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)
*
@@ -902,7 +902,7 @@ void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_ov
emit_write_bytecode_byte(emit, n_closed_over);
} else {
assert(n_closed_over <= 255);
- emit_bc_pre(emit, -2 - n_closed_over + 1);
+ emit_bc_pre(emit, -2 - (mp_int_t)n_closed_over + 1);
emit_write_bytecode_byte_raw_code(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->raw_code);
emit_write_bytecode_byte(emit, n_closed_over);
}
diff --git a/py/emitcommon.c b/py/emitcommon.c
index e914431d32..07b1dbb4ce 100644
--- a/py/emitcommon.c
+++ b/py/emitcommon.c
@@ -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)
*
diff --git a/py/emitglue.c b/py/emitglue.c
index ae63463828..d75cb80305 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -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)
*
@@ -35,7 +35,7 @@
#include "py/runtime0.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define WRITE_CODE (1)
#define DEBUG_printf DEBUG_printf
diff --git a/py/emitglue.h b/py/emitglue.h
index 37c4f1b18f..43930333d6 100644
--- a/py/emitglue.h
+++ b/py/emitglue.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_EMITGLUE_H__
-#define __MICROPY_INCLUDED_PY_EMITGLUE_H__
+#ifndef MICROPY_INCLUDED_PY_EMITGLUE_H
+#define MICROPY_INCLUDED_PY_EMITGLUE_H
#include "py/obj.h"
@@ -74,4 +74,4 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args);
mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, mp_uint_t n_closed_over, const mp_obj_t *args);
-#endif // __MICROPY_INCLUDED_PY_EMITGLUE_H__
+#endif // MICROPY_INCLUDED_PY_EMITGLUE_H
diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c
index f48086b1d2..a695b92b85 100644
--- a/py/emitinlinethumb.c
+++ b/py/emitinlinethumb.c
@@ -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)
*
diff --git a/py/emitnative.c b/py/emitnative.c
index 99adc809c7..4608cd1e0c 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -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)
*
@@ -50,7 +50,7 @@
#include "py/emit.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -824,7 +824,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de
break;
default:
// not handled
- mp_not_implemented("conversion to object");
+ mp_raise_NotImplementedError("conversion to object");
}
}
@@ -2158,7 +2158,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u
break;
default:
// this can happen when casting a cast: int(int)
- mp_not_implemented("casting");
+ mp_raise_NotImplementedError("casting");
}
} else {
assert(vtype_fun == VTYPE_PYOBJ);
@@ -2232,12 +2232,12 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) {
STATIC void emit_native_yield_value(emit_t *emit) {
// not supported (for now)
(void)emit;
- mp_not_implemented("native yield");
+ mp_raise_NotImplementedError("native yield");
}
STATIC void emit_native_yield_from(emit_t *emit) {
// not supported (for now)
(void)emit;
- mp_not_implemented("native yield from");
+ mp_raise_NotImplementedError("native yield from");
}
STATIC void emit_native_start_except_handler(emit_t *emit) {
diff --git a/py/formatfloat.c b/py/formatfloat.c
index 9ff80d9f63..35cd5d51af 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -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)
*
@@ -118,7 +118,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
*s++ = '?';
}
if (buf_size >= 1) {
- *s++ = '\0';
+ *s = '\0';
}
return buf_size >= 2;
}
@@ -161,7 +161,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
if (fmt == 'g' && prec == 0) {
prec = 1;
}
- int e, e1;
+ int e, e1;
int dec = 0;
char e_sign = '\0';
int num_digits = 0;
@@ -209,7 +209,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
e_sign_char = '+';
}
} else if (fp_isless1(f)) {
- e++;
+ e++;
f *= FPCONST(10.0);
}
@@ -232,7 +232,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
num_digits = prec;
if (num_digits) {
- *s++ = '.';
+ *s++ = '.';
while (--e && num_digits) {
*s++ = '0';
num_digits--;
@@ -266,7 +266,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
f *= FPCONST(0.1);
}
- // If the user specified fixed format (fmt == 'f') and e makes the
+ // If the user specified fixed format (fmt == 'f') and e makes the
// number too big to fit into the available buffer, then we'll
// switch to the 'e' format.
@@ -327,12 +327,12 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
if (prec == 0) {
prec = 1;
}
- num_digits = prec;
+ num_digits = prec;
}
// Print the digits of the mantissa
for (int i = 0; i < num_digits; ++i, --dec) {
- int32_t d = f;
+ int32_t d = (int32_t)f;
*s++ = '0' + d;
if (dec == 0 && prec > 0) {
*s++ = '.';
@@ -365,7 +365,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
if (rs == buf) {
break;
}
- rs--;
+ rs--;
}
if (*rs == '0') {
// We need to insert a 1
@@ -376,12 +376,17 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
rs[1] = '0';
if (e_sign == '-') {
e--;
+ if (e == 0) {
+ e_sign = '+';
+ }
} else {
- e++;
+ e++;
}
+ } else {
+ // Need at extra digit at the end to make room for the leading '1'
+ s++;
}
- s++;
- char *ss = s;
+ char *ss = s;
while (ss > rs) {
*ss = ss[-1];
ss--;
diff --git a/py/formatfloat.h b/py/formatfloat.h
index 0196034471..9a1643b4dd 100644
--- a/py/formatfloat.h
+++ b/py/formatfloat.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_FORMATFLOAT_H__
-#define __MICROPY_INCLUDED_PY_FORMATFLOAT_H__
+#ifndef MICROPY_INCLUDED_PY_FORMATFLOAT_H
+#define MICROPY_INCLUDED_PY_FORMATFLOAT_H
#include "py/mpconfig.h"
@@ -32,4 +32,4 @@
int mp_format_float(mp_float_t f, char *buf, size_t bufSize, char fmt, int prec, char sign);
#endif
-#endif // __MICROPY_INCLUDED_PY_FORMATFLOAT_H__
+#endif // MICROPY_INCLUDED_PY_FORMATFLOAT_H
diff --git a/py/frozenmod.c b/py/frozenmod.c
index 1eaaf574a2..06d4f84c8e 100644
--- a/py/frozenmod.c
+++ b/py/frozenmod.c
@@ -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)
*
diff --git a/py/frozenmod.h b/py/frozenmod.h
index 4b125ff247..8cddef6819 100644
--- a/py/frozenmod.h
+++ b/py/frozenmod.h
@@ -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)
*
@@ -23,6 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_PY_FROZENMOD_H
+#define MICROPY_INCLUDED_PY_FROZENMOD_H
#include "py/lexer.h"
@@ -35,3 +37,5 @@ enum {
int mp_find_frozen_module(const char *str, size_t len, void **data);
const char *mp_find_frozen_str(const char *str, size_t *len);
mp_import_stat_t mp_frozen_stat(const char *str);
+
+#endif // MICROPY_INCLUDED_PY_FROZENMOD_H
diff --git a/py/gc.c b/py/gc.c
index 937dae44f7..3a505e9c78 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -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)
*
@@ -35,7 +35,7 @@
#if MICROPY_ENABLE_GC
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -536,37 +536,34 @@ void gc_free(void *ptr) {
DEBUG_printf("gc_free(%p)\n", ptr);
- if (VERIFY_PTR(ptr)) {
+ if (ptr == NULL) {
+ GC_EXIT();
+ } else {
+ // get the GC block number corresponding to this pointer
+ assert(VERIFY_PTR(ptr));
size_t block = BLOCK_FROM_PTR(ptr);
- if (ATB_GET_KIND(block) == AT_HEAD) {
- #if MICROPY_ENABLE_FINALISER
- FTB_CLEAR(block);
- #endif
- // set the last_free pointer to this block if it's earlier in the heap
- if (block / BLOCKS_PER_ATB < MP_STATE_MEM(gc_last_free_atb_index)) {
- MP_STATE_MEM(gc_last_free_atb_index) = block / BLOCKS_PER_ATB;
- }
+ assert(ATB_GET_KIND(block) == AT_HEAD);
- // free head and all of its tail blocks
- do {
- ATB_ANY_TO_FREE(block);
- block += 1;
- } while (ATB_GET_KIND(block) == AT_TAIL);
-
- GC_EXIT();
+ #if MICROPY_ENABLE_FINALISER
+ FTB_CLEAR(block);
+ #endif
- #if EXTENSIVE_HEAP_PROFILING
- gc_dump_alloc_table();
- #endif
- } else {
- GC_EXIT();
- assert(!"bad free");
+ // set the last_free pointer to this block if it's earlier in the heap
+ if (block / BLOCKS_PER_ATB < MP_STATE_MEM(gc_last_free_atb_index)) {
+ MP_STATE_MEM(gc_last_free_atb_index) = block / BLOCKS_PER_ATB;
}
- } else if (ptr != NULL) {
- GC_EXIT();
- assert(!"bad free");
- } else {
+
+ // free head and all of its tail blocks
+ do {
+ ATB_ANY_TO_FREE(block);
+ block += 1;
+ } while (ATB_GET_KIND(block) == AT_TAIL);
+
GC_EXIT();
+
+ #if EXTENSIVE_HEAP_PROFILING
+ gc_dump_alloc_table();
+ #endif
}
}
diff --git a/py/gc.h b/py/gc.h
index 7d8fe2bf8c..739349c1f5 100644
--- a/py/gc.h
+++ b/py/gc.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_GC_H__
-#define __MICROPY_INCLUDED_PY_GC_H__
+#ifndef MICROPY_INCLUDED_PY_GC_H
+#define MICROPY_INCLUDED_PY_GC_H
#include <stdint.h>
@@ -64,4 +64,4 @@ void gc_info(gc_info_t *info);
void gc_dump_info(void);
void gc_dump_alloc_table(void);
-#endif // __MICROPY_INCLUDED_PY_GC_H__
+#endif // MICROPY_INCLUDED_PY_GC_H
diff --git a/py/grammar.h b/py/grammar.h
index 930d96dc15..6abb1de8c0 100644
--- a/py/grammar.h
+++ b/py/grammar.h
@@ -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)
*
@@ -32,7 +32,7 @@
// # single_input is a single interactive statement;
// # file_input is a module or sequence of commands read from an input file;
// # eval_input is the input for the eval() functions.
-// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in Micro Python
+// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in MicroPython
// single_input: NEWLINE | simple_stmt | compound_stmt
// file_input: (NEWLINE | stmt)* ENDMARKER
// eval_input: testlist NEWLINE* ENDMARKER
@@ -244,9 +244,9 @@ DEF_RULE(star_expr, c(star_expr), and(2), tok(OP_STAR), rule(expr))
DEF_RULE(expr, c(expr), list, rule(xor_expr), tok(OP_PIPE))
DEF_RULE(xor_expr, c(xor_expr), list, rule(and_expr), tok(OP_CARET))
DEF_RULE(and_expr, c(and_expr), list, rule(shift_expr), tok(OP_AMPERSAND))
-DEF_RULE(shift_expr, c(shift_expr), list, rule(arith_expr), rule(shift_op))
+DEF_RULE(shift_expr, c(term), list, rule(arith_expr), rule(shift_op))
DEF_RULE_NC(shift_op, or(2), tok(OP_DBL_LESS), tok(OP_DBL_MORE))
-DEF_RULE(arith_expr, c(arith_expr), list, rule(term), rule(arith_op))
+DEF_RULE(arith_expr, c(term), list, rule(term), rule(arith_op))
DEF_RULE_NC(arith_op, or(2), tok(OP_PLUS), tok(OP_MINUS))
DEF_RULE(term, c(term), list, rule(factor), rule(term_op))
DEF_RULE_NC(term_op, or(4), tok(OP_STAR), tok(OP_SLASH), tok(OP_PERCENT), tok(OP_DBL_SLASH))
diff --git a/py/lexer.c b/py/lexer.c
index abc1f3ebbb..074d6f3561 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -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)
*
@@ -341,7 +341,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
// 3MB of text; even gzip-compressed and with minimal structure, it'll take
// roughly half a meg of storage. This form of Unicode escape may be added
// later on, but it's definitely not a priority right now. -- CJA 20140607
- mp_not_implemented("unicode name escapes");
+ mp_raise_NotImplementedError("unicode name escapes");
break;
default:
if (c >= '0' && c <= '7') {
@@ -672,7 +672,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
lex->source_name = src_name;
lex->reader = reader;
lex->line = 1;
- lex->column = -2; // account for 3 dummy bytes
+ lex->column = (size_t)-2; // account for 3 dummy bytes
lex->emit_dent = 0;
lex->nested_bracket_level = 0;
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;
diff --git a/py/lexer.h b/py/lexer.h
index 5d998b3521..a29709107d 100644
--- a/py/lexer.h
+++ b/py/lexer.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_LEXER_H__
-#define __MICROPY_INCLUDED_PY_LEXER_H__
+#ifndef MICROPY_INCLUDED_PY_LEXER_H
+#define MICROPY_INCLUDED_PY_LEXER_H
#include <stdint.h>
@@ -32,7 +32,7 @@
#include "py/qstr.h"
#include "py/reader.h"
-/* lexer.h -- simple tokeniser for Micro Python
+/* lexer.h -- simple tokeniser for MicroPython
*
* Uses (byte) length instead of null termination.
* Tokens are the same - UTF-8 with (byte) length.
@@ -192,4 +192,4 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename);
mp_lexer_t *mp_lexer_new_from_fd(qstr filename, int fd, bool close_fd);
#endif
-#endif // __MICROPY_INCLUDED_PY_LEXER_H__
+#endif // MICROPY_INCLUDED_PY_LEXER_H
diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py
index 1d8f59bd22..749160b4df 100644
--- a/py/makeversionhdr.py
+++ b/py/makeversionhdr.py
@@ -59,8 +59,8 @@ def get_version_info_from_git():
def get_version_info_from_docs_conf():
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "docs", "conf.py")) as f:
for line in f:
- if line.startswith("release = '"):
- ver = line.strip()[10:].strip("'")
+ if line.startswith("version = release = '"):
+ ver = line.strip().split(" = ")[2].strip("'")
git_tag = "v" + ver
ver = ver.split(".")
if len(ver) == 2:
diff --git a/py/malloc.c b/py/malloc.c
index f48cb8da4f..af4ccf2e81 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -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)
*
@@ -32,7 +32,7 @@
#include "py/misc.h"
#include "py/mpstate.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(...) (void)0
@@ -46,7 +46,7 @@
#include "py/gc.h"
// We redirect standard alloc functions to GC heap - just for the rest of
-// this module. In the rest of micropython source, system malloc can be
+// this module. In the rest of MicroPython source, system malloc can be
// freely accessed - for interfacing with system and 3rd-party libs for
// example. On the other hand, some (e.g. bare-metal) ports may use GC
// heap as system heap, so, to avoid warnings, we do undef's first.
diff --git a/py/map.c b/py/map.c
index 50d74f38f5..7f3c900590 100644
--- a/py/map.c
+++ b/py/map.c
@@ -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)
*
diff --git a/py/misc.h b/py/misc.h
index c2b1b232b2..f0ebb558bd 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MISC_H__
-#define __MICROPY_INCLUDED_PY_MISC_H__
+#ifndef MICROPY_INCLUDED_PY_MISC_H
+#define MICROPY_INCLUDED_PY_MISC_H
// a mini library of useful types and functions
@@ -92,7 +92,7 @@ void *m_realloc(void *ptr, size_t new_num_bytes);
void *m_realloc_maybe(void *ptr, size_t new_num_bytes, bool allow_move);
void m_free(void *ptr);
#endif
-void *m_malloc_fail(size_t num_bytes);
+NORETURN void *m_malloc_fail(size_t num_bytes);
#if MICROPY_MEM_STATS
size_t m_get_total_bytes_allocated(void);
@@ -224,4 +224,4 @@ static inline mp_uint_t count_lead_ones(byte val) {
#define MP_FLOAT_EXP_BIAS ((1 << (MP_FLOAT_EXP_BITS - 1)) - 1)
#endif // MICROPY_PY_BUILTINS_FLOAT
-#endif // __MICROPY_INCLUDED_PY_MISC_H__
+#endif // MICROPY_INCLUDED_PY_MISC_H
diff --git a/py/mkrules.mk b/py/mkrules.mk
index 00ed279176..bf6ad29410 100644
--- a/py/mkrules.mk
+++ b/py/mkrules.mk
@@ -6,7 +6,7 @@ endif
# This file expects that OBJ contains a list of all of the object files.
# The directory portion of each object file is used to locate the source
-# and should not contain any ..'s but rather be relative to the top of the
+# and should not contain any ..'s but rather be relative to the top of the
# tree.
#
# So for example, py/map.c would have an object file name py/map.o
@@ -47,7 +47,7 @@ $(BUILD)/%.o: %.c
$(call compile_c)
# List all native flags since the current build system doesn't have
-# the micropython configuration available. However, these flags are
+# the MicroPython configuration available. However, these flags are
# needed to extract all qstrings
QSTR_GEN_EXTRA_CFLAGS += -DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB -DN_ARM -DN_XTENSA
QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp
@@ -135,7 +135,7 @@ $(PROG): $(OBJ)
ifndef DEBUG
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
endif
- $(Q)$(SIZE) $(PROG)
+ $(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $(PROG)
clean: clean-prog
clean-prog:
diff --git a/py/modarray.c b/py/modarray.c
index 356e48bee0..c0cdca9286 100644
--- a/py/modarray.c
+++ b/py/modarray.c
@@ -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)
*
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index fe8159953a..1c76b80739 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -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)
*
@@ -91,10 +91,8 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args)
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
- if (0) {
- // dummy
-#if MICROPY_PY_BUILTINS_FLOAT
- } else if (mp_obj_is_float(o_in)) {
+ #if MICROPY_PY_BUILTINS_FLOAT
+ if (mp_obj_is_float(o_in)) {
mp_float_t value = mp_obj_float_get(o_in);
// TODO check for NaN etc
if (value < 0) {
@@ -102,17 +100,17 @@ STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
} else {
return o_in;
}
-#if MICROPY_PY_BUILTINS_COMPLEX
+ #if MICROPY_PY_BUILTINS_COMPLEX
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
mp_float_t real, imag;
mp_obj_complex_get(o_in, &real, &imag);
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
-#endif
-#endif
- } else {
- // this will raise a TypeError if the argument is not integral
- return mp_obj_int_abs(o_in);
+ #endif
}
+ #endif
+
+ // this will raise a TypeError if the argument is not integral
+ return mp_obj_int_abs(o_in);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
@@ -226,14 +224,14 @@ STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) {
mp_obj_t dir = mp_obj_new_list(0, NULL);
if (dict != NULL) {
- for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
+ for (size_t i = 0; i < dict->map.alloc; i++) {
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
mp_obj_list_append(dir, dict->map.table[i].key);
}
}
}
if (members != NULL) {
- for (mp_uint_t i = 0; i < members->alloc; i++) {
+ for (size_t i = 0; i < members->alloc; i++) {
if (MP_MAP_SLOT_IS_FILLED(members, i)) {
mp_obj_list_append(dir, members->table[i].key);
}
@@ -326,7 +324,7 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t
// given many args
mp_obj_t best_key = MP_OBJ_NULL;
mp_obj_t best_obj = MP_OBJ_NULL;
- for (mp_uint_t i = 0; i < n_args; i++) {
+ for (size_t i = 0; i < n_args; i++) {
mp_obj_t key = key_fn == MP_OBJ_NULL ? args[i] : mp_call_function_1(key_fn, args[i]);
if (best_obj == MP_OBJ_NULL || (mp_binary_op(op, key, best_key) == mp_const_true)) {
best_key = key;
@@ -398,8 +396,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
#endif
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "ord expects a character"));
+ mp_raise_TypeError("ord expects a character");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"ord() expected a character, but string of length %d found", (int)len));
@@ -444,7 +441,7 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *args, mp_map_t *
mp_print_t print = {stream_obj, mp_stream_write_adaptor};
#endif
- for (mp_uint_t i = 0; i < n_args; i++) {
+ for (size_t i = 0; i < n_args; i++) {
if (i > 0) {
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
mp_stream_write_adaptor(stream_obj, sep_data, sep_len);
@@ -543,7 +540,7 @@ STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj, 1, mp_builtin_sorted);
// See mp_load_attr() if making any changes
-STATIC inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
+static inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
mp_obj_t dest[2];
// use load_method, raising or not raising exception
((defval == MP_OBJ_NULL) ? mp_load_method : mp_load_method_maybe)(base, attr, dest);
diff --git a/py/modcmath.c b/py/modcmath.c
index 7ad8f5ad60..627a2cbadb 100644
--- a/py/modcmath.c
+++ b/py/modcmath.c
@@ -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)
*
diff --git a/py/modcollections.c b/py/modcollections.c
index e610a28d24..1a1560387a 100644
--- a/py/modcollections.c
+++ b/py/modcollections.c
@@ -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)
*
diff --git a/py/modgc.c b/py/modgc.c
index 24564622ec..d45e007ebe 100644
--- a/py/modgc.c
+++ b/py/modgc.c
@@ -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)
*
diff --git a/py/modio.c b/py/modio.c
index 2d317d022a..353a002865 100644
--- a/py/modio.c
+++ b/py/modio.c
@@ -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)
*
@@ -112,9 +112,9 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush);
-STATIC const mp_map_elem_t bufwriter_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flush), (mp_obj_t)&bufwriter_flush_obj },
+STATIC const mp_rom_map_elem_t bufwriter_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&bufwriter_flush_obj) },
};
STATIC MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table);
@@ -127,7 +127,7 @@ STATIC const mp_obj_type_t bufwriter_type = {
.name = MP_QSTR_BufferedWriter,
.make_new = bufwriter_make_new,
.protocol = &bufwriter_stream_p,
- .locals_dict = (mp_obj_t)&bufwriter_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&bufwriter_locals_dict,
};
#endif // MICROPY_PY_IO_BUFFEREDWRITER
diff --git a/py/modmath.c b/py/modmath.c
index ddab337d05..c56056a5dd 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -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)
*
@@ -25,7 +25,7 @@
*/
#include "py/builtin.h"
-#include "py/nlr.h"
+#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH
@@ -41,7 +41,7 @@
/// working with floating-point numbers.
STATIC NORETURN void math_error(void) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "math domain error"));
+ mp_raise_ValueError("math domain error");
}
#define MATH_FUN_1(py_name, c_name) \
@@ -168,6 +168,8 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
mp_float_t base = mp_obj_get_float(args[1]);
if (base <= (mp_float_t)0.0) {
math_error();
+ } else if (base == (mp_float_t)1.0) {
+ mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
}
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
}
diff --git a/py/modmicropython.c b/py/modmicropython.c
index d767062301..6fa3f9ad28 100644
--- a/py/modmicropython.c
+++ b/py/modmicropython.c
@@ -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)
*
@@ -72,7 +72,8 @@ mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args) {
(mp_uint_t)m_get_total_bytes_allocated(), (mp_uint_t)m_get_current_bytes_allocated(), (mp_uint_t)m_get_peak_bytes_allocated());
#endif
#if MICROPY_STACK_CHECK
- mp_printf(&mp_plat_print, "stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_THREAD(stack_limit));
+ mp_printf(&mp_plat_print, "stack: " UINT_FMT " out of " UINT_FMT "\n",
+ mp_stack_usage(), (mp_uint_t)MP_STATE_THREAD(stack_limit));
#else
mp_printf(&mp_plat_print, "stack: " UINT_FMT "\n", mp_stack_usage());
#endif
diff --git a/py/modstruct.c b/py/modstruct.c
index 3c99ef1d8d..1daa333388 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -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)
*
diff --git a/py/modsys.c b/py/modsys.c
index b8c427ba87..b7d55fdcc6 100644
--- a/py/modsys.c
+++ b/py/modsys.c
@@ -1,9 +1,10 @@
/*
- * 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)
*
* Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2014-2017 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,8 +32,11 @@
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/objint.h"
+#include "py/objtype.h"
#include "py/stream.h"
#include "py/smallint.h"
+#include "py/runtime0.h"
+#include "py/runtime.h"
#if MICROPY_PY_SYS
@@ -87,7 +91,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
#undef I
#ifdef MICROPY_PY_SYS_PLATFORM
-/// \constant platform - the platform that Micro Python is running on
+/// \constant platform - the platform that MicroPython is running on
STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM);
#endif
@@ -143,6 +147,11 @@ STATIC mp_obj_t mp_sys_exc_info(void) {
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info);
#endif
+STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) {
+ return mp_unary_op(MP_UNARY_OP_SIZEOF, obj);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof);
+
STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) },
@@ -168,7 +177,7 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
// to not try to compare sys.maxsize to some literal number (as this
// number might not fit in available int size), but instead count number
// of "one" bits in sys.maxsize.
- { MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(MP_SMALL_INT_MAX) },
+ { MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_INT(MP_SMALL_INT_MAX) },
#else
{ MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_PTR(&mp_maxsize_obj) },
#endif
@@ -192,6 +201,9 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
#if MICROPY_PY_SYS_EXC_INFO
{ MP_ROM_QSTR(MP_QSTR_exc_info), MP_ROM_PTR(&mp_sys_exc_info_obj) },
#endif
+ #if MICROPY_PY_SYS_GETSIZEOF
+ { MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) },
+ #endif
/*
* Extensions to CPython
diff --git a/py/modthread.c b/py/modthread.c
index d0e71dad3b..bf74128e81 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -34,7 +34,7 @@
#include "py/mpthread.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -84,7 +84,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread
STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) {
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
- // TODO check if already unlocked
+ if (!self->locked) {
+ mp_raise_msg(&mp_type_RuntimeError, NULL);
+ }
self->locked = false;
MP_THREAD_GIL_EXIT();
mp_thread_mutex_unlock(&self->mutex);
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 1ec8ae21c8..dac8a903c9 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MPCONFIG_H__
-#define __MICROPY_INCLUDED_PY_MPCONFIG_H__
+#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
+#define MICROPY_INCLUDED_PY_MPCONFIG_H
// This file contains default configuration settings for MicroPython.
// You can override any of the options below using mpconfigport.h file
@@ -51,13 +51,13 @@
/*****************************************************************************/
/* Object representation */
-// A Micro Python object is a machine word having the following form:
+// A MicroPython object is a machine word having the following form:
// - xxxx...xxx1 : a small int, bits 1 and above are the value
// - xxxx...xx10 : a qstr, bits 2 and above are the value
// - xxxx...xx00 : a pointer to an mp_obj_base_t (unless a fake object)
#define MICROPY_OBJ_REPR_A (0)
-// A Micro Python object is a machine word having the following form:
+// A MicroPython object is a machine word having the following form:
// - xxxx...xx01 : a small int, bits 2 and above are the value
// - xxxx...xx11 : a qstr, bits 2 and above are the value
// - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
@@ -73,7 +73,6 @@
// Str and float stored as O = R + 0x80800000, retrieved as R = O - 0x80800000.
// This makes strs easier to encode/decode as they have zeros in the top 9 bits.
// This scheme only works with 32-bit word size and float enabled.
-
#define MICROPY_OBJ_REPR_C (2)
// A MicroPython object is a 64-bit word having the following form (called R):
@@ -235,7 +234,7 @@
#endif
/*****************************************************************************/
-/* Micro Python emitters */
+/* MicroPython emitters */
// Whether to support loading of persistent code
#ifndef MICROPY_PERSISTENT_CODE_LOAD
@@ -374,6 +373,11 @@
#define MICROPY_DEBUG_PRINTERS (0)
#endif
+// Whether to enable all debugging outputs (it will be extremely verbose)
+#ifndef MICROPY_DEBUG_VERBOSE
+#define MICROPY_DEBUG_VERBOSE (0)
+#endif
+
/*****************************************************************************/
/* Optimisations */
@@ -945,6 +949,11 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_EXIT (1)
#endif
+// Whether to provide "sys.getsizeof" function
+#ifndef MICROPY_PY_SYS_GETSIZEOF
+#define MICROPY_PY_SYS_GETSIZEOF (0)
+#endif
+
// Whether to provide sys.{stdin,stdout,stderr} objects
#ifndef MICROPY_PY_SYS_STDFILES
#define MICROPY_PY_SYS_STDFILES (0)
@@ -1254,4 +1263,4 @@ typedef double mp_float_t;
#define MP_UNLIKELY(x) __builtin_expect((x), 0)
#endif
-#endif // __MICROPY_INCLUDED_PY_MPCONFIG_H__
+#endif // MICROPY_INCLUDED_PY_MPCONFIG_H
diff --git a/py/mperrno.h b/py/mperrno.h
index 6ea99ae227..f439f65554 100644
--- a/py/mperrno.h
+++ b/py/mperrno.h
@@ -23,9 +23,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#ifndef MICROPY_INCLUDED_PY_MPERRNO_H
+#define MICROPY_INCLUDED_PY_MPERRNO_H
-#ifndef __MICROPY_INCLUDED_PY_MPERRNO_H__
-#define __MICROPY_INCLUDED_PY_MPERRNO_H__
+#include "py/mpconfig.h"
#if MICROPY_USE_INTERNAL_ERRNO
@@ -139,7 +140,11 @@
#endif
#if MICROPY_PY_UERRNO
+
+#include "py/obj.h"
+
qstr mp_errno_to_str(mp_obj_t errno_val);
+
#endif
-#endif // __MICROPY_INCLUDED_PY_MPERRNO_H__
+#endif // MICROPY_INCLUDED_PY_MPERRNO_H
diff --git a/py/mphal.h b/py/mphal.h
index 8d5654f9e3..92de01d08b 100644
--- a/py/mphal.h
+++ b/py/mphal.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MPHAL_H__
-#define __MICROPY_INCLUDED_PY_MPHAL_H__
+#ifndef MICROPY_INCLUDED_PY_MPHAL_H
+#define MICROPY_INCLUDED_PY_MPHAL_H
#include "py/mpconfig.h"
@@ -80,4 +80,4 @@ mp_uint_t mp_hal_ticks_cpu(void);
#include "extmod/virtpin.h"
#endif
-#endif // __MICROPY_INCLUDED_PY_MPHAL_H__
+#endif // MICROPY_INCLUDED_PY_MPHAL_H
diff --git a/py/mpprint.c b/py/mpprint.c
index 4bc45fef4d..6c02d7cefb 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -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)
*
@@ -354,9 +354,6 @@ int mp_print_float(const mp_print_t *print, mp_float_t f, char fmt, int flags, c
}
int len = mp_format_float(f, buf, sizeof(buf), fmt, prec, sign);
- if (len < 0) {
- len = 0;
- }
char *s = buf;
diff --git a/py/mpprint.h b/py/mpprint.h
index 4fc904a20a..07462bddcc 100644
--- a/py/mpprint.h
+++ b/py/mpprint.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MPPRINT_H__
-#define __MICROPY_INCLUDED_PY_MPPRINT_H__
+#ifndef MICROPY_INCLUDED_PY_MPPRINT_H
+#define MICROPY_INCLUDED_PY_MPPRINT_H
#include "py/mpconfig.h"
@@ -71,4 +71,4 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...);
int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args);
#endif
-#endif // __MICROPY_INCLUDED_PY_MPPRINT_H__
+#endif // MICROPY_INCLUDED_PY_MPPRINT_H
diff --git a/py/mpstate.c b/py/mpstate.c
index 4fc8bc506e..6ce64adfd1 100644
--- a/py/mpstate.c
+++ b/py/mpstate.c
@@ -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)
*
diff --git a/py/mpstate.h b/py/mpstate.h
index 2b8f29a6ae..eca14a9e44 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MPSTATE_H__
-#define __MICROPY_INCLUDED_PY_MPSTATE_H__
+#ifndef MICROPY_INCLUDED_PY_MPSTATE_H
+#define MICROPY_INCLUDED_PY_MPSTATE_H
#include <stdint.h>
@@ -36,7 +36,7 @@
#include "py/objlist.h"
#include "py/objexcept.h"
-// This file contains structures defining the state of the Micro Python
+// This file contains structures defining the state of the MicroPython
// memory system, runtime and virtual machine. The state is a global
// variable, but in the future it is hoped that the state can become local.
@@ -248,4 +248,4 @@ extern mp_state_thread_t *mp_thread_get_state(void);
#define MP_STATE_THREAD(x) (mp_state_ctx.thread.x)
#endif
-#endif // __MICROPY_INCLUDED_PY_MPSTATE_H__
+#endif // MICROPY_INCLUDED_PY_MPSTATE_H
diff --git a/py/mpthread.h b/py/mpthread.h
index 04d4f19684..602df830c4 100644
--- a/py/mpthread.h
+++ b/py/mpthread.h
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MPTHREAD_H__
-#define __MICROPY_INCLUDED_PY_MPTHREAD_H__
+#ifndef MICROPY_INCLUDED_PY_MPTHREAD_H
+#define MICROPY_INCLUDED_PY_MPTHREAD_H
#include "py/mpconfig.h"
@@ -58,4 +58,4 @@ void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex);
#define MP_THREAD_GIL_EXIT()
#endif
-#endif // __MICROPY_INCLUDED_PY_MPTHREAD_H__
+#endif // MICROPY_INCLUDED_PY_MPTHREAD_H
diff --git a/py/mpz.c b/py/mpz.c
index f5675a2917..d300a8e5db 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -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)
*
@@ -939,10 +939,6 @@ void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf)
z->len = mpn_remove_trailing_zeros(z->dig, z->dig + z->len);
}
-bool mpz_is_zero(const mpz_t *z) {
- return z->len == 0;
-}
-
#if 0
these functions are unused
@@ -950,10 +946,6 @@ bool mpz_is_pos(const mpz_t *z) {
return z->len > 0 && z->neg == 0;
}
-bool mpz_is_neg(const mpz_t *z) {
- return z->len > 0 && z->neg != 0;
-}
-
bool mpz_is_odd(const mpz_t *z) {
return z->len > 0 && (z->dig[0] & 1) != 0;
}
diff --git a/py/mpz.h b/py/mpz.h
index 5c88227223..e2d0c30aac 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_MPZ_H__
-#define __MICROPY_INCLUDED_PY_MPZ_H__
+#ifndef MICROPY_INCLUDED_PY_MPZ_H
+#define MICROPY_INCLUDED_PY_MPZ_H
#include <stdint.h>
@@ -111,7 +111,8 @@ void mpz_set_from_float(mpz_t *z, mp_float_t src);
size_t mpz_set_from_str(mpz_t *z, const char *str, size_t len, bool neg, unsigned int base);
void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf);
-bool mpz_is_zero(const mpz_t *z);
+static inline bool mpz_is_zero(const mpz_t *z) { return z->len == 0; }
+static inline bool mpz_is_neg(const mpz_t *z) { return z->len != 0 && z->neg != 0; }
int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
void mpz_abs_inpl(mpz_t *dest, const mpz_t *z);
@@ -139,4 +140,4 @@ mp_float_t mpz_as_float(const mpz_t *z);
#endif
size_t mpz_as_str_inpl(const mpz_t *z, unsigned int base, const char *prefix, char base_char, char comma, char *str);
-#endif // __MICROPY_INCLUDED_PY_MPZ_H__
+#endif // MICROPY_INCLUDED_PY_MPZ_H
diff --git a/py/nativeglue.c b/py/nativeglue.c
index c75e5ec047..e954234c27 100644
--- a/py/nativeglue.c
+++ b/py/nativeglue.c
@@ -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)
*
@@ -34,7 +34,7 @@
#include "py/emitglue.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(...) (void)0
@@ -42,7 +42,7 @@
#if MICROPY_EMIT_NATIVE
-// convert a Micro Python object to a valid native value based on type
+// convert a MicroPython object to a valid native value based on type
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
DEBUG_printf("mp_convert_obj_to_native(%p, " UINT_FMT ")\n", obj, type);
switch (type & 0xf) {
@@ -66,7 +66,7 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
-// convert a native value to a Micro Python object based on type
+// convert a native value to a MicroPython object based on type
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type);
switch (type & 0xf) {
diff --git a/py/nlr.h b/py/nlr.h
index 7a71ef34bd..63fe392d9e 100644
--- a/py/nlr.h
+++ b/py/nlr.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_NLR_H__
-#define __MICROPY_INCLUDED_PY_NLR_H__
+#ifndef MICROPY_INCLUDED_PY_NLR_H
+#define MICROPY_INCLUDED_PY_NLR_H
// non-local return
// exception handling, basically a stack of setjmp/longjmp buffers
@@ -112,4 +112,4 @@ NORETURN void nlr_jump_fail(void *val);
#endif
-#endif // __MICROPY_INCLUDED_PY_NLR_H__
+#endif // MICROPY_INCLUDED_PY_NLR_H
diff --git a/py/nlrsetjmp.c b/py/nlrsetjmp.c
index c3873e0b6d..1fb4594403 100644
--- a/py/nlrsetjmp.c
+++ b/py/nlrsetjmp.c
@@ -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)
*
diff --git a/py/obj.c b/py/obj.c
index 493945a227..515a95b2e4 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -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)
*
@@ -460,8 +460,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
}
} else if (value == MP_OBJ_SENTINEL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "object is not subscriptable"));
+ mp_raise_TypeError("object is not subscriptable");
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not subscriptable", mp_obj_get_type_str(base)));
diff --git a/py/obj.h b/py/obj.h
index a3c06a261a..22bfda0f99 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJ_H__
-#define __MICROPY_INCLUDED_PY_OBJ_H__
+#ifndef MICROPY_INCLUDED_PY_OBJ_H
+#define MICROPY_INCLUDED_PY_OBJ_H
#include "py/mpconfig.h"
#include "py/misc.h"
@@ -864,4 +864,4 @@ mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t
memmove(((char*)dest) + (beg + slice_len) * (item_sz), ((char*)dest) + (end) * (item_sz), ((dest_len) + (len_adj) - ((beg) + (slice_len))) * (item_sz)); \
memmove(((char*)dest) + (beg) * (item_sz), slice, slice_len * (item_sz));
-#endif // __MICROPY_INCLUDED_PY_OBJ_H__
+#endif // MICROPY_INCLUDED_PY_OBJ_H
diff --git a/py/objarray.c b/py/objarray.c
index 21479a800f..a31c536804 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -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)
*
@@ -288,7 +288,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
// Otherwise, can only look for a scalar numeric value in an array
if (MP_OBJ_IS_INT(rhs_in) || mp_obj_is_float(rhs_in)) {
- mp_not_implemented("");
+ mp_raise_NotImplementedError("");
}
return mp_const_false;
@@ -378,7 +378,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
} else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) {
- mp_not_implemented("only slices with step=1 (aka None) are supported");
+ mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
}
if (value != MP_OBJ_SENTINEL) {
#if MICROPY_PY_ARRAY_SLICE_ASSIGN
@@ -409,7 +409,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
src_len = bufinfo.len;
src_items = bufinfo.buf;
} else {
- mp_not_implemented("array/bytes required on right side");
+ mp_raise_NotImplementedError("array/bytes required on right side");
}
// TODO: check src/dst compat
diff --git a/py/objarray.h b/py/objarray.h
index 06a2a07efb..0389668458 100644
--- a/py/objarray.h
+++ b/py/objarray.h
@@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-
-#ifndef __MICROPY_INCLUDED_PY_OBJARRAY_H__
-#define __MICROPY_INCLUDED_PY_OBJARRAY_H__
+#ifndef MICROPY_INCLUDED_PY_OBJARRAY_H
+#define MICROPY_INCLUDED_PY_OBJARRAY_H
#include "py/obj.h"
@@ -40,4 +39,4 @@ typedef struct _mp_obj_array_t {
void *items;
} mp_obj_array_t;
-#endif // __MICROPY_INCLUDED_PY_OBJARRAY_H__
+#endif // MICROPY_INCLUDED_PY_OBJARRAY_H
diff --git a/py/objattrtuple.c b/py/objattrtuple.c
index 8c5e795757..3cc298d4e9 100644
--- a/py/objattrtuple.c
+++ b/py/objattrtuple.c
@@ -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)
*
diff --git a/py/objbool.c b/py/objbool.c
index 5bc04bb6f9..e5bc3c2287 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -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)
*
diff --git a/py/objboundmeth.c b/py/objboundmeth.c
index 57be6a6cfd..890f8b15b6 100644
--- a/py/objboundmeth.c
+++ b/py/objboundmeth.c
@@ -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)
*
diff --git a/py/objcell.c b/py/objcell.c
index 06a88b9547..111906412e 100644
--- a/py/objcell.c
+++ b/py/objcell.c
@@ -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)
*
diff --git a/py/objclosure.c b/py/objclosure.c
index 3e12358bbd..4eb9eb8b84 100644
--- a/py/objclosure.c
+++ b/py/objclosure.c
@@ -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)
*
diff --git a/py/objcomplex.c b/py/objcomplex.c
index 5f9183f0e7..55627afea2 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -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)
*
@@ -196,7 +196,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
}
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't do truncated division of a complex number"));
+ mp_raise_TypeError("can't do truncated division of a complex number");
case MP_BINARY_OP_TRUE_DIVIDE:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
@@ -229,7 +229,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");
}
diff --git a/py/objdict.c b/py/objdict.c
index 12ba61b2e9..f6357a905b 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -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)
*
@@ -105,6 +105,12 @@ STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) {
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
+ #if MICROPY_PY_SYS_GETSIZEOF
+ case MP_UNARY_OP_SIZEOF: {
+ size_t sz = sizeof(*self) + sizeof(*self->map.table) * self->map.alloc;
+ return MP_OBJ_NEW_SMALL_INT(sz);
+ }
+ #endif
default: return MP_OBJ_NULL; // op not supported
}
}
@@ -278,18 +284,20 @@ STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj));
-STATIC mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, mp_map_lookup_kind_t lookup_kind) {
- mp_map_elem_t *elem = mp_map_lookup(self, key, lookup_kind);
+STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind) {
+ mp_check_self(MP_OBJ_IS_DICT_TYPE(args[0]));
+ mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]);
+ mp_map_elem_t *elem = mp_map_lookup(&self->map, args[1], lookup_kind);
mp_obj_t value;
if (elem == NULL || elem->value == MP_OBJ_NULL) {
- if (deflt == MP_OBJ_NULL) {
+ if (n_args == 2) {
if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, key));
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, args[1]));
} else {
value = mp_const_none;
}
} else {
- value = deflt;
+ value = args[2];
}
if (lookup_kind == MP_MAP_LOOKUP_ADD_IF_NOT_FOUND) {
elem->value = value;
@@ -304,40 +312,20 @@ STATIC mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, mp
}
STATIC mp_obj_t dict_get(size_t n_args, const mp_obj_t *args) {
- mp_check_self(MP_OBJ_IS_DICT_TYPE(args[0]));
- mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]);
-
- return dict_get_helper(&self->map,
- args[1],
- n_args == 3 ? args[2] : MP_OBJ_NULL,
- MP_MAP_LOOKUP);
+ return dict_get_helper(n_args, args, MP_MAP_LOOKUP);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get);
STATIC mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args) {
- mp_check_self(MP_OBJ_IS_DICT_TYPE(args[0]));
- mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]);
-
- return dict_get_helper(&self->map,
- args[1],
- n_args == 3 ? args[2] : MP_OBJ_NULL,
- MP_MAP_LOOKUP_REMOVE_IF_FOUND);
+ return dict_get_helper(n_args, args, MP_MAP_LOOKUP_REMOVE_IF_FOUND);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop);
-
STATIC mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args) {
- mp_check_self(MP_OBJ_IS_DICT_TYPE(args[0]));
- mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]);
-
- return dict_get_helper(&self->map,
- args[1],
- n_args == 3 ? args[2] : MP_OBJ_NULL,
- MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
+ return dict_get_helper(n_args, args, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setdefault);
-
STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
mp_check_self(MP_OBJ_IS_DICT_TYPE(self_in));
mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
@@ -615,9 +603,8 @@ mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value) {
}
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key) {
- mp_check_self(MP_OBJ_IS_DICT_TYPE(self_in));
- mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
- dict_get_helper(&self->map, key, MP_OBJ_NULL, MP_MAP_LOOKUP_REMOVE_IF_FOUND);
+ mp_obj_t args[2] = {self_in, key};
+ dict_get_helper(2, args, MP_MAP_LOOKUP_REMOVE_IF_FOUND);
return self_in;
}
diff --git a/py/objenumerate.c b/py/objenumerate.c
index faae6516c0..1a9d30f836 100644
--- a/py/objenumerate.c
+++ b/py/objenumerate.c
@@ -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)
*
diff --git a/py/objexcept.c b/py/objexcept.c
index 4722aca914..a9fe040941 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -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)
*
diff --git a/py/objexcept.h b/py/objexcept.h
index 3128fded79..f67651a7eb 100644
--- a/py/objexcept.h
+++ b/py/objexcept.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJEXCEPT_H__
-#define __MICROPY_INCLUDED_PY_OBJEXCEPT_H__
+#ifndef MICROPY_INCLUDED_PY_OBJEXCEPT_H
+#define MICROPY_INCLUDED_PY_OBJEXCEPT_H
#include "py/obj.h"
#include "py/objtuple.h"
@@ -37,4 +37,4 @@ typedef struct _mp_obj_exception_t {
mp_obj_tuple_t *args;
} mp_obj_exception_t;
-#endif // __MICROPY_INCLUDED_PY_OBJEXCEPT_H__
+#endif // MICROPY_INCLUDED_PY_OBJEXCEPT_H
diff --git a/py/objfilter.c b/py/objfilter.c
index a655b8a785..cb965d8c32 100644
--- a/py/objfilter.c
+++ b/py/objfilter.c
@@ -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)
*
diff --git a/py/objfloat.c b/py/objfloat.c
index d0e6166121..15edd810f1 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -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)
*
diff --git a/py/objfun.c b/py/objfun.c
index 9f35891243..5606511d8a 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -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)
*
@@ -36,7 +36,7 @@
#include "py/bc.h"
#include "py/stackctrl.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#else // don't print debugging info
#define DEBUG_PRINT (0)
@@ -480,7 +480,7 @@ typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t);
typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t);
typedef mp_uint_t (*inline_asm_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t);
-// convert a Micro Python object to a sensible value for inline asm
+// convert a MicroPython object to a sensible value for inline asm
STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
// TODO for byte_array, pass pointer to the array
if (MP_OBJ_IS_SMALL_INT(obj)) {
diff --git a/py/objfun.h b/py/objfun.h
index d02fada9b1..fbb3516261 100644
--- a/py/objfun.h
+++ b/py/objfun.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJFUN_H__
-#define __MICROPY_INCLUDED_PY_OBJFUN_H__
+#ifndef MICROPY_INCLUDED_PY_OBJFUN_H
+#define MICROPY_INCLUDED_PY_OBJFUN_H
#include "py/obj.h"
@@ -41,4 +41,4 @@ typedef struct _mp_obj_fun_bc_t {
mp_obj_t extra_args[];
} mp_obj_fun_bc_t;
-#endif // __MICROPY_INCLUDED_PY_OBJFUN_H__
+#endif // MICROPY_INCLUDED_PY_OBJFUN_H
diff --git a/py/objgenerator.c b/py/objgenerator.c
index 8cb0e60ccb..2f39f3a52b 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -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)
*
@@ -74,6 +74,7 @@ const mp_obj_type_t mp_type_gen_wrap = {
{ &mp_type_type },
.name = MP_QSTR_generator,
.call = gen_wrap_call,
+ .unary_op = mp_generic_unary_op,
};
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun) {
@@ -235,6 +236,7 @@ const mp_obj_type_t mp_type_gen_instance = {
{ &mp_type_type },
.name = MP_QSTR_generator,
.print = gen_instance_print,
+ .unary_op = mp_generic_unary_op,
.getiter = mp_identity_getiter,
.iternext = gen_instance_iternext,
.locals_dict = (mp_obj_dict_t*)&gen_instance_locals_dict,
diff --git a/py/objgenerator.h b/py/objgenerator.h
index d1b9be4780..80bf9cd860 100644
--- a/py/objgenerator.h
+++ b/py/objgenerator.h
@@ -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)
*
@@ -23,12 +23,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJGENERATOR_H__
-#define __MICROPY_INCLUDED_PY_OBJGENERATOR_H__
+#ifndef MICROPY_INCLUDED_PY_OBJGENERATOR_H
+#define MICROPY_INCLUDED_PY_OBJGENERATOR_H
#include "py/obj.h"
#include "py/runtime.h"
mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_val, mp_obj_t throw_val, mp_obj_t *ret_val);
-#endif // __MICROPY_INCLUDED_PY_OBJGENERATOR_H__
+#endif // MICROPY_INCLUDED_PY_OBJGENERATOR_H
diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c
index a3c754448f..afd6fb22b0 100644
--- a/py/objgetitemiter.c
+++ b/py/objgetitemiter.c
@@ -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)
*
diff --git a/py/objint.c b/py/objint.c
index bda9c46cf0..29d889629f 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -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)
*
@@ -106,7 +106,7 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
#define MP_FLOAT_SIGN_SHIFT_I32 ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32)
#define MP_FLOAT_EXP_SHIFT_I32 (MP_FLOAT_FRAC_BITS % 32)
- if (e & (1 << MP_FLOAT_SIGN_SHIFT_I32)) {
+ if (e & (1U << MP_FLOAT_SIGN_SHIFT_I32)) {
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
e |= u.i[MP_ENDIANNESS_BIG] != 0;
#endif
@@ -432,15 +432,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_fro
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj));
STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
- // TODO: Support byteorder param
// TODO: Support signed param (assumes signed=False)
(void)n_args;
- if (args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
- mp_not_implemented("");
+ mp_int_t len = mp_obj_get_int(args[1]);
+ if (len < 0) {
+ mp_raise_ValueError(NULL);
}
-
- mp_uint_t len = MP_OBJ_SMALL_INT_VALUE(args[1]);
+ bool big_endian = args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little);
vstr_t vstr;
vstr_init_len(&vstr, len);
@@ -449,12 +448,13 @@ STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
if (!MP_OBJ_IS_SMALL_INT(args[0])) {
- mp_obj_int_to_bytes_impl(args[0], false, len, data);
+ mp_obj_int_to_bytes_impl(args[0], big_endian, len, data);
} else
#endif
{
mp_int_t val = MP_OBJ_SMALL_INT_VALUE(args[0]);
- mp_binary_set_int(MIN((size_t)len, sizeof(val)), false, data, val);
+ size_t l = MIN((size_t)len, sizeof(val));
+ mp_binary_set_int(l, big_endian, data + (big_endian ? (len - l) : 0), val);
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
diff --git a/py/objint.h b/py/objint.h
index da56c18624..394c23714b 100644
--- a/py/objint.h
+++ b/py/objint.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJINT_H__
-#define __MICROPY_INCLUDED_PY_OBJINT_H__
+#ifndef MICROPY_INCLUDED_PY_OBJINT_H
+#define MICROPY_INCLUDED_PY_OBJINT_H
#include "py/mpz.h"
#include "py/obj.h"
@@ -63,4 +63,4 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus);
-#endif // __MICROPY_INCLUDED_PY_OBJINT_H__
+#endif // MICROPY_INCLUDED_PY_OBJINT_H
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index f638a53202..02c005d2fd 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -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)
*
@@ -191,6 +191,13 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_POWER:
case MP_BINARY_OP_INPLACE_POWER: {
+ if (rhs_val < 0) {
+ #if MICROPY_PY_BUILTINS_FLOAT
+ return mp_obj_float_binary_op(op, lhs_val, rhs_in);
+ #else
+ mp_raise_ValueError("negative power with no float support");
+ #endif
+ }
long long ans = 1;
while (rhs_val > 0) {
if (rhs_val & 1) {
@@ -247,7 +254,7 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) {
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
// TODO raise an exception if the unsigned long long won't fit
if (val >> (sizeof(unsigned long long) * 8 - 1) != 0) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "ulonglong too large"));
+ mp_raise_msg(&mp_type_OverflowError, "ulonglong too large");
}
mp_obj_int_t *o = m_new_obj(mp_obj_int_t);
o->base.type = &mp_type_int;
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index d818b6f407..0791a8af2c 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -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)
*
@@ -290,6 +290,13 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_POWER:
case MP_BINARY_OP_INPLACE_POWER:
+ if (mpz_is_neg(zrhs)) {
+ #if MICROPY_PY_BUILTINS_FLOAT
+ return mp_obj_float_binary_op(op, mpz_as_float(zlhs), rhs_in);
+ #else
+ mp_raise_ValueError("negative power with no float support");
+ #endif
+ }
mpz_pow_inpl(&res->mpz, zlhs, zrhs);
break;
diff --git a/py/objlist.c b/py/objlist.c
index 45e69c8bcf..86d4300620 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -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)
*
@@ -104,6 +104,12 @@ STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) {
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
+ #if MICROPY_PY_SYS_GETSIZEOF
+ case MP_UNARY_OP_SIZEOF: {
+ size_t sz = sizeof(*self) + sizeof(mp_obj_t) * self->alloc;
+ return MP_OBJ_NEW_SMALL_INT(sz);
+ }
+ #endif
default: return MP_OBJ_NULL; // op not supported
}
}
@@ -156,7 +162,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
- mp_not_implemented("");
+ mp_raise_NotImplementedError("");
}
mp_int_t len_adj = slice.start - slice.stop;
@@ -196,7 +202,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_get_array(value, &value_len, &value_items);
mp_bound_slice_t slice_out;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
- mp_not_implemented("");
+ mp_raise_NotImplementedError("");
}
mp_int_t len_adj = value_len - (slice_out.stop - slice_out.start);
//printf("Len adj: %d\n", len_adj);
diff --git a/py/objlist.h b/py/objlist.h
index 5b2d216fc2..28b5495a92 100644
--- a/py/objlist.h
+++ b/py/objlist.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJLIST_H__
-#define __MICROPY_INCLUDED_PY_OBJLIST_H__
+#ifndef MICROPY_INCLUDED_PY_OBJLIST_H
+#define MICROPY_INCLUDED_PY_OBJLIST_H
#include "py/obj.h"
@@ -35,4 +35,4 @@ typedef struct _mp_obj_list_t {
mp_obj_t *items;
} mp_obj_list_t;
-#endif // __MICROPY_INCLUDED_PY_OBJLIST_H__
+#endif // MICROPY_INCLUDED_PY_OBJLIST_H
diff --git a/py/objmap.c b/py/objmap.c
index 111c964fdd..908c61507e 100644
--- a/py/objmap.c
+++ b/py/objmap.c
@@ -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)
*
diff --git a/py/objmodule.c b/py/objmodule.c
index 43bb36b98c..fc8507c27b 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -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)
*
diff --git a/py/objmodule.h b/py/objmodule.h
index 4e6612adc7..b5c07dc333 100644
--- a/py/objmodule.h
+++ b/py/objmodule.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJMODULE_H__
-#define __MICROPY_INCLUDED_PY_OBJMODULE_H__
+#ifndef MICROPY_INCLUDED_PY_OBJMODULE_H
+#define MICROPY_INCLUDED_PY_OBJMODULE_H
#include "py/obj.h"
@@ -34,4 +34,4 @@ extern const mp_map_t mp_builtin_module_weak_links_map;
mp_obj_t mp_module_get(qstr module_name);
void mp_module_register(qstr qstr, mp_obj_t module);
-#endif // __MICROPY_INCLUDED_PY_OBJMODULE_H__
+#endif // MICROPY_INCLUDED_PY_OBJMODULE_H
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index cbd845dce8..fb9d9f02cf 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -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)
*
@@ -94,43 +94,37 @@ STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args,
}
}
- mp_obj_t *arg_objects;
- if (n_args == num_fields) {
- arg_objects = (mp_obj_t*)args;
- } else {
- size_t alloc_size = sizeof(mp_obj_t) * num_fields;
- arg_objects = alloca(alloc_size);
- memset(arg_objects, 0, alloc_size);
+ // Create a tuple and set the type to this namedtuple
+ mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_fields, NULL));
+ tuple->base.type = type_in;
- for (size_t i = 0; i < n_args; i++) {
- arg_objects[i] = args[i];
- }
+ // Copy the positional args into the first slots of the namedtuple
+ memcpy(&tuple->items[0], args, sizeof(mp_obj_t) * n_args);
- for (size_t i = n_args; i < n_args + 2 * n_kw; i += 2) {
- qstr kw = mp_obj_str_get_qstr(args[i]);
- size_t id = namedtuple_find_field(type, kw);
- if (id == (size_t)-1) {
- if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- mp_arg_error_terse_mismatch();
- } else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "unexpected keyword argument '%q'", kw));
- }
+ // Fill in the remaining slots with the keyword args
+ memset(&tuple->items[n_args], 0, sizeof(mp_obj_t) * n_kw);
+ for (size_t i = n_args; i < n_args + 2 * n_kw; i += 2) {
+ qstr kw = mp_obj_str_get_qstr(args[i]);
+ size_t id = namedtuple_find_field(type, kw);
+ if (id == (size_t)-1) {
+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
+ mp_arg_error_terse_mismatch();
+ } else {
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
+ "unexpected keyword argument '%q'", kw));
}
- if (arg_objects[id] != MP_OBJ_NULL) {
- if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- mp_arg_error_terse_mismatch();
- } else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "function got multiple values for argument '%q'", kw));
- }
+ }
+ if (tuple->items[id] != MP_OBJ_NULL) {
+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
+ mp_arg_error_terse_mismatch();
+ } else {
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
+ "function got multiple values for argument '%q'", kw));
}
- arg_objects[id] = args[i + 1];
}
+ tuple->items[id] = args[i + 1];
}
- mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_fields, arg_objects));
- tuple->base.type = type_in;
return MP_OBJ_FROM_PTR(tuple);
}
diff --git a/py/objnone.c b/py/objnone.c
index 5d5b83540d..cd7319bec8 100644
--- a/py/objnone.c
+++ b/py/objnone.c
@@ -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)
*
diff --git a/py/objobject.c b/py/objobject.c
index f9a7d17c34..49d2ec62ee 100644
--- a/py/objobject.c
+++ b/py/objobject.c
@@ -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)
*
diff --git a/py/objproperty.c b/py/objproperty.c
index 8189935d20..0934fad058 100644
--- a/py/objproperty.c
+++ b/py/objproperty.c
@@ -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)
*
diff --git a/py/objrange.c b/py/objrange.c
index 8c4e14f49c..33b07a9d44 100644
--- a/py/objrange.c
+++ b/py/objrange.c
@@ -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)
*
diff --git a/py/objreversed.c b/py/objreversed.c
index fc85e72bfb..a596a2fde3 100644
--- a/py/objreversed.c
+++ b/py/objreversed.c
@@ -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)
*
diff --git a/py/objset.c b/py/objset.c
index f74bc74a07..376439b73e 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -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)
*
diff --git a/py/objsingleton.c b/py/objsingleton.c
index 394c127677..ea72ae38cc 100644
--- a/py/objsingleton.c
+++ b/py/objsingleton.c
@@ -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)
*
diff --git a/py/objslice.c b/py/objslice.c
index 928be6dab1..358c44d061 100644
--- a/py/objslice.c
+++ b/py/objslice.c
@@ -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)
*
diff --git a/py/objstr.c b/py/objstr.c
index e758dd0062..d4c038a686 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -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)
*
@@ -347,8 +347,9 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
rhs_data = bufinfo.buf;
rhs_len = bufinfo.len;
} else {
- // incompatible types
- return MP_OBJ_NULL; // op not supported
+ // LHS is str and RHS has an incompatible type
+ // (except if operation is EQUAL, but that's handled by mp_obj_equal)
+ bad_implicit_conversion(rhs_in);
}
switch (op) {
@@ -403,7 +404,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(self_len, index, &slice)) {
- mp_not_implemented("only slices with step=1 (aka None) are supported");
+ mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
}
return mp_obj_new_str_of_type(type, self_data + slice.start, slice.stop - slice.start);
}
@@ -469,6 +470,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
// return joined string
return mp_obj_new_str_from_vstr(self_type, &vstr);
}
+MP_DEFINE_CONST_FUN_OBJ_2(str_join_obj, str_join);
mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
@@ -544,6 +546,7 @@ mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) {
return res;
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_split_obj, 1, 3, mp_obj_str_split);
#if MICROPY_PY_BUILTINS_STR_SPLITLINES
STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -589,6 +592,7 @@ STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t
return res;
}
+MP_DEFINE_CONST_FUN_OBJ_KW(str_splitlines_obj, 1, str_splitlines);
#endif
STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
@@ -614,7 +618,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
mp_int_t idx = splits;
if (sep == mp_const_none) {
- mp_not_implemented("rsplit(None,n)");
+ mp_raise_NotImplementedError("rsplit(None,n)");
} else {
size_t sep_len;
const char *sep_str = mp_obj_str_get_data(sep, &sep_len);
@@ -656,6 +660,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_FROM_PTR(res);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rsplit_obj, 1, 3, str_rsplit);
STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
@@ -700,18 +705,22 @@ STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, b
STATIC mp_obj_t str_find(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, 1, false);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_find_obj, 2, 4, str_find);
STATIC mp_obj_t str_rfind(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, -1, false);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rfind_obj, 2, 4, str_rfind);
STATIC mp_obj_t str_index(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, 1, true);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_index_obj, 2, 4, str_index);
STATIC mp_obj_t str_rindex(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, -1, true);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rindex_obj, 2, 4, str_rindex);
// TODO: (Much) more variety in args
STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) {
@@ -727,12 +736,13 @@ STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) {
}
return mp_obj_new_bool(memcmp(start, prefix, prefix_len) == 0);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_startswith_obj, 2, 3, str_startswith);
STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) {
GET_STR_DATA_LEN(args[0], str, str_len);
GET_STR_DATA_LEN(args[1], suffix, suffix_len);
if (n_args > 2) {
- mp_not_implemented("start/end indices");
+ mp_raise_NotImplementedError("start/end indices");
}
if (suffix_len > str_len) {
@@ -740,6 +750,7 @@ STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) {
}
return mp_obj_new_bool(memcmp(str + (str_len - suffix_len), suffix, suffix_len) == 0);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_endswith_obj, 2, 3, str_endswith);
enum { LSTRIP, RSTRIP, STRIP };
@@ -817,14 +828,17 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_strip(size_t n_args, const mp_obj_t *args) {
return str_uni_strip(STRIP, n_args, args);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_strip_obj, 1, 2, str_strip);
STATIC mp_obj_t str_lstrip(size_t n_args, const mp_obj_t *args) {
return str_uni_strip(LSTRIP, n_args, args);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_lstrip_obj, 1, 2, str_lstrip);
STATIC mp_obj_t str_rstrip(size_t n_args, const mp_obj_t *args) {
return str_uni_strip(RSTRIP, n_args, args);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rstrip_obj, 1, 2, str_rstrip);
#if MICROPY_PY_BUILTINS_STR_CENTER
STATIC mp_obj_t str_center(mp_obj_t str_in, mp_obj_t width_in) {
@@ -841,6 +855,7 @@ STATIC mp_obj_t str_center(mp_obj_t str_in, mp_obj_t width_in) {
memcpy(vstr.buf + left, str, str_len);
return mp_obj_new_str_from_vstr(mp_obj_get_type(str_in), &vstr);
}
+MP_DEFINE_CONST_FUN_OBJ_2(str_center_obj, str_center);
#endif
// Takes an int arg, but only parses unsigned numbers, and only changes
@@ -1029,7 +1044,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
arg = key_elem->value;
}
if (field_name < field_name_top) {
- mp_not_implemented("attributes not supported yet");
+ mp_raise_NotImplementedError("attributes not supported yet");
}
} else {
if (*arg_i < 0) {
@@ -1064,7 +1079,6 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
arg = mp_obj_new_str_from_vstr(&mp_type_str, &arg_vstr);
}
- char sign = '\0';
char fill = '\0';
char align = '\0';
int width = -1;
@@ -1100,7 +1114,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
} else if (*s == ' ') {
flags |= PF_FLAG_SPACE_SIGN;
}
- sign = *s++;
+ s++;
}
if (*s == '#') {
flags |= PF_FLAG_SHOW_PREFIX;
@@ -1146,7 +1160,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
fill = ' ';
}
- if (sign) {
+ if (flags & (PF_FLAG_SHOW_SIGN | PF_FLAG_SPACE_SIGN)) {
if (type == 's') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
@@ -1162,8 +1176,6 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
"sign not allowed with integer format specifier 'c'");
}
}
- } else {
- sign = '-';
}
switch (align) {
@@ -1346,6 +1358,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
vstr_t vstr = mp_obj_str_format_helper((const char*)str, (const char*)str + len, &arg_i, n_args, args, kwargs);
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
+MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format);
STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) {
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(pattern));
@@ -1649,6 +1662,7 @@ STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_str_from_vstr(self_type, &vstr);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace);
STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
@@ -1689,6 +1703,7 @@ STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(num_occurrences);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj, 2, 4, str_count);
#if MICROPY_PY_BUILTINS_STR_PARTITION
STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) {
@@ -1736,10 +1751,12 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) {
STATIC mp_obj_t str_partition(mp_obj_t self_in, mp_obj_t arg) {
return str_partitioner(self_in, arg, 1);
}
+MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition);
STATIC mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) {
return str_partitioner(self_in, arg, -1);
}
+MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition);
#endif
// Supposedly not too critical operations, so optimize for code size
@@ -1757,10 +1774,12 @@ STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) {
STATIC mp_obj_t str_lower(mp_obj_t self_in) {
return str_caseconv(unichar_tolower, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_lower_obj, str_lower);
STATIC mp_obj_t str_upper(mp_obj_t self_in) {
return str_caseconv(unichar_toupper, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_upper_obj, str_upper);
STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) {
GET_STR_DATA_LEN(self_in, self_data, self_len);
@@ -1798,22 +1817,27 @@ STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) {
STATIC mp_obj_t str_isspace(mp_obj_t self_in) {
return str_uni_istype(unichar_isspace, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_isspace_obj, str_isspace);
STATIC mp_obj_t str_isalpha(mp_obj_t self_in) {
return str_uni_istype(unichar_isalpha, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_isalpha_obj, str_isalpha);
STATIC mp_obj_t str_isdigit(mp_obj_t self_in) {
return str_uni_istype(unichar_isdigit, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_isdigit_obj, str_isdigit);
STATIC mp_obj_t str_isupper(mp_obj_t self_in) {
return str_uni_istype(unichar_isupper, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_isupper_obj, str_isupper);
STATIC mp_obj_t str_islower(mp_obj_t self_in) {
return str_uni_istype(unichar_islower, self_in);
}
+MP_DEFINE_CONST_FUN_OBJ_1(str_islower_obj, str_islower);
#if MICROPY_CPYTHON_COMPAT
// These methods are superfluous in the presence of str() and bytes()
@@ -1829,6 +1853,7 @@ STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) {
}
return mp_obj_str_make_new(&mp_type_str, n_args, 0, args);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_decode_obj, 1, 3, bytes_decode);
// TODO: should accept kwargs too
STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) {
@@ -1841,6 +1866,7 @@ STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) {
}
return bytes_make_new(NULL, n_args, 0, args);
}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_encode_obj, 1, 3, str_encode);
#endif
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
@@ -1859,43 +1885,6 @@ mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_u
}
}
-#if MICROPY_CPYTHON_COMPAT
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_decode_obj, 1, 3, bytes_decode);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_encode_obj, 1, 3, str_encode);
-#endif
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_find_obj, 2, 4, str_find);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rfind_obj, 2, 4, str_rfind);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_index_obj, 2, 4, str_index);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rindex_obj, 2, 4, str_rindex);
-MP_DEFINE_CONST_FUN_OBJ_2(str_join_obj, str_join);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_split_obj, 1, 3, mp_obj_str_split);
-#if MICROPY_PY_BUILTINS_STR_SPLITLINES
-MP_DEFINE_CONST_FUN_OBJ_KW(str_splitlines_obj, 1, str_splitlines);
-#endif
-#if MICROPY_PY_BUILTINS_STR_CENTER
-MP_DEFINE_CONST_FUN_OBJ_2(str_center_obj, str_center);
-#endif
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rsplit_obj, 1, 3, str_rsplit);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_startswith_obj, 2, 3, str_startswith);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_endswith_obj, 2, 3, str_endswith);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_strip_obj, 1, 2, str_strip);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_lstrip_obj, 1, 2, str_lstrip);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rstrip_obj, 1, 2, str_rstrip);
-MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace);
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj, 2, 4, str_count);
-#if MICROPY_PY_BUILTINS_STR_PARTITION
-MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition);
-MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition);
-#endif
-MP_DEFINE_CONST_FUN_OBJ_1(str_lower_obj, str_lower);
-MP_DEFINE_CONST_FUN_OBJ_1(str_upper_obj, str_upper);
-MP_DEFINE_CONST_FUN_OBJ_1(str_isspace_obj, str_isspace);
-MP_DEFINE_CONST_FUN_OBJ_1(str_isalpha_obj, str_isalpha);
-MP_DEFINE_CONST_FUN_OBJ_1(str_isdigit_obj, str_isdigit);
-MP_DEFINE_CONST_FUN_OBJ_1(str_isupper_obj, str_isupper);
-MP_DEFINE_CONST_FUN_OBJ_1(str_islower_obj, str_islower);
-
STATIC const mp_rom_map_elem_t str8_locals_dict_table[] = {
#if MICROPY_CPYTHON_COMPAT
{ MP_ROM_QSTR(MP_QSTR_decode), MP_ROM_PTR(&bytes_decode_obj) },
diff --git a/py/objstr.h b/py/objstr.h
index e92832d106..3aef8c68e2 100644
--- a/py/objstr.h
+++ b/py/objstr.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJSTR_H__
-#define __MICROPY_INCLUDED_PY_OBJSTR_H__
+#ifndef MICROPY_INCLUDED_PY_OBJSTR_H
+#define MICROPY_INCLUDED_PY_OBJSTR_H
#include "py/obj.h"
@@ -102,4 +102,4 @@ MP_DECLARE_CONST_FUN_OBJ_1(str_isdigit_obj);
MP_DECLARE_CONST_FUN_OBJ_1(str_isupper_obj);
MP_DECLARE_CONST_FUN_OBJ_1(str_islower_obj);
-#endif // __MICROPY_INCLUDED_PY_OBJSTR_H__
+#endif // MICROPY_INCLUDED_PY_OBJSTR_H
diff --git a/py/objstringio.c b/py/objstringio.c
index 645c441cb2..61da0203e1 100644
--- a/py/objstringio.c
+++ b/py/objstringio.c
@@ -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)
*
@@ -118,15 +118,28 @@ STATIC mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
mp_uint_t ref = 0;
switch (s->whence) {
- case 1: // SEEK_CUR
+ case MP_SEEK_CUR:
ref = o->pos;
break;
- case 2: // SEEK_END
+ case MP_SEEK_END:
ref = o->vstr->len;
break;
}
- o->pos = ref + s->offset;
- s->offset = o->pos;
+ mp_uint_t new_pos = ref + s->offset;
+
+ // For MP_SEEK_SET, offset is unsigned
+ if (s->whence != MP_SEEK_SET && s->offset < 0) {
+ if (new_pos > ref) {
+ // Negative offset from SEEK_CUR or SEEK_END went past 0.
+ // CPython sets position to 0, POSIX returns an EINVAL error
+ new_pos = 0;
+ }
+ } else if (new_pos < ref) {
+ // positive offset went beyond the limit of mp_uint_t
+ *errcode = MP_EINVAL; // replace with MP_EOVERFLOW when defined
+ return MP_STREAM_ERROR;
+ }
+ s->offset = o->pos = new_pos;
return 0;
}
case MP_STREAM_FLUSH:
diff --git a/py/objstrunicode.c b/py/objstrunicode.c
index 9a6ce9b9a2..036f7f3c14 100644
--- a/py/objstrunicode.c
+++ b/py/objstrunicode.c
@@ -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)
*
@@ -142,7 +142,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (is_slice) {
return self_data;
}
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "string index out of range"));
+ mp_raise_msg(&mp_type_IndexError, "string index out of range");
}
if (!UTF8_IS_CONT(*s)) {
++i;
@@ -161,7 +161,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (is_slice) {
return top;
}
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "string index out of range"));
+ mp_raise_msg(&mp_type_IndexError, "string index out of range");
}
// Then check completion
if (i-- == 0) {
@@ -188,7 +188,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_t ostart, ostop, ostep;
mp_obj_slice_get(index, &ostart, &ostop, &ostep);
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
- mp_not_implemented("only slices with step=1 (aka None) are supported");
+ mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
}
const byte *pstart, *pstop;
diff --git a/py/objtuple.c b/py/objtuple.c
index eaf0e37f47..765edb907c 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -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)
*
@@ -148,7 +148,8 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
mp_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t);
return MP_OBJ_FROM_PTR(s);
}
- case MP_BINARY_OP_MULTIPLY: {
+ case MP_BINARY_OP_MULTIPLY:
+ case MP_BINARY_OP_INPLACE_MULTIPLY: {
mp_int_t n;
if (!mp_obj_get_int_maybe(rhs, &n)) {
return MP_OBJ_NULL; // op not supported
@@ -180,7 +181,7 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
- mp_not_implemented("only slices with step=1 (aka None) are supported");
+ mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
}
mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(slice.stop - slice.start, NULL));
mp_seq_copy(res->items, self->items + slice.start, res->len, mp_obj_t);
diff --git a/py/objtuple.h b/py/objtuple.h
index 555c3b3c2c..05c6490fe6 100644
--- a/py/objtuple.h
+++ b/py/objtuple.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJTUPLE_H__
-#define __MICROPY_INCLUDED_PY_OBJTUPLE_H__
+#ifndef MICROPY_INCLUDED_PY_OBJTUPLE_H
+#define MICROPY_INCLUDED_PY_OBJTUPLE_H
#include "py/obj.h"
@@ -61,4 +61,4 @@ void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields,
mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *items);
-#endif // __MICROPY_INCLUDED_PY_OBJTUPLE_H__
+#endif // MICROPY_INCLUDED_PY_OBJTUPLE_H
diff --git a/py/objtype.c b/py/objtype.c
index 2a119e40fb..e1a24da7e7 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -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)
*
@@ -35,7 +35,7 @@
#include "py/runtime0.h"
#include "py/runtime.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -339,11 +339,27 @@ const qstr mp_unary_op_method_name[] = {
[MP_UNARY_OP_NEGATIVE] = MP_QSTR___neg__,
[MP_UNARY_OP_INVERT] = MP_QSTR___invert__,
#endif
+ #if MICROPY_PY_SYS_GETSIZEOF
+ [MP_UNARY_OP_SIZEOF] = MP_QSTR_getsizeof,
+ #endif
[MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
};
STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
+
+ #if MICROPY_PY_SYS_GETSIZEOF
+ if (MP_UNLIKELY(op == MP_UNARY_OP_SIZEOF)) {
+ // TODO: This doesn't count inherited objects (self->subobj)
+ const mp_obj_type_t *native_base;
+ size_t num_native_bases = instance_count_native_bases(mp_obj_get_type(self_in), &native_base);
+
+ size_t sz = sizeof(*self) + sizeof(*self->subobj) * num_native_bases
+ + sizeof(*self->members.table) * self->members.alloc;
+ return MP_OBJ_NEW_SMALL_INT(sz);
+ }
+ #endif
+
qstr op_name = mp_unary_op_method_name[op];
/* Still try to lookup native slot
if (op_name == 0) {
@@ -375,7 +391,7 @@ STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) {
if (member[0] == MP_OBJ_NULL) {
// https://docs.python.org/3/reference/datamodel.html#object.__hash__
// "User-defined classes have __eq__() and __hash__() methods by default;
- // with them, all objects compare unequal (except with themselves) and
+ // with them, all objects compare unequal (except with themselves) and
// x.__hash__() returns an appropriate value such that x == y implies
// both that x is y and hash(x) == hash(y)."
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)self_in);
@@ -917,8 +933,8 @@ const mp_obj_type_t mp_type_type = {
};
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) {
- assert(MP_OBJ_IS_TYPE(bases_tuple, &mp_type_tuple)); // Micro Python restriction, for now
- assert(MP_OBJ_IS_TYPE(locals_dict, &mp_type_dict)); // Micro Python restriction, for now
+ assert(MP_OBJ_IS_TYPE(bases_tuple, &mp_type_tuple)); // MicroPython restriction, for now
+ assert(MP_OBJ_IS_TYPE(locals_dict, &mp_type_dict)); // MicroPython restriction, for now
// TODO might need to make a copy of locals_dict; at least that's how CPython does it
diff --git a/py/objtype.h b/py/objtype.h
index 61efd00c05..52419f3cdc 100644
--- a/py/objtype.h
+++ b/py/objtype.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_OBJTYPE_H__
-#define __MICROPY_INCLUDED_PY_OBJTYPE_H__
+#ifndef MICROPY_INCLUDED_PY_OBJTYPE_H
+#define MICROPY_INCLUDED_PY_OBJTYPE_H
#include "py/obj.h"
@@ -49,4 +49,4 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
// this needs to be exposed for the above macros to work correctly
mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
-#endif // __MICROPY_INCLUDED_PY_OBJTYPE_H__
+#endif // MICROPY_INCLUDED_PY_OBJTYPE_H
diff --git a/py/objzip.c b/py/objzip.c
index 6f72d15954..0183925e3c 100644
--- a/py/objzip.c
+++ b/py/objzip.c
@@ -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)
*
diff --git a/py/opmethods.c b/py/opmethods.c
index 80a953fb89..1200ba39ef 100644
--- a/py/opmethods.c
+++ b/py/opmethods.c
@@ -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)
*
diff --git a/py/parse.c b/py/parse.c
index 2f16748a6c..e399aac535 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -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)
*
diff --git a/py/parse.h b/py/parse.h
index c56145b1b0..2087a2d1a2 100644
--- a/py/parse.h
+++ b/py/parse.h
@@ -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)
*
@@ -24,8 +24,8 @@
* THE SOFTWARE.
*/
#include "py/parse2.h"
-#ifndef __MICROPY_INCLUDED_PY_PARSE_H__
-#define __MICROPY_INCLUDED_PY_PARSE_H__
+#ifndef MICROPY_INCLUDED_PY_PARSE_H
+#define MICROPY_INCLUDED_PY_PARSE_H
#include <stddef.h>
#include <stdint.h>
@@ -105,4 +105,4 @@ typedef struct _mp_parse_t {
mp_parse_tree_t mp_parse(struct _mp_lexer_t *lex, mp_parse_input_kind_t input_kind);
void mp_parse_tree_clear(mp_parse_tree_t *tree);
-#endif // __MICROPY_INCLUDED_PY_PARSE_H__
+#endif // MICROPY_INCLUDED_PY_PARSE_H
diff --git a/py/parsenum.c b/py/parsenum.c
index 1771188434..b62029f7c7 100644
--- a/py/parsenum.c
+++ b/py/parsenum.c
@@ -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)
*
diff --git a/py/parsenum.h b/py/parsenum.h
index f140cfc85e..a5bed731d2 100644
--- a/py/parsenum.h
+++ b/py/parsenum.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_PARSENUM_H__
-#define __MICROPY_INCLUDED_PY_PARSENUM_H__
+#ifndef MICROPY_INCLUDED_PY_PARSENUM_H
+#define MICROPY_INCLUDED_PY_PARSENUM_H
#include "py/mpconfig.h"
#include "py/lexer.h"
@@ -34,4 +34,4 @@
mp_obj_t mp_parse_num_integer(const char *restrict str, size_t len, int base, mp_lexer_t *lex);
mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex);
-#endif // __MICROPY_INCLUDED_PY_PARSENUM_H__
+#endif // MICROPY_INCLUDED_PY_PARSENUM_H
diff --git a/py/parsenumbase.c b/py/parsenumbase.c
index 73a3372f0a..ba10591226 100644
--- a/py/parsenumbase.c
+++ b/py/parsenumbase.c
@@ -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)
*
diff --git a/py/parsenumbase.h b/py/parsenumbase.h
index 9da9db8412..3a525f993c 100644
--- a/py/parsenumbase.h
+++ b/py/parsenumbase.h
@@ -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)
*
@@ -23,11 +23,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
-#define __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
+#ifndef MICROPY_INCLUDED_PY_PARSENUMBASE_H
+#define MICROPY_INCLUDED_PY_PARSENUMBASE_H
#include "py/mpconfig.h"
size_t mp_parse_num_base(const char *str, size_t len, int *base);
-#endif // __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
+#endif // MICROPY_INCLUDED_PY_PARSENUMBASE_H
diff --git a/py/py.mk b/py/py.mk
index 96fc92cac3..55ce98f127 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -22,13 +22,13 @@ CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\"
ifeq ($(MICROPY_PY_USSL),1)
CFLAGS_MOD += -DMICROPY_PY_USSL=1
ifeq ($(MICROPY_SSL_AXTLS),1)
-CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config
+CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/lib/axtls/config
LDFLAGS_MOD += -Lbuild -laxtls
else ifeq ($(MICROPY_SSL_MBEDTLS),1)
# Can be overridden by ports which have "builtin" mbedTLS
-MICROPY_SSL_MBEDTLS_INCLUDE ?= ../lib/mbedtls/include
+MICROPY_SSL_MBEDTLS_INCLUDE ?= $(TOP)/lib/mbedtls/include
CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(MICROPY_SSL_MBEDTLS_INCLUDE)
-LDFLAGS_MOD += -L../lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto
+LDFLAGS_MOD += -L$(TOP)/lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto
endif
endif
@@ -38,7 +38,7 @@ endif
ifeq ($(MICROPY_PY_LWIP),1)
LWIP_DIR = lib/lwip/src
-INC += -I../lib/lwip/src/include -I../lib/lwip/src/include/ipv4 -I../extmod/lwip-include
+INC += -I$(TOP)/lib/lwip/src/include -I$(TOP)/lib/lwip/src/include/ipv4 -I$(TOP)/extmod/lwip-include
CFLAGS_MOD += -DMICROPY_PY_LWIP=1
SRC_MOD += extmod/modlwip.c lib/netutils/netutils.c
SRC_MOD += $(addprefix $(LWIP_DIR)/,\
@@ -74,8 +74,8 @@ endif
ifeq ($(MICROPY_PY_BTREE),1)
BTREE_DIR = lib/berkeley-db-1.xx
-CFLAGS_MOD += -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ -Dvirt_fd_t=mp_obj_t "-DVIRT_FD_T_HEADER=<py/obj.h>"
-INC += -I../$(BTREE_DIR)/PORT/include
+BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ -Dvirt_fd_t=mp_obj_t "-DVIRT_FD_T_HEADER=<py/obj.h>"
+INC += -I$(TOP)/$(BTREE_DIR)/PORT/include
SRC_MOD += extmod/modbtree.c
SRC_MOD += $(addprefix $(BTREE_DIR)/,\
btree/bt_close.c \
@@ -95,7 +95,9 @@ mpool/mpool.c \
)
CFLAGS_MOD += -DMICROPY_PY_BTREE=1
# we need to suppress certain warnings to get berkeley-db to compile cleanly
-$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter
+# and we have separate BTREE_DEFS so the definitions don't interfere with other source code
+$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS)
+$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
endif
# py object files
diff --git a/py/qstr.c b/py/qstr.c
index 5aa1610648..95c9b6835e 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -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)
*
@@ -36,7 +36,7 @@
// ultimately we will replace this with a static hash table of some kind
// also probably need to include the length in the string data, to allow null bytes in the string
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(...) (void)0
diff --git a/py/qstr.h b/py/qstr.h
index 8c63fbbc8d..e2bdcc351e 100644
--- a/py/qstr.h
+++ b/py/qstr.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_QSTR_H__
-#define __MICROPY_INCLUDED_PY_QSTR_H__
+#ifndef MICROPY_INCLUDED_PY_QSTR_H
+#define MICROPY_INCLUDED_PY_QSTR_H
#include "py/mpconfig.h"
#include "py/misc.h"
@@ -76,4 +76,4 @@ const byte *qstr_data(qstr q, size_t *len);
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes);
void qstr_dump_data(void);
-#endif // __MICROPY_INCLUDED_PY_QSTR_H__
+#endif // MICROPY_INCLUDED_PY_QSTR_H
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 4581e5e1b1..9375b9101a 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -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)
*
diff --git a/py/reader.c b/py/reader.c
index 5df45c4957..c4d18d53dc 100644
--- a/py/reader.c
+++ b/py/reader.c
@@ -71,7 +71,6 @@ void mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include <errno.h>
typedef struct _mp_reader_posix_t {
bool close_fd;
diff --git a/py/repl.c b/py/repl.c
index 6d8f7cca46..7e8922e19a 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -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)
*
@@ -32,7 +32,7 @@
#if MICROPY_HELPER_REPL
STATIC bool str_startswith_word(const char *str, const char *head) {
- mp_uint_t i;
+ size_t i;
for (i = 0; str[i] && head[i]; i++) {
if (str[i] != head[i]) {
return false;
@@ -124,7 +124,7 @@ bool mp_repl_continue_with_input(const char *input) {
return false;
}
-mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str) {
+size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str) {
// scan backwards to find start of "a.b.c" chain
const char *org_str = str;
const char *top = str + len;
@@ -145,13 +145,13 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
while (str < top && *str != '.') {
++str;
}
- mp_uint_t s_len = str - s_start;
+ size_t s_len = str - s_start;
if (str < top) {
// a complete word, lookup in current dict
mp_obj_t obj = MP_OBJ_NULL;
- for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
+ for (size_t i = 0; i < dict->map.alloc; i++) {
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
size_t d_len;
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
@@ -194,8 +194,8 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
// look for matches
int n_found = 0;
const char *match_str = NULL;
- mp_uint_t match_len = 0;
- for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
+ size_t match_len = 0;
+ for (size_t i = 0; i < dict->map.alloc; i++) {
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
size_t d_len;
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
@@ -206,7 +206,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
} else {
// search for longest common prefix of match_str and d_str
// (assumes these strings are null-terminated)
- for (mp_uint_t j = s_len; j <= match_len && j <= d_len; ++j) {
+ for (size_t j = s_len; j <= match_len && j <= d_len; ++j) {
if (match_str[j] != d_str[j]) {
match_len = j;
break;
@@ -245,7 +245,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
#define MAX_LINE_LEN (4 * WORD_SLOT_LEN)
int line_len = MAX_LINE_LEN; // force a newline for first word
- for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
+ for (size_t i = 0; i < dict->map.alloc; i++) {
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
size_t d_len;
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
@@ -270,7 +270,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
}
mp_print_str(print, "\n");
- return (mp_uint_t)(-1); // indicate many matches
+ return (size_t)(-1); // indicate many matches
}
}
}
diff --git a/py/repl.h b/py/repl.h
index c34a5b8692..a7a4136cad 100644
--- a/py/repl.h
+++ b/py/repl.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_REPL_H__
-#define __MICROPY_INCLUDED_PY_REPL_H__
+#ifndef MICROPY_INCLUDED_PY_REPL_H
+#define MICROPY_INCLUDED_PY_REPL_H
#include "py/mpconfig.h"
#include "py/misc.h"
@@ -32,7 +32,7 @@
#if MICROPY_HELPER_REPL
bool mp_repl_continue_with_input(const char *input);
-mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str);
+size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str);
#endif
-#endif // __MICROPY_INCLUDED_PY_REPL_H__
+#endif // MICROPY_INCLUDED_PY_REPL_H
diff --git a/py/ringbuf.h b/py/ringbuf.h
index 5e108afad7..b416927060 100644
--- a/py/ringbuf.h
+++ b/py/ringbuf.h
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_RINGBUF_H__
-#define __MICROPY_INCLUDED_PY_RINGBUF_H__
+#ifndef MICROPY_INCLUDED_PY_RINGBUF_H
+#define MICROPY_INCLUDED_PY_RINGBUF_H
typedef struct _ringbuf_t {
uint8_t *buf;
@@ -69,4 +69,4 @@ static inline int ringbuf_put(ringbuf_t *r, uint8_t v) {
return 0;
}
-#endif // __MICROPY_INCLUDED_PY_RINGBUF_H__
+#endif // MICROPY_INCLUDED_PY_RINGBUF_H
diff --git a/py/runtime.c b/py/runtime.c
index bf2bfb8eae..eb1298813f 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -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)
*
@@ -44,7 +44,7 @@
#include "py/stackctrl.h"
#include "py/gc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#define DEBUG_OP_printf(...) DEBUG_printf(__VA_ARGS__)
@@ -127,7 +127,7 @@ void mp_deinit(void) {
//mp_obj_dict_free(&dict_main);
//mp_map_deinit(&MP_STATE_VM(mp_loaded_modules_map));
- // call port specific deinitialization if any
+ // call port specific deinitialization if any
#ifdef MICROPY_PORT_INIT_FUNC
MICROPY_PORT_DEINIT_FUNC;
#endif
@@ -1038,7 +1038,7 @@ void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
} else if (type->locals_dict != NULL) {
// generic method lookup
// this is a lookup in the object (ie not class or type)
- assert(type->locals_dict->base.type == &mp_type_dict); // Micro Python restriction, for now
+ assert(type->locals_dict->base.type == &mp_type_dict); // MicroPython restriction, for now
mp_map_t *locals_map = &type->locals_dict->map;
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
if (elem != NULL) {
@@ -1408,18 +1408,15 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i
#endif // MICROPY_ENABLE_COMPILER
-void *m_malloc_fail(size_t num_bytes) {
+NORETURN void *m_malloc_fail(size_t num_bytes) {
DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes);
- if (0) {
- // dummy
#if MICROPY_ENABLE_GC
- } else if (gc_is_locked()) {
+ if (gc_is_locked()) {
mp_raise_msg(&mp_type_MemoryError, "memory allocation failed, heap is locked");
- #endif
- } else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
- "memory allocation failed, allocating %u bytes", (uint)num_bytes));
}
+ #endif
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
+ "memory allocation failed, allocating %u bytes", (uint)num_bytes));
}
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg) {
@@ -1442,6 +1439,6 @@ NORETURN void mp_raise_OSError(int errno_) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_)));
}
-NORETURN void mp_not_implemented(const char *msg) {
+NORETURN void mp_raise_NotImplementedError(const char *msg) {
mp_raise_msg(&mp_type_NotImplementedError, msg);
}
diff --git a/py/runtime.h b/py/runtime.h
index d75d23ff18..428e2571cc 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_RUNTIME_H__
-#define __MICROPY_INCLUDED_PY_RUNTIME_H__
+#ifndef MICROPY_INCLUDED_PY_RUNTIME_H
+#define MICROPY_INCLUDED_PY_RUNTIME_H
#include "py/mpstate.h"
#include "py/obj.h"
@@ -149,8 +149,8 @@ NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg);
//NORETURN void nlr_raise_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...);
NORETURN void mp_raise_ValueError(const char *msg);
NORETURN void mp_raise_TypeError(const char *msg);
+NORETURN void mp_raise_NotImplementedError(const char *msg);
NORETURN void mp_raise_OSError(int errno_);
-NORETURN void mp_not_implemented(const char *msg); // Raise NotImplementedError with given message
NORETURN void mp_exc_recursion_depth(void);
#if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
@@ -178,4 +178,4 @@ void mp_warning(const char *msg, ...);
#define mp_warning(msg, ...)
#endif
-#endif // __MICROPY_INCLUDED_PY_RUNTIME_H__
+#endif // MICROPY_INCLUDED_PY_RUNTIME_H
diff --git a/py/runtime0.h b/py/runtime0.h
index 720fe6a23b..703c950f2d 100644
--- a/py/runtime0.h
+++ b/py/runtime0.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_RUNTIME0_H__
-#define __MICROPY_INCLUDED_PY_RUNTIME0_H__
+#ifndef MICROPY_INCLUDED_PY_RUNTIME0_H
+#define MICROPY_INCLUDED_PY_RUNTIME0_H
// These must fit in 8 bits; see scope.h
#define MP_SCOPE_FLAG_VARARGS (0x01)
@@ -50,6 +50,7 @@ typedef enum {
MP_UNARY_OP_NEGATIVE,
MP_UNARY_OP_INVERT,
MP_UNARY_OP_NOT,
+ MP_UNARY_OP_SIZEOF, // for sys.getsizeof()
} mp_unary_op_t;
typedef enum {
@@ -151,4 +152,4 @@ typedef enum {
extern void *const mp_fun_table[MP_F_NUMBER_OF];
-#endif // __MICROPY_INCLUDED_PY_RUNTIME0_H__
+#endif // MICROPY_INCLUDED_PY_RUNTIME0_H
diff --git a/py/runtime_utils.c b/py/runtime_utils.c
index e0495495aa..56a9180645 100644
--- a/py/runtime_utils.c
+++ b/py/runtime_utils.c
@@ -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)
*
diff --git a/py/scope.c b/py/scope.c
index 8143e655c9..19ab3727b7 100644
--- a/py/scope.c
+++ b/py/scope.c
@@ -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)
*
diff --git a/py/scope.h b/py/scope.h
index 012d906475..370de53356 100644
--- a/py/scope.h
+++ b/py/scope.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_SCOPE_H__
-#define __MICROPY_INCLUDED_PY_SCOPE_H__
+#ifndef MICROPY_INCLUDED_PY_SCOPE_H
+#define MICROPY_INCLUDED_PY_SCOPE_H
#include "py/parse.h"
#include "py/emitglue.h"
@@ -93,4 +93,4 @@ id_info_t *scope_find(scope_t *scope, qstr qstr);
id_info_t *scope_find_global(scope_t *scope, qstr qstr);
void scope_find_local_and_close_over(scope_t *scope, id_info_t *id, qstr qst);
-#endif // __MICROPY_INCLUDED_PY_SCOPE_H__
+#endif // MICROPY_INCLUDED_PY_SCOPE_H
diff --git a/py/sequence.c b/py/sequence.c
index 32db640dc1..0752ee1098 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -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)
*
diff --git a/py/showbc.c b/py/showbc.c
index 0bccf8427f..bb2b084ed7 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -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)
*
diff --git a/py/smallint.c b/py/smallint.c
index 4c42ee0cc9..aa542ca7bf 100644
--- a/py/smallint.c
+++ b/py/smallint.c
@@ -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)
*
diff --git a/py/smallint.h b/py/smallint.h
index b9686be30a..42679a78fb 100644
--- a/py/smallint.h
+++ b/py/smallint.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_SMALLINT_H__
-#define __MICROPY_INCLUDED_PY_SMALLINT_H__
+#ifndef MICROPY_INCLUDED_PY_SMALLINT_H
+#define MICROPY_INCLUDED_PY_SMALLINT_H
#include "py/mpconfig.h"
#include "py/misc.h"
@@ -65,4 +65,4 @@ bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y);
mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor);
mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom);
-#endif // __MICROPY_INCLUDED_PY_SMALLINT_H__
+#endif // MICROPY_INCLUDED_PY_SMALLINT_H
diff --git a/py/stackctrl.c b/py/stackctrl.c
index 1843e7339e..0bcd82f4f6 100644
--- a/py/stackctrl.c
+++ b/py/stackctrl.c
@@ -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)
*
diff --git a/py/stackctrl.h b/py/stackctrl.h
index e915f5000f..ff8da0ab13 100644
--- a/py/stackctrl.h
+++ b/py/stackctrl.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_STACKCTRL_H__
-#define __MICROPY_INCLUDED_PY_STACKCTRL_H__
+#ifndef MICROPY_INCLUDED_PY_STACKCTRL_H
+#define MICROPY_INCLUDED_PY_STACKCTRL_H
#include "py/mpconfig.h"
@@ -45,4 +45,4 @@ void mp_stack_check(void);
#endif
-#endif // __MICROPY_INCLUDED_PY_STACKCTRL_H__
+#endif // MICROPY_INCLUDED_PY_STACKCTRL_H
diff --git a/py/stream.c b/py/stream.c
index d3fc767bbd..0029a59a75 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -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)
*
@@ -142,7 +142,7 @@ STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte fl
while (more_bytes > 0) {
char *p = vstr_add_len(&vstr, more_bytes);
if (p == NULL) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError, "out of memory"));
+ mp_raise_msg(&mp_type_MemoryError, "out of memory");
}
int error;
mp_uint_t out_sz = mp_stream_read_exactly(args[0], p, more_bytes, &error);
@@ -381,7 +381,7 @@ STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args)
while (max_size == -1 || max_size-- != 0) {
char *p = vstr_add_len(&vstr, 1);
if (p == NULL) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError, "out of memory"));
+ mp_raise_msg(&mp_type_MemoryError, "out of memory");
}
int error;
@@ -448,11 +448,16 @@ STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) {
struct mp_stream_seek_t seek_s;
// TODO: Could be uint64
seek_s.offset = mp_obj_get_int(args[1]);
- seek_s.whence = 0;
+ seek_s.whence = SEEK_SET;
if (n_args == 3) {
seek_s.whence = mp_obj_get_int(args[2]);
}
+ // In POSIX, it's error to seek before end of stream, we enforce it here.
+ if (seek_s.whence == SEEK_SET && seek_s.offset < 0) {
+ mp_raise_OSError(MP_EINVAL);
+ }
+
int error;
mp_uint_t res = stream_p->ioctl(args[0], MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &error);
if (res == MP_STREAM_ERROR) {
diff --git a/py/stream.h b/py/stream.h
index 01199ab601..fbe3d7d859 100644
--- a/py/stream.h
+++ b/py/stream.h
@@ -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)
*
@@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_STREAM_H__
-#define __MICROPY_INCLUDED_PY_STREAM_H__
+#ifndef MICROPY_INCLUDED_PY_STREAM_H
+#define MICROPY_INCLUDED_PY_STREAM_H
#include "py/obj.h"
#include "py/mperrno.h"
@@ -50,10 +50,18 @@
// Argument structure for MP_STREAM_SEEK
struct mp_stream_seek_t {
+ // If whence == MP_SEEK_SET, offset should be treated as unsigned.
+ // This allows dealing with full-width stream sizes (16, 32, 64,
+ // etc. bits). For other seek types, should be treated as signed.
mp_off_t offset;
int whence;
};
+// seek ioctl "whence" values
+#define MP_SEEK_SET (0)
+#define MP_SEEK_CUR (1)
+#define MP_SEEK_END (2)
+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read1_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj);
@@ -103,4 +111,4 @@ int mp_stream_posix_fsync(mp_obj_t stream);
#define mp_is_nonblocking_error(errno) (0)
#endif
-#endif // __MICROPY_INCLUDED_PY_STREAM_H__
+#endif // MICROPY_INCLUDED_PY_STREAM_H
diff --git a/py/unicode.c b/py/unicode.c
index c6f872038d..eddb007d5e 100644
--- a/py/unicode.c
+++ b/py/unicode.c
@@ -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)
*
diff --git a/py/unicode.h b/py/unicode.h
index 89c28ed0ec..19487a65ae 100644
--- a/py/unicode.h
+++ b/py/unicode.h
@@ -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)
*
@@ -23,12 +23,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef __MICROPY_INCLUDED_PY_UNICODE_H__
-#define __MICROPY_INCLUDED_PY_UNICODE_H__
+#ifndef MICROPY_INCLUDED_PY_UNICODE_H
+#define MICROPY_INCLUDED_PY_UNICODE_H
#include "py/mpconfig.h"
#include "py/misc.h"
mp_uint_t utf8_ptr_to_index(const byte *s, const byte *ptr);
-#endif // __MICROPY_INCLUDED_PY_UNICODE_H__
+#endif // MICROPY_INCLUDED_PY_UNICODE_H
diff --git a/py/vm.c b/py/vm.c
index 404c799123..c7fc83d048 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -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)
*
@@ -162,9 +162,13 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp
run_code_state: ;
#endif
// Pointers which are constant for particular invocation of mp_execute_bytecode()
- size_t n_state = mp_decode_uint_value(code_state->fun_bc->bytecode);
- mp_obj_t * /*const*/ fastn = &code_state->state[n_state - 1];
- mp_exc_stack_t * /*const*/ exc_stack = (mp_exc_stack_t*)(code_state->state + n_state);
+ mp_obj_t * /*const*/ fastn;
+ mp_exc_stack_t * /*const*/ exc_stack;
+ {
+ size_t n_state = mp_decode_uint_value(code_state->fun_bc->bytecode);
+ fastn = &code_state->state[n_state - 1];
+ exc_stack = (mp_exc_stack_t*)(code_state->state + n_state);
+ }
// variables that are visible to the exception handler (declared volatile)
volatile bool currently_in_except_block = MP_TAGPTR_TAG0(code_state->exc_sp); // 0 or 1, to detect nested exceptions
@@ -1159,8 +1163,7 @@ yield:
ip--;
PUSH(ret_value);
goto yield;
- }
- if (ret_kind == MP_VM_RETURN_NORMAL) {
+ } else if (ret_kind == MP_VM_RETURN_NORMAL) {
// Pop exhausted gen
sp--;
// TODO: When ret_value can be MP_OBJ_NULL here??
@@ -1176,8 +1179,8 @@ yield:
// if it was swallowed, we re-raise GeneratorExit
GENERATOR_EXIT_IF_NEEDED(t_exc);
DISPATCH();
- }
- if (ret_kind == MP_VM_RETURN_EXCEPTION) {
+ } else {
+ assert(ret_kind == MP_VM_RETURN_EXCEPTION);
// Pop exhausted gen
sp--;
if (EXC_MATCH(ret_value, MP_OBJ_FROM_PTR(&mp_type_StopIteration))) {
diff --git a/py/vmentrytable.h b/py/vmentrytable.h
index dd9789e348..352a6dc315 100644
--- a/py/vmentrytable.h
+++ b/py/vmentrytable.h
@@ -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)
*
diff --git a/py/vstr.c b/py/vstr.c
index bd05c28de2..48eca38113 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -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)
*
@@ -34,7 +34,7 @@
#include "py/mpprint.h"
// returned value is always at least 1 greater than argument
-#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
+#define ROUND_ALLOC(a) (((a) & ((~0U) - 7)) + 8)
// Init the vstr so it allocs exactly given number of bytes. Set length to zero.
void vstr_init(vstr_t *vstr, size_t alloc) {
diff --git a/py/warning.c b/py/warning.c
index 4cdf3b3f10..46b31ecca7 100644
--- a/py/warning.c
+++ b/py/warning.c
@@ -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)
*