aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2018-01-31lib/utils/pyexec.h: Include py/obj.h because its decls are needed.Damien George
2018-01-31stm32: Add support for DHT11/DHT22 sensors.Damien George
2018-01-31esp8266/modules: Move dht.py driver to drivers/dht directory.Damien George
2018-01-31extmod/vfs_fat_file: Implement SEEK_CUR for non-zero offset.Ayke van Laethem
CPython doesn't allow SEEK_CUR with non-zero offset for files in text mode, and uPy inherited this behaviour for both text and binary files. It makes sense to provide full support for SEEK_CUR of binary-mode files in uPy, and to do this in a minimal way means also allowing to use SEEK_CUR with non-zero offsets on text-mode files. That seems to be a fair compromise.
2018-01-31windows: Add Appveyor CI builds for windows mingw portstijn
Build and test 32bit and 64bit versions of the windows port using gcc from mingw-w64. Note a bunch of tests which rely on floating point math/printing have been disabled for now since they fail.
2018-01-31stm32/modmachine: Handle case of no MICROPY_PY_MACHINE_I2C.Peter D. Gray
2018-01-10drivers/sdcard: Avoid allocation on the heap.Ayke van Laethem
This commit fixes two things: 1. Do not allocate on the heap in readblocks() - unless the block size is bigger than 512 bytes. 2. Raise an error instead of returning 1 to indicate an error: the FAT block device layer does not check the return value. And other backends (e.g. esp32 blockdev) also raise an error instead of returning non-zero.
2018-01-10drivers/display/ssd1306: Fix super() call in SSD1306 driver.Jim Mussared
2017-12-29py/nlr: Fix missing trailing characters in comments in nlr.cstijn
2017-12-29py/nlr: Fix nlr functions for 64bit ports built with gcc on Windowsstijn
The number of registers used should be 10, not 12, to match the assembly code in nlrx64.c. With this change the 64bit mingw builds don't need to use the setjmp implementation, and this fixes miscellaneous crashes and assertion failures as reported in #1751 for instance. To avoid mistakes in the future where something gcc-related for Windows only gets fixed for one particular compiler/environment combination, make use of a MICROPY_NLR_OS_WINDOWS macro. To make sure everything nlr-related is now ok when built with gcc this has been verified with: - unix port built with gcc on Cygwin (i686-pc-cygwin-gcc and x86_64-pc-cygwin-gcc, version 6.4.0) - windows port built with mingw-w64's gcc from Cygwin (i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc, version 6.4.0) and MSYS2 (like the ones on Cygwin but version 7.2.0)
2017-12-29windows/mpconfigport: Enable some features, including the Python stackstijn
Add some features which are already enabled in the unix port and default to using the Python stack for scoped allocations: this can be more performant in cases the heap is heavily used because for example the memory needed for storing *args and **kwargs doesn't require scanning the heap to find a free block.
2017-12-29windows/mpconfigport: Provide off_t definition for MSVC portstijn
For MSVC off_t is defined in sys/types.h but according to the comment earlier in mpconfigport.h this cannot be included directly. So just make off_t the same as mp_off_t. This fixes the build for MSVC with MICROPY_STREAMS_POSIX_API enabled because stream.h uses off_t.
2017-12-29py/mpz: In mpz_as_str_inpl, convert always-false checks to assertions.Damien George
There are two checks that are always false so can be converted to (negated) assertions to save code space and execution time. They are: 1. The check of the str parameter, which is required to be non-NULL as per the original comment that it has enough space in it as calculated by mp_int_format_size. And for all uses of this function str is indeed non-NULL. 2. The check of the base parameter, which is already required to be between 2 and 16 (inclusive) via the assertion in mp_int_format_size.
2017-12-29py/mpz: Simplify handling of borrow and quo adjustment in mpn_div.Damien George
The motivation behind this patch is to remove unreachable code in mpn_div. This unreachable code was added some time ago in 9a21d2e070c9ee0ef2c003f3a668e635c6ae4401, when a loop in mpn_div was copied and adjusted to work when mpz_dig_t was exactly half of the size of mpz_dbl_dig_t (a common case). The loop was copied correctly but it wasn't noticed at the time that the final part of the calculation of num-quo*den could be optimised, and hence unreachable code was left for a case that never occurred. The observation for the optimisation is that the initial value of quo in mpn_div is either exact or too large (never too small), and therefore the subtraction of quo*den from num may subtract exactly enough or too much (but never too little). Using this observation the part of the algorithm that handles the borrow value can be simplified, and most importantly this eliminates the unreachable code. The new code has been tested with DIG_SIZE=3 and DIG_SIZE=4 by dividing all possible combinations of non-negative integers with between 0 and 3 (inclusive) mpz digits.
2017-12-29py/parse: Fix macro evaluation by avoiding empty __VA_ARGS__.Damien George
Empty __VA_ARGS__ are not allowed in the C preprocessor so adjust the rule arg offset calculation to not use them. Also, some compilers (eg MSVC) require an extra layer of macro expansion.
2017-12-29py/parse: Update debugging code to compile on 64-bit arch.Damien George
2017-12-29py/parse: Compress rule pointer table to table of offsets.Damien George
This is the sixth and final patch in a series of patches to the parser that aims to reduce code size by compressing the data corresponding to the rules of the grammar. Prior to this set of patches the rules were stored as rule_t structs with rule_id, act and arg members. And then there was a big table of pointers which allowed to lookup the address of a rule_t struct given the id of that rule. The changes that have been made are: - Breaking up of the rule_t struct into individual components, with each component in a separate array. - Removal of the rule_id part of the struct because it's not needed. - Put all the rule arg data in a big array. - Change the table of pointers to rules to a table of offsets within the array of rule arg data. The last point is what is done in this patch here and brings about the biggest decreases in code size, because an array of pointers is now an array of bytes. Code size changes for the six patches combined is: bare-arm: -644 minimal x86: -1856 unix x64: -5408 unix nanbox: -2080 stm32: -720 esp8266: -812 cc3200: -712 For the change in parser performance: it was measured on pyboard that these six patches combined gave an increase in script parse time of about 0.4%. This is due to the slightly more complicated way of looking up the data for a rule (since the 9th bit of the offset into the rule arg data table is calculated with an if statement). This is an acceptable increase in parse time considering that parsing is only done once per script (if compiled on the target).
2017-12-28py/parse: Remove rule_t struct because it's no longer needed.Damien George
2017-12-28py/parse: Pass rule_id to push_result_token, instead of passing rule_t*.Damien George
2017-12-28py/parse: Pass rule_id to push_result_rule, instead of passing rule_t*.Damien George
Reduces code size by eliminating quite a few pointer dereferences.
2017-12-28py/parse: Break rule data into separate act and arg arrays.Damien George
Instead of each rule being stored in ROM as a struct with rule_id, act and arg, the act and arg parts are now in separate arrays and the rule_id part is removed because it's not needed. This reduces code size, by roughly one byte per grammar rule, around 150 bytes.
2017-12-28py/parse: Split out rule name from rule struct into separate array.Damien George
The rule name is only used for debugging, and this patch makes things a bit cleaner by completely separating out the rule name from the rest of the rule data.
2017-12-28stm32/spi: If MICROPY_HW_SPIn_MISO undefined, do not claim pin on init.Peter D. Gray
This permits output-only SPI use.
2017-12-28py/nlr: Factor out common NLR code to macro and generic funcs in nlr.c.Damien George
Each NLR implementation (Thumb, x86, x64, xtensa, setjmp) duplicates a lot of the NLR code, specifically that dealing with pushing and popping the NLR pointer to maintain the linked-list of NLR buffers. This patch factors all of that code out of the specific implementations into generic functions in nlr.c, along with a helper macro in nlr.h. This eliminates duplicated code.
2017-12-28py/nlr: Clean up selection and config of NLR implementation.Damien George
If MICROPY_NLR_SETJMP is not enabled and the machine is auto-detected then nlr.h now defines some convenience macros for the individual NLR implementations to use (eg MICROPY_NLR_THUMB). This keeps nlr.h and the implementation in sync, and also makes the nlr_buf_t struct easier to read.
2017-12-28py/nlrthumb: Fix use of naked funcs, must only contain basic asm code.Damien George
A function with a naked attribute must only contain basic inline asm statements and no C code. For nlr_push this means removing the "return 0" statement. But for some gcc versions this induces a compiler warning so the __builtin_unreachable() line needs to be added. For nlr_jump, this function contains a combination of C code and inline asm so cannot be naked.
2017-12-26zephyr/main: Remove unused do_str() function.Paul Sokolovsky
The artifact of initial porting effort.
2017-12-26Revert "py/nlr: Factor out common NLR code to generic functions."Paul Sokolovsky
This reverts commit 6a3a742a6c9caaa2be0fd0aac7a5df4ac816081c. The above commit has number of faults starting from the motivation down to the actual implementation. 1. Faulty implementation. The original code contained functions like: NORETURN void nlr_jump(void *val) { nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top); nlr_buf_t *top = *top_ptr; ... __asm volatile ( "mov %0, %%edx \n" // %edx points to nlr_buf "mov 28(%%edx), %%esi \n" // load saved %esi "mov 24(%%edx), %%edi \n" // load saved %edi "mov 20(%%edx), %%ebx \n" // load saved %ebx "mov 16(%%edx), %%esp \n" // load saved %esp "mov 12(%%edx), %%ebp \n" // load saved %ebp "mov 8(%%edx), %%eax \n" // load saved %eip "mov %%eax, (%%esp) \n" // store saved %eip to stack "xor %%eax, %%eax \n" // clear return register "inc %%al \n" // increase to make 1, non-local return "ret \n" // return : // output operands : "r"(top) // input operands : // clobbered registers ); } Which clearly stated that C-level variable should be a parameter of the assembly, whcih then moved it into correct register. Whereas now it's: NORETURN void nlr_jump_tail(nlr_buf_t *top) { (void)top; __asm volatile ( "mov 28(%edx), %esi \n" // load saved %esi "mov 24(%edx), %edi \n" // load saved %edi "mov 20(%edx), %ebx \n" // load saved %ebx "mov 16(%edx), %esp \n" // load saved %esp "mov 12(%edx), %ebp \n" // load saved %ebp "mov 8(%edx), %eax \n" // load saved %eip "mov %eax, (%esp) \n" // store saved %eip to stack "xor %eax, %eax \n" // clear return register "inc %al \n" // increase to make 1, non-local return "ret \n" // return ); for (;;); // needed to silence compiler warning } Which just tries to perform operations on a completely random register (edx in this case). The outcome is the expected: saving the pure random luck of the compiler putting the right value in the random register above, there's a crash. 2. Non-critical assessment. The original commit message says "There is a small overhead introduced (typically 1 machine instruction)". That machine instruction is a call if a compiler doesn't perform tail optimization (happens regularly), and it's 1 instruction only with the broken code shown above, fixing it requires adding more. With inefficiencies already presented in the NLR code, the overhead becomes "considerable" (several times more than 1%), not "small". The commit message also says "This eliminates duplicated code.". An obvious way to eliminate duplication would be to factor out common code to macros, not introduce overhead and breakage like above. 3. Faulty motivation. All this started with a report of warnings/errors happening for a niche compiler. It could have been solved in one the direct ways: a) fixing it just for affected compiler(s); b) rewriting it in proper assembly (like it was before BTW); c) by not doing anything at all, MICROPY_NLR_SETJMP exists exactly to address minor-impact cases like thar (where a) or b) are not applicable). Instead, a backwards "solution" was put forward, leading to all the issues above. The best action thus appears to be revert and rework, not trying to work around what went haywire in the first place.
2017-12-26zephyr/Makefile: clean: Clean libmicropython.a too.Paul Sokolovsky
2017-12-23docs/library/index: Elaborate uPy libraries intro.Paul Sokolovsky
2017-12-23stm32/i2c: Support more I2C baudrates for F746, and more F7 MCUs.Damien George
2017-12-23stm32/i2c: Fix bug with I2C4 initialisation.Damien George
2017-12-23stm32/uart: Support board configs with CTS/RTS on UART6.Damien George
2017-12-22esp8266/Makefile: Remove commented-out unused lines.Damien George
These were copied from the stm32 port (then stmhal) at the very beginning of this port, with the anticipation that the esp8266 port would have board definition files with a list of valid pins and their names. But that has not been implemented and likely won't be, so remove the corresponding lines from the Makefile.
2017-12-22drivers/sdcard: Support old SD cards (<=2GB).Ayke van Laethem
2017-12-22esp32/README: Update toolchain setup.Ayke van Laethem
2017-12-22stm32/uart: Add support for 7-bit modes: 7N1 and 7N2.Peter D. Gray
2017-12-22stm32: Allow to build a board without any hardware I2C ports defined.Damien George
This patch adds in internal config value MICROPY_HW_ENABLE_HW_I2C that is automatically configured, and enabled only if one or more hardware I2C ports are defined in the mpconfigboard.h file. If none are defined then the pyb.I2C class is excluded from the build, along with all supporting code. The machine.I2C class will still be available for software I2C. Disabling all hardware I2C on an F4 board saves around 10,000 bytes of code and 200 bytes of RAM.
2017-12-22stm32: Use corrected capitalization of HAL_SD_CardStateTypedef.Peter D. Gray
It was originally TypeDef. STM32L4 only supports Typedef and F4/F7 have legacy macros in stm32_hal_legacy.h to support both.
2017-12-20tests/basics/memoryerror: Add test for out-of-memory using realloc.Damien George
2017-12-20py/malloc: Remove unneeded code checking m_malloc return value.Damien George
m_malloc already checks for a failed allocation so there's no need to check for it in m_malloc0.
2017-12-20qemu-arm/test_main: Include setjmp.h because it's used by gc_collect.Damien George
And it's no longer unconditionally included by nlr.h, only if NLR_SETJMP is defined.
2017-12-20py/nlr: Factor out common NLR code to generic functions.Damien George
Each NLR implementation (Thumb, x86, x64, xtensa, setjmp) duplicates a lot of the NLR code, specifically that dealing with pushing and popping the NLR pointer to maintain the linked-list of NLR buffers. This patch factors all of that code out of the specific implementations into generic functions in nlr.c. This eliminates duplicated code. The factoring also allows to make the machine-specific NLR code pure assembler code, thus allowing nlrthumb.c to use naked function attributes in the correct way (naked functions can only have basic inline assembler code in them). There is a small overhead introduced (typically 1 machine instruction) because now the generic nlr_jump() must call nlr_jump_tail() rather than them being one combined function.
2017-12-19unix/mpconfigport_coverage.h: Enable MICROPY_PY_IO_RESOURCE_STREAM.Damien George
Where possible it's important to test all code in the code base.
2017-12-19py/modio: Use correct config macro to enable resource_stream function.Damien George
2017-12-19tests/extmod: Add some uctypes tests to improve coverage of that module.Damien George
2017-12-19tests: Add some more tests to improve coverage of py/parse.c.Damien George
2017-12-19py/mpz: Apply a small code-size optimisation.Damien George
2017-12-19tests/basics/builtin_pow3: Add tests for edge cases of pow3.Damien George
2017-12-19py/mpz: Fix pow3 function so it handles the case when 3rd arg is 1.Damien George
In this case the result should always be 0, even if 2nd arg is 0.