1 |
|
|
#include "gwion_util.h" |
2 |
|
|
#include "gwion_ast.h" |
3 |
|
|
#include "gwion_env.h" |
4 |
|
|
#include "vm.h" |
5 |
|
|
#include "object.h" |
6 |
|
|
#include "gwion.h" |
7 |
|
|
|
8 |
|
|
struct Stack_ { |
9 |
|
|
VM_Shred shred; |
10 |
|
|
char c[SIZEOF_REG]; |
11 |
|
|
char d[SIZEOF_MEM]; |
12 |
|
|
}; |
13 |
|
|
|
14 |
|
1220 |
static inline struct ShredInfo_ *new_shredinfo(MemPool p, const m_str name) { |
15 |
|
1220 |
struct ShredInfo_ *info = mp_calloc(p, ShredInfo); |
16 |
|
1220 |
info->mp = p; |
17 |
|
1220 |
info->name = mstrdup(p, name); |
18 |
|
1220 |
return info; |
19 |
|
|
} |
20 |
|
|
|
21 |
|
1217 |
static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) { |
22 |
|
1217 |
free_mstr(mp, info->name); |
23 |
✓✓ |
1217 |
if(info->args) { |
24 |
|
1 |
const Vector v = info->args; |
25 |
|
|
LOOP_OPTIM |
26 |
✓✓ |
3 |
for(m_uint i = vector_size(v) + 1; --i;) |
27 |
|
1 |
xfree((void*)vector_at(v, i - 1)); |
28 |
|
1 |
free_vector(mp, v); |
29 |
|
|
} |
30 |
|
1217 |
mp_free(mp, ShredInfo, info); |
31 |
|
1217 |
} |
32 |
|
|
|
33 |
|
1220 |
VM_Shred new_vm_shred(MemPool p, VM_Code c) { |
34 |
|
1220 |
const VM_Shred shred = mp_calloc(p, Stack); |
35 |
|
1220 |
shred->code = c; |
36 |
|
1220 |
shred->reg = (m_bit*)shred + sizeof(struct VM_Shred_); |
37 |
|
1220 |
shred->base = shred->mem = shred->reg + SIZEOF_REG; |
38 |
|
1220 |
shred->info = new_shredinfo(p, c->name); |
39 |
|
1220 |
shred->info->orig = c; |
40 |
|
1220 |
vector_init(&shred->gc); |
41 |
|
1220 |
return shred; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
1217 |
void free_vm_shred(VM_Shred shred) { |
45 |
✓✓ |
4391 |
for(m_uint i = vector_size(&shred->gc) + 1; --i;) |
46 |
|
1957 |
release((M_Object)vector_at(&shred->gc, i - 1), shred); |
47 |
|
1217 |
vector_release(&shred->gc); |
48 |
|
1217 |
REM_REF(shred->info->orig, shred->info->vm->gwion); |
49 |
|
1217 |
const MemPool mp = shred->info->mp; |
50 |
|
1217 |
mp_free(mp, ShredTick, shred->tick); |
51 |
|
1217 |
free_shredinfo(mp, shred->info); |
52 |
|
1217 |
mp_free(mp, Stack, shred); |
53 |
|
1217 |
} |