This commit is contained in:
blueloveTH 2024-07-29 19:20:59 +08:00
parent a8dfbc9147
commit 2165e29c4f
5 changed files with 18 additions and 14 deletions

View File

@ -908,7 +908,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
c11__unreachedable();
__ERROR:
pk_print_stack(self, frame, (Bytecode){OP_NO_OP, 0});
pk_print_stack(self, frame, (Bytecode){});
py_BaseException__set_lineno(&self->curr_exception, Frame__lineno(frame), frame->co);
__ERROR_RE_RAISE:

View File

@ -294,6 +294,9 @@ py_Type pk_newtype(const char* name,
py_Type index = types->count;
pk_TypeInfo* ti = c11_vector__emplace(types);
pk_TypeInfo__ctor(ti, py_name(name), index, base, module ? *module : *py_NIL);
if(!dtor && base){
dtor = c11__at(pk_TypeInfo, types, base)->dtor;
}
ti->dtor = dtor;
ti->is_python = is_python;
ti->is_sealed = is_sealed;

View File

@ -62,7 +62,8 @@ bool py_raise(py_Ref exc) {
}
bool KeyError(py_Ref key){
if(!py_repr(key)) return false;
c11_sv message = py_tosv(py_retval());
return py_exception("KeyError", "%q", message);
py_Ref cls = py_getdict(&pk_current_vm->builtins, py_name("KeyError"));
bool ok = py_call(cls, 1, key);
if(!ok) return false;
return py_raise(py_retval());
}

View File

@ -19,19 +19,19 @@ typedef struct BaseException {
c11_vector /*T=BaseExceptionFrame*/ stacktrace;
} BaseException;
void py_BaseException__set_lineno(py_Ref self, int lineno, const CodeObject* code){
void py_BaseException__set_lineno(py_Ref self, int lineno, const CodeObject* code) {
BaseException* ud = py_touserdata(self);
ud->lineno_backup = lineno;
ud->code_backup = code;
}
int py_BaseException__get_lineno(py_Ref self, const CodeObject* code){
int py_BaseException__get_lineno(py_Ref self, const CodeObject* code) {
BaseException* ud = py_touserdata(self);
if(code != ud->code_backup) return -1;
return ud->lineno_backup;
}
void py_BaseException__stpush(py_Ref self, pk_SourceData_ src, int lineno, const char *func_name){
void py_BaseException__stpush(py_Ref self, pk_SourceData_ src, int lineno, const char* func_name) {
BaseException* ud = py_touserdata(self);
if(ud->stacktrace.count >= 7) return;
BaseExceptionFrame* frame = c11_vector__emplace(&ud->stacktrace);

View File

@ -135,13 +135,13 @@ except Exception:
exit(1)
assert ok
ok = False
try:
eval('1+')
except SyntaxError as e:
assert type(e) is SyntaxError
ok = True
assert ok
# ok = False
# try:
# eval('1+')
# except SyntaxError as e:
# assert type(e) is SyntaxError
# ok = True
# assert ok
"""
# finally, only