From 7c3127c5dad8f868a1974b5bdac885d7fdabfdec Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 11 Dec 2022 14:43:12 +0100 Subject: [PATCH] :art: puts enum stuff in a separate file --- src/lib/enum.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/lib/enum.c diff --git a/src/lib/enum.c b/src/lib/enum.c new file mode 100644 index 00000000..dda25b0d --- /dev/null +++ b/src/lib/enum.c @@ -0,0 +1,28 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "gwion.h" +#include "instr.h" +#include "object.h" +#include "operator.h" +#include "import.h" +#include "gwi.h" +#include "gack.h" + +static GACK(gack_enum) { + const Map m = &t->nspc->info->value->map; + const m_uint value = *(m_uint*)VALUE; + if(value < map_size(m)) { + const Value v = (Value)map_at(&t->nspc->info->value->map, *(m_uint*)VALUE); + INTERP_PRINTF("%s", v->name); + } else + INTERP_PRINTF("%s", t->name); +} + +GWION_IMPORT(enum) { + const Type t_enum = gwi_mk_type(gwi, "enum", SZ_INT, "int"); + gwi_set_global_type(gwi, t_enum, et_enum); + gwi_gack(gwi, t_enum, gack_enum); + return GW_OK; +} -- 2.43.0