git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'pure11' of github.com:pure11/purescript into pure11-0.8
commit99894e5365769388a73df0b930210424cea1c283 authorAndy Arvanitis <andyarvanitis@gmail.com> dateWed 20 Jan 2016, 19:15 (11 years ago) parent0abf1468d70001
5 files changed+11−9
pcc/include/purescript.hh+1 src/Language/PureScript/CodeGen/Cpp.hs+6−3 src/Language/PureScript/CodeGen/Cpp/Common.hs+1−4 src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1 src/Language/PureScript/Pretty/Cpp.hs+2−1
pcc/include/purescript.hh+1
@@ -56,6 +56,7 @@ public:
5656};
5757
5858const bool undefined = false;
59+const std::vector<int>::size_type kDataCtor = 0;
5960
6061// A variant data class designed to provide some features of dynamic typing.
6162//
src/Language/PureScript/CodeGen/Cpp.hs+6−3
@@ -26,6 +26,7 @@ module Language.PureScript.CodeGen.Cpp
2626 , P.prettyPrintCpp
2727 ) where
2828
29+import Data.Char (isLetter)
2930import Data.List
3031import Data.Function (on)
3132import qualified Data.Map as M
@@ -146,7 +147,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
146147 CppLambda [CppCaptureAll] (farg <$> [f'])
147148 (Just $ CppAny [])
148149 (CppBlock $ fieldLambdas fs')]
149− | otherwise = [CppReturn (CppObjectLiteral ((ctorKey, CppStringLiteral name) : zip fields' (CppVar <$> fields')))]
150+ | otherwise = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
150151
151152 declToCpp _ ident val = do
152153 val' <- valueToCpp val
@@ -404,7 +405,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
404405 return $ case ctorType of
405406 ProductType -> cpps
406407 SumType ->
407− [ CppIfElse (CppBinary Equal (CppIndexer (CppStringLiteral ctorKey) (CppVar varName))
408+ [ CppIfElse (CppBinary Equal (CppIndexer (CppVar ctorKey) (CppVar varName))
408409 (CppStringLiteral ctor'))
409410 (CppBlock cpps)
410411 Nothing ]
@@ -417,8 +418,10 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
417418 cpps <- binderToCpp argVar done'' binder
418419 return (CppVariableIntroduction (argVar, Nothing)
419420 []
420− (Just (CppIndexer (CppStringLiteral $ identToCpp field) (CppVar varName)))
421+ (Just (CppIndexer (fieldToIndex field) (CppVar varName)))
421422 : cpps)
423+ fieldToIndex :: Ident -> Cpp
424+ fieldToIndex = CppNumericLiteral . Left . (+1) . read . dropWhile isLetter . runIdent
422425
423426 binderToCpp _ _ b@(ConstructorBinder{}) =
424427 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b
src/Language/PureScript/CodeGen/Cpp/Common.hs+1−4
@@ -106,7 +106,6 @@ nameIsCppReserved name =
106106 , "decltype"
107107 , "default"
108108 , "delete"
109− , "djb2"
110109 , "do"
111110 , "double"
112111 , "dynamic_cast"
@@ -121,15 +120,13 @@ nameIsCppReserved name =
121120 , "for"
122121 , "friend"
123122 , "goto"
124− , "HASH"
125123 , "if"
126124 , "import"
125+ , "kDataCtor"
127126 , "inline"
128127 , "int"
129− , "KEY"
130128 , "list"
131129 , "long"
132− , "map_key_t"
133130 , "mutable"
134131 , "namespace"
135132 , "new"
src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1
@@ -118,4 +118,4 @@ unthunkMarkerValue :: String
118118unthunkMarkerValue = "any::unthunk"
119119
120120ctorKey :: String
121−ctorKey = "constructor"
121+ctorKey = "kDataCtor"
src/Language/PureScript/Pretty/Cpp.hs+2−1
@@ -303,7 +303,8 @@ accessor = mkPattern match
303303indexer :: Pattern PrinterState Cpp (String, Cpp)
304304indexer = mkPattern' match
305305 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)
307308 match (CppIndexer index val) = do
308309 index' <- prettyPrintCpp' index
309310 return (index', val)