Skip to content
Snippets Groups Projects
  1. May 29, 2019
    • Damien George's avatar
      py/nativeglue: Remove dependency on mp_fun_table in dyn-compiler mode. · a4f1d827
      Damien George authored
      mpy-cross uses MICROPY_DYNAMIC_COMPILER and MICROPY_EMIT_NATIVE but does
      not actually need to execute native functions, and does not need
      mp_fun_table.  This commit makes it so mp_fun_table and all its entries are
      not built when MICROPY_DYNAMIC_COMPILER is enabled, significantly reducing
      the size of the mpy-cross executable and allowing it to be built on more
      machines/OS's.
      a4f1d827
  2. May 06, 2019
    • Jun Wu's avatar
      py: remove "if (0)" and "if (false)" branches. · 089c9b71
      Jun Wu authored
      Prior to this commit, building the unix port with `DEBUG=1` and
      `-finstrument-functions` the compilation would fail with an error like
      "control reaches end of non-void function".  This change fixes this by
      removing the problematic "if (0)" branches.  Not all branches affect
      compilation, but they are all removed for consistency.
      089c9b71
  3. May 03, 2019
  4. Mar 14, 2019
  5. Mar 08, 2019
    • Damien George's avatar
      py: Add support to save native, viper and asm code to .mpy files. · 1396a026
      Damien George authored
      This commit adds support for saving and loading .mpy files that contain
      native code (native, viper and inline-asm).  A lot of the ground work was
      already done for this in the form of removing pointers from generated
      native code.  The changes here are mainly to link in qstr values to the
      native code, and change the format of .mpy files to contain native code
      blocks (possibly mixed with bytecode).
      
      A top-level summary:
      
      - @micropython.native, @micropython.viper and @micropython.asm_thumb/
        asm_xtensa are now allowed in .py files when compiling to .mpy, and they
        work transparently to the user.
      
      - Entire .py files can be compiled to native via mpy-cross -X emit=native
        and for the most part the generated .mpy files should work the same as
        their bytecode version.
      
      - The .mpy file format is changed to 1) specify in the header if the file
        contains native code and if so the architecture (eg x86, ARMV7M, Xtensa);
        2) for each function block the kind of code is specified (bytecode,
        native, viper, asm).
      
      - When native code is loaded from a .mpy file the native code must be
        modified (in place) to link qstr values in, just like bytecode (see
        py/persistentcode.c:arch_link_qstr() function).
      
      In addition, this now defines a public, native ABI for dynamically loadable
      native code generated by other languages, like C.
      1396a026
    • Damien George's avatar
      py/emitnative: Adjust accounting of size of const_table. · 39868209
      Damien George authored
      n_obj no longer includes a count for mp_fun_table to make it a bit simpler.
      39868209
    • Damien George's avatar
    • Damien George's avatar
      py/emitnative: Consolidate where HASCONSTS is set to load-const-obj fun. · 01a1f31f
      Damien George authored
      Simplifies the code and fixes handling of the Ellipsis const in native code
      generation (which also needs the constant table so must set this flag).
      01a1f31f
    • Damien George's avatar
      py: Add independent config for debugging sentinel object values. · 02cc288e
      Damien George authored
      The new compile-time option is MICROPY_DEBUG_MP_OBJ_SENTINELS, disabled by
      default.  This is to allow finer control of whether this debugging feature
      is enabled or not (because, for example, this setting must be the same for
      mpy-cross and the MicroPython main code when using native code generation).
      02cc288e
  6. Mar 05, 2019
  7. Feb 25, 2019
  8. Oct 14, 2018
  9. Oct 13, 2018
  10. Oct 02, 2018
  11. Oct 01, 2018
    • Damien George's avatar
      py/emitnative: Implement yield and yield-from in native emitter. · cc2bd63c
      Damien George authored
      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.
      cc2bd63c
    • Damien George's avatar
      py/emitnative: Reorder native state on C stack so nlr_buf_t is first. · 8fec6f54
      Damien George authored
      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).
      8fec6f54
  12. Sep 27, 2018
    • Damien George's avatar
      py/emitnative: Change type of const_table from uintptr_t to mp_uint_t. · e9012a20
      Damien George authored
      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.
      e9012a20
    • Damien George's avatar
      py/emitnative: Place const objs for native code in separate const table. · 7d4b6cc8
      Damien George authored
      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.
      7d4b6cc8
  13. Sep 15, 2018
  14. Sep 13, 2018
    • Damien George's avatar
      py: Fix native functions so they run with their correct globals context. · 4f3d9429
      Damien George authored
      Prior to this commit a function compiled with the native decorator
      @micropython.native would not work correctly when accessing global
      variables, because the globals dict was not being set upon function entry.
      
      This commit fixes this problem by, upon function entry, setting as the
      current globals dict the globals dict context the function was defined
      within, as per normal Python semantics, and as bytecode does.  Upon
      function exit the original globals dict is restored.
      
      In order to restore the globals dict when an exception is raised the native
      function must guard its internals with an nlr_push/nlr_pop pair.  Because
      this push/pop is relatively expensive, in both C stack usage for the
      nlr_buf_t and CPU execution time, the implementation here optimises things
      as much as possible.  First, the compiler keeps track of whether a function
      even needs to access global variables.  Using this information the native
      emitter then generates three different kinds of code:
      
      1. no globals used, no exception handlers: no nlr handling code and no
         setting of the globals dict.
      
      2. globals used, no exception handlers: an nlr_buf_t is allocated on the
         C stack but it is not used if the globals dict is unchanged, saving
         execution time because nlr_push/nlr_pop don't need to run.
      
      3. function has exception handlers, may use globals: an nlr_buf_t is
         allocated and nlr_push/nlr_pop are always called.
      
      In the end, native functions that don't access globals and don't have
      exception handlers will run more efficiently than those that do.
      
      Fixes issue #1573.
      4f3d9429
  15. Sep 11, 2018
  16. Sep 04, 2018
  17. Sep 03, 2018
Loading