GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/tupleform.c Lines: 38 38 100.0 %
Date: 2020-07-24 14:14:26 Branches: 15 16 93.8 %

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 "instr.h"
6
#include "object.h"
7
#include "emit.h"
8
#include "vm.h"
9
#include "gwion.h"
10
#include "operator.h"
11
#include "import.h"
12
#include "gwi.h"
13
#include "traverse.h"
14
#include "object.h"
15
#include "parse.h"
16
#include "array.h"
17
18
12586
ANN void tuple_info(const Env env, const Value v) {
19
12586
  const m_uint offset = vector_back(&env->class_def->e->tuple->offset);
20
12586
  vector_add(&env->class_def->e->tuple->types, (vtype)v->type);
21
12586
  vector_add(&env->class_def->e->tuple->offset, offset + v->type->size);
22
12586
}
23
24
12623
ANN void tuple_contains(const Env env, const Value value) {
25
12623
  const Type t = value->type;
26

12623
  if(!env->class_def->e->tuple || env->class_def == value->type)
27
2
    return;
28
12621
  const Vector v = &env->class_def->e->tuple->contains;
29
12621
  const m_int idx = vector_size(v) ? vector_find(v, (vtype)t) : -1;
30
12621
  if(idx == -1) {
31
8225
    ADD_REF(t);
32
8225
    vector_add(v, (vtype)t);
33
  }
34
}
35
36
12761
ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) {
37
12761
  TupleForm tuple = mp_malloc(p, TupleForm);
38
12761
  vector_init(&tuple->contains);
39
12761
  vector_init(&tuple->types);
40
12761
  vector_init(&tuple->offset);
41

19402
  if(parent_type && parent_type->e->tuple) {
42
6641
    const TupleForm parent = parent_type->e->tuple;
43
6641
    const m_uint sz = vector_size(&parent->types);
44
6641
    tuple->start = parent->start + sz;
45
6641
    if(sz) {
46
5844
      const Type last = (Type)vector_back(&parent->types);
47
5844
      const m_uint offset = vector_back(&parent->offset);
48
5844
      vector_add(&tuple->offset, offset + last->size);
49
    } else {
50
797
      vector_add(&tuple->offset, 0);
51
    }
52
  } else {
53
6120
    vector_add(&tuple->offset, 0);
54
6120
    tuple->start = 0;
55
  }
56
12761
  return tuple;
57
}
58
59
12744
ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) {
60
20958
  for(m_uint i = 0; i < vector_size(&tuple->contains); ++i)
61
8214
    REM_REF((Type)vector_at(&tuple->contains, i), (void*)gwion);
62
12744
  vector_release(&tuple->contains);
63
12744
  vector_release(&tuple->types);
64
12744
  vector_release(&tuple->offset);
65
12744
}