-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport.t
57 lines (45 loc) · 1.14 KB
/
export.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
require("export_decl")
local io = terralib.includec("stdio.h")
local lib = terralib.includec("stdlib.h")
terra addtwo(x: int, y: int): int
return x + y
end
local function matrix(T)
return struct{
a: T
}
end
local function matrix_impl(T)
local matrixT = matrix(T)
terra matrixT:setone()
io.printf("Calling from type %s with value %g\n", [tostring(T)], self.a)
end
local terra new(a: T)
var ret = [&matrixT](lib.malloc(sizeof(matrixT)))
ret.a = a
return ret
end
local terra del(m: &matrixT)
lib.free(m)
end
local self = {type = matrixT, new = new, del = del}
return self
end
mat_float = matrix_impl(float)
mat_double = matrix_impl(double)
local export = {
addtwo = addtwo,
-- float
new_float = mat_float.new,
del_float = mat_float.del,
setone_float = mat_float.type.methods["setone"],
-- double
new_double = mat_double.new,
del_double = mat_double.del,
setone_double = mat_double.type.methods["setone"]
}
terralib.saveobj("export.o", "object", export)