diff --git a/include/pocketpy/codeobject.h b/include/pocketpy/codeobject.h index 9cb79d3d..cba571b1 100644 --- a/include/pocketpy/codeobject.h +++ b/include/pocketpy/codeobject.h @@ -65,8 +65,8 @@ struct CodeObject { std::vector iblocks; // block index for each bytecode std::vector lines; - small_vector_no_copy_and_move consts; // constants - small_vector_no_copy_and_move varnames; // local variables + small_vector_2 consts; // constants + small_vector_2 varnames; // local variables NameDictInt varnames_inv; std::vector blocks; @@ -100,8 +100,8 @@ struct FuncDecl { }; CodeObject_ code; // code object of this function - small_vector_no_copy_and_move args; // indices in co->varnames - small_vector_no_copy_and_move kwargs; // indices in co->varnames + small_vector_2 args; // indices in co->varnames + small_vector_2 kwargs; // indices in co->varnames int starred_arg = -1; // index in co->varnames, -1 if no *arg int starred_kwarg = -1; // index in co->varnames, -1 if no **kwarg diff --git a/include/pocketpy/lexer.h b/include/pocketpy/lexer.h index ff268454..fff1d7e3 100644 --- a/include/pocketpy/lexer.h +++ b/include/pocketpy/lexer.h @@ -100,7 +100,7 @@ struct Lexer { const char* curr_char; int current_line = 1; std::vector nexts; - stack_no_copy> indents; + stack_no_copy> indents; int brackets_level = 0; char peekchar() const{ return *curr_char; } diff --git a/include/pocketpy/obj.h b/include/pocketpy/obj.h index 8859437a..ad4dc58a 100644 --- a/include/pocketpy/obj.h +++ b/include/pocketpy/obj.h @@ -112,15 +112,10 @@ struct PyObject{ } virtual void _obj_gc_mark() = 0; + virtual ~PyObject(); PyObject(Type type) : gc_enabled(true), gc_marked(false), type(type), _attr(nullptr) {} - virtual ~PyObject(){ - if(_attr == nullptr) return; - _attr->~NameDict(); - pool128_dealloc(_attr); - } - void _enable_instance_dict() { _attr = new(pool128_alloc()) NameDict(); } diff --git a/include/pocketpy/vector.h b/include/pocketpy/vector.h index cc334c5e..25b507fd 100644 --- a/include/pocketpy/vector.h +++ b/include/pocketpy/vector.h @@ -394,16 +394,14 @@ namespace pkpy } }; -// small_vector_no_copy_and_move - template - class small_vector_no_copy_and_move: public small_vector + class small_vector_2: public small_vector { public: - small_vector_no_copy_and_move() = default; - small_vector_no_copy_and_move(const small_vector_no_copy_and_move& other) = delete; - small_vector_no_copy_and_move& operator=(const small_vector_no_copy_and_move& other) = delete; - small_vector_no_copy_and_move(small_vector_no_copy_and_move&& other) = delete; - small_vector_no_copy_and_move& operator=(small_vector_no_copy_and_move&& other) = delete; + small_vector_2() = default; + small_vector_2(const small_vector_2& other) = delete; + small_vector_2& operator=(const small_vector_2& other) = delete; + small_vector_2(small_vector_2&& other) = delete; + small_vector_2& operator=(small_vector_2&& other) = delete; }; } // namespace pkpy \ No newline at end of file diff --git a/src/compiler.cpp b/src/compiler.cpp index 889854f6..408cc321 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -704,9 +704,10 @@ __EAT_DOTS_END: void Compiler::compile_try_except() { ctx()->enter_block(CodeBlockType::TRY_EXCEPT); compile_block_body(); - pod_vector patches = { + small_vector_2 patches; + patches.push_back( ctx()->emit_(OP_JUMP_ABSOLUTE, BC_NOARG, BC_KEEPLINE) - }; + ); ctx()->exit_block(); int finally_entry = -1; diff --git a/src/lexer.cpp b/src/lexer.cpp index 918dec48..5b45d2d1 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -204,7 +204,7 @@ static bool is_unicode_Lo_char(uint32_t c) { Str Lexer::eat_string_until(char quote, bool raw) { bool quote3 = match_n_chars(2, quote); - pod_vector buff; + small_vector_2 buff; while (true) { char c = eatchar_include_newline(); if (c == quote){ diff --git a/src/obj.cpp b/src/obj.cpp index 0e1ab193..2df4cece 100644 --- a/src/obj.cpp +++ b/src/obj.cpp @@ -47,4 +47,10 @@ namespace pkpy{ return {p, size}; } + PyObject::~PyObject(){ + if(_attr == nullptr) return; + _attr->~NameDict(); + pool128_dealloc(_attr); + } + } // namespace pkpy \ No newline at end of file