Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.

Commit

Permalink
ffiCodegen - erl
Browse files Browse the repository at this point in the history
  • Loading branch information
nwolverson committed Nov 28, 2018
1 parent bd1be11 commit 756db33
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Language/PureScript/Make/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,17 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
let mn = CF.moduleName m
foreignExports <- lift $ case mn `M.lookup` foreigns of
Just path
| not $ requiresForeign m -> do
tell $ errorMessage $ UnnecessaryFFIModule mn path
| not $ requiresForeign m ->
return []
| otherwise -> getForeigns path
Nothing -> do
when (requiresForeign m) $ throwError . errorMessage $ MissingFFIModule mn
Nothing ->
return []

(exports, rawErl) <- E.moduleToErl env m foreignExports foreignTypes
let pretty = prettyPrintErl rawErl
let moduleDir = outputDir </> T.unpack (runModuleName mn)
outFile = moduleDir </> T.unpack (erlModuleName mn PureScriptModule) ++ ".erl"
externsFile = moduleDir </> "externs.json"
foreignFile = moduleDir </> T.unpack (erlModuleName mn ForeignModule) ++ ".erl"
prefix :: [Text]
prefix = ["Generated by purs version " <> T.pack (showVersion Paths.version) | usePrefix]
directives :: [Text]
Expand All @@ -185,7 +182,6 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
let erl :: Text = T.unlines $ map ("% " <>) prefix ++ directives ++ [ pretty ]
lift $ do
writeTextFile outFile $ B.fromStrict $ TE.encodeUtf8 erl
for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
writeTextFile externsFile exts

getForeigns :: String -> Make [(Text, Int)]
Expand Down Expand Up @@ -240,6 +236,18 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
Nothing | requiresForeign m -> throwError . errorMessage' (CF.moduleSourceSpan m) $ MissingFFIModule mn
| otherwise -> return ()
for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
when (S.member Erl codegenTargets) $ do
let mn = CF.moduleName m
moduleDir = outputDir </> T.unpack (runModuleName mn)
foreignFile = moduleDir </> T.unpack (erlModuleName mn ForeignModule) ++ ".erl"
case mn `M.lookup` foreigns of
Just path
| not $ requiresForeign m ->
tell $ errorMessage $ UnnecessaryFFIModule mn path
| otherwise -> pure ()
Nothing -> do
when (requiresForeign m) $ throwError . errorMessage $ MissingFFIModule mn
for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)

genSourceMap :: String -> String -> Int -> [SMap] -> Make ()
genSourceMap dir mapFile extraLines mappings = do
Expand Down

0 comments on commit 756db33

Please sign in to comment.