From 6d609950f99e74e2681fe149c1c67bda2ae5f176 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 5 Nov 2020 16:23:25 +0100 Subject: [PATCH] :white_check_mark: Test struct import --- include/import/cdef.h | 1 + tests/plug/op_already_imported.c | 1 - tests/plug/struct.c | 43 ++++++++++++++++++++++++++++++++ tests/plug/struct.gw | 18 +++++++++++++ tests/sh/import.sh | 2 +- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/plug/struct.c create mode 100644 tests/plug/struct.gw diff --git a/include/import/cdef.h b/include/import/cdef.h index 25722edc..3cdb9728 100644 --- a/include/import/cdef.h +++ b/include/import/cdef.h @@ -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 diff --git a/tests/plug/op_already_imported.c b/tests/plug/op_already_imported.c index 0454a3f1..4a527ec7 100644 --- a/tests/plug/op_already_imported.c +++ b/tests/plug/op_already_imported.c @@ -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 index 00000000..0f95038c --- /dev/null +++ b/tests/plug/struct.c @@ -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 index 00000000..d3ecf582 --- /dev/null +++ b/tests/plug/struct.gw @@ -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] >>>; diff --git a/tests/sh/import.sh b/tests/sh/import.sh index 96a20e0d..93aacb3f 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #78 +# [test] #79 n=0 [ "$1" ] && n="$1" -- 2.43.0