Idris2/tests/chez/chez022/usealloc.idr
Edwin Brady ca28dab1d7 Add finalisers for Racket back end
Like Chez, we also need an explicit call to the garbage collector at the
end to ensure that all the finalisers get run on exit.
2020-06-08 22:13:24 +01:00

33 lines
843 B
Idris

%foreign "C:mkThing, libmkalloc"
prim__mkThing : PrimIO AnyPtr
%foreign "C:getStr, libmkalloc"
prim__getStr : GCAnyPtr -> PrimIO String
%foreign "C:freeThing, libmkalloc"
prim__freeThing : AnyPtr -> PrimIO ()
mkThing : IO AnyPtr
mkThing = primIO prim__mkThing
getThingStr : GCAnyPtr -> IO String
getThingStr t = primIO (prim__getStr t)
freeThing : AnyPtr -> IO ()
freeThing t = primIO (prim__freeThing t)
doThings : IO ()
doThings
= do xp <- mkThing
yp <- mkThing
x <- onCollectAny xp (\p => do putStrLn "Free X"
freeThing p)
y <- onCollectAny yp (\p => do putStrLn "Free Y"
freeThing p)
putStrLn !(getThingStr x)
putStrLn !(getThingStr y)
main : IO ()
main = do doThings
putStrLn "Done"