mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-11 11:55:45 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
32
samples/Terra/cnamespaces.t
Normal file
32
samples/Terra/cnamespaces.t
Normal file
@@ -0,0 +1,32 @@
|
||||
C,T = terralib.includecstring [[
|
||||
|
||||
struct Foo {
|
||||
int a;
|
||||
};
|
||||
typedef int Foo;
|
||||
typedef struct Foo * Bar;
|
||||
typedef Foo * Bar2;
|
||||
Bar bar(struct Foo * a, Bar2 b) { return (Bar)0; }
|
||||
]]
|
||||
|
||||
terra what()
|
||||
var f = T.Foo { 3 }
|
||||
var a : C.Bar = &f
|
||||
return a.a
|
||||
end
|
||||
|
||||
assert(3 == what())
|
||||
|
||||
C,T = terralib.includecstring [[
|
||||
typedef struct { int a; } Foo;
|
||||
typedef Foo * FooPtr;
|
||||
int returna(FooPtr a) { return a->a; }
|
||||
]]
|
||||
|
||||
terra what2()
|
||||
var a : C.Foo = C.Foo { 3 }
|
||||
var ap : C.FooPtr = &a
|
||||
return C.returna(ap)
|
||||
end
|
||||
|
||||
assert(3 == what2())
|
||||
Reference in New Issue
Block a user