From d4192be0e4eb85cc0a880773c1181592455ddc94 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 4 May 2024 21:56:47 +0800 Subject: [PATCH] fix `py_list` --- docs/cheatsheet.md | 2 +- include/pocketpy/vm.h | 2 +- src/pocketpy.cpp | 6 +++--- src/vm.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/cheatsheet.md b/docs/cheatsheet.md index f36a4212..ddf1820c 100644 --- a/docs/cheatsheet.md +++ b/docs/cheatsheet.md @@ -283,7 +283,7 @@ Convert a python iterable to a list ```cpp PyObject* obj = vm->eval("range(3)"); -PyObject* list = vm->py_list(obj); +List list = vm->py_list(obj); ``` ## Bindings diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index dac7a3df..3e5451d6 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -191,8 +191,8 @@ public: PyObject* _py_next(const PyTypeInfo*, PyObject*); PyObject* py_import(Str path, bool throw_err=true); PyObject* py_negate(PyObject* obj); - PyObject* py_list(PyObject*); + List py_list(PyObject*); bool py_callable(PyObject* obj); bool py_bool(PyObject* obj); i64 py_hash(PyObject* obj); diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 72f968cb..82eb28db 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -833,7 +833,7 @@ void __init_builtins(VM* _vm) { _vm->bind_func(VM::tp_list, __new__, -1, [](VM* vm, ArgsView args) { if(args.size() == 1+0) return VAR(List()); - if(args.size() == 1+1) return vm->py_list(args[1]); + if(args.size() == 1+1) return VAR(vm->py_list(args[1])); vm->TypeError("list() takes 0 or 1 arguments"); return vm->None; }); @@ -1020,7 +1020,7 @@ void __init_builtins(VM* _vm) { _vm->bind_func(VM::tp_tuple, __new__, -1, [](VM* vm, ArgsView args) { if(args.size() == 1+0) return VAR(Tuple(0)); if(args.size() == 1+1){ - List list(CAST(List, vm->py_list(args[1]))); + List list = vm->py_list(args[1]); return VAR(Tuple(std::move(list))); } vm->TypeError("tuple() takes at most 1 argument"); @@ -1512,7 +1512,7 @@ void __init_builtins(VM* _vm) { void VM::__post_init_builtin_types(){ __init_builtins(this); - + bind_func(tp_module, __new__, -1, PK_ACTION(vm->NotImplementedError())); _all_types[tp_module].m__getattr__ = [](VM* vm, PyObject* obj, StrName name) -> PyObject*{ diff --git a/src/vm.cpp b/src/vm.cpp index 7150c758..dfbf10c4 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -414,7 +414,7 @@ bool VM::py_bool(PyObject* obj){ return true; } -PyObject* VM::py_list(PyObject* it){ +List VM::py_list(PyObject* it){ auto _lock = heap.gc_scope_lock(); it = py_iter(it); List list; @@ -424,7 +424,7 @@ PyObject* VM::py_list(PyObject* it){ list.push_back(obj); obj = _py_next(info, it); } - return VAR(std::move(list)); + return list; }