fix py_list

This commit is contained in:
blueloveTH 2024-05-04 21:56:47 +08:00
parent b8769aa560
commit d4192be0e4
4 changed files with 7 additions and 7 deletions

View File

@ -283,7 +283,7 @@ Convert a python iterable to a list
```cpp ```cpp
PyObject* obj = vm->eval("range(3)"); PyObject* obj = vm->eval("range(3)");
PyObject* list = vm->py_list(obj); List list = vm->py_list(obj);
``` ```
## Bindings ## Bindings

View File

@ -191,8 +191,8 @@ public:
PyObject* _py_next(const PyTypeInfo*, PyObject*); PyObject* _py_next(const PyTypeInfo*, PyObject*);
PyObject* py_import(Str path, bool throw_err=true); PyObject* py_import(Str path, bool throw_err=true);
PyObject* py_negate(PyObject* obj); PyObject* py_negate(PyObject* obj);
PyObject* py_list(PyObject*);
List py_list(PyObject*);
bool py_callable(PyObject* obj); bool py_callable(PyObject* obj);
bool py_bool(PyObject* obj); bool py_bool(PyObject* obj);
i64 py_hash(PyObject* obj); i64 py_hash(PyObject* obj);

View File

@ -833,7 +833,7 @@ void __init_builtins(VM* _vm) {
_vm->bind_func(VM::tp_list, __new__, -1, [](VM* vm, ArgsView args) { _vm->bind_func(VM::tp_list, __new__, -1, [](VM* vm, ArgsView args) {
if(args.size() == 1+0) return VAR(List()); 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"); vm->TypeError("list() takes 0 or 1 arguments");
return vm->None; return vm->None;
}); });
@ -1020,7 +1020,7 @@ void __init_builtins(VM* _vm) {
_vm->bind_func(VM::tp_tuple, __new__, -1, [](VM* vm, ArgsView args) { _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+0) return VAR(Tuple(0));
if(args.size() == 1+1){ 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))); return VAR(Tuple(std::move(list)));
} }
vm->TypeError("tuple() takes at most 1 argument"); vm->TypeError("tuple() takes at most 1 argument");

View File

@ -414,7 +414,7 @@ bool VM::py_bool(PyObject* obj){
return true; return true;
} }
PyObject* VM::py_list(PyObject* it){ List 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;
@ -424,7 +424,7 @@ PyObject* VM::py_list(PyObject* it){
list.push_back(obj); list.push_back(obj);
obj = _py_next(info, it); obj = _py_next(info, it);
} }
return VAR(std::move(list)); return list;
} }