mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
...
This commit is contained in:
parent
9d7204fe3a
commit
db283d4ba6
26
src/ceval.h
26
src/ceval.h
@ -471,7 +471,7 @@ __NEXT_STEP:;
|
|||||||
TOP() = py_iter(TOP());
|
TOP() = py_iter(TOP());
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
TARGET(FOR_ITER)
|
TARGET(FOR_ITER)
|
||||||
_0 = PyIterNext(TOP());
|
_0 = py_next(TOP());
|
||||||
if(_0 != StopIteration){
|
if(_0 != StopIteration){
|
||||||
PUSH(_0);
|
PUSH(_0);
|
||||||
}else{
|
}else{
|
||||||
@ -493,35 +493,39 @@ __NEXT_STEP:;
|
|||||||
frame->f_globals()._try_perfect_rehash();
|
frame->f_globals()._try_perfect_rehash();
|
||||||
DISPATCH();
|
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; i<byte.arg; i++){
|
||||||
|
_1 = py_next(_0);
|
||||||
|
if(_1 == StopIteration) ValueError("not enough values to unpack");
|
||||||
|
PUSH(_1);
|
||||||
|
}
|
||||||
|
if(py_next(_0) != StopIteration) ValueError("too many values to unpack");
|
||||||
|
} DISPATCH();
|
||||||
TARGET(UNPACK_EX) {
|
TARGET(UNPACK_EX) {
|
||||||
auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!!
|
auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!!
|
||||||
_0 = py_iter(POPX());
|
_0 = py_iter(POPX());
|
||||||
for(int i=0; i<byte.arg; i++){
|
for(int i=0; i<byte.arg; i++){
|
||||||
_1 = PyIterNext(_0);
|
_1 = py_next(_0);
|
||||||
if(_1 == StopIteration) ValueError("not enough values to unpack");
|
if(_1 == StopIteration) ValueError("not enough values to unpack");
|
||||||
PUSH(_1);
|
PUSH(_1);
|
||||||
}
|
}
|
||||||
// handle extra items
|
|
||||||
if(byte.op == OP_UNPACK_EX){
|
|
||||||
List extras;
|
List extras;
|
||||||
while(true){
|
while(true){
|
||||||
_1 = PyIterNext(_0);
|
_1 = py_next(_0);
|
||||||
if(_1 == StopIteration) break;
|
if(_1 == StopIteration) break;
|
||||||
extras.push_back(_1);
|
extras.push_back(_1);
|
||||||
}
|
}
|
||||||
PUSH(VAR(extras));
|
PUSH(VAR(extras));
|
||||||
}else{
|
|
||||||
if(PyIterNext(_0) != StopIteration) ValueError("too many values to unpack");
|
|
||||||
}
|
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(UNPACK_UNLIMITED) {
|
TARGET(UNPACK_UNLIMITED) {
|
||||||
auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!!
|
auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!!
|
||||||
_0 = py_iter(POPX());
|
_0 = py_iter(POPX());
|
||||||
_1 = PyIterNext(_0);
|
_1 = py_next(_0);
|
||||||
while(_1 != StopIteration){
|
while(_1 != StopIteration){
|
||||||
PUSH(_1);
|
PUSH(_1);
|
||||||
_1 = PyIterNext(_0);
|
_1 = py_next(_0);
|
||||||
}
|
}
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
|
@ -185,7 +185,7 @@ inline void init_builtins(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_builtin_func<1>("next", [](VM* vm, ArgsView args) {
|
_vm->bind_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) {
|
_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]);
|
const Str& self = _CAST(Str&, args[0]);
|
||||||
FastStrStream ss;
|
FastStrStream ss;
|
||||||
PyObject* it = vm->py_iter(args[1]); // strong ref
|
PyObject* it = vm->py_iter(args[1]); // strong ref
|
||||||
PyObject* obj = vm->PyIterNext(it);
|
PyObject* obj = vm->py_next(it);
|
||||||
while(obj != vm->StopIteration){
|
while(obj != vm->StopIteration){
|
||||||
if(!ss.empty()) ss << self;
|
if(!ss.empty()) ss << self;
|
||||||
ss << CAST(Str&, obj);
|
ss << CAST(Str&, obj);
|
||||||
obj = vm->PyIterNext(it);
|
obj = vm->py_next(it);
|
||||||
}
|
}
|
||||||
return VAR(ss.str());
|
return VAR(ss.str());
|
||||||
});
|
});
|
||||||
@ -560,10 +560,10 @@ inline void init_builtins(VM* _vm) {
|
|||||||
auto _lock = vm->heap.gc_scope_lock();
|
auto _lock = vm->heap.gc_scope_lock();
|
||||||
List& self = _CAST(List&, args[0]);
|
List& self = _CAST(List&, args[0]);
|
||||||
PyObject* it = vm->py_iter(args[1]); // strong ref
|
PyObject* it = vm->py_iter(args[1]); // strong ref
|
||||||
PyObject* obj = vm->PyIterNext(it);
|
PyObject* obj = vm->py_next(it);
|
||||||
while(obj != vm->StopIteration){
|
while(obj != vm->StopIteration){
|
||||||
self.push_back(obj);
|
self.push_back(obj);
|
||||||
obj = vm->PyIterNext(it);
|
obj = vm->py_next(it);
|
||||||
}
|
}
|
||||||
return vm->None;
|
return vm->None;
|
||||||
});
|
});
|
||||||
|
6
src/vm.h
6
src/vm.h
@ -485,7 +485,7 @@ public:
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* PyIterNext(PyObject* obj){
|
PyObject* py_next(PyObject* obj){
|
||||||
const PyTypeInfo* ti = _inst_type_info(obj);
|
const PyTypeInfo* ti = _inst_type_info(obj);
|
||||||
if(ti->m__next__) return ti->m__next__(this, obj);
|
if(ti->m__next__) return ti->m__next__(this, obj);
|
||||||
return call_method(obj, __next__);
|
return call_method(obj, __next__);
|
||||||
@ -790,10 +790,10 @@ inline PyObject* VM::py_list(PyObject* it){
|
|||||||
auto _lock = heap.gc_scope_lock();
|
auto _lock = heap.gc_scope_lock();
|
||||||
it = py_iter(it);
|
it = py_iter(it);
|
||||||
List list;
|
List list;
|
||||||
PyObject* obj = PyIterNext(it);
|
PyObject* obj = py_next(it);
|
||||||
while(obj != StopIteration){
|
while(obj != StopIteration){
|
||||||
list.push_back(obj);
|
list.push_back(obj);
|
||||||
obj = PyIterNext(it);
|
obj = py_next(it);
|
||||||
}
|
}
|
||||||
return VAR(std::move(list));
|
return VAR(std::move(list));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user