GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/vm/vm_shred.c Lines: 33 33 100.0 %
Date: 2020-09-12 17:36:58 Branches: 6 6 100.0 %

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 "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
1211
static inline struct ShredInfo_ *new_shredinfo(MemPool p, const m_str name) {
15
1211
  struct ShredInfo_ *info = mp_calloc(p, ShredInfo);
16
1211
  info->mp = p;
17
1211
  info->name = mstrdup(p, name);
18
1211
  return info;
19
}
20
21
1207
static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) {
22
1207
  free_mstr(mp, info->name);
23
1207
  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
1207
  mp_free(mp, ShredInfo, info);
31
1207
}
32
33
1211
VM_Shred new_vm_shred(MemPool p, VM_Code c) {
34
1211
  const VM_Shred shred = mp_calloc(p, Stack);
35
1211
  shred->code = c;
36
1211
  shred->reg  = (m_bit*)shred + sizeof(struct VM_Shred_);
37
1211
  shred->base = shred->mem = shred->reg + SIZEOF_REG;
38
1211
  shred->info = new_shredinfo(p, c->name);
39
1211
  shred->info->orig = c;
40
1211
  vector_init(&shred->gc);
41
1211
  return shred;
42
}
43
44
1207
void free_vm_shred(VM_Shred shred) {
45
4369
  for(m_uint i = vector_size(&shred->gc) + 1; --i;)
46
1955
    release((M_Object)vector_at(&shred->gc, i - 1), shred);
47
1207
  vector_release(&shred->gc);
48
1207
  REM_REF(shred->info->orig, shred->info->vm->gwion);
49
1207
  const MemPool mp = shred->info->mp;
50
1207
  mp_free(mp, ShredTick, shred->tick);
51
1207
  free_shredinfo(mp, shred->info);
52
1207
  mp_free(mp, Stack, shred);
53
1207
}