From 7dbaf7fe881547138e10a926101989b6dfd2f8fd Mon Sep 17 00:00:00 2001 From: lemmih Date: Thu, 19 May 2005 03:23:30 +0000 Subject: [PATCH] Example program for 'unloadAll'. --- examples/unloadAll/null/Dep.hs | 7 +++++++ examples/unloadAll/null/Makefile | 4 ++++ examples/unloadAll/null/Null.hs | 12 ++++++++++++ examples/unloadAll/null/api/API.hs | 12 ++++++++++++ examples/unloadAll/null/prog/Main.hs | 15 +++++++++++++++ examples/unloadAll/null/prog/expected | 2 ++ 6 files changed, 52 insertions(+) create mode 100644 examples/unloadAll/null/Dep.hs create mode 100644 examples/unloadAll/null/Makefile create mode 100644 examples/unloadAll/null/Null.hs create mode 100644 examples/unloadAll/null/api/API.hs create mode 100644 examples/unloadAll/null/prog/Main.hs create mode 100644 examples/unloadAll/null/prog/expected diff --git a/examples/unloadAll/null/Dep.hs b/examples/unloadAll/null/Dep.hs new file mode 100644 index 0000000..60aab5b --- /dev/null +++ b/examples/unloadAll/null/Dep.hs @@ -0,0 +1,7 @@ +module Dep ( resource ) where + +import API +import Data.Dynamic +import Prelude hiding (null) + +resource = null diff --git a/examples/unloadAll/null/Makefile b/examples/unloadAll/null/Makefile new file mode 100644 index 0000000..83999ad --- /dev/null +++ b/examples/unloadAll/null/Makefile @@ -0,0 +1,4 @@ +TEST= unloadAll/null +EXTRA_OBJS=Null.o Dep.o +TOP=../../.. +include ../../build.mk diff --git a/examples/unloadAll/null/Null.hs b/examples/unloadAll/null/Null.hs new file mode 100644 index 0000000..2432738 --- /dev/null +++ b/examples/unloadAll/null/Null.hs @@ -0,0 +1,12 @@ +module Null ( resource ) where + +import API +import Data.Dynamic +import Prelude hiding (null) +import qualified Dep + +resource = Dep.resource + +-- ! this has to be special: it can't be overridden by the user. +resource_dyn :: Dynamic +resource_dyn = toDyn resource diff --git a/examples/unloadAll/null/api/API.hs b/examples/unloadAll/null/api/API.hs new file mode 100644 index 0000000..a77126c --- /dev/null +++ b/examples/unloadAll/null/api/API.hs @@ -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 } + diff --git a/examples/unloadAll/null/prog/Main.hs b/examples/unloadAll/null/prog/Main.hs new file mode 100644 index 0000000..b8fd0bb --- /dev/null +++ b/examples/unloadAll/null/prog/Main.hs @@ -0,0 +1,15 @@ + +import System.Plugins +import API + +-- an example where we just want to load an object and run it + +main = do + m_v <- load_ "../Null.o" ["../api",".."] "resource" + t <- load_ "../Dep.o" ["../api"] "resource" + case m_v of + LoadFailure err -> error (unlines err) + LoadSuccess m v -> do putStrLn ( show (a v) ) ; unloadAll m + case t of + LoadFailure err -> error (unlines err) + LoadSuccess m v -> do putStrLn ( show (a v) ) ; unloadAll m diff --git a/examples/unloadAll/null/prog/expected b/examples/unloadAll/null/prog/expected new file mode 100644 index 0000000..daaac9e --- /dev/null +++ b/examples/unloadAll/null/prog/expected @@ -0,0 +1,2 @@ +42 +42