1. 20 Feb, 2018 3 commits
    • Damien George's avatar
      py/modmicropython: Allow to have stack_use() func without mem_info(). · 7e2a4885
      Damien George authored
      The micropython.stack_use() function is useful to query the current C stack
      usage, and it's inclusion in the micropython module doesn't need to be tied
      to the inclusion of mem_info()/qstr_info() because it doesn't rely on any
      of the code from these functions.  So this patch introduces the config
      option MICROPY_PY_MICROPYTHON_STACK_USE which can be used to independently
      control the inclusion of stack_use().  By default it is enabled if
      MICROPY_PY_MICROPYTHON_MEM_INFO is enabled (thus not changing any of the
      existing ports).
      7e2a4885
    • Damien George's avatar
      py/builtinimport: Add compile-time option to disable external imports. · 20993688
      Damien George authored
      The new option is MICROPY_ENABLE_EXTERNAL_IMPORT and is enabled by default
      so that the default behaviour is the same as before.  With it disabled
      import is only supported for built-in modules, not for external files nor
      frozen modules.  This allows to support targets that have no filesystem of
      any kind and that only have access to pre-supplied built-in modules
      implemented natively.
      20993688
    • Damien George's avatar
  2. 19 Feb, 2018 10 commits
    • Damien George's avatar
    • Damien George's avatar
      py/objstr: Protect against creating bytes(n) with n negative. · 4e469085
      Damien George authored
      Prior to this patch uPy (on a 32-bit arch) would have severe issues when
      calling bytes(-1): such a call would call vstr_init_len(vstr, -1) which
      would then +1 on the len and call vstr_init(vstr, 0), which would then
      round this up and allocate a small amount of memory for the vstr.  The
      bytes constructor would then attempt to zero out all this memory, thinking
      it had allocated 2^32-1 bytes.
      4e469085
    • Damien George's avatar
      py/repl: Generalise REPL autocomplete to use qstr probing. · 165aab12
      Damien George authored
      This patch changes the way REPL autocomplete finds matches.  It now probes
      the target object for all qstrs via mp_load_method_maybe to look for a
      match with the given input string.  Similar to how the builtin dir()
      function works, this new algorithm now find all methods and instances of
      user-defined classes including attributes of their parent classes.  This
      helps a lot at the REPL prompt for user-discovery and to autocomplete names
      even for classes that are derived.
      
      The downside is that this new algorithm is slower than the previous one,
      and in particular will be slower the more qstrs there are in the system.
      But because REPL autocomplete is primarily used in an interactive way it is
      not that important to make it fast, as long as it is "fast enough" compared
      to human reaction.
      
      On a slow microcontroller (CPU running at 16MHz) the autocomplete time for
      a list of 35 names in the outer namespace (pressing tab at a bare prompt)
      takes about 160ms with this algorithm, compared to about 40ms for the
      previous implementation (this time includes the actual printing of the
      names as well).  This time of 160ms is very reasonable especially given the
      new functionality of listing all the names.
      
      This patch also decreases code size by:
      
         bare-arm:    +0
      minimal x86:  -128
         unix x64:  -128
      unix nanbox:  -224
            stm32:   -88
           cc3200:   -80
          esp8266:   -92
            esp32:   -84
      165aab12
    • Damien George's avatar
      py/modbuiltins: Simplify and generalise dir() by probing qstrs. · 98647e83
      Damien George authored
      This patch improves the builtin dir() function by probing the target object
      with all possible qstrs via mp_load_method_maybe.  This is very simple (in
      terms of implementation), doesn't require recursion, and allows to list all
      methods of user-defined classes (without duplicates) even if they have
      multiple inheritance with a common parent.  The downside is that it can be
      slow because it has to iterate through all the qstrs in the system, but
      the "dir()" function is anyway mostly used for testing frameworks and user
      introspection of types, so speed is not considered a priority.
      
      In addition to providing a more complete implementation of dir(), this
      patch is simpler than the previous implementation and saves some code
      space:
      
         bare-arm:   -80
      minimal x86:   -80
         unix x64:   -56
      unix nanbox:   -48
            stm32:   -80
           cc3200:   -80
          esp8266:  -104
            esp32:   -64
      98647e83
    • Damien George's avatar
      a8775aae
    • Damien George's avatar
    • Ayke van Laethem's avatar
      py/gc: Make GC stack pointer a local variable. · 736faef2
      Ayke van Laethem authored
      This saves a bit in code size, and saves some precious .bss RAM:
      
                       .text  .bss
      minimal CROSS=1: -28    -4
      unix (64-bit):   -64    -8
      736faef2
    • Ayke van Laethem's avatar
      py/gc: Rename gc_drain_stack to gc_mark_subtree and pass it first block. · 5c9e5618
      Ayke van Laethem authored
      This saves a bit in code size:
      
      minimal CROSS=1: -44
      unix:            -96
      5c9e5618
    • Ayke van Laethem's avatar
      py/gc: Reduce code size by specialising VERIFY_MARK_AND_PUSH macro. · ea7cf2b7
      Ayke van Laethem authored
      This macro is written out explicitly in the two locations that it is used
      and then the code is optimised, opening possibilities for further
      optimisations and reducing code size:
      
      unix:            -48
      minimal CROSS=1: -32
      stm32:           -32
      ea7cf2b7
    • Mike Wadsten's avatar
  3. 18 Feb, 2018 4 commits
    • Damien George's avatar
      esp32/machine_touchpad: Swap pins 32 and 33. · 5a82ba8e
      Damien George authored
      Based on testing, this is how the mapping should be.
      5a82ba8e
    • Damien George's avatar
      py/pystack: Use "pystack exhausted" as error msg for out of pystack mem. · 7b2a9b05
      Damien George authored
      Using the message "maximum recursion depth exceeded" for when the pystack
      runs out of memory can be misleading because the pystack can run out for
      reasons other than deep recursion (although in most cases pystack
      exhaustion is probably indirectly related to deep recursion).  And it's
      important to give the user more precise feedback as to the reason for the
      error: if they know precisely that the pystack was exhausted then they have
      a chance to increase the amount of memory available to the pystack (as
      opposed to not knowing if it was the C stack or pystack that ran out).
      
      Also, C stack exhaustion is more serious than pystack exhaustion because it
      could have been that the C stack overflowed and overwrote/corrupted some
      data and so the system must be restarted.  The pystack can never corrupt
      data in this way so pystack exhaustion does not require a system restart.
      Knowing the difference between these two cases is therefore important.
      
      The actual exception type for pystack exhaustion remains as RuntimeError so
      that programatically it behaves the same as a C stack exhaustion.
      7b2a9b05
    • Damien George's avatar
    • Ayke van Laethem's avatar
      py/nlrthumb: Do not mark nlr_push as not returning anything. · 5591bd23
      Ayke van Laethem authored
      By adding __builtin_unreachable() at the end of nlr_push, we're
      essentially telling the compiler that this function will never return.
      When GCC LTO is in use, this means that any time nlr_push() is called
      (which is often), the compiler thinks this function will never return
      and thus eliminates all code following the call.
      
      Note: I've added a 'return 0' for older GCC versions like 4.6 which
      complain about not returning anything (which doesn't make sense in a
      naked function). Newer GCC versions (tested 4.8, 5.4 and some others)
      don't complain about this.
      5591bd23
  4. 16 Feb, 2018 3 commits
  5. 15 Feb, 2018 9 commits
  6. 14 Feb, 2018 9 commits
  7. 13 Feb, 2018 2 commits