diff options
author | Damien George <damien@micropython.org> | 2021-06-29 17:34:34 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-07-15 00:12:41 +1000 |
commit | bb00125aaac8376b8cc4c8f3da2423fcf6dae496 (patch) | |
tree | 7a0d5f4de325776418beb96d9f27e46c5793597c /py/runtime.h | |
parent | e3825e28e61561427fd5811c1167e05ee3372eb4 (diff) |
py: Support single argument to optimised MP_OBJ_STOP_ITERATION.
The MP_OBJ_STOP_ITERATION optimisation is a shortcut for creating a
StopIteration() exception object, and means that heap memory does not need
to be allocated for the exception (in cases where it can be used). This
commit allows this optimised object to take an optional argument (before,
it could only have no argument).
The commit also adds some new tests to cover corner cases with
StopIteration and generators that previously did not work.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/runtime.h')
-rw-r--r-- | py/runtime.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/runtime.h b/py/runtime.h index 7d2cb94e8..8484479a5 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -154,6 +154,11 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_STOP_ITERATIO mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_STOP_ITERATION instead of raising StopIteration(...) mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val); +static inline mp_obj_t mp_make_stop_iteration(mp_obj_t o) { + MP_STATE_THREAD(stop_iteration_arg) = o; + return MP_OBJ_STOP_ITERATION; +} + mp_obj_t mp_make_raise_obj(mp_obj_t o); mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level); @@ -179,6 +184,7 @@ NORETURN void mp_raise_TypeError(mp_rom_error_text_t msg); NORETURN void mp_raise_NotImplementedError(mp_rom_error_text_t msg); #endif +NORETURN void mp_raise_StopIteration(mp_obj_t arg); NORETURN void mp_raise_OSError(int errno_); NORETURN void mp_raise_recursion_depth(void); |