git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix inlining
54ee44dAndy Arvanitis
runtime/purescript.go+1−1
@@ -24,7 +24,7 @@ func Apply(f Any, args ...Any) Any {
24 return result
24 return result
25}
25}
26
26
27−func EffApply(f Any, args ...Any) Any {
27+func Run(f Any, args ...Any) Any {
28 fn, _ := f.(EffFn)
28 fn, _ := f.(EffFn)
29 return fn()
29 return fn()
30}
30}
src/CodeGen/IL.hs+1−2
@@ -198,8 +198,7 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) _ =
198 fn <- valueToIL f
198 fn <- valueToIL f
199 case f of
199 case f of
200 Var (_, _, _, Just IsNewtype) _ -> return (head args')
200 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
203 where
202 where
204 unApp :: Expr Ann -> [Expr Ann] -> (Expr Ann, [Expr Ann])
203 unApp :: Expr Ann -> [Expr Ann] -> (Expr Ann, [Expr Ann])
205 unApp (App _ val arg) args = unApp val (arg : args)
204 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
16moduleNameToIL :: ModuleName -> Text
16moduleNameToIL :: ModuleName -> Text
17moduleNameToIL (ModuleName pns) =
17moduleNameToIL (ModuleName pns) =
18 let name = T.intercalate "_" (runProperName `map` pns)
18 let name = T.intercalate "_" (runProperName `map` pns)
19+ in moduleNameToIL' name
20+
21+moduleNameToIL' :: Text -> Text
22+moduleNameToIL' name =
19− in if moduleIsReserved name then (name <> "_") else name
23+ if moduleIsReserved name then (name <> "_") else name
20
24
21-- | Convert an 'Ident' into a valid IL identifier:
25-- | Convert an 'Ident' into a valid IL identifier:
22--
26--
src/CodeGen/IL/Optimizer.hs+2−2
@@ -12,7 +12,7 @@ import Language.PureScript.CoreImp.Optimizer.Inliner hiding (inlineUnsafeCoerce,
12import Language.PureScript.CoreImp.Optimizer.Unused
12import Language.PureScript.CoreImp.Optimizer.Unused
13import Language.PureScript.PSString (PSString, decodeString)
13import Language.PureScript.PSString (PSString, decodeString)
14
14
15−import CodeGen.IL.Common (undefinedName, unusedName)
15+import CodeGen.IL.Common (moduleNameToIL', undefinedName, unusedName)
16import CodeGen.IL.Optimizer.TCO
16import CodeGen.IL.Optimizer.TCO
17
17
18import qualified Language.PureScript.Constants as C
18import qualified Language.PureScript.Constants as C
@@ -136,5 +136,5 @@ magicDo'' effectModule C.EffectDictionaries{..} = everywhereTopDown convert
136
136
137 isDict :: (Text, PSString) -> AST -> Bool
137 isDict :: (Text, PSString) -> AST -> Bool
138 isDict (moduleName, dictName) (Indexer _ (Var _ x) (Var _ y)) =
138 isDict (moduleName, dictName) (Indexer _ (Var _ x) (Var _ y)) =
139− Just x == decodeString dictName && y == moduleName
139+ Just x == decodeString dictName && y == moduleNameToIL' moduleName
140 isDict _ _ = False
140 isDict _ _ = False
src/CodeGen/IL/Printer.hs+21−7
@@ -83,7 +83,7 @@ literals = mkPattern' match'
83 , prettyPrintIL' value
83 , prettyPrintIL' value
84 ]
84 ]
85 match (App _ val []) = mconcat <$> sequence
85 match (App _ val []) = mconcat <$> sequence
86− [ return $ emit "EffApply("
86+ [ return $ emit "Run("
87 , prettyPrintIL' val
87 , prettyPrintIL' val
88 , return $ emit ")"
88 , return $ emit ")"
89 ]
89 ]
@@ -93,7 +93,7 @@ literals = mkPattern' match'
93 , prettyPrintIL' arg
93 , prettyPrintIL' arg
94 , return $ emit ")"
94 , return $ emit ")"
95 ]
95 ]
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])
97 | fnMod == dictMod
97 | fnMod == dictMod
98 , dictMod == C.dataEq || dictMod == C.dataSemiring || dictMod == C.dataRing ||
98 , dictMod == C.dataEq || dictMod == C.dataSemiring || dictMod == C.dataRing ||
99 dictMod == C.dataEuclideanRing || dictMod == C.dataHeytingAlgebra || dictMod == C.dataOrd
99 dictMod == C.dataEuclideanRing || dictMod == C.dataHeytingAlgebra || dictMod == C.dataOrd
@@ -104,7 +104,7 @@ literals = mkPattern' match'
104 , return $ emit op
104 , return $ emit op
105 , return $ emit $ unbox' t y
105 , return $ emit $ unbox' t y
106 ]
106 ]
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])
108 | fnMod == dictMod
108 | fnMod == dictMod
109 , dictMod == C.dataRing
109 , dictMod == C.dataRing
110 , fn == C.negate
110 , fn == C.negate
@@ -114,7 +114,7 @@ literals = mkPattern' match'
114 , return $ emit $ unbox' t n
114 , return $ emit $ unbox' t n
115 , return $ emit ")"
115 , return $ emit ")"
116 ]
116 ]
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])
118 | fnMod == dictMod
118 | fnMod == dictMod
119 , dictMod == C.dataHeytingAlgebra
119 , dictMod == C.dataHeytingAlgebra
120 , fn == properToIL C.not
120 , fn == properToIL C.not
@@ -124,6 +124,16 @@ literals = mkPattern' match'
124 , return $ emit $ unbox' t n
124 , return $ emit $ unbox' t n
125 , return $ emit ")"
125 , return $ emit ")"
126 ]
126 ]
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+ ]
127 match (App _ val args) = mconcat <$> sequence
137 match (App _ val args) = mconcat <$> sequence
128 [ return $ emit "Apply("
138 [ return $ emit "Apply("
129 , prettyPrintIL' val
139 , prettyPrintIL' val
@@ -217,8 +227,8 @@ literals = mkPattern' match'
217 , return $ emit " "
227 , return $ emit " "
218 , prettyPrintIL' sts
228 , prettyPrintIL' sts
219 ]
229 ]
220− match (IfElse _ (Binary _ EqualTo cond (BooleanLiteral Nothing True)) thens elses)
230+ 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
231+ | (App _ (App _ (App _ (Indexer _ (Var _ _) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [x]) [y]) <- cond
222 , fnMod == dictMod
232 , fnMod == dictMod
223 , dictMod == C.dataEq || dictMod == C.dataOrd
233 , dictMod == C.dataEq || dictMod == C.dataOrd
224 , Just _ <- unboxTypeInt dict
234 , Just _ <- unboxTypeInt dict
@@ -361,6 +371,10 @@ isComplexLiteral ObjectLiteral{} = True
361isComplexLiteral ArrayLiteral{} = True
371isComplexLiteral ArrayLiteral{} = True
362isComplexLiteral _ = False
372isComplexLiteral _ = False
363
373
374+unApp :: AST -> [AST] -> (AST, [AST])
375+unApp (App _ val [arg]) args = unApp val (arg : args)
376+unApp other args = (other, args)
377+
364prettyStatements :: (Emit gen) => [AST] -> StateT PrinterState Maybe gen
378prettyStatements :: (Emit gen) => [AST] -> StateT PrinterState Maybe gen
365prettyStatements sts = do
379prettyStatements sts = do
366 ils <- forM sts prettyPrintIL'
380 ils <- forM sts prettyPrintIL'
@@ -521,7 +535,7 @@ implFooterSource mn foreigns =
521 mainSource :: Text
535 mainSource :: Text
522 mainSource = "\
536 mainSource = "\
523 \func main() {\n\
537 \func main() {\n\
524− \ EffApply(PS__main())\n\
538+ \ Run(PS__main())\n\
525 \}\n\n\
539 \}\n\n\
526 \"
540 \"
527
541