Commit d9d6201b authored by Damien's avatar Damien
Browse files

py: simplify __next__ method for generators.

parent d99b0528
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "obj.h" #include "obj.h"
#include "runtime0.h" #include "runtime0.h"
#include "runtime.h" #include "runtime.h"
//#include "bc.h"
#include "map.h" #include "map.h"
#include "builtin.h" #include "builtin.h"
...@@ -293,8 +292,13 @@ mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) { ...@@ -293,8 +292,13 @@ mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) {
} }
} }
static mp_obj_t mp_builtin_next(mp_obj_t o_in) { static mp_obj_t mp_builtin_next(mp_obj_t o) {
return mp_obj_gen_instance_next(o_in); mp_obj_t ret = rt_iternext(o);
if (ret == mp_const_stop_iteration) {
nlr_jump(mp_obj_new_exception(qstr_from_str_static("StopIteration")));
} else {
return ret;
}
} }
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next);
......
...@@ -220,8 +220,6 @@ void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte ...@@ -220,8 +220,6 @@ void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte
// generator // generator
extern const mp_obj_type_t gen_instance_type; extern const mp_obj_type_t gen_instance_type;
mp_obj_t mp_obj_gen_instance_next(mp_obj_t self_in);
MP_DECLARE_CONST_FUN_OBJ(mp_obj_gen_instance_next_obj);
// class // class
extern const mp_obj_type_t class_type; extern const mp_obj_type_t class_type;
......
...@@ -117,14 +117,3 @@ mp_obj_t mp_obj_new_gen_instance(mp_obj_t state, const byte *ip, mp_obj_t *sp) { ...@@ -117,14 +117,3 @@ mp_obj_t mp_obj_new_gen_instance(mp_obj_t state, const byte *ip, mp_obj_t *sp) {
o->sp = sp; o->sp = sp;
return o; return o;
} }
mp_obj_t mp_obj_gen_instance_next(mp_obj_t self_in) {
mp_obj_t ret = rt_iternext(self_in);
if (ret == mp_const_stop_iteration) {
nlr_jump(mp_obj_new_exception(qstr_from_str_static("StopIteration")));
} else {
return ret;
}
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_obj_gen_instance_next_obj, mp_obj_gen_instance_next);
...@@ -772,7 +772,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { ...@@ -772,7 +772,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) { void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
DEBUG_OP_printf("load method %s\n", qstr_str(attr)); DEBUG_OP_printf("load method %s\n", qstr_str(attr));
if (MP_OBJ_IS_TYPE(base, &gen_instance_type) && attr == rt_q___next__) { if (MP_OBJ_IS_TYPE(base, &gen_instance_type) && attr == rt_q___next__) {
dest[1] = (mp_obj_t)&mp_obj_gen_instance_next_obj; dest[1] = (mp_obj_t)&mp_builtin_next_obj;
dest[0] = base; dest[0] = base;
return; return;
} else if (MP_OBJ_IS_TYPE(base, &instance_type)) { } else if (MP_OBJ_IS_TYPE(base, &instance_type)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment