GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/value.c Lines: 25 25 100.0 %
Date: 2020-10-03 11:54:50 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
96013
ANN static void free_value(Value a, Gwion gwion) {
8
96013
  const Type t = a->type;
9


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

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

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