GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/func.c Lines: 23 23 100.0 %
Date: 2020-09-14 20:46:08 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
42308
ANN static void free_func(Func a, Gwion gwion) {
9
42308
  if(GET_FLAG(a, template))
10
39
    func_def_cleaner(gwion, a->def);
11
42308
  if(a->code)
12
42204
    REM_REF(a->code, gwion);
13
42308
  mp_free(gwion->mp, Func, a);
14
42308
}
15
16
42469
ANN Func new_func(MemPool p, const m_str name, const Func_Def def) {
17
42469
  Func func = mp_calloc(p, Func);
18
42469
  func->name = name;
19
42469
  func->def = def;
20
42469
  func->ref = new_refcount(p, free_func);
21
42469
  return func;
22
}
23
24
42782
ANN2(1,2) Symbol func_symbol(const Env env, const m_str nspc, const m_str base,
25
42782
    const m_str tmpl, const m_uint i) {
26
42782
  const size_t base_len = strlen(base);
27
42782
  const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 4;
28
42782
  const size_t nspc_len = strlen(nspc);
29
42782
  const size_t idx_len = num_digit(i);
30
42782
  const size_t len = base_len + tmpl_len + nspc_len + idx_len + 2;
31
42782
  char name[len + 1];
32


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