From: fennecdjay Date: Sun, 11 Dec 2022 13:43:12 +0000 (+0100) Subject: :art: puts enum stuff in a separate file X-Git-Tag: nightly~207^2~45 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7c3127c5dad8f868a1974b5bdac885d7fdabfdec;p=gwion.git :art: puts enum stuff in a separate file --- 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; +}