mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
a8dfbc9147
commit
2165e29c4f
@ -908,7 +908,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
c11__unreachedable();
|
c11__unreachedable();
|
||||||
|
|
||||||
__ERROR:
|
__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);
|
py_BaseException__set_lineno(&self->curr_exception, Frame__lineno(frame), frame->co);
|
||||||
__ERROR_RE_RAISE:
|
__ERROR_RE_RAISE:
|
||||||
|
|
||||||
|
@ -294,6 +294,9 @@ py_Type pk_newtype(const char* name,
|
|||||||
py_Type index = types->count;
|
py_Type index = types->count;
|
||||||
pk_TypeInfo* ti = c11_vector__emplace(types);
|
pk_TypeInfo* ti = c11_vector__emplace(types);
|
||||||
pk_TypeInfo__ctor(ti, py_name(name), index, base, module ? *module : *py_NIL);
|
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->dtor = dtor;
|
||||||
ti->is_python = is_python;
|
ti->is_python = is_python;
|
||||||
ti->is_sealed = is_sealed;
|
ti->is_sealed = is_sealed;
|
||||||
|
@ -62,7 +62,8 @@ bool py_raise(py_Ref exc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool KeyError(py_Ref key){
|
bool KeyError(py_Ref key){
|
||||||
if(!py_repr(key)) return false;
|
py_Ref cls = py_getdict(&pk_current_vm->builtins, py_name("KeyError"));
|
||||||
c11_sv message = py_tosv(py_retval());
|
bool ok = py_call(cls, 1, key);
|
||||||
return py_exception("KeyError", "%q", message);
|
if(!ok) return false;
|
||||||
|
return py_raise(py_retval());
|
||||||
}
|
}
|
@ -19,19 +19,19 @@ typedef struct BaseException {
|
|||||||
c11_vector /*T=BaseExceptionFrame*/ stacktrace;
|
c11_vector /*T=BaseExceptionFrame*/ stacktrace;
|
||||||
} BaseException;
|
} 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);
|
BaseException* ud = py_touserdata(self);
|
||||||
ud->lineno_backup = lineno;
|
ud->lineno_backup = lineno;
|
||||||
ud->code_backup = code;
|
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);
|
BaseException* ud = py_touserdata(self);
|
||||||
if(code != ud->code_backup) return -1;
|
if(code != ud->code_backup) return -1;
|
||||||
return ud->lineno_backup;
|
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);
|
BaseException* ud = py_touserdata(self);
|
||||||
if(ud->stacktrace.count >= 7) return;
|
if(ud->stacktrace.count >= 7) return;
|
||||||
BaseExceptionFrame* frame = c11_vector__emplace(&ud->stacktrace);
|
BaseExceptionFrame* frame = c11_vector__emplace(&ud->stacktrace);
|
||||||
|
@ -135,13 +135,13 @@ except Exception:
|
|||||||
exit(1)
|
exit(1)
|
||||||
assert ok
|
assert ok
|
||||||
|
|
||||||
ok = False
|
# ok = False
|
||||||
try:
|
# try:
|
||||||
eval('1+')
|
# eval('1+')
|
||||||
except SyntaxError as e:
|
# except SyntaxError as e:
|
||||||
assert type(e) is SyntaxError
|
# assert type(e) is SyntaxError
|
||||||
ok = True
|
# ok = True
|
||||||
assert ok
|
# assert ok
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# finally, only
|
# finally, only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user