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 |
|
346023 |
ANN static Type _get_type(const Gwi gwi, const m_str s) { |
20 |
✓✓ |
346023 |
if(s == (m_str)OP_ANY_TYPE) |
21 |
|
8760 |
return OP_ANY_TYPE; |
22 |
|
337263 |
Type_Decl *td = str2decl(gwi, s); |
23 |
|
337263 |
const Type t = known_type(gwi->gwion->env, td); |
24 |
|
337263 |
free_type_decl(gwi->gwion->mp, td); |
25 |
|
337263 |
return t; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
387633 |
ANN2(1) static inline Type get_type(const Gwi gwi, const m_str str) { |
29 |
✓✓ |
387633 |
return str ? _get_type(gwi, str) : NULL; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
129211 |
ANN2(1,2) static int import_op(const Gwi gwi, const struct OperCK* op, |
33 |
|
|
const f_instr f) { |
34 |
|
129211 |
const Type lhs = get_type(gwi, op->lhs), |
35 |
|
129211 |
rhs = get_type(gwi, op->rhs), |
36 |
|
129211 |
ret = get_type(gwi, op->ret); |
37 |
|
129211 |
const struct Op_Func opfunc = { .ck=op->ck, .em=op->em }; |
38 |
|
516844 |
const struct Op_Import opi = { .lhs=lhs, .rhs=rhs, .ret=ret, |
39 |
|
387633 |
.func=&opfunc, .data=(uintptr_t)f, .pos=gwi->loc, .op=op->sym }; |
40 |
|
129211 |
return add_op(gwi->gwion, &opi); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
|
44 |
|
46721 |
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 |
|
46721 |
gwi->oper->ret = t; |
47 |
|
46721 |
gwi->oper->rhs = r; |
48 |
|
46721 |
gwi->oper->lhs = l; |
49 |
|
46721 |
return GW_OK; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
59130 |
ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*, m_bool*)) { |
53 |
|
59130 |
gwi->oper->ck = ck; |
54 |
|
59130 |
return GW_OK; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
16060 |
ANN m_int gwi_oper_emi(const Gwi gwi, const opem em) { |
58 |
|
16060 |
gwi->oper->em = em; |
59 |
|
16060 |
return GW_OK; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
129211 |
ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) { |
63 |
|
129211 |
gwi->oper->sym = insert_symbol(gwi->gwion->st, op); |
64 |
|
129211 |
const m_bool ret = import_op(gwi, gwi->oper, f); |
65 |
|
129211 |
gwi->oper->ck = NULL; |
66 |
|
129211 |
gwi->oper->em = NULL; |
67 |
|
129211 |
return ret; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
4380 |
ANN m_int gwi_oper_cond(const Gwi gwi, const m_str type, |
71 |
|
|
const f_instr f1, const f_instr f2) { |
72 |
|
4380 |
GWI_BB(gwi_oper_ini(gwi, NULL, type, "bool")) |
73 |
|
4380 |
GWI_BB(gwi_oper_end(gwi, "@conditionnal", f1)) |
74 |
|
4380 |
GWI_BB(gwi_oper_end(gwi, "@unconditionnal", f2)) |
75 |
|
4380 |
return GW_OK; |
76 |
|
|
} |