summaryrefslogtreecommitdiff
path: root/py/objfun.c
AgeCommit message (Collapse)Author
2017-08-15py: Add verbose debug compile-time flag MICROPY_DEBUG_VERBOSE.Stefan Naumann
It enables all the DEBUG_printf outputs in the py/ source code.
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-06-09py: Provide mp_decode_uint_skip() to help reduce stack usage.Damien George
Taking the address of a local variable leads to increased stack usage, so the mp_decode_uint_skip() function is added to reduce the need for taking addresses. The changes in this patch reduce stack usage of a Python call by 8 bytes on ARM Thumb, by 16 bytes on non-windowing Xtensa archs, and by 16 bytes on x86-64. Code size is also slightly reduced on most archs by around 32 bytes.
2017-03-29py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George
2017-03-29py: Convert mp_uint_t to size_t for tuple/list accessors.Damien George
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.
2017-03-17py: Reduce size of mp_code_state_t structure.Damien George
Instead of caching data that is constant (code_info, const_table and n_state), store just a pointer to the underlying function object from which this data can be derived. This helps reduce stack usage for the case when the mp_code_state_t structure is stored on the stack, as well as heap usage when it's stored on the heap. The downside is that the VM becomes a little more complex because it now needs to derive the data from the underlying function object. But this doesn't impact the performance by much (if at all) because most of the decoding of data is done outside the main opcode loop. Measurements using pystone show that little to no performance is lost. This patch also fixes a nasty bug whereby the bytecode can be reclaimed by the GC during execution. With this patch there is always a pointer to the function object held by the VM during execution, since it's stored in the mp_code_state_t structure.
2017-03-07py: Use mp_obj_get_array where sequence may be a tuple or a list.Krzysztof Blazewicz
2017-02-16py/objfun: Convert mp_uint_t to size_t where appropriate.Damien George
2016-12-09py: Allow inline-assembler emitter to be generic.Damien George
This patch refactors some code so that it is easier to integrate new inline assemblers for different architectures other than ARM Thumb.
2016-10-21py: Specialise builtin funcs to use separate type for fixed arg count.Damien George
Builtin functions with a fixed number of arguments (0, 1, 2 or 3) are quite common. Before this patch the wrapper for such a function cost 3 machine words. After this patch it only takes 2, which can reduce the code size by quite a bit (and pays off even more, the more functions are added). It also makes function dispatch slightly more efficient in CPU usage, and furthermore reduces stack usage for these cases. On x86 and Thumb archs the dispatch functions are now tail-call optimised by the compiler. The bare-arm port has its code size increase by 76 bytes, but stmhal drops by 904 bytes. Stack usage by these builtin functions is decreased by 48 bytes on Thumb2 archs.
2016-09-27py/objfun: Use if instead of switch to check return value of VM execute.Damien George
It's simpler and improves code coverage.
2016-09-27py/objfun: Remove unnecessary check for viper fun with 5 or more args.Damien George
The native emitter/compiler restricts viper functions to 4 args, so there is no need for an extra check in the dynamic dispatch.
2016-08-27py: Rename struct mp_code_state to mp_code_state_t.Damien George
Also at _t to mp_exc_stack pre-declaration in struct typedef.
2016-03-16py/objfun: Allow inline-asm functions to be called with 4 arguments.Damien George
2016-02-02py: Extend native type-sig to use 4 bits, so uint is separate to ptr.Damien George
Before this patch, the native types for uint and ptr/ptr8/ptr16/ptr32 all overlapped and it was possible to make a mistake in casting. Now, these types are all separate and any coding mistakes will be raised as runtime errors.
2016-01-27py/inlineasm: Add ability to specify return type of asm_thumb funcs.Damien George
Supported return types are: object, bool, int, uint. For example: @micropython.asm_thumb def foo(r0, r1) -> uint: add(r0, r0, r1)
2016-01-11py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George
This patch changes the type signature of .make_new and .call object method slots to use size_t for n_args and n_kw (was mp_uint_t. Makes code more efficient when mp_uint_t is larger than a machine word. Doesn't affect ports when size_t and mp_uint_t have the same size.
2016-01-03py: Change struct and macro for builtin fun so they can be type checked.Damien George
2015-12-17py/bc: Use size_t instead of mp_uint_t to count size of state and args.Damien George
2015-12-17py: Fix MICROPY_STACKLESS mode to compile with MICROPY_OBJ_REPR_D.Damien George
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
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.
2015-11-29py: Make mp_setup_code_state take concrete pointer for func arg.Damien George
2015-11-13py: Add MICROPY_PERSISTENT_CODE so code can persist beyond the runtime.Damien George
Main changes when MICROPY_PERSISTENT_CODE is enabled are: - qstrs are encoded as 2-byte fixed width in the bytecode - all pointers are removed from bytecode and put in const_table (this includes const objects and raw code pointers) Ultimately this option will enable persistence for not just bytecode but also native code.
2015-11-13py: Add constant table to bytecode.Damien George
Contains just argument names at the moment but makes it easy to add arbitrary constants.
2015-11-13py: Put all bytecode state (arg count, etc) in bytecode.Damien George
2015-11-13py: Reorganise bytecode layout so it's more structured, easier to edit.Damien George
2015-07-23py: Allow viper functions to take up to 4 arguments.Damien George
Addresses issue #1380.
2015-06-08py: Fallback to stack alloca for Python-stack if heap alloc fails.Damien George
If heap allocation for the Python-stack of a function fails then we may as well allocate the Python-stack on the C stack. This will allow to run more code without using the heap.
2015-05-12py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George
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__".
2015-04-25objfun: Fix to stackless mode after recent refactor.Paul Sokolovsky
2015-04-16py: Add %q format support to mp_[v]printf, and use it.Damien George
2015-04-16py: Overhaul and simplify printf/pfenv mechanism.Damien George
Previous to this patch the printing mechanism was a bit of a tangled mess. This patch attempts to consolidate printing into one interface. All (non-debug) printing now uses the mp_print* family of functions, mainly mp_printf. All these functions take an mp_print_t structure as their first argument, and this structure defines the printing backend through the "print_strn" function of said structure. Printing from the uPy core can reach the platform-defined print code via two paths: either through mp_sys_stdout_obj (defined pert port) in conjunction with mp_stream_write; or through the mp_plat_print structure which uses the MP_PLAT_PRINT_STRN macro to define how string are printed on the platform. The former is only used when MICROPY_PY_IO is defined. With this new scheme printing is generally more efficient (less layers to go through, less arguments to pass), and, given an mp_print_t* structure, one can call mp_print_str for efficiency instead of mp_printf("%s", ...). Code size is also reduced by around 200 bytes on Thumb2 archs.
2015-04-11py: Combine load_attr and store_attr type methods into one (attr).Damien George
This simplifies the API for objects and reduces code size (by around 400 bytes on Thumb2, and around 2k on x86). Performance impact was measured with Pystone score, but change was barely noticeable.
2015-04-09py: Adjust some spaces in code style/format, purely for consistency.Damien George
2015-04-07py: Implement full func arg passing for native emitter.Damien George
This patch gets full function argument passing working with native emitter. Includes named args, keyword args, default args, var args and var keyword args. Fully Python compliant. It reuses the bytecode mp_setup_code_state function to do all the hard work. This function is slightly adjusted to accommodate native calls, and the native emitter is forced a bit to emit similar prelude and code-info as bytecode.
2015-04-02py: Add finer configuration of static funcs when not in stackless mode.Damien George
Also rename call_args_t to mp_call_args_t.
2015-04-03vm: If there's no heap to call function in stackless manner, call via C stack.Paul Sokolovsky
2015-04-03vm: Initial support for calling bytecode functions w/o C stack ("stackless").Paul Sokolovsky
2015-03-20py: Allow retrieving a function's __name__.stijn
Disabled by default. Enabled on unix and stmhal ports.
2015-02-15py: Make old_globals part of mp_code_state structure.Paul Sokolovsky
Conceptually it is part of code state, so let it be allocated in the same way as the rest of state.
2015-02-13py: Implement sdiv/udiv for inline Thumb assembler.Damien George
2015-01-20py, unix: Allow to compile with -Wunused-parameter.Damien George
See issue #699.
2015-01-14py: Add "default" to switches to allow better code flow analysis.Damien George
This helps compiler produce smaller code. Saves 124 bytes on stmhal and bare-arm.
2015-01-12py: Allow to compile with -Wstrict-prototypes.Damien George
2015-01-11py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.Damien George
Previous patch c38dc3ccc76d1a9bf867704f43ea5d15da3fea7b allowed any object to be compared with any other, using pointer comparison for a fallback. As such, existing code which checked for this case is no longer needed.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-11-05py: Fix some macros defines; cleanup some includes.Damien George
2014-10-25py: Store bytecode arg names in bytecode (were in own array).Damien George
This saves a lot of RAM for 2 reasons: 1. For functions that don't have default values, var args or var kw args (which is a large number of functions in the general case), the mp_obj_fun_bc_t type now fits in 1 GC block (previously needed 2 because of the extra pointer to point to the arg_names array). So this saves 16 bytes per function (32 bytes on 64-bit machines). 2. Combining separate memory regions generally saves RAM because the unused bytes at the end of the GC block are saved for 1 of the blocks (since that block doesn't exist on its own anymore). So generally this saves 8 bytes per function. Tested by importing lots of modules: - 64-bit Linux gave about an 8% RAM saving for 86k of used RAM. - pyboard gave about a 6% RAM saving for 31k of used RAM.
2014-10-03py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.Damien George
This should pretty much resolve issue #50.
2014-09-29py: Fix types, uint -> mp_uint_t.Damien George