@@ -110,7 +110,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
110110 symbols = allSymbols bodyCpps
111111 moduleBody =
112112 CppInclude (runModuleName mn) (runModuleName mn) :
113− symbolDefs symbols :
113+ (CppDefineSymbol <$> symbols) ++
114114 (if null bodyCpps
115115 then []
116116 else [ CppNamespace (runModuleName mn) $
@@ -235,7 +235,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
235235 isAccessor Accessor {} = True
236236 isAccessor _ = False
237237 isGet :: Cpp -> Bool
238− isGet (CppGet (CppSymbol _) (CppVar _)) = True
238+ isGet (CppMapGet (CppSymbol _) (CppVar _)) = True
239239 isGet _ = False
240240 classes =
241241 zip
@@ -249,7 +249,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
249249 []
250250 (Just $ Any [])
251251 [Inline]
252− (returnBlock $ CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar "data")])
252+ (returnBlock $ CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar ctorNS)])
253253 declToCpp _ (_, ident) (Constructor _ _ (ProperName _) fields) =
254254 return . CppNamespace "" $
255255 [ CppFunction
@@ -258,7 +258,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
258258 (Just $ Any [])
259259 [Inline]
260260 (returnBlock $
261− CppDataLiteral $ CppAccessor (CppVar name) (CppVar "data") : (CppVar <$> fields'))
261+ CppDataLiteral $ CppAccessor (CppVar name) (CppVar ctorNS) : (CppVar <$> fields'))
262262 ] ++
263263 if length fields > 0
264264 then [ CppFunction
@@ -387,13 +387,12 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
387387 accessed dictname name =
388388 ( name
389389 , CppApp
390− (CppIndexer
390+ (CppDataGet
391391 (CppNumericLiteral . Left . fromIntegral . fromJust $ findIndex ((== name) . fst) fns)
392− dict'')
392+ dict')
393393 [dict'])
394394 where
395395 dict' = CppVar dictname
396− dict'' = CppCast (dataType 1) dict'
397396 accessor :: Text -> (Text, Cpp) -> Cpp
398397 accessor dictname (name, _) =
399398 CppVariableIntroduction (name, Just $ Any [Const]) [] (Just . snd $ accessed dictname name)
@@ -444,13 +443,13 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
444443 valueToCpp (Literal _ (ObjectLiteral ps)) =
445444 CppMapLiteral Record <$>
446445 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
448447 -- TODO: use a more efficient way of copying/updating the map?
449448 valueToCpp (ObjectUpdate (_, _, Just ty, _) obj ps) = do
450449 obj' <- valueToCpp obj
451450 updatedFields <- mapM (sndM valueToCpp) ps
452451 let origKeys = (allKeys ty) \\ (fst <$> updatedFields)
453− origFields = (\key -> (key, CppGet (CppSymbol key) obj')) <$> origKeys
452+ origFields = (\key -> (key, CppMapGet (CppSymbol key) obj')) <$> origKeys
454453 return $
455454 CppMapLiteral Record $
456455 (\(k, v) -> (CppSymbol k, v)) <$> sortBy (compare `on` fst) (origFields ++ updatedFields)
@@ -603,7 +602,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
603602 [ CppIfElse
604603 (CppBinary
605604 EqualTo
606− (CppIndexer (CppVar ctorKey) (CppCast (dataType 1) $ CppVar varName))
605+ (CppApp (CppVar getCtor) [CppVar varName])
607606 ctorCpp)
608607 (CppBlock cpps)
609608 Nothing
@@ -620,16 +619,16 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
620619 (argVar, Nothing)
621620 []
622621 (Just $
623− CppIndexer
622+ CppDataGet
624623 (fieldToIndex' field)
625− (CppCast (dataType $ fieldToIndex field + 1) $ CppVar varName)) :
624+ (CppVar varName)) :
626625 cpps
627626 fieldToIndex :: Ident -> Int
628627 fieldToIndex = (+ 1) . read . dropWhile isLetter . unpack . runIdent
629628 fieldToIndex' :: Ident -> Cpp
630629 fieldToIndex' = CppNumericLiteral . Left . toInteger . fieldToIndex
631630 ctor' :: Cpp
632− ctor' = CppAccessor (CppVar . identToCpp $ Ident ctor) (CppVar "data")
631+ ctor' = CppAccessor (CppVar $ safeName ctor) (CppVar ctorNS)
633632 ctorCpp :: Cpp
634633 ctorCpp
635634 | Just mn'' <- mn'
@@ -678,18 +677,16 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
678677 CppVariableIntroduction
679678 (propVar, Nothing)
680679 []
681− (Just $ CppGet (CppSymbol prop) (CppVar varName)) :
680+ (Just $ CppMapGet (CppSymbol prop) (CppVar varName)) :
682681 cpp
683682 literalToBinderCpp varName done (ArrayLiteral bs) = do
684683 cpp <- go done 0 bs
685684 let cond =
686685 case length bs of
687− 0 -> CppBinary Dot (CppCast arrayType $ CppVar varName) (CppApp (CppVar "empty") [])
688− n ->
689− let var = CppCast arrayType $ CppVar varName
690− in CppBinary
686+ 0 -> CppBinary Dot (CppVar varName) (CppApp (CppVar "empty") [])
687+ n -> CppBinary
691688 EqualTo
692− (CppBinary Dot var (CppApp (CppVar "size") []))
689+ (CppBinary Dot (CppVar varName) (CppApp (CppVar "size") []))
693690 (CppNumericLiteral (Left (fromIntegral n)))
694691 return [CppIfElse cond (CppBlock cpp) Nothing]
695692 where
@@ -753,7 +750,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
753750 -------------------------------------------------------------------------------------------------
754751 dataCtors =
755752 [ CppNamespace
756− "data"
753+ ctorNS
757754 [ CppEnum Nothing (Just intType) . ("_" :) . catMaybes . map modCtor . M.keys $
758755 E.dataConstructors env
759756 ]
@@ -761,7 +758,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
761758 where
762759 modCtor :: Qualified (ProperName a) -> Maybe Text
763760 modCtor (Qualified (Just mn') (ProperName name))
764− | mn' == mn = Just $ identToCpp (Ident name)
761+ | mn' == mn = Just (safeName name)
765762 modCtor _ = Nothing
766763 -------------------------------------------------------------------------------------------------
767764 curriedForeigns :: m [Cpp]
@@ -840,10 +837,10 @@ optIndexers :: [(Cpp, Cpp)] -> Cpp -> Cpp
840837optIndexers classes = everywhereOnCpp dictIndexerToEnum
841838 where
842839 dictIndexerToEnum :: Cpp -> Cpp
843− dictIndexerToEnum (CppGet (CppSymbol prop) dict)
840+ dictIndexerToEnum (CppMapGet (CppSymbol prop) dict)
844841 | Just cls <- lookup dict classes =
845− let index = CppAccessor (CppVar . identToCpp $ Ident prop) cls
846− in CppGet index dict
842+ let index = CppAccessor (CppVar $ safeName prop) cls
843+ in CppMapGet index dict
847844 dictIndexerToEnum cpp = cpp
848845
849846---------------------------------------------------------------------------------------------------
@@ -852,8 +849,8 @@ curriedName :: Text -> Text
852849curriedName name
853850 | Text.null name = name
854851curriedName name
855− | Text.head name == '$' = name
856− | otherwise = '$' `Text.cons` name
852+ | Text.head name == '*' = name
853+ | otherwise = '*' `Text.cons` name
857854
858855---------------------------------------------------------------------------------------------------
859856curriedName' :: Cpp -> Cpp
@@ -889,7 +886,7 @@ convertIfPrimFn :: Maybe T.Type -> Cpp -> Cpp
889886convertIfPrimFn ty@(Just _) (CppNamespace ns fs) = CppNamespace ns (convertIfPrimFn ty <$> fs)
890887convertIfPrimFn (Just _) cpp@(CppFunction name _ _ _ _)
891888 | not $ Text.null name
892− , Text.head name == '$' = cpp
889+ , Text.head name == '*' = cpp
893890convertIfPrimFn (Just ty) (CppFunction name params _ qs body)
894891 | (tys', Just rty') <- primFn ty =
895892 CppFunction name (zipWith (\(p, _) t -> (p, Just t)) params tys') (Just rty') qs body
@@ -901,18 +898,9 @@ allSymbols :: [Cpp] -> [Text]
901898allSymbols cpps = nub $ concatMap (everythingOnCpp (++) symbols) cpps
902899 where
903900 symbols :: Cpp -> [Text]
904− symbols (CppSymbol s) = [symbolname s]
901+ symbols (CppSymbol s) = [s]
905902 symbols _ = []
906903
907−---------------------------------------------------------------------------------------------------
908−symbolDefs :: [Text] -> Cpp
909−---------------------------------------------------------------------------------------------------
910−symbolDefs [] = CppNoOp
911−symbolDefs syms = CppNamespace "PureScript" [CppNamespace "symbol" (asStruct <$> syms)]
912− where
913− asStruct :: Text -> Cpp
914− asStruct s = CppStruct s []
915−
916904---------------------------------------------------------------------------------------------------
917905filterInlineFuncs :: Cpp -> Cpp
918906---------------------------------------------------------------------------------------------------