@@ -30,6 +30,7 @@ import Language.PureScript.ModuleDependencies as P
3030import Language.PureScript.Environment as P
3131import Language.PureScript.Errors as P
3232import Language.PureScript.DeadCodeElimination as P
33+ import Language.PureScript.Supply as P
3334
3435import qualified Language.PureScript.Constants as C
3536
@@ -40,7 +41,7 @@ import Data.Maybe (fromJust, fromMaybe)
4041import Control.Monad.Error
4142import Control.Monad.State.Lazy
4243import Control.Arrow ((&&&) )
43- import Control.Applicative ( (<$>) )
44+ import Control.Applicative
4445import qualified Data.Map as M
4546import qualified Data.Set as S
4647import System.FilePath (pathSeparator )
@@ -70,14 +71,14 @@ compile = compile' initEnvironment
7071compile' :: Environment -> Options -> [Module ] -> Either String (String , String , Environment )
7172compile' env opts ms = do
7273 (sorted, _) <- sortModules $ if optionsNoPrelude opts then ms else (map importPrelude ms)
73- desugared <- stringifyErrorStack True $ desugar sorted
74+ ( desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
7475 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
7576 regrouped <- stringifyErrorStack True $ createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
7677 let entryPoints = moduleNameFromString `map` optionsModules opts
7778 let elim = if null entryPoints then regrouped else eliminateDeadCode entryPoints regrouped
7879 let codeGenModules = moduleNameFromString `map` optionsCodeGenModules opts
7980 let modulesToCodeGen = if null codeGenModules then elim else filter (\ (Module mn _ _) -> mn `elem` codeGenModules) elim
80- let js = concatMap (\ m -> moduleToJs Globals opts m env') modulesToCodeGen
81+ let (js, _) = runSupply nextVar $ concat <$> mapM (\ m -> moduleToJs Globals opts m env') modulesToCodeGen
8182 let exts = intercalate " \n " . map (`moduleToPs` env') $ modulesToCodeGen
8283 js' <- generateMain env' opts js
8384 return (prettyPrintJS js', exts, env')
@@ -165,7 +166,7 @@ class MonadMake m where
165166-- If timestamps have not changed, the externs file can be used to provide the module's types without
166167-- having to typecheck the module again.
167168--
168- make :: (Functor m , Monad m , MonadMake m ) => FilePath -> Options -> [(FilePath , Module )] -> m Environment
169+ make :: (Functor m , Applicative m , Monad m , MonadMake m ) => FilePath -> Options -> [(FilePath , Module )] -> m Environment
169170make outputDir opts ms = do
170171 let filePathMap = M. fromList (map (\ (fp, Module mn _ _) -> (mn, fp)) ms)
171172
@@ -188,34 +189,34 @@ make outputDir opts ms = do
188189
189190 marked <- rebuildIfNecessary (reverseDependencies graph) toRebuild sorted
190191
191- desugared <- liftError $ stringifyErrorStack True $ zip (map fst marked) <$> desugar (map snd marked)
192+ ( desugared, nextVar) <- liftError $ stringifyErrorStack True $ runSupplyT 0 $ zip (map fst marked) <$> desugar (map snd marked)
192193
193- go initEnvironment desugared
194+ fst <$> runSupplyT nextVar ( go initEnvironment desugared)
194195
195196 where
196- go :: (Functor m , Monad m , MonadMake m ) => Environment -> [(Bool , Module )] -> m Environment
197+ go :: (Functor m , Applicative m , Monad m , MonadMake m ) => Environment -> [(Bool , Module )] -> SupplyT m Environment
197198 go env [] = return env
198199 go env ((False , m) : ms') = do
199- (_, env') <- liftError . runCheck' opts env $ typeCheckModule Nothing m
200+ (_, env') <- lift . liftError . runCheck' opts env $ typeCheckModule Nothing m
200201
201202 go env' ms'
202203 go env ((True , m@ (Module moduleName' _ exps)) : ms') = do
203204 let filePath = runModuleName moduleName'
204205 jsFile = outputDir ++ pathSeparator : filePath ++ pathSeparator : " index.js"
205206 externsFile = outputDir ++ pathSeparator : filePath ++ pathSeparator : " externs.purs"
206207
207- progress $ " Compiling " ++ runModuleName moduleName'
208+ lift . progress $ " Compiling " ++ runModuleName moduleName'
208209
209- (Module _ elaborated _, env') <- liftError . runCheck' opts env $ typeCheckModule Nothing m
210+ (Module _ elaborated _, env') <- lift . liftError . runCheck' opts env $ typeCheckModule Nothing m
210211
211- regrouped <- liftError . stringifyErrorStack True . createBindingGroups moduleName' . collapseBindingGroups $ elaborated
212+ regrouped <- lift . liftError . stringifyErrorStack True . createBindingGroups moduleName' . collapseBindingGroups $ elaborated
212213
213214 let mod' = Module moduleName' regrouped exps
214- js = prettyPrintJS $ moduleToJs CommonJS opts mod' env'
215- exts = moduleToPs mod' env'
215+ js <- prettyPrintJS <$> moduleToJs CommonJS opts mod' env'
216+ let exts = moduleToPs mod' env'
216217
217- writeTextFile jsFile js
218- writeTextFile externsFile exts
218+ lift $ writeTextFile jsFile js
219+ lift $ writeTextFile externsFile exts
219220
220221 go env' ms'
221222
0 commit comments