@@ -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
@@ -149,7 +150,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
149 CppLambda [CppCaptureAll] (farg <$> [f'])
150 CppLambda [CppCaptureAll] (farg <$> [f'])
150 (Just $ CppAny [])
151 (Just $ CppAny [])
151 (CppBlock $ fieldLambdas fs')]
152 (CppBlock $ fieldLambdas fs')]
152− | otherwise = [CppReturn (CppObjectLiteral ((ctorKey, CppStringLiteral name) : zip fields' (CppVar <$> fields')))]
153+ | otherwise = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
154 declToCpp _ ident val = do
155 declToCpp _ ident val = do
155 val' <- valueToCpp val
156 val' <- valueToCpp val
@@ -407,7 +408,7 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
407 return $ case ctorType of
408 return $ case ctorType of
408 ProductType -> cpps
409 ProductType -> cpps
409 SumType ->
410 SumType ->
410− [ CppIfElse (CppBinary Equal (CppIndexer (CppStringLiteral ctorKey) (CppVar varName))
411+ [ CppIfElse (CppBinary Equal (CppIndexer (CppVar ctorKey) (CppVar varName))
411 (CppStringLiteral ctor'))
412 (CppStringLiteral ctor'))
412 (CppBlock cpps)
413 (CppBlock cpps)
413 Nothing ]
414 Nothing ]
@@ -420,8 +421,10 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
420 cpps <- binderToCpp argVar done'' binder
421 cpps <- binderToCpp argVar done'' binder
421 return (CppVariableIntroduction (argVar, Nothing)
422 return (CppVariableIntroduction (argVar, Nothing)
423− (Just (CppIndexer (CppStringLiteral $ identToCpp field) (CppVar varName)))
424+ (Just (CppIndexer (fieldToIndex field) (CppVar varName)))
426+ fieldToIndex :: Ident -> Cpp
427+ fieldToIndex = CppNumericLiteral . Left . (+1) . read . dropWhile isLetter . runIdent
426 binderToCpp _ _ b@(ConstructorBinder{}) =
429 binderToCpp _ _ b@(ConstructorBinder{}) =
427 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b
430 error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b