GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/vm/vm_shred.c Lines: 33 33 100.0 %
Date: 2020-07-24 14:14:26 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
1219
static inline struct ShredInfo_ *new_shredinfo(MemPool p, const m_str name) {
15
1219
  struct ShredInfo_ *info = mp_calloc(p, ShredInfo);
16
1219
  info->mp = p;
17
1219
  info->name = mstrdup(p, name);
18
1219
  return info;
19
}
20
21
1215
static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) {
22
1215
  free_mstr(mp, info->name);
23
1215
  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
1215
  mp_free(mp, ShredInfo, info);
31
1215
}
32
33
1219
VM_Shred new_vm_shred(MemPool p, VM_Code c) {
34
1219
  const VM_Shred shred = mp_calloc(p, Stack);
35
1219
  shred->code = c;
36
1219
  shred->reg  = (m_bit*)shred + sizeof(struct VM_Shred_);
37
1219
  shred->base = shred->mem = shred->reg + SIZEOF_REG;
38
1219
  shred->info = new_shredinfo(p, c->name);
39
1219
  shred->info->orig = c;
40
1219
  vector_init(&shred->gc);
41
1219
  return shred;
42
}
43
44
1215
void free_vm_shred(VM_Shred shred) {
45
4370
  for(m_uint i = vector_size(&shred->gc) + 1; --i;)
46
1940
    release((M_Object)vector_at(&shred->gc, i - 1), shred);
47
1215
  vector_release(&shred->gc);
48
1215
  REM_REF(shred->info->orig, shred->info->vm->gwion);
49
1215
  const MemPool mp = shred->info->mp;
50
1215
  mp_free(mp, ShredTick, shred->tick);
51
1215
  free_shredinfo(mp, shred->info);
52
1215
  mp_free(mp, Stack, shred);
53
1215
}