git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'pure11' of github.com:pure11/purescript into pure11-0.8
99894e5Andy Arvanitis
pcc/include/purescript.hh+1
@@ -56,6 +56,7 @@ public:
56};
56};
57
57
58const bool undefined = false;
58const bool undefined = false;
59+const std::vector<int>::size_type kDataCtor = 0;
59
60
60// A variant data class designed to provide some features of dynamic typing.
61// A variant data class designed to provide some features of dynamic typing.
61//
62//
src/Language/PureScript/CodeGen/Cpp.hs+6−3
@@ -26,6 +26,7 @@ module Language.PureScript.CodeGen.Cpp
26 , P.prettyPrintCpp
26 , P.prettyPrintCpp
27 ) where
27 ) where
28
28
29+import Data.Char (isLetter)
29import Data.List
30import Data.List
30import Data.Function (on)
31import Data.Function (on)
31import qualified Data.Map as M
32import qualified Data.Map as M
@@ -146,7 +147,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
146 CppLambda [CppCaptureAll] (farg <$> [f'])
147 CppLambda [CppCaptureAll] (farg <$> [f'])
147 (Just $ CppAny [])
148 (Just $ CppAny [])
148 (CppBlock $ fieldLambdas fs')]
149 (CppBlock $ fieldLambdas fs')]
149− | otherwise = [CppReturn (CppObjectLiteral ((ctorKey, CppStringLiteral name) : zip fields' (CppVar <$> fields')))]
150+ | otherwise = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
150
151
151 declToCpp _ ident val = do
152 declToCpp _ ident val = do
152 val' <- valueToCpp val
153 val' <- valueToCpp val
@@ -404,7 +405,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
404 return $ case ctorType of
405 return $ case ctorType of
405 ProductType -> cpps
406 ProductType -> cpps
406 SumType ->
407 SumType ->
407− [ CppIfElse (CppBinary Equal (CppIndexer (CppStringLiteral ctorKey) (CppVar varName))
408+ [ CppIfElse (CppBinary Equal (CppIndexer (CppVar ctorKey) (CppVar varName))
408 (CppStringLiteral ctor'))
409 (CppStringLiteral ctor'))
409 (CppBlock cpps)
410 (CppBlock cpps)
410 Nothing ]
411 Nothing ]
@@ -417,8 +418,10 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
417 cpps <- binderToCpp argVar done'' binder
418 cpps <- binderToCpp argVar done'' binder
418 return (CppVariableIntroduction (argVar, Nothing)
419 return (CppVariableIntroduction (argVar, Nothing)
419 []
420 []
420− (Just (CppIndexer (CppStringLiteral $ identToCpp field) (CppVar varName)))
421+ (Just (CppIndexer (fieldToIndex field) (CppVar varName)))
421 : cpps)
422 : cpps)
423+ fieldToIndex :: Ident -> Cpp
424+ fieldToIndex = CppNumericLiteral . Left . (+1) . read . dropWhile isLetter . runIdent
422
425
423 binderToCpp _ _ b@(ConstructorBinder{}) =
426 binderToCpp _ _ b@(ConstructorBinder{}) =
424 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b
427 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b
src/Language/PureScript/CodeGen/Cpp/Common.hs+1−4
@@ -106,7 +106,6 @@ nameIsCppReserved name =
106 , "decltype"
106 , "decltype"
107 , "default"
107 , "default"
108 , "delete"
108 , "delete"
109− , "djb2"
110 , "do"
109 , "do"
111 , "double"
110 , "double"
112 , "dynamic_cast"
111 , "dynamic_cast"
@@ -121,15 +120,13 @@ nameIsCppReserved name =
121 , "for"
120 , "for"
122 , "friend"
121 , "friend"
123 , "goto"
122 , "goto"
124− , "HASH"
125 , "if"
123 , "if"
126 , "import"
124 , "import"
125+ , "kDataCtor"
127 , "inline"
126 , "inline"
128 , "int"
127 , "int"
129− , "KEY"
130 , "list"
128 , "list"
131 , "long"
129 , "long"
132− , "map_key_t"
133 , "mutable"
130 , "mutable"
134 , "namespace"
131 , "namespace"
135 , "new"
132 , "new"
src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1
@@ -118,4 +118,4 @@ unthunkMarkerValue :: String
118unthunkMarkerValue = "any::unthunk"
118unthunkMarkerValue = "any::unthunk"
119
119
120ctorKey :: String
120ctorKey :: String
121−ctorKey = "constructor"
121+ctorKey = "kDataCtor"
src/Language/PureScript/Pretty/Cpp.hs+2−1
@@ -303,7 +303,8 @@ accessor = mkPattern match
303indexer :: Pattern PrinterState Cpp (String, Cpp)
303indexer :: Pattern PrinterState Cpp (String, Cpp)
304indexer = mkPattern' match
304indexer = mkPattern' match
305 where
305 where
306− match (CppIndexer (CppNumericLiteral (Left index)) val) = return (show index ++ "UL", val)
306+ match (CppIndexer (CppNumericLiteral (Left 0)) val) = return ("0UL", val)
307+ match (CppIndexer (CppNumericLiteral (Left index)) val) = return (show index, val)
307 match (CppIndexer index val) = do
308 match (CppIndexer index val) = do
308 index' <- prettyPrintCpp' index
309 index' <- prettyPrintCpp' index
309 return (index', val)
310 return (index', val)