blueloveTH 2 anni fa
parent
commit
352688e9ae
3 ha cambiato i file con 8 aggiunte e 4 eliminazioni
  1. 3 2
      src/error.h
  2. 1 1
      src/lexer.h
  3. 4 1
      src/vector.h

+ 3 - 2
src/error.h

@@ -75,9 +75,10 @@ struct SourceData {
 };
 
 class Exception {
+    using StackTrace = stack<Str>;
     StrName type;
     Str msg;
-    stack<Str> stacktrace;
+    StackTrace stacktrace;
 public:
     Exception(StrName type, Str msg): type(type), msg(msg) {}
     bool match_type(StrName type) const { return this->type == type;}
@@ -89,7 +90,7 @@ public:
     }
 
     Str summary() const {
-        stack<Str> st(stacktrace);
+        StackTrace st(stacktrace);
         StrStream ss;
         if(is_re) ss << "Traceback (most recent call last):\n";
         while(!st.empty()) { ss << st.top() << '\n'; st.pop(); }

+ 1 - 1
src/lexer.h

@@ -100,7 +100,7 @@ struct Lexer {
     const char* curr_char;
     int current_line = 1;
     std::vector<Token> nexts;
-    stack<int> indents;
+    small_stack<int, 4> indents;
     int brackets_level = 0;
     bool used = false;
 

+ 4 - 1
src/vector.h

@@ -52,6 +52,9 @@ struct small_vector{
         return *this;
     }
 
+    // remove copy assignment
+    small_vector& operator=(const small_vector& other) = delete;
+
     template<typename __ValueT>
     void push_back(__ValueT&& t) {
         if (_size == _capacity) {
@@ -107,6 +110,6 @@ public:
 	const Container& data() const { return vec; }
 };
 
-template <typename T, int N=8>
+template <typename T, int N>
 using small_stack = stack<T, small_vector<T, N>>;
 } // namespace pkpy