summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
Commit message (Collapse)AuthorAge
* Merge branch 'alloca' of github.com:marcusva/micropython into marcusva-allocaDamien George2014-06-08
|\
| * - FreeBSD provides alloca() via stdlib.h, in contrast to Linux and WindowsMarcus von Appen2014-06-07
| | | | | | | | - Move the includes for alloca() intp mpconfigport.h
* | py: Merge mp_execute_bytecode into fun_bc_call.Damien George2014-06-07
|/ | | | | | This reduces stack usage by 16 words (64 bytes) for stmhal/ port. See issue #640.
* vm: If there's no lineno info, set lineno in traceback to 0, not 1.Paul Sokolovsky2014-06-03
| | | | To clearly signify that lineno is not known.
* py: Add option to disable set() object (enabled by default).Damien George2014-06-01
|
* Rename bultins config variables to MICROPY_PY_BUILTINS_*.Damien George2014-06-01
| | | | | | | | | | 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.
* py, vm: Replace save_ip, save_sp with code_state->{ip, sp}.Damien George2014-06-01
| | | | | | | | | | | | | | | | | | 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).
* Merge branch 'vm-alloca' of github.com:pfalcon/micropython into ↵Damien George2014-06-01
|\ | | | | | | | | | | | | | | | | | | | | 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.
| * vm: Factor out structure with code execution state and pass it around.Paul Sokolovsky2014-05-31
| | | | | | | | | | | | | | This improves stack usage in callers to mp_execute_bytecode2, and is step forward towards unifying execution interface for function and generators (which is important because generators don't even support full forms of arguments passing (keywords, etc.)).
| * vm: Don't unconditionally allocate state on stack, do that only if needed.Paul Sokolovsky2014-05-31
| | | | | | | | | | This makes sure that only as much stack allocated as actually used, reducing stack usage for each Python function call.
* | py: Fix stack underflow with optimised for loop.Damien George2014-05-31
|/
* vm: Detect stack underflow in addition to overflow.Paul Sokolovsky2014-05-31
|
* py: Reformat few long functions argument lists for clarity.Paul Sokolovsky2014-05-31
|
* py: Fix break from within a for loop.Damien George2014-05-30
| | | | | | | Needed to pop the iterator object when breaking out of a for loop. Need also to be careful to unwind exception handler before popping iterator. Addresses issue #635.
* py: Implement long int parsing in int(...).Damien George2014-05-28
| | | | Addresses issue #627.
* py, vm: Where possible, make variables local to each opcode.Damien George2014-05-25
| | | | | | | | | This helps the compiler do its optimisation, makes it clear which variables are local per opcode and which global, and makes it consistent when extra variables are needed in an opcode (in addition to old obj1, obj2 pair, for example). Could also make unum local, but that's for another time.
* objslice: Support arbitrary objects start, stop, and step.Paul Sokolovsky2014-05-25
| | | | | Older int-only encoding is not expressive enough to support arbitrary slice assignment operations.
* Rename configuration variables controling Python features.Damien George2014-05-24
| | | | Now of the form MICROPY_PY_*. See issue #35.
* Tidy up some configuration options.Damien George2014-05-21
| | | | | | | | | | MP_ALLOC_* -> MICROPY_ALLOC_* MICROPY_PATH_MAX -> MICROPY_ALLOC_PATH_MAX MICROPY_ENABLE_REPL_HELPERS -> MICROPY_HELPER_REPL MICROPY_ENABLE_LEXER_UNIX -> MICROPY_HELPER_LEXER_UNIX MICROPY_EXTRA_* -> MICROPY_PORT_* See issue #35.
* py, unix: Add copyright for modules I worked closely on.Paul Sokolovsky2014-05-13
|
* py: Don't expect that type->getiter() always returns iterator, check for NULL.Paul Sokolovsky2014-05-11
| | | | This is better than forcing each getiter() implementation to raise exception.
* py: Rename byte_code to bytecode everywhere.Damien George2014-05-10
| | | | bytecode is the more widely used. See issue #590.
* py: Improve native emitter; now supports more opcodes.Damien George2014-05-07
|
* Add license header to (almost) all files.Damien George2014-05-03
| | | | | | | 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/.
* py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky2014-05-02
| | | | Specifically, nlr.h does.
* py: Remove unnecessary LOAD_CONST_ID bytecode.Damien George2014-04-27
| | | | It's the same as LOAD_CONST_STR.
* py: Eliminate 'op' variable in VM dispatch loop.Damien George2014-04-27
| | | | | Remembering the last op is rarely needed, and when it is, can simply use *save_ip.
* py, vm: Fix recent bug where state is freed too early.Damien George2014-04-24
|
* py, vm: Free heap-allocated state if it was allocated on the heap.Damien George2014-04-24
|
* vm: Add rudimentary bytecode execution tracing capability.Paul Sokolovsky2014-04-23
|
* py: Wrap #if's around emitter functions that are used only by emitcpy.Damien George2014-04-20
| | | | | | | 3 emitter functions are needed only for emitcpy, and so we can #if them out when compiling with emitcpy support. Also remove unused SETUP_LOOP bytecode.
* py: Making closures now passes pointer to stack, not a tuple for vars.Damien George2014-04-20
| | | | | | | Closed over variables are now passed on the stack, instead of creating a tuple and passing that. This way memory for the closed over variables can be allocated within the closure object itself. See issue #510 for background.
* py: Rename USE_COMPUTED_GOTOS to USE_COMPUTED_GOTO and enable on stmhal.Damien George2014-04-17
| | | | | | On stmhal, computed gotos make the binary about 1k bigger, but makes it run faster, and we have the room, so why not. All tests pass on pyboard using computed gotos.
* py: Add MP_OBJ_STOP_ITERATION and make good use of it.Damien George2014-04-17
| | | | | Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL. This helps a lot in debugging and understanding of function API.
* py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.Damien George2014-04-17
| | | | mp_obj_t->subscr now does load/store/delete.
* py: Tidy up variables in VM, probably fixes subtle bugs.Damien George2014-04-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Things get tricky when using the nlr code to catch exceptions. Need to ensure that the variables (stack layout) in the exception handler are the same as in the bit protected by the exception handler. Prior to this patch there were a few bugs. 1) The constant mp_const_MemoryError_obj was being preloaded to a specific location on the stack at the start of the function. But this location on the stack was being overwritten in the opcode loop (since it didn't think that variable would ever be referenced again), and so when an exception occurred, the variable holding the address of MemoryError was corrupt. 2) The FOR_ITER opcode detection in the exception handler used sp, which may or may not contain the right value coming out of the main opcode loop. With this patch there is a clear separation of variables used in the opcode loop and in the exception handler (should fix issue (2) above). Furthermore, nlr_raise is no longer used in the opcode loop. Instead, it jumps directly into the exception handler. This tells the C compiler more about the possible code flow, and means that it should have the same stack layout for the exception handler. This should fix issue (1) above. Indeed, the generated (ARM) assembler has been checked explicitly, and with 'goto exception_handler', the problem with &MemoryError is fixed. This may now fix problems with rge-sm, and probably many other subtle bugs yet to show themselves. Incidentally, rge-sm now passes on pyboard (with a reduced range of integration)! Main lesson: nlr is tricky. Don't use nlr_push unless you know what you are doing! Luckily, it's not used in many places. Using nlr_raise/jump is fine.
* Rename header file.AZ Huang2014-04-15
|
* Move entry_table to separated header file.AZ Huang2014-04-15
|
* Make USE_COMPUTED_GOTO a config option in mpconfig.h.Damien George2014-04-14
| | | | Disabled by default. Enabled in unix port.
* Use computed goto instead of switching op-codes.AZ Huang2014-04-15
|
* py: Remove unique_codes from emitglue.c. Replace with pointers.Damien George2014-04-13
| | | | | | | | | | | | | | | | Attempt to address issue #386. unique_code_id's have been removed and replaced with a pointer to the "raw code" information. This pointer is stored in the actual byte code (aligned, so the GC can trace it), so that raw code (ie byte code, native code and inline assembler) is kept only for as long as it is needed. In memory it's now like a tree: the outer module's byte code points directly to its children's raw code. So when the outer code gets freed, if there are no remaining functions that need the raw code, then the children's code gets freed as well. This is pretty much like CPython does it, except that CPython stores indexes in the byte code rather than machine pointers. These indices index the per-function constant table in order to find the relevant code.
* py: Make all LOAD_FAST ops check for unbound local.Damien George2014-04-12
| | | | | | | | This is necessary to catch all cases where locals are referenced before assignment. We still keep the _0, _1, _2 versions of LOAD_FAST to help reduced the byte code size in RAM. Addresses issue #457.
* py: Change compile order for default positional and keyword args.Damien George2014-04-11
| | | | | | | | | | | This simplifies the compiler a little, since now it can do 1 pass over a function declaration, to determine default arguments. I would have done this originally, but CPython 3.3 somehow had the default keyword args compiled before the default position args (even though they appear in the other order in the text of the script), and I thought it was important to have the same order of execution when evaluating default arguments. CPython 3.4 has changed the order to the more obvious one, so we can also change.
* py: Fix VM stack overflow detection.Damien George2014-04-10
|
* py: Add option to VM to detect stack overflow.Damien George2014-04-10
|
* py: Clear state to MP_OBJ_NULL before executing byte code.Damien George2014-04-09
|
* py: Properly implement deletion of locals and derefs, and detect errors.Damien George2014-04-09
| | | | | Needed to reinstate 2 delete opcodes, to specifically check that a local is not deleted twice.
* py: Remove DELETE_SUBSCR opcode, combine with STORE_SUBSCR.Damien George2014-04-08
| | | | | This makes the runtime and object APIs more consistent. mp_store_subscr functionality now moved into objects (ie list and dict store_item).
* py: Finish implementation of all del opcodes.Damien George2014-04-08
| | | | | | | At this point, all opcodes are now implemented! Some del opcodes have been combined with store opcodes, with the value to store being MP_OBJ_NULL.
* py: implement UNPACK_EX byte code (for: a, *b, c = d)Damien George2014-04-08
|