This commit is contained in:
blueloveTH 2024-07-25 20:46:41 +08:00
parent 3ea3cf7366
commit a8dfbc9147
3 changed files with 19 additions and 16 deletions

View File

@ -82,20 +82,6 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
while(true) {
Bytecode byte;
__NEXT_FRAME:
// if(__internal_exception.type == InternalExceptionType::Null) {
// // None
// frame->_ip++;
// } else if(__internal_exception.type == InternalExceptionType::Handled) {
// // HandledException + continue
// frame->_ip = c11__at(Bytecode, &frame->co->codes, __internal_exception.arg);
// __internal_exception = {};
// } else {
// // UnhandledException + continue (need_raise = true)
// // ToBeRaisedException + continue (need_raise = true)
// __internal_exception = {};
// __raise_exc(); // no return
// }
frame->ip++;
__NEXT_STEP:
@ -939,7 +925,14 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
DISPATCH_JUMP_ABSOLUTE(target);
} else {
// 2. Exception need to be propagated to the upper frame
return RES_ERROR;
bool is_base_frame_to_be_popped = frame == base_frame;
pk_VM__pop_frame(self);
if(self->top_frame == NULL || is_base_frame_to_be_popped) {
// propagate to the top level
return RES_ERROR;
}
frame = self->top_frame;
goto __ERROR;
}
}

View File

@ -278,7 +278,9 @@ bool pk__parse_int_slice(py_Ref slice, int length, int* start, int* stop, int* s
bool pk__normalize_index(int* index, int length) {
if(*index < 0) *index += length;
if(*index < 0 || *index >= length) { return IndexError("index out of range"); }
if(*index < 0 || *index >= length) {
return IndexError("%d not in [0, %d)", *index, length);
}
return true;
}

View File

@ -57,6 +57,13 @@ static bool _py_type__repr__(int argc, py_Ref argv) {
return true;
}
static bool _py_type__new__(int argc, py_Ref argv){
PY_CHECK_ARGC(2);
py_Type type = py_typeof(py_arg(1));
py_assign(py_retval(), py_tpobject(type));
return true;
}
void pk_object__register() {
// use staticmethod
py_bindmagic(tp_object, __new__, _py_object__new__);
@ -68,4 +75,5 @@ void pk_object__register() {
// type patch...
py_bindmagic(tp_type, __repr__, _py_type__repr__);
py_bindmagic(tp_type, __new__, _py_type__new__);
}