git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fixes for issue #57 and issue #58
commitef4efcd616ed5263381f25d968c11042aeb59883 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 4 Oct 2020, 17:50 (6 years ago) parent6364659
2 files changed+21−6
src/CodeGen/IL/Common.hs+3 src/CodeGen/IL/Optimizer/Inliner.hs+18−6
src/CodeGen/IL/Common.hs+3
@@ -198,6 +198,9 @@ dictType = "dict_t"
198198arrayType :: Text
199199arrayType = "array_t"
200200
201+uncurriedFnType :: Int -> Text
202+uncurriedFnType i = "Fn" <> (T.pack . show $ i)
203+
201204int :: Text
202205int = "int"
203206
src/CodeGen/IL/Optimizer/Inliner.hs+18−6
@@ -75,7 +75,7 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
7575 , binary euclideanRingNumber opDiv Divide
7676
7777 -- , binary eqNumber opEq EqualTo
78− , binary eqNumber opNotEq NotEqualTo
78+ -- , binary eqNumber opNotEq NotEqualTo
7979 , binary eqInt opEq EqualTo
8080 , binary eqInt opNotEq NotEqualTo
8181 , binary eqString opEq EqualTo
@@ -122,7 +122,7 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
122122
123123 , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> App Nothing f [x]
124124 , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> App Nothing f [x]
125− , inlineNonClassFunction (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
125+ , inlineUnsafeIndex (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
126126 ] -- ++
127127 -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ] ++
128128 -- [ fn | i <- [0..10], fn <- [ mkEffFn C.controlMonadEffUncurried C.mkEffFn i, runEffFn C.controlMonadEffUncurried C.runEffFn i ] ] ++
@@ -186,13 +186,14 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
186186 runFn :: Int -> AST -> AST
187187 runFn = runFn' C.dataFunctionUncurried C.runFn (\ss f args ->
188188 let len = length args
189− typ = mkString $ "Fn" <> (T.pack . show $ len) in
189+ typ = mkString $ uncurriedFnType len in
190190 if len > 0
191191 then App ss (App Nothing (StringLiteral Nothing typ) [f]) args
192192 else App ss f args)
193193 runEffFn :: Text -> Text -> Int -> AST -> AST
194194 runEffFn modName fnName = runFn' modName fnName $ \ss fn acc ->
195− Function ss Nothing [] (Block ss [Return ss (App ss fn acc)])
195+ let typ = mkString . uncurriedFnType $ length acc in
196+ Function ss Nothing [] (Block ss [Return ss (App ss (App Nothing (StringLiteral Nothing typ) [fn]) acc)])
196197
197198 runFn' :: Text -> Text -> (Maybe SourceSpan -> AST -> [AST] -> AST) -> Int -> AST -> AST
198199 runFn' modName runFnName res n = convert where
@@ -211,6 +212,17 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
211212 convert (App _ (App _ op' [x]) [y]) | p op' = f x y
212213 convert other = other
213214
215+ inlineUnsafeIndex :: (AST -> Bool) -> (AST -> AST -> AST) -> AST -> AST
216+ inlineUnsafeIndex p _ = convert where
217+ convert :: AST -> AST
218+ convert (App _ (App ss op' [x]) [y@NumericLiteral{}])
219+ | p op' = Indexer ss y x
220+ convert (App _ (App ss op' [x]) [y])
221+ | p op' = Indexer ss y' x
222+ where
223+ y' = App Nothing (StringLiteral Nothing $ mkString int) [y]
224+ convert other = other
225+
214226 isModFn :: (Text, PSString) -> AST -> Bool
215227 isModFn (m, op) (Indexer _ (Var _ op') (Var _ m')) =
216228 m == m' && decodeString op == Just op'
@@ -294,8 +306,8 @@ ringInt = (C.dataRing, C.ringInt)
294306euclideanRingNumber :: forall a b. (IsString a, IsString b) => (a, b)
295307euclideanRingNumber = (C.dataEuclideanRing, C.euclideanRingNumber)
296308
297−eqNumber :: forall a b. (IsString a, IsString b) => (a, b)
298−eqNumber = (C.dataEq, C.eqNumber)
309+-- eqNumber :: forall a b. (IsString a, IsString b) => (a, b)
310+-- eqNumber = (C.dataEq, C.eqNumber)
299311
300312eqInt :: forall a b. (IsString a, IsString b) => (a, b)
301313eqInt = (C.dataEq, C.eqInt)