diff options
author | Damien George <damien.p.george@gmail.com> | 2016-01-09 23:59:52 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-02-16 18:38:06 +1100 |
commit | f4df3aaa72a0460614b1ab8b7b8a7927a1165e31 (patch) | |
tree | 2c1ee2988630c79a4e79e40a15173af588d8fd2c /py/vm.c | |
parent | ae8d86758631e62466a55d179897d2111c3cb1c1 (diff) | |
download | micropython-f4df3aaa72a0460614b1ab8b7b8a7927a1165e31.tar.gz micropython-f4df3aaa72a0460614b1ab8b7b8a7927a1165e31.zip |
py: Allow bytecode/native to put iter_buf on stack for simple for loops.
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).
Diffstat (limited to 'py/vm.c')
-rw-r--r-- | py/vm.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -681,7 +681,9 @@ unwind_jump:; } ip = (const byte*)MP_OBJ_TO_PTR(POP()); // pop destination ip for jump if (unum != 0) { + // pop iter and iter_buf sp--; + sp -= sizeof(mp_obj_iter_buf_t) / sizeof(mp_obj_t); } DISPATCH_WITH_PEND_EXC_CHECK(); } @@ -726,6 +728,15 @@ unwind_jump:; SET_TOP(mp_getiter(TOP(), NULL)); DISPATCH(); + ENTRY(MP_BC_GET_ITER_STACK): { + MARK_EXC_IP_SELECTIVE(); + mp_obj_t obj = TOP(); + mp_obj_iter_buf_t *iter_buf = (mp_obj_iter_buf_t*)sp; + sp += sizeof(mp_obj_iter_buf_t) / sizeof(mp_obj_t); + SET_TOP(mp_getiter(obj, iter_buf)); + DISPATCH(); + } + ENTRY(MP_BC_FOR_ITER): { MARK_EXC_IP_SELECTIVE(); DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward |