git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: merge fixes for 0.8.1.0
7591176Andy Arvanitis
pcc/Main.hs+6
@@ -145,6 +145,11 @@ noPrefix = switch $
145 <> long "no-prefix"
145 <> long "no-prefix"
146 <> help "Do not include comment header"
146 <> help "Do not include comment header"
147
147
148+sourceMaps :: Parser Bool
149+sourceMaps = switch $
150+ long "source-maps"
151+ <> help "Generate source maps"
152+
148options :: Parser P.Options
153options :: Parser P.Options
149options = P.Options <$> noTco
154options = P.Options <$> noTco
150 <*> noMagicDo
155 <*> noMagicDo
@@ -153,6 +158,7 @@ options = P.Options <$> noTco
153 <*> verboseErrors
158 <*> verboseErrors
154 <*> (not <$> comments)
159 <*> (not <$> comments)
155 <*> requirePath
160 <*> requirePath
161+ <*> sourceMaps
156
162
157pccOptions :: Parser PCCOptions
163pccOptions :: Parser PCCOptions
158pccOptions = PCCOptions <$> many inputFile
164pccOptions = PCCOptions <$> many inputFile
src/Language/PureScript/CodeGen/Cpp.hs+10−15
@@ -65,7 +65,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
65 cppImports <-
65 cppImports <-
66 traverse (pure . runModuleName) .
66 traverse (pure . runModuleName) .
67 delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $
67 delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $
68− imps
68+ (snd <$> imps)
69 let cppImports' = "PureScript" : cppImports
69 let cppImports' = "PureScript" : cppImports
70 cppDecls <- concat <$> mapM (bindToCpp [CppTopLevel]) decls
70 cppDecls <- concat <$> mapM (bindToCpp [CppTopLevel]) decls
71 cppDecls' <- traverse optimize cppDecls
71 cppDecls' <- traverse optimize cppDecls
@@ -109,22 +109,22 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
109 -------------------------------------------------------------------------------------------------
109 -------------------------------------------------------------------------------------------------
110 bindToCpp :: [CppValueQual] -> Bind Ann -> m [Cpp]
110 bindToCpp :: [CppValueQual] -> Bind Ann -> m [Cpp]
111 -------------------------------------------------------------------------------------------------
111 -------------------------------------------------------------------------------------------------
112− bindToCpp qs (NonRec ident val) = return <$> declToCpp qs ident val
112+ bindToCpp qs (NonRec ann ident val) = return <$> declToCpp qs (ann, ident) val
113 bindToCpp qs (Rec vals) = forM vals (uncurry $ declToCpp (CppRecursive:qs))
113 bindToCpp qs (Rec vals) = forM vals (uncurry $ declToCpp (CppRecursive:qs))
114
114
115 -- |
115 -- |
116 -- Desugar a declaration into a variable introduction or named function
116 -- Desugar a declaration into a variable introduction or named function
117 -- declaration.
117 -- declaration.
118 -------------------------------------------------------------------------------------------------
118 -------------------------------------------------------------------------------------------------
119− declToCpp :: [CppValueQual] -> Ident -> Expr Ann -> m Cpp
119+ declToCpp :: [CppValueQual] -> (Ann, Ident) -> Expr Ann -> m Cpp
120 -------------------------------------------------------------------------------------------------
120 -------------------------------------------------------------------------------------------------
121 declToCpp _ _ (Abs (_, _, _, Just IsTypeClassConstructor) _ _) =
121 declToCpp _ _ (Abs (_, _, _, Just IsTypeClassConstructor) _ _) =
122 return CppNoOp
122 return CppNoOp
123
123
124− declToCpp _ (Op _) (Var (_, _, Nothing, _) _) =
124+ declToCpp _ (_, Op _) (Var (_, _, Nothing, _) _) =
125 return CppNoOp -- skip operator aliases
125 return CppNoOp -- skip operator aliases
126
126
127− declToCpp vqs ident (Abs (_, com, ty, _) arg body) = do
127+ declToCpp vqs (_, ident) (Abs (_, com, ty, _) arg body) = do
128 fn <- if argcnt > 1 && CppTopLevel `elem` vqs
128 fn <- if argcnt > 1 && CppTopLevel `elem` vqs
129 then do
129 then do
130 argNames <- replicateM (argcnt - length args' - 1) freshName
130 argNames <- replicateM (argcnt - length args' - 1) freshName
@@ -180,7 +180,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
180 isIndexer (CppIndexer (CppStringLiteral _) (CppVar _)) = True
180 isIndexer (CppIndexer (CppStringLiteral _) (CppVar _)) = True
181 isIndexer _ = False
181 isIndexer _ = False
182
182
183− declToCpp _ ident (Constructor _ _ (ProperName _) []) =
183+ declToCpp _ (_, ident) (Constructor _ _ (ProperName _) []) =
184 return $
184 return $
185 CppFunction
185 CppFunction
186 (identToCpp ident)
186 (identToCpp ident)
@@ -190,7 +190,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
190 (asReturnBlock $
190 (asReturnBlock $
191 CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar "data")])
191 CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar "data")])
192
192
193− declToCpp _ ident (Constructor _ _ (ProperName _) fields) =
193+ declToCpp _ (_, ident) (Constructor _ _ (ProperName _) fields) =
194 return . CppNamespace "" $
194 return . CppNamespace "" $
195 [ CppFunction
195 [ CppFunction
196 name
196 name
@@ -227,7 +227,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
227 (CppBlock $ fieldLambdas fs') ]
227 (CppBlock $ fieldLambdas fs') ]
228 | otherwise = [CppReturn $ CppApp (CppVar name) (CppVar <$> fields')]
228 | otherwise = [CppReturn $ CppApp (CppVar name) (CppVar <$> fields')]
229
229
230− declToCpp qs ident e
230+ declToCpp qs (_, ident) e
231 | Just ty <- exprType e,
231 | Just ty <- exprType e,
232 CppTopLevel `elem` qs,
232 CppTopLevel `elem` qs,
233 argcnt <- countArgs ty,
233 argcnt <- countArgs ty,
@@ -262,7 +262,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
262 aty = Just $ CppAny [CppConst, CppRef]
262 aty = Just $ CppAny [CppConst, CppRef]
263 rty = Just $ CppAny []
263 rty = Just $ CppAny []
264
264
265− declToCpp _ ident val = do
265+ declToCpp _ (_, ident) val = do
266 val' <- valueToCpp val
266 val' <- valueToCpp val
267 return $
267 return $
268 CppVariableIntroduction
268 CppVariableIntroduction
@@ -750,16 +750,11 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
750 | mn /= mn' = CppAccessor (CppVar . identToCpp $ f a) (CppVar (moduleNameToCpp mn'))
750 | mn /= mn' = CppAccessor (CppVar . identToCpp $ f a) (CppVar (moduleNameToCpp mn'))
751 qualifiedToCpp f (Qualified _ a) = CppVar $ identToCpp (f a)
751 qualifiedToCpp f (Qualified _ a) = CppVar $ identToCpp (f a)
752
752
753− -------------------------------------------------------------------------------------------------
754− qualifiedToStr' :: (a -> Ident) -> Qualified a -> String
755− -------------------------------------------------------------------------------------------------
756− qualifiedToStr' = qualifiedToStr mn
757−
758 -- |
753 -- |
759 -- Find a class in scope by name, retrieving its list of constraints, function names and types.
754 -- Find a class in scope by name, retrieving its list of constraints, function names and types.
760 --
755 --
761 -------------------------------------------------------------------------------------------------
756 -------------------------------------------------------------------------------------------------
762− findClass :: Qualified (ProperName ClassName) -> Maybe ([String], [T.Constraint], [(String, T.Type)])
757+ findClass :: Qualified (ProperName 'ClassName) -> Maybe ([String], [T.Constraint], [(String, T.Type)])
763 -------------------------------------------------------------------------------------------------
758 -------------------------------------------------------------------------------------------------
764 findClass name
759 findClass name
765 | Just (params, fns, constraints) <- M.lookup name (E.typeClasses env),
760 | 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
38import Language.PureScript.CodeGen.Cpp.AST
38import Language.PureScript.CodeGen.Cpp.AST
39import Language.PureScript.CodeGen.Cpp.Types
39import Language.PureScript.CodeGen.Cpp.Types
40import Language.PureScript.Comments
40import Language.PureScript.Comments
41−import Language.PureScript.Pretty.Common
41+-- import Language.PureScript.Pretty.Common
42import qualified Language.PureScript.Constants as C
42import qualified Language.PureScript.Constants as C
43−
44import Numeric
43import Numeric
45−
46-- import Debug.Trace
44-- import Debug.Trace
47
45
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+
48literals :: Pattern PrinterState Cpp String
78literals :: Pattern PrinterState Cpp String
49literals = mkPattern' match
79literals = mkPattern' match
50 where
80 where