Permalink
Browse files

Fix Maybe hack (refs #134).

  • Loading branch information...
chrisdone committed Oct 30, 2012
1 parent c1ba127 commit 85e5a4350aeef597a5e3318c2209bc96436828e1
Showing with 9 additions and 6 deletions.
  1. +3 −4 src/Language/Fay.hs
  2. +6 −2 src/Language/Fay/Compiler.hs
View
@@ -66,16 +66,15 @@ compileFromToAndGenerateHtml config filein fileout = do
compileFile :: CompileConfig -> FilePath -> IO (Either CompileError String)
compileFile config filein = do
runtime <- getDataFileName "js/runtime.js"
- stdlibpath <- getDataFileName "hs/stdlib.hs"
srcdir <- fmap (takeDirectory . takeDirectory . takeDirectory) (getDataFileName "src/Language/Fay/Stdlib.hs")
raw <- readFile runtime
- stdlib <- readFile stdlibpath
hscode <- readFile filein
compileToModule filein
- config { configDirectoryIncludes = configDirectoryIncludes config ++ [srcdir] }
+ config { configDirectoryIncludes = configDirectoryIncludes config ++ [srcdir]
+ }
raw
compileToplevelModule
- (hscode ++ "\n" ++ stdlib)
+ hscode
-- | Compile the given module to a runnable module.
compileToModule :: (Show from,Show to,CompilesTo from to)
@@ -243,18 +243,22 @@ warn w = do
instance CompilesTo Module [JsStmt] where compileTo = compileModule
findImport :: [FilePath] -> ModuleName -> Compile (FilePath,String)
-findImport alldirs = go alldirs where
+findImport alldirs mname = go alldirs mname where
go (dir:dirs) name = do
exists <- io (doesFileExist path)
if exists
- then fmap (path,) (io (readFile path))
+ then fmap (path,) (fmap stdlibHack (io (readFile path)))
else go dirs name
where
path = dir </> replace '.' '/' (prettyPrint name) ++ ".hs"
replace c r = map (\x -> if x == c then r else x)
go [] name =
throwError $ Couldn'tFindImport name alldirs
+ stdlibHack
+ | mname == ModuleName "Language.Fay.Stdlib" = \s -> s ++ "\n\ndata Maybe a = Just a | Nothing"
+ | otherwise = id
+
-- | Compile the given import.
compileImport :: ImportDecl -> Compile [JsStmt]
compileImport (ImportDecl _ "Prelude" _ _ _ _ _) = return []

0 comments on commit 85e5a43

Please sign in to comment.