From f1c969fe765d8f12d8d1c230be4e95a6ff7f2855 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 13 Aug 2024 13:39:00 +0800 Subject: [PATCH] ... --- include/pocketpy/interpreter/vm.h | 1 + src/interpreter/vm.c | 2 +- src/public/modules.c | 4 ++-- src/public/py_method.c | 17 ++++++++--------- src/public/py_object.c | 16 ++++++++-------- src/public/py_property.c | 8 ++++---- src/public/py_slice.c | 12 ++++++------ 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/pocketpy/interpreter/vm.h b/include/pocketpy/interpreter/vm.h index 922db351..00acdc9d 100644 --- a/include/pocketpy/interpreter/vm.h +++ b/include/pocketpy/interpreter/vm.h @@ -126,6 +126,7 @@ py_Type pk_array_iterator__register(); py_Type pk_slice__register(); py_Type pk_function__register(); py_Type pk_nativefunc__register(); +py_Type pk_boundmethod__register(); py_Type pk_range__register(); py_Type pk_range_iterator__register(); py_Type pk_BaseException__register(); diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 86015a4a..28fa6d10 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -108,7 +108,7 @@ void VM__ctor(VM* self) { validate(tp_function, pk_function__register()); validate(tp_nativefunc, pk_nativefunc__register()); - validate(tp_boundmethod, pk_newtype("boundmethod", tp_object, NULL, NULL, false, true)); + validate(tp_boundmethod, pk_boundmethod__register()); validate(tp_super, pk_super__register()); validate(tp_BaseException, pk_BaseException__register()); diff --git a/src/public/modules.c b/src/public/modules.c index 70817eee..613b5b93 100644 --- a/src/public/modules.c +++ b/src/public/modules.c @@ -613,7 +613,7 @@ static void function__gc_mark(void* ud) { CodeObject__gc_mark(&func->decl->code); } -static bool function__doc__getter(int argc, py_Ref argv) { +static bool function__doc__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); Function* func = py_touserdata(py_arg(0)); if(func->decl->docstring){ @@ -630,7 +630,7 @@ py_Type pk_function__register() { pk__tp_set_marker(type, function__gc_mark); - py_bindproperty(type, "__doc__", function__doc__getter, NULL); + py_bindproperty(type, "__doc__", function__doc__, NULL); return type; } diff --git a/src/public/py_method.c b/src/public/py_method.c index 1b9c9979..fa562385 100644 --- a/src/public/py_method.c +++ b/src/public/py_method.c @@ -13,9 +13,9 @@ static bool staticmethod__new__(int argc, py_Ref argv) { return true; } -py_Type pk_staticmethod__register(){ +py_Type pk_staticmethod__register() { py_Type type = pk_newtype("staticmethod", tp_object, NULL, NULL, false, true); - + py_bindmagic(type, __new__, staticmethod__new__); return type; } @@ -28,7 +28,7 @@ static bool classmethod__new__(int argc, py_Ref argv) { return true; } -py_Type pk_classmethod__register(){ +py_Type pk_classmethod__register() { py_Type type = pk_newtype("classmethod", tp_object, NULL, NULL, false, true); py_bindmagic(type, __new__, classmethod__new__); @@ -36,22 +36,21 @@ py_Type pk_classmethod__register(){ } /* boundmethod */ -static bool boundmethod__self__getter(int argc, py_Ref argv) { +static bool boundmethod__self__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_assign(py_retval(), py_getslot(argv, 0)); return true; } -static bool boundmethod__func__getter(int argc, py_Ref argv) { +static bool boundmethod__func__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_assign(py_retval(), py_getslot(argv, 1)); return true; } -py_Type pk_boundmethod__register(){ +py_Type pk_boundmethod__register() { py_Type type = pk_newtype("boundmethod", tp_object, NULL, NULL, false, true); - - py_bindproperty(type, "__self__", boundmethod__self__getter, NULL); - py_bindproperty(type, "__func__", boundmethod__func__getter, NULL); + py_bindproperty(type, "__self__", boundmethod__self__, NULL); + py_bindproperty(type, "__func__", boundmethod__func__, NULL); return type; } \ No newline at end of file diff --git a/src/public/py_object.c b/src/public/py_object.c index baa37a6a..1cc97e55 100644 --- a/src/public/py_object.c +++ b/src/public/py_object.c @@ -44,7 +44,7 @@ static bool object__repr__(int argc, py_Ref argv) { return true; } -static bool object__dict__getter(int argc, py_Ref argv) { +static bool object__dict__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); if(argv->is_ptr && argv->_obj->slots == -1) { pk_mappingproxy__namedict(py_retval(), argv); @@ -70,7 +70,7 @@ static bool type__new__(int argc, py_Ref argv) { return true; } -static bool type__base__getter(int argc, py_Ref argv) { +static bool type__base__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_Type type = py_totype(argv); py_TypeInfo* ti = c11__at(py_TypeInfo, &pk_current_vm->types, type); @@ -82,7 +82,7 @@ static bool type__base__getter(int argc, py_Ref argv) { return true; } -static bool type__name__getter(int argc, py_Ref argv) { +static bool type__name__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_Type type = py_totype(argv); py_TypeInfo* ti = c11__at(py_TypeInfo, &pk_current_vm->types, type); @@ -95,7 +95,7 @@ static bool type__getitem__(int argc, py_Ref argv) { return true; } -static bool type__module__getter(int argc, py_Ref argv) { +static bool type__module__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_Type type = py_totype(argv); py_TypeInfo* ti = c11__at(py_TypeInfo, &pk_current_vm->types, type); @@ -116,13 +116,13 @@ void pk_object__register() { py_bindmagic(tp_object, __eq__, object__eq__); py_bindmagic(tp_object, __ne__, object__ne__); py_bindmagic(tp_object, __repr__, object__repr__); - py_bindproperty(tp_object, "__dict__", object__dict__getter, NULL); + py_bindproperty(tp_object, "__dict__", object__dict__, NULL); py_bindmagic(tp_type, __repr__, type__repr__); py_bindmagic(tp_type, __new__, type__new__); py_bindmagic(tp_type, __getitem__, type__getitem__); - py_bindproperty(tp_type, "__module__", type__module__getter, NULL); + py_bindproperty(tp_type, "__module__", type__module__, NULL); - py_bindproperty(tp_type, "__base__", type__base__getter, NULL); - py_bindproperty(tp_type, "__name__", type__name__getter, NULL); + py_bindproperty(tp_type, "__base__", type__base__, NULL); + py_bindproperty(tp_type, "__name__", type__name__, NULL); } \ No newline at end of file diff --git a/src/public/py_property.c b/src/public/py_property.c index bc8fe7fe..0f93f78c 100644 --- a/src/public/py_property.c +++ b/src/public/py_property.c @@ -25,14 +25,14 @@ static bool property_setter(int argc, py_Ref argv) { return true; } -static bool property_fget__getter(int argc, py_Ref argv) { +static bool property_fget(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_Ref fget = py_getslot(argv, 0); py_assign(py_retval(), fget); return true; } -static bool property_fset__getter(int argc, py_Ref argv) { +static bool property_fset(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_Ref fset = py_getslot(argv, 1); py_assign(py_retval(), fset); @@ -45,7 +45,7 @@ py_Type pk_property__register() { py_bindmagic(type, __new__, property__new__); py_bindmethod(type, "setter", property_setter); - py_bindproperty(type, "fget", property_fget__getter, NULL); - py_bindproperty(type, "fset", property_fset__getter, NULL); + py_bindproperty(type, "fget", property_fget, NULL); + py_bindproperty(type, "fset", property_fset, NULL); return type; } diff --git a/src/public/py_slice.c b/src/public/py_slice.c index dc2dc19a..b6ee5885 100644 --- a/src/public/py_slice.c +++ b/src/public/py_slice.c @@ -42,21 +42,21 @@ static bool slice__repr__(int argc, py_Ref argv) { return true; } -static bool slice_start__getter(int argc, py_Ref argv) { +static bool slice_start(int argc, py_Ref argv) { py_Ref self = py_arg(0); py_TValue* val = py_getslot(self, 0); py_assign(py_retval(), val); return true; } -static bool slice_stop__getter(int argc, py_Ref argv) { +static bool slice_stop(int argc, py_Ref argv) { py_Ref self = py_arg(0); py_TValue* val = py_getslot(self, 1); py_assign(py_retval(), val); return true; } -static bool slice_step__getter(int argc, py_Ref argv) { +static bool slice_step(int argc, py_Ref argv) { py_Ref self = py_arg(0); py_TValue* val = py_getslot(self, 2); py_assign(py_retval(), val); @@ -69,8 +69,8 @@ py_Type pk_slice__register() { py_bindmagic(type, __new__, slice__new__); py_bindmagic(type, __repr__, slice__repr__); - py_bindproperty(type, "start", slice_start__getter, NULL); - py_bindproperty(type, "stop", slice_stop__getter, NULL); - py_bindproperty(type, "step", slice_step__getter, NULL); + py_bindproperty(type, "start", slice_start, NULL); + py_bindproperty(type, "stop", slice_stop, NULL); + py_bindproperty(type, "step", slice_step, NULL); return type; } \ No newline at end of file