| 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 "gwion.h" | ||
| 7 | #include "object.h" | ||
| 8 | #include "emit.h" | ||
| 9 | #include "vm.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 | 2695 | ANN void tuple_info(const Env env, const Value v) { | |
| 19 | 2695 | const m_uint offset = vector_back(&env->class_def->info->tuple->offset); | |
| 20 | 2695 | vector_add(&env->class_def->info->tuple->types, (vtype)v->type); | |
| 21 | 2695 | vector_add(&env->class_def->info->tuple->offset, offset + v->type->size); | |
| 22 | 2695 | } | |
| 23 | |||
| 24 | 2729 | ANN void tuple_contains(const Env env, const Value value) { | |
| 25 | 2729 | const Type t = value->type; | |
| 26 |
3/4✓ Branch 0 taken 2729 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2728 times.
|
2729 | if (!env->class_def->info->tuple || env->class_def == value->type) return; |
| 27 | 2728 | const Vector v = &env->class_def->info->tuple->contains; | |
| 28 |
2/2✓ Branch 1 taken 690 times.
✓ Branch 2 taken 2038 times.
|
2728 | const m_int idx = vector_size(v) ? vector_find(v, (vtype)t) : -1; |
| 29 |
2/2✓ Branch 0 taken 2718 times.
✓ Branch 1 taken 10 times.
|
2728 | if (idx == -1) { |
| 30 | 2718 | type_addref(t); | |
| 31 | 2718 | vector_add(v, (vtype)t); | |
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | 22524 | ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { | |
| 36 | 22524 | TupleForm tuple = mp_malloc(p, TupleForm); | |
| 37 | 22524 | vector_init(&tuple->contains); | |
| 38 | 22524 | vector_init(&tuple->types); | |
| 39 | 22524 | vector_init(&tuple->offset); | |
| 40 |
4/4✓ Branch 0 taken 20602 times.
✓ Branch 1 taken 1922 times.
✓ Branch 2 taken 14616 times.
✓ Branch 3 taken 5986 times.
|
37140 | if (parent_type && parent_type->info->tuple) { |
| 41 | 14616 | const TupleForm parent = parent_type->info->tuple; | |
| 42 | 14616 | const m_uint sz = vector_size(&parent->types); | |
| 43 | 14616 | tuple->start = parent->start + sz; | |
| 44 |
2/2✓ Branch 0 taken 1918 times.
✓ Branch 1 taken 12698 times.
|
14616 | if (sz) { |
| 45 | 1918 | const Type last = (Type)vector_back(&parent->types); | |
| 46 | 1918 | const m_uint offset = vector_back(&parent->offset); | |
| 47 | 1918 | vector_add(&tuple->offset, offset + last->size); | |
| 48 | } else { | ||
| 49 | 12698 | vector_add(&tuple->offset, 0); | |
| 50 | } | ||
| 51 | } else { | ||
| 52 | 7908 | vector_add(&tuple->offset, 0); | |
| 53 | 7908 | tuple->start = 0; | |
| 54 | } | ||
| 55 | 22524 | return tuple; | |
| 56 | } | ||
| 57 | |||
| 58 | 22323 | ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) { | |
| 59 |
2/2✓ Branch 1 taken 3323 times.
✓ Branch 2 taken 22323 times.
|
25646 | for (m_uint i = 0; i < vector_size(&tuple->contains); ++i) |
| 60 | 3323 | type_remref((Type)vector_at(&tuple->contains, i), (void *)gwion); | |
| 61 | 22323 | vector_release(&tuple->contains); | |
| 62 | 22323 | vector_release(&tuple->types); | |
| 63 | 22323 | vector_release(&tuple->offset); | |
| 64 | 22323 | } | |
| 65 |