-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.idr
52 lines (34 loc) · 1.23 KB
/
test.idr
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
import Data.Vect
import System.FFI
PointNum : Type
PointNum = Struct "pointnum" [("ptr", Ptr Int), ("num", Int)]
%foreign "C:getPointer, libsmall"
getPointer : Ptr Int
%foreign "C:freePointer, libsmall"
freePointer : (1 mem : Ptr Int) -> ()
%foreign "C:readNumber, libsmall"
readNumber : (1 mem : Ptr Int) -> Int
%foreign "C:writePointer, libsmall"
writePointer : (1 mem : Ptr Int) -> Int -> Ptr Int
%foreign "C:testFunc, libsmall"
testFunc : (Int -> Int) -> Int
%foreign "C:dumbread, libsmall"
dumbread : Int
%foreign "C:doDumb, libsmall"
doDumb : (1 mem : Ptr Int) -> Ptr Int
ab : ((1 mem : Ptr Int) -> IO ()) -> IO ()
ab f = f getPointer
write : Int -> ((1 mem : Ptr Int) -> IO ()) -> (1 mem : Ptr Int) -> IO ()
write int f ptr = let x = writePointer ptr int in f x
read : ((1 mem : Ptr Int) -> Int -> IO ()) -> (1 mem : Ptr Int) -> IO ()
read f ptr = let ptr2 = doDumb ptr in f ptr2 dumbread
freeProper : (1 mem : Ptr Int) -> IO ()
freeProper mem = case freePointer mem of
() => print ""
finalPart : (1 mem : Ptr Int) -> Int -> IO ()
finalPart ptr int = case freePointer ptr of
() => print int
z : (1 mem : Ptr Int) -> IO ()
z = (write 5 (write 10 (read (finalPart))))
main : IO ()
main = ab z