GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/import/import_oper.c Lines: 39 39 100.0 %
Date: 2020-09-21 18:02:52 Branches: 4 4 100.0 %

Line Branch Exec Source
1
#include <stdlib.h>
2
#include <string.h>
3
#include <ctype.h>
4
#include "gwion_util.h"
5
#include "gwion_ast.h"
6
#include "gwion_env.h"
7
#include "vm.h"
8
#include "traverse.h"
9
#include "instr.h"
10
#include "object.h"
11
#include "emit.h"
12
#include "gwion.h"
13
#include "operator.h"
14
#include "import.h"
15
#include "gwi.h"
16
#include "mpool.h"
17
#include "specialid.h"
18
19
341051
ANN static Type _get_type(const Gwi gwi, const m_str s) {
20
341051
  if(s == (m_str)OP_ANY_TYPE)
21
9256
    return OP_ANY_TYPE;
22
331795
  Type_Decl *td = str2decl(gwi, s);
23
331795
  const Type t = known_type(gwi->gwion->env, td);
24
331795
  free_type_decl(gwi->gwion->mp, td);
25
331795
  return t;
26
}
27
28
384483
ANN2(1) static inline Type gwi_get_type(const Gwi gwi, const m_str str) {
29
384483
  return str ? _get_type(gwi, str) : NULL;
30
}
31
32
128161
ANN2(1,2) static int import_op(const Gwi gwi, const struct OperCK* op,
33
    const f_instr f) {
34
128161
  const Type lhs = gwi_get_type(gwi, op->lhs),
35
128161
             rhs = gwi_get_type(gwi, op->rhs),
36
128161
             ret = gwi_get_type(gwi, op->ret);
37
128161
  const struct Op_Func opfunc = { .ck=op->ck, .em=op->em };
38
512644
  const struct Op_Import opi = { .lhs=lhs, .rhs=rhs, .ret=ret,
39
384483
    .func=&opfunc, .data=(uintptr_t)f, .pos=gwi->loc, .op=op->sym };
40
128161
  return add_op(gwi->gwion, &opi);
41
}
42
43
44
47705
ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const restrict m_str l,
45
    const restrict m_str r, const restrict m_str t) {
46
47705
  gwi->oper->ret = t;
47
47705
  gwi->oper->rhs = r;
48
47705
  gwi->oper->lhs = l;
49
47705
  return GW_OK;
50
}
51
52
59808
ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*, m_bool*)) {
53
59808
  gwi->oper->ck = ck;
54
59808
  return GW_OK;
55
}
56
57
17800
ANN m_int gwi_oper_emi(const Gwi gwi, const opem em) {
58
17800
  gwi->oper->em = em;
59
17800
  return GW_OK;
60
}
61
62
128161
ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) {
63
128161
  gwi->oper->sym = insert_symbol(gwi->gwion->st, op);
64
128161
  const m_bool ret = import_op(gwi, gwi->oper, f);
65
128161
  gwi->oper->ck = NULL;
66
128161
  gwi->oper->em = NULL;
67
128161
  return ret;
68
}
69
70
4272
ANN m_int gwi_oper_cond(const Gwi gwi, const m_str type,
71
  const f_instr f1, const f_instr f2) {
72
4272
  GWI_BB(gwi_oper_ini(gwi, NULL, type, "bool"))
73
4272
  GWI_BB(gwi_oper_end(gwi, "@conditionnal", f1))
74
4272
  GWI_BB(gwi_oper_end(gwi, "@unconditionnal", f2))
75
4272
  return GW_OK;
76
}