From c70fc55871ff71f71ce22603cb7b9b2501604108 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 24 Sep 2019 22:41:15 +0200 Subject: [PATCH] :art: Add global types array --- include/gwion.h | 1 + include/import.h | 1 + include/type.h | 8 +++++++- src/gwion.c | 3 +++ src/lib/engine.c | 2 +- src/lib/import.c | 6 ++++++ src/plug.c | 1 + 7 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/gwion.h b/include/gwion.h index 18046403..f7393e36 100644 --- a/include/gwion.h +++ b/include/gwion.h @@ -15,6 +15,7 @@ struct Gwion_ { struct GwionData_ *data; SymTable *st; MemPool mp; + Type *type; }; ANN m_bool gwion_ini(const Gwion, struct Arg_*); diff --git a/include/import.h b/include/import.h index 8db7f574..d3bc83e9 100644 --- a/include/import.h +++ b/include/import.h @@ -33,6 +33,7 @@ typedef struct Gwi_* Gwi; ANN VM* gwi_vm(const Gwi); ANN2(1,2) ANEW Type gwi_mk_type(const Gwi, const m_str, const m_uint, const Type); ANN m_int gwi_add_type(const Gwi gwi, Type type); +ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te); ANN2(1,2)m_int gwi_class_ini(const Gwi gwi, const Type type, const f_xtor pre_ctor, const f_xtor dtor); ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td); ANN m_int gwi_class_end(const Gwi gwi); diff --git a/include/type.h b/include/type.h index e55834ac..05f79e1f 100644 --- a/include/type.h +++ b/include/type.h @@ -52,5 +52,11 @@ ANN static inline m_bool is_fptr(const Type t) { return isa(actual_type(t), t_fptr) > 0; } ANN m_uint get_depth(const Type type); -#endif +typedef enum { + et_void, et_int, et_bool, et_float, et_dur, et_time, et_now, et_complex, et_polar, et_vec3, et_vec4, + et_null, et_object, et_shred, et_fork, et_event, et_ugen, et_string, et_ptr, et_array, zt_gack, + et_function, et_fptr, et_varloop, et_vararg, et_lambda, et_class, et_union, et_undefined, et_auto, et_tuple, + MAX_TYPE +} type_enum; +#endif diff --git a/src/gwion.c b/src/gwion.c index e26a9202..e5948975 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -57,6 +57,7 @@ ANN VM* gwion_cpy(const VM* src) { gwion->data = src->gwion->data; gwion->st = src->gwion->st; gwion->mp = src->gwion->mp; + gwion->type = src->gwion->type; return gwion->vm; } @@ -72,6 +73,7 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { gwion->env->gwion = gwion; gwion->vm->bbq->si = new_soundinfo(gwion->mp); gwion->data = new_gwiondata(gwion->mp); + gwion->type = xmalloc(MAX_TYPE * sizeof(struct Type_)); pass_default(gwion); arg->si = gwion->vm->bbq->si; const m_bool ret = arg_parse(gwion, arg); @@ -108,6 +110,7 @@ ANN void gwion_end(const Gwion gwion) { free_plug(gwion); free_gwiondata(gwion->mp, gwion->data); free_symbols(gwion->st); + xfree(gwion->type); mempool_end(gwion->mp); } diff --git a/src/lib/engine.c b/src/lib/engine.c index 03e67e03..824f6114 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -45,7 +45,7 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(gwi_add_type(gwi, t_auto)) SET_FLAG(t_class, abstract); GWI_OB((t_void = gwi_mk_type(gwi, "void", 0, NULL))) - GWI_BB(gwi_add_type(gwi, t_void)) + GWI_BB(gwi_set_global_type(gwi, t_void, et_void)) GWI_OB((t_null = gwi_mk_type(gwi, "@null", SZ_INT, NULL))) GWI_BB(gwi_add_type(gwi, t_null)) GWI_OB((t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL))) diff --git a/src/lib/import.c b/src/lib/import.c index 6391fce5..e9c8cefa 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -198,6 +198,12 @@ ANN m_int gwi_add_type(const Gwi gwi, const Type type) { return (m_int)type->xid; } +ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) { + GWI_BB(gwi_add_type(gwi, type)) + gwi->gwion->type[te] = type; + return GW_OK; +} + ANN2(1,2) static void import_class_ini(const Env env, const Type type, const f_xtor pre_ctor, const f_xtor dtor) { type->nspc = new_nspc(env->gwion->mp, type->name); diff --git a/src/plug.c b/src/plug.c index e3611a15..19313806 100644 --- a/src/plug.c +++ b/src/plug.c @@ -14,6 +14,7 @@ #include "operator.h" #include "instr.h" #include "object.h" +#include "type.h" #include "import.h" typedef m_bool (*import)(Gwi); -- 2.43.0