From db283d4ba6c6813ea89c0ab865cb13f5307e4c61 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 27 May 2023 19:59:17 +0800 Subject: [PATCH] ... --- src/ceval.h | 36 ++++++++++++++++++++---------------- src/pocketpy.h | 10 +++++----- src/vm.h | 6 +++--- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/ceval.h b/src/ceval.h index 1d5e639c..2242f751 100644 --- a/src/ceval.h +++ b/src/ceval.h @@ -471,7 +471,7 @@ __NEXT_STEP:; TOP() = py_iter(TOP()); DISPATCH(); TARGET(FOR_ITER) - _0 = PyIterNext(TOP()); + _0 = py_next(TOP()); if(_0 != StopIteration){ PUSH(_0); }else{ @@ -493,35 +493,39 @@ __NEXT_STEP:; frame->f_globals()._try_perfect_rehash(); DISPATCH(); /*****************************************/ - TARGET(UNPACK_SEQUENCE) + TARGET(UNPACK_SEQUENCE){ + auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!! + _0 = py_iter(POPX()); + for(int i=0; ibind_builtin_func<1>("next", [](VM* vm, ArgsView args) { - return vm->PyIterNext(args[0]); + return vm->py_next(args[0]); }); _vm->bind_builtin_func<1>("dir", [](VM* vm, ArgsView args) { @@ -463,11 +463,11 @@ inline void init_builtins(VM* _vm) { const Str& self = _CAST(Str&, args[0]); FastStrStream ss; PyObject* it = vm->py_iter(args[1]); // strong ref - PyObject* obj = vm->PyIterNext(it); + PyObject* obj = vm->py_next(it); while(obj != vm->StopIteration){ if(!ss.empty()) ss << self; ss << CAST(Str&, obj); - obj = vm->PyIterNext(it); + obj = vm->py_next(it); } return VAR(ss.str()); }); @@ -560,10 +560,10 @@ inline void init_builtins(VM* _vm) { auto _lock = vm->heap.gc_scope_lock(); List& self = _CAST(List&, args[0]); PyObject* it = vm->py_iter(args[1]); // strong ref - PyObject* obj = vm->PyIterNext(it); + PyObject* obj = vm->py_next(it); while(obj != vm->StopIteration){ self.push_back(obj); - obj = vm->PyIterNext(it); + obj = vm->py_next(it); } return vm->None; }); diff --git a/src/vm.h b/src/vm.h index f36cfce7..5e24b2f0 100644 --- a/src/vm.h +++ b/src/vm.h @@ -485,7 +485,7 @@ public: return index; } - PyObject* PyIterNext(PyObject* obj){ + PyObject* py_next(PyObject* obj){ const PyTypeInfo* ti = _inst_type_info(obj); if(ti->m__next__) return ti->m__next__(this, obj); return call_method(obj, __next__); @@ -790,10 +790,10 @@ inline PyObject* VM::py_list(PyObject* it){ auto _lock = heap.gc_scope_lock(); it = py_iter(it); List list; - PyObject* obj = PyIterNext(it); + PyObject* obj = py_next(it); while(obj != StopIteration){ list.push_back(obj); - obj = PyIterNext(it); + obj = py_next(it); } return VAR(std::move(list)); }