git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Declare all top-level values in header (for circular deps)
e34cc85Andy Arvanitis
src/CodeGen/Cpp.hs+8−9
@@ -50,7 +50,7 @@ moduleToCpp
50 => Module Ann
50 => Module Ann
51 -> Maybe AST
51 -> Maybe AST
52 -> m (Text, [Text], [AST], Text, Text)
52 -> m (Text, [Text], [AST], Text, Text)
53−moduleToCpp (Module _ coms mn _ imps exports foreigns decls) _ =
53+moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
54 do
54 do
55 let usedNames = concatMap getNames decls
55 let usedNames = concatMap getNames decls
56 let mnLookup = renameImports usedNames imps
56 let mnLookup = renameImports usedNames imps
@@ -60,9 +60,9 @@ moduleToCpp (Module _ coms mn _ imps exports foreigns decls) _ =
60 cppDecls <- mapM (bindToCpp ModuleDecl) decls'
60 cppDecls <- mapM (bindToCpp ModuleDecl) decls'
61 optimized <- traverse (traverse (optimize modName')) cppDecls
61 optimized <- traverse (traverse (optimize modName')) cppDecls
62 let optimized' = concat optimized
62 let optimized' = concat optimized
63− exports' = mapMaybe (export $ identToCpp <$> exports) optimized'
63+ values = annotValue <$> optimized'
64 foreigns' = identToCpp <$> foreigns
64 foreigns' = identToCpp <$> foreigns
65− interface = interfaceSource modName exports' foreigns
65+ interface = interfaceSource modName values foreigns
66 implHeader = implHeaderSource modName cppImports interfaceImport
66 implHeader = implHeaderSource modName cppImports interfaceImport
67 implFooter = implFooterSource modName foreigns
67 implFooter = implFooterSource modName foreigns
68 return $ (interface, foreigns', optimized', implHeader, implFooter)
68 return $ (interface, foreigns', optimized', implHeader, implFooter)
@@ -70,12 +70,11 @@ moduleToCpp (Module _ coms mn _ imps exports foreigns decls) _ =
70 modName = moduleNameToCpp mn
70 modName = moduleNameToCpp mn
71 modName' = AST.Var Nothing modName
71 modName' = AST.Var Nothing modName
72
72
73− export :: [Text] -> AST -> Maybe (Text, Bool)
73+ annotValue :: AST -> (Text, Bool)
74− export names (AST.Function _ (Just name) [] (AST.Block _ [AST.Return _ ret]))
74+ annotValue (AST.Function _ (Just name) [] (AST.Block _ [AST.Return _ ret]))
75− | name `elem` names && isLiteral ret = Just (name, True)
75+ | isLiteral ret = (name, True)
76− export names (AST.Function _ (Just name) [] _)
76+ annotValue (AST.Function _ (Just name) [] _) = (name, False)
77− | name `elem` names = Just (name, False)
77+ annotValue _ = error "Unexpected top-level value form"
78− export _ _ = Nothing
79
78
80 -- | Extracts all declaration names from a binding group.
79 -- | Extracts all declaration names from a binding group.
81 getNames :: Bind Ann -> [Ident]
80 getNames :: Bind Ann -> [Ident]
src/CodeGen/Cpp/Printer.hs+5−5
@@ -429,11 +429,11 @@ renderOp op
429 | otherwise = Nothing
429 | otherwise = Nothing
430
430
431interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text
431interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text
432−interfaceSource mn exports foreigns =
432+interfaceSource mn values foreigns =
433 let foreigns' = identToCpp <$> foreigns
433 let foreigns' = identToCpp <$> foreigns
434− exportNames = fst <$> exports
434+ valueNames = fst <$> values
435− exports' = filter ((`notElem` foreigns') . fst) exports ++
435+ values' = filter ((`notElem` foreigns') . fst) values ++
436− zip (foreigns' \\ exportNames) (repeat True)
436+ zip (foreigns' \\ valueNames) (repeat True)
437 in
437 in
438 "// Generated by pscpp compiler\n\n" <>
438 "// Generated by pscpp compiler\n\n" <>
439 "#ifndef " <> mn <> "_H\n" <>
439 "#ifndef " <> mn <> "_H\n" <>
@@ -443,7 +443,7 @@ interfaceSource mn exports foreigns =
443 "using namespace purescript;\n\n" <>
443 "using namespace purescript;\n\n" <>
444 (T.concat $ (\(export, static) ->
444 (T.concat $ (\(export, static) ->
445 let rty = if static then "const boxed&" else "boxed" in
445 let rty = if static then "const boxed&" else "boxed" in
446− "auto " <> export <> "() -> " <> rty <> ";\n") <$> exports') <> "\n" <>
446+ "auto " <> export <> "() -> " <> rty <> ";\n") <$> values') <> "\n" <>
447 "} // end namespace " <> mn <> "\n\n" <>
447 "} // end namespace " <> mn <> "\n\n" <>
448 "#endif // " <> mn <> "_H\n\n"
448 "#endif // " <> mn <> "_H\n\n"
449
449