Skip to content

Commit

Permalink
Use Data.Sequence instead of DList's.
Browse files Browse the repository at this point in the history
  • Loading branch information
mainland committed Sep 12, 2016
1 parent 7448284 commit 5260b90
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
45 changes: 23 additions & 22 deletions src/Codegen/CgMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Writer
import Data.Char (toUpper)
import Data.DList (DList)
import qualified Data.DList as DL
import Data.Foldable (toList)
import Data.Monoid
import Data.Maybe (catMaybes)
import Data.Monoid
import Data.Loc (noLoc)
import Data.Loc
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import qualified Data.Symbol
import Control.Monad (ap)
import Control.Monad.IO.Class (MonadIO(..))
Expand Down Expand Up @@ -203,9 +204,9 @@ instance IfThenElse C.Exp Code where
$decls:el_decls
$stms:el_stms
}|]
in Code (DL.fromList (th_defs ++ el_defs))
(DL.empty)
(DL.singleton s)
in Code (Seq.fromList (th_defs ++ el_defs))
(mempty)
(Seq.singleton s)


------------------------------------------------------------------------------
Expand Down Expand Up @@ -378,15 +379,15 @@ emptyState = CgState [] 0 Opts.cMAX_STACK_ALLOC [] [] []

data Code = Code
{ -- Top-level definitions
defs :: !(DList C.Definition)
defs :: !(Seq C.Definition)
-- Local declarations
, decls :: !(DList C.InitGroup)
, decls :: !(Seq C.InitGroup)
-- Local statements
, stmts :: !(DList C.Stm)
, stmts :: !(Seq C.Stm)
}

getCode :: Code -> ([C.Definition],[C.InitGroup],[C.Stm])
getCode (Code df dc st) = (DL.toList df, DL.toList dc, DL.toList st)
getCode (Code df dc st) = (toList df, toList dc, toList st)


instance Monoid Code where
Expand All @@ -413,7 +414,7 @@ evalCg sym stack_alloc_threshold m = do
(emptyState { maxStackAlloc = stack_alloc_threshold })
case res of
Left err -> return $ Left err
Right (_, code, _) -> return $ Right $ DL.toList (defs code)
Right (_, code, _) -> return $ Right $ toList (defs code)

instance Monad Cg where
return x = Cg $ \rho s -> return (Right (x, mempty, s))
Expand Down Expand Up @@ -505,8 +506,8 @@ inNewBlock :: Cg a -> Cg ([C.InitGroup], [C.Stm], a)
inNewBlock m
= do { (x, code) <- collect m
; tell code { decls = mempty, stmts = mempty }
; let decls' = DL.toList (decls code)
stmts' = DL.toList (stmts code)
; let decls' = toList (decls code)
stmts' = toList (stmts code)
; return (decls',stmts',x)
}

Expand Down Expand Up @@ -540,7 +541,7 @@ collectDefinitions :: Cg a -> Cg ([C.Definition], a)
collectDefinitions m = do
(x, code) <- collect m
tell code { defs = mempty }
return (DL.toList (defs code), x)
return (toList (defs code), x)

collectDefinitions_ :: Cg () -> Cg ([C.Definition])
collectDefinitions_ m = do
Expand All @@ -551,7 +552,7 @@ collectStmts :: Cg a -> Cg ([C.Stm], a)
collectStmts m = do
(x, code) <- collect m
tell code { stmts = mempty }
return (DL.toList (stmts code), x)
return (toList (stmts code), x)

collectStmts_ :: Cg () -> Cg ([C.Stm])
collectStmts_ m = do
Expand Down Expand Up @@ -642,11 +643,11 @@ printState = do

appendTopDef :: C.Definition -> Cg ()
appendTopDef newDef =
tell mempty { defs = DL.singleton newDef }
tell mempty { defs = Seq.singleton newDef }

appendTopDefs :: [C.Definition] -> Cg ()
appendTopDefs newDefs =
tell mempty { defs = DL.fromList newDefs }
tell mempty { defs = Seq.fromList newDefs }

appendStructDef :: TyName -> C.InitGroup -> Cg ()
-- Structs can't shadow each other in Blink, but we may end up
Expand All @@ -670,11 +671,11 @@ $esc:("#endif")

appendTopDecl :: C.InitGroup -> Cg ()
appendTopDecl newDecl =
tell mempty { defs = DL.singleton (C.DecDef newDecl noLoc) }
tell mempty { defs = Seq.singleton (C.DecDef newDecl noLoc) }

appendTopDecls :: [C.InitGroup] -> Cg ()
appendTopDecls newDecls =
tell mempty { defs = DL.fromList [C.DecDef decl noLoc | decl <- newDecls] }
tell mempty { defs = Seq.fromList [C.DecDef decl noLoc | decl <- newDecls] }

appendDecl :: C.InitGroup -> Cg ()
appendDecl newDecl = tell (codeDecl newDecl)
Expand All @@ -683,16 +684,16 @@ appendDecls :: [C.InitGroup] -> Cg ()
appendDecls newDecls = tell (codeDecls newDecls)

codeStmt :: C.Stm -> Code
codeStmt newStmt = mempty { stmts = DL.singleton newStmt }
codeStmt newStmt = mempty { stmts = Seq.singleton newStmt }

codeStmts :: [C.Stm] -> Code
codeStmts newStmts = mempty { stmts = DL.fromList newStmts }
codeStmts newStmts = mempty { stmts = Seq.fromList newStmts }

codeDecl :: C.InitGroup -> Code
codeDecl newDecl = mempty { decls = DL.singleton newDecl }
codeDecl newDecl = mempty { decls = Seq.singleton newDecl }

codeDecls :: [C.InitGroup] -> Code
codeDecls newDecls = mempty { decls = DL.fromList newDecls }
codeDecls newDecls = mempty { decls = Seq.fromList newDecls }


emitCode :: Code -> Cg ()
Expand Down
1 change: 0 additions & 1 deletion src/Codegen/CgOpt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import CgExpr
import CgLUT

import Control.Monad.Writer
import qualified Data.DList as DL
import qualified Data.List
import Data.Loc
import Data.Monoid
Expand Down
1 change: 0 additions & 1 deletion src/Codegen/CgProgram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import qualified CgSetupThreads as ST
import qualified PassPipeline as PP

import Control.Monad.Writer
import qualified Data.DList as DL
import qualified Data.List
import Data.Loc
import Data.Monoid
Expand Down
1 change: 0 additions & 1 deletion wplc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Executable wplc
-- deepseq-generics is needed for deepseq < 1.4
deepseq-generics >= 0.1 && < 0.3,
directory >= 1.2 && < 1.3,
dlist >= 0.6 && < 0.7,
exception-transformers >= 0.3 && < 0.5,
ghc-prim >= 0.3 && < 0.6,
hashable >= 1.2 && < 1.3,
Expand Down

0 comments on commit 5260b90

Please sign in to comment.