Update examples

This commit is contained in:
Don Stewart
2005-09-03 04:45:14 +00:00
parent 5321754614
commit dff0363224
421 changed files with 19 additions and 9 deletions

View File

@ -0,0 +1,4 @@
TEST= dynload/should_fail_3
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,19 @@
--
-- the plugin doesn't even make the resource_dyn a Dynamic.
-- let's hope that makeWith strips out the invalid declarations
--
{-# OPTIONS -fglasgow-exts #-}
module Plugin where
import API
import AltData.Typeable
import GHC.Base
v :: Int
v = 0xdeadbeef
resource_dyn = (typeOf plugin, unsafeCoerce v)

View File

@ -0,0 +1,12 @@
{-# OPTIONS -fglasgow-exts #-}
module Plugin ( resource_dyn ) where
import API
import AltData.Dynamic
resource = plugin
resource_dyn :: Dynamic
resource_dyn = toDyn resource

View File

@ -0,0 +1,22 @@
{-# OPTIONS -cpp -fglasgow-exts #-}
module API where
import AltData.Typeable
import GHC.Base
data Interface = Interface {
function :: String
}
instance Typeable Interface where
#if __GLASGOW_HASKELL__ >= 603
typeOf _ = mkTyConApp (mkTyCon "API.Interface") []
#else
typeOf _ = mkAppTy (mkTyCon "API.Interface") []
#endif
plugin :: Interface
plugin = Interface { function = "goodbye" }
unsafeCoerce = unsafeCoerce#

View File

@ -0,0 +1,18 @@
import System.Plugins
import API
conf = "../Plugin.in"
stub = "../Plugin.stub"
main = do
status <- makeWith conf stub ["-i../api", "-i../../../../src/altdata"]
o <- case status of
MakeFailure e -> mapM_ putStrLn e >> error "failed"
MakeSuccess _ o -> return o
m_v <- dynload o ["../api"] [] "resource_dyn"
case m_v of
LoadFailure _ -> error "didn't compile"
LoadSuccess _ v -> do putStrLn $ (function v)
makeCleaner o

View File

@ -0,0 +1,9 @@
../Plugin.in:18:
Couldn't match `Dynamic' against `(t, t1)'
Expected type: Dynamic
Inferred type: (t, t1)
In the definition of `resource_dyn':
resource_dyn = (typeOf plugin, unsafeCoerce v)
Fail: failed

View File

@ -0,0 +1,8 @@
../Plugin.in:18:15:
Couldn't match `Dynamic' against `(a, b)'
Expected type: Dynamic
Inferred type: (a, b)
In the definition of `resource_dyn':
resource_dyn = (typeOf plugin, unsafeCoerce v)
a.out: failed

View File

@ -0,0 +1,8 @@
../Plugin.in:18:15:
Couldn't match `Dynamic' against `(a, b)'
Expected type: Dynamic
Inferred type: (a, b)
In the definition of `resource_dyn':
resource_dyn = (typeOf plugin, unsafeCoerce v)
a.out: failed