Skip to content
Snippets Groups Projects
  1. Mar 08, 2019
    • Andrew Leech's avatar
      py: Allow registration of modules at their definition. · cf22f479
      Andrew Leech authored
      During make, makemoduledefs.py parses the current builds c files for
      MP_REGISTER_MODULE(module_name, obj_module, enabled_define)
      
      These are used to generate a header with the required entries for
      "mp_rom_map_elem_t mp_builtin_module_table[]" in py/objmodule.c
      cf22f479
    • Damien George's avatar
      9a5f92ea
    • 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
    • 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
  2. Mar 05, 2019
    • Damien George's avatar
      py/persistentcode: Define static qstr set to reduce size of mpy files. · 4f0931b2
      Damien George authored
      When encoded in the mpy file, if qstr <= QSTR_LAST_STATIC then store two
      bytes: 0, static_qstr_id.  Otherwise encode the qstr as usual (either with
      string data or a reference into the qstr window).
      
      Reduces mpy file size by about 5%.
      4f0931b2
    • Damien George's avatar
      py/persistentcode: Pack qstrs directly in bytecode to reduce mpy size. · 992a6e1d
      Damien George authored
      Instead of emitting two bytes in the bytecode for where the linked qstr
      should be written to, it is now replaced by the actual qstr data, or a
      reference into the qstr window.
      
      Reduces mpy file size by about 10%.
      992a6e1d
    • Damien George's avatar
      py/persistentcode: Add a qstr window to save mpy files more efficiently. · 5996eeb4
      Damien George authored
      This is an implementation of a sliding qstr window used to reduce the
      number of qstrs stored in a .mpy file.  The window size is configured to 32
      entries which takes a fixed 64 bytes (16-bits each) on the C stack when
      loading/saving a .mpy file.  It allows to remember the most recent 32 qstrs
      so they don't need to be stored again in the .mpy file.  The qstr window
      uses a simple least-recently-used mechanism to discard the least recently
      used qstr when the window overflows (similar to dictionary compression).
      This scheme only needs a single pass to save/load the .mpy file.
      
      Reduces mpy file size by about 25% with a window size of 32.
      5996eeb4
    • Damien George's avatar
      py: Replace POP_BLOCK and POP_EXCEPT opcodes with POP_EXCEPT_JUMP. · 5a2599d9
      Damien George authored
      POP_BLOCK and POP_EXCEPT are now the same, and are always followed by a
      JUMP.  So this optimisation reduces code size, and RAM usage of bytecode by
      two bytes for each try-except handler.
      5a2599d9
    • Damien George's avatar
      py/vm: Remove currently_in_except_block variable. · 6f9e3ff7
      Damien George authored
      After the previous commit it is no longer needed.
      6f9e3ff7
    • Damien George's avatar
      py: Fix VM crash with unwinding jump out of a finally block. · e1fb03f3
      Damien George authored
      This patch fixes a bug in the VM when breaking within a try-finally.  The
      bug has to do with executing a break within the finally block of a
      try-finally statement.  For example:
      
          def f():
              for x in (1,):
                  print('a', x)
                  try:
                      raise Exception
                  finally:
                      print(1)
                      break
                  print('b', x)
          f()
      
      Currently in uPy the above code will print:
      
          a 1
          1
          1
          segmentation fault (core dumped)  micropython
      
      Not only is there a seg fault, but the "1" in the finally block is printed
      twice.  This is because when the VM executes a finally block it doesn't
      really know if that block was executed due to a fall-through of the try (no
      exception raised), or because an exception is active.  In particular, for
      nested finallys the VM has no idea which of the nested ones have active
      exceptions and which are just fall-throughs.  So when a break (or continue)
      is executed it tries to unwind all of the finallys, when in fact only some
      may be active.
      
      It's questionable whether break (or return or continue) should be allowed
      within a finally block, because they implicitly swallow any active
      exception, but nevertheless it's allowed by CPython (although almost never
      used in the standard library).  And uPy should at least not crash in such a
      case.
      
      The solution here relies on the fact that exception and finally handlers
      always appear in the bytecode after the try body.
      
      Note: there was a similar bug with a return in a finally block, but that
      was previously fixed in b7352084
      e1fb03f3
  3. Mar 04, 2019
  4. Mar 01, 2019
    • Damien George's avatar
      py/compile: Add optimisation to compile OrderedDict inplace. · 0779693c
      Damien George authored
      This optimisation eliminates the need to create a temporary normal dict.
      The optimisation is enabled via MICROPY_COMP_CONST_LITERAL which is enabled
      by default (although only has an effect if OrderdDict is enabled).
      
      Thanks to @pfalcon for the initial idea and implementation.
      0779693c
  5. Feb 26, 2019
  6. Feb 25, 2019
  7. Feb 20, 2019
  8. Feb 19, 2019
  9. Feb 13, 2019
  10. Feb 12, 2019
  11. Feb 05, 2019
  12. Jan 31, 2019
    • Paul Sokolovsky's avatar
      py/warning: Support categories for warnings. · 2f5d113f
      Paul Sokolovsky authored
      Python defines warnings as belonging to categories, where category is a
      warning type (descending from exception type). This is useful, as e.g.
      allows to disable warnings selectively and provide user-defined warning
      types.  So, implement this in MicroPython, except that categories are
      represented just with strings.  However, enough hooks are left to implement
      categories differently per-port (e.g. as types), without need to patch each
      and every usage.
      2f5d113f
  13. Jan 27, 2019
  14. Jan 25, 2019
  15. Jan 10, 2019
  16. Jan 04, 2019
  17. Dec 27, 2018
Loading