git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove special underscores; adjust unused arg handling
b5707f3Andy Arvanitis
app/Main.hs+1−8
@@ -103,7 +103,7 @@ transpile opts jsonFile = do
103 where
103 where
104 conv :: Text -> Text
104 conv :: Text -> Text
105 conv
105 conv
106− | "--ucns" `elem` opts = toUCNs . toDollars
106+ | "--ucns" `elem` opts = toUCNs
107 | otherwise = id
107 | otherwise = id
108
108
109outdir :: FilePath
109outdir :: FilePath
@@ -128,10 +128,3 @@ toUCNs = T.pack . concatMap toUCN . T.unpack
128toUCN :: Char -> String
128toUCN :: Char -> String
129toUCN c | isAscii c = [c]
129toUCN c | isAscii c = [c]
130toUCN c = printf "\\U%08x" $ ord c
130toUCN c = printf "\\U%08x" $ ord c
131−
132−toDollars :: Text -> Text
133−toDollars = T.map toDollar
134−
135−toDollar :: Char -> Char
136−toDollar '_' = '$'
137−toDollar c = c
src/CodeGen/Cpp/Common.hs+3−6
@@ -14,7 +14,7 @@ import Language.PureScript.Names
14moduleNameToCpp :: ModuleName -> Text
14moduleNameToCpp :: ModuleName -> Text
15moduleNameToCpp (ModuleName pns) =
15moduleNameToCpp (ModuleName pns) =
16 let name = T.intercalate "_" (runProperName `map` pns)
16 let name = T.intercalate "_" (runProperName `map` pns)
17− in if nameIsCppBuiltIn name then "_" <> name else name
17+ in if nameIsCppBuiltIn name then ("$" <> name <> "$") else name
18
18
19-- | Convert an 'Ident' into a valid C++ identifier:
19-- | Convert an 'Ident' into a valid C++ identifier:
20--
20--
@@ -30,7 +30,7 @@ identToCpp (Ident name) = properToCpp name
30identToCpp (GenIdent _ _) = internalError "GenIdent in identToCpp"
30identToCpp (GenIdent _ _) = internalError "GenIdent in identToCpp"
31
31
32unusedName :: Text
32unusedName :: Text
33−unusedName = "__unused_"
33+unusedName = "$unused$"
34
34
35properToCpp :: Text -> Text
35properToCpp :: Text -> Text
36properToCpp name
36properToCpp name
@@ -192,8 +192,5 @@ cppLiterals =
192 , "unbox"
192 , "unbox"
193 ]
193 ]
194
194
195−unretainedSuffix :: Text
196−unretainedSuffix = "_unretained"
197−
198tcoLoop :: Text
195tcoLoop :: Text
199−tcoLoop = "_TCO_loop_"
196+tcoLoop = "$TCO_loop$"
src/CodeGen/Cpp/Optimizer/TCO.hs+4−4
@@ -15,16 +15,16 @@ import qualified Language.PureScript.Constants as C
15tco :: AST -> AST
15tco :: AST -> AST
16tco = everywhere convert where
16tco = everywhere convert where
17 tcoVar :: Text -> Text
17 tcoVar :: Text -> Text
18− tcoVar arg = "_TCO_" <> arg <> "_"
18+ tcoVar arg = "$TCO_" <> arg <> "$"
19
19
20 copyVar :: Text -> Text
20 copyVar :: Text -> Text
21− copyVar arg = "_TCO_copy_" <> arg <> "_"
21+ copyVar arg = "$TCO_copy_" <> arg <> "$"
22
22
23 tcoDone :: Text
23 tcoDone :: Text
24− tcoDone = "_TCO_done_"
24+ tcoDone = "$TCO_done$"
25
25
26 tcoResult :: Text
26 tcoResult :: Text
27− tcoResult = "_TCO_result_"
27+ tcoResult = "$TCO_result$"
28
28
29 convert :: AST -> AST
29 convert :: AST -> AST
30 convert fn@(Function ss (Just name) args _)
30 convert fn@(Function ss (Just name) args _)
src/CodeGen/Cpp/Printer.hs+16−8
@@ -87,7 +87,7 @@ literals = mkPattern' match'
87 , prettyPrintCpp' target
87 , prettyPrintCpp' target
88 , return $ emit "]"
88 , return $ emit "]"
89 , return $ emit "("
89 , return $ emit "("
90− , return $ emit $ intercalate ", " (("const boxed& " <>) <$> args)
90+ , return $ emit $ intercalate ", " (renderArg <$> args)
91 , return $ emit ") -> boxed "
91 , return $ emit ") -> boxed "
92 , prettyPrintCpp' body
92 , prettyPrintCpp' body
93 ]
93 ]
@@ -169,7 +169,7 @@ literals = mkPattern' match'
169 match (Function _ name args ret) = mconcat <$> sequence
169 match (Function _ name args ret) = mconcat <$> sequence
170 [ return $ emit $ if name == (Just tcoLoop) then "[&]" else "[=]"
170 [ return $ emit $ if name == (Just tcoLoop) then "[&]" else "[=]"
171 , return $ emit "("
171 , return $ emit "("
172− , return $ emit $ intercalate ", " (("const boxed& " <>) <$> args)
172+ , return $ emit $ intercalate ", " (renderArg <$> args)
173 , return $ emit ") -> boxed "
173 , return $ emit ") -> boxed "
174 , prettyPrintCpp' ret
174 , prettyPrintCpp' ret
175 ]
175 ]
@@ -454,7 +454,7 @@ interfaceSource mn exports foreigns =
454 (if null foreigns then "" else ("// Foreign values\n\nauto " <> foreignDict <> "() -> " <> dictType <> "&;\n\n")) <>
454 (if null foreigns then "" else ("// Foreign values\n\nauto " <> foreignDict <> "() -> " <> dictType <> "&;\n\n")) <>
455 (T.concat $ (\foreign' -> "inline auto " <>
455 (T.concat $ (\foreign' -> "inline auto " <>
456 identToCpp foreign' <>
456 identToCpp foreign' <>
457− "() -> const boxed& { " <>
457+ "() -> " <> varDecl <> " { " <>
458 dispatchOnceBegin <>
458 dispatchOnceBegin <>
459 foreignDict <> "().at(" <>
459 foreignDict <> "().at(" <>
460 (stringLiteral . mkString $ runIdent foreign') <> "); " <>
460 (stringLiteral . mkString $ runIdent foreign') <> "); " <>
@@ -475,8 +475,8 @@ implFooterSource :: Text -> [Ident] -> Text
475implFooterSource mn foreigns =
475implFooterSource mn foreigns =
476 "\n\n" <>
476 "\n\n" <>
477 (if null foreigns then "" else ("auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
477 (if null foreigns then "" else ("auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
478− " static " <> dictType <> " _dict_;\n" <>
478+ " static " <> dictType <> " $dict$;\n" <>
479− " return _dict_;\n" <>
479+ " return $dict$;\n" <>
480 "}\n\n")) <>
480 "}\n\n")) <>
481 "} // end namespace " <> mn <>
481 "} // end namespace " <> mn <>
482 "\n\n" <>
482 "\n\n" <>
@@ -485,7 +485,7 @@ implFooterSource mn foreigns =
485 mainSource :: Text
485 mainSource :: Text
486 mainSource = "\
486 mainSource = "\
487 \int main(int argc, const char * argv[]) {\n\
487 \int main(int argc, const char * argv[]) {\n\
488− \ Main::main()(nullptr);\n\
488+ \ Main::main()();\n\
489 \ return 0;\n\
489 \ return 0;\n\
490 \}\n\n\
490 \}\n\n\
491 \"
491 \"
@@ -508,11 +508,19 @@ bool = "bool"
508string :: Text
508string :: Text
509string = "string"
509string = "string"
510
510
511+varDecl :: Text
512+varDecl = "const boxed&"
513+
514+renderArg :: Text -> Text
515+renderArg arg
516+ | arg == unusedName = varDecl
517+ | otherwise = varDecl <> " " <> arg
518+
511foreignDict :: Text
519foreignDict :: Text
512foreignDict = "foreign"
520foreignDict = "foreign"
513
521
514dispatchOnceBegin :: Text
522dispatchOnceBegin :: Text
515−dispatchOnceBegin = "static const boxed _value_ = "
523+dispatchOnceBegin = "static const boxed $value$ = "
516
524
517dispatchOnceEnd :: Text
525dispatchOnceEnd :: Text
518−dispatchOnceEnd = "return _value_;"
526+dispatchOnceEnd = "return $value$;"