samples: add Terra samples

source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
Bayu Aldi Yansyah
2016-01-28 11:22:27 +07:00
parent e32a837fb2
commit 9b8b39f444
370 changed files with 11921 additions and 0 deletions

35
samples/Terra/cunion2.t Normal file
View File

@@ -0,0 +1,35 @@
local C = terralib.includecstring [[
union testunion {
int idata;
float fdata;
};
void setUnionI(union testunion * u){
u->idata = 3;
}
void setUnionF(union testunion * u){
u->fdata = 4.f;
}
]]
terra foo() : int
var u : C.testunion
C.setUnionI(&u)
var f = u.idata
C.setUnionF(&u)
var f2 = u.fdata
return f + f2
end
terra foo2()
var a : C.testunion
a.fdata = -3.0
a.idata = a.idata and not (1 << 31)
return a.fdata
end
local test = require("test")
test.eq(foo(),7)
test.eq(foo2(),3)