diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-26 18:37:06 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-26 18:37:06 +0000 |
commit | 9e6e935df0583fa761148a659181813ca532cb56 (patch) | |
tree | b54cbfb58014ac5a8d931ab6e427e46079fc97b1 /py/vm.c | |
parent | 38f0c607b0626ecee9cb2e4aefb25c3756232dab (diff) | |
download | micropython-9e6e935df0583fa761148a659181813ca532cb56.tar.gz micropython-9e6e935df0583fa761148a659181813ca532cb56.zip |
py: Add support for user-defined iterators via __iter__, __next__.
Diffstat (limited to 'py/vm.c')
-rw-r--r-- | py/vm.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -124,6 +124,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i // outer exception handling loop for (;;) { +outer_dispatch_loop: if (nlr_push(&nlr) == 0) { // If we have exception to inject, now that we finish setting up // execution context, raise it. This works as if RAISE_VARARGS @@ -642,6 +643,15 @@ unwind_return: } else { // exception occurred + // check if it's a StopIteration within a for block + if (*save_ip == MP_BC_FOR_ITER && mp_obj_is_subclass_fast(mp_obj_get_type(nlr.ret_val), &mp_type_StopIteration)) { + ip = save_ip + 1; + DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward + --sp; // pop the exhausted iterator + ip += unum; // jump to after for-block + goto outer_dispatch_loop; // continue with dispatch loop + } + // set file and line number that the exception occurred at // TODO: don't set traceback for exceptions re-raised by END_FINALLY. // But consider how to handle nested exceptions. |