git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix some TCO cases; more generated names changes
commitbb9e116b9a6e6f41d7c7b60a8d687bb8fd078eb8 authorAndy Arvanitis <andyarvanitis@gmail.com> dateTue 23 Jul 2019, 21:59 (7 years ago) parenteb14b10
4 files changed+11−3
src/CodeGen/IL.hs+5−1 src/CodeGen/IL/Common.hs+1−1 src/CodeGen/IL/Optimizer/TCO.hs+3 src/CodeGen/IL/Printer.hs+2−1
src/CodeGen/IL.hs+5−1
@@ -404,4 +404,8 @@ arrayLength :: AST -> AST
404404arrayLength a = AST.App Nothing (AST.Var Nothing arrayLengthFn) [a]
405405
406406unbox' :: Text -> AST -> AST
407−unbox' ty e = AST.App Nothing (AST.StringLiteral Nothing $ mkString ty) [e]
407+unbox' _ v@AST.NumericLiteral{} = v
408+unbox' _ v@AST.BooleanLiteral{} = v
409+unbox' _ v@AST.StringLiteral{} = v
410+unbox' _ v@AST.Binary{} = v
411+unbox' t v = AST.App Nothing (AST.StringLiteral Nothing $ mkString t) [v]
src/CodeGen/IL/Common.hs+1−1
@@ -225,4 +225,4 @@ unretainedSuffix = "_weak_"
225225freshName' :: MonadSupply m => m Text
226226freshName' = do
227227 name <- freshName
228− return $ T.replace "$" "_" name
228+ return $ T.replace "$" "_var" name <> "_"
src/CodeGen/IL/Optimizer/TCO.hs+3
@@ -48,6 +48,9 @@ tco mn = everywhere convert where
4848 collectAllFunctionArgs :: [[Text]] -> (AST -> AST) -> AST -> ([[Text]], AST, AST -> AST)
4949 collectAllFunctionArgs allArgs f (Function s1 ident args (Block s2 (body@(Return _ _):_))) =
5050 collectAllFunctionArgs (args : allArgs) (\b -> f (Function s1 ident (map copyVar args) (Block s2 [b]))) body
51+ -- Handle RecLetDecl weak assignment case
52+ collectAllFunctionArgs allArgs f (Function s1 ident args (Block s2 (Var{}:body@(Return _ _):_))) =
53+ collectAllFunctionArgs (args : allArgs) (\b -> f (Function s1 ident (map copyVar args) (Block s2 [b]))) body
5154 collectAllFunctionArgs allArgs f (Function ss ident args body@(Block _ _)) =
5255 (args : allArgs, body, f . Function ss ident (map copyVar args))
5356 collectAllFunctionArgs allArgs f (Return s1 (Function s2 ident args (Block s3 [body]))) =
src/CodeGen/IL/Printer.hs+2−1
@@ -407,7 +407,8 @@ stringLiteral _ = "\"\\uFFFD\""
407407unbox' :: Text -> AST -> Text
408408unbox' _ v@(NumericLiteral{}) = prettyPrintIL1 v
409409unbox' _ v@(BooleanLiteral{}) = prettyPrintIL1 v
410−unbox' _ v@(StringLiteral{}) = prettyPrintIL1 v
410+unbox' _ v@(StringLiteral{}) = prettyPrintIL1 v
411+unbox' _ v@(Binary{}) = prettyPrintIL1 v
411412unbox' t v = unbox t <> "(" <> prettyPrintIL1 v <> ")"
412413
413414interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text