summaryrefslogtreecommitdiffstatshomepage
path: root/py/objfun.c
Commit message (Collapse)AuthorAge
* py: Allow inline-assembler emitter to be generic.Damien George2016-12-09
| | | | | This patch refactors some code so that it is easier to integrate new inline assemblers for different architectures other than ARM Thumb.
* py: Specialise builtin funcs to use separate type for fixed arg count.Damien George2016-10-21
| | | | | | | | | | | | | | | 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.
* py/objfun: Use if instead of switch to check return value of VM execute.Damien George2016-09-27
| | | | It's simpler and improves code coverage.
* py/objfun: Remove unnecessary check for viper fun with 5 or more args.Damien George2016-09-27
| | | | | The native emitter/compiler restricts viper functions to 4 args, so there is no need for an extra check in the dynamic dispatch.
* py: Rename struct mp_code_state to mp_code_state_t.Damien George2016-08-27
| | | | Also at _t to mp_exc_stack pre-declaration in struct typedef.
* py/objfun: Allow inline-asm functions to be called with 4 arguments.Damien George2016-03-16
|
* py: Extend native type-sig to use 4 bits, so uint is separate to ptr.Damien George2016-02-02
| | | | | | | 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.
* py/inlineasm: Add ability to specify return type of asm_thumb funcs.Damien George2016-01-27
| | | | | | | | | | Supported return types are: object, bool, int, uint. For example: @micropython.asm_thumb def foo(r0, r1) -> uint: add(r0, r0, r1)
* py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George2016-01-11
| | | | | | | 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.
* py: Change struct and macro for builtin fun so they can be type checked.Damien George2016-01-03
|
* py/bc: Use size_t instead of mp_uint_t to count size of state and args.Damien George2015-12-17
|
* py: Fix MICROPY_STACKLESS mode to compile with MICROPY_OBJ_REPR_D.Damien George2015-12-17
|
* 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: Make mp_setup_code_state take concrete pointer for func arg.Damien George2015-11-29
|
* py: Add MICROPY_PERSISTENT_CODE so code can persist beyond the runtime.Damien George2015-11-13
| | | | | | | | | | | 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.
* py: Add constant table to bytecode.Damien George2015-11-13
| | | | | Contains just argument names at the moment but makes it easy to add arbitrary constants.
* py: Put all bytecode state (arg count, etc) in bytecode.Damien George2015-11-13
|
* py: Reorganise bytecode layout so it's more structured, easier to edit.Damien George2015-11-13
|
* py: Allow viper functions to take up to 4 arguments.Damien George2015-07-23
| | | | Addresses issue #1380.
* py: Fallback to stack alloca for Python-stack if heap alloc fails.Damien George2015-06-08
| | | | | | 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.
* 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__".
* objfun: Fix to stackless mode after recent refactor.Paul Sokolovsky2015-04-25
|
* py: Add %q format support to mp_[v]printf, and use it.Damien George2015-04-16
|
* py: Overhaul and simplify printf/pfenv mechanism.Damien George2015-04-16
| | | | | | | | | | | | | | | | | | | | | | 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.
* py: Combine load_attr and store_attr type methods into one (attr).Damien George2015-04-11
| | | | | | 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.
* py: Adjust some spaces in code style/format, purely for consistency.Damien George2015-04-09
|
* py: Implement full func arg passing for native emitter.Damien George2015-04-07
| | | | | | | | | | | 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.
* py: Add finer configuration of static funcs when not in stackless mode.Damien George2015-04-02
| | | | Also rename call_args_t to mp_call_args_t.
* vm: If there's no heap to call function in stackless manner, call via C stack.Paul Sokolovsky2015-04-03
|
* vm: Initial support for calling bytecode functions w/o C stack ("stackless").Paul Sokolovsky2015-04-03
|
* py: Allow retrieving a function's __name__.stijn2015-03-20
| | | | Disabled by default. Enabled on unix and stmhal ports.
* py: Make old_globals part of mp_code_state structure.Paul Sokolovsky2015-02-15
| | | | | Conceptually it is part of code state, so let it be allocated in the same way as the rest of state.
* py: Implement sdiv/udiv for inline Thumb assembler.Damien George2015-02-13
|
* py, unix: Allow to compile with -Wunused-parameter.Damien George2015-01-20
| | | | See issue #699.
* py: Add "default" to switches to allow better code flow analysis.Damien George2015-01-14
| | | | | This helps compiler produce smaller code. Saves 124 bytes on stmhal and bare-arm.
* py: Allow to compile with -Wstrict-prototypes.Damien George2015-01-12
|
* py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.Damien George2015-01-11
| | | | | | | 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.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Fix some macros defines; cleanup some includes.Damien George2014-11-05
|
* py: Store bytecode arg names in bytecode (were in own array).Damien George2014-10-25
| | | | | | | | | | | | | | | | | | | | 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.
* py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.Damien George2014-10-03
| | | | This should pretty much resolve issue #50.
* py: Fix types, uint -> mp_uint_t.Damien George2014-09-29
|
* stmhal: Initialise stack pointer correctly.Damien George2014-09-23
| | | | | | | | | | | | | Stack is full descending and must be 8-byte aligned. It must start off pointing to just above the last byte of RAM. Previously, stack started pointed to last byte of RAM (eg 0x2001ffff) and so was not 8-byte aligned. This caused a bug in combination with alloca. This patch also updates some debug printing code. Addresses issue #872 (among many other undiscovered issues).
* py: Use variable length encoded uints in more places in bytecode.Damien George2014-09-04
| | | | | | Code-info size, block name, source name, n_state and n_exc_stack now use variable length encoded uints. This saves 7-9 bytes per bytecode function for most functions.
* Change some parts of the core API to use mp_uint_t instead of uint/int.Damien George2014-08-30
| | | | Addressing issue #50, still some way to go yet.
* py: Fix bug where GC collected native/viper/asm function data.Damien George2014-08-24
| | | | | | | | Because (for Thumb) a function pointer has the LSB set, pointers to dynamic functions in RAM (eg native, viper or asm functions) were not being traced by the GC. This patch is a comprehensive fix for this. Addresses issue #820.
* py: Viper can now store to global.Damien George2014-08-15
|
* py: Allow viper to have type annotations.Damien George2014-08-15
| | | | | | | | | Viper functions can now be annotated with the type of their arguments and return value. Eg: @micropython.viper def f(x:int) -> int: return x + 1
* Rename machine_(u)int_t to mp_(u)int_t.Damien George2014-07-03
| | | | See discussion in issue #50.
* stackctrl: Add "mp_" prefix.Paul Sokolovsky2014-07-01
|