]> Nishi Git Mirror - gwion.git/commitdiff
:art: Test enum import
authorfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 11 Oct 2019 21:46:19 +0000 (23:46 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 11 Oct 2019 21:46:19 +0000 (23:46 +0200)
src/lib/import.c
tests/import/Makefile
tests/import/enum_fail.c [new file with mode: 0644]
tests/import/enum_fail2.c [new file with mode: 0644]
tests/sh/import.sh

index af8af4b027127161a44f9dd5ad7cb77df7e9c968..102317c6ddd67c6edb0f36ccef15c4d68ee98702 100644 (file)
@@ -678,13 +678,9 @@ ANN Type gwi_enum_end(const Gwi gwi) {
   DL_Enum* d = &gwi->enum_data;
   const Enum_Def edef  = new_enum_def(gwi->gwion->mp, d->base, d->t ? insert_symbol(gwi->gwion->st, d->t) : NULL, 
     loc_cpy(gwi->gwion->mp, gwi->loc));
-  if(traverse_enum_def(gwi->gwion->env, edef) < 0) {
-    if(!edef->t)
-      free_enum_def(gwi->gwion->mp, edef);
-    return NULL;
-  }
+  const m_bool ret = traverse_enum_def(gwi->gwion->env, edef);
   import_enum_end(gwi, &edef->values);
-  const Type t =edef->t;
+  const Type t = ret > 0 ? edef->t : NULL;
   free_enum_def(gwi->gwion->mp, edef);
   return t;
 }
index e7f73371e4ef3bced01ef96b622ab60a126412aa..8d0336baeb9df5e5a3ec966242f0cd97d0903873 100644 (file)
@@ -4,7 +4,7 @@ CC       ?= gcc
 NAME := ${NAME}
 SRC = ${NAME}.c
 OBJ = $(SRC:.c=.o)
-CFLAGS   = -std=c99 $(../../gwion -k 2>&1 | grep CFLAGS | sed 's/CFLAGS: //') ${INC} ${CICFLAGS} -Wall -Wextra
+CFLAGS   = -std=c99 $(../../gwion -k 2>&1 | grep CFLAGS | sed 's/CFLAGS: //') ${INC} ${CICFLAGS} -Wall -Wextra -g -Og
 LDFLAGS   = $(../../gwion -k 2>&1 | grep LDFLAGS)
 
 # os specific
diff --git a/tests/import/enum_fail.c b/tests/import/enum_fail.c
new file mode 100644 (file)
index 0000000..8071ad4
--- /dev/null
@@ -0,0 +1,19 @@
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "vm.h"
+#include "env.h"
+#include "type.h"
+#include "object.h"
+#include "instr.h"
+#include "gwion.h"
+#include "value.h"
+#include "operator.h"
+#include "import.h"
+
+GWION_IMPORT(enum_test) {
+  GWI_BB(gwi_enum_ini(gwi, "int"))
+    GWI_BB(gwi_enum_add(gwi, "zero", 0))
+  GWI_OB(gwi_enum_end(gwi))
+  return GW_OK;
+}
diff --git a/tests/import/enum_fail2.c b/tests/import/enum_fail2.c
new file mode 100644 (file)
index 0000000..6f5550b
--- /dev/null
@@ -0,0 +1,19 @@
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "vm.h"
+#include "env.h"
+#include "type.h"
+#include "object.h"
+#include "instr.h"
+#include "gwion.h"
+#include "value.h"
+#include "operator.h"
+#include "import.h"
+
+GWION_IMPORT(enum_test) {
+  GWI_BB(gwi_enum_ini(gwi, NULL))
+    GWI_BB(gwi_enum_add(gwi, "adc", 0))
+  GWI_OB(gwi_enum_end(gwi))
+  return GW_OK;
+}
index af464767b1cd4e9dc711f703ca665606296c30ae..ab2028c6dcd3de158027b9b01799cd8a2366671a 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# [test] #41
+# [test] #43
 
 n=0
 [ "$1" ] && n="$1"