mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
add function name in error's snapshot
This commit is contained in:
parent
45bafb7534
commit
7632d2a918
@ -34,7 +34,7 @@ struct SourceData {
|
||||
|
||||
SourceData(const Str& source, const Str& filename, CompileMode mode);
|
||||
std::pair<const char*,const char*> get_line(int lineno) const;
|
||||
Str snapshot(int lineno, const char* cursor=nullptr);
|
||||
Str snapshot(int lineno, const char* cursor=nullptr, std::string_view name="");
|
||||
};
|
||||
|
||||
struct Exception {
|
||||
|
@ -110,8 +110,6 @@ struct Frame {
|
||||
return co->codes[_ip];
|
||||
}
|
||||
|
||||
Str snapshot();
|
||||
|
||||
PyObject** actual_sp_base() const { return _locals.a; }
|
||||
int stack_size() const { return _s->_sp - actual_sp_base(); }
|
||||
ArgsView stack_view() const { return ArgsView(actual_sp_base(), _s->_sp); }
|
||||
|
@ -750,7 +750,10 @@ __NEXT_STEP:;
|
||||
PK_UNUSED(e);
|
||||
PyObject* obj = POPX();
|
||||
Exception& _e = CAST(Exception&, obj);
|
||||
_e.st_push(frame->snapshot());
|
||||
int current_line = frame->co->lines[frame->_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));
|
||||
_pop_frame();
|
||||
if(callstack.empty()){
|
||||
#if PK_DEBUG_FULL_EXCEPTION
|
||||
|
@ -30,9 +30,11 @@ namespace pkpy{
|
||||
return {_start, i};
|
||||
}
|
||||
|
||||
Str SourceData::snapshot(int lineno, const char* cursor){
|
||||
Str SourceData::snapshot(int lineno, const char* cursor, std::string_view name){
|
||||
std::stringstream ss;
|
||||
ss << " " << "File \"" << filename << "\", line " << lineno << '\n';
|
||||
ss << " " << "File \"" << filename << "\", line " << lineno;
|
||||
if(!name.empty()) ss << ", in " << name;
|
||||
ss << '\n';
|
||||
std::pair<const char*,const char*> pair = get_line(lineno);
|
||||
Str line = "<?>";
|
||||
int removed_spaces = 0;
|
||||
|
@ -23,11 +23,6 @@ namespace pkpy{
|
||||
return fn._closure->try_get(name);
|
||||
}
|
||||
|
||||
Str Frame::snapshot(){
|
||||
int line = co->lines[_ip];
|
||||
return co->src->snapshot(line);
|
||||
}
|
||||
|
||||
bool Frame::jump_to_exception_handler(){
|
||||
// try to find a parent try block
|
||||
int block = co->codes[_ip].block;
|
||||
|
Loading…
x
Reference in New Issue
Block a user