mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-06 18:20:17 +00:00
...
This commit is contained in:
parent
7632d2a918
commit
5d3d9b2dec
@ -43,9 +43,11 @@ struct Exception {
|
||||
bool is_re;
|
||||
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;}
|
||||
void st_push(Str snapshot);
|
||||
void st_push(Str&& snapshot);
|
||||
Str summary() const;
|
||||
};
|
||||
|
||||
|
||||
@ -750,7 +750,9 @@ __NEXT_STEP:;
|
||||
PK_UNUSED(e);
|
||||
PyObject* obj = POPX();
|
||||
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
|
||||
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
||||
_e.st_push(frame->co->src->snapshot(current_line, nullptr, current_f_name));
|
||||
|
||||
@ -51,9 +51,9 @@ namespace pkpy{
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Exception::st_push(Str snapshot){
|
||||
void Exception::st_push(Str&& snapshot){
|
||||
if(stacktrace.size() >= 8) return;
|
||||
stacktrace.push(snapshot);
|
||||
stacktrace.push(std::move(snapshot));
|
||||
}
|
||||
|
||||
Str Exception::summary() const {
|
||||
|
||||
@ -1069,11 +1069,12 @@ PyObject* VM::bind_property(PyObject* obj, Str name, NativeFuncC fget, NativeFun
|
||||
}
|
||||
|
||||
void VM::_error(Exception e){
|
||||
e._ip_on_error = top_frame()->_ip;
|
||||
if(callstack.empty()){
|
||||
e.is_re = false;
|
||||
throw e;
|
||||
}
|
||||
PUSH(VAR(e));
|
||||
PUSH(VAR(std::move(e)));
|
||||
_raise();
|
||||
}
|
||||
|
||||
|
||||
@ -69,4 +69,4 @@ try:
|
||||
assert test(0) == '0.00'
|
||||
exit(1)
|
||||
except UnboundLocalError:
|
||||
pass
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user