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,8 @@
TEST= hier/hier1
EXTRA_OBJS=Plugin.o
PRIOR_OBJS=Modules/Flags.o
EXTRAFLAGS=
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,15 @@
--
-- A simple module
--
module Modules.Flags where
data FlagRec = FlagRec {
f1 :: Int,
f2 :: Int
}
foo :: FlagRec -> Int
foo x = f1 x

View File

@ -0,0 +1,6 @@
all:
ghc -O -c Flags.hs
clean:
rm -f *.hi *.o

View File

@ -0,0 +1,14 @@
--
-- Plugin
--
module Plugin where
import API
import Modules.Flags as Flags
resource = plugin {
dbFunc = (\x -> Flags.f1 x)
}

View File

@ -0,0 +1,16 @@
--
-- API for plugin test
--
module API where
import Modules.Flags as Flags
data Interface = Interface {
dbFunc :: Flags.FlagRec -> Int
}
plugin :: Interface
plugin = Interface { dbFunc = (\x -> 1) }

View File

@ -0,0 +1,21 @@
--
-- Test multiple plugins
--
module Main where
import System.Plugins
import API
import Modules.Flags as Flags
rec = Flags.FlagRec { Flags.f1 = 4, Flags.f2 = 10 }
main = do
status <- load "../Plugin.o" ["../api",".."] [] "resource"
case status of
LoadFailure _ -> error "load failed"
LoadSuccess _ v -> do let func = dbFunc v
print (func rec)

View File

@ -0,0 +1 @@
4

View File

@ -0,0 +1,8 @@
--
-- A simple module
--
module A.B.C.Module where
symbol = "You found me"

View File

@ -0,0 +1,7 @@
all:
ghc -c B/C/Module.hs
clean:
rm -f B/C/*.hi B/C/*.o

View File

@ -0,0 +1,7 @@
TEST= hier/hier2
PRIOR_OBJS=A/B/C/Module.o
EXTRAFLAGS=
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,4 @@
module API where
-- just a dummy for the build system

View File

@ -0,0 +1,15 @@
--
-- Test if we can load a module with a hierarchical name from some weird
-- path. Tests our the module name handling in the .hi file parser.
--
module Main where
import System.Plugins
main = do
status <- load "../A/B/C/Module.o" [".."] [] "symbol"
case status of
LoadFailure ers -> mapM_ putStrLn ers
LoadSuccess _ v -> print (v :: String)

View File

@ -0,0 +1 @@
"You found me"

View File

@ -0,0 +1,25 @@
module Main where
import System.Plugins
main = do
makeAll "One.hs" []
load2 "Two.o"
load2 "./Two.o" -- shouldn't load
load2 "../hier3/Two.o" -- shouldn't load
load2 "././././Two.o" -- shouldn't load
-- and this one pulls in "../hier3/Two.o" as a dep
y <- load "One.o" ["../hier3"] [] "resource"
case y of
LoadSuccess _ s -> putStrLn $ "One plugin: " ++ s
LoadFailure _ -> putStrLn "Failure: y"
load2 f = do
x <- load f [".", "../hier3", ""] [] "resource" -- depend on One.o
case x of
LoadSuccess _ s -> putStrLn $ "Two plugin: " ++ s
LoadFailure _ -> putStrLn "Failure: x"

View File

@ -0,0 +1,7 @@
TEST= hier/hier3
EXTRA_OBJS=One.o Two.o
EXTRAFLAGS=
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1,7 @@
module One where
import qualified Two
resource = "This is the sub-plugin of (" ++ Two.resource ++ ")"

View File

@ -0,0 +1,4 @@
module Two where
resource = "This is the top plugin"

View File

@ -0,0 +1,5 @@
Two plugin: This is the top plugin
Two plugin: This is the top plugin
Two plugin: This is the top plugin
Two plugin: This is the top plugin
One plugin: This is the sub-plugin of (This is the top plugin)

11
testsuite/hier/hier4/A.hs Normal file
View File

@ -0,0 +1,11 @@
-- now, the question is: is it possible to not depend on a module or
-- package, but nonetheless have an orphan to it? this could cause
-- problems....
module A where
import B
u :: Int
u = undefined

View File

@ -0,0 +1,4 @@
module B where
import C () -- instances, to make available to those who use B

12
testsuite/hier/hier4/C.hs Normal file
View File

@ -0,0 +1,12 @@
-- try to construct an orphan module == an instance decl-only module,
-- that uses classes and types not defined in this module
module C (C) where
import D
instance C a => D (T a) where
class C a where

View File

@ -0,0 +1,6 @@
module D where
class D a where
data T a = T

View File

@ -0,0 +1,12 @@
module Main where
import System.Plugins
main = do
makeAll "A.hs" []
y <- load "A.o" ["."] [] "u"
case y of
LoadSuccess _ _ -> putStrLn $ "YES"
LoadFailure e -> mapM_ putStrLn e

View File

@ -0,0 +1,4 @@
TEST= hier/hier4
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1 @@
YES