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


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

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

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