GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/value.c Lines: 25 25 100.0 %
Date: 2020-09-12 17:36:58 Branches: 20 20 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
95764
ANN static void free_value(Value a, Gwion gwion) {
8
95764
  const Type t = a->type;
9


106019
  if(!GET_FLAG(a, func) && a->d.ptr && !GET_FLAG(a, union) &&
10

11722
      !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->from->owner_class)
11
10237
      && isa(t, gwion->type[et_object]) < 0)
12
7855
   _mp_free(gwion->mp, t->size, a->d.ptr);
13

87909
  else if(GET_FLAG(a, enum) && GET_FLAG(a, dtor))
14
1
    xfree(a->d.ptr);
15
95764
  if(is_class(gwion, t))
16
29697
    REM_REF(t, gwion)
17
95764
  mp_free(gwion->mp, ValueFrom, a->from);
18
95764
  mp_free(gwion->mp, Value, a);
19
95764
}
20
21
121946
ANN Value new_value(MemPool p, const Type type, const m_str name) {
22
121946
  const Value a = mp_calloc(p, Value);
23
121946
  a->from = mp_calloc(p, ValueFrom);
24
121946
  a->type       = type;
25
121946
  a->name       = name;
26
121946
  a->ref = new_refcount(p, free_value);
27
121946
  return a;
28
}
29
30
113107
ANN void valuefrom(const Env env, struct ValueFrom_ *from) {
31
113107
  from->owner = env->curr;
32
113107
  from->owner_class = env->class_def;
33
113107
  from->ctx = env->context;
34
113107
}