1 |
|
|
#include "gwion_util.h" |
2 |
|
|
#include "gwion_ast.h" |
3 |
|
|
#include "gwion_env.h" |
4 |
|
|
#include "vm.h" |
5 |
|
|
#include "gwion.h" |
6 |
|
|
|
7 |
|
95734 |
ANN static void free_value(Value a, Gwion gwion) { |
8 |
|
95734 |
const Type t = a->type; |
9 |
✓✓✓✓ ✓✓✓✓
|
105986 |
if(!GET_FLAG(a, func) && a->d.ptr && !GET_FLAG(a, union) && |
10 |
✓✓✓✓
|
11719 |
!(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->from->owner_class) |
11 |
✓✓ |
10234 |
&& isa(t, gwion->type[et_object]) < 0) |
12 |
|
7855 |
_mp_free(gwion->mp, t->size, a->d.ptr); |
13 |
✓✓✓✓
|
87879 |
else if(GET_FLAG(a, enum) && GET_FLAG(a, dtor)) |
14 |
|
1 |
xfree(a->d.ptr); |
15 |
✓✓ |
95734 |
if(is_class(gwion, t)) |
16 |
|
29685 |
REM_REF(t, gwion) |
17 |
|
95734 |
mp_free(gwion->mp, ValueFrom, a->from); |
18 |
|
95734 |
mp_free(gwion->mp, Value, a); |
19 |
|
95734 |
} |
20 |
|
|
|
21 |
|
121913 |
ANN Value new_value(MemPool p, const Type type, const m_str name) { |
22 |
|
121913 |
const Value a = mp_calloc(p, Value); |
23 |
|
121913 |
a->from = mp_calloc(p, ValueFrom); |
24 |
|
121913 |
a->type = type; |
25 |
|
121913 |
a->name = name; |
26 |
|
121913 |
a->ref = new_refcount(p, free_value); |
27 |
|
121913 |
return a; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
113073 |
ANN void valuefrom(const Env env, struct ValueFrom_ *from) { |
31 |
|
113073 |
from->owner = env->curr; |
32 |
|
113073 |
from->owner_class = env->class_def; |
33 |
|
113073 |
from->ctx = env->context; |
34 |
|
113073 |
} |