git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use inlines for foreign dict accessor -- tolerate unneeded ffi impls
commitea8164d680270f8e50c799d7bf5d883d7fe4813b authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 30 Sep 2018, 13:50 (8 years ago) parent90fcee2
2 files changed+8−5
runtime/purescript.h+7−1 src/CodeGen/Cpp/Printer.hs+1−4
runtime/purescript.h+7−1
@@ -172,9 +172,15 @@ namespace purescript {
172172
173173} // namespace purescript
174174
175+#define DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR() \
176+ inline auto foreign() -> dict_t& {\
177+ static dict_t $dict$;\
178+ return $dict$;\
179+ }
180+
175181#define FOREIGN_BEGIN(NS) namespace NS {\
176182 using namespace purescript;\
177− auto foreign() -> dict_t&;\
183+ DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR()\
178184 static const auto& NS ## $foreign_init = []() {\
179185 dict_t& exports = foreign();
180186#define FOREIGN_END return exports; }(); }
src/CodeGen/Cpp/Printer.hs+1−4
@@ -459,10 +459,7 @@ implFooterSource mn foreigns =
459459 (if null foreigns
460460 then ""
461461 else ("// Foreign values\n\n" <>
462− "auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
463− " static " <> dictType <> " $dict$;\n" <>
464− " return $dict$;\n" <>
465− "}\n\n" <>
462+ "DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR()\n\n" <>
466463 (T.concat $ (\foreign' -> "auto " <>
467464 identToCpp foreign' <>
468465 "() -> const boxed& { " <>