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

42
samples/Terra/method.t Normal file
View File

@@ -0,0 +1,42 @@
--the zero line
struct A { b : B } and
struct B {a : int, b : int}
B.methods.foo = terra(b : B)
return b.a
end
terra bar()
var b = B { 1,2 }
return b:foo()
end
B.methods.foo2 = terra(b : &B)
b.a = 6
end
terra bar2()
var b = B { 1,2 }
b:foo2()
return b.a
end
B.methods.foo3 = terra(b : B)
return b.a
end
terra bar3()
var b = B { 1,2 }
return (&b):foo3()
end
terra bar4()
var b = B { 1,2 }
(&b):foo2()
return b.a
end
test = require("test")
test.eq(bar(),1)
test.eq(bar2(),6)
test.eq(bar3(),1)
test.eq(bar4(),6)