GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/context.c Lines: 26 26 100.0 %
Date: 2020-09-14 20:46:08 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
620
ANN static void free_context(const Context a, Gwion gwion) {
8
620
  REM_REF(a->nspc, gwion)
9
620
  free_mstr(gwion->mp, a->name);
10
620
  mp_free(gwion->mp, Context, a);
11
620
}
12
13
620
ANN2(2) Context new_context(MemPool p, const Ast ast, const m_str str) {
14
620
  const Context context = mp_calloc(p, Context);
15
620
  context->name = mstrdup(p, str);
16
620
  context->nspc = new_nspc(p, context->name);
17
620
  context->tree = ast;
18
620
  context->ref = new_refcount(p, free_context);
19
620
  return context;
20
}
21
22
620
ANN void load_context(const Context context, const Env env) {
23
620
  ADD_REF((env->context = context))
24
620
  vector_add(&env->scope->nspc_stack, (vtype)env->curr);
25
620
  context->nspc->parent = env->curr;
26
620
  env->curr = context->nspc;
27
620
}
28
29
620
ANN void unload_context(const Context context, const Env env) {
30
620
  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
620
  REM_REF(context, env->gwion)
37
620
  env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
38
620
}