GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/func.c Lines: 23 23 100.0 %
Date: 2020-10-03 11:54:50 Branches: 13 14 92.9 %

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
42370
ANN static void free_func(Func a, Gwion gwion) {
9
42370
  if(GET_FLAG(a, template))
10
39
    func_def_cleaner(gwion, a->def);
11
42370
  if(a->code)
12
42265
    REM_REF(a->code, gwion);
13
42370
  mp_free(gwion->mp, Func, a);
14
42370
}
15
16
42535
ANN Func new_func(MemPool p, const m_str name, const Func_Def def) {
17
42535
  Func func = mp_calloc(p, Func);
18
42535
  func->name = name;
19
42535
  func->def = def;
20
42535
  func->ref = new_refcount(p, free_func);
21
42535
  return func;
22
}
23
24
42854
ANN2(1,2) Symbol func_symbol(const Env env, const m_str nspc, const m_str base,
25
42854
    const m_str tmpl, const m_uint i) {
26
42854
  const size_t base_len = strlen(base);
27
42854
  const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 4;
28
42854
  const size_t nspc_len = strlen(nspc);
29
42854
  const size_t idx_len = num_digit(i);
30
42854
  const size_t len = base_len + tmpl_len + nspc_len + idx_len + 2;
31
42854
  char name[len + 1];
32


42854
  CHECK_BO(sprintf(name, "%s%s%s%s@%" UINT_F "@%s",
33
    base, !tmpl ? "" : ":[", !tmpl ? "" : tmpl, !tmpl ? "" : "]",
34
    i, nspc))
35
42854
  return insert_symbol(env->gwion->st, name);
36
}