git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Support uncurried fn inlining
commit075cc5d5177413dfc146086c6286188de9becc8a authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 11 Jul 2019, 11:37 (7 years ago) parentebb9d4f
3 files changed+36−3
runtime/purescript.go+11 src/CodeGen/IL/Optimizer/Inliner.hs+6−2 src/CodeGen/IL/Printer.hs+19−1
runtime/purescript.go+11
@@ -13,6 +13,17 @@ type Array = []Any
1313
1414type Once = sync.Once
1515
16+type Fn1 = func(Any) Any
17+type Fn2 = func(Any, Any) Any
18+type Fn3 = func(Any, Any, Any) Any
19+type Fn4 = func(Any, Any, Any, Any) Any
20+type Fn5 = func(Any, Any, Any, Any, Any) Any
21+type Fn6 = func(Any, Any, Any, Any, Any, Any) Any
22+type Fn7 = func(Any, Any, Any, Any, Any, Any, Any) Any
23+type Fn8 = func(Any, Any, Any, Any, Any, Any, Any, Any) Any
24+type Fn9 = func(Any, Any, Any, Any, Any, Any, Any, Any, Any) Any
25+type Fn10 = func(Any, Any, Any, Any, Any, Any, Any, Any, Any, Any) Any
26+
1627type IGNORE_UNUSED_RUNTIME = bool
1728
1829const Undefined = "undefined"
src/CodeGen/IL/Optimizer/Inliner.hs+6−2
@@ -182,8 +182,12 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
182182 isNFn _ _ _ _ = False
183183
184184 runFn :: Int -> AST -> AST
185− runFn = runFn' C.dataFunctionUncurried C.runFn App
186−
185+ runFn = runFn' C.dataFunctionUncurried C.runFn (\ss f args ->
186+ let len = length args
187+ typ = mkString $ "Fn" <> (T.pack . show $ len) in
188+ if len > 0
189+ then App ss (App Nothing (StringLiteral Nothing typ) [f]) args
190+ else App ss f args)
187191 runEffFn :: Text -> Text -> Int -> AST -> AST
188192 runEffFn modName fnName = runFn' modName fnName $ \ss fn acc ->
189193 Function ss Nothing [] (Block ss [Return ss (App ss fn acc)])
src/CodeGen/IL/Printer.hs+19−1
@@ -106,6 +106,24 @@ literals = mkPattern' match'
106106 , intercalate (emit ", ") <$> forM args prettyPrintIL'
107107 , return $ emit ")"
108108 ]
109+ match (App _ (App Nothing (StringLiteral Nothing fnx) [fn@Function{}]) args)
110+ | Just ftype <- decodeString fnx
111+ , "Fn" `T.isPrefixOf` ftype = mconcat <$> sequence
112+ [ prettyPrintIL' fn
113+ , return $ emit "("
114+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
115+ , return $ emit ")"
116+ ]
117+ match (App _ (App Nothing (StringLiteral Nothing fnx) [fn]) args)
118+ | Just ftype <- decodeString fnx
119+ , "Fn" `T.isPrefixOf` ftype = mconcat <$> sequence
120+ [ prettyPrintIL' fn
121+ , return $ emit ".("
122+ , return $ emit ftype
123+ , return $ emit ")("
124+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
125+ , return $ emit ")"
126+ ]
109127 match app@(App{})
110128 | (val, args) <- unApp app []
111129 , length args > 1
@@ -368,7 +386,7 @@ prettyPrintIL' = A.runKleisli $ runPattern matchValue
368386 matchValue = buildPrettyPrinter operators (literals <+> fmap parensPos matchValue)
369387 operators :: (Emit gen) => OperatorTable PrinterState AST gen
370388 operators =
371− OperatorTable [ [ unary New "box" ]
389+ OperatorTable [ [ unary New "?" ]
372390 , [ unary Not "!"
373391 , unary BitwiseNot "~"
374392 , unary Positive "+"