git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #306. Had to move ref(In)Eq back to Prelude to avoid circular dependency between Prelude and Data.Eq.Unsafe
commit53e8af8b8490d84e9ad23d0cc1de977e81127f71 authorPhil Freeman <paf31@cantab.net> dateWed 19 Mar 2014, 20:39 (13 years ago) parent272be04
4 files changed+42−52
prelude/prelude.purs+22−32 src/Language/PureScript.hs+16−2 src/Language/PureScript/ModuleDependencies.hs+1−1 src/Language/PureScript/Sugar/Names.hs+3−17
prelude/prelude.purs+22−32
@@ -146,17 +146,31 @@ module Prelude where
146146 (==) :: a -> a -> Boolean
147147 (/=) :: a -> a -> Boolean
148148
149+ foreign import refEq
150+ "function refEq(r1) {\
151+ \ return function(r2) {\
152+ \ return r1 === r2;\
153+ \ };\
154+ \}" :: forall a. a -> a -> Boolean
155+
156+ foreign import refIneq
157+ "function refIneq(r1) {\
158+ \ return function(r2) {\
159+ \ return r1 !== r2;\
160+ \ };\
161+ \}" :: forall a. a -> a -> Boolean
162+
149163 instance eqString :: Eq String where
150− (==) = Data.Eq.Unsafe.refEq
151− (/=) = Data.Eq.Unsafe.refIneq
164+ (==) = refEq
165+ (/=) = refIneq
152166
153167 instance eqNumber :: Eq Number where
154− (==) = Data.Eq.Unsafe.refEq
155− (/=) = Data.Eq.Unsafe.refIneq
168+ (==) = refEq
169+ (/=) = refIneq
156170
157171 instance eqBoolean :: Eq Boolean where
158− (==) = Data.Eq.Unsafe.refEq
159− (/=) = Data.Eq.Unsafe.refIneq
172+ (==) = refEq
173+ (/=) = refIneq
160174
161175 instance eqArray :: (Eq a) => Eq [a] where
162176 (==) [] [] = true
@@ -321,39 +335,15 @@ module Prelude where
321335
322336module Data.Eq where
323337
324− import qualified Data.Eq.Unsafe as Unsafe
325−
326338 data Ref a = Ref a
327339
328340 liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
329341 liftRef f (Ref x) (Ref y) = f x y
330342
331− refEq :: forall a. Ref a -> Ref a -> Boolean
332− refEq = liftRef Unsafe.refEq
333−
334− refIneq :: forall a. Ref a -> Ref a -> Boolean
335− refIneq = liftRef Unsafe.refIneq
336−
337343 instance eqRef :: Eq (Ref a) where
338− (==) = refEq
339− (/=) = refIneq
344+ (==) = liftRef refEq
345+ (/=) = liftRef refIneq
340346
341−module Data.Eq.Unsafe where
342−
343− foreign import refEq
344− "function refEq(r1) {\
345− \ return function(r2) {\
346− \ return r1 === r2;\
347− \ };\
348− \}" :: forall a. a -> a -> Boolean
349−
350− foreign import refIneq
351− "function refIneq(r1) {\
352− \ return function(r2) {\
353− \ return r1 !== r2;\
354− \ };\
355− \}" :: forall a. a -> a -> Boolean
356−
357347module Control.Monad.Eff where
358348
359349 foreign import data Eff :: # ! -> * -> *
src/Language/PureScript.hs+16−2
@@ -68,7 +68,7 @@ compile = compile' initEnvironment
6868
6969compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
7070compile' env opts ms = do
71− (sorted, _) <- sortModules ms
71+ (sorted, _) <- sortModules (map importPrelude ms)
7272 desugared <- desugar sorted
7373 (elaborated, env') <- runCheck' env $ forM desugared $ \(Module moduleName' decls exps) -> do
7474 modify (\s -> s { checkCurrentModule = Just moduleName' })
@@ -129,7 +129,7 @@ make :: (Functor m, Monad m, MonadMake m) => Options -> [(FilePath, Module)] ->
129129make opts ms = do
130130 let filePathMap = M.fromList (map (\(fp, (Module mn _ _)) -> (mn, fp)) ms)
131131
132− (sorted, graph) <- liftError $ sortModules (map snd ms)
132+ (sorted, graph) <- liftError $ sortModules (map (importPrelude . snd) ms)
133133
134134 toRebuild <- foldM (\s (Module moduleName' _ _) -> do
135135 let filePath = toFileName moduleName'
@@ -204,3 +204,17 @@ reverseDependencies g = combine [ (dep, mn) | (mn, deps) <- g, dep <- deps ]
204204 where
205205 combine :: (Ord a) => [(a, b)] -> M.Map a [b]
206206 combine = M.fromList . map ((fst . head) &&& map snd) . groupBy ((==) `on` fst) . sortBy (compare `on` fst)
207+
208+-- |
209+-- Add an import declaration for the Prelude to a module if it does not already explicitly import
210+-- it.
211+--
212+importPrelude :: Module -> Module
213+importPrelude m@(Module mn decls exps) =
214+ if isPreludeImport `any` decls || mn == prelude then m
215+ else Module mn (preludeImport : decls) exps
216+ where
217+ prelude = ModuleName [ProperName C.prelude]
218+ isPreludeImport (ImportDeclaration (ModuleName [ProperName mn']) _ _) | mn' == C.prelude = True
219+ isPreludeImport _ = False
220+ preludeImport = ImportDeclaration prelude Nothing Nothing
src/Language/PureScript/ModuleDependencies.hs+1−1
@@ -67,4 +67,4 @@ getModuleName (Module mn _ _) = mn
6767toModule :: SCC Module -> Either String Module
6868toModule (AcyclicSCC m) = return m
6969toModule (CyclicSCC [m]) = return m
70−toModule (CyclicSCC _) = Left "Cycle in module dependencies"
70+toModule (CyclicSCC ms) = Left $ "Cycle in module dependencies: " ++ show (map getModuleName ms)
src/Language/PureScript/Sugar/Names.hs+3−17
@@ -134,10 +134,9 @@ addExport exports name =
134134--
135135desugarImports :: [Module] -> Either String [Module]
136136desugarImports modules = do
137− let modules' = importPrelude `map` modules
138− unfilteredExports <- findExports modules'
139− exports <- foldM filterModuleExports unfilteredExports modules'
140− mapM (renameInModule' unfilteredExports exports) modules'
137+ unfilteredExports <- findExports modules
138+ exports <- foldM filterModuleExports unfilteredExports modules
139+ mapM (renameInModule' unfilteredExports exports) modules
141140 where
142141
143142 -- Filters the exports for a module in the global exports environment so that only explicitly
@@ -156,19 +155,6 @@ desugarImports modules = do
156155 imports <- resolveImports env m
157156 renameInModule imports env (elaborateExports exps m)
158157
159−-- |
160−-- Add an import declaration for the Prelude to a module if it does not already explicitly import
161−-- it.
162−--
163−importPrelude :: Module -> Module
164−importPrelude m@(Module mn decls exps) =
165− if isPreludeImport `any` decls then m
166− else Module mn (preludeImport : decls) exps
167− where
168− isPreludeImport (ImportDeclaration (ModuleName [ProperName "Prelude"]) _ _) = True
169− isPreludeImport _ = False
170− preludeImport = ImportDeclaration (ModuleName [ProperName "Prelude"]) Nothing Nothing
171−
172158-- |
173159-- Rethrow an error with the name of the current module in the case of a failure
174160--