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