mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-07 10:40:16 +00:00
...
This commit is contained in:
parent
7632d2a918
commit
5d3d9b2dec
@ -43,9 +43,11 @@ struct Exception {
|
|||||||
bool is_re;
|
bool is_re;
|
||||||
stack<Str> stacktrace;
|
stack<Str> stacktrace;
|
||||||
|
|
||||||
Exception(StrName type, Str msg): type(type), msg(msg), is_re(true) {}
|
int _ip_on_error;
|
||||||
|
|
||||||
|
Exception(StrName type, Str msg): type(type), msg(msg), is_re(true), _ip_on_error(-1) {}
|
||||||
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);
|
void st_push(Str&& snapshot);
|
||||||
Str summary() const;
|
Str summary() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -750,7 +750,9 @@ __NEXT_STEP:;
|
|||||||
PK_UNUSED(e);
|
PK_UNUSED(e);
|
||||||
PyObject* obj = POPX();
|
PyObject* obj = POPX();
|
||||||
Exception& _e = CAST(Exception&, obj);
|
Exception& _e = CAST(Exception&, obj);
|
||||||
int current_line = frame->co->lines[frame->_ip]; // current line
|
int actual_ip = frame->_ip;
|
||||||
|
if(_e._ip_on_error >= 0) actual_ip = _e._ip_on_error;
|
||||||
|
int current_line = frame->co->lines[actual_ip]; // current line
|
||||||
auto current_f_name = frame->co->name.sv(); // current function name
|
auto current_f_name = frame->co->name.sv(); // current function name
|
||||||
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
||||||
_e.st_push(frame->co->src->snapshot(current_line, nullptr, current_f_name));
|
_e.st_push(frame->co->src->snapshot(current_line, nullptr, current_f_name));
|
||||||
|
|||||||
@ -51,9 +51,9 @@ namespace pkpy{
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Exception::st_push(Str snapshot){
|
void Exception::st_push(Str&& snapshot){
|
||||||
if(stacktrace.size() >= 8) return;
|
if(stacktrace.size() >= 8) return;
|
||||||
stacktrace.push(snapshot);
|
stacktrace.push(std::move(snapshot));
|
||||||
}
|
}
|
||||||
|
|
||||||
Str Exception::summary() const {
|
Str Exception::summary() const {
|
||||||
|
|||||||
@ -1069,11 +1069,12 @@ PyObject* VM::bind_property(PyObject* obj, Str name, NativeFuncC fget, NativeFun
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VM::_error(Exception e){
|
void VM::_error(Exception e){
|
||||||
|
e._ip_on_error = top_frame()->_ip;
|
||||||
if(callstack.empty()){
|
if(callstack.empty()){
|
||||||
e.is_re = false;
|
e.is_re = false;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
PUSH(VAR(e));
|
PUSH(VAR(std::move(e)));
|
||||||
_raise();
|
_raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user