Skip to content
Snippets Groups Projects
  1. 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
  2. Jan 27, 2019
  3. Sep 20, 2018
  4. Jun 20, 2018
  5. May 22, 2018
  6. May 10, 2018
  7. May 09, 2018
  8. Feb 19, 2018
    • 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
  9. Feb 14, 2018
  10. Feb 07, 2018
  11. Dec 05, 2017
    • Damien George's avatar
      py/modbuiltins: Use standard arg-parsing helper func for builtin print. · 58f00d7c
      Damien George authored
      This allows the function to raise an exception when unknown keyword args
      are passed in.  This patch also reduces code size by (in bytes):
      
         bare-arm:   -24
      minimal x86:   -76
         unix x64:   -56
      unix nanbox:   -84
            stm32:   -40
          esp8266:   -68
           cc3200:   -48
      
      Furthermore, this patch adds space (" ") to the set of ROM qstrs which
      means it doesn't need to be put in RAM if it's ever used.
      58f00d7c
  12. Nov 22, 2017
  13. 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
  14. Oct 11, 2017
  15. Oct 04, 2017
    • Damien George's avatar
      all: Remove inclusion of internal py header files. · a3dc1b19
      Damien George authored
      Header files that are considered internal to the py core and should not
      normally be included directly are:
          py/nlr.h - internal nlr configuration and declarations
          py/bc0.h - contains bytecode macro definitions
          py/runtime0.h - contains basic runtime enums
      
      Instead, the top-level header files to include are one of:
          py/obj.h - includes runtime0.h and defines everything to use the
              mp_obj_t type
          py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
              and defines everything to use the general runtime support functions
      
      Additional, specific headers (eg py/objlist.h) can be included if needed.
      a3dc1b19
  16. Sep 17, 2017
    • Paul Sokolovsky's avatar
      py/modbuiltins: Implement abs() by dispatching to MP_UNARY_OP_ABS. · 9dce823c
      Paul Sokolovsky authored
      This allows user classes to implement __abs__ special method, and saves
      code size (104 bytes for x86_64), even though during refactor, an issue
      was fixed and few optimizations were made:
      
      * abs() of minimum (negative) small int value is calculated properly.
      * objint_longlong and objint_mpz avoid allocating new object is the
        argument is already non-negative.
      9dce823c
  17. Aug 02, 2017
  18. Jul 31, 2017
  19. Jul 07, 2017
  20. Jul 04, 2017
  21. Jun 15, 2017
  22. Jun 01, 2017
    • Damien George's avatar
      py/modbuiltins: Add core-provided version of input() function. · bc76302e
      Damien George authored
      The implementation is taken from stmhal/input.c, with code added to handle
      ctrl-C.  This built-in is controlled by MICROPY_PY_BUILTINS_INPUT and is
      disabled by default.  It uses readline() to capture input but this can be
      overridden by defining the mp_hal_readline macro.
      bc76302e
  23. May 14, 2017
  24. Mar 29, 2017
  25. Mar 28, 2017
  26. Mar 24, 2017
    • Damien George's avatar
      py/modbuiltins: Allow round() to return a big int if necessary. · c236ebfe
      Damien George authored
      Previous to this patch, if the result of the round function overflowed a
      small int, or was inf or nan, then a garbage value was returned.  With
      this patch the correct big-int is returned if necessary and exceptions are
      raised for inf or nan.
      c236ebfe
    • Damien George's avatar
      py/modbuiltins: For round() builtin use nearbyint instead of round. · 125eae1b
      Damien George authored
      The C nearbyint function has exactly the semantics that Python's round()
      requires, whereas C's round() requires extra steps to handle rounding of
      numbers half way between integers.  So using nearbyint reduces code size
      and potentially eliminates any source of errors in the handling of half-way
      numbers.
      
      Also, bare-metal implementations of nearbyint can be more efficient than
      round, so further code size is saved (and efficiency improved).
      
      nearbyint is provided in the C99 standard so it should be available on all
      supported platforms.
      125eae1b
  27. Feb 16, 2017
    • Damien George's avatar
      py: Add iter_buf to getiter type method. · ae8d8675
      Damien George authored
      Allows to iterate over the following without allocating on the heap:
      - tuple
      - list
      - string, bytes
      - bytearray, array
      - dict (not dict.keys, dict.values, dict.items)
      - set, frozenset
      
      Allows to call the following without heap memory:
      - all, any, min, max, sum
      
      TODO: still need to allocate stack memory in bytecode for iter_buf.
      ae8d8675
  28. Feb 02, 2017
  29. Jan 22, 2017
  30. Dec 20, 2016
  31. Oct 24, 2016
  32. Oct 21, 2016
  33. Oct 17, 2016
  34. Sep 21, 2016
Loading