git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix inlining
commit54ee44d85a27afc815c92a2fefc9a36deadd14e5 authorAndy Arvanitis <andyarvanitis@gmail.com> dateWed 26 Jun 2019, 21:29 (7 years ago) parent92b82dd
5 files changed+30−13
runtime/purescript.go+1−1 src/CodeGen/IL.hs+1−2 src/CodeGen/IL/Common.hs+5−1 src/CodeGen/IL/Optimizer.hs+2−2 src/CodeGen/IL/Printer.hs+21−7
runtime/purescript.go+1−1
@@ -24,7 +24,7 @@ func Apply(f Any, args ...Any) Any {
2424 return result
2525}
2626
27−func EffApply(f Any, args ...Any) Any {
27+func Run(f Any, args ...Any) Any {
2828 fn, _ := f.(EffFn)
2929 return fn()
3030}
src/CodeGen/IL.hs+1−2
@@ -198,8 +198,7 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) _ =
198198 fn <- valueToIL f
199199 case f of
200200 Var (_, _, _, Just IsNewtype) _ -> return (head args')
201− _ -> return $ AST.App Nothing fn args'
202− -- _ -> flip (foldl (\fn a -> AST.App Nothing fn [a])) args' <$> valueToIL f
201+ _ -> flip (foldl (\fn a -> AST.App Nothing fn [a])) args' <$> valueToIL f
203202 where
204203 unApp :: Expr Ann -> [Expr Ann] -> (Expr Ann, [Expr Ann])
205204 unApp (App _ val arg) args = unApp val (arg : args)
src/CodeGen/IL/Common.hs+5−1
@@ -16,7 +16,11 @@ import qualified Language.PureScript.Constants as C
1616moduleNameToIL :: ModuleName -> Text
1717moduleNameToIL (ModuleName pns) =
1818 let name = T.intercalate "_" (runProperName `map` pns)
19− in if moduleIsReserved name then (name <> "_") else name
19+ in moduleNameToIL' name
20+
21+moduleNameToIL' :: Text -> Text
22+moduleNameToIL' name =
23+ if moduleIsReserved name then (name <> "_") else name
2024
2125-- | Convert an 'Ident' into a valid IL identifier:
2226--
src/CodeGen/IL/Optimizer.hs+2−2
@@ -12,7 +12,7 @@ import Language.PureScript.CoreImp.Optimizer.Inliner hiding (inlineUnsafeCoerce,
1212import Language.PureScript.CoreImp.Optimizer.Unused
1313import Language.PureScript.PSString (PSString, decodeString)
1414
15−import CodeGen.IL.Common (undefinedName, unusedName)
15+import CodeGen.IL.Common (moduleNameToIL', undefinedName, unusedName)
1616import CodeGen.IL.Optimizer.TCO
1717
1818import qualified Language.PureScript.Constants as C
@@ -136,5 +136,5 @@ magicDo'' effectModule C.EffectDictionaries{..} = everywhereTopDown convert
136136
137137 isDict :: (Text, PSString) -> AST -> Bool
138138 isDict (moduleName, dictName) (Indexer _ (Var _ x) (Var _ y)) =
139− Just x == decodeString dictName && y == moduleName
139+ Just x == decodeString dictName && y == moduleNameToIL' moduleName
140140 isDict _ _ = False
src/CodeGen/IL/Printer.hs+21−7
@@ -83,7 +83,7 @@ literals = mkPattern' match'
8383 , prettyPrintIL' value
8484 ]
8585 match (App _ val []) = mconcat <$> sequence
86− [ return $ emit "EffApply("
86+ [ return $ emit "Run("
8787 , prettyPrintIL' val
8888 , return $ emit ")"
8989 ]
@@ -93,7 +93,7 @@ literals = mkPattern' match'
9393 , prettyPrintIL' arg
9494 , return $ emit ")"
9595 ]
96− match (App ss (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod), x, y])
96+ match (App _ (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [x]) [y])
9797 | fnMod == dictMod
9898 , dictMod == C.dataEq || dictMod == C.dataSemiring || dictMod == C.dataRing ||
9999 dictMod == C.dataEuclideanRing || dictMod == C.dataHeytingAlgebra || dictMod == C.dataOrd
@@ -104,7 +104,7 @@ literals = mkPattern' match'
104104 , return $ emit op
105105 , return $ emit $ unbox' t y
106106 ]
107− match (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod), n])
107+ match (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [n])
108108 | fnMod == dictMod
109109 , dictMod == C.dataRing
110110 , fn == C.negate
@@ -114,7 +114,7 @@ literals = mkPattern' match'
114114 , return $ emit $ unbox' t n
115115 , return $ emit ")"
116116 ]
117− match (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod), n])
117+ match (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [n])
118118 | fnMod == dictMod
119119 , dictMod == C.dataHeytingAlgebra
120120 , fn == properToIL C.not
@@ -124,6 +124,16 @@ literals = mkPattern' match'
124124 , return $ emit $ unbox' t n
125125 , return $ emit ")"
126126 ]
127+ match app@(App{})
128+ | (val, args) <- unApp app []
129+ , length args > 1
130+ = mconcat <$> sequence
131+ [ return $ emit "Apply("
132+ , prettyPrintIL' val
133+ , return $ emit ", "
134+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
135+ , return $ emit ")"
136+ ]
127137 match (App _ val args) = mconcat <$> sequence
128138 [ return $ emit "Apply("
129139 , prettyPrintIL' val
@@ -217,8 +227,8 @@ literals = mkPattern' match'
217227 , return $ emit " "
218228 , prettyPrintIL' sts
219229 ]
220− match (IfElse _ (Binary _ EqualTo cond (BooleanLiteral Nothing True)) thens elses)
221− | (App ss (Indexer _ (Var _ _) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod), x, y]) <- cond
230+ match (IfElse _ (Binary _ EqualTo cond (BooleanLiteral Nothing True)) thens elses)
231+ | (App _ (App _ (App _ (Indexer _ (Var _ _) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [x]) [y]) <- cond
222232 , fnMod == dictMod
223233 , dictMod == C.dataEq || dictMod == C.dataOrd
224234 , Just _ <- unboxTypeInt dict
@@ -361,6 +371,10 @@ isComplexLiteral ObjectLiteral{} = True
361371isComplexLiteral ArrayLiteral{} = True
362372isComplexLiteral _ = False
363373
374+unApp :: AST -> [AST] -> (AST, [AST])
375+unApp (App _ val [arg]) args = unApp val (arg : args)
376+unApp other args = (other, args)
377+
364378prettyStatements :: (Emit gen) => [AST] -> StateT PrinterState Maybe gen
365379prettyStatements sts = do
366380 ils <- forM sts prettyPrintIL'
@@ -521,7 +535,7 @@ implFooterSource mn foreigns =
521535 mainSource :: Text
522536 mainSource = "\
523537 \func main() {\n\
524− \ EffApply(PS__main())\n\
538+ \ Run(PS__main())\n\
525539 \}\n\n\
526540 \"
527541