@@ -26,6 +26,7 @@ module Language.PureScript.CodeGen.Cpp
26 , P.prettyPrintCpp
26 , P.prettyPrintCpp
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')))]
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)
420− (Just (CppIndexer (CppStringLiteral $ identToCpp field) (CppVar varName)))
421+ (Just (CppIndexer (fieldToIndex field) (CppVar varName)))
423+ fieldToIndex :: Ident -> Cpp
424+ fieldToIndex = CppNumericLiteral . Left . (+1) . read . dropWhile isLetter . runIdent
423 binderToCpp _ _ b@(ConstructorBinder{}) =
426 binderToCpp _ _ b@(ConstructorBinder{}) =
424 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b
427 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b