git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove special underscores; adjust unused arg handling
commitb5707f32614e38cea0b4450c202304dbdd3e5485 authorAndy Arvanitis <andyarvanitis@gmail.com> dateWed 22 Aug 2018, 22:40 (8 years ago) parent9ec7bf4
4 files changed+24−26
app/Main.hs+1−8 src/CodeGen/Cpp/Common.hs+3−6 src/CodeGen/Cpp/Optimizer/TCO.hs+4−4 src/CodeGen/Cpp/Printer.hs+16−8
app/Main.hs+1−8
@@ -103,7 +103,7 @@ transpile opts jsonFile = do
103103 where
104104 conv :: Text -> Text
105105 conv
106− | "--ucns" `elem` opts = toUCNs . toDollars
106+ | "--ucns" `elem` opts = toUCNs
107107 | otherwise = id
108108
109109outdir :: FilePath
@@ -128,10 +128,3 @@ toUCNs = T.pack . concatMap toUCN . T.unpack
128128toUCN :: Char -> String
129129toUCN c | isAscii c = [c]
130130toUCN 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
1414moduleNameToCpp :: ModuleName -> Text
1515moduleNameToCpp (ModuleName pns) =
1616 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
1818
1919-- | Convert an 'Ident' into a valid C++ identifier:
2020--
@@ -30,7 +30,7 @@ identToCpp (Ident name) = properToCpp name
3030identToCpp (GenIdent _ _) = internalError "GenIdent in identToCpp"
3131
3232unusedName :: Text
33−unusedName = "__unused_"
33+unusedName = "$unused$"
3434
3535properToCpp :: Text -> Text
3636properToCpp name
@@ -192,8 +192,5 @@ cppLiterals =
192192 , "unbox"
193193 ]
194194
195−unretainedSuffix :: Text
196−unretainedSuffix = "_unretained"
197−
198195tcoLoop :: 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
1515tco :: AST -> AST
1616tco = everywhere convert where
1717 tcoVar :: Text -> Text
18− tcoVar arg = "_TCO_" <> arg <> "_"
18+ tcoVar arg = "$TCO_" <> arg <> "$"
1919
2020 copyVar :: Text -> Text
21− copyVar arg = "_TCO_copy_" <> arg <> "_"
21+ copyVar arg = "$TCO_copy_" <> arg <> "$"
2222
2323 tcoDone :: Text
24− tcoDone = "_TCO_done_"
24+ tcoDone = "$TCO_done$"
2525
2626 tcoResult :: Text
27− tcoResult = "_TCO_result_"
27+ tcoResult = "$TCO_result$"
2828
2929 convert :: AST -> AST
3030 convert fn@(Function ss (Just name) args _)
src/CodeGen/Cpp/Printer.hs+16−8
@@ -87,7 +87,7 @@ literals = mkPattern' match'
8787 , prettyPrintCpp' target
8888 , return $ emit "]"
8989 , return $ emit "("
90− , return $ emit $ intercalate ", " (("const boxed& " <>) <$> args)
90+ , return $ emit $ intercalate ", " (renderArg <$> args)
9191 , return $ emit ") -> boxed "
9292 , prettyPrintCpp' body
9393 ]
@@ -169,7 +169,7 @@ literals = mkPattern' match'
169169 match (Function _ name args ret) = mconcat <$> sequence
170170 [ return $ emit $ if name == (Just tcoLoop) then "[&]" else "[=]"
171171 , return $ emit "("
172− , return $ emit $ intercalate ", " (("const boxed& " <>) <$> args)
172+ , return $ emit $ intercalate ", " (renderArg <$> args)
173173 , return $ emit ") -> boxed "
174174 , prettyPrintCpp' ret
175175 ]
@@ -454,7 +454,7 @@ interfaceSource mn exports foreigns =
454454 (if null foreigns then "" else ("// Foreign values\n\nauto " <> foreignDict <> "() -> " <> dictType <> "&;\n\n")) <>
455455 (T.concat $ (\foreign' -> "inline auto " <>
456456 identToCpp foreign' <>
457− "() -> const boxed& { " <>
457+ "() -> " <> varDecl <> " { " <>
458458 dispatchOnceBegin <>
459459 foreignDict <> "().at(" <>
460460 (stringLiteral . mkString $ runIdent foreign') <> "); " <>
@@ -475,8 +475,8 @@ implFooterSource :: Text -> [Ident] -> Text
475475implFooterSource mn foreigns =
476476 "\n\n" <>
477477 (if null foreigns then "" else ("auto " <> foreignDict <> "() -> " <> dictType <> "& {\n" <>
478− " static " <> dictType <> " _dict_;\n" <>
479− " return _dict_;\n" <>
478+ " static " <> dictType <> " $dict$;\n" <>
479+ " return $dict$;\n" <>
480480 "}\n\n")) <>
481481 "} // end namespace " <> mn <>
482482 "\n\n" <>
@@ -485,7 +485,7 @@ implFooterSource mn foreigns =
485485 mainSource :: Text
486486 mainSource = "\
487487 \int main(int argc, const char * argv[]) {\n\
488− \ Main::main()(nullptr);\n\
488+ \ Main::main()();\n\
489489 \ return 0;\n\
490490 \}\n\n\
491491 \"
@@ -508,11 +508,19 @@ bool = "bool"
508508string :: Text
509509string = "string"
510510
511+varDecl :: Text
512+varDecl = "const boxed&"
513+
514+renderArg :: Text -> Text
515+renderArg arg
516+ | arg == unusedName = varDecl
517+ | otherwise = varDecl <> " " <> arg
518+
511519foreignDict :: Text
512520foreignDict = "foreign"
513521
514522dispatchOnceBegin :: Text
515−dispatchOnceBegin = "static const boxed _value_ = "
523+dispatchOnceBegin = "static const boxed $value$ = "
516524
517525dispatchOnceEnd :: Text
518−dispatchOnceEnd = "return _value_;"
526+dispatchOnceEnd = "return $value$;"