Skip to content

Commit

Permalink
[ohua-dev/ohuac#12] Starting with some basic machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Oct 10, 2018
1 parent 233f6bb commit 007c5e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/Ohua/Stage.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Ohua.Stage (stage) where

import Ohua.Prelude

stage :: (MonadReadEnvironment m, MonadIO m, Show code, Pretty code) => StageName -> code -> m ()
stage stName code = do
stageH <- fromEnv stageHandling
let (dumpInstructions, shouldAbort) = stageH stName


when shouldAbort exitSuccess
21 changes: 15 additions & 6 deletions src/Ohua/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ module Ohua.Types
, NameGenerator
, simpleNameList
, takenNames
, callEnvExpr
, callLocalFunction
, transformRecursiveFunctions
, options
, Annotated(Annotated)
, TyExprF(..)
Expand Down Expand Up @@ -358,11 +355,20 @@ type instance SourceType (OhuaState envExpr) =
instance Make (OhuaState envExpr) where
make (ng, fnid, exprs) = pure $ OhuaState ng fnid exprs

type StageName = Text
type AbortCompilation = Bool
data DumpCode
= Don'tDump
| DumpShow
| DumpPretty
| DumpOther Text
type StageHandling = StageName -> (AbortCompilation, DumpCode)

-- | The read only compiler environment
newtype Environment = Environment Options
newtype Environment = Environment Options StageHandling

instance Default Environment where
def = Environment def
def = Environment def (const (Don'tDump, True))

nameGenerator :: Lens' (OhuaState envExpr) NameGenerator
nameGenerator f (OhuaState gen counter envExprs) =
Expand Down Expand Up @@ -404,7 +410,10 @@ transformRecursiveFunctions :: Lens' Options Bool
transformRecursiveFunctions f (Options c l e) = f e <&> Options c l

options :: Lens' Environment Options
options f (Environment opts) = Environment <$> f opts
options f (Environment opts s) = (\a -> Environment a s) <$> f opts

stageHandling :: Lens' Environment Options
stageHandling f (Environment opts s) = Environment opts <$> f s

-- | Generic way of attaching arbitrary, alterable data to some type.
--
Expand Down

0 comments on commit 007c5e9

Please sign in to comment.