-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimdef.fer
165 lines (149 loc) · 3.92 KB
/
primdef.fer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
let io = import('std/io');
let fmt = import('std/fmt');
let sys = import('std/sys');
let vec = import('std/vec');
let arith_assn_only_templ = `INTRINSIC({opname}_{ty})
\\{
args[0]->updateValue(c, args[1]->getVal());
stmt->setVal(args[0]->getVal());
return true;
}`;
# int
{
let op = '=';
let opname = 'assn';
let ty = 'int';
let tycap = 'Int';
io.println(fmt.template(arith_assn_only_templ));
io.println();
}
# flt
{
let op = '=';
let opname = 'assn';
let ty = 'flt';
let tycap = 'Flt';
io.println(fmt.template(arith_assn_only_templ));
io.println();
}
let arith_templ = `INTRINSIC({opname}_{ty})
\\{
auto res = Get{tycap}(args[0]) {op} Get{tycap}(args[1]);
stmt->setVal({tycap}Val::create(c, CDTRUE, res));
return true;
}`;
let arith_ops = vec.new('+', '-', '*', '/', '%', '&', '|', '^', '<<', '>>');
let arith_opnames = vec.new(.add, .sub, .mul, .div, .mod, .band, .bor, .bxor, .lshift, .rshift);
# int
for let i = 0; i < arith_ops.len(); ++i {
let op = arith_ops[i];
let opname = arith_opnames[i];
let ty = 'int';
let tycap = 'Int';
io.println(fmt.template(arith_templ));
io.println();
}
# flt
for let i = 0; i < arith_ops.len(); ++i {
let op = arith_ops[i];
if op == '%' { break; } # don't go after '/'
let opname = arith_opnames[i];
let ty = 'flt';
let tycap = 'Flt';
io.println(fmt.template(arith_templ));
io.println();
}
let arithassn_templ = `INTRINSIC({opname}_{ty})
\\{
auto res = Get{tycap}(args[0]) {op} Get{tycap}(args[1]);
stmt->setVal({tycap}Val::create(c, CDTRUE, res));
return true;
}
`;
let arithassn_ops = vec.new('+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>=');
let arithassn_opnames = vec.new(.addassn, .subassn, .mulassn, .divassn, .modassn, .bandassn, .borassn, .bxorassn, .lshiftassn, .rshiftassn);
# int
for let i = 0; i < arithassn_ops.len(); ++i {
let op = arithassn_ops[i];
let opname = arithassn_opnames[i];
let ty = 'int';
let tycap = 'Int';
io.println(fmt.template(arithassn_templ));
io.println();
}
# flt
for let i = 0; i < arithassn_ops.len(); ++i {
let op = arithassn_ops[i];
if op == '%=' { break; } # don't go after '/='
let opname = arithassn_opnames[i];
let ty = 'flt';
let tycap = 'Flt';
io.println(fmt.template(arithassn_templ));
io.println();
}
let log_ops = vec.new('&&', '||', '==', '<', '>', '<=', '>=', '!=');
let log_opnames = vec.new(.logand, .logor, .eq, .lt, .gt, .le, .ge, .ne);
# int
for let i = 0; i < log_ops.len(); ++i {
let op = log_ops[i];
let opname = log_opnames[i];
let ty = 'int';
let tycap = 'Int';
io.println(fmt.template(arith_templ));
io.println();
}
# flt
for let i = 0; i < log_ops.len(); ++i {
let op = log_ops[i];
let opname = log_opnames[i];
let ty = 'flt';
let tycap = 'Flt';
io.println(fmt.template(arith_templ));
io.println();
}
let preunary_templ = `INTRINSIC({opname}_{ty})
\\{
auto res = {op}Get{tycap}(args[0]);
stmt->setVal({tycap}Val::create(c, CDTRUE, res));
return true;
}
`;
let preunary_ops = vec.new('+', '-', '!', '~', '++', '--');
let preunary_opnames = vec.new(.uadd, .usub, .lognot, .bnot, .incx, .decx);
# int
for let i = 0; i < preunary_ops.len(); ++i {
let op = preunary_ops[i];
let opname = preunary_opnames[i];
let ty = 'int';
let tycap = 'Int';
io.println(fmt.template(preunary_templ));
io.println();
}
# flt
for let i = 0; i < preunary_ops.len(); ++i {
let op = preunary_ops[i];
if op == '~' { break; } # don't go after '!'
let opname = preunary_opnames[i];
let ty = 'flt';
let tycap = 'Flt';
io.println(fmt.template(preunary_templ));
io.println();
}
let postunary_templ = `INTRINSIC({opname}_{ty})
\\{
auto res = Get{tycap}(args[0]){op};
stmt->setVal({tycap}Val::create(c, CDTRUE, res));
return true;
}
`;
let postunary_ops = vec.new('++', '--');
let postunary_opnames = vec.new(.xinc, .xdec);
# int
for let i = 0; i < postunary_ops.len(); ++i {
let op = postunary_ops[i];
let opname = postunary_opnames[i];
let ty = 'int';
let tycap = 'Int';
io.println(fmt.template(postunary_templ));
io.println();
}