GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/tupleform.c Lines: 38 38 100.0 %
Date: 2020-10-03 11:19:27 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
11581
ANN void tuple_info(const Env env, const Value v) {
19
11581
  const m_uint offset = vector_back(&env->class_def->e->tuple->offset);
20
11581
  vector_add(&env->class_def->e->tuple->types, (vtype)v->type);
21
11581
  vector_add(&env->class_def->e->tuple->offset, offset + v->type->size);
22
11581
}
23
24
11619
ANN void tuple_contains(const Env env, const Value value) {
25
11619
  const Type t = value->type;
26

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

20380
  if(parent_type && parent_type->e->tuple) {
42
7200
    const TupleForm parent = parent_type->e->tuple;
43
7200
    const m_uint sz = vector_size(&parent->types);
44
7200
    tuple->start = parent->start + sz;
45
7200
    if(sz) {
46
6422
      const Type last = (Type)vector_back(&parent->types);
47
6422
      const m_uint offset = vector_back(&parent->offset);
48
6422
      vector_add(&tuple->offset, offset + last->size);
49
    } else {
50
778
      vector_add(&tuple->offset, 0);
51
    }
52
  } else {
53
5980
    vector_add(&tuple->offset, 0);
54
5980
    tuple->start = 0;
55
  }
56
13180
  return tuple;
57
}
58
59
13162
ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) {
60
21188
  for(m_uint i = 0; i < vector_size(&tuple->contains); ++i)
61
8026
    REM_REF((Type)vector_at(&tuple->contains, i), (void*)gwion);
62
13162
  vector_release(&tuple->contains);
63
13162
  vector_release(&tuple->types);
64
13162
  vector_release(&tuple->offset);
65
13162
}