fx: re-arrange type system to allow for reflection
This commit is contained in:
@@ -35,7 +35,7 @@ struct map {
|
||||
|
||||
struct type {
|
||||
struct map_item e_map_item;
|
||||
fx_type e_type;
|
||||
fx_type_id e_type;
|
||||
};
|
||||
|
||||
struct fx_assembly_p {
|
||||
@@ -131,7 +131,7 @@ static void assembly_set_version(
|
||||
static void assembly_add_type(
|
||||
struct fx_assembly_p *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
fx_type_id type_id)
|
||||
{
|
||||
struct type *type = malloc(sizeof *type);
|
||||
memset(type, 0x0, sizeof *type);
|
||||
@@ -218,7 +218,7 @@ void fx_assembly_set_version(
|
||||
void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
fx_type_id type_id)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
@@ -249,11 +249,11 @@ static void assembly_fini(fx_object *obj, void *priv)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_string DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_assembly)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_assembly)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_assembly)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_ID(0xf6690c30, 0x6642, 0x42f0, 0xb79f, 0xe2baf3684b1b);
|
||||
|
||||
@@ -178,14 +178,15 @@ static void function_fini(fx_object *obj, void *priv)
|
||||
/*** CLASS DEFINITION
|
||||
* *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_function)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_function)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_function)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_function)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_function)
|
||||
FX_TYPE_ID(0x09e40174, 0x7443, 0x486e, 0xad21, 0xcc9374762e7e);
|
||||
FX_TYPE_NAME("fx.reflection.function");
|
||||
FX_TYPE_CLASS(fx_function_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_function_p);
|
||||
FX_TYPE_INSTANCE_INIT(function_init);
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_assembly);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_assembly)
|
||||
|
||||
FX_API fx_type fx_assembly_get_type();
|
||||
FX_API fx_type_id fx_assembly_get_type();
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_assembly, FX_REFLECTION_TYPE_ASSEMBLY);
|
||||
|
||||
@@ -27,11 +27,10 @@ FX_API void fx_assembly_set_version(
|
||||
FX_API void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id);
|
||||
fx_type_id type_id);
|
||||
|
||||
FX_API void fx_assembly_dump(const fx_assembly *asm);
|
||||
|
||||
FX_DECLS_END
|
||||
;
|
||||
FX_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@ FX_DECLARE_TYPE(fx_function);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_function)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_function)
|
||||
|
||||
FX_API fx_type fx_function_get_type();
|
||||
FX_API fx_type_id fx_function_get_type();
|
||||
|
||||
FX_API fx_function *fx_function_create(
|
||||
const char *name,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef FX_REFLECTION_TYPE_H_
|
||||
#define FX_REFLECTION_TYPE_H_
|
||||
|
||||
#include <fx/macros.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
struct fx_type_info;
|
||||
|
||||
#define FX_REFLECTION_TYPE_TYPE (fx_type_get_type())
|
||||
|
||||
FX_DECLARE_TYPE(fx_type);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_type)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_type)
|
||||
|
||||
FX_API fx_type_id fx_type_get_type();
|
||||
|
||||
FX_API const char *fx_type_get_name(const fx_type *ty);
|
||||
|
||||
FX_API const fx_type *fx_type_get_by_id(fx_type_id id);
|
||||
FX_API const fx_type *fx_type_get_by_name(const char *name);
|
||||
|
||||
FX_API fx_type *__fx_type_create(struct fx_type_info *opaque);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <fx/macros.h>
|
||||
#include <fx/reflection/type.h>
|
||||
#include <fx/type.h>
|
||||
|
||||
struct fx_type_registration;
|
||||
|
||||
struct fx_type_p {
|
||||
struct fx_type_info *ty_info;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
extern struct fx_type_info *fx_type_info_get_by_id(const union fx_type_id *key);
|
||||
extern struct fx_type_info *fx_type_info_get_by_name(const char *name);
|
||||
|
||||
static const char *type_get_name(const struct fx_type_p *ty)
|
||||
{
|
||||
return ty->ty_info->ty_name;
|
||||
}
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_type *__fx_type_create(struct fx_type_info *type_info)
|
||||
{
|
||||
fx_type *out = fx_object_create(FX_REFLECTION_TYPE_TYPE);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_type_p *p = fx_object_get_private(
|
||||
out,
|
||||
FX_REFLECTION_TYPE_TYPE);
|
||||
p->ty_info = type_info;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
const char *fx_type_get_name(const fx_type *ty)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_REFLECTION_TYPE_TYPE, type_get_name, ty);
|
||||
}
|
||||
|
||||
const fx_type *fx_type_get_by_id(fx_type_id id)
|
||||
{
|
||||
struct fx_type_info *ty = fx_type_info_get_by_id(id);
|
||||
return ty ? ty->ty_metatype : NULL;
|
||||
}
|
||||
|
||||
const fx_type *fx_type_get_by_name(const char *name)
|
||||
{
|
||||
struct fx_type_info *ty = fx_type_info_get_by_name(name);
|
||||
return ty ? ty->ty_metatype : NULL;
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static void type_init(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
static void type_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_BEGIN(fx_type)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_type)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_type)
|
||||
FX_TYPE_ID(0xec8b2679, 0x5c73, 0x4ec9, 0xa04e, 0x3f72881b5b5a);
|
||||
FX_TYPE_NAME("fx.reflection.type");
|
||||
FX_TYPE_CLASS(fx_type_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_type_p);
|
||||
FX_TYPE_INSTANCE_INIT(type_init);
|
||||
FX_TYPE_INSTANCE_FINI(type_fini);
|
||||
FX_TYPE_DEFINITION_END(fx_type)
|
||||
Reference in New Issue
Block a user