diff --git a/include/pocketpy/interpreter/vm.hpp b/include/pocketpy/interpreter/vm.hpp index 28fc4471..48ed5f48 100644 --- a/include/pocketpy/interpreter/vm.hpp +++ b/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) return PyVar(type, T(std::forward(args)...)); else return heap.gcnew(type, std::forward(args)...); } - - template - void new_stack_object(Type type, Args&&... args){ - static_assert(std::is_same_v>); - static_assert(std::is_trivially_destructible_v); - PyObject* p = new(__stack_alloc(py_sizeof)) PyObject(type); - p->placement_new(std::forward(args)...); - vm->s_data.emplace(p->type, p); - } #endif template @@ -540,7 +529,6 @@ template<> constexpr Type _tp_builtin() { return VM::tp_property; } template<> constexpr Type _tp_builtin() { return VM::tp_star_wrapper; } template<> constexpr Type _tp_builtin() { return VM::tp_staticmethod; } template<> constexpr Type _tp_builtin() { return VM::tp_classmethod; } -template<> constexpr Type _tp_builtin() { return VM::tp_stack_memory; } // clang-format on diff --git a/src/interpreter/ceval.cpp b/src/interpreter/ceval.cpp index 9a7b7ac3..01e77832 100644 --- a/src/interpreter/ceval.cpp +++ b/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) { diff --git a/src/interpreter/iter.cpp b/src/interpreter/iter.cpp index e1f27f1d..15d058d5 100644 --- a/src/interpreter/iter.cpp +++ b/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().count; - if(count < 0) { - void* new_p = p + count; - p[1]._1 = reinterpret_cast(new_p); - } - } - } s_backup.clear(); vm->callstack.pushx(lf); lf = nullptr; diff --git a/src/interpreter/vm.cpp b/src/interpreter/vm.cpp index 74e9f73b..3508385e 100644 --- a/src/interpreter/vm.cpp +++ b/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().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 << "obj_get()).escape() + ">"; break; case tp_list: ss << "list(size=" << p->obj_get().size() << ")"; break; case tp_tuple: ss << "tuple(size=" << p->obj_get().size() << ")"; break; - case tp_stack_memory: { - int count = p->obj_get().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(nullptr, "_stack_memory", tp_object, false)); // SyntaxError and IndentationError must be created here PyObject* SyntaxError = new_type_object(nullptr, "SyntaxError", tp_exception, true); diff --git a/src/modules/array2d.cpp b/src/modules/array2d.cpp index efe8ffd8..cffe196f 100644 --- a/src/modules/array2d.cpp +++ b/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(_0, &_0.obj_get()); }); - vm->_all_types[array2d_iter_t].op__iter__ = [](VM* vm, PyVar _0) { - vm->new_stack_object(vm->_tp_user(), _0, &_0.obj_get()); - }; } } // namespace pkpy diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index cbd1a338..4e7452eb 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -400,14 +400,6 @@ void __init_builtins(VM* _vm) { return vm->new_user_object(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(vm->_tp_user(), r); - } else { - vm->new_stack_object(vm->_tp_user(), 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(_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(vm->_tp_user(), _0.get(), self.begin(), self.end()); - }; _vm->bind__getitem__(VM::tp_list, PyArrayGetItem); _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(_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(vm->_tp_user(), _0.get(), self.begin(), self.end()); - }; _vm->bind__getitem__(VM::tp_tuple, PyArrayGetItem); _vm->bind__len__(VM::tp_tuple, [](VM* vm, PyVar obj) {