From 14433b1210a3ebd7aa5868c9944ed93f453064bd Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 5 Apr 2023 17:43:34 +0800 Subject: [PATCH] up --- src/ceval.h | 41 +++++++++++++++++++++++------------------ src/compiler.h | 3 ++- src/opcodes.h | 9 +++++---- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/ceval.h b/src/ceval.h index e7b91b95..2a7a1308 100644 --- a/src/ceval.h +++ b/src/ceval.h @@ -319,6 +319,7 @@ __NEXT_STEP:; if(item == nullptr) ValueError("not enough values to unpack"); frame->push(item); } + // handle extra items if(byte.op == OP_UNPACK_EX){ List extras; while(true){ @@ -332,25 +333,29 @@ __NEXT_STEP:; } }; DISPATCH(); /*****************************************/ + case OP_BEGIN_CLASS: { + StrName name = frame->co->names[byte.arg]; + PyObject* super_cls = frame->popx(); + if(super_cls == None) super_cls = _t(tp_object); + check_type(super_cls, tp_type); + PyObject* cls = new_type_object(frame->_module, name, OBJ_GET(Type, super_cls)); + frame->push(cls); + } DISPATCH(); + case OP_END_CLASS: { + PyObject* cls = frame->popx(); + cls->attr()._try_perfect_rehash(); + }; DISPATCH(); + case OP_STORE_CLASS_ATTR: { + StrName name = frame->co->names[byte.arg]; + PyObject* obj = frame->popx(); + PyObject* cls = frame->top(); + cls->attr().set(name, obj); + } DISPATCH(); + /*****************************************/ + /*****************************************/ + /*****************************************/ // case OP_SETUP_DECORATOR: DISPATCH(); - // case OP_BEGIN_CLASS: { - // StrName name = frame->co->names[byte.arg]; - // PyObject* clsBase = frame->popx(); - // if(clsBase == None) clsBase = _t(tp_object); - // check_type(clsBase, tp_type); - // PyObject* cls = new_type_object(frame->_module, name, OBJ_GET(Type, clsBase)); - // frame->push(cls); - // } DISPATCH(); - // case OP_END_CLASS: { - // PyObject* cls = frame->popx(); - // cls->attr()._try_perfect_rehash(); - // }; DISPATCH(); - // case OP_STORE_CLASS_ATTR: { - // StrName name = frame->co->names[byte.arg]; - // PyObject* obj = frame->popx(); - // PyObject* cls = frame->top(); - // cls->attr().set(name, obj); - // } DISPATCH(); + // case OP_ASSERT: { // PyObject* _msg = frame->pop_value(this); // Str msg = CAST(Str, asStr(_msg)); diff --git a/src/compiler.h b/src/compiler.h index 9b070200..c4d2be1f 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -835,7 +835,8 @@ class Compiler { ctx()->emit(OP_STORE_ATTR, index, prev().line); } }else{ - ctx()->emit(OP_STORE_CLASS_ATTR, ctx()->add_name(decl->name), BC_KEEPLINE); + int index = ctx()->add_name(decl->name); + ctx()->emit(OP_STORE_CLASS_ATTR, index, prev().line); } } diff --git a/src/opcodes.h b/src/opcodes.h index 46a81360..7ba77d2a 100644 --- a/src/opcodes.h +++ b/src/opcodes.h @@ -18,10 +18,6 @@ OPCODE(YIELD_VALUE) OPCODE(SETUP_DECORATOR) -OPCODE(BEGIN_CLASS) -OPCODE(END_CLASS) -OPCODE(STORE_CLASS_ATTR) - /**************************/ OPCODE(NO_OP) /**************************/ @@ -96,4 +92,9 @@ OPCODE(IMPORT_STAR) OPCODE(UNPACK_SEQUENCE) OPCODE(UNPACK_EX) /**************************/ +// TODO: examine this +OPCODE(BEGIN_CLASS) +OPCODE(END_CLASS) +OPCODE(STORE_CLASS_ATTR) +/**************************/ #endif \ No newline at end of file