git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Look for runtime identifier conflicts - fixesi issue #38
commitbc8ddad20c69eff932137c5ac3b9a56adb131bc0 authorAndy Arvanitis <andyarvanitis@gmail.com> dateMon 2 Sep 2019, 15:17 (7 years ago) parent907dd3f
3 files changed+19−5
src/CodeGen/IL.hs+3−1 src/CodeGen/IL/Common.hs+15−2 src/CodeGen/IL/Printer.hs+1−2
src/CodeGen/IL.hs+3−1
@@ -107,8 +107,10 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) project =
107107 importToIL = AST.everything (++) modRef
108108 where
109109 modRef (AST.Indexer _ (AST.Var _ _) (AST.Var _ mname))
110− | not $ T.null mname = [mname]
110+ | not $ T.null mname = [extract mname]
111111 modRef _ = []
112+ extract :: Text -> Text
113+ extract = T.replace "_" "." . T.dropWhileEnd (=='_')
112114
113115 -- | Replaces the `ModuleName`s in the AST so that the generated code refers to
114116 -- the collision-avoiding renamed module imports.
src/CodeGen/IL/Common.hs+15−2
@@ -16,7 +16,9 @@ import Language.PureScript.Names
1616import qualified Language.PureScript.Constants as C
1717
1818moduleNameToIL :: ModuleName -> Text
19−moduleNameToIL (ModuleName pns) = T.intercalate "_" (runProperName `map` pns)
19+moduleNameToIL (ModuleName pns) =
20+ let name = T.intercalate "_" (runProperName `map` pns)
21+ in if nameIsILBuiltIn name then (name <> "_") else name
2022
2123moduleNameToIL' :: ModuleName -> Text
2224moduleNameToIL' (ModuleName pns) = T.intercalate "." (runProperName `map` pns)
@@ -71,7 +73,18 @@ nameIsILReserved name =
7173nameIsILBuiltIn :: Text -> Bool
7274nameIsILBuiltIn name =
7375 name `elem`
74− [
76+ [ "Any"
77+ , "Apply"
78+ , "Contains"
79+ , "Dict"
80+ , "EffFn"
81+ , "Fn"
82+ , "Foreign"
83+ , "Get"
84+ , "Length"
85+ , "Once"
86+ , "Run"
87+ , "Undefined"
7588 ]
7689
7790ilAnyReserved :: [Text]
src/CodeGen/IL/Printer.hs+1−2
@@ -442,7 +442,6 @@ interfaceSource _ _ _ = ""
442442
443443implHeaderSource :: Text -> [Text] -> Text -> Text
444444implHeaderSource mn imports otherPrefix =
445− let imports' = T.replace "_" "." <$> imports in
446445 "// Code generated by psgo. DO NOT EDIT.\n\n" <>
447446 "package " <> (if mn == "Main" then "main" else mn) <> "\n\n" <>
448447 "import . \"" <> runtime <> "\"\n" <>
@@ -450,7 +449,7 @@ implHeaderSource mn imports otherPrefix =
450449 then "import _ \"" <> otherPrefix <> "/" <> ffiLoader <> "\"\n"
451450 else "\n") <>
452451 "import (\n" <>
453− (T.concat $ formatImport <$> imports') <> ")\n\n" <>
452+ (T.concat $ formatImport <$> imports) <> ")\n\n" <>
454453 "type _ = Any\n\n"
455454 where
456455 formatImport :: Text -> Text