This commit is contained in:
blueloveTH 2023-04-06 14:58:38 +08:00
parent e69b66f0b7
commit 352688e9ae
3 changed files with 8 additions and 4 deletions

View File

@ -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(); }

View File

@ -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;

View File

@ -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