| 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 | |||
| 8 | struct Stack_ { | ||
| 9 | VM_Shred shred; | ||
| 10 | char c[SIZEOF_REG]; | ||
| 11 | char d[SIZEOF_MEM]; | ||
| 12 | }; | ||
| 13 | |||
| 14 | 1067 | static inline struct ShredInfo_ *new_shredinfo(MemPool p, const VM_Code c) { | |
| 15 | 1067 | struct ShredInfo_ *const info = mp_calloc(p, ShredInfo); | |
| 16 | 1067 | info->mp = p; | |
| 17 | 1067 | info->orig = c; | |
| 18 | 1067 | return info; | |
| 19 | } | ||
| 20 | |||
| 21 | 1063 | static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) { | |
| 22 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1063 times.
|
1063 | if (info->args.ptr) { |
| 23 | ✗ | const Vector v = &info->args; | |
| 24 | LOOP_OPTIM | ||
| 25 | ✗ | for (m_uint i = vector_size(v) + 1; --i;) | |
| 26 | ✗ | xfree((void *)vector_at(v, i - 1)); | |
| 27 | ✗ | vector_release(v); | |
| 28 | } | ||
| 29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1063 times.
|
1063 | if (info->line.ptr) vector_release(&info->line); |
| 30 | 1063 | mp_free(mp, ShredInfo, info); | |
| 31 | 1063 | } | |
| 32 | |||
| 33 | 1067 | VM_Shred new_vm_shred(MemPool p, VM_Code c) { | |
| 34 | 1067 | const VM_Shred shred = mp_calloc(p, Stack); | |
| 35 | 1067 | shred->code = c; | |
| 36 | 1067 | shred->reg = (m_bit *)shred + sizeof(struct VM_Shred_); | |
| 37 | 1067 | shred->base = shred->mem = shred->reg + SIZEOF_REG; | |
| 38 | 1067 | shred->info = new_shredinfo(p, c); | |
| 39 | 1067 | MUTEX_SETUP(shred->mutex); | |
| 40 | 1067 | return shred; | |
| 41 | } | ||
| 42 | |||
| 43 | 1063 | void free_vm_shred(VM_Shred shred) { | |
| 44 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1060 times.
|
1063 | if (shred->info->frame.ptr) vector_release(&shred->info->frame); |
| 45 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1032 times.
|
1063 | if (shred->tick->child.ptr) vector_release(&shred->tick->child); |
| 46 | 1063 | vmcode_remref(shred->info->orig, shred->info->vm->gwion); | |
| 47 | 1063 | const MemPool mp = shred->info->mp; | |
| 48 | 1063 | mp_free(mp, ShredTick, shred->tick); | |
| 49 | 1063 | free_shredinfo(mp, shred->info); | |
| 50 | 1063 | MUTEX_CLEANUP(shred->mutex); | |
| 51 | 1063 | mp_free(mp, Stack, shred); | |
| 52 | 1063 | } | |
| 53 |