浏览代码

fix `py_list`

blueloveTH 1 年之前
父节点
当前提交
d4192be0e4
共有 4 个文件被更改,包括 7 次插入7 次删除
  1. 1 1
      docs/cheatsheet.md
  2. 1 1
      include/pocketpy/vm.h
  3. 3 3
      src/pocketpy.cpp
  4. 2 2
      src/vm.cpp

+ 1 - 1
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

+ 1 - 1
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);

+ 3 - 3
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*{

+ 2 - 2
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;
 }