aboutsummaryrefslogtreecommitdiff
path: root/py/emitglue.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-10-01 13:07:04 +1000
committerDamien George <damien.p.george@gmail.com>2018-10-01 13:31:11 +1000
commitcc2bd63c57a72ec37d839965c6bb61cd1fa202fc (patch)
tree44acc885421554921db85273aed4d1b1de4ecbf8 /py/emitglue.c
parent8fec6f543411dc16b42e9850af0cc3a1097162a7 (diff)
py/emitnative: Implement yield and yield-from in native emitter.
This commit adds first class support for yield and yield-from in the native emitter, including send and throw support, and yields enclosed in exception handlers (which requires pulling down the NLR stack before yielding, then rebuilding it when resuming). This has been fully tested and is working on unix x86 and x86-64, and stm32. Also basic tests have been done with the esp8266 port. Performance of existing native code is unchanged.
Diffstat (limited to 'py/emitglue.c')
-rw-r--r--py/emitglue.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/emitglue.c b/py/emitglue.c
index f99631450..064a83800 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -136,6 +136,10 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
case MP_CODE_NATIVE_PY:
case MP_CODE_NATIVE_VIPER:
fun = mp_obj_new_fun_native(def_args, def_kw_args, rc->data.u_native.fun_data, rc->data.u_native.const_table);
+ // Check for a generator function, and if so change the type of the object
+ if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) {
+ ((mp_obj_base_t*)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_gen_wrap;
+ }
break;
#endif
#if MICROPY_EMIT_INLINE_ASM