@@ -110,7 +110,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
110 symbols = allSymbols bodyCpps
110 symbols = allSymbols bodyCpps
111 moduleBody =
111 moduleBody =
112 CppInclude (runModuleName mn) (runModuleName mn) :
112 CppInclude (runModuleName mn) (runModuleName mn) :
113− symbolDefs symbols :
113+ (CppDefineSymbol <$> symbols) ++
114 (if null bodyCpps
114 (if null bodyCpps
116 else [ CppNamespace (runModuleName mn) $
116 else [ CppNamespace (runModuleName mn) $
@@ -235,7 +235,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
235 isAccessor Accessor {} = True
235 isAccessor Accessor {} = True
236 isAccessor _ = False
236 isAccessor _ = False
237 isGet :: Cpp -> Bool
237 isGet :: Cpp -> Bool
238− isGet (CppGet (CppSymbol _) (CppVar _)) = True
238+ isGet (CppMapGet (CppSymbol _) (CppVar _)) = True
239 isGet _ = False
239 isGet _ = False
240 classes =
240 classes =
@@ -249,7 +249,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
250 (Just $ Any [])
250 (Just $ Any [])
252− (returnBlock $ CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar "data")])
252+ (returnBlock $ CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar ctorNS)])
253 declToCpp _ (_, ident) (Constructor _ _ (ProperName _) fields) =
253 declToCpp _ (_, ident) (Constructor _ _ (ProperName _) fields) =
254 return . CppNamespace "" $
254 return . CppNamespace "" $
255 [ CppFunction
255 [ CppFunction
@@ -258,7 +258,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
258 (Just $ Any [])
258 (Just $ Any [])
260 (returnBlock $
260 (returnBlock $
261− CppDataLiteral $ CppAccessor (CppVar name) (CppVar "data") : (CppVar <$> fields'))
261+ CppDataLiteral $ CppAccessor (CppVar name) (CppVar ctorNS) : (CppVar <$> fields'))
263 if length fields > 0
263 if length fields > 0
264 then [ CppFunction
264 then [ CppFunction
@@ -387,13 +387,12 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
387 accessed dictname name =
387 accessed dictname name =
390− (CppIndexer
390+ (CppDataGet
391 (CppNumericLiteral . Left . fromIntegral . fromJust $ findIndex ((== name) . fst) fns)
391 (CppNumericLiteral . Left . fromIntegral . fromJust $ findIndex ((== name) . fst) fns)
395 dict' = CppVar dictname
395 dict' = CppVar dictname
396− dict'' = CppCast (dataType 1) dict'
397 accessor :: Text -> (Text, Cpp) -> Cpp
396 accessor :: Text -> (Text, Cpp) -> Cpp
398 accessor dictname (name, _) =
397 accessor dictname (name, _) =
399 CppVariableIntroduction (name, Just $ Any [Const]) [] (Just . snd $ accessed dictname name)
398 CppVariableIntroduction (name, Just $ Any [Const]) [] (Just . snd $ accessed dictname name)
@@ -444,13 +443,13 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
444 valueToCpp (Literal _ (ObjectLiteral ps)) =
443 valueToCpp (Literal _ (ObjectLiteral ps)) =
445 CppMapLiteral Record <$>
444 CppMapLiteral Record <$>
446 mapM (sndM valueToCpp) ((\(k, v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) ps)
445 mapM (sndM valueToCpp) ((\(k, v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) ps)
447− valueToCpp (Accessor _ prop val) = CppGet <$> pure (CppSymbol prop) <*> valueToCpp val
446+ valueToCpp (Accessor _ prop val) = CppMapGet <$> pure (CppSymbol prop) <*> valueToCpp val
448 -- TODO: use a more efficient way of copying/updating the map?
447 -- TODO: use a more efficient way of copying/updating the map?
449 valueToCpp (ObjectUpdate (_, _, Just ty, _) obj ps) = do
448 valueToCpp (ObjectUpdate (_, _, Just ty, _) obj ps) = do
450 obj' <- valueToCpp obj
449 obj' <- valueToCpp obj
451 updatedFields <- mapM (sndM valueToCpp) ps
450 updatedFields <- mapM (sndM valueToCpp) ps
452 let origKeys = (allKeys ty) \\ (fst <$> updatedFields)
451 let origKeys = (allKeys ty) \\ (fst <$> updatedFields)
453− origFields = (\key -> (key, CppGet (CppSymbol key) obj')) <$> origKeys
452+ origFields = (\key -> (key, CppMapGet (CppSymbol key) obj')) <$> origKeys
455 CppMapLiteral Record $
454 CppMapLiteral Record $
456 (\(k, v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) (origFields ++ updatedFields)
455 (\(k, v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) (origFields ++ updatedFields)
@@ -603,7 +602,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
603 [ CppIfElse
602 [ CppIfElse
604 (CppBinary
603 (CppBinary
606− (CppIndexer (CppVar ctorKey) (CppCast (dataType 1) $ CppVar varName))
605+ (CppApp (CppVar getCtor) [CppVar varName])
608 (CppBlock cpps)
607 (CppBlock cpps)
@@ -620,16 +619,16 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
620 (argVar, Nothing)
619 (argVar, Nothing)
623− CppIndexer
622+ CppDataGet
624 (fieldToIndex' field)
623 (fieldToIndex' field)
625− (CppCast (dataType $ fieldToIndex field + 1) $ CppVar varName)) :
624+ (CppVar varName)) :
627 fieldToIndex :: Ident -> Int
626 fieldToIndex :: Ident -> Int
628 fieldToIndex = (+ 1) . read . dropWhile isLetter . unpack . runIdent
627 fieldToIndex = (+ 1) . read . dropWhile isLetter . unpack . runIdent
629 fieldToIndex' :: Ident -> Cpp
628 fieldToIndex' :: Ident -> Cpp
630 fieldToIndex' = CppNumericLiteral . Left . toInteger . fieldToIndex
629 fieldToIndex' = CppNumericLiteral . Left . toInteger . fieldToIndex
631 ctor' :: Cpp
630 ctor' :: Cpp
632− ctor' = CppAccessor (CppVar . identToCpp $ Ident ctor) (CppVar "data")
631+ ctor' = CppAccessor (CppVar $ safeName ctor) (CppVar ctorNS)
633 ctorCpp :: Cpp
632 ctorCpp :: Cpp
635 | Just mn'' <- mn'
634 | Just mn'' <- mn'
@@ -678,18 +677,16 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
678 CppVariableIntroduction
677 CppVariableIntroduction
679 (propVar, Nothing)
678 (propVar, Nothing)
681− (Just $ CppGet (CppSymbol prop) (CppVar varName)) :
680+ (Just $ CppMapGet (CppSymbol prop) (CppVar varName)) :
683 literalToBinderCpp varName done (ArrayLiteral bs) = do
682 literalToBinderCpp varName done (ArrayLiteral bs) = do
684 cpp <- go done 0 bs
683 cpp <- go done 0 bs
685 let cond =
684 let cond =
686 case length bs of
685 case length bs of
687− 0 -> CppBinary Dot (CppCast arrayType $ CppVar varName) (CppApp (CppVar "empty") [])
686+ 0 -> CppBinary Dot (CppVar varName) (CppApp (CppVar "empty") [])
689− let var = CppCast arrayType $ CppVar varName
690− in CppBinary
687+ n -> CppBinary
692− (CppBinary Dot var (CppApp (CppVar "size") []))
689+ (CppBinary Dot (CppVar varName) (CppApp (CppVar "size") []))
693 (CppNumericLiteral (Left (fromIntegral n)))
690 (CppNumericLiteral (Left (fromIntegral n)))
694 return [CppIfElse cond (CppBlock cpp) Nothing]
691 return [CppIfElse cond (CppBlock cpp) Nothing]
@@ -753,7 +750,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
753 -------------------------------------------------------------------------------------------------
750 -------------------------------------------------------------------------------------------------
754 dataCtors =
751 dataCtors =
755 [ CppNamespace
752 [ CppNamespace
757 [ CppEnum Nothing (Just intType) . ("_" :) . catMaybes . map modCtor . M.keys $
754 [ CppEnum Nothing (Just intType) . ("_" :) . catMaybes . map modCtor . M.keys $
758 E.dataConstructors env
755 E.dataConstructors env
@@ -761,7 +758,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
762 modCtor :: Qualified (ProperName a) -> Maybe Text
759 modCtor :: Qualified (ProperName a) -> Maybe Text
763 modCtor (Qualified (Just mn') (ProperName name))
760 modCtor (Qualified (Just mn') (ProperName name))
764− | mn' == mn = Just $ identToCpp (Ident name)
761+ | mn' == mn = Just (safeName name)
765 modCtor _ = Nothing
762 modCtor _ = Nothing
766 -------------------------------------------------------------------------------------------------
763 -------------------------------------------------------------------------------------------------
767 curriedForeigns :: m [Cpp]
764 curriedForeigns :: m [Cpp]
@@ -840,10 +837,10 @@ optIndexers :: [(Cpp, Cpp)] -> Cpp -> Cpp
840optIndexers classes = everywhereOnCpp dictIndexerToEnum
837optIndexers classes = everywhereOnCpp dictIndexerToEnum
842 dictIndexerToEnum :: Cpp -> Cpp
839 dictIndexerToEnum :: Cpp -> Cpp
843− dictIndexerToEnum (CppGet (CppSymbol prop) dict)
840+ dictIndexerToEnum (CppMapGet (CppSymbol prop) dict)
844 | Just cls <- lookup dict classes =
841 | Just cls <- lookup dict classes =
845− let index = CppAccessor (CppVar . identToCpp $ Ident prop) cls
842+ let index = CppAccessor (CppVar $ safeName prop) cls
846− in CppGet index dict
843+ in CppMapGet index dict
847 dictIndexerToEnum cpp = cpp
844 dictIndexerToEnum cpp = cpp
849---------------------------------------------------------------------------------------------------
846---------------------------------------------------------------------------------------------------
@@ -852,8 +849,8 @@ curriedName :: Text -> Text
852curriedName name
849curriedName name
853 | Text.null name = name
850 | Text.null name = name
854curriedName name
851curriedName name
855− | Text.head name == '$' = name
852+ | Text.head name == '*' = name
856− | otherwise = '$' `Text.cons` name
853+ | otherwise = '*' `Text.cons` name
858---------------------------------------------------------------------------------------------------
855---------------------------------------------------------------------------------------------------
859curriedName' :: Cpp -> Cpp
856curriedName' :: Cpp -> Cpp
@@ -889,7 +886,7 @@ convertIfPrimFn :: Maybe T.Type -> Cpp -> Cpp
889convertIfPrimFn ty@(Just _) (CppNamespace ns fs) = CppNamespace ns (convertIfPrimFn ty <$> fs)
886convertIfPrimFn ty@(Just _) (CppNamespace ns fs) = CppNamespace ns (convertIfPrimFn ty <$> fs)
890convertIfPrimFn (Just _) cpp@(CppFunction name _ _ _ _)
887convertIfPrimFn (Just _) cpp@(CppFunction name _ _ _ _)
891 | not $ Text.null name
888 | not $ Text.null name
892− , Text.head name == '$' = cpp
889+ , Text.head name == '*' = cpp
893convertIfPrimFn (Just ty) (CppFunction name params _ qs body)
890convertIfPrimFn (Just ty) (CppFunction name params _ qs body)
894 | (tys', Just rty') <- primFn ty =
891 | (tys', Just rty') <- primFn ty =
895 CppFunction name (zipWith (\(p, _) t -> (p, Just t)) params tys') (Just rty') qs body
892 CppFunction name (zipWith (\(p, _) t -> (p, Just t)) params tys') (Just rty') qs body
@@ -901,18 +898,9 @@ allSymbols :: [Cpp] -> [Text]
901allSymbols cpps = nub $ concatMap (everythingOnCpp (++) symbols) cpps
898allSymbols cpps = nub $ concatMap (everythingOnCpp (++) symbols) cpps
903 symbols :: Cpp -> [Text]
900 symbols :: Cpp -> [Text]
904− symbols (CppSymbol s) = [symbolname s]
901+ symbols (CppSymbol s) = [s]
905 symbols _ = []
902 symbols _ = []
907−---------------------------------------------------------------------------------------------------
908−symbolDefs :: [Text] -> Cpp
909−---------------------------------------------------------------------------------------------------
910−symbolDefs [] = CppNoOp
911−symbolDefs syms = CppNamespace "PureScript" [CppNamespace "symbol" (asStruct <$> syms)]
913− asStruct :: Text -> Cpp
914− asStruct s = CppStruct s []
916---------------------------------------------------------------------------------------------------
904---------------------------------------------------------------------------------------------------
917filterInlineFuncs :: Cpp -> Cpp
905filterInlineFuncs :: Cpp -> Cpp
918---------------------------------------------------------------------------------------------------
906---------------------------------------------------------------------------------------------------