2 | import Control.Monad.Either
3 | import JS.Inheritance
20 | interface ToFFI a ffiRepr | a where
21 | toFFI : a -> ffiRepr
24 | ToFFI AnyPtr AnyPtr where toFFI = id
27 | ToFFI Bits8 Bits8 where toFFI = id
30 | ToFFI Bits16 Bits16 where toFFI = id
33 | ToFFI Bits32 Bits32 where toFFI = id
36 | ToFFI Bits64 Bits64 where toFFI = id
39 | ToFFI Int8 Int8 where toFFI = id
42 | ToFFI Int16 Int16 where toFFI = id
45 | ToFFI Int32 Int32 where toFFI = id
48 | ToFFI Int64 Int64 where toFFI = id
51 | ToFFI Int Int where toFFI = id
54 | ToFFI Char Char where toFFI = id
57 | ToFFI Integer Integer where toFFI = id
60 | ToFFI Double Double where toFFI = id
63 | ToFFI String String where toFFI = id
66 | ToFFI WindowProxy WindowProxy where toFFI = id
71 | interface FromFFI a ffiRepr | a where
72 | fromFFI : ffiRepr -> Maybe a
75 | FromFFI AnyPtr AnyPtr where fromFFI = Just
78 | FromFFI Bits8 Bits8 where fromFFI = Just
81 | FromFFI Bits16 Bits16 where fromFFI = Just
84 | FromFFI Bits32 Bits32 where fromFFI = Just
87 | FromFFI Bits64 Bits64 where fromFFI = Just
90 | FromFFI Int8 Int8 where fromFFI = Just
93 | FromFFI Int16 Int16 where fromFFI = Just
96 | FromFFI Int32 Int32 where fromFFI = Just
99 | FromFFI Int64 Int64 where fromFFI = Just
102 | FromFFI Char Char where fromFFI = Just
105 | FromFFI Int Int where fromFFI = Just
108 | FromFFI Integer Integer where fromFFI = Just
111 | FromFFI Double Double where fromFFI = Just
114 | FromFFI String String where fromFFI = Just
117 | FromFFI WindowProxy WindowProxy where fromFFI = Just
120 | tryFromFFI : FromFFI a ffiRepr => (fun : Lazy String) -> ffiRepr -> JSIO a
121 | tryFromFFI fun ptr = case fromFFI ptr of
122 | Nothing => throwError $
CastErr fun ptr
126 | tryJS : FromFFI a ffiRepr => (fun : Lazy String) -> PrimIO ffiRepr -> JSIO a
127 | tryJS fun prim = primJS prim >>= tryFromFFI fun