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 | #include "object.h" | ||
7 | #include "operator.h" | ||
8 | |||
9 | 345 | ANN void nspc_commit(const Nspc nspc) { | |
10 | 345 | scope_commit(nspc->info->value); | |
11 | 345 | scope_commit(nspc->info->func); | |
12 | 345 | scope_commit(nspc->info->type); | |
13 | 345 | scope_commit(nspc->info->trait); | |
14 | 345 | } | |
15 | |||
16 | 2949 | ANN static inline void nspc_release_object(const Nspc a, Value value, | |
17 | Gwion gwion) { | ||
18 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2944 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
2949 | if ((GET_FLAG(value, static) && a->class_data) || |
19 |
4/4✓ Branch 0 taken 2142 times.
✓ Branch 1 taken 802 times.
✓ Branch 3 taken 1914 times.
✓ Branch 4 taken 228 times.
|
2944 | (value->d.ptr && vflag(value, vflag_builtin))) { |
20 | 1919 | const M_Object obj = | |
21 | 1919 | value->d.ptr ? (M_Object)value->d.ptr | |
22 |
2/2✓ Branch 0 taken 1914 times.
✓ Branch 1 taken 5 times.
|
1919 | : *(M_Object *)(a->class_data + value->from->offset); |
23 | 1919 | release(obj, gwion->vm->cleaner_shred); | |
24 | } | ||
25 | 2949 | } | |
26 | |||
27 | ANN2(1, 3) | ||
28 | 18 | static inline void nspc_release_struct(const Nspc a, Value value, Gwion gwion) { | |
29 |
3/8✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 18 times.
|
36 | if (value && ((GET_FLAG(value, static) && a->class_data) || |
30 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
18 | (vflag(value, vflag_builtin) && value->d.ptr))) { |
31 | ✗ | const m_bit *ptr = | |
32 | ✗ | (value && value->d.ptr) | |
33 | ? (m_bit *)value->d.ptr | ||
34 | ✗ | : (m_bit *)(a->class_data + value->from->offset); | |
35 | ✗ | for (m_uint i = 0; i < vector_size(&value->type->info->tuple->types); ++i) { | |
36 | ✗ | const Type t = (Type)vector_at(&value->type->info->tuple->types, i); | |
37 | ✗ | if (isa(t, gwion->type[et_object]) > 0) | |
38 | ✗ | release(*(M_Object *)(ptr + | |
39 | ✗ | vector_at(&value->type->info->tuple->offset, i)), | |
40 | ✗ | gwion->vm->cleaner_shred); | |
41 | ✗ | else if (tflag(t, tflag_struct)) | |
42 | ✗ | nspc_release_struct(t->nspc, NULL, gwion); | |
43 | } | ||
44 | } | ||
45 | 18 | } | |
46 | |||
47 | 192806 | static inline void _free_nspc_value(const Nspc a, const Value v, Gwion gwion) { | |
48 |
4/4✓ Branch 0 taken 1330 times.
✓ Branch 1 taken 191476 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 1261 times.
|
192806 | if(v->from->ctx && v->from->ctx->error) return; // this is quite a hack |
49 |
2/2✓ Branch 1 taken 2967 times.
✓ Branch 2 taken 189770 times.
|
192737 | if (tflag(v->type, tflag_compound) ) { |
50 |
2/2✓ Branch 1 taken 2949 times.
✓ Branch 2 taken 18 times.
|
2967 | if (!tflag(v->type, tflag_struct)) |
51 | 2949 | nspc_release_object(a, v, gwion); | |
52 | 18 | else nspc_release_struct(a, v, gwion); | |
53 | } | ||
54 | 192737 | value_remref(v, gwion); | |
55 | } | ||
56 | |||
57 | #define describe_nspc_free(A, b, dofree) \ | ||
58 | ANN static void nspc_free_##b(Nspc n, Gwion gwion) { \ | ||
59 | struct scope_iter iter = {n->info->b, 0, 0}; \ | ||
60 | A a; \ | ||
61 | while (scope_iter(&iter, &a) > 0) dofree; \ | ||
62 | free_scope(gwion->mp, n->info->b); \ | ||
63 | } | ||
64 | |||
65 |
2/2✓ Branch 2 taken 192806 times.
✓ Branch 3 taken 24973 times.
|
217779 | describe_nspc_free(Value, value, _free_nspc_value(n, a, gwion)); |
66 |
2/2✓ Branch 2 taken 76368 times.
✓ Branch 3 taken 24973 times.
|
101341 | describe_nspc_free(Func, func, func_remref(a, gwion)); |
67 |
2/2✓ Branch 2 taken 103766 times.
✓ Branch 3 taken 24973 times.
|
128739 | describe_nspc_free(Type, type, type_remref(a, gwion)); |
68 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 24973 times.
|
24973 | describe_nspc_free(Trait, trait, free_trait(gwion->mp, a)); |
69 | |||
70 | 24973 | ANN void free_nspc(const Nspc a, const Gwion gwion) { | |
71 | 24973 | nspc_free_value(a, gwion); | |
72 | 24973 | nspc_free_func(a, gwion); | |
73 | 24973 | nspc_free_trait(a, gwion); | |
74 |
2/2✓ Branch 0 taken 683 times.
✓ Branch 1 taken 24290 times.
|
24973 | if(a->operators) { |
75 |
1/2✓ Branch 0 taken 683 times.
✗ Branch 1 not taken.
|
683 | if (a->operators->map.ptr) free_op_map(&a->operators->map, gwion); |
76 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 682 times.
|
683 | if (a->operators->tmpl.ptr) free_op_tmpl(&a->operators->tmpl, gwion); |
77 | 683 | mp_free(gwion->mp, NspcOp, a->operators); | |
78 | } | ||
79 | 24973 | nspc_free_type(a, gwion); | |
80 |
3/4✓ Branch 0 taken 650 times.
✓ Branch 1 taken 24323 times.
✓ Branch 2 taken 650 times.
✗ Branch 3 not taken.
|
24973 | if (a->class_data && a->class_data_size) |
81 | 650 | mp_free2(gwion->mp, a->class_data_size, a->class_data); | |
82 |
2/2✓ Branch 0 taken 18460 times.
✓ Branch 1 taken 6513 times.
|
24973 | if (a->vtable.ptr) vector_release(&a->vtable); |
83 | 24973 | mp_free(gwion->mp, NspcInfo, a->info); | |
84 |
2/2✓ Branch 0 taken 10870 times.
✓ Branch 1 taken 14103 times.
|
24973 | if (a->dtor) vmcode_remref(a->dtor, gwion); |
85 | 24973 | mp_free(gwion->mp, Nspc, a); | |
86 | 24973 | } | |
87 | |||
88 | 25837 | ANN Nspc new_nspc(MemPool p, const m_str name) { | |
89 | 25837 | const Nspc a = mp_calloc(p, Nspc); | |
90 | 25837 | a->name = name; | |
91 | 25837 | a->info = mp_calloc(p, NspcInfo); | |
92 | 25837 | a->info->value = new_scope(p); | |
93 | 25837 | a->info->type = new_scope(p); | |
94 | 25837 | a->info->func = new_scope(p); | |
95 | 25837 | a->info->trait = new_scope(p); | |
96 | 25837 | a->ref = 1; | |
97 | 25837 | return a; | |
98 | } | ||
99 | |||
100 | static nspc_add_value_t _add = _nspc_add_value; | ||
101 | static nspc_add_value_t _front = _nspc_add_value_front; | ||
102 | 197140 | ANN void nspc_add_value(const Nspc n, const Symbol s, const Value a) { | |
103 | 197140 | _add(n, s, a); | |
104 | 197140 | } | |
105 | 104934 | ANN void nspc_add_value_front(const Nspc n, const Symbol s, const Value a) { | |
106 | 104934 | _front(n, s, a); | |
107 | 104934 | } | |
108 | |||
109 | ✗ | ANN void nspc_add_value_set_func(nspc_add_value_t add, nspc_add_value_t front) { | |
110 | ✗ | _add = add; | |
111 | ✗ | _front = front; | |
112 | } | ||
113 | |||
114 |