Gwion coverage report


Directory: src/
File: src/lib/event.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 7 7 100.0%
Branches: 5 6 83.3%

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 "gwion.h"
6 #include "instr.h"
7 #include "object.h"
8 #include "operator.h"
9 #include "import.h"
10 #include "gwi.h"
11
12 8 static CTOR(event_ctor) { vector_init(&EV_SHREDS(o)); }
13
14 9 static DTOR(event_dtor) {
15
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
10 for (m_uint i = 0; i < vector_size(&EV_SHREDS(o)); i++) {
16 1 const VM_Shred sh = (VM_Shred)vector_at(&EV_SHREDS(o), i);
17 1 release(sh->info->me, sh);
18 }
19 9 vector_release(&EV_SHREDS(o));
20 9 }
21
22 4 static INSTR(EventWait) {
23 4 POP_REG(shred, SZ_FLOAT);
24 4 const M_Object event = *(M_Object *)REG(-SZ_INT);
25 4 shreduler_remove(shred->tick->shreduler, shred, false);
26 4 shred->info->me->ref++;
27 4 const Vector v = &EV_SHREDS(event);
28 4 vector_add(v, (vtype)shred);
29 4 *(m_int *)REG(-SZ_INT) = 1;
30 4 }
31
32 1 static MFUN(event_signal) {
33 1 const Vector v = &EV_SHREDS(o);
34
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if(!vector_size(v)) return;
35 1 const VM_Shred sh = (VM_Shred)vector_front(v);
36 1 shredule(sh->tick->shreduler, sh, GWION_EPSILON);
37 1 vector_rem(v, 0);
38 1 release(sh->info->me, sh);
39 }
40
41 4 ANN void broadcast(const M_Object o) {
42
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 4 times.
7 for (m_uint i = 0; i < vector_size(&EV_SHREDS(o)); i++) {
43 3 const VM_Shred sh = (VM_Shred)vector_at(&EV_SHREDS(o), i);
44 3 shredule(sh->tick->shreduler, sh, GWION_EPSILON);
45 3 release(sh->info->me, sh);
46 }
47 4 vector_clear(&EV_SHREDS(o));
48 4 }
49
50 3 static MFUN(event_broadcast) { broadcast(o); }
51
52 638 GWION_IMPORT(event) {
53 638 const Type t_event = gwi_class_ini(gwi, "Event", "Object");
54 638 gwi_class_xtor(gwi, event_ctor, event_dtor);
55 638 gwi->gwion->type[et_event] = t_event; // use func
56 638 t_event->nspc->offset += SZ_INT;
57 638 GWI_BB(gwi_func_ini(gwi, "void", "signal"))
58 638 GWI_BB(gwi_func_end(gwi, event_signal, ae_flag_none))
59 638 GWI_BB(gwi_func_ini(gwi, "void", "broadcast"))
60 638 GWI_BB(gwi_func_end(gwi, event_broadcast, ae_flag_none))
61 638 GWI_BB(gwi_class_end(gwi))
62 638 GWI_BB(gwi_oper_ini(gwi, "Event", "@now", "int"))
63 638 GWI_BB(gwi_oper_end(gwi, "=>", EventWait))
64 638 return GW_OK;
65 }
66