2020-06-30 12:51:09 +03:00
|
|
|
import System.FFI
|
|
|
|
|
|
|
|
libsmall : String -> String
|
2020-07-24 15:21:48 +03:00
|
|
|
libsmall fn = "C:" ++ fn ++ ",libsmallc"
|
2020-06-30 12:51:09 +03:00
|
|
|
|
|
|
|
Point : Type
|
|
|
|
Point = Struct "point" [("x", Int), ("y", Int)]
|
|
|
|
|
|
|
|
%foreign (libsmall "mkPoint")
|
|
|
|
mkPoint : Int -> Int -> Point
|
|
|
|
|
|
|
|
%foreign (libsmall "freePoint")
|
|
|
|
prim_freePoint : Point -> PrimIO ()
|
|
|
|
|
|
|
|
freePoint : Point -> IO ()
|
|
|
|
freePoint p = primIO $ prim_freePoint p
|
|
|
|
|
|
|
|
showPoint : Point -> String
|
|
|
|
showPoint pt
|
|
|
|
= let x : Int = getField pt "x"
|
|
|
|
y : Int = getField pt "y" in
|
|
|
|
show (x, y)
|
|
|
|
|
|
|
|
main : IO ()
|
|
|
|
main
|
|
|
|
= do let pt = mkPoint 20 30
|
|
|
|
setField pt "x" (the Int 40)
|
|
|
|
putStrLn $ showPoint pt
|
|
|
|
freePoint pt
|