This commit is contained in:
blueloveTH 2023-02-04 20:13:53 +08:00
parent 79158fb4cd
commit 2ad01d1b79
4 changed files with 17 additions and 5 deletions

View File

@ -1083,7 +1083,7 @@ __LISTCOMP:
}
void __throw_e(_Str type, _Str msg){
auto e = _Exception("SyntaxError", msg, false);
auto e = _Exception("SyntaxError", msg);
e.st_push(getLineSnapshot());
throw e;
}

View File

@ -71,11 +71,11 @@ struct SourceData {
class _Exception {
_Str type;
_Str msg;
bool is_re;
std::stack<_Str> stacktrace;
public:
_Exception(_Str type, _Str msg, bool is_re): type(type), msg(msg), is_re(is_re) {}
_Exception(_Str type, _Str msg): type(type), msg(msg) {}
bool match_type(const _Str& type) const { return this->type == type;}
bool is_re = true;
void st_push(_Str snapshot){
if(stacktrace.size() >= 8) return;

View File

@ -6,7 +6,12 @@
_Code VM::compile(_Str source, _Str filename, CompileMode mode) {
Compiler compiler(this, source.c_str(), filename, mode);
return compiler.__fillCode();
try{
return compiler.__fillCode();
}catch(_Exception& e){
_error(e);
return nullptr;
}
}
#define BIND_NUM_ARITH_OPT(name, op) \

View File

@ -908,7 +908,14 @@ public:
/***** Error Reporter *****/
private:
void _error(const _Str& name, const _Str& msg){
auto e = _Exception(name, msg, true);
_error(_Exception(name, msg));
}
void _error(_Exception e){
if(callstack.empty()){
e.is_re = false;
throw e;
}
top_frame()->push(PyException(e));
_raise();
}