py: simplify __next__ method for generators.
This commit is contained in:
parent
d99b05282d
commit
d9d6201b52
10
py/builtin.c
10
py/builtin.c
@ -11,7 +11,6 @@
|
||||
#include "obj.h"
|
||||
#include "runtime0.h"
|
||||
#include "runtime.h"
|
||||
//#include "bc.h"
|
||||
#include "map.h"
|
||||
#include "builtin.h"
|
||||
|
||||
@ -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) {
|
||||
return mp_obj_gen_instance_next(o_in);
|
||||
static mp_obj_t mp_builtin_next(mp_obj_t o) {
|
||||
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);
|
||||
|
2
py/obj.h
2
py/obj.h
@ -220,8 +220,6 @@ void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte
|
||||
|
||||
// generator
|
||||
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
|
||||
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) {
|
||||
o->sp = sp;
|
||||
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) {
|
||||
void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
|
||||
DEBUG_OP_printf("load method %s\n", qstr_str(attr));
|
||||
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;
|
||||
return;
|
||||
} else if (MP_OBJ_IS_TYPE(base, &instance_type)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user