GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/context.c Lines: 26 26 100.0 %
Date: 2020-10-03 11:19:27 Branches: 4 4 100.0 %

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
7
622
ANN static void free_context(const Context a, Gwion gwion) {
8
622
  REM_REF(a->nspc, gwion)
9
622
  free_mstr(gwion->mp, a->name);
10
622
  mp_free(gwion->mp, Context, a);
11
622
}
12
13
622
ANN2(2) Context new_context(MemPool p, const Ast ast, const m_str str) {
14
622
  const Context context = mp_calloc(p, Context);
15
622
  context->name = mstrdup(p, str);
16
622
  context->nspc = new_nspc(p, context->name);
17
622
  context->tree = ast;
18
622
  context->ref = new_refcount(p, free_context);
19
622
  return context;
20
}
21
22
622
ANN void load_context(const Context context, const Env env) {
23
622
  ADD_REF((env->context = context))
24
622
  vector_add(&env->scope->nspc_stack, (vtype)env->curr);
25
622
  context->nspc->parent = env->curr;
26
622
  env->curr = context->nspc;
27
622
}
28
29
622
ANN void unload_context(const Context context, const Env env) {
30
622
  if(context->lbls.ptr) {
31
    LOOP_OPTIM
32
14
    for(m_uint i = 0; i < map_size(&context->lbls); i++)
33
7
      free_map(env->gwion->mp, (Map)map_at(&context->lbls, i));
34
7
    map_release(&context->lbls);
35
  }
36
622
  REM_REF(context, env->gwion)
37
622
  env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
38
622
}