Update examples
This commit is contained in:
8
testsuite/hier/hier1/Makefile
Normal file
8
testsuite/hier/hier1/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
TEST= hier/hier1
|
||||
|
||||
EXTRA_OBJS=Plugin.o
|
||||
PRIOR_OBJS=Modules/Flags.o
|
||||
EXTRAFLAGS=
|
||||
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
15
testsuite/hier/hier1/Modules/Flags.hs
Normal file
15
testsuite/hier/hier1/Modules/Flags.hs
Normal 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
|
6
testsuite/hier/hier1/Modules/Makefile
Normal file
6
testsuite/hier/hier1/Modules/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
all:
|
||||
ghc -O -c Flags.hs
|
||||
|
||||
clean:
|
||||
rm -f *.hi *.o
|
14
testsuite/hier/hier1/Plugin.hs
Normal file
14
testsuite/hier/hier1/Plugin.hs
Normal file
@ -0,0 +1,14 @@
|
||||
--
|
||||
-- Plugin
|
||||
--
|
||||
|
||||
module Plugin where
|
||||
|
||||
import API
|
||||
import Modules.Flags as Flags
|
||||
|
||||
|
||||
resource = plugin {
|
||||
dbFunc = (\x -> Flags.f1 x)
|
||||
}
|
||||
|
16
testsuite/hier/hier1/api/API.hs
Normal file
16
testsuite/hier/hier1/api/API.hs
Normal 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) }
|
||||
|
21
testsuite/hier/hier1/prog/Main.hs
Normal file
21
testsuite/hier/hier1/prog/Main.hs
Normal 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)
|
1
testsuite/hier/hier1/prog/expected
Normal file
1
testsuite/hier/hier1/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
4
|
Reference in New Issue
Block a user