Skip to content

Commit

Permalink
Make deemon.Type implement Callable
Browse files Browse the repository at this point in the history
... since types can be called to invoke their constructors.
  • Loading branch information
GrieferAtWork committed Nov 10, 2023
1 parent afb76e6 commit 920993b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/deemon/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion src/deemon/objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <deemon/arg.h>
#include <deemon/attribute.h>
#include <deemon/bool.h>
#include <deemon/callable.h>
#include <deemon/class.h>
#include <deemon/code.h>
#include <deemon/error.h>
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
};


Expand Down
4 changes: 3 additions & 1 deletion util/test-errors.dee
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down

0 comments on commit 920993b

Please sign in to comment.