Commit Graph

59 Commits

Author SHA1 Message Date
Damien George 9aa2a527b5 py: Tidy up BINARY_OPs; negation done by special NOT bytecode.
IS_NOT and NOT_IN are now compiled to IS + NOT and IN + NOT, with a new
special NOT bytecode.
2014-02-01 23:04:09 +00:00
Damien George cbddb279bb py: Implement break/continue from an exception with finally.
Still todo: break/continue from within the finally block itself.
2014-02-01 20:08:18 +00:00
Damien George fb083ea986 py: mp_execute_byte_code has 2 arg arrays, for more efficient default params. 2014-02-01 18:29:40 +00:00
Damien George 87413a4d0c Merge branch 'fun-defargs' of github.com:pfalcon/micropython into pfalcon-fun-defargs 2014-02-01 17:51:47 +00:00
Paul Sokolovsky 90750029df Implement default function arguments (for Python functions).
TODO: Decide if we really need separate bytecode for creating functions
with default arguments - we would need same for closures, then there're
keywords arguments too. Having all combinations is a small exponential
explosion, likely we need just 2 cases - simplest (no defaults, no kw),
and full - defaults & kw.
2014-02-01 15:38:22 +02:00
Paul Sokolovsky 6472dea146 Add exception stack unwind support for RETURN_VALUE.
This properly implements return from try/finally block(s).

TODO: Consider if we need to do any value stack unwinding for RETURN_VALUE
case. Intuitively, this is "success" return, so value stack should be in
good shape, and unwinding shouldn't be required.
2014-02-01 15:23:03 +02:00
Paul Sokolovsky 8519342c1a Update VM stacks comments. 2014-01-31 19:48:53 +02:00
Paul Sokolovsky c7a0b14df9 vm: Introduce structure for exception stack entry, record entry type.
Also, handle SETUP_FINALLY opcode.
2014-01-31 19:48:53 +02:00
Paul Sokolovsky 382e8eeea2 vm: Add basic implementation of END_FINALLY opcode.
Allows to have nested try blocks with except filters.

TODO: Don't add END_FINALLY's exception re-raise points to traceback.
2014-01-30 13:49:18 +02:00
Damien George d0691ccaec py: Simplify fastn in VM; reduce size of unique code struct.
We still have FAST_[0,1,2] byte codes, but they now just access the
fastn array (before they had special local variables).  It's now
simpler, a bit faster, and uses a bit less stack space (on STM at least,
which is most important).

The only reason now to keep FAST_[0,1,2] byte codes is for compressed
byte code size.
2014-01-29 20:30:52 +00:00
Damien George 08d075592f py: Fix bug with LOAD_METHOD; fix int->machine_int_t for small int.
LOAD_METHOD bug was: emitbc did not correctly calculate the amount of
stack usage for a LOAD_METHOD operation.

small int bug was: int was being used to pass small ints, when it should
have been machine_int_t.
2014-01-29 18:58:52 +00:00
Paul Sokolovsky bf38e2a03a Implement send() method for generators. 2014-01-26 20:56:08 +02:00
Damien George 28eb57786d py: Optimise generated code for working out line numbers. 2014-01-25 11:43:20 +00:00
Paul Sokolovsky 91fb1c9b13 Add basic implementation of bytes type, piggybacking on str.
This reuses as much str implementation as possible, from this we
can make them more separate as needed.
2014-01-24 22:56:26 +02:00
Damien George 600ae734cf py: Implement break and continue byte codes, and add tests.
Also fixes a bug in the for-in-range optimiser.

I hope to remove break and continue byte codes in the future and just
use jump (if possible).
2014-01-21 23:48:04 +00:00
Damien George 55baff4c9b Revamp qstrs: they now include length and hash.
Can now have null bytes in strings.  Can define ROM qstrs per port using
qstrdefsport.h
2014-01-21 21:40:13 +00:00
Damien George 136b149e41 py: Add full traceback to exception printing. 2014-01-19 12:38:49 +00:00
Damien George cbd2f7482c py: Add module/function/class name to exceptions.
Exceptions know source file, line and block name.

Also tidy up some debug printing functions and provide a global
flag to enable/disable them.
2014-01-19 11:48:48 +00:00
Damien George e02b2d4391 py: Temporary fix for bug where not enough VM state is allocated. 2014-01-19 01:14:37 +00:00
Damien George 932bf1c48f py: Fix VM/runtime unpack sequence bug, Issue #193. 2014-01-18 23:42:49 +00:00
Damien George 08335004cf Add source file name and line number to error messages.
Byte code has a map from byte-code offset to source-code line number,
used to give better error messages.
2014-01-18 23:24:36 +00:00
Damien George 20006dbba9 Make VM stack grow upwards, and so no reversed args arrays.
Change state layout in VM so the stack starts at state[0] and grows
upwards.  Locals are at the top end of the state and number downwards.
This cleans up a lot of the interface connecting the VM to C: now all
functions that take an array of Micro Python objects are in order (ie no
longer in reverse).

Also clean up C API with keyword arguments (call_n and call_n_kw
replaced with single call method that takes keyword arguments).  And now
make_new takes keyword arguments.

emitnative.c has not yet been changed to comply with the new order of
stack layout.
2014-01-18 14:10:48 +00:00
Paul Sokolovsky a9f5abd48c Implement LOAD_CONST_INT (by dispatching to int object implementation). 2014-01-17 20:05:10 +02:00
John R. Lenton 5c76839559 sorted 2014-01-13 05:12:50 +00:00
Damien George 8d4ccc49ed Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-11 09:37:41 +00:00
Damien George 25042b19d2 py: Make arg to MP_BC_RAISE_VARARGS a byte. 2014-01-11 09:33:39 +00:00
John R. Lenton b8698fca75 unified the bops 2014-01-11 00:58:59 +00:00
Paul Sokolovsky 5388a3c29a Crude attempt to implement RAISE_VARARGS (with args=1 so far only). 2014-01-11 00:55:08 +02:00
Paul Sokolovsky e5ee1693ad Use constructor to create small int (avoid exposing mp_obj_t internals to VM). 2014-01-06 17:54:16 +02:00
Damien George e9906ac3d7 Add ellipsis object. 2014-01-04 18:44:46 +00:00
Paul Sokolovsky e606cb6561 slice: Allow building with MICROPY_ENABLE_SLICE=0. 2014-01-04 02:35:49 +02:00
Paul Sokolovsky ded0a1efa5 Implement BUILD_SLICE opcode (2-arg version). 2014-01-04 02:35:48 +02:00
Damien George 66327006fc py: change negative array indices with array - 1. 2014-01-02 18:20:41 +00:00
Paul Sokolovsky bdf822b3d8 Add quick impl for MP_BC_LOAD_CONST_BYTES which just creates qstr so far.
This is based on the fact that qstr so far behaves more like byte string
than like Unicode string (for example, "012"[0] returns 48 (int)).
2014-01-02 18:51:19 +02:00
Damien George 6baf76e28b py: make closures work. 2013-12-30 22:32:17 +00:00
Damien 02a7c41e76 py: implement POP_BLOCK in VM. 2013-12-29 18:48:37 +00:00
Damien b86e3f9293 py: implement some basic exception matching. 2013-12-29 17:17:43 +00:00
Damien 8f9e2ee157 Add code in VM to handle nested exceptions correctly. 2013-12-29 16:54:59 +00:00
Damien d99b05282d Change object representation from 1 big union to individual structs.
A big change.  Micro Python objects are allocated as individual structs
with the first element being a pointer to the type information (which
is itself an object).  This scheme follows CPython.  Much more flexible,
not necessarily slower, uses same heap memory, and can allocate objects
statically.

Also change name prefix, from py_ to mp_ (mp for Micro Python).
2013-12-21 18:17:45 +00:00
Damien 660365e14c py: split runtime into map, obj, builtin. 2013-12-17 18:27:24 +00:00
Damien 9ecbcfff99 py: work towards working closures. 2013-12-11 00:41:43 +00:00
Damien db4c361f1c py: add skeletal import functionality. 2013-12-10 17:27:24 +00:00
Damien 6f3e7fc505 py: add UNPACK_SEQUENCE and keyword methods to VM. 2013-11-26 15:15:50 +00:00
Damien 94658e2e25 Add JUMP_IF_x_OR_POP opcodes to VM. 2013-11-09 20:12:32 +00:00
Damien 40fdfe3000 Improve allocation of stack for byte code. 2013-11-05 22:16:22 +00:00
Damien 03c9cfb015 Make byte code jumps relative. 2013-11-05 22:06:08 +00:00
Damien 6addc89e55 Byte code for SMALL_INT uses 3 bytes for integer. 2013-11-04 23:04:50 +00:00
Damien 7410e440ab Add basic complex number support. 2013-11-02 19:47:57 +00:00
Damien 4ebb32fb95 Implement: str.join, more float support, ROT_TWO in VM. 2013-11-02 14:33:10 +00:00
Damien c12aa468a1 Add SET_ADD opcode to VM. 2013-10-16 20:57:49 +01:00