소스 검색

some revert

blueloveTH 1 년 전
부모
커밋
0946c67fe0
6개의 변경된 파일2개의 추가작업 그리고 85개의 파일을 삭제
  1. 0 12
      include/pocketpy/interpreter/vm.hpp
  2. 2 21
      src/interpreter/ceval.cpp
  3. 0 11
      src/interpreter/iter.cpp
  4. 0 22
      src/interpreter/vm.cpp
  5. 0 3
      src/modules/array2d.cpp
  6. 0 16
      src/pocketpy.cpp

+ 0 - 12
include/pocketpy/interpreter/vm.hpp

@@ -87,7 +87,6 @@ struct PyTypeInfo {
     i64 (*m__hash__)(VM* vm, PyVar) = nullptr;
     i64 (*m__len__)(VM* vm, PyVar) = nullptr;
     PyVar (*m__iter__)(VM* vm, PyVar) = nullptr;
-    void (*op__iter__)(VM* vm, PyVar) = nullptr;
     unsigned (*op__next__)(VM* vm, PyVar) = nullptr;
     PyVar (*m__neg__)(VM* vm, PyVar) = nullptr;
     PyVar (*m__invert__)(VM* vm, PyVar) = nullptr;
@@ -218,7 +217,6 @@ public:
     constexpr static Type tp_staticmethod = Type(22), tp_classmethod = Type(23);
     constexpr static Type tp_none_type = Type(kTpNoneTypeIndex), tp_not_implemented_type = Type(kTpNotImplementedTypeIndex);
     constexpr static Type tp_ellipsis = Type(26);
-    constexpr static Type tp_stack_memory = Type(kTpStackMemoryIndex);
 
     constexpr static PyVar True{const_sso_var(), tp_bool, 1};
     constexpr static PyVar False{const_sso_var(), tp_bool, 0};
@@ -451,15 +449,6 @@ public:
         if constexpr(is_sso_v<T>) return PyVar(type, T(std::forward<Args>(args)...));
         else return heap.gcnew<T>(type, std::forward<Args>(args)...);
     }
-
-    template<typename T, typename ...Args>
-    void new_stack_object(Type type, Args&&... args){
-        static_assert(std::is_same_v<T, std::decay_t<T>>);
-        static_assert(std::is_trivially_destructible_v<T>);
-        PyObject* p = new(__stack_alloc(py_sizeof<T>)) PyObject(type);
-        p->placement_new<T>(std::forward<Args>(args)...);
-        vm->s_data.emplace(p->type, p);
-    }
 #endif
 
     template <typename T>
@@ -540,7 +529,6 @@ template<> constexpr Type _tp_builtin<Property>() { return VM::tp_property; }
 template<> constexpr Type _tp_builtin<StarWrapper>() { return VM::tp_star_wrapper; }
 template<> constexpr Type _tp_builtin<StaticMethod>() { return VM::tp_staticmethod; }
 template<> constexpr Type _tp_builtin<ClassMethod>() { return VM::tp_classmethod; }
-template<> constexpr Type _tp_builtin<StackMemory>() { return VM::tp_stack_memory; }
 
 // clang-format on
 

+ 2 - 21
src/interpreter/ceval.cpp

@@ -880,16 +880,7 @@ PyVar VM::__run_top_frame() {
                         DISPATCH()
                     /*****************************************/
                     case OP_UNARY_NEGATIVE: TOP() = py_negate(TOP()); DISPATCH()
-                    case OP_UNARY_NOT: {
-                        PyVar _0 = TOP();
-                        if(_0 == True)
-                            TOP() = False;
-                        else if(_0 == False)
-                            TOP() = True;
-                        else
-                            TOP() = VAR(!py_bool(_0));
-                    }
-                        DISPATCH()
+                    case OP_UNARY_NOT: TOP() = VAR(!py_bool(TOP())); DISPATCH()  
                     case OP_UNARY_STAR: TOP() = VAR(StarWrapper(byte.arg, TOP())); DISPATCH()
                     case OP_UNARY_INVERT: {
                         PyVar _0;
@@ -903,17 +894,7 @@ PyVar VM::__run_top_frame() {
                         DISPATCH()
                     /*****************************************/
                     case OP_GET_ITER: TOP() = py_iter(TOP()); DISPATCH()
-                    case OP_GET_ITER_NEW: {
-                        // This opcode always creates a temporary iterator object
-                        const PyTypeInfo* _ti = _tp_info(TOP());
-                        if(_ti->op__iter__) {
-                            PyVar _0 = POPX();
-                            _ti->op__iter__(this, _0);
-                        } else {
-                            TOP() = py_iter(TOP());
-                        }
-                        DISPATCH()
-                    }
+                    case OP_GET_ITER_NEW: TOP() = py_iter(TOP()); DISPATCH()
                     case OP_FOR_ITER: {
                         PyVar _0 = py_next(TOP());
                         if(_0 == StopIteration) {

+ 0 - 11
src/interpreter/iter.cpp

@@ -64,17 +64,6 @@ PyVar Generator::next(VM* vm) {
     // restore the context
     for(PyVar obj: s_backup)
         vm->s_data.push(obj);
-    // relocate stack objects (their addresses become invalid)
-    for(PyVar* p = lf->frame.actual_sp_base(); p != vm->s_data.end(); p++) {
-        if(p->type == VM::tp_stack_memory) {
-            // TODO: refactor this
-            int count = p->as<StackMemory>().count;
-            if(count < 0) {
-                void* new_p = p + count;
-                p[1]._1 = reinterpret_cast<i64>(new_p);
-            }
-        }
-    }
     s_backup.clear();
     vm->callstack.pushx(lf);
     lf = nullptr;

+ 0 - 22
src/interpreter/vm.cpp

@@ -450,25 +450,10 @@ void VM::__stack_gc_mark(PyVar* begin, PyVar* end) {
     for(PyVar* it = begin; it != end; it++) {
         if(it->is_ptr) {
             __obj_gc_mark(it->get());
-        } else {
-            if(it->type == tp_stack_memory) {
-                // [sm:3, _0, _1, _2, sm:-3]
-                int count = it->as<StackMemory>().count;
-                if(count > 0) it += count;
-            }
         }
     }
 }
 
-void* VM::__stack_alloc(int size) {
-    int count = size / sizeof(PyVar) + 1;
-    s_data.emplace(tp_stack_memory, StackMemory(count));
-    void* out = s_data._sp;
-    s_data._sp += count;
-    s_data.emplace(tp_stack_memory, StackMemory(-count));
-    return out;
-}
-
 List VM::py_list(PyVar it) {
     auto _lock = heap.gc_scope_lock();
     it = py_iter(it);
@@ -851,12 +836,6 @@ void VM::__log_s_data(const char* title) {
                 case tp_type: ss << "<class " + _type_name(this, p->obj_get<Type>()).escape() + ">"; break;
                 case tp_list: ss << "list(size=" << p->obj_get<List>().size() << ")"; break;
                 case tp_tuple: ss << "tuple(size=" << p->obj_get<Tuple>().size() << ")"; break;
-                case tp_stack_memory: {
-                    int count = p->obj_get<StackMemory>().count;
-                    ss << "M[" << count << "]";
-                    if(count > 0) p += count;
-                    break;
-                }
                 default: ss << "(" << _type_name(this, p->type) << ")"; break;
             }
         }
@@ -913,7 +892,6 @@ void VM::__init_builtin_types() {
     validate(tp_none_type, new_type_object(nullptr, "NoneType", tp_object, false));
     validate(tp_not_implemented_type, new_type_object(nullptr, "NotImplementedType", tp_object, false));
     validate(tp_ellipsis, new_type_object(nullptr, "ellipsis", tp_object, false));
-    validate(tp_stack_memory, new_type_object<StackMemory>(nullptr, "_stack_memory", tp_object, false));
 
     // SyntaxError and IndentationError must be created here
     PyObject* SyntaxError = new_type_object(nullptr, "SyntaxError", tp_exception, true);

+ 0 - 3
src/modules/array2d.cpp

@@ -401,9 +401,6 @@ void add_module_array2d(VM* vm) {
     vm->bind__iter__(array2d_iter_t, [](VM* vm, PyVar _0) {
         return vm->new_user_object<Array2dIter>(_0, &_0.obj_get<Array2d>());
     });
-    vm->_all_types[array2d_iter_t].op__iter__ = [](VM* vm, PyVar _0) {
-        vm->new_stack_object<Array2dIter>(vm->_tp_user<Array2dIter>(), _0, &_0.obj_get<Array2d>());
-    };
 }
 
 }  // namespace pkpy

+ 0 - 16
src/pocketpy.cpp

@@ -400,14 +400,6 @@ void __init_builtins(VM* _vm) {
             return vm->new_user_object<RangeIterR>(r);
         }
     });
-    _vm->_all_types[VM::tp_range].op__iter__ = [](VM* vm, PyVar _0) {
-        const Range& r = PK_OBJ_GET(Range, _0);
-        if(r.step > 0) {
-            vm->new_stack_object<RangeIter>(vm->_tp_user<RangeIter>(), r);
-        } else {
-            vm->new_stack_object<RangeIterR>(vm->_tp_user<RangeIterR>(), r);
-        }
-    };
 
     // tp_nonetype
     _vm->bind__repr__(_vm->_tp(_vm->None), [](VM* vm, PyVar _0) -> Str {
@@ -1053,10 +1045,6 @@ void __init_builtins(VM* _vm) {
         List& self = _CAST(List&, _0);
         return vm->new_user_object<ArrayIter>(_0.get(), self.begin(), self.end());
     });
-    _vm->_all_types[VM::tp_list].op__iter__ = [](VM* vm, PyVar _0) {
-        List& self = _CAST(List&, _0);
-        vm->new_stack_object<ArrayIter>(vm->_tp_user<ArrayIter>(), _0.get(), self.begin(), self.end());
-    };
 
     _vm->bind__getitem__(VM::tp_list, PyArrayGetItem<List>);
     _vm->bind__setitem__(VM::tp_list, [](VM* vm, PyVar _0, PyVar _1, PyVar _2) {
@@ -1122,10 +1110,6 @@ void __init_builtins(VM* _vm) {
         Tuple& self = _CAST(Tuple&, _0);
         return vm->new_user_object<ArrayIter>(_0.get(), self.begin(), self.end());
     });
-    _vm->_all_types[VM::tp_tuple].op__iter__ = [](VM* vm, PyVar _0) {
-        Tuple& self = _CAST(Tuple&, _0);
-        vm->new_stack_object<ArrayIter>(vm->_tp_user<ArrayIter>(), _0.get(), self.begin(), self.end());
-    };
 
     _vm->bind__getitem__(VM::tp_tuple, PyArrayGetItem<Tuple>);
     _vm->bind__len__(VM::tp_tuple, [](VM* vm, PyVar obj) {