From a8dfbc91477ba8c4c5ef901c35da3b0717466c33 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 25 Jul 2024 20:46:41 +0800 Subject: [PATCH] ... --- src/interpreter/ceval.c | 23 ++++++++--------------- src/interpreter/vm.c | 4 +++- src/public/py_object.c | 8 ++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index f5c7124d..0bf6b026 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -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; } } diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 4d8d8952..ad1e2c0c 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -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; } diff --git a/src/public/py_object.c b/src/public/py_object.c index eac38063..0d886d6e 100644 --- a/src/public/py_object.c +++ b/src/public/py_object.c @@ -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__); } \ No newline at end of file