summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/cpranal
diff options
context:
space:
mode:
authorsimonmar <unknown>2001-08-22 12:21:15 +0000
committersimonmar <unknown>2001-08-22 12:21:15 +0000
commit1ff078e3e252bdd21664e05a761ba116a3b144b0 (patch)
treef92a010d126cbd9affd55e247820c0e43a99b0c6 /testsuite/tests/ghc-regress/cpranal
parentee157e656d58f82a97a9c76cd17d0219a103f9a5 (diff)
downloadhaskell-1ff078e3e252bdd21664e05a761ba116a3b144b0.tar.gz
[project @ 2001-08-22 12:21:15 by simonmar]
Add cpranal tests.
Diffstat (limited to 'testsuite/tests/ghc-regress/cpranal')
-rw-r--r--testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001.hs16
-rw-r--r--testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001_imp.hs55
-rw-r--r--testsuite/tests/ghc-regress/cpranal/should_compile/Makefile3
-rw-r--r--testsuite/tests/ghc-regress/cpranal/should_compile/all.T7
4 files changed, 81 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001.hs b/testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001.hs
new file mode 100644
index 0000000000..0871205bb7
--- /dev/null
+++ b/testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001.hs
@@ -0,0 +1,16 @@
+module Cpr001
+ (intpInstr) where
+
+import Cpr001_imp
+
+-- -------------------------------------------------------------------
+
+intpInstr :: Instr -> MST ()
+
+intpInstr (SysCall "exit")
+ = setMTerminated
+
+intpInstr (SysCall call)
+ = setMSvc call
+
+-- -------------------------------------------------------------------
diff --git a/testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001_imp.hs b/testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001_imp.hs
new file mode 100644
index 0000000000..5b2586127b
--- /dev/null
+++ b/testsuite/tests/ghc-regress/cpranal/should_compile/Cpr001_imp.hs
@@ -0,0 +1,55 @@
+-- $Id: Cpr001_imp.hs,v 1.1 2001/08/22 12:21:15 simonmar Exp $
+
+module Cpr001_imp where
+
+data MS = MS { instr :: String
+ , pc :: Int
+ , mem :: String
+ , stack :: String
+ , frames :: [String]
+ , status :: Maybe String
+ }
+
+
+newtype StateTrans s a = ST ( s -> (s, Maybe a))
+
+-- state monad with error handling
+-- in case of an error, the state remains
+-- as it is and Nothing is returned as value
+-- else execution continues
+
+instance Monad (StateTrans s) where
+ (ST p) >>= k
+ = ST (\s0 -> let
+ (s1, r0) = p s0
+ in
+ case r0 of
+ Just v -> let
+ (ST q) = k v
+ in
+ q s1
+ Nothing -> (s1, Nothing)
+ )
+ return v
+ = ST (\s -> (s, Just v))
+
+
+-- machine state transitions
+
+type MachineStateTrans = StateTrans MS
+
+type MST = MachineStateTrans
+
+{-# NOINLINE setMTerminated #-}
+setMTerminated
+ = ST (\ms -> (ms { status = Just "Terminated" }, Just ()))
+
+setMSvc call
+ = ST (\ms -> (ms { status = Just "Service" }, Just ()))
+
+-- -------------------------------------------------------------------
+
+data Instr
+ = LoadI Int -- load int const
+ | SysCall String -- system call (svc)
+
diff --git a/testsuite/tests/ghc-regress/cpranal/should_compile/Makefile b/testsuite/tests/ghc-regress/cpranal/should_compile/Makefile
new file mode 100644
index 0000000000..1c39d1c1fe
--- /dev/null
+++ b/testsuite/tests/ghc-regress/cpranal/should_compile/Makefile
@@ -0,0 +1,3 @@
+TOP=../../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/ghc-regress/cpranal/should_compile/all.T b/testsuite/tests/ghc-regress/cpranal/should_compile/all.T
new file mode 100644
index 0000000000..0e7689e124
--- /dev/null
+++ b/testsuite/tests/ghc-regress/cpranal/should_compile/all.T
@@ -0,0 +1,7 @@
+
+include ($confdir ++ "/../vanilla-test.T")
+
+-- Args to vtc are: extra compile flags
+
+test "Cpr001_imp" { vtc("-O") }
+test "Cpr001" { vtc("-O") }