projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ae08a1e
)
update commentry for foreign import "wrapper" handling
author
Simon Marlow
<simonmar@microsoft.com>
Tue, 18 Apr 2006 14:37:14 +0000
(14:37 +0000)
committer
Simon Marlow
<simonmar@microsoft.com>
Tue, 18 Apr 2006 14:37:14 +0000
(14:37 +0000)
compiler/deSugar/DsForeign.lhs
patch
|
blob
|
history
diff --git
a/compiler/deSugar/DsForeign.lhs
b/compiler/deSugar/DsForeign.lhs
index
fcac3a6
..
725681e
100644
(file)
--- a/
compiler/deSugar/DsForeign.lhs
+++ b/
compiler/deSugar/DsForeign.lhs
@@
-314,26
+314,34
@@
dsFExport fn_id ty ext_name cconv isDyn
fe_arg_tys res_ty is_IO_res_ty cconv
\end{code}
fe_arg_tys res_ty is_IO_res_ty cconv
\end{code}
-@foreign export dynamic@ lets you dress up Haskell IO actions
-of some fixed type behind an externally callable interface (i.e.,
-as a C function pointer). Useful for callbacks and stuff.
+@foreign import "wrapper"@ (previously "foreign export dynamic") lets
+you dress up Haskell IO actions of some fixed type behind an
+externally callable interface (i.e., as a C function pointer). Useful
+for callbacks and stuff.
\begin{verbatim}
\begin{verbatim}
-foreign export dynamic f :: (Addr -> Int -> IO Int) -> IO Addr
+type Fun = Bool -> Int -> IO Int
+foreign import "wrapper" f :: Fun -> IO (FunPtr Fun)
-- Haskell-visible constructor, which is generated from the above:
-- SUP: No check for NULL from createAdjustor anymore???
-- Haskell-visible constructor, which is generated from the above:
-- SUP: No check for NULL from createAdjustor anymore???
-f :: (Addr -> Int -> IO Int) -> IO Addr
+f :: Fun -> IO (FunPtr Fun)
f cback =
bindIO (newStablePtr cback)
(\StablePtr sp# -> IO (\s1# ->
case _ccall_ createAdjustor cconv sp# ``f_helper'' s1# of
(# s2#, a# #) -> (# s2#, A# a# #)))
f cback =
bindIO (newStablePtr cback)
(\StablePtr sp# -> IO (\s1# ->
case _ccall_ createAdjustor cconv sp# ``f_helper'' s1# of
(# s2#, a# #) -> (# s2#, A# a# #)))
-foreign export "f_helper" f_helper :: StablePtr (Addr -> Int -> IO Int) -> Addr -> Int -> IO Int
--- `special' foreign export that invokes the closure pointed to by the
--- first argument.
+foreign import "&f_helper" f_helper :: FunPtr (StablePtr Fun -> Fun)
+
+-- and the helper in C:
+
+f_helper(StablePtr s, HsBool b, HsInt i)
+{
+ rts_evalIO(rts_apply(rts_apply(deRefStablePtr(s),
+ rts_mkBool(b)), rts_mkInt(i)));
+}
\end{verbatim}
\begin{code}
\end{verbatim}
\begin{code}