git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use inlines for foreign dict accessor -- tolerate unneeded ffi impls
ea8164dAndy Arvanitis
runtime/purescript.h+7−1
@@ -172,9 +172,15 @@ namespace purescript {
172
172
173} // namespace purescript
173} // namespace purescript
174
174
175+#define DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR() \
176+ inline auto foreign() -> dict_t& {\
177+ static dict_t $dict$;\
178+ return $dict$;\
179+ }
180+
175#define FOREIGN_BEGIN(NS) namespace NS {\
181#define FOREIGN_BEGIN(NS) namespace NS {\
176 using namespace purescript;\
182 using namespace purescript;\
177− auto foreign() -> dict_t&;\
183+ DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR()\
178 static const auto& NS ## $foreign_init = []() {\
184 static const auto& NS ## $foreign_init = []() {\
179 dict_t& exports = foreign();
185 dict_t& exports = foreign();
180#define FOREIGN_END return exports; }(); }
186#define FOREIGN_END return exports; }(); }
src/CodeGen/Cpp/Printer.hs+1−4
@@ -459,10 +459,7 @@ implFooterSource mn foreigns =
459 (if null foreigns
459 (if null foreigns
460 then ""
460 then ""
461 else ("// Foreign values\n\n" <>
461 else ("// Foreign values\n\n" <>
462− "auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
462+ "DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR()\n\n" <>
463− " static " <> dictType <> " $dict$;\n" <>
464− " return $dict$;\n" <>
465− "}\n\n" <>
466 (T.concat $ (\foreign' -> "auto " <>
463 (T.concat $ (\foreign' -> "auto " <>
467 identToCpp foreign' <>
464 identToCpp foreign' <>
468 "() -> const boxed& { " <>
465 "() -> const boxed& { " <>