]> Nishi Git Mirror - gwion.git/commitdiff
:white_check_mark: Test struct import
authorfennecdjay <fennecdjay@gwion.tk>
Thu, 5 Nov 2020 15:23:25 +0000 (16:23 +0100)
committerfennecdjay <fennecdjay@gwion.tk>
Thu, 5 Nov 2020 15:23:25 +0000 (16:23 +0100)
include/import/cdef.h
tests/plug/op_already_imported.c
tests/plug/struct.c [new file with mode: 0644]
tests/plug/struct.gw [new file with mode: 0644]
tests/sh/import.sh

index 25722edcfc6bcb0d7ec3248c2c74c30afbc661d0..3cdb9728fae791eea50f5c2562f489bbed82d804 100644 (file)
@@ -4,5 +4,6 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str, const m_str parent);
 ANN2(1,2) Type gwi_struct_ini(const Gwi gwi, const m_str);
 ANN2(1) void gwi_class_xtor(const Gwi gwi, const f_xtor ctor, const f_xtor dtor);
 ANN m_int gwi_class_end(const Gwi gwi);
+#define gwi_struct_end(a) gwi_class_end(a)
 ANN void inherit(const Type);
 #endif
index 0454a3f1ad40917de42b1c6bb3534a14f0860f38..4a527ec757a5f8d9dc8499db0469e328292141c4 100644 (file)
@@ -11,7 +11,6 @@
 #include "import.h"
 #include "gwi.h"
 
-
 GWION_IMPORT(op_already_imported) {
   GWI_BB(gwi_oper_ini(gwi, "int", "int", "int"))
   GWI_BB(gwi_oper_end(gwi, "=>", NULL))
diff --git a/tests/plug/struct.c b/tests/plug/struct.c
new file mode 100644 (file)
index 0000000..0f95038
--- /dev/null
@@ -0,0 +1,43 @@
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "gwion_env.h"
+#include "vm.h"
+#include "object.h"
+#include "instr.h"
+#include "gwion.h"
+#include "operator.h"
+#include "import.h"
+#include "gwi.h"
+
+SFUN(coverage_int)     { *(m_uint*)RETURN    = 0; }
+SFUN(coverage_float)   { *(m_float*)RETURN   = 0; }
+
+GWION_IMPORT(coverage) {
+  GWI_OB(gwi_struct_ini(gwi, "Struct"))
+  GWI_BB(gwi_func_ini(gwi, "int", "i"))
+  GWI_BB(gwi_func_end(gwi, coverage_int, ae_flag_static))
+  GWI_BB(gwi_func_ini(gwi, "float", "f"))
+  GWI_BB(gwi_func_end(gwi, coverage_float, ae_flag_static))
+
+  ALLOC_PTR(gwi->gwion->mp, i, m_uint, 5);
+  GWI_BB(gwi_item_ini(gwi,"int", "s_i"))
+  GWI_BB(gwi_item_end(gwi, ae_flag_static, i))
+
+  ALLOC_PTR(gwi->gwion->mp, f, m_float, 2.1);
+  GWI_BB(gwi_item_ini(gwi,"int", "s_f"))
+  GWI_BB(gwi_item_end(gwi, ae_flag_static, (void*)f))
+
+  ALLOC_PTR(gwi->gwion->mp, ci, m_uint, 5);
+  GWI_BB(gwi_item_ini(gwi,"int", "sc_i"))
+  GWI_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, ci))
+
+  ALLOC_PTR(gwi->gwion->mp, cf, m_float, 2.1);
+  GWI_BB(gwi_item_ini(gwi,"float", "sc_f"))
+  GWI_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cf))
+
+  GWI_BB(gwi_item_ini(gwi,"int[][]", "test_array"))
+  GWI_BB(gwi_item_end(gwi, ae_flag_none, NULL))
+
+  GWI_BB(gwi_struct_end(gwi))
+  return GW_OK;
+}
diff --git a/tests/plug/struct.gw b/tests/plug/struct.gw
new file mode 100644 (file)
index 0000000..d3ecf58
--- /dev/null
@@ -0,0 +1,18 @@
+#require struct
+
+<<< var float f >>>;
+var Struct c;
+c.s_i;
+<<<  Coverage.i()  >>>;
+<<<  Coverage.f()  >>>;
+
+<<< Coverage.s_i  >>>;
+<<< Coverage.s_f  >>>;
+
+<<< Coverage.sc_i  >>>;
+<<< Coverage.sc_f  >>>;
+
+<<<  1 => Coverage.s_i  >>>;
+<<<  1.2 => Coverage.s_f  >>>;
+
+<<< c.test_array[0][0] >>>;
index 96a20e0d31d19bd3c71774a0f298880d0be38667..93aacb3f09aaedab4193c9d2ef18e136aeca3cf2 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# [test] #78
+# [test] #79
 
 n=0
 [ "$1" ] && n="$1"