git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: merge fixes for 0.8.1.0
commit7591176f400d7b78cdfe7059aeb7c43c9066cf03 authorAndy Arvanitis <andyarvanitis@gmail.com> dateTue 15 Mar 2016, 19:27 (11 years ago) parentfa8106b
3 files changed+49−18
pcc/Main.hs+6 src/Language/PureScript/CodeGen/Cpp.hs+10−15 src/Language/PureScript/Pretty/Cpp.hs+33−3
pcc/Main.hs+6
@@ -145,6 +145,11 @@ noPrefix = switch $
145145 <> long "no-prefix"
146146 <> help "Do not include comment header"
147147
148+sourceMaps :: Parser Bool
149+sourceMaps = switch $
150+ long "source-maps"
151+ <> help "Generate source maps"
152+
148153options :: Parser P.Options
149154options = P.Options <$> noTco
150155 <*> noMagicDo
@@ -153,6 +158,7 @@ options = P.Options <$> noTco
153158 <*> verboseErrors
154159 <*> (not <$> comments)
155160 <*> requirePath
161+ <*> sourceMaps
156162
157163pccOptions :: Parser PCCOptions
158164pccOptions = PCCOptions <$> many inputFile
src/Language/PureScript/CodeGen/Cpp.hs+10−15
@@ -65,7 +65,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
6565 cppImports <-
6666 traverse (pure . runModuleName) .
6767 delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $
68− imps
68+ (snd <$> imps)
6969 let cppImports' = "PureScript" : cppImports
7070 cppDecls <- concat <$> mapM (bindToCpp [CppTopLevel]) decls
7171 cppDecls' <- traverse optimize cppDecls
@@ -109,22 +109,22 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
109109 -------------------------------------------------------------------------------------------------
110110 bindToCpp :: [CppValueQual] -> Bind Ann -> m [Cpp]
111111 -------------------------------------------------------------------------------------------------
112− bindToCpp qs (NonRec ident val) = return <$> declToCpp qs ident val
112+ bindToCpp qs (NonRec ann ident val) = return <$> declToCpp qs (ann, ident) val
113113 bindToCpp qs (Rec vals) = forM vals (uncurry $ declToCpp (CppRecursive:qs))
114114
115115 -- |
116116 -- Desugar a declaration into a variable introduction or named function
117117 -- declaration.
118118 -------------------------------------------------------------------------------------------------
119− declToCpp :: [CppValueQual] -> Ident -> Expr Ann -> m Cpp
119+ declToCpp :: [CppValueQual] -> (Ann, Ident) -> Expr Ann -> m Cpp
120120 -------------------------------------------------------------------------------------------------
121121 declToCpp _ _ (Abs (_, _, _, Just IsTypeClassConstructor) _ _) =
122122 return CppNoOp
123123
124− declToCpp _ (Op _) (Var (_, _, Nothing, _) _) =
124+ declToCpp _ (_, Op _) (Var (_, _, Nothing, _) _) =
125125 return CppNoOp -- skip operator aliases
126126
127− declToCpp vqs ident (Abs (_, com, ty, _) arg body) = do
127+ declToCpp vqs (_, ident) (Abs (_, com, ty, _) arg body) = do
128128 fn <- if argcnt > 1 && CppTopLevel `elem` vqs
129129 then do
130130 argNames <- replicateM (argcnt - length args' - 1) freshName
@@ -180,7 +180,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
180180 isIndexer (CppIndexer (CppStringLiteral _) (CppVar _)) = True
181181 isIndexer _ = False
182182
183− declToCpp _ ident (Constructor _ _ (ProperName _) []) =
183+ declToCpp _ (_, ident) (Constructor _ _ (ProperName _) []) =
184184 return $
185185 CppFunction
186186 (identToCpp ident)
@@ -190,7 +190,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
190190 (asReturnBlock $
191191 CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar "data")])
192192
193− declToCpp _ ident (Constructor _ _ (ProperName _) fields) =
193+ declToCpp _ (_, ident) (Constructor _ _ (ProperName _) fields) =
194194 return . CppNamespace "" $
195195 [ CppFunction
196196 name
@@ -227,7 +227,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
227227 (CppBlock $ fieldLambdas fs') ]
228228 | otherwise = [CppReturn $ CppApp (CppVar name) (CppVar <$> fields')]
229229
230− declToCpp qs ident e
230+ declToCpp qs (_, ident) e
231231 | Just ty <- exprType e,
232232 CppTopLevel `elem` qs,
233233 argcnt <- countArgs ty,
@@ -262,7 +262,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
262262 aty = Just $ CppAny [CppConst, CppRef]
263263 rty = Just $ CppAny []
264264
265− declToCpp _ ident val = do
265+ declToCpp _ (_, ident) val = do
266266 val' <- valueToCpp val
267267 return $
268268 CppVariableIntroduction
@@ -750,16 +750,11 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
750750 | mn /= mn' = CppAccessor (CppVar . identToCpp $ f a) (CppVar (moduleNameToCpp mn'))
751751 qualifiedToCpp f (Qualified _ a) = CppVar $ identToCpp (f a)
752752
753− -------------------------------------------------------------------------------------------------
754− qualifiedToStr' :: (a -> Ident) -> Qualified a -> String
755− -------------------------------------------------------------------------------------------------
756− qualifiedToStr' = qualifiedToStr mn
757−
758753 -- |
759754 -- Find a class in scope by name, retrieving its list of constraints, function names and types.
760755 --
761756 -------------------------------------------------------------------------------------------------
762− findClass :: Qualified (ProperName ClassName) -> Maybe ([String], [T.Constraint], [(String, T.Type)])
757+ findClass :: Qualified (ProperName 'ClassName) -> Maybe ([String], [T.Constraint], [(String, T.Type)])
763758 -------------------------------------------------------------------------------------------------
764759 findClass name
765760 | Just (params, fns, constraints) <- M.lookup name (E.typeClasses env),
src/Language/PureScript/Pretty/Cpp.hs+33−3
@@ -38,13 +38,43 @@ import qualified Control.Arrow as A
3838import Language.PureScript.CodeGen.Cpp.AST
3939import Language.PureScript.CodeGen.Cpp.Types
4040import Language.PureScript.Comments
41−import Language.PureScript.Pretty.Common
41+-- import Language.PureScript.Pretty.Common
4242import qualified Language.PureScript.Constants as C
43−
4443import Numeric
45−
4644-- import Debug.Trace
4745
46+---------------------------------------------------------------------------------------------------
47+-- TODO: Go back to using Pretty.Common? (will require some work)
48+--
49+newtype PrinterState = PrinterState { indent :: Int } deriving (Show, Read, Eq, Ord)
50+-- |
51+-- Pretty print with a new indentation level
52+--
53+withIndent :: StateT PrinterState Maybe String -> StateT PrinterState Maybe String
54+withIndent action = do
55+ modify $ \st -> st { indent = indent st + blockIndent }
56+ result <- action
57+ modify $ \st -> st { indent = indent st - blockIndent }
58+ return result
59+
60+-- |
61+-- Get the current indentation level
62+--
63+currentIndent :: StateT PrinterState Maybe String
64+currentIndent = do
65+ current <- get
66+ return $ replicate (indent current) ' '
67+
68+blockIndent :: Int
69+blockIndent = 2
70+
71+-- |
72+-- Wrap a string in parentheses
73+--
74+parens :: String -> String
75+parens s = '(':s ++ ")"
76+---------------------------------------------------------------------------------------------------
77+
4878literals :: Pattern PrinterState Cpp String
4979literals = mkPattern' match
5080 where