summaryrefslogtreecommitdiffstatshomepage
path: root/py/modbuiltins.c
Commit message (Collapse)AuthorAge
* py,extmod,stmhal: Use "static inline" for funcs that should be inline.Damien George2017-08-02
| | | | | "STATIC inline" can expand to "inline" if STATIC is defined to nothing, and this case can lead to link errors.
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* py,extmod: Some casts and minor refactors to quiet compiler warnings.Tom Collins2017-07-07
|
* py: Change mp_uint_t to size_t in builtins code.Damien George2017-07-04
|
* all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers.Damien George2017-06-15
|
* py/modbuiltins: Add core-provided version of input() function.Damien George2017-06-01
| | | | | | | 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.
* py/modsys: update conditionals for code referencing sys.stdoutTom Collins2017-05-14
| | | | Working on a build with PY_IO enabled (for PY_UJSON support) but PY_SYS_STDFILES disabled (no filesystem). There are multiple references to mp_sys_stdout_obj that should only be enabled if both PY_IO and PY_SYS_STDFILES are enabled.
* py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George2017-03-29
|
* py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.Damien George2017-03-28
| | | | Saves 168 bytes on bare-arm.
* py/modbuiltins: Allow round() to return a big int if necessary.Damien George2017-03-24
| | | | | | | 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.
* py/modbuiltins: For round() builtin use nearbyint instead of round.Damien George2017-03-24
| | | | | | | | | | | | | | 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.
* py: Add iter_buf to getiter type method.Damien George2017-02-16
| | | | | | | | | | | | | | | 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.
* py: Added optimised support for 3-argument calls to builtin.pow()Nicko van Someren2017-02-02
| | | | | | Updated modbuiltin.c to add conditional support for 3-arg calls to pow() using MICROPY_PY_BUILTINS_POW3 config parameter. Added support in objint_mpz.c for for optimised implementation.
* py: Add builtin help function to core, with default help msg.Damien George2017-01-22
| | | | | This builtin is configured using MICROPY_PY_BUILTINS_HELP, and is disabled by default.
* py/modbuiltins: Remove unreachable code.Damien George2016-12-20
|
* py: Add "delattr" builtin, conditional on MICROPY_CPYTHON_COMPAT.Damien George2016-10-24
|
* py/modbuiltins: Add builtin "slice", pointing to existing slice type.Damien George2016-10-24
|
* py/{modbuiltins,obj}: Use MP_PYTHON_PRINTER where possible.Paul Sokolovsky2016-10-22
|
* py: Use mp_raise_msg helper function where appropriate.Damien George2016-10-17
| | | | | Saves the following number of bytes of code space: 176 for bare-arm, 352 for minimal, 272 for unix x86-64, 140 for stmhal, 120 for esp8266.
* all: Remove 'name' member from mp_obj_module_t struct.Damien George2016-09-22
| | | | One can instead lookup __name__ in the modules dict to get the value.
* py: Get rid of assert() in method argument checking functions.Paul Sokolovsky2016-08-12
| | | | | | Checks for number of args removes where guaranteed by function descriptor, self checking is replaced with mp_check_self(). In few cases, exception is raised instead of assert.
* py: add async/await/async for/async with syntaxpohmelie2016-04-13
| | | | | | | | They are sugar for marking function as generator, "yield from" and pep492 python "semantically equivalents" respectively. @dpgeorge was the original author of this patch, but @pohmelie made changes to implement `async for` and `async with`.
* py/modbuiltins: __repl_print__: Add comment about setting "_" special var.Paul Sokolovsky2016-04-13
|
* py: Fix passing of some wide int types to printf varg format list.Damien George2016-03-14
| | | | | | Passing an mp_uint_t to a %d printf format is incorrect for builds where mp_uint_t is larger than word size (eg a nanboxing build). This patch adds some simple casting to int in these cases.
* py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.Damien George2016-01-11
| | | | | | | | The first argument to the type.make_new method is naturally a uPy type, and all uses of this argument cast it directly to a pointer to a type structure. So it makes sense to just have it a pointer to a type from the very beginning (and a const pointer at that). This patch makes such a change, and removes all unnecessary casting to/from mp_obj_t.
* py: Change type signature of builtin funs that take variable or kw args.Damien George2016-01-11
| | | | | With this patch the n_args parameter is changed type from mp_uint_t to size_t.
* py/modbuiltins: Fix access of mp_obj_t variable, wrap in MP_OBJ_TO_PTR.Damien George2016-01-04
|
* py: Make dir report instance membersDave Hylands2016-01-03
|
* py: Change struct and macro for builtin fun so they can be type checked.Damien George2016-01-03
|
* py: Add MICROPY_ENABLE_COMPILER and MICROPY_PY_BUILTINS_EVAL_EXEC opts.Damien George2015-12-18
| | | | | | | | | | | | MICROPY_ENABLE_COMPILER can be used to enable/disable the entire compiler, which is useful when only loading of pre-compiled bytecode is supported. It is enabled by default. MICROPY_PY_BUILTINS_EVAL_EXEC controls support of eval and exec builtin functions. By default they are only included if MICROPY_ENABLE_COMPILER is enabled. Disabling both options saves about 40k of code size on 32-bit x86.
* py: Add min/max "default" keyword argumentpohmelie2015-12-07
|
* py: Add MICROPY_PY_BUILTINS_MIN_MAX, disable for minimal ports.pohmelie2015-12-07
|
* py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George2015-11-29
| | | | | | | | | This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
* py: Add MP_ROM_* macros and mp_rom_* types and use them.Damien George2015-11-29
|
* py: Check that second argument to hasattr is actually a string.Damien George2015-11-23
| | | | Fixes issue #1623.
* py: Add mp_obj_is_float function (macro) and use it where appropriate.Damien George2015-10-20
|
* py: Add support for _ in REPL to hold last computed value.Damien George2015-10-17
| | | | Only available when MICROPY_CAN_OVERRIDE_BUILTINS is enabled.
* py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming.Paul Sokolovsky2015-10-11
|
* modbuiltins: Consistently use indentation for #if.Paul Sokolovsky2015-08-31
|
* py: Add MICROPY_PY_BUILTINS_FILTER, disable for minimal ports.Paul Sokolovsky2015-08-20
| | | | Saves 320 bytes on x86.
* modbuiltins: Implement round() to precision.Sebastian Plamauer2015-07-19
|
* py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin.Damien George2015-06-13
|
* py: Expose KeyboardInterrupt in builtins module.Damien George2015-06-05
|
* py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George2015-05-12
| | | | | | | | | | | | | | Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
* objsingleton: New home for Ellipsis and NotImplemented.Paul Sokolovsky2015-05-05
| | | | | | | Having NotImplemented as MP_OBJ_SENTINEL turned out to be problematic (it needs to be checked for in a lot of places, otherwise it'll crash as would pass MP_OBJ_IS_OBJ()), so made a proper singleton value like Ellipsis, both of them sharing the same type.
* modbuiltins: Add NotImplemented builtin constant.Paul Sokolovsky2015-05-04
| | | | | | | | | | | | From https://docs.python.org/3/library/constants.html#NotImplemented : "Special value which should be returned by the binary special methods (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g. __imul__(), __iand__(), etc.) for the same purpose. Its truth value is true." Some people however appear to abuse it to mean "no value" when None is a legitimate value (don't do that).
* py: Make viper codegen raise proper exception (ViperTypeError) on error.Damien George2015-04-20
| | | | | | | | | | | This fixes a long standing problem that viper code generation gave terrible error messages, and actually no errors on pyboard where assertions are disabled. Now all compile-time errors are raised as proper Python exceptions, and are of type ViperTypeError. Addresses issue #940.
* py: Fix builtin ord so that it can handle bytes values >= 0x80.Damien George2015-04-19
| | | | Addresses issue #1188.
* py: Convert occurrences of non-debug printf to mp_printf.Damien George2015-04-16
|
* py: Make mp_sys_stdout_print object, wrapping sys.stdout for mp_print*.Damien George2015-04-16
| | | | | So now all printing should go via either mp_plat_print or mp_sys_stdout_print.