fix invalid free on syntax error
[m6w6/ext-psi] / scripts / gen_calc_bin.php
1 <?php
2
3 include __DIR__."/_include.php";
4
5 $ops = [
6 "lshift" => "<<",
7 "rshift" => ">>",
8 "and" => "&",
9 "xor" => "^",
10 "or" => "|",
11 ];
12
13 ?>
14
15 <?php foreach ($ops as $op_name => $op) : ?>
16
17 static inline token_t psi_calc_bin_<?=$op_name?>(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
18 {
19 impl_val i1, i2;
20
21 switch (t1) {<?php /*nobr*/ ?>
22 <?php foreach ($types as $t1 => $v1) : ?>
23 <?php if (t_is_special($t1)) :?>
24
25 #if HAVE_<?=$t1?>
26 <?php endif; ?>
27
28 case PSI_T_<?=$t1?>:
29 i1.u64 = v1-><?=$v1?>;
30 break;
31 <?php if (t_is_special($t1)) : ?>
32
33 #endif
34 <?php endif; ?>
35 <?php endforeach; ?>
36
37 default:
38 assert(0);
39 break;
40 }
41
42 switch (t2) {<?php /*nobr*/ ?>
43 <?php foreach ($types as $t2 => $v2) : ?>
44 <?php if (t_is_special($t2)) :?>
45
46 #if HAVE_<?=$t2?>
47 <?php endif; ?>
48
49 case PSI_T_<?=$t2?>:
50 i2.u64 = v2-><?=$v2?>;
51 break;<?php /*nobr*/ ?>
52 <?php if (t_is_special($t2)) : ?>
53
54 #endif
55 <?php endif; ?>
56 <?php endforeach; ?>
57
58 default:
59 assert(0);
60 break;
61 }
62
63 res->u64 = i1.u64 <?=$op?> i2.u64;
64 return PSI_T_UINT64;
65 }
66 <?php endforeach; ?>