git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: cleanup -- CppMapLiteral instead of CppObjectLiteral
commit59738976e930ac8ff17cc23b9a407fce419d15d6 authorAndy Arvanitis <andyarvanitis@gmail.com> dateMon 31 Oct 2016, 21:44 (10 years ago) parentaba280f
6 files changed+16−16
src/Language/PureScript/CodeGen/Cpp.hs+3−3 src/Language/PureScript/CodeGen/Cpp/AST.hs+4−4 src/Language/PureScript/CodeGen/Cpp/File.hs+3−3 src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs+4−4 src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1 src/Language/PureScript/Pretty/Cpp.hs+1−1
src/Language/PureScript/CodeGen/Cpp.hs+3−3
@@ -442,7 +442,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
442442 CppArrayLiteral <$> mapM valueToCpp xs
443443
444444 valueToCpp (Literal _ (ObjectLiteral ps)) =
445− CppObjectLiteral CppRecord <$>
445+ CppMapLiteral CppRecord <$>
446446 mapM (sndM valueToCpp) ((\(k,v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) ps)
447447
448448 valueToCpp (Accessor _ prop val) =
@@ -454,7 +454,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
454454 updatedFields <- mapM (sndM valueToCpp) ps
455455 let origKeys = (allKeys ty) \\ (fst <$> updatedFields)
456456 origFields = (\key -> (key, CppIndexer (CppSymbol key) obj')) <$> origKeys
457− return $ CppObjectLiteral CppRecord $
457+ return $ CppMapLiteral CppRecord $
458458 (\(k,v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) (origFields ++ updatedFields)
459459 where
460460 allKeys :: T.Type -> [String]
@@ -487,7 +487,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
487487 Var (_, _, _, Just IsNewtype) _ -> return (head args')
488488 Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
489489 let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
490− return . CppObjectLiteral CppInstance $
490+ return . CppMapLiteral CppInstance $
491491 zip
492492 (CppSymbol <$> (sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
493493 args'
src/Language/PureScript/CodeGen/Cpp/AST.hs+4−4
@@ -185,7 +185,7 @@ data Cpp
185185 -- |
186186 -- An object literal
187187 --
188− | CppObjectLiteral CppObjectType [(Cpp, Cpp)]
188+ | CppMapLiteral CppMapType [(Cpp, Cpp)]
189189 -- |
190190 -- An general property accessor expression (property, expr)
191191 --
@@ -302,7 +302,7 @@ everywhereOnCpp f = go
302302 go (CppArrayLiteral cpp) = f (CppArrayLiteral (map go cpp))
303303 go (CppDataLiteral cpp) = f (CppDataLiteral (map go cpp))
304304 go (CppIndexer j1 j2) = f (CppIndexer (go j1) (go j2))
305− go (CppObjectLiteral t cpps) = f (CppObjectLiteral t (map (fmap go) cpps))
305+ go (CppMapLiteral t cpps) = f (CppMapLiteral t (map (fmap go) cpps))
306306 go (CppAccessor prop j) = f (CppAccessor (go prop) (go j))
307307 go (CppFunction name args rty qs j) = f (CppFunction name args rty qs (go j))
308308 go (CppLambda cps args rty j) = f (CppLambda cps args rty (go j))
@@ -333,7 +333,7 @@ everywhereOnCppTopDownM f = f >=> go
333333 go (CppArrayLiteral cpp) = CppArrayLiteral <$> traverse f' cpp
334334 go (CppDataLiteral cpp) = CppDataLiteral <$> traverse f' cpp
335335 go (CppIndexer j1 j2) = CppIndexer <$> f' j1 <*> f' j2
336− go (CppObjectLiteral t cpps) = CppObjectLiteral t <$> traverse (pairM f' f') cpps
336+ go (CppMapLiteral t cpps) = CppMapLiteral t <$> traverse (pairM f' f') cpps
337337 go (CppAccessor prop j) = CppAccessor prop <$> f' j
338338 go (CppFunction name args rty qs j) = CppFunction name args rty qs <$> f' j
339339 go (CppLambda cps args rty j) = CppLambda cps args rty <$> f' j
@@ -360,7 +360,7 @@ everythingOnCpp (<>) f = go
360360 go j@(CppArrayLiteral cpp) = foldl (<>) (f j) (map go cpp)
361361 go j@(CppDataLiteral cpp) = foldl (<>) (f j) (map go cpp)
362362 go j@(CppIndexer j1 j2) = f j <> go j1 <> go j2
363− go j@(CppObjectLiteral _ cpps) = foldl (<>) (f j) ((map (go . fst) cpps) ++ (map (go . snd) cpps))
363+ go j@(CppMapLiteral _ cpps) = foldl (<>) (f j) ((map (go . fst) cpps) ++ (map (go . snd) cpps))
364364 go j@(CppAccessor j1 j2) = f j <> go j1 <> go j2
365365 go j@(CppFunction _ _ _ _ j1) = f j <> go j1
366366 go j@(CppLambda _ _ _ j1) = f j <> go j1
src/Language/PureScript/CodeGen/Cpp/File.hs+3−3
@@ -58,7 +58,7 @@ toHeader = catMaybes . map go
5858 -- Generate thunks for top-level values
5959 go (CppVariableIntroduction (name, _) _ (Just cpp)) =
6060 case cpp of
61− CppObjectLiteral CppInstance _ ->
61+ CppMapLiteral CppInstance _ ->
6262 Just $ CppFunction name [("", Just thunkMarkerType)] (Just $ CppAny [CppConst, CppRef]) [] CppNoOp
6363 _ ->
6464 Just $ CppVariableIntroduction (name, Just $ CppAny [CppConst]) [CppExtern] Nothing
@@ -130,7 +130,7 @@ toBody = catMaybes . map go
130130 -- Generate thunks for top-level values
131131 go (CppVariableIntroduction (name, _) _ (Just cpp)) =
132132 case cpp of
133− CppObjectLiteral CppInstance _ ->
133+ CppMapLiteral CppInstance _ ->
134134 Just $ CppFunction name [("", Just thunkMarkerType)] (Just $ CppAny [CppConst, CppRef]) [] block
135135 _ ->
136136 Just $ CppVariableIntroduction (name, Just $ CppAny [CppConst]) [] (Just lambda)
@@ -139,7 +139,7 @@ toBody = catMaybes . map go
139139 block = CppBlock [val, CppReturn (CppVar "$value$")]
140140 lambda = CppLambda [] [("", Just $ thunkMarkerType)] (Just $ CppAny [CppConst, CppRef]) block
141141 addCaptures :: Cpp -> Cpp
142− addCaptures (CppObjectLiteral t objs) = CppObjectLiteral t (objlam <$> objs)
142+ addCaptures (CppMapLiteral t objs) = CppMapLiteral t (objlam <$> objs)
143143 where
144144 objlam :: (Cpp, Cpp) -> (Cpp, Cpp)
145145 objlam (name', (CppLambda _ args rty body)) = (name' , CppLambda [] args rty $ addCaptures body)
src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs+4−4
@@ -74,12 +74,12 @@ magicDo' = everywhereOnCpp undo . everywhereOnCppTopDown convert
7474 | otherwise = CppVariableIntroduction arg [] (Just (CppApp m []))
7575 -- Desugar untilE
7676 convert (CppApp (CppApp f [arg]) []) | isEffFunc C.untilE f =
77− CppApp (CppLambda [CppCaptureAll] [] Nothing (CppBlock [ CppWhile (CppUnary Not (CppApp arg [])) (CppBlock []), CppReturn $ CppObjectLiteral CppRecord []])) []
77+ CppApp (CppLambda [CppCaptureAll] [] Nothing (CppBlock [ CppWhile (CppUnary Not (CppApp arg [])) (CppBlock []), CppReturn $ CppMapLiteral CppRecord []])) []
7878 -- Desugar whileE
7979 convert (CppApp (CppApp f [arg1, arg2]) []) | isEffFunc C.whileE f =
80− CppApp (CppLambda [CppCaptureAll] [] Nothing (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppObjectLiteral CppRecord []])) []
80+ CppApp (CppLambda [CppCaptureAll] [] Nothing (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppMapLiteral CppRecord []])) []
8181 convert (CppApp (CppApp (CppApp f [arg1]) [arg2]) []) | isEffFunc C.whileE f =
82− CppApp (CppLambda [CppCaptureAll] [] Nothing (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppObjectLiteral CppRecord []])) []
82+ CppApp (CppLambda [CppCaptureAll] [] Nothing (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppMapLiteral CppRecord []])) []
8383 convert other = other
8484 -- Check if an expression represents a monomorphic call to >>= for the Eff monad
8585 isBind (CppApp fn [dict]) | isDict (C.eff, C.bindEffDictionary) dict && isBindPoly fn = True
@@ -128,7 +128,7 @@ inlineST = everywhereOnCpp convertBlock
128128 -- or in a more aggressive way, turning wrappers into local variables depending on the
129129 -- agg(ressive) parameter.
130130 convert agg (CppApp f [arg]) | isSTFunc C.newSTRef f =
131− CppLambda [CppCaptureAll] [] Nothing (CppBlock [CppReturn $ if agg then arg else CppObjectLiteral CppRecord [(CppSymbol C.stRefValue, arg)]])
131+ CppLambda [CppCaptureAll] [] Nothing (CppBlock [CppReturn $ if agg then arg else CppMapLiteral CppRecord [(CppSymbol C.stRefValue, arg)]])
132132 convert agg (CppApp (CppApp f [ref]) []) | isSTFunc C.readSTRef f =
133133 if agg then ref else CppAccessor (CppVar C.stRefValue) ref
134134 convert agg (CppApp (CppApp (CppApp f [ref]) [arg]) []) | isSTFunc C.writeSTRef f =
src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1
@@ -73,7 +73,7 @@ data CppCaptureType = CppCaptureAll
7373-- |
7474-- C++ object/map literal type
7575--
76−data CppObjectType = CppInstance | CppRecord
76+data CppMapType = CppInstance | CppRecord
7777 deriving (Show, Eq)
7878
7979runType :: CppType -> String
src/Language/PureScript/Pretty/Cpp.hs+1−1
@@ -116,7 +116,7 @@ literals = mkPattern' match
116116 , return $ intercalate ", " es
117117 , return " }"
118118 ]
119− match (CppObjectLiteral _ ps) = fmap concat $ sequence
119+ match (CppMapLiteral _ ps) = fmap concat $ sequence
120120 [ return $ runType (mapType $ length ps + 1) ++ "{{\n"
121121 , withIndent $ do
122122 cpps <- forM ps $ \(key, value) -> do