git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Inline boolean Heyting Algebra operators
commitb0c4f47593b32b8af8a8dace48713a88ea798e95 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 27 Jan 2019, 15:05 (8 years ago) parent1e53e82
2 files changed+18−4
src/CodeGen/Cpp/Optimizer.hs+1−1 src/CodeGen/Cpp/Printer.hs+17−3
src/CodeGen/Cpp/Optimizer.hs+1−1
@@ -18,7 +18,7 @@ import CodeGen.Cpp.Optimizer.TCO
1818import qualified Language.PureScript.Constants as C
1919
2020
21−-- | Apply a series of optimizer passes to simplified Objective-C code
21+-- | Apply a series of optimizer passes to simplified C++ code
2222optimize :: MonadSupply m => AST -> AST -> m AST
2323-- optimize = untilFixedPoint $ return . inlineUnsafeCoerce . inlineUnsafePartial . tidyUp . tco
2424optimize mn cpp = do
src/CodeGen/Cpp/Printer.hs+17−3
@@ -92,7 +92,8 @@ literals = mkPattern' match'
9292 ]
9393 match (App ss (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [x]) [y])
9494 | fnMod == dictMod
95− , dictMod == C.dataEq || dictMod == C.dataSemiring || dictMod == C.dataRing || dictMod == C.dataEuclideanRing
95+ , dictMod == C.dataEq || dictMod == C.dataSemiring || dictMod == C.dataRing ||
96+ dictMod == C.dataEuclideanRing || dictMod == C.dataHeytingAlgebra
9697 , Just op <- renderOp fn
9798 , Just t <- unboxType dict
9899 = mconcat <$> sequence
@@ -109,6 +110,15 @@ literals = mkPattern' match'
109110 [ return $ emit "-"
110111 , return $ emit $ unbox' t n
111112 ]
113+ match (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [n])
114+ | fnMod == dictMod
115+ , dictMod == C.dataHeytingAlgebra
116+ , fn == properToCpp C.not
117+ , Just t <- unboxType dict
118+ = mconcat <$> sequence
119+ [ return $ emit "!"
120+ , return $ emit $ unbox' t n
121+ ]
112122 match (App _ val args) = mconcat <$> sequence
113123 [ prettyPrintCpp' val
114124 , return $ emit "("
@@ -326,7 +336,7 @@ prettyStatements sts = do
326336 indentString <- currentIndent
327337 return $ intercalate (emit "\n") $ map ((<> emit ";") . (indentString <>)) cpps
328338
329−-- | Generate a pretty-printed string representing a collection of Objective-C expressions at the same indentation level
339+-- | Generate a pretty-printed string representing a collection of C++ expressions at the same indentation level
330340prettyPrintCppWithSourceMaps :: [AST] -> (Text, [SMap])
331341prettyPrintCppWithSourceMaps cpp =
332342 let StrPos (_, s, mp) = (fromMaybe (internalError "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyStatements) cpp
@@ -335,7 +345,7 @@ prettyPrintCppWithSourceMaps cpp =
335345prettyPrintCpp :: [AST] -> Text
336346prettyPrintCpp = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyStatements
337347
338−-- | Generate an indented, pretty-printed string representing a Objective-C expression
348+-- | Generate an indented, pretty-printed string representing a C++ expression
339349prettyPrintCpp' :: (Emit gen) => AST -> StateT PrinterState Maybe gen
340350prettyPrintCpp' = A.runKleisli $ runPattern matchValue
341351 where
@@ -409,6 +419,8 @@ unboxType t
409419 t == C.ringNumber ||
410420 t == C.euclideanRingNumber
411421 = Just float
422+ | t == C.heytingAlgebraBoolean
423+ = Just bool
412424 | otherwise = Nothing
413425
414426renderOp :: Text -> Maybe Text
@@ -419,6 +431,8 @@ renderOp op
419431 | op == C.sub = Just " - "
420432 | op == C.mul = Just " * "
421433 | op == C.div = Just " / "
434+ | op == C.conj = Just " && "
435+ | op == C.disj = Just "|| "
422436 | otherwise = Nothing
423437
424438interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text