Gwion coverage report


Directory: src/
File: src/lib/prim.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 407 410 99.3%
Functions: 98 99 99.0%
Branches: 186 476 39.1%

Line Branch Exec Source
1 #include <limits.h>
2 #include "gwion_util.h"
3 #include "gwion_ast.h"
4 #include "gwion_env.h"
5 #include "vm.h"
6 #include "gwion.h"
7 #include "instr.h"
8 #include "object.h"
9 #include "emit.h"
10 #include "operator.h"
11 #include "import.h"
12 #include "gwi.h"
13 #include "driver.h"
14 #include "traverse.h"
15 #include "parse.h"
16 #include "specialid.h"
17 #include "array.h"
18 #include "gack.h"
19
20 #define CHECK_OP(op, check, func) _CHECK_OP(op, check, int_##func)
21
22 #define POWEROF2_OPT(name, OP) \
23 if (is_prim_int(bin->rhs) && pot(bin->rhs->d.prim.d.num)) { \
24 bin->op = insert_symbol(#OP); \
25 bin->rhs->d.prim.d.num = sqrt(bin->rhs->d.prim.d.num); \
26 return check_exp(env, exp_self(bin)); \
27 }
28
29 #define BINARY_FOLD(ntype, name, TYPE, OP, pre, funcl, funcr, ctype, \
30 exptype, lmember, rmember, retmember) \
31 static OP_CHECK(opck_##ntype##_##name) { \
32 /*const*/ Exp_Binary *bin = (Exp_Binary *)data; \
33 const Type t = env->gwion->type[TYPE]; \
34 if (!exp_self(bin)->pos.first.line) return t; \
35 pre if (!funcl(bin->lhs) || !funcr(bin->rhs)) return t; \
36 const ctype num = \
37 bin->lhs->d.prim.d.lmember OP bin->rhs->d.prim.d.rmember; \
38 free_exp(env->gwion->mp, bin->lhs); \
39 free_exp(env->gwion->mp, bin->rhs); \
40 exp_self(bin)->exp_type = ae_exp_primary; \
41 exp_self(bin)->d.prim.prim_type = exptype; \
42 exp_self(bin)->d.prim.d.retmember = num; \
43 return t; \
44 }
45
46 #define BINARY_FOLD_Z(ntype, name, TYPE, OP, pre, funcl, funcr, ctype, \
47 exptype, lmember, rmember, retmember) \
48 static OP_CHECK(opck_##ntype##_##name) { \
49 /*const*/ Exp_Binary *bin = (Exp_Binary *)data; \
50 const Type t = env->gwion->type[TYPE]; \
51 if (!exp_self(bin)->pos.first.line) return t; \
52 const bool rconst = funcr(bin->rhs); \
53 if(rconst && !bin->rhs->d.prim.d.retmember) \
54 ERR_N(bin->rhs->pos, _("ZeroDivideException")); \
55 pre if (!funcl(bin->lhs) || !rconst) return t; \
56 const ctype num = \
57 bin->lhs->d.prim.d.lmember OP bin->rhs->d.prim.d.rmember; \
58 free_exp(env->gwion->mp, bin->lhs); \
59 free_exp(env->gwion->mp, bin->rhs); \
60 exp_self(bin)->exp_type = ae_exp_primary; \
61 exp_self(bin)->d.prim.prim_type = exptype; \
62 exp_self(bin)->d.prim.d.retmember = num; \
63 return t; \
64 }
65
66 #define BINARY_INT_FOLD(name, TYPE, OP, pre) \
67 BINARY_FOLD(int, name, TYPE, OP, pre, is_prim_int, is_prim_int, m_int, \
68 ae_prim_num, num, num, num)
69
70 #define BINARY_INT_FOLD_Z(name, TYPE, OP, pre) \
71 BINARY_FOLD_Z(int, name, TYPE, OP, pre, is_prim_int, is_prim_int, m_int, \
72 ae_prim_num, num, num, num)
73
74
5/6
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 22 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 5 times.
28 BINARY_INT_FOLD(add, et_int, +,)
75
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
13 BINARY_INT_FOLD(sub, et_int, -,)
76
4/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 BINARY_INT_FOLD(mul, et_int, *, /*POWEROF2_OPT(name, <<)*/)
77
7/10
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
4 BINARY_INT_FOLD_Z(div, et_int, /,/* POWEROF2_OPT(name, >>)*/)
78
5/10
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
2 BINARY_INT_FOLD_Z(mod, et_int, %,)
79
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(sl, et_int, <<,)
80
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(sr, et_int, >>,)
81
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(sand, et_int, &,)
82
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(sor, et_int, |,)
83
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(xor, et_int, ^,)
84
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
5 BINARY_INT_FOLD(gt, et_bool, >,)
85
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
15 BINARY_INT_FOLD(lt, et_bool, <,)
86
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(ge, et_bool, >=,)
87
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FOLD(le, et_bool, <=,)
88
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_INT_FOLD(and, et_bool, &&,)
89
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_INT_FOLD(or, et_bool, ||,)
90
4/6
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
16 BINARY_INT_FOLD(eq, et_bool, ==,)
91
4/6
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
3 BINARY_INT_FOLD(neq, et_bool, !=,)
92
93 #define BINARY_OP_EMIT(name, type, member, val) \
94 static OP_EMIT(opem_##type##_##name) { \
95 Exp_Binary *const bin = (Exp_Binary *)data; \
96 if(!is_prim_##type(bin->rhs)) \
97 (void)emit_add_instr(emit, type##_##name); \
98 else { \
99 const Instr instr = (Instr)vector_back(&emit->code->instr); \
100 instr->opcode = e##type##_##name##_imm; \
101 instr->val = bin->rhs->d.prim.d.member; \
102 } \
103 return GW_OK; \
104 }
105
106 #define BINARY_INT_EMIT(name) BINARY_OP_EMIT(name, int, num, m_val)
107
2/2
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 2 times.
19 BINARY_INT_EMIT(add)
108
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
13 BINARY_INT_EMIT(sub)
109
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_INT_EMIT(mul)
110
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 BINARY_INT_EMIT(div)
111
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_INT_EMIT(mod)
112
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 11 times.
13 BINARY_INT_EMIT(lt)
113
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_INT_EMIT(le)
114
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
5 BINARY_INT_EMIT(gt)
115
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_INT_EMIT(ge)
116
117 #define IMPORT_BINARY_INT(name, op) \
118 GWI_BB(gwi_oper_add(gwi, opck_int_##name)) \
119 GWI_BB(gwi_oper_emi(gwi, opem_int_##name)) \
120 GWI_BB(gwi_oper_end(gwi, #op, NULL))
121
122 638 GWION_IMPORT(int_op) {
123 638 GWI_BB(gwi_oper_ini(gwi, "int", "int", "int"))
124 638 IMPORT_BINARY_INT(add, +)
125 638 IMPORT_BINARY_INT(sub, -)
126 638 IMPORT_BINARY_INT(mul, *)
127 638 IMPORT_BINARY_INT(div, /)
128 638 IMPORT_BINARY_INT(mod, %)
129 638 return GW_OK;
130 }
131
132 638 static GWION_IMPORT(int_logical) {
133 638 GWI_BB(gwi_oper_ini(gwi, "int", "int", "int"))
134 638 IMPORT_BINARY_INT(gt, >)
135 638 IMPORT_BINARY_INT(ge, >=)
136 638 IMPORT_BINARY_INT(lt, <)
137 638 IMPORT_BINARY_INT(le, <=)
138 638 GWI_BB(gwi_oper_add(gwi, opck_int_sr))
139 638 GWI_BB(gwi_oper_end(gwi, ">>", int_sr))
140 638 GWI_BB(gwi_oper_add(gwi, opck_int_sl))
141 638 GWI_BB(gwi_oper_end(gwi, "<<", int_sl))
142 638 GWI_BB(gwi_oper_add(gwi, opck_int_sand))
143 638 GWI_BB(gwi_oper_end(gwi, "&", int_sand))
144 638 GWI_BB(gwi_oper_add(gwi, opck_int_sor))
145 638 GWI_BB(gwi_oper_end(gwi, "|", int_sor))
146 638 GWI_BB(gwi_oper_add(gwi, opck_int_xor))
147 638 GWI_BB(gwi_oper_end(gwi, "^", int_xor))
148 638 GWI_BB(gwi_oper_ini(gwi, "int", "int", "bool"))
149 638 GWI_BB(gwi_oper_add(gwi, opck_int_and))
150 638 GWI_BB(gwi_oper_end(gwi, "&&", int_and))
151 638 GWI_BB(gwi_oper_add(gwi, opck_int_or))
152 638 GWI_BB(gwi_oper_end(gwi, "||", int_or))
153 638 GWI_BB(gwi_oper_add(gwi, opck_int_eq))
154 638 GWI_BB(gwi_oper_end(gwi, "==", int_eq))
155 638 GWI_BB(gwi_oper_add(gwi, opck_int_neq))
156 638 return gwi_oper_end(gwi, "!=", int_neq);
157 }
158
159 638 static GWION_IMPORT(int_r) {
160 638 GWI_BB(gwi_oper_ini(gwi, "int", "int", "int"))
161 638 CHECK_OP(":=>", rassign, r_assign)
162 638 CHECK_OP("+=>", rassign, r_plus)
163 638 CHECK_OP("-=>", rassign, r_minus)
164 638 CHECK_OP("*=>", rassign, r_mul)
165 638 CHECK_OP("/=>", rassign, r_div)
166 638 CHECK_OP("%=>", rassign, r_modulo)
167 638 CHECK_OP("<<=>", rassign, r_sl)
168 638 CHECK_OP(">>=>", rassign, r_sr)
169 638 CHECK_OP("&=>", rassign, r_sand)
170 638 CHECK_OP("|=>", rassign, r_sor)
171 638 CHECK_OP("^=>", rassign, r_sxor)
172 638 return GW_OK;
173 }
174
175 2 static INSTR(IntRange) {
176 2 shred->reg -= SZ_INT;
177 2 const m_int start = *(m_int *)REG(-SZ_INT);
178 2 const m_int end = *(m_int *)REG(0);
179
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 const m_int op = start < end ? 1 : -1;
180
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 const m_uint sz = op > 0 ? end - start : start - end;
181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(sz >= SIZE_MAX/SZ_INT) {
182 handle(shred, "RangeTooBig");
183 return;
184 }
185 2 const M_Object array = new_array(shred->info->mp, (Type)instr->m_val, sz);
186
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
9 for (m_int i = start, j = 0; i != end; i += op, ++j)
187 7 m_vector_set(ARRAY(array), j, &i);
188 2 *(M_Object *)REG(-SZ_INT) = array;
189 }
190
191 2 static OP_CHECK(opck_int_range) {
192 2 const Exp exp = (Exp)data;
193 2 const Range *range = exp->d.prim.d.range;
194
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 const Exp e = range->start ?: range->end;
195 2 return array_type(env, e->type, 1);
196 }
197
198 2 static OP_EMIT(opem_int_range) {
199 2 const Exp exp = (Exp)data;
200 2 const Instr instr = emit_add_instr(emit, IntRange);
201 2 instr->m_val = (m_uint)exp->type;
202 2 return GW_OK;
203 }
204
205 #define UNARY_FOLD(ntype, name, TYPE, OP, func, ctype, exptype, member) \
206 static OP_CHECK(opck_##ntype##_##name) { \
207 /*const*/ Exp_Unary *unary = (Exp_Unary *)data; \
208 const Type t = env->gwion->type[TYPE]; \
209 CHECK_NN(opck_unary_meta(env, data)); \
210 if (!func(unary->exp)) return t; \
211 const ctype num = OP unary->exp->d.prim.d.member; \
212 exp_self(unary)->exp_type = ae_exp_primary; \
213 exp_self(unary)->d.prim.prim_type = exptype; \
214 exp_self(unary)->d.prim.d.num = num; \
215 return t; \
216 }
217 #define UNARY_INT_FOLD(name, TYPE, OP) \
218 UNARY_FOLD(int, name, TYPE, OP, is_prim_int, m_int, ae_prim_num, num)
219
3/4
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 18 times.
19 UNARY_INT_FOLD(negate, et_int, -)
220 UNARY_INT_FOLD(cmp, et_int, ~)
221
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 UNARY_INT_FOLD(not, et_bool, !)
222
223 638 static GWION_IMPORT(int_unary) {
224 638 GWI_BB(gwi_oper_ini(gwi, NULL, "int", "int"))
225 638 GWI_BB(gwi_oper_add(gwi, opck_int_negate))
226 638 GWI_BB(gwi_oper_end(gwi, "-", int_negate))
227 638 GWI_BB(gwi_oper_add(gwi, opck_unary))
228 638 GWI_BB(gwi_oper_end(gwi, "++", int_pre_inc))
229 638 GWI_BB(gwi_oper_add(gwi, opck_unary))
230 638 GWI_BB(gwi_oper_end(gwi, "--", int_pre_dec))
231 638 GWI_BB(gwi_oper_add(gwi, opck_int_cmp))
232 638 GWI_BB(gwi_oper_end(gwi, "~", int_cmp))
233 638 GWI_BB(gwi_oper_ini(gwi, "int", NULL, NULL))
234 638 GWI_BB(gwi_oper_add(gwi, opck_int_range))
235 638 GWI_BB(gwi_oper_emi(gwi, opem_int_range))
236 638 GWI_BB(gwi_oper_end(gwi, "[:]", NULL))
237 638 GWI_BB(gwi_oper_ini(gwi, "int", NULL, "int"))
238 638 GWI_BB(gwi_oper_add(gwi, opck_post))
239 638 GWI_BB(gwi_oper_end(gwi, "++", int_post_inc))
240 638 GWI_BB(gwi_oper_add(gwi, opck_post))
241 638 GWI_BB(gwi_oper_end(gwi, "--", int_post_dec))
242 638 return GW_OK;
243 }
244 68 static GACK(gack_bool) {
245 // gw_out("%s", *(m_uint*)VALUE ? "true" : "false");
246
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 32 times.
68 INTERP_PRINTF("%s", *(m_uint *)VALUE ? "true" : "false");
247 68 }
248
249 2 static OP_CHECK(bool2float) {
250 2 struct Implicit *impl = (struct Implicit *)data;
251
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(!env->context->error) {
252 1 gwerr_basic("Can't implicitely cast {G+}bool{0} to {G+}float{0}", NULL, "Did you forget a cast?",
253 1 env->name, impl->e->pos, 0);
254 1 env_set_error(env, true);
255 }
256 2 return env->gwion->type[et_error];
257 }
258
259 638 static GWION_IMPORT(int_values) {
260
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 638 times.
638 DECL_OB(const Type, t_bool, = gwi_mk_type(gwi, "bool", SZ_INT, "int"));
261 638 GWI_BB(gwi_set_global_type(gwi, t_bool, et_bool))
262 638 GWI_BB(gwi_gack(gwi, t_bool, gack_bool))
263 638 gwi_item_ini(gwi, "bool", "true");
264 638 gwi_item_end(gwi, ae_flag_const, num, 1);
265 638 gwi_item_ini(gwi, "bool", "false");
266 638 gwi_item_end(gwi, ae_flag_const, num, 0);
267 638 GWI_BB(gwi_oper_ini(gwi, NULL, "int", "bool"))
268 638 GWI_BB(gwi_oper_add(gwi, opck_unary_meta))
269 638 GWI_BB(gwi_oper_add(gwi, opck_int_not))
270 638 GWI_BB(gwi_oper_end(gwi, "!", IntNot))
271 638 GWI_BB(gwi_oper_ini(gwi, "bool", "float", NULL))
272 638 GWI_BB(gwi_oper_add(gwi, bool2float));
273 638 GWI_BB(gwi_oper_end(gwi, "@implicit", NULL))
274 638 struct SpecialId_ spid = {
275 .type = t_bool, .exec = RegPushMaybe, .is_const = 1};
276 638 gwi_specialid(gwi, "maybe", &spid);
277 638 return GW_OK;
278 }
279
280 638 static GWION_IMPORT(int) {
281 638 GWI_BB(gwimport_int_values(gwi))
282 638 GWI_BB(gwi_oper_cond(gwi, "int", BranchEqInt, BranchNeqInt))
283 638 GWI_BB(gwi_oper_ini(gwi, "int", "int", "int"))
284 638 GWI_BB(gwimport_int_op(gwi))
285 638 GWI_BB(gwimport_int_logical(gwi))
286 638 GWI_BB(gwimport_int_r(gwi))
287 638 GWI_BB(gwimport_int_unary(gwi))
288 638 return GW_OK;
289 }
290
291 5 static OP_CHECK(opck_cast_f2i) {
292 5 Exp_Cast *cast = (Exp_Cast*)data;
293
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
5 if(is_prim_float(cast->exp)) {
294 2 const m_float f = cast->exp->d.prim.d.fnum;
295 2 free_type_decl(env->gwion->mp, cast->td);
296 2 free_exp(env->gwion->mp, cast->exp);
297 2 Exp e = exp_self(cast);
298 2 e->exp_type = ae_exp_primary;
299 2 e->d.prim.prim_type = ae_prim_num;
300 2 e->d.prim.d.num = f;
301 }
302 5 return env->gwion->type[et_int];
303 }
304 /*
305 ANN static void tofloat(Exp e, const m_int i) {
306 e->exp_type = ae_exp_primary;
307 e->d.prim.prim_type = ae_prim_float;
308 e->d.prim.d.fnum = i;
309 }
310 */
311 2 static OP_CHECK(opck_cast_i2f) {
312 2 Exp_Cast *cast = (Exp_Cast*)data;
313
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if(is_prim_int(cast->exp)) {
314 2 const m_int i = cast->exp->d.prim.d.num;
315 2 free_type_decl(env->gwion->mp, cast->td);
316 2 free_exp(env->gwion->mp, cast->exp);
317 2 Exp e = exp_self(cast);
318 2 e->exp_type = ae_exp_primary;
319 2 e->d.prim.prim_type = ae_prim_float;
320 2 e->d.prim.d.fnum = i;
321 }
322 2 return env->gwion->type[et_float];
323 }
324
325 22 static OP_CHECK(opck_implicit_i2f) {
326 // TODO: same as in cast_i2f
327 22 return env->gwion->type[et_float];
328 }
329
330 #define CHECK_FF(op, check, func) _CHECK_OP(op, check, float_##func)
331 #define CHECK_IF(op, check, func) _CHECK_OP(op, check, int_float_##func)
332 #define CHECK_FI(op, check, func) _CHECK_OP(op, check, float_int_##func)
333
334 #define BINARY_INT_FLOAT_FOLD(name, TYPE, OP, pre) \
335 BINARY_FOLD(int_float, name, TYPE, OP, pre, is_prim_int, \
336 is_prim_float, m_float, ae_prim_float, num, fnum, fnum)
337 #define BINARY_INT_FLOAT_FOLD_Z(name, TYPE, OP, pre) \
338 BINARY_FOLD_Z(int_float, name, TYPE, OP, pre, is_prim_int, \
339 is_prim_float, m_float, ae_prim_float, num, fnum, fnum)
340 #define BINARY_INT_FLOAT_FOLD2(name, TYPE, OP, pre) \
341 BINARY_FOLD(int_float, name, TYPE, OP, pre, is_prim_int, \
342 is_prim_float, m_float, ae_prim_num, num, fnum, num)
343
344
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FLOAT_FOLD(add, et_float, +,)
345
4/6
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
4 BINARY_INT_FLOAT_FOLD(sub, et_float, -,)
346
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_INT_FLOAT_FOLD(mul, et_float, *, /*POWEROF2_OPT(name, <<)*/)
347
3/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
1 BINARY_INT_FLOAT_FOLD_Z(div, et_float, /, /*POWEROF2_OPT(name, >>)*/)
348
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1 BINARY_INT_FLOAT_FOLD2(gt, et_bool, >,)
349
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1 BINARY_INT_FLOAT_FOLD2(ge, et_bool, >=,)
350
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1 BINARY_INT_FLOAT_FOLD2(lt, et_bool, <=,)
351
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1 BINARY_INT_FLOAT_FOLD2(le, et_bool, <=,)
352
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_INT_FLOAT_FOLD2(and, et_bool, &&,)
353
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_INT_FLOAT_FOLD2(or, et_bool, ||,)
354
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1 BINARY_INT_FLOAT_FOLD2(eq, et_bool, ==,)
355
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1 BINARY_INT_FLOAT_FOLD2(neq, et_bool, !=,)
356
357 638 static GWION_IMPORT(intfloat) {
358 638 GWI_BB(gwi_oper_ini(gwi, "int", "float", "int"))
359 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_gt))
360 638 GWI_BB(gwi_oper_end(gwi, ">", int_float_gt))
361 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_ge))
362 638 GWI_BB(gwi_oper_end(gwi, ">=", int_float_ge))
363 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_lt))
364 638 GWI_BB(gwi_oper_end(gwi, "<", int_float_lt))
365 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_le))
366 638 GWI_BB(gwi_oper_end(gwi, "<=", int_float_le))
367 638 GWI_BB(gwi_oper_ini(gwi, "int", "float", "float"))
368 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_add))
369 638 GWI_BB(gwi_oper_end(gwi, "+", int_float_plus))
370 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_mul))
371 638 GWI_BB(gwi_oper_end(gwi, "*", int_float_mul))
372 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_sub))
373 638 GWI_BB(gwi_oper_end(gwi, "-", int_float_minus))
374 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_div))
375 638 GWI_BB(gwi_oper_end(gwi, "/", int_float_div))
376 638 CHECK_IF(":=>", rassign, r_assign)
377 638 CHECK_IF("+=>", rassign, r_plus)
378 638 CHECK_IF("-=>", rassign, r_minus)
379 638 CHECK_IF("*=>", rassign, r_mul)
380 638 CHECK_IF("/=>", rassign, r_div)
381 638 _CHECK_OP("$", cast_i2f, CastI2F)
382 638 _CHECK_OP("@implicit", implicit_i2f, CastI2F)
383 638 GWI_BB(gwi_oper_ini(gwi, "int", "float", "bool"))
384 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_and))
385 638 GWI_BB(gwi_oper_end(gwi, "&&", int_float_and))
386 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_or))
387 638 GWI_BB(gwi_oper_end(gwi, "||", int_float_or))
388 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_eq))
389 638 GWI_BB(gwi_oper_end(gwi, "==", int_float_eq))
390 638 GWI_BB(gwi_oper_add(gwi, opck_int_float_neq))
391 638 GWI_BB(gwi_oper_end(gwi, "!=", int_float_neq))
392 638 return GW_OK;
393 }
394
395 #define BINARY_FLOAT_INT_FOLD(name, TYPE, OP, pre) \
396 BINARY_FOLD(float_int, name, TYPE, OP, pre, is_prim_float, \
397 is_prim_int, m_float, ae_prim_float, fnum, num, fnum)
398
399 #define BINARY_FLOAT_INT_FOLD_Z(name, TYPE, OP, pre) \
400 BINARY_FOLD_Z(float_int, name, TYPE, OP, pre, is_prim_float, \
401 is_prim_int, m_float, ae_prim_float, fnum, num, fnum)
402
403 #define BINARY_FLOAT_INT_FOLD2(name, TYPE, OP, pre) \
404 BINARY_FOLD(float_int, name, TYPE, OP, pre, is_prim_float, \
405 is_prim_int, m_int, ae_prim_num, fnum, num, num)
406
407
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD(add, et_float, +,)
408
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD(sub, et_float, -,)
409
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD(mul, et_float, *, /*POWEROF2_OPT(name, <<)*/)
410
3/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
1 BINARY_FLOAT_INT_FOLD_Z(div, et_float, /, /*POWEROF2_OPT(name, >>)*/)
411
412
4/6
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
5 BINARY_FLOAT_INT_FOLD2(gt, et_bool, >,)
413
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD2(ge, et_bool, >=,)
414
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD2(lt, et_bool, <=,)
415
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD2(le, et_bool, <=,)
416
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_FLOAT_INT_FOLD2(and, et_bool, &&,)
417
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_FLOAT_INT_FOLD2(or, et_bool, ||,)
418
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 BINARY_FLOAT_INT_FOLD2(eq, et_bool, ==,)
419
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_INT_FOLD2(neq, et_bool, !=,)
420
421 638 static GWION_IMPORT(floatint) {
422 638 GWI_BB(gwi_oper_ini(gwi, "float", "int", "float"))
423 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_add))
424 638 GWI_BB(gwi_oper_end(gwi, "+", float_int_plus))
425 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_sub))
426 638 GWI_BB(gwi_oper_end(gwi, "-", float_int_minus))
427 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_mul))
428 638 GWI_BB(gwi_oper_end(gwi, "*", float_int_mul))
429 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_div))
430 638 GWI_BB(gwi_oper_end(gwi, "/", float_int_div))
431 638 CHECK_FI(":=>", rassign, r_assign)
432 638 CHECK_FI("+=>", rassign, r_plus)
433 638 CHECK_FI("-=>", rassign, r_minus)
434 638 CHECK_FI("*=>", rassign, r_mul)
435 638 CHECK_FI("/=>", rassign, r_div)
436 638 _CHECK_OP("$", cast_f2i, CastF2I)
437 638 GWI_BB(gwi_oper_ini(gwi, "float", "int", "bool"))
438 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_and))
439 638 GWI_BB(gwi_oper_end(gwi, "&&", float_int_and))
440 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_or))
441 638 GWI_BB(gwi_oper_end(gwi, "||", float_int_or))
442 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_eq))
443 638 GWI_BB(gwi_oper_end(gwi, "==", float_int_eq))
444 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_neq))
445 638 GWI_BB(gwi_oper_end(gwi, "!=", float_int_neq))
446 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_gt))
447 638 GWI_BB(gwi_oper_end(gwi, ">", float_int_gt))
448 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_ge))
449 638 GWI_BB(gwi_oper_end(gwi, ">=", float_int_ge))
450 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_lt))
451 638 GWI_BB(gwi_oper_end(gwi, "<", float_int_lt))
452 638 GWI_BB(gwi_oper_add(gwi, opck_float_int_le))
453 638 GWI_BB(gwi_oper_end(gwi, "<=", float_int_le))
454 638 return GW_OK;
455 }
456
457 638 static GWION_IMPORT(dur) {
458 638 GWI_BB(gwi_oper_cond(gwi, "dur", BranchEqFloat, BranchNeqFloat))
459 638 GWI_BB(gwi_oper_ini(gwi, "dur", "dur", "dur"))
460 638 CHECK_FF(":=>", rassign, r_assign)
461 638 CHECK_FF("+=>", rassign, r_plus)
462 638 CHECK_FF("-=>", rassign, r_minus)
463 638 CHECK_FF("*=>", rassign, r_mul)
464 638 CHECK_FF("/=>", rassign, r_div)
465 638 GWI_BB(gwi_oper_end(gwi, "+", float_add))
466 638 GWI_BB(gwi_oper_end(gwi, "-", float_sub))
467 638 GWI_BB(gwi_oper_end(gwi, "*", float_mul))
468 638 GWI_BB(gwi_oper_ini(gwi, "dur", "dur", "float"))
469 638 GWI_BB(gwi_oper_eff(gwi, "ZeroDivideException"))
470 638 GWI_BB(gwi_oper_end(gwi, "/", float_div))
471
472 638 GWI_BB(gwi_oper_ini(gwi, "dur", "float", "dur"))
473 638 GWI_BB(gwi_oper_eff(gwi, "ZeroDivideException"))
474 638 GWI_BB(gwi_oper_end(gwi, "/", float_div))
475
476 638 GWI_BB(gwi_oper_ini(gwi, "float", "dur", "dur"))
477 638 CHECK_FF("*=>", rassign, r_mul)
478 638 CHECK_FF("/=>", rassign, r_div)
479
480 638 GWI_BB(gwi_oper_ini(gwi, "dur", "dur", "bool"))
481 638 GWI_BB(gwi_oper_end(gwi, "==", float_eq))
482 638 GWI_BB(gwi_oper_end(gwi, "!=", float_neq))
483 638 GWI_BB(gwi_oper_end(gwi, ">", float_gt))
484 638 GWI_BB(gwi_oper_end(gwi, ">=", float_ge))
485 638 GWI_BB(gwi_oper_end(gwi, "<", float_lt))
486 638 return gwi_oper_end(gwi, "<=", float_le);
487 }
488
489 70 static inline int is_now(const Env env, const Exp exp) {
490 140 return exp->exp_type == ae_exp_primary &&
491
2/4
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
140 exp->d.prim.prim_type == ae_prim_id &&
492
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 exp->d.prim.d.var == insert_symbol("now");
493 }
494
495 70 static OP_CHECK(opck_now) {
496 70 const Exp_Binary *bin = (Exp_Binary *)data;
497
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
70 if (!is_now(env, bin->rhs)) CHECK_NN(opck_const_rhs(env, data));
498 70 exp_setvar(bin->rhs, 1);
499 70 return bin->rhs->type;
500 }
501
502 638 static GWION_IMPORT(time) {
503 638 GWI_BB(gwi_oper_cond(gwi, "time", BranchEqFloat, BranchNeqFloat))
504 638 GWI_BB(gwi_oper_ini(gwi, "time", "time", "time"))
505 638 CHECK_FF(":=>", rassign, r_assign)
506 638 GWI_BB(gwi_oper_ini(gwi, "time", "dur", "time"))
507 638 GWI_BB(gwi_oper_end(gwi, "+", float_add))
508 638 GWI_BB(gwi_oper_end(gwi, "*", float_mul))
509 638 GWI_BB(gwi_oper_eff(gwi, "ZeroDivideException"))
510 638 GWI_BB(gwi_oper_end(gwi, "/", float_div))
511 638 GWI_BB(gwi_oper_ini(gwi, "time", "time", "dur"))
512 638 GWI_BB(gwi_oper_end(gwi, "-", float_sub))
513 638 GWI_BB(gwi_oper_ini(gwi, "float", "time", "time"))
514 638 CHECK_FF("*=>", rassign, r_mul)
515 638 CHECK_FF("/=>", rassign, r_div)
516 638 GWI_BB(gwi_oper_ini(gwi, "dur", "time", "time"))
517 638 CHECK_FF(":=>", rassign, r_assign)
518 638 GWI_BB(gwi_oper_end(gwi, "+", float_add))
519 638 GWI_BB(gwi_oper_ini(gwi, "dur", "@now", "time"))
520 638 _CHECK_OP("=>", now, Time_Advance)
521 638 GWI_BB(gwi_oper_ini(gwi, "time", "time", "bool"))
522 638 GWI_BB(gwi_oper_end(gwi, ">", float_gt))
523 638 GWI_BB(gwi_oper_end(gwi, ">=", float_ge))
524 638 GWI_BB(gwi_oper_end(gwi, "<", float_lt))
525 638 return gwi_oper_end(gwi, "<=", float_le);
526 }
527
528 #define BINARY_FLOAT_FOLD(name, TYPE, OP, pre) \
529 BINARY_FOLD(float, name, TYPE, OP, pre, is_prim_float, is_prim_float, \
530 m_float, ae_prim_float, fnum, fnum, fnum)
531
532 #define BINARY_FLOAT_FOLD_Z(name, TYPE, OP, pre) \
533 BINARY_FOLD_Z(float, name, TYPE, OP, pre, is_prim_float, is_prim_float, \
534 m_float, ae_prim_float, fnum, fnum, fnum)
535
536 #define BINARY_FLOAT_FOLD2(name, TYPE, OP, pre) \
537 BINARY_FOLD(float, name, TYPE, OP, pre, is_prim_float, is_prim_float, \
538 m_int, ae_prim_num, fnum, fnum, num)
539
540
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 BINARY_FLOAT_FOLD(add, et_float, +,)
541
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 BINARY_FLOAT_FOLD(sub, et_float, -,)
542
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_FOLD(mul, et_float, *, /*POWEROF2_OPT(name, <<)*/)
543
3/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
1 BINARY_FLOAT_FOLD_Z(div, et_float, /, /*POWEROF2_OPT(name, >>)*/)
544
545
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_FLOAT_FOLD2(and, et_bool, &&,)
546
2/10
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1 BINARY_FLOAT_FOLD2(or, et_bool, ||,)
547
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 BINARY_FLOAT_FOLD2(eq, et_bool, ==,)
548
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_FOLD2(neq, et_bool, !=,)
549
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 BINARY_FLOAT_FOLD2(gt, et_bool, >,)
550
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_FOLD2(ge, et_bool, >=,)
551
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_FOLD2(lt, et_bool, <,)
552
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 BINARY_FLOAT_FOLD2(le, et_bool, <=,)
553
554 #define BINARY_FLOAT_EMIT(name) BINARY_OP_EMIT(name, float, fnum, f)
555
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_FLOAT_EMIT(add)
556
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 BINARY_FLOAT_EMIT(sub)
557
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_FLOAT_EMIT(mul)
558
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_FLOAT_EMIT(div)
559
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_FLOAT_EMIT(ge)
560
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 BINARY_FLOAT_EMIT(gt)
561
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_FLOAT_EMIT(le)
562
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 BINARY_FLOAT_EMIT(lt)
563
564 #define UNARY_FLOAT_FOLD(name, TYPE, OP) \
565 UNARY_FOLD(float, name, TYPE, OP, is_prim_int, m_float, ae_prim_float, fnum)
566
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 UNARY_FLOAT_FOLD(negate, et_float, -)
567 // UNARY_INT_FOLD(cmp, et_float, ~)
568
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 UNARY_FLOAT_FOLD(not, et_bool, !)
569
570 #define IMPORT_BINARY_FLOAT(name, op) \
571 GWI_BB(gwi_oper_add(gwi, opck_float_##name)) \
572 GWI_BB(gwi_oper_emi(gwi, opem_float_##name)) \
573 GWI_BB(gwi_oper_end(gwi, #op, NULL))
574
575 638 static GWION_IMPORT(float) {
576 638 GWI_BB(gwi_oper_cond(gwi, "float", BranchEqFloat, BranchNeqFloat))
577 638 GWI_BB(gwi_oper_ini(gwi, "float", "float", "float"))
578 638 IMPORT_BINARY_FLOAT(add, +);
579 638 IMPORT_BINARY_FLOAT(sub, -);
580 638 IMPORT_BINARY_FLOAT(mul, *);
581 638 IMPORT_BINARY_FLOAT(div, /);
582 638 GWI_BB(gwi_oper_end(gwi, "@implicit", NULL))
583 638 CHECK_FF(":=>", rassign, r_assign)
584 638 CHECK_FF("+=>", rassign, r_plus)
585 638 CHECK_FF("-=>", rassign, r_minus)
586 638 CHECK_FF("*=>", rassign, r_mul)
587 638 CHECK_FF("/=>", rassign, r_div)
588 638 GWI_BB(gwi_oper_ini(gwi, "float", "float", "bool"))
589 638 GWI_BB(gwi_oper_add(gwi, opck_float_and))
590 638 GWI_BB(gwi_oper_end(gwi, "&&", float_and))
591 638 GWI_BB(gwi_oper_add(gwi, opck_float_or))
592 638 GWI_BB(gwi_oper_end(gwi, "||", float_or))
593 638 GWI_BB(gwi_oper_add(gwi, opck_float_eq))
594 638 GWI_BB(gwi_oper_end(gwi, "==", float_eq))
595 638 GWI_BB(gwi_oper_add(gwi, opck_float_neq))
596 638 GWI_BB(gwi_oper_end(gwi, "!=", float_neq))
597 638 IMPORT_BINARY_FLOAT(gt, >);
598 638 IMPORT_BINARY_FLOAT(ge, >=);
599 638 IMPORT_BINARY_FLOAT(lt, <);
600 638 IMPORT_BINARY_FLOAT(le, <=);
601 638 GWI_BB(gwi_oper_ini(gwi, NULL, "float", "float"))
602 // CHECK_FF("-", unary_meta, negate)
603 638 GWI_BB(gwi_oper_add(gwi, opck_float_negate))
604 638 GWI_BB(gwi_oper_end(gwi, "-", float_negate))
605 638 GWI_BB(gwi_oper_ini(gwi, "int", "dur", "dur"))
606 638 GWI_BB(gwi_oper_end(gwi, "::", int_float_mul))
607 638 GWI_BB(gwi_oper_ini(gwi, "float", "dur", "dur"))
608 638 GWI_BB(gwi_oper_end(gwi, "::", float_mul))
609 638 GWI_BB(gwi_oper_ini(gwi, NULL, "float", "bool"))
610 // GWI_BB(gwi_oper_add(gwi, opck_unary_meta2))
611 638 GWI_BB(gwi_oper_add(gwi, opck_float_not))
612 638 GWI_BB(gwi_oper_end(gwi, "!", float_not))
613 638 return GW_OK;
614 }
615
616 638 ANN static GWION_IMPORT(ux) {
617 638 char c[8] = { 'u' };
618 638 const Env env = gwi->gwion->env;
619
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 638 times.
3190 for(uint i = 1; i <= SZ_INT; i *= 2) {
620 2552 sprintf(c+1, "%u", i * CHAR_BIT);
621 2552 const Symbol s = insert_symbol(c);
622 2552 GWI_OB(gwi_primitive(gwi, s_name(s), i, ae_flag_none));
623 }
624 638 return GW_OK;
625 }
626
627 638 GWION_IMPORT(prim) {
628 638 GWI_BB(gwimport_int(gwi))
629 638 GWI_BB(gwimport_ux(gwi));
630 638 GWI_BB(gwimport_float(gwi)) // const folded
631 638 GWI_BB(gwimport_intfloat(gwi)) // const folded
632 638 GWI_BB(gwimport_floatint(gwi)) // const folded
633 638 GWI_BB(gwimport_dur(gwi))
634 638 return gwimport_time(gwi);
635 }
636