Gwion coverage report


Directory: src/
File: src/lib/lib_gack.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 11 31 35.5%
Functions: 1 4 25.0%
Branches: 2 10 20.0%

Line Branch Exec Source
1 #include "gwion_util.h"
2 #include "gwion_ast.h"
3 #include "gwion_env.h"
4 #include "vm.h"
5 #include "instr.h"
6 #include "emit.h"
7 #include "gwion.h"
8 #include "object.h"
9 #include "operator.h"
10 #include "import.h"
11 #include "gwi.h"
12 #include "gack.h"
13
14 static GACK(gack_gack) { INTERP_PRINTF("%s", *(m_str *)VALUE) }
15
16 static OP_CHECK(opck_gack_implicit) {
17 const struct Implicit *imp = (struct Implicit *)data;
18 return imp->t;
19 }
20
21 static OP_EMIT(opem_gack_implicit) {
22 const struct Implicit *imp = (struct Implicit *)data;
23 const Type t = imp->e->d.prim.d.exp->cast_to ?: imp->e->d.prim.d.exp->type;
24 if(t == imp->t) {
25 const Instr cpy = emit_add_instr(emit, Reg2RegOther); // kind
26 cpy->m_val2 = SZ_INT;
27 emit_regmove(emit, imp->t->size - SZ_INT);
28 } else {
29 emit_regmove(emit, SZ_INT);
30 struct Op_Import opi = {.lhs = t,
31 .op = insert_symbol(emit->gwion->st, "@implicit"),
32 .rhs = imp->t};
33 CHECK_BB(op_emit(emit, &opi));
34 emit_regmove(emit, -SZ_INT);
35 const Instr cpy = emit_add_instr(emit, Reg2RegOther); // kind
36 cpy->m_val = cpy->m_val2 = imp->t->size;
37 }
38 return GW_OK;
39 }
40
41 638 GWION_IMPORT(gack) {
42
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
638 gwidoc(gwi, "a type for *pretty print*.");
44 638 const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL);
45 638 GWI_BB(gwi_gack(gwi, t_gack, gack_gack))
46 638 GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack));
47
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
638 gwidoc(gwi, "@Gack implicit cast");
49 638 GWI_BB(gwi_oper_ini(gwi, "@Gack", (m_str)OP_ANY_TYPE, NULL))
50 638 GWI_BB(gwi_oper_add(gwi, opck_gack_implicit))
51 638 GWI_BB(gwi_oper_emi(gwi, opem_gack_implicit))
52 638 GWI_BB(gwi_oper_end(gwi, "@implicit", NULL))
53
54 638 return GW_OK;
55 }
56