Fixes for GHC 8.x, archive loading, -dynamic, and file generation

This commit is contained in:
Mark Laws
2018-01-20 10:16:48 +09:00
parent 22dabddd73
commit 9eb6ab384e
16 changed files with 458 additions and 216 deletions

View File

@ -13,7 +13,7 @@ REALBIN= ./Main
API_OBJ= api/API.o
INCLUDES= -i$(TOP)/testsuite/$(TEST)/api
GHCFLAGS= -O0 -cpp -fglasgow-exts
GHCFLAGS= -rdynamic -O0 -cpp -fglasgow-exts
.SUFFIXES : .o .hs .hi .lhs .hc .s
@ -26,7 +26,7 @@ $(BIN) : $(PRIOR_OBJS) $(API_OBJ) $(SRC) $(EXTRA_OBJS)
# Standard suffix rules
.o.hi:
@:
.hs.o:
.hs.o: $(API_OBJ)
@$(GHC) $(INCLUDES) $(PKGFLAGS) $(GHCFLAGS) $(EXTRAFLAGS) -c $<
clean:

View File

@ -1,4 +1,3 @@
{-# OPTIONS -fglasgow-exts -cpp #-}
--
-- Copyright (c) 2004 Don Stewart - http://www.cse.unsw.edu.au/~dons
-- LGPL version 2.1 or later (see http://www.gnu.org/copyleft/lesser.html)
@ -9,6 +8,8 @@ module TestIO ( resource_dyn ) where
import API
import Data.Dynamic
import Control.Exception (SomeException, catch)
import System.IO
import System.Posix.Types ( ProcessID, Fd )
import System.Posix.Process ( forkProcess, executeFile, getProcessID )
@ -26,7 +27,7 @@ resource = testio { field = date }
-- call a shell command , returning it's output
--
date :: IO String
date = do (hdl,_,_) <- catch (popen "/bin/date") (\_->error "popen failed")
date = do (hdl,_,_) <- catch (popen "/bin/date") (\(_ :: SomeException)->error "popen failed")
hGetLine hdl
------------------------------------------------------------------------

View File

@ -1,19 +1,20 @@
{-# OPTIONS -fglasgow-exts #-}
module API where
import Data.Typeable
data TestIO = TestIO {
field :: IO String
#if __GLASGOW_HASKELL__ >= 800
} deriving Typeable
#else
}
instance Typeable TestIO where
#if __GLASGOW_HASKELL__ >= 603
typeOf i = mkTyConApp (mkTyCon "API.TestIO") []
#else
typeOf i = mkAppTy (mkTyCon "API.TestIO") []
#endif
#endif
testio :: TestIO
testio = TestIO { field = return "default value" }

View File

@ -1,12 +1,13 @@
import System.Plugins
import API
main = do
m_v <- dynload "../TestIO.o" ["../api"]
[] "resource_dyn"
case m_v of
LoadFailure _ -> error "couldn't compile"
LoadSuccess _ v -> do
s <- field v
if s /= [] then print True else print False
m_v <- dynload "../TestIO.o" ["../api"]
[] "resource_dyn" :: IO (LoadStatus TestIO)
case m_v of
LoadFailure _ -> error "couldn't link"
LoadSuccess _ v -> do
s <- field v
if s /= "" then print True else print False

View File

@ -0,0 +1,6 @@
TEST=load/plain
EXTRA_OBJS=TestIO.o
TOP=../../..
include ../../build.mk

View File

@ -0,0 +1,11 @@
module TestIO (resource) where
import Control.Monad (forever)
import API
resource :: CLIInterface
resource = testio { repl = loop }
loop :: IO ()
loop = forever $ getLine >>= putStrLn

View File

@ -0,0 +1,10 @@
module API(CLIInterface(..), testio) where
import Data.Typeable
data CLIInterface = CLIInterface {
repl :: IO ()
} deriving Typeable
testio :: CLIInterface
testio = CLIInterface { repl = return () }

View File

@ -0,0 +1,22 @@
module Main (main) where
import Control.Exception (handle)
import System.Plugins
import API
fexn :: IOError -> IO ()
fexn = print
main :: IO ()
main = handle fexn $ do
mf <- load "../TestIO.o" ["../api"] [] "resource"
case mf of
LoadFailure _ -> error "nope"
LoadSuccess _ v -> do
putStrLn "success"
engage v
engage :: CLIInterface -> IO ()
engage plugin = repl plugin