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 |
|
11565 |
ANN void tuple_info(const Env env, const Value v) { |
19 |
|
11565 |
const m_uint offset = vector_back(&env->class_def->e->tuple->offset); |
20 |
|
11565 |
vector_add(&env->class_def->e->tuple->types, (vtype)v->type); |
21 |
|
11565 |
vector_add(&env->class_def->e->tuple->offset, offset + v->type->size); |
22 |
|
11565 |
} |
23 |
|
|
|
24 |
|
11603 |
ANN void tuple_contains(const Env env, const Value value) { |
25 |
|
11603 |
const Type t = value->type; |
26 |
✓✗✓✓
|
11603 |
if(!env->class_def->e->tuple || env->class_def == value->type) |
27 |
|
2 |
return; |
28 |
|
11601 |
const Vector v = &env->class_def->e->tuple->contains; |
29 |
✓✓ |
11601 |
const m_int idx = vector_size(v) ? vector_find(v, (vtype)t) : -1; |
30 |
✓✓ |
11601 |
if(idx == -1) { |
31 |
|
8026 |
ADD_REF(t); |
32 |
|
8026 |
vector_add(v, (vtype)t); |
33 |
|
|
} |
34 |
|
|
} |
35 |
|
|
|
36 |
|
13160 |
ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { |
37 |
|
13160 |
TupleForm tuple = mp_malloc(p, TupleForm); |
38 |
|
13160 |
vector_init(&tuple->contains); |
39 |
|
13160 |
vector_init(&tuple->types); |
40 |
|
13160 |
vector_init(&tuple->offset); |
41 |
✓✓✓✓
|
20350 |
if(parent_type && parent_type->e->tuple) { |
42 |
|
7190 |
const TupleForm parent = parent_type->e->tuple; |
43 |
|
7190 |
const m_uint sz = vector_size(&parent->types); |
44 |
|
7190 |
tuple->start = parent->start + sz; |
45 |
✓✓ |
7190 |
if(sz) { |
46 |
|
6413 |
const Type last = (Type)vector_back(&parent->types); |
47 |
|
6413 |
const m_uint offset = vector_back(&parent->offset); |
48 |
|
6413 |
vector_add(&tuple->offset, offset + last->size); |
49 |
|
|
} else { |
50 |
|
777 |
vector_add(&tuple->offset, 0); |
51 |
|
|
} |
52 |
|
|
} else { |
53 |
|
5970 |
vector_add(&tuple->offset, 0); |
54 |
|
5970 |
tuple->start = 0; |
55 |
|
|
} |
56 |
|
13160 |
return tuple; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
13142 |
ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) { |
60 |
✓✓ |
21157 |
for(m_uint i = 0; i < vector_size(&tuple->contains); ++i) |
61 |
|
8015 |
REM_REF((Type)vector_at(&tuple->contains, i), (void*)gwion); |
62 |
|
13142 |
vector_release(&tuple->contains); |
63 |
|
13142 |
vector_release(&tuple->types); |
64 |
|
13142 |
vector_release(&tuple->offset); |
65 |
|
13142 |
} |