mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
36 lines
514 B
Perl
36 lines
514 B
Perl
|
|
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() |