Commit Graph

11838 Commits

Author SHA1 Message Date
Damien George 190c7dba89 stm32/mpconfigport.h: Enable DELATTR_SETATTR and BUILTINS_NOTIMPLEMENTED
MICROPY_PY_DELATTR_SETATTR can now be enabled without a performance hit for
classes that don't use this feature.

MICROPY_PY_BUILTINS_NOTIMPLEMENTED is a minor addition that improves
compatibility with CPython.
2018-06-08 12:55:18 +10:00
Damien George 93150a0d40 ports: Enable descriptors on stm32, esp8266, esp32 ports.
They are now efficient (in runtime performance) and provide a useful
feature that's hard to obtain without them enabled.

See issue #3644 and PR #3826 for background.
2018-06-08 12:23:08 +10:00
Damien George 36c1052183 py/objtype: Optimise instance get/set/del by skipping special accessors.
This patch is a code optimisation, trading text bytes for speed.  On
pyboard it's an increase of 0.06% in code size for a gain (in pystone
performance) of roughly 6.5%.

The patch optimises load/store/delete of attributes in user defined classes
by not looking up special accessors (@property, __get__, __delete__,
__set__, __setattr__ and __getattr_) if they are guaranteed not to exist in
the class.

Currently, if you do my_obj.foo() then the runtime has to do a few checks
to see if foo is a property or has __get__, and if so delegate the call.
And for stores things like my_obj.foo = 1 has to first check if foo is a
property or has __set__ defined on it.

Doing all those checks each and every time the attribute is accessed has a
performance penalty.  This patch eliminates all those checks for cases when
it's guaranteed that the checks will always fail, ie no attributes are
properties nor have any special accessor methods defined on them.

To make this guarantee it checks all attributes of a user-defined class
when it is first created.  If any of the attributes of the user class are
properties or have special accessors, or any of the base classes of the
user class have them, then it sets a flag in the class to indicate that
special accessors must be checked for.  Then in the load/store/delete code
it checks this flag to see if it can take the shortcut and optimise the
lookup.

It's an optimisation that's pretty widely applicable because it improves
lookup performance for all methods of user defined classes, and stores of
attributes, at least for those that don't have special accessors.  And, it
allows to enable descriptors with minimal additional runtime overhead if
they are not used for a particular user class.

There is one restriction on dynamic class creation that has been introduced
by this patch: a user-defined class cannot go from zero special accessors
to one special accessor (or more) after that class has been subclassed.  If
the script attempts this an AttributeError is raised (see addition to
tests/misc/non_compliant.py for an example of this case).

The cost in code space bytes for the optimisation in this patch is:

   unix x64:  +528
unix nanbox:  +508
      stm32:  +192
     cc3200:  +200
    esp8266:  +332
      esp32:  +244

Performance tests that were done:

- on unix x86-64, pystone improved by about 5%
- on pyboard, pystone improved by about 6.5%, from 1683 up to 1794
- on pyboard, bm_chaos (from CPython benchmark suite) improved by about 5%
- on esp32, pystone improved by about 30% (but there are caching effects)
- on esp32, bm_chaos improved by about 11%
2018-06-08 12:12:08 +10:00
Damien George bace1a16d0 py/objtype: Don't expose mp_obj_instance_attr().
mp_obj_is_instance_type() can be used instead to check for instance types.
2018-06-08 11:48:25 +10:00
Damien George db5d8c97f1 py/obj.h: Introduce a "flags" entry in mp_obj_type_t. 2018-06-08 11:48:25 +10:00
Dan Halbert c01ce175bb
Merge pull request #914 from SConaway/patch-1
Update README.rst
2018-06-07 20:44:19 -04:00
Dan Halbert 0ecfd2923f
Merge pull request #913 from kattni/itsybitsy-name-fix
Itsybitsy name fixes
2018-06-07 18:12:51 -04:00
Steven Conaway f36fa308e7
Update README.rst 2018-06-07 12:15:15 -07:00
Kattni Rembor ba7e0e2f86 Add Adafruit to other M4 board name strings 2018-06-07 13:39:04 -04:00
Kattni Rembor 7b2875d54a Add Adafruit to board name string 2018-06-07 13:33:13 -04:00
Kattni Rembor 0ab2a60dcd Update ItsyBitsy board name to one word 2018-06-07 13:12:44 -04:00
hathach c854e2dc17 Merge branch 'master' into usbboot 2018-06-07 13:51:21 +07:00
hathach 9bb4ded5fa Merge remote-tracking branch 'upstream/master' 2018-06-07 13:50:04 +07:00
Dan Halbert 44721cba3d
Merge pull request #910 from kattni/rotaryio-doc-fix
Fixed documentation formatting for RTD
2018-06-06 20:06:33 -04:00
Kattni Rembor 3a38172627 Fixed documentation formatting for RTD 2018-06-06 18:28:01 -04:00
Kattni ca24cad60a
Merge pull request #902 from dhalbert/feather_m0x_crickit
Feather M0 Express build with frozen Crickit libraries
2018-06-06 14:41:13 -04:00
Dan Halbert 1079f94fc5
Merge pull request #905 from jepler/main-stack-usage
main: move code pertaining to boot.py out of line
2018-06-06 09:24:51 -04:00
Jeff Epler 654591e11f main: move code pertaining to boot.py out of line
.. this reduces stack usage in main() substantially, because
the 512 byte stack allocation will only exist during the new run_boot_py
function's duration.

Closes: #904
2018-06-06 08:01:17 -05:00
Damien George b789c640f7 travis: Install explicit version of urllib3 for coveralls.
Coveralls requires a "recent" version of urllib3, whereas requests requires
a "not so recent" version, less than 1.23.  So force urllib3 v1.22 to get
it all working.
2018-06-06 20:56:24 +10:00
Scott Shawcroft aa636841a2
Merge pull request #903 from jepler/stack-overflow-crash
main: Explicitly set the stack top based on _estack
2018-06-05 22:05:13 -07:00
Damien George a8b9e71ac1 py/mpconfig.h: Add default MICROPY_VFS_FAT config value.
At least to document it's existence.
2018-06-06 14:33:42 +10:00
Damien George c117effddd extmod/vfs: Introduce a C-level VFS protocol, with fast import_stat.
Following other C-level protocols, this VFS protocol is added to help
abstract away implementation details of the underlying VFS in an efficient
way.  As a starting point, the import_stat function is put into this
protocol so that the VFS sub-system does not need to know about every VFS
implementation in order to do an efficient stat for importing files.

In the future it might be worth adding other functions to this protocol.
2018-06-06 14:33:42 +10:00
Damien George fadd6bbe43 unix/moduos_vfs: Add missing uos functions from traditional uos module.
Now that the coverage build has fully switched to the VFS sub-system these
functions were no longer available, so add them to the uos_vfs module.

Also, vfs_open is no longer needed, it's available as the built-in open.
2018-06-06 14:28:23 +10:00
Damien George 5ef0d2ab14 tests/extmod: Remove conditional import of uos_vfs, it no longer exists.
This conditional import was only used to get the tests working on the unix
coverage build, which has now switched to use VFS by default so the uos
module alone has the required functionality.
2018-06-06 14:28:23 +10:00
Damien George 6c02da2eec tests/extmod: Add test for importing a script from a user VFS. 2018-06-06 14:28:23 +10:00
Damien George 1d40f12e44 unix: Support MICROPY_VFS_POSIX and enable it in coverage build.
The unix coverage build is now switched fully to the VFS implementation, ie
the uos module is the uos_vfs module.  For example, one can now sandbox uPy
to their home directory via:

    $ ./micropython_coverage

    >>> import uos
    >>> uos.umount('/') # unmount existing root VFS
    >>> vfs = uos.VfsPosix('/home/user') # create new POSIX VFS
    >>> uos.mount(vfs, '/') # mount new POSIX VFS at root

Some filesystem/OS features may no longer work with the coverage build due
to this change, and these need to be gradually fixed.

The standard unix port remains unchanged, it still uses the traditional uos
module which directly accesses the underlying host filesystem.
2018-06-06 14:28:23 +10:00
Damien George d4ce57e4e3 extmod/vfs: Add fast path for stating VfsPosix filesystem. 2018-06-06 14:28:23 +10:00
Damien George a93144cb65 py/reader: Allow MICROPY_VFS_POSIX to work with MICROPY_READER_POSIX. 2018-06-06 14:28:23 +10:00
Damien George 8d82b0edbd extmod: Add VfsPosix filesystem component.
This VFS component allows to mount a host POSIX filesystem within the uPy
VFS sub-system.  All traditional POSIX file access then goes through the
VFS, allowing to sandbox a uPy process to a certain sub-dir of the host
system, as well as mount other filesystem types alongside the host
filesystem.
2018-06-06 14:28:23 +10:00
Damien George f35aae366c extmod/vfs_fat: Rename FileIO/TextIO types to mp_type_vfs_fat_XXX.
So they don't clash with other VFS implementations.
2018-06-06 14:28:23 +10:00
Damien George 172c23fe5d extmod/vfs: Use u_rom_obj properly in argument structures. 2018-06-06 14:28:23 +10:00
Jeff Epler a4e06bd998 main: Explicitly set the stack top based on _estack
.. setting it based on the ad-hoc stack pointer calculation of
mp_stack_ctrl_init() meant that the stack used above main() counts
against the 1KiB safety factor that the mp_stack_set_limit call tries
to establish.  It turns out, at least on M4, that over half of the
safety factor is used up by stack-above-main()!

In the case of the basics/gen_stack_overflow.py test,
which blows the stack on purpose, it turns out that gc would be called
while handling the "maximum recursion depth exceeded" error, and this
needed more stack than was left.

Closes: #900
2018-06-05 22:04:55 -05:00
Dan Halbert 36a7ebe88e add feather_m0_express_crickit to .travis.yml 2018-06-05 18:24:55 -04:00
Dan Halbert 9ba6990228 Feather M0 Express build with Crickit libraries 2018-06-05 18:21:47 -04:00
Dan Halbert 74ced174ce
Merge pull request #898 from dhalbert/feather_m4_d4
add PA14 as D4 to Feather M4 Express
2018-06-05 11:41:31 -04:00
Dan Halbert 7e7e33e460 add PA14 as D4 to Feather M4 Exprses 2018-06-05 08:15:34 -04:00
Damien George aace60a75e esp8266/modules/ntptime.py: Remove print of newly-set time.
It should be up to the user if they want to print the new time out or not.

Fixes issue #3766.
2018-06-05 14:30:35 +10:00
Damien George a90124a9e2 esp32: Add support for building with external SPI RAM.
This patch adds support for building the firmware with external SPI RAM
enabled.  It is disabled by default because it adds overhead (due to
silicon workarounds) and reduces performance (because it's slower to have
bytecode and objects stored in external RAM).

To enable it, either use "make CONFIG_SPIRAM_SUPPORT=1", or add this line
to you custom makefile/GNUmakefile (before "include Makefile"):

    CONFIG_SPIRAM_SUPPORT = 1

When this option is enabled the MicroPython heap is automatically allocated
in external SPI RAM.

Thanks to Angus Gratton for help with the compiler and linker settings.
2018-06-05 13:57:59 +10:00
Angus Gratton bc92206f89 esp32/Makefile: Extract common C & C++ flags for consistent compilation. 2018-06-05 13:05:12 +10:00
Scott Shawcroft 52cc3ed76a
Merge pull request #893 from notro/cpboard
tools: Add cpboard.py
2018-06-04 17:31:44 -07:00
Scott Shawcroft 0c7c0821fc
Merge pull request #891 from godlygeek/low_flash_errno_fixes
Human readable OSError messages for low flash devices
2018-06-04 17:22:57 -07:00
Damien George df13ecde06 cc3200/mods: Include stream.h to get definition of mp_stream_p_t. 2018-06-04 16:58:45 +10:00
Damien George 1427f8f593 py/stream: Move definition of mp_stream_p_t from obj.h to stream.h.
Since a long time now, mp_obj_type_t no longer refers explicitly to
mp_stream_p_t but rather to an abstract "const void *protocol".  So there's
no longer any need to define mp_stream_p_t in obj.h and it can go with all
its associated definitions in stream.h.  Pretty much all users of this type
will already include the stream header.
2018-06-04 16:53:17 +10:00
Damien George 309fe39dbb stm32/modnetwork: Fix arg indexing in generic ifconfig method. 2018-06-03 21:50:49 +10:00
Dan Halbert 9a6a5ea2d9
Merge pull request #892 from tannewt/clock_w_crystal
Use the external crystal on SAMD21 again.
2018-06-02 18:43:23 -04:00
Kattni 47b60fd3fa
Merge pull request #896 from dhalbert/update_frozen_lis3dh
Update HID code and seesaw version
2018-06-02 18:09:52 -04:00
Dan Halbert 0ed946c5b8 Merge remote-tracking branch 'adafruit/master' into update_frozen_lis3dh 2018-06-02 17:44:56 -04:00
Dan Halbert 27eba65dc7 update HID, and update seesaw version 2018-06-02 17:43:08 -04:00
Kattni 41865887f7
Merge pull request #895 from dhalbert/update_frozen_lis3dh
Update frozen LIS3DH to 4.2.1 to save space
2018-06-02 17:37:41 -04:00
Dan Halbert 6e6bfc4d57 Update frozen LIS3DH to 4.2.1 to save space 2018-06-02 17:00:23 -04:00