mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-11 03:45:31 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
35
samples/Terra/constant.t
Normal file
35
samples/Terra/constant.t
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
local foo = terralib.constant(terralib.new(int[4],{1,2,3,4}))
|
||||
|
||||
struct A {
|
||||
a : int;
|
||||
b : float
|
||||
}
|
||||
|
||||
local mystr = terralib.new(A,{3,4.5})
|
||||
local const = constant(mystr)
|
||||
|
||||
|
||||
terra bar()
|
||||
return foo[3] + mystr.a
|
||||
end
|
||||
|
||||
terra bar2()
|
||||
return foo[1] + mystr.b
|
||||
end
|
||||
|
||||
function wrapper(a)
|
||||
return a + 1
|
||||
end
|
||||
|
||||
local p1 = terralib.constant(int -> int, wrapper)
|
||||
|
||||
terra doit()
|
||||
return p1(3)
|
||||
end
|
||||
|
||||
local test = require("test")
|
||||
test.eq(bar(),7)
|
||||
test.eq(bar2(),6.5)
|
||||
test.eq(doit(),4)
|
||||
Reference in New Issue
Block a user