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


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