-
Notifications
You must be signed in to change notification settings - Fork 205
/
cconv.t
488 lines (372 loc) · 7.71 KB
/
cconv.t
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
local test = require("test")
terra f1(a : int)
return a
end
terra c1()
return 1 + f1(4),f1(4)
end
terra f2(a : int, b : float)
return a + b
end
terra c2()
return f2(3,4) + 1, f2(3,4)
end
terra f3()
return 3,4
end
terra c3()
var r = f3()
return f3()._0 + 1,unpackstruct(r)
end
terra f4() : {float,float}
return 3.25,4.25
end
terra c4()
var r = f4()
return f4()._0 + 1, unpackstruct(r)
end
terra f5(a : int) : {uint8,uint8,uint8,uint8}
return 0,1,a,3
end
terra c5()
var r = f5(8)
return f5(8)._0 + 1, unpackstruct(r)
end
terra f6() : {double, double, int}
return 3.25, 4.25, 3
end
terra c6()
var r = f6()
return f6()._0 + 1, unpackstruct(r)
end
test.meq({4.25, 3.25,4.25,3},c6())
terra f7(a : int) : {double, double, int}
return 3.25, 4.25, a
end
terra c7()
var r = f7(4)
return f7(4)._0 + 1, unpackstruct(r)
end
test.meq({4.25,3.25,4.25,4},c7())
terra f8() : {double, double}
return 3.25, 4.25
end
terra c8()
var r= f8()
return f8()._0 + 1, unpackstruct(r)
end
test.meq({4.25,3.25,4.25},c8())
struct S1 {
a : int;
b : int;
}
terra f9(a : S1)
return a.a+1,a.b+2
end
terra c9()
var a = S1 { 4, 5}
var r = f9(a)
return f9(a)._0 + 1, unpackstruct(r)
end
test.meq({6,5,7},c9())
struct S2 {
a : int;
b : double;
c : double;
}
terra f10(a : S2)
return a.a, a.b, a.c
end
terra c10()
var s2 = S2 { 4,5,6 }
var r = f10(s2)
return f10(s2)._0 + 1, unpackstruct(r)
end
test.meq({5,4,5,6},c10())
C = terralib.includec("stdio.h")
terra f11(a : int)
C.printf("f11 %d\n",a)
end
terra c11()
f11(7)
end
c11()
struct S3 {
a : vector(float,2);
b : double;
}
struct S4 {
b : double;
a : vector(float,2);
}
struct S5 {
a : vector(uint8,4);
b : int;
}
terra f12a(a : S3)
return a.a[0] + a.a[1], a.b
end
terra c12a()
var a = S3 { vector(2.25f, 3.25f), 4 }
var r = f12a(a)
return f12a(a)._0 + 1, unpackstruct(r)
end
test.meq({6.5,5.5,4},c12a())
terra f12b(a : S4)
return a.a[0] + a.a[1], a.b
end
terra c12b()
var a = S4 { 4, vector(2.25f, 3.25f) }
var r = f12b(a)
return f12b(a)._0 + 1, unpackstruct(r)
end
test.meq({6.5,5.5,4},c12b())
terra f12()
var a = S3 { vector(8.f,2.f), 3.0 }
var b = S4 { 3.0, vector(8.f,2.f) }
var c,d = f12a(a)
var e,f = f12b(b)
return c,d,e,f
end
terra f13a(a : S5)
return a.a[0] + a.a[1] + a.a[2] + a.a[3], a.b
end
terra f13()
var a = S5 { vectorof(int8, 1,2,3,4), 5 }
return f13a(a)
end
struct S6 {
a : float;
aa : float;
b : float
}
struct S7a {
a : int;
b : int;
}
struct S7 {
a : int;
b : S7a;
c : int;
}
terra f14(a : S6)
return a.a,a.aa,a.b
end
terra c14()
var a = S6 { 4,2,3}
var r = f14(a)
return f14(a)._0 + 1, unpackstruct(r)
end
test.meq({5,4,2,3},c14())
terra f15(a : S7)
return a.a, a.b.a, a.b.b, a.c
end
terra c15()
var a = S7 {1, S7a { 2,3 }, 4}
var r = f15(a)
return f15(a)._0 + 1, unpackstruct(r)
end
test.meq({2,1,2,3,4}, c15())
struct S8 {
a : uint8[7];
}
terra f16(a : S8)
return a.a[0],a.a[6]
end
terra c16()
var a = S8 { arrayof(uint8, 1,2,3,4,5,6,7) }
var r = f16(a)
return f16(a)._0 + 1, unpackstruct(r)
end
test.meq({2,1,7},c16())
struct S9 {
a : uint8[9];
}
terra f17(a : S9)
return a.a[0],a.a[8]
end
terra c17()
var a = S9 { arrayof(uint8, 1,2,3,4,5,6,7,8,9) }
var r = f17(a)
return f17(a)._0 + 1, unpackstruct(r)
end
test.meq({2,1,9},c17())
struct S10 {
a : double;
b : int64
}
terra f18a(a0 : int, a1 : int, a2 : int, a3 : int, a4: int, a5 : int, a : S10)
return a.a, a.b
end
terra c18a()
var r = f18a(1,2,3,4,5,6,S10{7,8})
return f18a(1,2,3,4,5,6,S10{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8},c18a())
terra f18b(a0 : int, a1 : int, a2 : int, a3 : int, a4: int, a : S10)
return a.a, a.b
end
terra c18b()
var r = f18b(1,2,3,4,5,S10{7,8})
return f18b(1,2,3,4,5,S10{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8},c18b())
terra f18c(a0 : int, a1 : int, a2 : int, a3 : int, a4: int, a : S10)
return a.a, a.b, a0, a1, a2
end
terra c18c()
var r = f18c(1,2,3,4,5,S10 {7,8})
return f18c(1,2,3,4,5,S10{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8,1,2,3},c18c())
struct S11 {
a : float;
b : int;
}
terra f18d(a0 : int, a1 : int, a2 : int, a3 : int, a4: int, a5 : int, a : S11)
return a.a, a.b
end
terra c18d()
var r = f18d(1,2,3,4,5,6,S11{7,8})
return f18d(1,2,3,4,5,6,S11{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8},c18d())
terra f18e(a0 : int, a1 : int, a2 : int, a3 : int, a4: int, a : S11)
return a.a, a.b
end
terra c18e()
var r = f18e(1,2,3,4,5,S11{7,8})
return f18e(1,2,3,4,5,S11{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8},c18e())
terra f18f(a0 : int, a1 : int, a2 : int, a3 : int, a4: int, a : S11)
return a.a, a.b, a0, a1, a2
end
terra c18f()
var r = f18f(1,2,3,4,5,S11{7,8})
return f18f(1,2,3,4,5,S11{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8,1,2,3},c18f())
terra f18g(a0 : float, a1 : float, a2 : float, a3 : float, a4: float, a5 : float, a6 : float, a7 : float, a : S10)
return a.a, a.b
end
terra c18g()
var r = f18g(1,2,3,4,5,6,9,10,S10{7,8})
return f18g(1,2,3,4,5,6,9,10,S10{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8},c18g())
terra f18h(a0 : float, a1 : float, a2 : float, a3 : float, a4: float, a5 : float, a6 : float, a : S10)
return a.a, a.b
end
terra c18h()
var r = f18h(1,2,3,4,5,6,9,S10{7,8})
return f18h(1,2,3,4,5,6,9,S10{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8},c18h())
terra f18i(a0 : float, a1 : float, a2 : float, a3 : float, a4: float, a5 : float, a6 : float, a : S10)
return a.a, a.b, a0, a1, a2
end
terra c18i()
var r = f18i(1,2,3,4,5,6,9,S10{7,8})
return f18i(1,2,3,4,5,6,9,S10{7,8})._0 + 1, unpackstruct(r)
end
test.meq({8,7,8,1,2,3},c18i())
struct S12 {
a : float;
b : int;
}
terra f19(a : S12)
return a.a, a.b
end
terra c19()
var a = S12 { 3,5 }
var r = f19(a)
return f19(a)._0 + 1, unpackstruct(r)
end
test.meq({4,3,5},c19())
terra f20(a : S10, b : int)
return a.a,a.b,b
end
terra c20()
var r = f20(S10{1,2},3)
return f20(S10{1,2},3)._0 + 1, unpackstruct(r)
end
test.meq({2,1,2,3},c20())
terra f21()
return
end
f21()
terra f22()
return S12 { 3, 4}
end
terra c22()
return f22().a, f22()
end
local s22_0, s22_1 = terralib.unpackstruct(c22())
test.eq(s22_0,3)
test.eq(s22_1.a,3)
test.eq(s22_1.b,4)
terra f23()
return S10 { 1, 2}
end
terra c23()
return f23().a, f23()
end
local s23_0, s23_1 = terralib.unpackstruct(c23())
test.eq(s23_0,1)
test.eq(s23_1.a,1)
test.eq(s23_1.b,2)
terra f24()
return S2 { 1,2,3}
end
terra c24()
return f24().a, f24()
end
local s24_0, s24_1 = terralib.unpackstruct(c24())
test.eq(s24_0,1)
test.eq(s24_1.a,1)
test.eq(s24_1.b,2)
test.eq(s24_1.c,3)
local s22 = f22()
test.eq(s22.a,3)
test.eq(s22.b,4)
local s23 = f23()
test.eq(s23.a,1)
test.eq(s23.b,2)
local s24 = f24()
test.eq(s24.a,1)
test.eq(s24.b,2)
test.eq(s24.c,3)
test.meq({1,2,3},f20({1,2},3))
test.eq(f1(3),3)
test.eq(f2(4,5),9)
test.meq({3,4},f3())
test.meq({3.25,4.25},f4())
test.meq({0,1,2,3},f5(2))
test.meq({3.25,4.25,3},f6())
test.meq({3.25,4.25,4},f7(4))
test.meq({3.25,4.25},f8())
test.meq({3,5},f9({2,3}))
test.meq({1,2.5,3.5},f10({1,2.5,3.5}))
f11(3)
test.meq({10,3,10,3},f12())
test.meq({10,5},f13())
test.meq({4,5,6},f14({4,5,6}))
test.meq({1,2,3,4},f15({1,{2,3},4}))
test.meq({1,7},f16({{1,2,3,4,5,6,7}}))
test.meq({1,9},f17({{1,2,3,4,5,6,7,8,9}}))
test.meq({7,8},f18a(1,2,3,4,5,6,{7,8}))
test.meq({7,8},f18b(1,2,3,4,5,{7,8}))
test.meq({7,8,1,2,3},f18c(1,2,3,4,5,{7,8}))
test.meq({7,8},f18d(1,2,3,4,5,6,{7,8}))
test.meq({7,8},f18e(1,2,3,4,5,{7,8}))
test.meq({7,8,1,2,3},f18f(1,2,3,4,5,{7,8}))
test.meq({9,10},f18g(1,2,3,4,5,6,7,8,{9,10}))
test.meq({9,10},f18h(1,2,3,4,5,6,7,{9,10}))
test.meq({9,10,1,2,3},f18i(1,2,3,4,5,6,7,{9,10}))
test.meq({4,5}, f19({4,5}))
test.meq({5,4},c1())
test.meq({8,7},c2())
test.meq({4,3,4},c3())
test.meq({4.25,3.25,4.25},c4())
test.meq({1,0,1,8,3},c5())