From 920993bea0fd0c48442c2e5df73398f6ae9e417f Mon Sep 17 00:00:00 2001 From: GrieferAtWork Date: Fri, 10 Nov 2023 12:00:14 +0100 Subject: [PATCH] Make `deemon.Type` implement `Callable` ... since types can be called to invoke their constructors. --- include/deemon/object.h | 2 +- src/deemon/objects/object.c | 10 +++++++++- util/test-errors.dee | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/deemon/object.h b/include/deemon/object.h index da09f845a..f35a97be9 100644 --- a/include/deemon/object.h +++ b/include/deemon/object.h @@ -2540,7 +2540,7 @@ struct Dee_type_object { * extra instance fields (i.e. have the `TP_FABSTRACT' flag set). * As such, these types essentially only act as interface definitions, * with the ability to define fixed functions and operations, - * thought no actual instance members, but not as actual types + * thought no actual instance members, and not as actual types * when it comes to instancing. * - Constructors/Destructors of MRO bases are NOT invoked by default. * They are only invoked if sub-classed by a user-defined class type. diff --git a/src/deemon/objects/object.c b/src/deemon/objects/object.c index 20b436dab..191bec133 100644 --- a/src/deemon/objects/object.c +++ b/src/deemon/objects/object.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -4439,8 +4440,14 @@ PRIVATE struct type_gc tpconst type_gc_data = { /* .tp_gcprio = */ Dee_GC_PRIORITY_CLASS }; +PRIVATE DeeTypeObject *tpconst type_mro[] = { + &DeeObject_Type, + &DeeCallable_Type, /* Types can be called to invoke their constructor, so have them implement deemon.Callable. */ + NULL, +}; + PUBLIC DeeTypeObject DeeType_Type = { - OBJECT_HEAD_INIT(&DeeType_Type), + OBJECT_HEAD_INIT(&DeeType_Type), /* The type of Type is Type :D */ /* .tp_name = */ DeeString_STR(&str_Type), /* .tp_doc = */ DOC("The so-called Type-Type, that is the type of anything that " /**/ "is also a Type, such as ?Dint or ?DList, or even itself"), @@ -4486,6 +4493,7 @@ PUBLIC DeeTypeObject DeeType_Type = { /* .tp_class_getsets = */ NULL, /* .tp_class_members = */ NULL, /* .tp_call_kw = */ (DeeObject *(DCALL *)(DeeObject *, size_t, DeeObject *const *, DeeObject *))&DeeObject_NewKw, + /* .tp_mro = */ type_mro }; diff --git a/util/test-errors.dee b/util/test-errors.dee index 2d02e608f..108fdde20 100644 --- a/util/test-errors.dee +++ b/util/test-errors.dee @@ -261,7 +261,9 @@ function main() { //invokeTypeMembers(deemon.List); //invokeTypeMembers(deemon.Tuple); //invokeTypeMembers(deemon.Sequence); - invokeTypeMembers(deemon.Object); + //invokeTypeMembers(deemon.Object); + //invokeTypeMembers(deemon.bool); + //invokeTypeMembers(type(none)); }