summaryrefslogtreecommitdiff
path: root/py/emitnative.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-08-13all: Raise exceptions via mp_raise_XXXJavier Candeira
- Changed: ValueError, TypeError, NotImplementedError - OSError invocations unchanged, because the corresponding utility function takes ints, not strings like the long form invocation. - OverflowError, IndexError and RuntimeError etc. not changed for now until we decide whether to add new utility functions.
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-04-22py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls.Damien George
This patch allows the following code to run without allocating on the heap: super().foo(...) Before this patch such a call would allocate a super object on the heap and then load the foo method and call it right away. The super object is only needed to perform the lookup of the method and not needed after that. This patch makes an optimisation to allocate the super object on the C stack and discard it right after use. Changes in code size due to this patch are: bare-arm: +128 minimal: +232 unix x64: +416 unix nanbox: +364 stmhal: +184 esp8266: +340 cc3200: +128
2017-03-23py: Define and use MP_OBJ_ITER_BUF_NSLOTS to get size of stack iter buf.Damien George
It improves readability of code and reduces the chance to make a mistake. This patch also fixes a bug with nan-boxing builds by rounding up the calculation of the new NSLOTS variable, giving the correct number of slots (being 4) even if mp_obj_t is larger than the native machine size.
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-15py/emitnative: Remove obsolete commented out code.Damien George
2017-03-14py/emitnative: Use assertions and mp_not_implemented correctly.Damien George
Assertions are used to check expressions that should always be true, and mp_not_implemented is used for code that can be reached.
2017-02-16py: Remove unused "use_stack" argument from for_iter_end emit function.Damien George
2017-02-16py: Optimise storage of iterator so it takes only 4 slots on Py stack.Damien George
2017-02-16py: Allow bytecode/native to put iter_buf on stack for simple for loops.Damien George
So that the "for x in it: ..." statement can now work without using the heap (so long as the iterator argument fits in an iter_buf structure).
2017-02-16py: Add iter_buf to getiter type method.Damien George
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.
2017-01-17py/emitnative: Remove assert(0)'s or replace with mp_not_implemented.Damien George
2016-12-09py: Integrate Xtensa assembler into native emitter.Damien George
The config option MICROPY_EMIT_XTENSA can now be enabled to target the Xtensa architecture with @micropython.native and @micropython.viper decorators.
2016-12-09py: Move arch-specific assembler macros from emitnative to asmXXX.h.Damien George
2016-11-28py: Factor out common code from assemblers into asmbase.[ch].Damien George
All assemblers should "derive" from mp_asm_base_t.
2016-11-10py/emitnative: Fix native import emitter when in viper mode.Damien George
2016-09-19py: Combine 3 comprehension emit functions (list/dict/set) into 1.Damien George
The 3 kinds of comprehensions are similar enough that merging their emit functions reduces code size. Decreases in code size in bytes are: bare-arm:24, minimal:96, unix(NDEBUG,x86-64):328, stmhal:80, esp8266:76.
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-04-26py/emitnative: Use MP_OBJ_NEW_SMALL_INT instead of manual bit shifting.Damien George
2016-04-07py: Implement basic with support in native emitter.Damien George
2016-04-07py: Combine continuous block of emit steps into with_cleanup emit call.Damien George
Because different emitters need to handle with-cleanup in different ways.
2016-02-15py/emitnative: Add check that RHS of viper store is of integral type.Damien George
2016-02-09py/viper: Allow uint as index to load/store, and give better error msg.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.
2015-12-10py: Make UNARY_OP_NOT a first-class op, to agree with Py not semantics.Damien George
Fixes #1684 and makes "not" match Python semantics. The code is also simplified (the separate MP_BC_NOT opcode is removed) and the patch saves 68 bytes for bare-arm/ and 52 bytes for minimal/. Previously "not x" was implemented as !mp_unary_op(x, MP_UNARY_OP_BOOL), so any given object only needs to implement MP_UNARY_OP_BOOL (and the VM had a special opcode to do the ! bit). With this patch "not x" is implemented as mp_unary_op(x, MP_UNARY_OP_NOT), but this operation is caught at the start of mp_unary_op and dispatched as !mp_obj_is_true(x). mp_obj_is_true has special logic to test for truthness, and is the correct way to handle the not operation.
2015-11-29py/emit: Change type of arg of load_const_obj from void* to mp_obj_t.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-10-14py: Fix build of ARM native emitter due to recent viper changes.Damien George
Addresses #1510.
2015-10-13py: Implement ptr32 load and store in viper emitter.Damien George
2015-10-08py/emitnative: Raise ViperTypeError for unsupported unary ops.Damien George
2015-09-23py: Slightly simplify compile and emit of star/double-star arguments.Damien George
Saves a few bytes of code space and eliminates need for rot_two bytecode (hence saving RAM and execution time, by a tiny bit).
2015-08-12py: In native ARM emitter, load r7 with table earlier in func prelude.Damien George
r7 may be needed to set up code state, so it must be loaded before the set-up function is called.
2015-07-27py: For viper compile errors, add traceback with function and filename.Damien George
ViperTypeError now includes filename and function name where the error occurred. The line number is the line number of the start of the function definition, which is the best that can be done without a lot more work. Partially addresses issue #1381.
2015-07-23py: Issue an error when compiling Viper functions with more than 4 args.Damien George
Otherwise it can be very hard to track down bugs.
2015-06-25py: Remove mp_load_const_bytes and instead load precreated bytes object.Damien George
Previous to this patch each time a bytes object was referenced a new instance (with the same data) was created. With this patch a single bytes object is created in the compiler and is loaded directly at execute time as a true constant (similar to loading bignum and float objects). This saves on allocating RAM and means that bytes objects can now be used when the memory manager is locked (eg in interrupts). The MP_BC_LOAD_CONST_BYTES bytecode was removed as part of this. Generated bytecode is slightly larger due to storing a pointer to the bytes object instead of the qstr identifier. Code size is reduced by about 60 bytes on Thumb2 architectures.
2015-06-25py: Remove mp_load_const_str and replace uses with inlined version.Damien George
2015-06-04py: Implement native multiply operation in viper emitter.Damien George
2015-06-04py: Implement implicit cast to obj for viper load/store index/value.Damien George
This allows to do "ar[i]" and "ar[i] = val" in viper when ar is a Python object and i and/or val are native viper types (eg ints). Patch also includes tests for this feature.
2015-05-08emitnative: Revamp ARM codegen compile after full-arg support refactors.Paul Sokolovsky
The code was apparently broken after 9988618e0e0f5c319e31b135d993e22efb593093 "py: Implement full func arg passing for native emitter.". This attempts to propagate those changes to ARM emitter.
2015-05-06py: Fix naming of function arguments when function is a closure.Damien George
Addresses issue #1226.
2015-04-22py/emitnative.c: Fix stack adjustment when erroring on binary op.Damien George
2015-04-20py: Make viper codegen raise proper exception (ViperTypeError) on error.Damien George
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.
2015-04-16py: Add %q format support to mp_[v]printf, and use it.Damien George
2015-04-16py: Convert occurrences of non-debug printf to mp_printf.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-06py: Implement calling functions with *args in native emitter.Damien George