-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimdecl.fer
207 lines (194 loc) · 6.02 KB
/
primdecl.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
let io = import('std/io');
let fmt = import('std/fmt');
let sys = import('std/sys');
let vec = import('std/vec');
let getOperCStr = fn(op) {
if op == 'assn' { return "__assn__"; }
if op == 'add' { return "__add__"; }
if op == 'sub' { return "__sub__"; }
if op == 'mul' { return "__mul__"; }
if op == 'div' { return "__div__"; }
if op == 'mod' { return "__mod__"; }
if op == 'addassn' { return "__add_assn__"; }
if op == 'subassn' { return "__sub_assn__"; }
if op == 'mulassn' { return "__mul_assn__"; }
if op == 'divassn' { return "__div_assn__"; }
if op == 'modassn' { return "__mod_assn__"; }
if op == 'xinc' { return "__xinc__"; }
if op == 'xdec' { return "__xdec__"; }
if op == 'incx' { return "__incx__"; }
if op == 'decx' { return "__decx__"; }
if op == 'uadd' { return "__uadd__"; }
if op == 'usub' { return "__usub__"; }
if op == 'logand' { return "__logand__"; }
if op == 'logor' { return "__logor__"; }
if op == 'lognot' { return "__lognot__"; }
if op == 'eq' { return "__eq__"; }
if op == 'lt' { return "__lt__"; }
if op == 'gt' { return "__gt__"; }
if op == 'le' { return "__le__"; }
if op == 'ge' { return "__ge__"; }
if op == 'ne' { return "__ne__"; }
if op == 'band' { return "__band__"; }
if op == 'bor' { return "__bor__"; }
if op == 'bnot' { return "__bnot__"; }
if op == 'bxor' { return "__bxor__"; }
if op == 'bandassn' { return "__band_assn__"; }
if op == 'borassn' { return "__bor_assn__"; }
if op == 'bnotassn' { return "__bnot_assn__"; }
if op == 'bxorassn' { return "__bxor_assn__"; }
if op == 'lshift' { return "__lshift__"; }
if op == 'rshift' { return "__rshift__"; }
if op == 'lshiftassn' { return "__lshift_assn__"; }
if op == 'rshiftassn' { return "__rshift_assn__"; }
if op == 'subs' { return "__subs__"; }
};
let twoparamint_templ = `
g = TypeTy::get(c);
ADD{tycap}FN("{opname}", createFnVal(c, \\{g, i0}, g, intrinsic_{opn}_{ty}, IVALUE));`;
let twoparamflt_templ = `
g = TypeTy::get(c);
ADD{tycap}FN("{opname}", createFnVal(c, \\{g, f0}, g, intrinsic_{opn}_{ty}, IVALUE));`;
let oneparam_templ = `
g = TypeTy::get(c);
ADD{tycap}FN("{opname}", createFnVal(c, \\{g}, g, intrinsic_{opn}_{ty}, IVALUE));`;
let twoparamintbool_templ = `
g = TypeTy::get(c);
ADD{tycap}FN("{opname}", createFnVal(c, \\{g, i0}, i1, intrinsic_{opn}_{ty}, IVALUE));`;
let twoparamfltbool_templ = `
g = TypeTy::get(c);
ADD{tycap}FN("{opname}", createFnVal(c, \\{g, f0}, i1, intrinsic_{opn}_{ty}, IVALUE));`;
let oneparambool_templ = `
g = TypeTy::get(c);
ADD{tycap}FN("{opname}", createFnVal(c, \\{g}, i1, intrinsic_{opn}_{ty}, IVALUE));`;
# int
{
let op = '=';
let opn = 'assn';
let opname = getOperCStr(opn);
let ty = 'int';
let tycap = 'INT';
io.println(fmt.template(twoparamint_templ));
io.println();
}
# flt
{
let op = '=';
let opn = 'assn';
let opname = getOperCStr(opn);
let ty = 'flt';
let tycap = 'FLT';
io.println(fmt.template(twoparamflt_templ));
io.println();
}
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 opn = arith_opnames[i];
let opname = getOperCStr(opn);
let ty = 'int';
let tycap = 'INT';
io.println(fmt.template(twoparamint_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 opn = arith_opnames[i];
let opname = getOperCStr(opn);
let ty = 'flt';
let tycap = 'FLT';
io.println(fmt.template(twoparamflt_templ));
io.println();
}
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 opn = arithassn_opnames[i];
let opname = getOperCStr(opn);
let ty = 'int';
let tycap = 'INT';
io.println(fmt.template(twoparamint_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 opn = arithassn_opnames[i];
let opname = getOperCStr(opn);
let ty = 'flt';
let tycap = 'FLT';
io.println(fmt.template(twoparamflt_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 opn = log_opnames[i];
let opname = getOperCStr(opn);
let ty = 'int';
let tycap = 'INT';
io.println(fmt.template(twoparamintbool_templ));
io.println();
}
# flt
for let i = 0; i < log_ops.len(); ++i {
let op = log_ops[i];
let opn = log_opnames[i];
let opname = getOperCStr(opn);
let ty = 'flt';
let tycap = 'FLT';
io.println(fmt.template(twoparamfltbool_templ));
io.println();
}
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 opn = preunary_opnames[i];
let opname = getOperCStr(opn);
let ty = 'int';
let tycap = 'INT';
if op == '!' {
io.println(fmt.template(oneparambool_templ));
} else {
io.println(fmt.template(oneparam_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 opn = preunary_opnames[i];
let opname = getOperCStr(opn);
let ty = 'flt';
let tycap = 'FLT';
if op == '!' {
io.println(fmt.template(oneparambool_templ));
} else {
io.println(fmt.template(oneparam_templ));
}
io.println();
}
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 opn = postunary_opnames[i];
let opname = getOperCStr(opn);
let ty = 'int';
let tycap = 'INT';
io.println(fmt.template(oneparam_templ));
io.println();
}