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
      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. Feb 20, 2019
  3. Feb 12, 2019
    • Damien George's avatar
      054dd33e
    • Damien George's avatar
      py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. · eee1e884
      Damien George authored
      These macros could in principle be (inline) functions so it makes sense to
      have them lower case, to match the other C API functions.
      
      The remaining macros that are upper case are:
      - MP_OBJ_TO_PTR, MP_OBJ_FROM_PTR
      - MP_OBJ_NEW_SMALL_INT, MP_OBJ_SMALL_INT_VALUE
      - MP_OBJ_NEW_QSTR, MP_OBJ_QSTR_VALUE
      - MP_OBJ_FUN_MAKE_SIG
      - MP_DECLARE_CONST_xxx
      - MP_DEFINE_CONST_xxx
      
      These must remain macros because they are used when defining const data (at
      least, MP_OBJ_NEW_SMALL_INT is so it makes sense to have
      MP_OBJ_SMALL_INT_VALUE also a macro).
      
      For those macros that have been made lower case, compatibility macros are
      provided for the old names so that users do not need to change their code
      immediately.
      eee1e884
  4. Jan 25, 2019
    • Damien George's avatar
      py/obj.h: Explicitly cast args to uint32_t in MP_OBJ_FUN_MAKE_SIG. · 5089b3ff
      Damien George authored
      For architectures where size_t is less than 32 bits (eg 16 bits) the args
      must be casted to uint32_t so the left shift will work.  For architectures
      where size_t is greater than 32 bits (eg 64 bits) this new casting will not
      lose any bits because the end result must anyway fit in a uint32_t.
      5089b3ff
  5. Oct 01, 2018
    • Damien George's avatar
      py/obj.h: Use uint64_t instead of mp_int_t in repr-D MP_OBJ_IS_x macros. · 69e79039
      Damien George authored
      This follows how it's already done in MP_OBJ_IS_OBJ: the objects are
      considered 64-bit unsigned ints for the purpose of bitwise manipulation.
      69e79039
    • 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
  6. Sep 26, 2018
    • stijn's avatar
      py: Fix msvc C++ compiler warnings with MP_OBJ_FUN_MAKE_SIG macro. · 57a7d5be
      stijn authored
      When obj.h is compiled as C++ code, the cl compiler emits a warning about
      possibly unsafe mixing of size_t and bool types in the or operation in
      MP_OBJ_FUN_MAKE_SIG.  Similarly there's an implicit narrowing integer
      conversion in runtime.h.  This commit fixes this by being explicit.
      57a7d5be
  7. Sep 14, 2018
    • Damien George's avatar
      py: Optimise call to mp_arg_check_num by compressing fun signature. · 9f241ef3
      Damien George authored
      With 5 arguments to mp_arg_check_num(), some architectures need to pass
      values on the stack.  So compressing n_args_min, n_args_max, takes_kw into
      a single word and passing only 3 arguments makes the call more efficient,
      because almost all calls to this function pass in constant values.  Code
      size is also reduced by a decent amount:
      
         bare-arm:  -116
      minimal x86:   -64
         unix x64:  -256
      unix nanbox:  -112
            stm32:  -324
           cc3200:  -192
          esp8266:  -192
            esp32:  -144
      9f241ef3
  8. Jul 08, 2018
  9. Jul 02, 2018
  10. Jun 08, 2018
  11. Jun 04, 2018
    • Damien George's avatar
      py/stream: Move definition of mp_stream_p_t from obj.h to stream.h. · 1427f8f5
      Damien George authored
      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.
      1427f8f5
  12. May 01, 2018
  13. Mar 30, 2018
  14. Mar 13, 2018
  15. Feb 21, 2018
    • Paul Sokolovsky's avatar
      py/objdeque: Implement ucollections.deque type with fixed size. · 970eedce
      Paul Sokolovsky authored
      So far, implements just append() and popleft() methods, required for
      a normal queue. Constructor doesn't accept an arbitarry sequence to
      initialize from (am empty deque is always created), so an empty tuple
      must be passed as such. Only fixed-size deques are supported, so 2nd
      argument (size) is required.
      
      There's also an extension to CPython - if True is passed as 3rd argument,
      append(), instead of silently overwriting the oldest item on queue
      overflow, will throw IndexError. This behavior is desired in many
      cases, where queues should store information reliably, instead of
      silently losing some items.
      970eedce
  16. Feb 15, 2018
    • Damien George's avatar
      py/objexcept: Remove long-obsolete mp_const_MemoryError_obj. · 73d1d20b
      Damien George authored
      This constant exception instance was once used by m_malloc_fail() to raise
      a MemoryError without allocating memory, but it was made obsolete long ago
      by 3556e457.  The functionality is now
      replaced by the use of mp_emergency_exception_obj which lives in the global
      uPy state, and which can handle any exception type, not just MemoryError.
      73d1d20b
  17. Dec 11, 2017
  18. Nov 16, 2017
    • Damien George's avatar
      py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str. · 4601759b
      Damien George authored
      This patch simplifies the str creation API to favour the common case of
      creating a str object that is not forced to be interned.  To force
      interning of a new str the new mp_obj_new_str_via_qstr function is added,
      and should only be used if warranted.
      
      Apart from simplifying the mp_obj_new_str function (and making it have the
      same signature as mp_obj_new_bytes), this patch also reduces code size by a
      bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
      4601759b
  19. Sep 04, 2017
  20. Sep 02, 2017
    • Paul Sokolovsky's avatar
      py/objfloat: Fix binary ops with incompatible objects. · 9950865c
      Paul Sokolovsky authored
      These are now returned as "operation not supported" instead of raising
      TypeError. In particular, this fixes equality for float vs incompatible
      types, which now properly results in False instead of exception. This
      also paves the road to support reverse operation (e.g. __radd__) with
      float objects.
      
      This is achieved by introducing mp_obj_get_float_maybe(), similar to
      existing mp_obj_get_int_maybe().
      9950865c
  21. Aug 29, 2017
  22. Jul 31, 2017
  23. Jul 18, 2017
    • Alexander Steffen's avatar
      all: Unify header guard usage. · 299bc625
      Alexander Steffen authored
      The code conventions suggest using header guards, but do not define how
      those should look like and instead point to existing files. However, not
      all existing files follow the same scheme, sometimes omitting header guards
      altogether, sometimes using non-standard names, making it easy to
      accidentally pick a "wrong" example.
      
      This commit ensures that all header files of the MicroPython project (that
      were not simply copied from somewhere else) follow the same pattern, that
      was already present in the majority of files, especially in the py folder.
      
      The rules are as follows.
      
      Naming convention:
      * start with the words MICROPY_INCLUDED
      * contain the full path to the file
      * replace special characters with _
      
      In addition, there are no empty lines before #ifndef, between #ifndef and
      one empty line before #endif. #endif is followed by a comment containing
      the name of the guard macro.
      
      py/grammar.h cannot use header guards by design, since it has to be
      included multiple times in a single C file. Several other files also do not
      need header guards as they are only used internally and guaranteed to be
      included only once:
      * MICROPY_MPHALPORT_H
      * mpconfigboard.h
      * mpconfigport.h
      * mpthreadport.h
      * pin_defs_*.h
      * qstrdefs*.h
      299bc625
  24. Apr 22, 2017
  25. Apr 12, 2017
    • Damien George's avatar
      py/objfloat: Add implementation of high-quality float hashing. · a73501b1
      Damien George authored
      Disabled by default.
      a73501b1
    • Damien George's avatar
      py: Optimise types for common case where type has a single parent type. · 816413e4
      Damien George authored
      The common cases for inheritance are 0 or 1 parent types, for both built-in
      types (eg built-in exceptions) as well as user defined types.  So it makes
      sense to optimise the case of 1 parent type by storing just the type and
      not a tuple of 1 value (that value being the single parent type).
      
      This patch makes such an optimisation.  Even though there is a bit more
      code to handle the two cases (either a single type or a tuple with 2 or
      more values) it helps reduce overall code size because it eliminates the
      need to create a static tuple to hold single parents (eg for the built-in
      exceptions).  It also helps reduce RAM usage for user defined types that
      only derive from a single parent.
      
      Changes in code size (in bytes) due to this patch:
      
          bare-arm:       -16
          minimal (x86): -176
          unix (x86-64): -320
          unix nanbox:   -384
          stmhal:         -64
          cc3200:         -32
          esp8266:       -108
      816413e4
    • Damien George's avatar
  26. Apr 04, 2017
    • Damien George's avatar
      py: Add very simple but correct hashing for float and complex numbers. · 19f2e47d
      Damien George authored
      Hashing of float and complex numbers that are exact (real) integers should
      return the same integer hash value as hashing the corresponding integer
      value.  Eg hash(1), hash(1.0) and hash(1+0j) should all be the same (this
      is how Python is specified: if x==y then hash(x)==hash(y)).
      
      This patch implements the simplest way of doing float/complex hashing by
      just converting the value to int and returning that value.
      19f2e47d
  27. Apr 02, 2017
  28. Mar 29, 2017
    • Damien George's avatar
    • Damien George's avatar
      py: Convert mp_uint_t to size_t for tuple/list accessors. · 6213ad7f
      Damien George authored
      This patch changes mp_uint_t to size_t for the len argument of the
      following public facing C functions:
      
      mp_obj_tuple_get
      mp_obj_list_get
      mp_obj_get_array
      
      These functions take a pointer to the len argument (to be filled in by the
      function) and callers of these functions should update their code so the
      type of len is changed to size_t.  For ports that don't use nan-boxing
      there should be no change in generate code because the size of the type
      remains the same (word sized), and in a lot of cases there won't even be a
      compiler warning if the type remains as mp_uint_t.
      
      The reason for this change is to standardise on the use of size_t for
      variables that count memory (or memory related) sizes/lengths.  It helps
      builds that use nan-boxing.
      6213ad7f
Loading