|
@@ -34,21 +34,41 @@ struct SourceData {
|
|
|
|
|
|
|
|
SourceData(const Str& source, const Str& filename, CompileMode mode);
|
|
SourceData(const Str& source, const Str& filename, CompileMode mode);
|
|
|
std::pair<const char*,const char*> get_line(int lineno) const;
|
|
std::pair<const char*,const char*> get_line(int lineno) const;
|
|
|
- Str snapshot(int lineno, const char* cursor=nullptr, std::string_view name="");
|
|
|
|
|
|
|
+ Str snapshot(int lineno, const char* cursor, std::string_view name) const;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+struct ExceptionLine{
|
|
|
|
|
+ std::shared_ptr<SourceData> src;
|
|
|
|
|
+ int lineno;
|
|
|
|
|
+ const char* cursor;
|
|
|
|
|
+ std::string name;
|
|
|
|
|
+
|
|
|
|
|
+ Str snapshot() const { return src->snapshot(lineno, cursor, name); }
|
|
|
|
|
+
|
|
|
|
|
+ ExceptionLine(std::shared_ptr<SourceData> src, int lineno, const char* cursor, std::string_view name):
|
|
|
|
|
+ src(src), lineno(lineno), cursor(cursor), name(name) {}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct Exception {
|
|
struct Exception {
|
|
|
StrName type;
|
|
StrName type;
|
|
|
Str msg;
|
|
Str msg;
|
|
|
bool is_re;
|
|
bool is_re;
|
|
|
- stack<Str> stacktrace;
|
|
|
|
|
|
|
|
|
|
int _ip_on_error;
|
|
int _ip_on_error;
|
|
|
void* _code_on_error;
|
|
void* _code_on_error;
|
|
|
|
|
+
|
|
|
|
|
+ stack<ExceptionLine> stacktrace;
|
|
|
|
|
|
|
|
- Exception(StrName type, Str msg): type(type), msg(msg), is_re(true), _ip_on_error(-1), _code_on_error(nullptr) {}
|
|
|
|
|
|
|
+ Exception(StrName type, Str msg):
|
|
|
|
|
+ type(type), msg(msg), is_re(true), _ip_on_error(-1), _code_on_error(nullptr) {}
|
|
|
bool match_type(StrName t) const { return this->type == t;}
|
|
bool match_type(StrName t) const { return this->type == t;}
|
|
|
- void st_push(Str&& snapshot);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ template<typename... Args>
|
|
|
|
|
+ void st_push(Args&&... args){
|
|
|
|
|
+ if(stacktrace.size() >= 8) return;
|
|
|
|
|
+ stacktrace.emplace(std::forward<Args>(args)...);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Str summary() const;
|
|
Str summary() const;
|
|
|
};
|
|
};
|
|
|
|
|
|