git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Declare all top-level values in header (for circular deps)
commite34cc85a8aa7157c639c43788fc190c8a389a18c authorAndy Arvanitis <andyarvanitis@gmail.com> dateWed 10 Oct 2018, 18:31 (8 years ago) parentff82c9e
2 files changed+13−14
src/CodeGen/Cpp.hs+8−9 src/CodeGen/Cpp/Printer.hs+5−5
src/CodeGen/Cpp.hs+8−9
@@ -50,7 +50,7 @@ moduleToCpp
5050 => Module Ann
5151 -> Maybe AST
5252 -> m (Text, [Text], [AST], Text, Text)
53−moduleToCpp (Module _ coms mn _ imps exports foreigns decls) _ =
53+moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
5454 do
5555 let usedNames = concatMap getNames decls
5656 let mnLookup = renameImports usedNames imps
@@ -60,9 +60,9 @@ moduleToCpp (Module _ coms mn _ imps exports foreigns decls) _ =
6060 cppDecls <- mapM (bindToCpp ModuleDecl) decls'
6161 optimized <- traverse (traverse (optimize modName')) cppDecls
6262 let optimized' = concat optimized
63− exports' = mapMaybe (export $ identToCpp <$> exports) optimized'
63+ values = annotValue <$> optimized'
6464 foreigns' = identToCpp <$> foreigns
65− interface = interfaceSource modName exports' foreigns
65+ interface = interfaceSource modName values foreigns
6666 implHeader = implHeaderSource modName cppImports interfaceImport
6767 implFooter = implFooterSource modName foreigns
6868 return $ (interface, foreigns', optimized', implHeader, implFooter)
@@ -70,12 +70,11 @@ moduleToCpp (Module _ coms mn _ imps exports foreigns decls) _ =
7070 modName = moduleNameToCpp mn
7171 modName' = AST.Var Nothing modName
7272
73− export :: [Text] -> AST -> Maybe (Text, Bool)
74− export names (AST.Function _ (Just name) [] (AST.Block _ [AST.Return _ ret]))
75− | name `elem` names && isLiteral ret = Just (name, True)
76− export names (AST.Function _ (Just name) [] _)
77− | name `elem` names = Just (name, False)
78− export _ _ = Nothing
73+ annotValue :: AST -> (Text, Bool)
74+ annotValue (AST.Function _ (Just name) [] (AST.Block _ [AST.Return _ ret]))
75+ | isLiteral ret = (name, True)
76+ annotValue (AST.Function _ (Just name) [] _) = (name, False)
77+ annotValue _ = error "Unexpected top-level value form"
7978
8079 -- | Extracts all declaration names from a binding group.
8180 getNames :: Bind Ann -> [Ident]
src/CodeGen/Cpp/Printer.hs+5−5
@@ -429,11 +429,11 @@ renderOp op
429429 | otherwise = Nothing
430430
431431interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text
432−interfaceSource mn exports foreigns =
432+interfaceSource mn values foreigns =
433433 let foreigns' = identToCpp <$> foreigns
434− exportNames = fst <$> exports
435− exports' = filter ((`notElem` foreigns') . fst) exports ++
436− zip (foreigns' \\ exportNames) (repeat True)
434+ valueNames = fst <$> values
435+ values' = filter ((`notElem` foreigns') . fst) values ++
436+ zip (foreigns' \\ valueNames) (repeat True)
437437 in
438438 "// Generated by pscpp compiler\n\n" <>
439439 "#ifndef " <> mn <> "_H\n" <>
@@ -443,7 +443,7 @@ interfaceSource mn exports foreigns =
443443 "using namespace purescript;\n\n" <>
444444 (T.concat $ (\(export, static) ->
445445 let rty = if static then "const boxed&" else "boxed" in
446− "auto " <> export <> "() -> " <> rty <> ";\n") <$> exports') <> "\n" <>
446+ "auto " <> export <> "() -> " <> rty <> ";\n") <$> values') <> "\n" <>
447447 "} // end namespace " <> mn <> "\n\n" <>
448448 "#endif // " <> mn <> "_H\n\n"
449449