mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-10 19:35:32 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
36
samples/Terra/class3.t
Normal file
36
samples/Terra/class3.t
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
C = terralib.includec("stdio.h")
|
||||
|
||||
local Class = require("lib/javalike")
|
||||
|
||||
|
||||
local Prints = Class.interface { print = {} -> {} }
|
||||
|
||||
struct Leaf {
|
||||
data : int
|
||||
}
|
||||
Class.implements(Leaf,Prints)
|
||||
|
||||
terra Leaf:print() : {}
|
||||
C.printf("%d\n",self.data)
|
||||
end
|
||||
|
||||
|
||||
struct Node {
|
||||
next : &Leaf
|
||||
}
|
||||
Class.extends(Node,Leaf)
|
||||
|
||||
terra Node:print() : {}
|
||||
C.printf("%d\n",self.data)
|
||||
self.next:print()
|
||||
end
|
||||
|
||||
terra test()
|
||||
var a,b = Leaf.alloc(), Node.alloc()
|
||||
a.data,b.data,b.next = 1,2,a
|
||||
var p : &Prints = b
|
||||
p:print()
|
||||
end
|
||||
|
||||
test()
|
||||
Reference in New Issue
Block a user