GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/import/import_oper.c Lines: 39 39 100.0 %
Date: 2020-10-03 10:30:04 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
341530
ANN static Type _get_type(const Gwi gwi, const m_str s) {
20
341530
  if(s == (m_str)OP_ANY_TYPE)
21
9269
    return OP_ANY_TYPE;
22
332261
  Type_Decl *td = str2decl(gwi, s);
23
332261
  const Type t = known_type(gwi->gwion->env, td);
24
332261
  free_type_decl(gwi->gwion->mp, td);
25
332261
  return t;
26
}
27
28
385023
ANN2(1) static inline Type gwi_get_type(const Gwi gwi, const m_str str) {
29
385023
  return str ? _get_type(gwi, str) : NULL;
30
}
31
32
128341
ANN2(1,2) static int import_op(const Gwi gwi, const struct OperCK* op,
33
    const f_instr f) {
34
128341
  const Type lhs = gwi_get_type(gwi, op->lhs),
35
128341
             rhs = gwi_get_type(gwi, op->rhs),
36
128341
             ret = gwi_get_type(gwi, op->ret);
37
128341
  const struct Op_Func opfunc = { .ck=op->ck, .em=op->em };
38
513364
  const struct Op_Import opi = { .lhs=lhs, .rhs=rhs, .ret=ret,
39
385023
    .func=&opfunc, .data=(uintptr_t)f, .pos=gwi->loc, .op=op->sym };
40
128341
  return add_op(gwi->gwion, &opi);
41
}
42
43
44
47772
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
47772
  gwi->oper->ret = t;
47
47772
  gwi->oper->rhs = r;
48
47772
  gwi->oper->lhs = l;
49
47772
  return GW_OK;
50
}
51
52
59892
ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*, m_bool*)) {
53
59892
  gwi->oper->ck = ck;
54
59892
  return GW_OK;
55
}
56
57
17825
ANN m_int gwi_oper_emi(const Gwi gwi, const opem em) {
58
17825
  gwi->oper->em = em;
59
17825
  return GW_OK;
60
}
61
62
128341
ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) {
63
128341
  gwi->oper->sym = insert_symbol(gwi->gwion->st, op);
64
128341
  const m_bool ret = import_op(gwi, gwi->oper, f);
65
128341
  gwi->oper->ck = NULL;
66
128341
  gwi->oper->em = NULL;
67
128341
  return ret;
68
}
69
70
4278
ANN m_int gwi_oper_cond(const Gwi gwi, const m_str type,
71
  const f_instr f1, const f_instr f2) {
72
4278
  GWI_BB(gwi_oper_ini(gwi, NULL, type, "bool"))
73
4278
  GWI_BB(gwi_oper_end(gwi, "@conditionnal", f1))
74
4278
  GWI_BB(gwi_oper_end(gwi, "@unconditionnal", f2))
75
4278
  return GW_OK;
76
}