Import hs-plugins cvs
This commit is contained in:
3
examples/make/makeall001/A.hs
Normal file
3
examples/make/makeall001/A.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module A where
|
||||
|
||||
a = "a"
|
3
examples/make/makeall001/B.hs
Normal file
3
examples/make/makeall001/B.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module B where
|
||||
|
||||
b = "b"
|
3
examples/make/makeall001/C.hs
Normal file
3
examples/make/makeall001/C.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module C where
|
||||
|
||||
c = "c"
|
3
examples/make/makeall001/Makefile
Normal file
3
examples/make/makeall001/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
TEST= make/makeall001
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
13
examples/make/makeall001/Tiny.hs
Normal file
13
examples/make/makeall001/Tiny.hs
Normal file
@ -0,0 +1,13 @@
|
||||
module Tiny ( resource ) where
|
||||
|
||||
import API
|
||||
|
||||
import A
|
||||
import B
|
||||
import C
|
||||
|
||||
resource = tiny {
|
||||
|
||||
field = a ++ b ++ c
|
||||
|
||||
}
|
13
examples/make/makeall001/api/API.hs
Normal file
13
examples/make/makeall001/api/API.hs
Normal file
@ -0,0 +1,13 @@
|
||||
{-# OPTIONS -fglasgow-exts #-}
|
||||
-- ^ needed to derive Typeable
|
||||
|
||||
module API where
|
||||
|
||||
import Data.Dynamic
|
||||
|
||||
data Tiny = Tiny { field :: String }
|
||||
deriving (Typeable, Show)
|
||||
|
||||
tiny :: Tiny
|
||||
tiny = Tiny { field = "default value" }
|
||||
|
18
examples/make/makeall001/prog/Main.hs
Normal file
18
examples/make/makeall001/prog/Main.hs
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
-- little more complex. use the path to the obj file we get back from
|
||||
-- 'make'. load() uses this to find the .hi file
|
||||
|
||||
import Plugins
|
||||
import API
|
||||
|
||||
main = do
|
||||
status <- makeAll "../Tiny.hs" ["-i../api"]
|
||||
o <- case status of
|
||||
MakeSuccess _ o -> return o
|
||||
MakeFailure e -> mapM_ putStrLn e >> error "failed"
|
||||
m_v <- load o [".."] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
_ -> error "load failed"
|
||||
putStrLn $ field v
|
||||
|
1
examples/make/makeall001/prog/expected
Normal file
1
examples/make/makeall001/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
abc
|
4
examples/make/null/Makefile
Normal file
4
examples/make/null/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST= make/null
|
||||
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
11
examples/make/null/Null.hs
Normal file
11
examples/make/null/Null.hs
Normal file
@ -0,0 +1,11 @@
|
||||
module Null ( resource, resource_dyn ) where
|
||||
|
||||
import API
|
||||
import Data.Dynamic
|
||||
import Prelude hiding (null)
|
||||
|
||||
resource = null
|
||||
|
||||
-- ! this has to be special: it can't be overridden by the user.
|
||||
resource_dyn :: Dynamic
|
||||
resource_dyn = toDyn resource
|
12
examples/make/null/api/API.hs
Normal file
12
examples/make/null/api/API.hs
Normal file
@ -0,0 +1,12 @@
|
||||
{-# OPTIONS -fglasgow-exts #-}
|
||||
|
||||
module API where
|
||||
|
||||
import Data.Dynamic
|
||||
|
||||
data Null = Null { a, b :: Int }
|
||||
deriving (Typeable, Show)
|
||||
|
||||
null :: Null
|
||||
null = Null { a = 42 , b = 1 }
|
||||
|
13
examples/make/null/prog/Main.hs
Normal file
13
examples/make/null/prog/Main.hs
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
-- an example where we want to compile and load a file
|
||||
|
||||
import Plugins
|
||||
import API
|
||||
|
||||
main = do
|
||||
make "../Null.hs" ["-i../api"]
|
||||
m_v <- load "../Null.o" ["../api"] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
_ -> error "load failed"
|
||||
putStrLn ( show (a v) )
|
1
examples/make/null/prog/expected
Normal file
1
examples/make/null/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
42
|
3
examples/make/o/Makefile
Normal file
3
examples/make/o/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
TEST=make/o
|
||||
TOP =../../..
|
||||
include ../../build.mk
|
7
examples/make/o/Plugin.hs
Normal file
7
examples/make/o/Plugin.hs
Normal file
@ -0,0 +1,7 @@
|
||||
module Plugin ( resource ) where
|
||||
|
||||
import API
|
||||
|
||||
resource = plugin {
|
||||
field = "hello out there"
|
||||
}
|
8
examples/make/o/api/API.hs
Normal file
8
examples/make/o/api/API.hs
Normal file
@ -0,0 +1,8 @@
|
||||
module API where
|
||||
|
||||
data Interface = Interface {
|
||||
field :: String
|
||||
}
|
||||
|
||||
plugin :: Interface
|
||||
plugin = Interface { field = undefined }
|
23
examples/make/o/prog/Main.hs
Normal file
23
examples/make/o/prog/Main.hs
Normal file
@ -0,0 +1,23 @@
|
||||
import Plugins
|
||||
import API
|
||||
|
||||
import System.Directory
|
||||
|
||||
-- note: the name of the original *source* module is used to find
|
||||
-- symbols in the *object* file. load works out what the source file
|
||||
-- name was by looking at the object file name, i.e. it assumes they
|
||||
-- have the same name. so, if you are going to store objects in a
|
||||
-- tmpdir, you should make a tmp directory, and store them inside that,
|
||||
-- rather than mkstemp'ing the name of the object file yourself.
|
||||
--
|
||||
-- this should go away once we can read .hi files.
|
||||
|
||||
main = do
|
||||
make "../Plugin.hs" [ "-i../api", "-o", "/tmp/Plugin.o" ]
|
||||
m_v <- load "/tmp/Plugin.o" ["../api"] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
_ -> error "load failed"
|
||||
putStrLn $ field v
|
||||
|
||||
mapM_ removeFile [ "/tmp/Plugin.o" , "/tmp/Plugin.hi" ]
|
1
examples/make/o/prog/expected
Normal file
1
examples/make/o/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
hello out there
|
3
examples/make/odir/Makefile
Normal file
3
examples/make/odir/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
TEST= make/odir
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
7
examples/make/odir/Plugin.hs
Normal file
7
examples/make/odir/Plugin.hs
Normal file
@ -0,0 +1,7 @@
|
||||
module Plugin ( resource ) where
|
||||
|
||||
import API
|
||||
|
||||
resource = plugin {
|
||||
field = "hello out there"
|
||||
}
|
8
examples/make/odir/api/API.hs
Normal file
8
examples/make/odir/api/API.hs
Normal file
@ -0,0 +1,8 @@
|
||||
module API where
|
||||
|
||||
data Interface = Interface {
|
||||
field :: String
|
||||
}
|
||||
|
||||
plugin :: Interface
|
||||
plugin = Interface { field = undefined }
|
16
examples/make/odir/prog/Main.hs
Normal file
16
examples/make/odir/prog/Main.hs
Normal file
@ -0,0 +1,16 @@
|
||||
import Plugins
|
||||
import API
|
||||
import System.Directory
|
||||
|
||||
main = do
|
||||
status <- make "../Plugin.hs" [ "-i../api", "-odir", "/tmp" ]
|
||||
o <- case status of
|
||||
MakeSuccess _ o -> return o
|
||||
MakeFailure e -> mapM_ putStrLn e >> error "didn't compile"
|
||||
m_v <- load o ["../api"] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
_ -> error "load failed"
|
||||
putStrLn $ field v
|
||||
mapM_ removeFile ["/tmp/Plugin.hi", "/tmp/Plugin.o" ]
|
||||
|
1
examples/make/odir/prog/expected
Normal file
1
examples/make/odir/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
hello out there
|
3
examples/make/remake001/Bar.hs
Normal file
3
examples/make/remake001/Bar.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module Bar where
|
||||
|
||||
bar = undefined
|
3
examples/make/remake001/Foo.hs
Normal file
3
examples/make/remake001/Foo.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module Foo where
|
||||
|
||||
foo = undefined
|
36
examples/make/remake001/Main.hs
Normal file
36
examples/make/remake001/Main.hs
Normal file
@ -0,0 +1,36 @@
|
||||
--
|
||||
-- expected output:
|
||||
-- $ ./a.out
|
||||
-- True
|
||||
-- False
|
||||
-- True
|
||||
-- False
|
||||
--
|
||||
|
||||
import Plugins
|
||||
import System.Directory
|
||||
|
||||
main = do
|
||||
status <- make "Foo.hs" [] -- should make
|
||||
print status
|
||||
|
||||
status <- make "Foo.hs" [] -- shouldn't make
|
||||
print status
|
||||
|
||||
status <- merge "Foo.hs" "Bar.hs"
|
||||
case status of
|
||||
MergeFailure e -> error $ show e
|
||||
MergeSuccess _ _ fp -> do {
|
||||
|
||||
;status <- make fp [] -- should make
|
||||
;() <- case status of
|
||||
MakeSuccess c _ -> print c
|
||||
MakeFailure e -> error $ show e
|
||||
|
||||
;status <- make fp [] -- shouldn't make
|
||||
;case status of
|
||||
MakeSuccess c _ -> print c
|
||||
MakeFailure e -> error $ show e
|
||||
;removeFile "Foo.o"
|
||||
}
|
||||
|
4
examples/make/remake001/Makefile
Normal file
4
examples/make/remake001/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST= merge/remake001
|
||||
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
4
examples/make/remake001/expected
Normal file
4
examples/make/remake001/expected
Normal file
@ -0,0 +1,4 @@
|
||||
MakeSuccess ReComp "Foo.o"
|
||||
MakeSuccess NotReq "Foo.o"
|
||||
ReComp
|
||||
NotReq
|
3
examples/make/remake001_should_fail/Bar.hs
Normal file
3
examples/make/remake001_should_fail/Bar.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module Bar where
|
||||
|
||||
bar = undef {- error -}
|
3
examples/make/remake001_should_fail/Foo.hs
Normal file
3
examples/make/remake001_should_fail/Foo.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module Foo where
|
||||
|
||||
foo = undefined
|
31
examples/make/remake001_should_fail/Main.hs
Normal file
31
examples/make/remake001_should_fail/Main.hs
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
import Plugins
|
||||
|
||||
import System.Directory
|
||||
|
||||
main = do
|
||||
status <- make "Foo.hs" [] -- should make
|
||||
print status
|
||||
|
||||
status <- make "Foo.hs" [] -- shouldn't make
|
||||
print status
|
||||
|
||||
status <- merge "Foo.hs" "Bar.hs"
|
||||
case status of
|
||||
MergeFailure e -> error $ show e
|
||||
MergeSuccess _ _ fp -> do {
|
||||
|
||||
;status <- make fp [] -- should make
|
||||
;() <- case status of
|
||||
MakeSuccess c _ -> print c
|
||||
MakeFailure _ -> print "make failure"
|
||||
|
||||
;status <- make fp [] -- shouldn't make
|
||||
;case status of
|
||||
MakeSuccess c _ -> print c
|
||||
MakeFailure _ -> print "make failure"
|
||||
|
||||
;removeFile "Foo.o" -- make test deterministic
|
||||
}
|
||||
|
||||
|
4
examples/make/remake001_should_fail/Makefile
Normal file
4
examples/make/remake001_should_fail/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST= make/remake001_should_fail
|
||||
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
4
examples/make/remake001_should_fail/expected
Normal file
4
examples/make/remake001_should_fail/expected
Normal file
@ -0,0 +1,4 @@
|
||||
MakeSuccess ReComp "Foo.o"
|
||||
MakeSuccess NotReq "Foo.o"
|
||||
"make failure"
|
||||
"make failure"
|
3
examples/make/simple/Makefile
Normal file
3
examples/make/simple/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
TEST= make/simple
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
14
examples/make/simple/Tiny.hs
Normal file
14
examples/make/simple/Tiny.hs
Normal file
@ -0,0 +1,14 @@
|
||||
module Tiny ( resource, resource_dyn ) where
|
||||
|
||||
import API
|
||||
import Data.Dynamic
|
||||
|
||||
resource = tiny {
|
||||
|
||||
field = "hello strange world"
|
||||
|
||||
}
|
||||
|
||||
resource_dyn :: Dynamic
|
||||
resource_dyn = toDyn resource
|
||||
|
13
examples/make/simple/api/API.hs
Normal file
13
examples/make/simple/api/API.hs
Normal file
@ -0,0 +1,13 @@
|
||||
{-# OPTIONS -fglasgow-exts #-}
|
||||
-- ^ needed to derive Typeable
|
||||
|
||||
module API where
|
||||
|
||||
import Data.Dynamic
|
||||
|
||||
data Tiny = Tiny { field :: String }
|
||||
deriving (Typeable, Show)
|
||||
|
||||
tiny :: Tiny
|
||||
tiny = Tiny { field = "default value" }
|
||||
|
19
examples/make/simple/prog/Main.hs
Normal file
19
examples/make/simple/prog/Main.hs
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
-- little more complex. use the path to the obj file we get back from
|
||||
-- 'make'. load() uses this to find the .hi file
|
||||
|
||||
import Plugins
|
||||
import API
|
||||
|
||||
main = do
|
||||
status <- make "../Tiny.hs" ["-i../api"]
|
||||
o <- case status of
|
||||
MakeSuccess _ o -> return o
|
||||
MakeFailure e -> mapM_ putStrLn e >> error "failed"
|
||||
|
||||
m_v <- load o ["../api"] [] "resource"
|
||||
v <- case m_v of
|
||||
LoadSuccess _ v -> return v
|
||||
_ -> error "load failed"
|
||||
putStrLn $ field v
|
||||
|
1
examples/make/simple/prog/expected
Normal file
1
examples/make/simple/prog/expected
Normal file
@ -0,0 +1 @@
|
||||
hello strange world
|
Reference in New Issue
Block a user