aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2018-10-01tests/run-tests: Enabled native tests that pass now that yield works.Damien George
2018-10-01py/emitnative: Implement yield and yield-from in native emitter.Damien George
This commit adds first class support for yield and yield-from in the native emitter, including send and throw support, and yields enclosed in exception handlers (which requires pulling down the NLR stack before yielding, then rebuilding it when resuming). This has been fully tested and is working on unix x86 and x86-64, and stm32. Also basic tests have been done with the esp8266 port. Performance of existing native code is unchanged.
2018-10-01py/emitnative: Reorder native state on C stack so nlr_buf_t is first.Damien George
The nlr_buf_t doesn't need to be part of the Python value stack (as it was before this commit), it's simpler to have it separated as auxiliary state that lives on the C stack. This will help adding yield support because in that case the nlr_buf_t and Python value stack live in separate memory areas (C stack and heap respectively).
2018-10-01py/asmxtensa: Use proper calculation for const table offset.Damien George
Instead of hard-coding it to 4 bytes. This allows for there to be other data stored at the very start of the emitted native code.
2018-10-01py/asmx64: Extend asm_x64_mov_reg_pcrel to accept high registers.Damien George
2018-10-01py/asmx86: Comment out unused asm_x86_nop to prevent compiler warnings.Damien George
2018-09-30py/asmthumb: Extend asm entry/exit to handle stack larger than 508 bytesDamien George
2018-09-30py/asmthumb: Clean up asm_thumb_bl_ind to use new optimised ldr helper.Damien George
2018-09-30py/asmthumb: Add wide ldr to handle larger offsets.Damien George
In particular this allows native functions on Thumb2 to index more than 32 constants in the constant table.
2018-09-29py/vm: When VM raises exception put exc obj at beginning of func state.Damien George
Instead of at end of state, n_state - 1. It was originally (way back in v1.0) put at the end of the state because the VM didn't have a pointer to the start. But now that the VM takes a mp_code_state_t pointer it does have a pointer to the start of the state so can put the exception object there. This commit saves about 30 bytes of code on all architectures, and, more importantly, reduces C-stack usage by a couple of words (8 bytes on Thumb2 and 16 bytes on x86-64) for every (non-generator) call of a bytecode function because fun_bc_call no longer needs to remember the n_state variable.
2018-09-28py/objtype: Support full object model for get/set/delitem special meths.Damien George
This makes these special methods have the same calling behaviour as other methods in a class instance (mp_convert_member_lookup() is already called by mp_obj_class_lookup()).
2018-09-28py/objtype: Remove TODO about storing attributes to classes.Damien George
This behaviour is tested in basics/class_store.py and follows CPython.
2018-09-28py/runtime: Remove nlr protection when calling __next__ in mp_resume.Damien George
And remove related comment about needing such protection when calling send. Reasoning for removal is as follows: - mp_resume is only called by the VM in YIELD_FROM opcode - if send_value != MP_OBJ_NULL then throw_value == MP_OBJ_NULL - so if __next__ or send are called then throw_value == MP_OBJ_NULL - if __next__ or send raise an exception without nlr protection then the exception will be handled by the global exception handler of the VM - this handler already has code to handle exceptions raised in YIELD_FROM, including correct handling of StopIteration - this handler doesn't handle the case of injection of GeneratorExit, but this won't be needed because throw_value == MP_OBJ_NULL Note that it's already possible for mp_resume() to raise an exception (including StopIteration) from the unprotected call to type->iternext(), so that's why the VM already has code to handle the case of exceptions coming out of mp_resume(). This commit reduces code size by a bit, and significantly reduces C stack usage when using yield-from, from 88 bytes down to 40 for Thumb2, and 152 down to 72 bytes for x86-64 (better than half). (Note that gcc doesn't seem to tail-call optimise the call from mp_resume() to mp_obj_gen_resume() so this saving in C stack usage helps all uses of yield-from.)
2018-09-28py/vm: Fix case of throwing GeneratorExit type into yield-from.Damien George
mp_make_raise_obj must be used to convert a possible exception type to an instance object, otherwise the VM may raise a non-exception object. An existing test is adjusted to test this case, with the original test already moved to generator_throw.py.
2018-09-28tests/basics: Split out gen throw tests from yield-from-throw tests.Damien George
2018-09-28py/emitnative: Change type of const_table from uintptr_t to mp_uint_t.Damien George
This matches how bytecode does it, and matches the signature of mp_emit_glue_assign_native. Since the native emitter doesn't support nan-boxing uintptr_t and mp_uint_t are anyway the same bit-width.
2018-09-27esp8266: Remove scanning of GC pointers in native code block.Damien George
The native code no longer holds live GC pointers so doesn't need to be scanned.
2018-09-27tests/micropython: Test loading const objs in native and viper funcs.Damien George
2018-09-27py/asm*: Remove ASM_MOV_REG_ALIGNED_IMM emit macro, it's no longer used.Damien George
After the previous commit this macro is no longer needed by the native emitter because live heap pointers are no longer stored in generated native machine code.
2018-09-27py/emitnative: Place const objs for native code in separate const table.Damien George
This commit changes native code to handle constant objects like bytecode: instead of storing the pointers inside the native code they are now stored in a separate constant table (such pointers include objects like bignum, bytes, and raw code for nested functions). This removes the need for the GC to scan native code for root pointers, and takes a step towards making native code independent of the runtime (eg so it can be compiled offline by mpy-cross). Note that the changes to the struct scope_t did not increase its size: on a 32-bit architecture it is still 48 bytes, and on a 64-bit architecture it decreased from 80 to 72 bytes.
2018-09-27docs/library/network: Make AbstractNIC methods layout correctly.Damien George
2018-09-27docs/library/network: Move specific network classes to their own file.Damien George
All concrete network classes are now moved to their own file (eg network.WLAN.rst) and deconditionalised (remove ..only:: directives). This makes the network documentation the same for all ports. After this change there are no more "..only::" directives for different ports, and the only difference among ports is the very front page of the docs.
2018-09-27py/objfloat: Fix abs(-0.0) so it returns 0.0.Damien George
Nan and inf (signed and unsigned) are also handled correctly by using signbit (they were also handled correctly with "val<0", but that didn't handle -0.0 correctly). A test case is added for this behaviour.
2018-09-27lib/libm/math: Add implementation of __signbitf, if needed by a port.Damien George
2018-09-27lib/libm/math: Fix int type in float union, uint64_t should be uint32_t.Damien George
A float is 32-bits wide.
2018-09-27py/objgenerator: Remove TODO about returning gen being called again.Damien George
The code implements correct behaviour, as tested by the new test case added in this commit.
2018-09-27py/vm: Reword TODO about invalid ip/sp after an exception to a note.Damien George
2018-09-27py/objmodule: Remove TODO about checking store attr to a module.Damien George
The code implements correct behaviour, as tested by basics/module1.py.
2018-09-27py/objint: Remove TODO about checking of int() arg types with 2 args.Damien George
The arguments are checked by mp_obj_str_get_data and mp_obj_get_int.
2018-09-27py/objdict: Reword TODO about inlining mp_obj_dict_get to a note.Damien George
2018-09-27py/objslice: Remove long-obsolete comment about enhancing slice object.Damien George
Commit afaaf535e6cfaf599432b13a2fbe9373e6a2c4b8 made this comment obsolete.
2018-09-27py/vm: Make small optimisation of BUILD_SLICE opcode.Damien George
No need to call DECODE_UINT since the value will always be either 2 or 3.
2018-09-26py: Fix msvc C++ compiler warnings with MP_OBJ_FUN_MAKE_SIG macro.stijn
When obj.h is compiled as C++ code, the cl compiler emits a warning about possibly unsafe mixing of size_t and bool types in the or operation in MP_OBJ_FUN_MAKE_SIG. Similarly there's an implicit narrowing integer conversion in runtime.h. This commit fixes this by being explicit.
2018-09-26tests/cpydiff: Add case for difference in behaviour of bytes.format().Paul Sokolovsky
2018-09-26py/objstr: format: Return bytes result for bytes format string.Paul Sokolovsky
This is an improvement over previous behavior when str was returned for both str and bytes input format. This new behaviour is also consistent with how the % operator works, as well as many other str/bytes methods. It should be noted that it's not how current versions of CPython work, where there's a gap in the functionality and bytes.format() is not supported.
2018-09-26docs/library/machine.SPI: Add note about baudrate imprecision.Peter Hinch
2018-09-26unix/mpconfigport.h: Enable MICROPY_PY_UHASHLIB_MD5 for uhashlib.md5.Paul Sokolovsky
This will allow to e.g. implement HTTP Digest authentication. Adds 540 bytes for x86_32, 332 for arm_thumb2 (for Unix port, which already includes axTLS library).
2018-09-26stm32/mpconfigport.h: Enable math.factorial, optimised version.Damien George
2018-09-26py/modmath: Add math.factorial, optimised and non-opt implementations.Christopher Swenson
This commit adds the math.factorial function in two variants: - squared difference, which is faster than the naive version, relatively compact, and non-recursive; - a mildly optimised recursive version, faster than the above one. There are some more optimisations that could be done, but they tend to take more code, and more storage space. The recursive version seems like a sensible compromise. The new function is disabled by default, and uses the non-optimised version by default if it is enabled. The options are MICROPY_PY_MATH_FACTORIAL and MICROPY_OPT_MATH_FACTORIAL.
2018-09-26stm32/usbd_conf: Allocate enough space in USB HS TX FIFO for CDC packet.Damien George
The CDC maximum packet size is 512 bytes, or 128 32-bit words, and the TX FIFO must be configured to have at least this size.
2018-09-26lib/stm32lib: Update library to fix issue with filling USB TX FIFO.Damien George
2018-09-24stm32/powerctrl: Don't configure clocks if already at desired frequency.Damien George
Configuring clocks is a critical operation and is best to avoid when possible. If the clocks really need to be reset to the same values then one can pass in a slightly higher value, eg 168000001 Hz to get 168MHz.
2018-09-24stm32/powerctrl: Optimise passing of default values to set_sysclk.Damien George
2018-09-24stm32/powerctrl: Factor code that configures PLLSAI on F7 MCUs.Damien George
2018-09-24stm32/powerctrl: Factor code to set RCC PLL and use it in startup.Damien George
This ensures that on first boot the most optimal settings are used for the voltage scaling and flash latency (for F7 MCUs). This commit also provides more fine-grained control for the flash latency settings.
2018-09-24stm32/powerctrl: Fix configuring APB1/APB2 frequency when AHB also set.Damien George
APB1/APB2 are derived from AHB, so if the user sets AHB!=SYSCLK then the APB1/APB2 dividers must be computed from the new AHB.
2018-09-24stm32/powerctrl: Move function to set SYSCLK into new powerctrl file.Damien George
Power and clock control is low-level functionality and it makes sense to have it in a dedicated file, at least so it can be reused by other parts of the code.
2018-09-24stm32/modmachine: Re-enable PLLSAI[1] after waking from stop mode.Damien George
On F7s PLLSAI is used as a 48MHz clock source if the main PLL cannot provide such a frequency, and on L4s PLLSAI1 is always used as a clock source for the peripherals. This commit makes sure these PLLs are re-enabled upon waking from stop mode so the peripherals work. See issues #4022 and #4178 (L4 specific).
2018-09-21stm32/boards/NUCLEO_F091RC: Enable USART3-8 with default pins.Damien George
2018-09-21stm32/uart: Add support for USART3-8 on F0 MCUs.Damien George