From ffee64655eaec1fa67876ac7d1739e9da90eaa08 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 19 Feb 2024 11:50:55 +0800 Subject: [PATCH] some more replace --- include/pocketpy/codeobject.h | 8 +++++--- include/pocketpy/compiler.h | 2 +- include/pocketpy/frame.h | 2 +- include/pocketpy/lexer.h | 2 +- include/pocketpy/profiler.h | 2 +- include/pocketpy/vector.h | 13 +++++++++++++ include/pocketpy/vm.h | 2 +- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/pocketpy/codeobject.h b/include/pocketpy/codeobject.h index 4da74cdc..708f74af 100644 --- a/include/pocketpy/codeobject.h +++ b/include/pocketpy/codeobject.h @@ -71,7 +71,7 @@ struct CodeObject { std::vector iblocks; // block index for each bytecode std::vector lines; - small_vector consts; + small_vector_no_copy_and_move consts; pod_vector varnames; // local variables NameDictInt varnames_inv; @@ -97,8 +97,10 @@ struct FuncDecl { PyObject* value; // default value }; CodeObject_ code; // code object of this function - pod_vector args; // indices in co->varnames - pod_vector kwargs; // indices in co->varnames + + small_vector_no_copy_and_move args; // indices in co->varnames + small_vector_no_copy_and_move 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 bool nested = false; // whether this function is nested diff --git a/include/pocketpy/compiler.h b/include/pocketpy/compiler.h index 92137cb4..42c3bc8b 100644 --- a/include/pocketpy/compiler.h +++ b/include/pocketpy/compiler.h @@ -22,7 +22,7 @@ class Compiler { inline static PrattRule rules[kTokenCount]; Lexer lexer; - stack contexts; + stack_no_copy contexts; VM* vm; bool unknown_global_scope; // for eval/exec() call bool used; diff --git a/include/pocketpy/frame.h b/include/pocketpy/frame.h index 06df37cd..b11eeb60 100644 --- a/include/pocketpy/frame.h +++ b/include/pocketpy/frame.h @@ -126,7 +126,7 @@ struct Frame { } }; -using CallstackContainer = small_vector; +using CallstackContainer = small_vector_no_copy_and_move; struct FrameId{ CallstackContainer* data; diff --git a/include/pocketpy/lexer.h b/include/pocketpy/lexer.h index 97fed808..47611d37 100644 --- a/include/pocketpy/lexer.h +++ b/include/pocketpy/lexer.h @@ -104,7 +104,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; bool used = false; diff --git a/include/pocketpy/profiler.h b/include/pocketpy/profiler.h index ee6c2129..e1f77c94 100644 --- a/include/pocketpy/profiler.h +++ b/include/pocketpy/profiler.h @@ -22,7 +22,7 @@ struct _FrameRecord{ struct LineProfiler{ // filename -> records std::map> records; - stack<_FrameRecord> frames; + stack_no_copy<_FrameRecord> frames; std::set functions; void begin(); diff --git a/include/pocketpy/vector.h b/include/pocketpy/vector.h index 73c02038..fefb645e 100644 --- a/include/pocketpy/vector.h +++ b/include/pocketpy/vector.h @@ -393,4 +393,17 @@ namespace pkpy m_end = m_begin; } }; + +// small_vector_no_copy_and_move + + template + class small_vector_no_copy_and_move: 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; + }; } // namespace pkpy \ No newline at end of file diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index eee9fdaf..1c1f0593 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -120,7 +120,7 @@ public: struct{ PyObject* error; - stack s_view; + stack_no_copy s_view; } _c; PyObject* None;