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,5 @@
TEST=pdynload/badint
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,4 @@
module Plugin where
resource :: Num t => t
resource = 0xBAD

View File

@ -0,0 +1,9 @@
module API where
data Interface = Interface {
transform :: String -> String
}
rsrc :: Interface
rsrc = Interface { transform = id }

View File

@ -0,0 +1,18 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e-> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn $ (transform a) "foo"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
wrong types

View File

@ -0,0 +1,34 @@
module Load where
import API
import System.Plugins
testload = do
s <- make "../Plugin1.hs" ["-i../api"]
o1 <- case s of
MakeSuccess _ o -> return o
MakeFailure e -> mapM_ putStrLn e >> fail "o1"
s <- make "../Sub/Plugin2.hs" ["-i../api"]
o2 <- case s of
MakeSuccess _ o -> return o
MakeFailure e -> mapM_ putStrLn e >> fail "o2"
fc <- pdynload o1 ["..","../api"] [] "API.PluginAPI" "action"
case fc of
LoadFailure msg -> mapM_ putStrLn msg
LoadSuccess modul proc -> do
let ac :: API.PluginAPI; ac = proc
let s = proc 42
print s
print o2
fc <- pdynload o2 ["..","../api"] [] "API.PluginAPI" "action"
case fc of
LoadFailure msg -> mapM_ putStrLn msg
LoadSuccess modul proc -> do
let ac :: API.PluginAPI; ac = proc
let s = proc 42
print s

View File

@ -0,0 +1,5 @@
TEST=pdynload/bayley1
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,6 @@
module Plugin1 where
import qualified API
action :: API.PluginAPI
action i = show i

View File

@ -0,0 +1,6 @@
module Sub.Plugin2 where
import qualified API
action :: API.PluginAPI
action i = show i

View File

@ -0,0 +1,6 @@
module API where
type PluginAPI = Int -> String
action :: PluginAPI
action i = show i

View File

@ -0,0 +1,4 @@
module Main where
import Load
main = testload

View File

@ -0,0 +1,4 @@
TEST= pdynload/null
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,5 @@
module Plugin where
import API
resource = D 1

View File

@ -0,0 +1,5 @@
module API where
data Num t => Interface t = D t

View File

@ -0,0 +1,19 @@
import System.Plugins
-- import System.Plugins.Utils
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e-> mapM_ putStrLn e
where f = do v <- load "../Plugin.o" ["../api"] [] "resource"
-- (i,_) <- exec "ghc" ["--numeric-version"]
-- mapM_ putStrLn i
putStrLn "done."

View File

@ -0,0 +1 @@
done.

View File

@ -0,0 +1,4 @@
TEST= pdynload/numclass
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,5 @@
module Plugin where
-- import API
resource = "error"

View File

@ -0,0 +1,5 @@
module API where
data Num t => Interface t = D t

View File

@ -0,0 +1,19 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeFailure _ -> putStrLn "make failed"
MakeSuccess _ _ -> do {
;v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface Integer" "resource"
;case v of
LoadSuccess _ a -> let D i = snd a in putStrLn $ show i
_ -> putStrLn "wrong types"
}

View File

@ -0,0 +1 @@
wrong types

View File

@ -0,0 +1,5 @@
TEST=pdynload/poly
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,9 @@
module Plugin where
import Data.Generics.Schemes
import API
resource = rsrc {
field = id listify
}

View File

@ -0,0 +1,12 @@
{-# OPTIONS -fglasgow-exts #-}
-- a really nasty type:
module API where
import Data.Generics
data Interface = Interface { field :: Typeable r => (r -> Bool) -> GenericQ [r] }
rsrc :: Interface
rsrc = Interface { field = listify }

View File

@ -0,0 +1,17 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn "loaded .. yay!"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
loaded .. yay!

View File

@ -0,0 +1,4 @@
TEST= pdynload/poly1
EXTRA_OBJS=Plugin.o
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,5 @@
module Plugin where
import API
resource = plugin { function = (+) }

View File

@ -0,0 +1,9 @@
module API where
data Interface = Interface {
function :: (Num a) => a -> a -> a
}
plugin :: Interface
plugin = Interface { function = error "no function defined" }

View File

@ -0,0 +1,18 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> let fn = function a in putStrLn $ show $ 1 `fn` 2
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
3

View File

@ -0,0 +1,4 @@
TEST= pdynload/should_fail0
EXTRA_OBJS=Plugin.o
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,9 @@
module Plugin where
import API
resource = 0xBAD :: Int
-- resource = tiny {
-- field = "hello strange world"
-- }

View File

@ -0,0 +1,13 @@
{-# OPTIONS -fglasgow-exts #-}
-- ^ needed to derive Typeable
module API where
import Data.Dynamic
data Interface = Interface { field :: String }
deriving (Show)
rsrc :: Interface
rsrc = Interface { field = "default value" }

View File

@ -0,0 +1,18 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where
f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn "loaded .. yay!"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
wrong types

View File

@ -0,0 +1,5 @@
# Missing class constraint... can't do that in Clean
TEST= pdynload/should_fail1
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,5 @@
module Plugin where
data I = I Int
resource = I 1

View File

@ -0,0 +1,8 @@
module API where
newtype Interface = I Int
rsrc :: Interface
rsrc = I 1

View File

@ -0,0 +1,17 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn "loaded .. yay!"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
wrong types

View File

@ -0,0 +1,4 @@
TEST= pdynload/small
EXTRA_OBJS=Plugin.o
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,5 @@
module Plugin where
import API
resource = plugin { function = "good" }

View File

@ -0,0 +1,9 @@
module API where
data Interface = Interface {
function :: String
}
plugin :: Interface
plugin = Interface { function = "goodbye" }

View File

@ -0,0 +1,18 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn "loaded .. yay!"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
loaded .. yay!

View File

@ -0,0 +1,5 @@
TEST=pdynload/spj1
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,17 @@
module Plugin where
-- user doesn't import the API
-- and provides a polymorphic value
-- import API
-- resource :: Interface
--
-- should pass type check, and dump core
--
-- resource :: Num a => a
-- import API
resource :: Num a => a
resource = 7

View File

@ -0,0 +1,9 @@
module API where
-- data Interface = Interface { field :: Int }
-- newtype Interface = Interface Int
type Interface = Int

View File

View File

@ -0,0 +1,17 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ (a :: Interface) -> print $ a -- will crash
LoadFailure es -> putStrLn $ show es

View File

View File

@ -0,0 +1,5 @@
TEST=pdynload/spj1
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,13 @@
module Plugin where
-- user doesn't import the API
-- and provides a polymorphic value
import API
resource :: Interface
--
-- should pass type check, and dump core
--
-- resource :: Num a => a
resource = 7

View File

@ -0,0 +1,6 @@
module API where
-- simple type
type Interface = Int

View File

@ -0,0 +1,17 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ (a :: Interface) -> putStrLn $ show a -- will crash
LoadFailure es -> putStrLn $ show es

View File

@ -0,0 +1 @@
7

View File

@ -0,0 +1,3 @@
TEST= pdynload/spj3
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,5 @@
module Plugin where
import API
resource = plugin { function = (+) :: Int -> Int -> Int }

View File

@ -0,0 +1,9 @@
module API where
data Interface = Interface {
function :: (Num a) => a -> a -> a
}
plugin :: Interface
plugin = Interface { function = error "no function defined" }

View File

@ -0,0 +1,18 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> let fn = function a in putStrLn $ show $ 1 `fn` 2
_ -> putStrLn "wrong types"

View File

@ -0,0 +1,8 @@
../Plugin.hs:5:
Cannot unify the type-signature variable `a' with the type `Int'
Expected type: a -> a -> a
Inferred type: Int -> Int -> Int
When checking the type signature of the expression:
(+) :: Int -> Int -> Int
In the `function' field of a record

View File

@ -0,0 +1,9 @@
../Plugin.hs:5:31:
Couldn't match the rigid variable `a' against `Int'
`a' is bound by the polymorphic type `forall a. (Num a) => a -> a -> a'
at ../Plugin.hs:5:11-56
Expected type: a -> a -> a
Inferred type: Int -> Int -> Int
In the expression: (+) :: Int -> Int -> Int
In the `function' field of a record

View File

@ -0,0 +1,9 @@
../Plugin.hs:5:31:
Couldn't match the rigid variable `a' against `Int'
`a' is bound by the polymorphic type `forall a. (Num a) => a -> a -> a'
at ../Plugin.hs:5:11-56
Expected type: a -> a -> a
Inferred type: Int -> Int -> Int
In the expression: (+) :: Int -> Int -> Int
In the `function' field of a record

View File

@ -0,0 +1,5 @@
TEST=pdynload/spj4
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,16 @@
module Plugin where
-- user doesn't import the API
-- and provides a polymorphic value
-- import API
-- resource :: Interface
--
-- should pass type check, and dump core
--
-- resource :: Num a => a
import API
resource = Interface { field = 7 :: Num a => a }

View File

@ -0,0 +1,5 @@
module API where
newtype Interface = Interface { field :: Int }

View File

@ -0,0 +1,17 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> error "there was a type error"
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ (a :: Interface) -> print $ field a -- will crash
LoadFailure es -> mapM_ putStrLn es

View File

@ -0,0 +1 @@
7

View File

@ -0,0 +1,5 @@
# Missing class constraint... can't do that in Clean
TEST= pdynload/typealias
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,3 @@
module Plugin where
resource = 1 :: Int

View File

@ -0,0 +1,8 @@
module API where
type Interface = Int
rsrc :: Interface
rsrc = 1

View File

@ -0,0 +1,19 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn "loaded .. yay!"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
loaded .. yay!

View File

@ -0,0 +1,4 @@
TEST= pdynload/univquant
EXTRA_OBJS=Plugin.o
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,8 @@
module Plugin where
import API
resource = plugin { function = my_id }
my_id :: forall a. a -> a
my_id x = x

View File

@ -0,0 +1,9 @@
module API where
data Interface = Interface {
function :: forall a. a -> a
}
plugin :: Interface
plugin = Interface { function = id }

View File

@ -0,0 +1,17 @@
import System.Plugins
import API
src = "../Plugin.hs"
wrap = "../Wrapper.hs"
apipath = "../api"
main = do status <- make src ["-i"++apipath]
case status of
MakeSuccess _ _ -> f
MakeFailure e -> mapM_ putStrLn e
where f = do v <- pdynload "../Plugin.o" ["../api"] [] "API.Interface" "resource"
case v of
LoadSuccess _ a -> putStrLn "loaded .. yay!"
_ -> putStrLn "wrong types"

View File

@ -0,0 +1 @@
loaded .. yay!