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