Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 6 commits
  • 18 files changed
  • 0 commit comments
  • 1 contributor
View
1 .gitignore
@@ -0,0 +1 @@
+dist/
View
2 README.txt
@@ -10,4 +10,4 @@ For building and installing please consult the web page:
Feedback, feature requests, bug reports:
- Bernie Pope: http://www.cs.mu.oz.au/~bjpop/
+ Bernie Pope: http://www.berniepope.id.au
View
4 ministg.cabal
@@ -11,13 +11,13 @@ description: ministg is an interpreter for a simple high-level operation
category: Language
license: BSD3
license-file: LICENSE
-copyright: (c) 2009, 2010, 2011 Bernard James Pope
+copyright: (c) 2009-2012 Bernard James Pope
author: Bernard James Pope
maintainer: florbitous@gmail.com
homepage: http://www.haskell.org/haskellwiki/Ministg
build-type: Simple
stability: experimental
-tested-with: GHC==6.10.4
+tested-with: GHC==7.4.1
extra-source-files: README.txt test/*.stg
source-repository head
View
5 src/Main.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Main
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
@@ -77,4 +77,3 @@ dump flags dumped str msg =
putStrLn msg
putStrLn str
putStr "\n"
-
View
4 src/Ministg/AST.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.AST
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
4 src/Ministg/Annotate.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Annotate
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
4 src/Ministg/Arity.hs
@@ -2,9 +2,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Arity
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
4 src/Ministg/CallStack.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.CallStack
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
31 src/Ministg/Eval.hs
@@ -2,9 +2,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Eval
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
@@ -23,7 +23,7 @@ import Ministg.AST
import Ministg.CallStack (CallStack, push, showCallStack)
import Ministg.Pretty
import Ministg.State
-import Ministg.TraceEval (traceEval, traceEnd)
+import Ministg.TraceEval (traceEval, traceEnd, traceMaxStepsExceeded)
import Ministg.Options as Opts
(Flag (..), EvalStyle (..), defaultEvalStyle, probeFlagsFirst, getEvalStyle)
import Ministg.GC (garbageCollect)
@@ -58,15 +58,22 @@ evalProgram style heap = do
-- of one or more small step reductions).
bigStep :: EvalStyle -> Exp -> Stack -> Heap -> Eval (Exp, Stack, Heap)
bigStep style exp stack heap = do
- gcHeap <- garbageCollect exp stack heap
- traceEval exp stack gcHeap
- result <- smallStep style exp stack gcHeap
- incStepCount
- case result of
- -- Nothing more to do, we have reached a WHNF value (or perhaps some error).
- Nothing -> return (exp, stack, gcHeap)
- -- There might be more to do, keep trying.
- Just (newExp, newStack, newHeap) -> bigStep style newExp newStack newHeap
+ count <- gets state_stepCount
+ maxSteps <- gets state_maxTraceSteps
+ if count > maxSteps
+ then do
+ traceMaxStepsExceeded
+ fail ("Maximum reduction steps " ++ show maxSteps ++ " exceeded")
+ else do
+ gcHeap <- garbageCollect exp stack heap
+ traceEval exp stack gcHeap
+ result <- smallStep style exp stack gcHeap
+ incStepCount
+ case result of
+ -- Nothing more to do, we have reached a WHNF value (or perhaps some error).
+ Nothing -> return (exp, stack, gcHeap)
+ -- There might be more to do, keep trying.
+ Just (newExp, newStack, newHeap) -> bigStep style newExp newStack newHeap
-- | Perform one step of reduction. These equations correspond to the
-- rules in the operational semantics described in the "fast curry" paper.
View
4 src/Ministg/GC.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.GC
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
4 src/Ministg/Lexer.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Lexer
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
24 src/Ministg/Options.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Options
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
@@ -22,7 +22,7 @@ module Ministg.Options
, probeFlagsFirst
, existsFlag
, getTraceDir
- , getMaxTraceSteps
+ , getMaxSteps
, getEvalStyle
)
where
@@ -39,7 +39,7 @@ programName = "ministg"
-- This should really come from the cabal file somehow.
versionNumber :: String
-versionNumber = "0.2"
+versionNumber = "0.3"
versionInfo :: String
versionInfo = unwords [programName, "version", versionNumber]
@@ -85,7 +85,7 @@ data Flag
= Style EvalStyle -- ^ Which evaluation rules to use (eval/apply or push enter)
| Trace -- ^ Turn tracing on.
| TraceDir String -- ^ Directory to save trace file.
- | MaxTraceSteps Integer -- ^ Maximum trace steps to record.
+ | MaxSteps Integer -- ^ Maximum reduction steps to perform.
| CallStack -- ^ Include call stack in trace.
| Dump Dumped -- ^ Dump something out to debug the interpreter.
| NoPrelude -- ^ Do not automatically include the Prelude.
@@ -112,7 +112,7 @@ options =
[ Option ['s'] ["style"] (ReqArg mkStyle "STYLE") "evaluation STYLE to use (EA = eval apply, PE = push enter)"
, Option ['t'] ["trace"] (NoArg Trace) "record a trace of program evaluation"
, Option [] ["tracedir"] (ReqArg TraceDir "DIR") "directory (DIR) to store trace files"
- , Option ['m'] ["maxsteps"] (ReqArg mkMaxSteps "STEPS") "maximum number of evaluation STEPS to record in trace"
+ , Option ['m'] ["maxsteps"] (ReqArg mkMaxSteps "STEPS") "maximum number of reduction STEPS to perform"
, Option ['c'] ["callstack"] (NoArg CallStack) "enable call stack tracing"
, Option [] ["noprelude"] (NoArg NoPrelude) "do not import the Prelude"
, Option [] ["nogc"] (NoArg NoGC) "disable garbage collector"
@@ -147,15 +147,15 @@ defaultMaxSteps :: Integer
defaultMaxSteps = 1000
mkMaxSteps :: String -> Flag
-mkMaxSteps [] = MaxTraceSteps defaultMaxSteps
+mkMaxSteps [] = MaxSteps defaultMaxSteps
mkMaxSteps n
- | all isDigit n = MaxTraceSteps $ read n
- | otherwise = MaxTraceSteps defaultMaxSteps
+ | all isDigit n = MaxSteps $ read n
+ | otherwise = MaxSteps defaultMaxSteps
-getMaxTraceSteps :: [Flag] -> Integer
-getMaxTraceSteps flags =
+getMaxSteps :: [Flag] -> Integer
+getMaxSteps flags =
probeFlagsFirst flags probe defaultMaxSteps
- where probe (MaxTraceSteps i) = Just i
+ where probe (MaxSteps i) = Just i
probe other = Nothing
getTraceDir :: [Flag] -> String
View
4 src/Ministg/Parser.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Parser
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
4 src/Ministg/Pretty.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Pretty
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
8 src/Ministg/State.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.State
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
@@ -41,7 +41,7 @@ import Ministg.CallStack (CallStack, push, prettyCallStack)
import Ministg.Pretty
import Ministg.Options
( Flag (..), defaultMaxSteps, defaultTraceDir
- , probeFlagsFirst, existsFlag, getTraceDir, getMaxTraceSteps )
+ , probeFlagsFirst, existsFlag, getTraceDir, getMaxSteps )
-- | Stack continuations.
data Continuation
@@ -108,7 +108,7 @@ initState flags =
, state_stepCount = 0
, state_lastRule = ""
, state_trace = existsFlag flags Trace
- , state_maxTraceSteps = getMaxTraceSteps flags
+ , state_maxTraceSteps = getMaxSteps flags
, state_traceDir = getTraceDir flags
, state_gc = not $ existsFlag flags NoGC
, state_traceCallStack = existsFlag flags CallStack
View
19 src/Ministg/TraceEval.hs
@@ -2,16 +2,16 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.TraceEval
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
-- Trace the evaluation steps of the interpreter and generate HTML output.
-----------------------------------------------------------------------------
-module Ministg.TraceEval (traceEval, traceEnd) where
+module Ministg.TraceEval (traceEval, traceEnd, traceMaxStepsExceeded) where
import System.FilePath ((<.>), (</>))
import Control.Monad (when, join)
@@ -30,12 +30,13 @@ import Data.List as List (sortBy)
traceEval :: Exp -> Stack -> Heap -> Eval ()
traceEval exp stack heap = do
traceOn <- gets state_trace
- when traceOn $ do
- count <- gets state_stepCount
- maxSteps <- gets state_maxTraceSteps
- when (count <= maxSteps) $ do
- join (writeTraceFile <$> makeHtml exp stack heap)
- when (count == maxSteps + 1) $ lastTracePage "Maximum trace steps exceeded"
+ when traceOn $
+ join (writeTraceFile <$> makeHtml exp stack heap)
+
+traceMaxStepsExceeded :: Eval ()
+traceMaxStepsExceeded = do
+ maxSteps <- gets state_maxTraceSteps
+ lastTracePage ("Maximum trace steps " ++ show maxSteps ++ " exceeded")
traceEnd :: Eval ()
traceEnd = do
View
4 src/Ministg/Utils.hs
@@ -1,9 +1,9 @@
-----------------------------------------------------------------------------
-- |
-- Module : Ministg.Utils
--- Copyright : (c) 2009 Bernie Pope
+-- Copyright : (c) 2009-2012 Bernie Pope
-- License : BSD-style
--- Maintainer : bjpop@csse.unimelb.edu.au
+-- Maintainer : florbitous@gmail.com
-- Stability : experimental
-- Portability : ghc
--
View
0 test/loop.stg → test/blackhole.stg
File renamed without changes.

No commit comments for this range

Something went wrong with that request. Please try again.