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