summaryrefslogtreecommitdiff
path: root/py/builtin.c
AgeCommit message (Collapse)Author
2014-12-09py: Allow builtins to be overridden.Damien George
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS) which, when enabled, allows to override all names within the builtins module. A builtins override dict is created the first time the user assigns to a name in the builtins model, and then that dict is searched first on subsequent lookups. Note that this implementation doesn't allow deleting of names. This patch also does some refactoring of builtins code, creating the modbuiltins.c file. Addresses issue #959.
2014-11-27builtin: Reimplement __repl_print__() in terms of print().Paul Sokolovsky
Before, __repl_print__() used libc printf(), while print() used uPy streams and own printf() implementation. This led to subtle, but confusing differences in output when just doing "foo" vs "print(foo)" on interactive prompt.
2014-11-06py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.Damien George
Going from MICROPY_ERROR_REPORTING_NORMAL to MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2, and 2200 bytes ROM for 32-bit x86. This is about a 2.5% code size reduction for bare-arm.
2014-10-31py: Add builtin round function.Damien George
Addresses issue #934.
2014-10-22py: Fix smallint modulo with negative arguments.Damien George
Addresses issue #927.
2014-10-03py: Convert [u]int to mp_[u]int_t where appropriate.Damien George
Addressing issue #50.
2014-09-13py: Fix build error when float disabled; add test for divmod.Damien George
2014-09-13py: Implement divmod, % and proper // for floating point.Damien George
Tested and working on unix and pyboard.
2014-09-07py: Rename mp_builtin_id to mp_obj_id and make it public.Damien George
2014-08-30py: Change uint to mp_uint_t in runtime.h, stackctrl.h, binary.h.Damien George
Part of code cleanup, working towards resolving issue #50.
2014-08-30py: Change all uint to mp_uint_t in obj.h.Damien George
Part of code cleanup, working towards resolving issue #50.
2014-08-24py: Consolidate min/max functions into one, and add key= argument.Damien George
Addresses issue #811.
2014-08-12py: Implement builtin reversed() function.Damien George
reversed function now implemented, and works for tuple, list, str, bytes and user objects with __len__ and __getitem__. Renamed mp_builtin_len to mp_obj_len to make it publically available (eg for reversed).
2014-08-12py: Make a function static; replace NULL with MP_OBJ_NULL.Damien George
2014-07-31py: Improve handling of long-int overflow.Damien George
This removes mpz_as_int, since that was a terrible function (it implemented saturating conversion). Use mpz_as_int_checked and mpz_as_uint_checked. These now work correctly (they previously had wrong overflow checking, eg print(chr(10000000000000)) on 32-bit machine would incorrectly convert this large number to a small int).
2014-07-28py: Make id() return small int for the most common address space mapping.Paul Sokolovsky
Many OSes/CPUs have affinity to put "user" data into lower half of address space. Take advantage of that and remap such addresses into full small int range (including negative part). If address is from upper half, long int will be used. Previously, small int was returned for lower quarter of address space, and upper quarter. For 2 middle quarters, long int was used, which is clearly worse schedule than the above.
2014-07-19py: Make print() accept "file" argument, and actually print to stream.Paul Sokolovsky
And not system printf(), like it was before. For this, move pfenv_printf() from stmhal port to py/.
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-28py: Make unichar_charlen() accept/return machine_uint_t.Paul Sokolovsky
2014-06-28py: Small comments, name changes, use of machine_int_t.Damien George
2014-06-27builtin: Restore bytestr compatibility.Paul Sokolovsky
2014-06-27builtin: ord, chr: Unicode support.Chris Angelico
2014-06-20py: Separate MICROPY_PY_BUILTINS_COMPLEX from MICROPY_PY_BUILTINS_FLOAT.Paul Sokolovsky
One thing is wanting to do 1 / 2 and get something else but 0, and quite another - doing rocket science ;-).
2014-06-19Prefix ARRAY_SIZE with micropython prefix MP_Emmanuel Blot
2014-06-08py: Make sure getattr() works with non-interned strings (by interning them).Paul Sokolovsky
2014-06-06Change comments (mainly URLs) to no longer specifically say Python 3.3Chris Angelico
2014-06-01Rename bultins config variables to MICROPY_PY_BUILTINS_*.Damien George
This renames: MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT See issue #35 for discussion.
2014-05-25Change const byte* to const char* where sensible.Damien George
This removes need for some casts (at least, more than it adds need for new casts!).
2014-05-11py: Add basic implementation of hasattr() function.Paul Sokolovsky
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-02py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky
Specifically, nlr.h does.
2014-05-01Fix the builtin min() and max() functions (and add tests).Andrew Scheller
Fixes #539
2014-04-26Add ARRAY_SIZE macro, and use it where possible.Damien George
2014-04-17py: Add MP_OBJ_STOP_ITERATION and make good use of it.Damien George
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL. This helps a lot in debugging and understanding of function API.
2014-04-17py: Make built-in 'range' a class.Damien George
Addresses issue #487.
2014-04-15py: Add builtin functions bin and oct, and some tests for them.Damien George
2014-04-15py: Fix builtin hex to print prefix.Damien George
I was too hasty. Still a one-liner though.
2014-04-15py: Add hex builtin function.Damien George
A one-liner, added especially for @pfalcon :)
2014-04-06py: Revert mp_load_attr() to its previous state (not supporting default val).Paul Sokolovsky
Based on the discussion in #433. mp_load_attr() is critical-path function, so any extra check will slowdown any script. As supporting default val required only for getattr() builtin, move correspending implementation there (still as a separate function due to concerns of maintainability of such almost-duplicated code instances).
2014-04-06py: Optimize locals()/globals() implementation.Paul Sokolovsky
2014-04-06py: Implement globals() and locals() builtins.Paul Sokolovsky
2014-04-05py: Make globals and locals proper dictionary objects.Damien George
Finishes addressing issue #424. In the end this was a very neat refactor that now makes things a lot more consistent across the py code base. It allowed some simplifications in certain places, now that everything is a dict object. Also converted builtins tables to dictionaries. This will be useful when we need to turn builtins into a proper module.
2014-04-05py: Change module globals from mp_map_t* to mp_obj_dict_t*.Damien George
Towards addressing issue #424. Had a small increase to ROM usage (order 60 bytes).
2014-04-05py: Change nlr_jump to nlr_raise, to aid in debugging.Damien George
This does not affect code size or performance when debugging turned off. To address issue #420.
2014-04-05py: Support 3-arg getattr() builtin (with default value).Paul Sokolovsky
2014-04-04py: Remove mp_obj_less (use mp_binary_op(MP_BINARY_OP_LESS..) instead).Damien George
2014-04-02py: Move to Python 3.4.0 compatibility.Damien George
Very little has changed. In Python 3.4 they removed the opcode STORE_LOCALS, but in Micro Python we only ever used this for CPython compatibility, so it was a trivial thing to remove. It also allowed to clean up some dead code (eg the 0xdeadbeef in class construction), and now class builders use 1 less stack word. Python 3.4.0 introduced the LOAD_CLASSDEREF opcode, which I have not yet understood. Still, all tests (apart from bytecode test) still pass. Bytecode tests needs some more attention, but they are not that important anymore.
2014-04-02py: Add support for sep and end keywords in print.Damien George
2014-03-31py: Remove old "run time" functions that were 1 liners.Damien George
2014-03-30Merge map.h into obj.h.Damien George
Pretty much everyone needs to include map.h, since it's such an integral part of the Micro Python object implementation. Thus, the definitions are now in obj.h instead. map.h is removed.