Gwion coverage report


Directory: src/
File: src/env/func.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 32 36 88.9%
Functions: 4 4 100.0%
Branches: 20 24 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 "clean.h"
7
8 76368 ANN void free_func(Func a, Gwion gwion) {
9
2/2
✓ Branch 1 taken 10139 times.
✓ Branch 2 taken 66229 times.
76368 if (fflag(a, fflag_tmpl)) func_def_cleaner(gwion, a->def);
10
2/2
✓ Branch 0 taken 70918 times.
✓ Branch 1 taken 5450 times.
76368 if (a->code) vmcode_remref(a->code, gwion);
11
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 76363 times.
76368 if (a->_wait) free_mp_vector(gwion->mp, Value, a->_wait);
12 76368 mp_free(gwion->mp, Func, a);
13 76368 }
14
15 76699 ANN Func new_func(MemPool p, const m_str name, const Func_Def def) {
16 76699 Func func = mp_calloc(p, Func);
17 76699 func->name = name;
18 76699 func->def = def;
19 76699 func->inline_mult = 1.0;
20 76699 func->ref = 1;
21 76699 return func;
22 }
23
24 ANN2(1, 2)
25 76991 Symbol func_symbol(const Env env, const m_str nspc, const m_str base,
26 76991 const m_str tmpl, const m_uint i) {
27 76991 const size_t base_len = strlen(base);
28
2/2
✓ Branch 0 taken 10387 times.
✓ Branch 1 taken 66604 times.
76991 const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 4;
29 76991 const size_t nspc_len = strlen(nspc);
30 76991 const size_t idx_len = num_digit(i);
31 76991 const size_t len = base_len + tmpl_len + nspc_len + idx_len + 2;
32 76991 char name[len + 1];
33
7/8
✓ Branch 0 taken 66604 times.
✓ Branch 1 taken 10387 times.
✓ Branch 2 taken 10387 times.
✓ Branch 3 taken 66604 times.
✓ Branch 4 taken 66604 times.
✓ Branch 5 taken 10387 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 76991 times.
76991 CHECK_BO(sprintf(name, "%s%s%s%s@%" UINT_F "@%s", base, !tmpl ? "" : ":[",
34 !tmpl ? "" : tmpl, !tmpl ? "" : "]", i, nspc));
35 76991 return insert_symbol(env->gwion->st, name);
36 }
37
38 70691 ANN void builtin_func(const Gwion gwion, const Func f, void *func_ptr) {
39 70691 set_vflag(f->value_ref, vflag_builtin);
40 70691 f->code = new_vmcode(gwion->mp, NULL, NULL, f->name, f->def->stack_depth, true, false);
41 70691 f->code->native_func = (m_uint)func_ptr;
42 70691 f->code->ret_type = f->def->base->ret_type;
43
4/4
✓ Branch 0 taken 10111 times.
✓ Branch 1 taken 60580 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 10110 times.
70691 if(f->def->base->tmpl && f->def->base->tmpl->call) {
44 1 const Specialized *spec = mp_vector_at(f->def->base->tmpl->list, Specialized, f->def->base->tmpl->list->len - 1);
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(!strcmp(s_name(spec->xid), "...")) {
46 f->code->types = new_mp_vector(gwion->mp, Type_Decl*, f->def->base->tmpl->call->len);
47 for(uint32_t i = 0; i < f->def->base->tmpl->call->len; i++) {
48 Type_Decl *const td = *mp_vector_at(f->def->base->tmpl->call, Type_Decl*, i);
49 mp_vector_set(f->code->types, Type, i, known_type(gwion->env, td));
50 }
51 }
52 }
53 70691 }
54