mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix py_list
This commit is contained in:
parent
b8769aa560
commit
d4192be0e4
@ -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
|
||||||
|
@ -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);
|
||||||
|
@ -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");
|
||||||
@ -1512,7 +1512,7 @@ void __init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
void VM::__post_init_builtin_types(){
|
void VM::__post_init_builtin_types(){
|
||||||
__init_builtins(this);
|
__init_builtins(this);
|
||||||
|
|
||||||
bind_func(tp_module, __new__, -1, PK_ACTION(vm->NotImplementedError()));
|
bind_func(tp_module, __new__, -1, PK_ACTION(vm->NotImplementedError()));
|
||||||
|
|
||||||
_all_types[tp_module].m__getattr__ = [](VM* vm, PyObject* obj, StrName name) -> PyObject*{
|
_all_types[tp_module].m__getattr__ = [](VM* vm, PyObject* obj, StrName name) -> PyObject*{
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user