Przeglądaj źródła

some more replace

blueloveTH 2 lat temu
rodzic
commit
ffee64655e

+ 5 - 3
include/pocketpy/codeobject.h

@@ -71,7 +71,7 @@ struct CodeObject {
     std::vector<int> iblocks;       // block index for each bytecode
     std::vector<LineInfo> lines;
     
-    small_vector<PyObject*, 8> consts;
+    small_vector_no_copy_and_move<PyObject*, 8> consts;
 
     pod_vector<StrName> 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<int> args;      // indices in co->varnames
-    pod_vector<KwArg> kwargs;  // indices in co->varnames
+
+    small_vector_no_copy_and_move<int, 6> args;      // indices in co->varnames
+    small_vector_no_copy_and_move<KwArg, 6> 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

+ 1 - 1
include/pocketpy/compiler.h

@@ -22,7 +22,7 @@ class Compiler {
     inline static PrattRule rules[kTokenCount];
 
     Lexer lexer;
-    stack<CodeEmitContext> contexts;
+    stack_no_copy<CodeEmitContext> contexts;
     VM* vm;
     bool unknown_global_scope;     // for eval/exec() call
     bool used;

+ 1 - 1
include/pocketpy/frame.h

@@ -126,7 +126,7 @@ struct Frame {
     }
 };
 
-using CallstackContainer = small_vector<Frame, 16>;
+using CallstackContainer = small_vector_no_copy_and_move<Frame, 16>;
 
 struct FrameId{
     CallstackContainer* data;

+ 1 - 1
include/pocketpy/lexer.h

@@ -104,7 +104,7 @@ struct Lexer {
     const char* curr_char;
     int current_line = 1;
     std::vector<Token> nexts;
-    stack_no_copy<int, pod_vector<int>> indents;
+    stack_no_copy<int, small_vector_no_copy_and_move<int, 8>> indents;
     int brackets_level = 0;
     bool used = false;
 

+ 1 - 1
include/pocketpy/profiler.h

@@ -22,7 +22,7 @@ struct _FrameRecord{
 struct LineProfiler{
     // filename -> records
     std::map<std::string_view, std::vector<_LineRecord>> records;
-    stack<_FrameRecord> frames;
+    stack_no_copy<_FrameRecord> frames;
     std::set<FuncDecl*> functions;
 
     void begin();

+ 13 - 0
include/pocketpy/vector.h

@@ -393,4 +393,17 @@ namespace pkpy
             m_end = m_begin;
         }
     };
+
+// small_vector_no_copy_and_move
+
+    template<typename T, std::size_t N>
+    class small_vector_no_copy_and_move: public small_vector<T, N>
+    {
+    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

+ 1 - 1
include/pocketpy/vm.h

@@ -120,7 +120,7 @@ public:
 
     struct{
         PyObject* error;
-        stack<ArgsView> s_view;
+        stack_no_copy<ArgsView> s_view;
     } _c;
 
     PyObject* None;