]> Nishi Git Mirror - gwion.git/commitdiff
:art: puts enum stuff in a separate file
authorfennecdjay <fennecdjay@gmail.com>
Sun, 11 Dec 2022 13:43:12 +0000 (14:43 +0100)
committerfennecdjay <fennecdjay@gmail.com>
Sun, 11 Dec 2022 13:43:12 +0000 (14:43 +0100)
src/lib/enum.c [new file with mode: 0644]

diff --git a/src/lib/enum.c b/src/lib/enum.c
new file mode 100644 (file)
index 0000000..dda25b0
--- /dev/null
@@ -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;
+}