git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve foreign accessors -- get rid of inline functions
commitaa476343facb79b10a8d73cb2fee4244adb3d9dc authorAndy Arvanitis <andyarvanitis@gmail.com> dateFri 28 Sep 2018, 17:27 (8 years ago) parent80bcb4a
1 file changed+25−23
src/CodeGen/Cpp/Printer.hs+25−23
src/CodeGen/Cpp/Printer.hs+25−23
@@ -16,7 +16,7 @@ import Control.Monad (forM, mzero)
1616import Control.Monad.State (StateT, evalStateT)
1717import Control.PatternArrows
1818import Data.Char (isAscii)
19−import Data.List (filter)
19+import Data.List (filter, (\\))
2020import qualified Control.Arrow as A
2121
2222import Data.Maybe (fromMaybe)
@@ -431,30 +431,20 @@ renderOp op
431431interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text
432432interfaceSource mn exports foreigns =
433433 let foreigns' = identToCpp <$> foreigns
434− exports' = filter ((`notElem` foreigns') . fst) exports in
434+ exportNames = fst <$> exports
435+ exports' = filter ((`notElem` foreigns') . fst) exports ++
436+ zip (foreigns' \\ exportNames) (repeat True)
437+ in
435438 "// Generated by pscpp compiler\n\n" <>
436439 "#ifndef " <> mn <> "_H\n" <>
437440 "#define " <> mn <> "_H\n\n" <>
438− "#include \"purescript.h\"\n" <>
439− "\n" <>
441+ "#include \"purescript.h\"\n\n" <>
440442 "namespace " <> mn <> " {\n\n" <>
441443 "using namespace purescript;\n\n" <>
442444 (T.concat $ (\(export, static) ->
443445 let rty = if static then "const boxed&" else "boxed" in
444− "auto " <> export <> "() -> " <> rty <> ";\n") <$> exports') <>
445− "\n" <>
446− (if null foreigns then "" else ("// Foreign values\n\nauto " <> foreignDict <> "() -> " <> dictType <> "&;\n\n")) <>
447− (T.concat $ (\foreign' -> "inline auto " <>
448− identToCpp foreign' <>
449− "() -> const boxed& { " <>
450− staticValueBegin <>
451− foreignDict <> "().at(" <>
452− (stringLiteral . mkString $ runIdent foreign') <> "); " <>
453− staticValueEnd <>
454− " };\n") <$> foreigns) <>
455− "\n" <>
456− "} // end namespace " <> mn <>
457− "\n\n" <>
446+ "auto " <> export <> "() -> " <> rty <> ";\n") <$> exports') <> "\n" <>
447+ "} // end namespace " <> mn <> "\n\n" <>
458448 "#endif // " <> mn <> "_H\n\n"
459449
460450implHeaderSource :: Text -> [Text] -> Text -> Text
@@ -465,11 +455,23 @@ implHeaderSource mn imports interfaceImport =
465455
466456implFooterSource :: Text -> [Ident] -> Text
467457implFooterSource mn foreigns =
468− "\n\n" <>
469− (if null foreigns then "" else ("auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
470− " static " <> dictType <> " $dict$;\n" <>
471− " return $dict$;\n" <>
472− "}\n\n")) <>
458+ "\n\n\n" <>
459+ (if null foreigns
460+ then ""
461+ else ("// Foreign values\n\n" <>
462+ "auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
463+ " static " <> dictType <> " $dict$;\n" <>
464+ " return $dict$;\n" <>
465+ "}\n\n" <>
466+ (T.concat $ (\foreign' -> "auto " <>
467+ identToCpp foreign' <>
468+ "() -> const boxed& { " <>
469+ staticValueBegin <>
470+ foreignDict <> "().at(" <>
471+ (stringLiteral . mkString $ runIdent foreign') <> "); " <>
472+ staticValueEnd <>
473+ " };\n") <$> foreigns) <>
474+ "\n")) <>
473475 "} // end namespace " <> mn <>
474476 "\n\n" <>
475477 if mn == "Main" then mainSource else "\n"