summaryrefslogtreecommitdiff
path: root/py/vm.c
AgeCommit message (Collapse)Author
2015-09-01vm: Handle "raise X from Y" statements the best way we can.Paul Sokolovsky
By issuing a warning that exception chaining is not supported, and ignoring "from Y" argument.
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-13py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin.Damien George
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-05-11vm: Properly handle StopIteration raised in user instance iterator.Paul Sokolovsky
I.e. in bytecode Python functions.
2015-05-10vm: Null pointer test when checking for StopIteration optimizations.Paul Sokolovsky
When generator raises exception, it is automatically terminated (by setting its code_state.ip to 0), which interferes with this check. Triggered in particular by CPython's test_pep380.py.
2015-05-05py: Remove LOAD_CONST_ELLIPSIS bytecode, use LOAD_CONST_OBJ instead.Damien George
Ellipsis constant is rarely used so no point having an extra bytecode for it.
2015-04-26vm: On exiting except block, clear sys.exc_info() value.Paul Sokolovsky
This doesn't handle case fo enclosed except blocks, but once again, sys.exc_info() support is a workaround for software which uses it instead of properly catching exceptions via variable in except clause.
2015-04-25modsys: Add basic sys.exc_info() implementation.Paul Sokolovsky
The implementation is very basic and non-compliant and provided solely for CPython compatibility. The function itself is bad Python2 heritage, its usage is discouraged.
2015-04-24py: Modify bytecode "with" behaviour so it doesn't use any heap.Damien George
Before this patch a "with" block needed to create a bound method object on the heap for the __exit__ call. Now it doesn't because we use load_method instead of load_attr, and save the method+self on the stack.
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-09py: Fix msvc warning '*/ found outside of comment'stijn
Also prevents some of the weaker syntax parsers out there treating the whole '*/*const*/' part as a comment
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: Support strict stackless mode, with proper exception reporting.Paul Sokolovsky
I.e. in this mode, C stack will never be used to call a Python function, but if there's no free heap for a call, it will be reported as RuntimeError (as expected), not MemoryError.
2015-04-03vm: Implement stackless for CALL_FUNCTION_VAR_KW & CALL_METHOD_VAR_KW.Paul Sokolovsky
2015-04-03vm: Stackless support for MP_BC_CALL_METHOD.Paul Sokolovsky
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-26py: Add optional support for descriptors' __get__ and __set__ methods.stijn
Disabled by default. Enabled on unix and windows ports.
2015-03-25py: Clean up some logic in VM to remove assert(0)'s.Damien George
Saves around 30 bytes code on Thumb2 archs.
2015-02-26py: Small optimisation of logic flow in BC_WITH_CLEANUP bytecode.Damien George
Slightly smaller code, and does not need to use C stack to save temporaries.
2015-02-10py: Reuse value stack in VM WITH_CLEANUP opcode to reduce C-stack size.Damien George
Saves 8 bytes C-stack on stmhal and 16 bytes on unix x86.
2015-02-08py: Parse big-int/float/imag constants directly in parser.Damien George
Previous to this patch, a big-int, float or imag constant was interned (made into a qstr) and then parsed at runtime to create an object each time it was needed. This is wasteful in RAM and not efficient. Now, these constants are parsed straight away in the parser and turned into objects. This allows constants with large numbers of digits (so addresses issue #1103) and takes us a step closer to #722.
2015-01-13py: Add load_const_obj to emitter, add LOAD_CONST_OBJ to bytecode.Damien George
This allows to directly load a Python object to the Python stack. See issue #722 for background.
2015-01-07py: Add option to cache map lookup results in bytecode.Damien George
This is a simple optimisation inspired by JITing technology: we cache in the bytecode (using 1 byte) the offset of the last successful lookup in a map. This allows us next time round to check in that location in the hash table (mp_map_t) for the desired entry, and if it's there use that entry straight away. Otherwise fallback to a normal map lookup. Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes. On a few tests it gives >90% cache hit and greatly improves speed of code. Disabled by default. Enabled for unix and stmhal ports.
2015-01-07py: Put all global state together in state structures.Damien George
This patch consolidates all global variables in py/ core into one place, in a global structure. Root pointers are all located together to make GC tracing easier and more efficient.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-29py: In VM, for selective ip saving, store 1 byte past last opcode.Damien George
This is for efficiency, so we don't need to subtract 1 from the ip before storing it to code_state->ip. It saves a lot of ROM bytes on unix and stmhal.
2014-12-28vm: Record exception ip only for instructions where exceptions may happen.Paul Sokolovsky
Mirroring ip to a volatile memory variable for each opcode is an expensive operation. For quite a lot of often executed opcodes like stack manipulation or jumps, exceptions cannot actually happen. So, record ip only for opcode where that's possible.
2014-12-22py: Reduce size of VM exception stack element by 1 machine word.Damien George
This optimisation reduces the VM exception stack element (mp_exc_stack_t) by 1 word, by using bit 1 of a pointer to store whether the opcode was a FINALLY or WITH opcode. This optimisation was pending, waiting for maturity of the exception handling code, which has now proven itself. Saves 1 machine word RAM for each exception (4->3 words per exception). Increases stmhal code by 4 bytes, and decreases unix x64 code by 32 bytes.
2014-12-12py: Fix label printing in showbc; print sp in vm trace.Damien George
2014-12-02py, vm: Make unum a local variable for each opcode that uses it.Damien George
This makes no change to the generated code, but it's now easier to understand since unum is not a "global" variable anymore.
2014-10-26py: Fix VM dispatch following a pending exception check.Damien George
2014-10-25py: Add mp_pending_exception global variable, for VM soft interrupt.Damien George
This allows to implement KeyboardInterrupt on unix, and a much safer ctrl-C in stmhal port. First ctrl-C is a soft one, with hope that VM will notice it; second ctrl-C is a hard one that kills anything (for both unix and stmhal). One needs to check for a pending exception in the VM only for jump opcodes. Others can't produce an infinite loop (infinite recursion is caught by stack check).
2014-10-25py: Compress load-int, load-fast, store-fast, unop, binop bytecodes.Damien George
There is a lot potential in compress bytecodes and make more use of the coding space. This patch introduces "multi" bytecodes which have their argument included in the bytecode (by addition). UNARY_OP and BINARY_OP now no longer take a 1 byte argument for the opcode. Rather, the opcode is included in the first byte itself. LOAD_FAST_[0,1,2] and STORE_FAST_[0,1,2] are removed in favour of their multi versions, which can take an argument between 0 and 15 inclusive. The majority of LOAD_FAST/STORE_FAST codes fit in this range and so this saves a byte for each of these. LOAD_CONST_SMALL_INT_MULTI is used to load small ints between -16 and 47 inclusive. Such ints are quite common and now only need 1 byte to store, and now have much faster decoding. In all this patch saves about 2% RAM for typically bytecode (1.8% on 64-bit test, 2.5% on pyboard test). It also reduces the binary size (because bytecodes are simplified) and doesn't harm performance.
2014-09-04py: Use variable length encoded uints in more places in bytecode.Damien George
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.
2014-08-26py: Fix line number printing for file with 1 line.Damien George
With a file with 1 line (and an error on that line), used to show the line as number 0. Now shows it correctly as line number 1. But, when line numbers are disabled, it now prints line number 1 for any line that has an error (instead of 0 as previously). This might end up being confusing, but requires extra RAM and/or hack logic to make it print something special in the case of no line numbers.
2014-07-31py: Improve encoding scheme for line-number to bytecode map.Damien George
Reduces by about a factor of 10 on average the amount of RAM needed to store the line-number to bytecode map in the bytecode prelude. Using CPython3.4's stdlib for statistics: previously, an average of 13 bytes were used per (bytecode offset, line-number offset) pair, and now with this improvement, that's down to 1.3 bytes on average. Large RAM usage before was due to some very large steps in line numbers, both from the start of the first line in a function way down in the file, and also functions that have big comments and/or big strings in them (both cases were significant). Although the savings are large on average for the CPython stdlib, it won't have such a big effect for small scripts used in embedded programming. Addresses issue #648.
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-08Merge branch 'alloca' of github.com:marcusva/micropython into marcusva-allocaDamien George
2014-06-07py: Merge mp_execute_bytecode into fun_bc_call.Damien George
This reduces stack usage by 16 words (64 bytes) for stmhal/ port. See issue #640.
2014-06-07- FreeBSD provides alloca() via stdlib.h, in contrast to Linux and WindowsMarcus von Appen
- Move the includes for alloca() intp mpconfigport.h
2014-06-03vm: If there's no lineno info, set lineno in traceback to 0, not 1.Paul Sokolovsky
To clearly signify that lineno is not known.
2014-06-01py: Add option to disable set() object (enabled by default).Damien George
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-06-01py, vm: Replace save_ip, save_sp with code_state->{ip, sp}.Damien George
This may seem a bit of a risky change, in that it may introduce crazy bugs with respect to volatile variables in the VM loop. But, I think it should be fine: code_state points to some external memory, so the compiler should always read/write to that memory when accessing the ip/sp variables (ie not put them in registers). Anyway, it passes all tests and improves on all efficiency fronts: about 2-4% faster (64-bit unix), 16 bytes less stack space per call (64-bit unix) and slightly less executable size (unix and stmhal). The reason it's more efficient is save_ip and save_sp were volatile variables, so were anyway stored on the stack (in memory, not regs). Thus converting them to code_state->{ip, sp} doesn't cost an extra memory dereference (except maybe to get code_state, but that can be put in a register and then made more efficient for other uses of it).
2014-06-01Merge branch 'vm-alloca' of github.com:pfalcon/micropython into ↵Damien George
pfalcon-vm-alloca Conflicts: py/vm.c Fixed stack underflow check. Use UINT_FMT/INT_FMT where necessary. Specify maximum VM-stack byte size by multiple of machine word size, so that on 64 bit machines it has same functionality as 32 bit.
2014-05-31py: Fix stack underflow with optimised for loop.Damien George