@@ -132,14 +132,13 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
133 (snd abs')
133 (snd abs')
134 (Var nullAnn . Qualified Nothing . Ident $ head argNames)))
134 (Var nullAnn . Qualified Nothing . Ident $ head argNames)))
135− let block' = convertNestedLambdas block
136 return $ CppNamespace ""
135 return $ CppNamespace ""
137 [ CppFunction
136 [ CppFunction
139 (arg' : args' ++ args'')
138 (arg' : args' ++ args'')
141− vqs
140+ (vqs ++ if isAccessor (snd abs') then [CppInline] else [])
142− block'
141+ (convertNestedLambdas block)
143 , CppFunction
142 , CppFunction
144 (curriedName name)
143 (curriedName name)
@@ -152,8 +151,13 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
152 (CppVar . fst <$> (arg' : args' ++ args''))))
151 (CppVar . fst <$> (arg' : args' ++ args''))))
155− block <- asReturnBlock <$> valueToCpp body
154+ block <- valueToCpp body
155+ return $ CppFunction
159+ (vqs ++ if isIndexer block then [CppInline] else [])
156− return $ CppFunction name [arg'] rty vqs (convertNestedLambdas block)
160+ (convertNestedLambdas $ asReturnBlock block)
157 return (CppComment com fn)
161 return (CppComment com fn)
159 argcnt = maybe 0 countArgs ty
163 argcnt = maybe 0 countArgs ty
@@ -163,6 +167,12 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
163 arg' = (identToCpp arg, aty)
167 arg' = (identToCpp arg, aty)
164 args' = (\i -> (identToCpp i, aty)) <$> fst abs'
168 args' = (\i -> (identToCpp i, aty)) <$> fst abs'
165 abs' = unAbs body []
169 abs' = unAbs body []
170+ isAccessor :: Expr Ann -> Bool
171+ isAccessor Accessor{} = True
172+ isAccessor _ = False
173+ isIndexer :: Cpp -> Bool
174+ isIndexer (CppIndexer (CppStringLiteral _) (CppVar _)) = True
167 declToCpp _ ident (Constructor _ _ (ProperName _) []) =
177 declToCpp _ ident (Constructor _ _ (ProperName _) []) =
@@ -420,7 +430,21 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
420 return $ CppApp (uncurried' $ qualifiedToCpp id ident) args'
430 return $ CppApp (uncurried' $ qualifiedToCpp id ident) args'
421 Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
431 Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
422 let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
432 let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
433+ return . CppObjectLiteral $
423− return . CppObjectLiteral $ zip ((sort $ superClassDictionaryNames constraints) ++ (fst <$> fns)) args'
435+ ((sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
436+ (arity2or3 <$> args')
438+ -- For arity 2/3 optimization
439+ arity2or3 :: Cpp -> Cpp
440+ arity2or3 (CppLambda cs [a1] rty
441+ (CppBlock [CppReturn (CppLambda _ [a2] _
442+ (CppBlock [CppReturn (CppLambda _ [a3] _ ret)]))])) =
443+ CppLambda cs [a1, a2, a3] rty ret
444+ arity2or3 (CppLambda cs [a1] rty
445+ (CppBlock [CppReturn (CppLambda _ [a2] _ ret)])) =
446+ CppLambda cs [a1, a2] rty ret
447+ arity2or3 cpp' = cpp'
424 Var ann (Qualified (Just mn') ident)
448 Var ann (Qualified (Just mn') ident)
425 | argcnt <- maybe 0 countArgs ty,
449 | argcnt <- maybe 0 countArgs ty,
426 argcnt > 1 -> do
450 argcnt > 1 -> do
@@ -438,6 +462,10 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
438 ty | (_, _, Just t, _) <- ann = Just t
462 ty | (_, _, Just t, _) <- ann = Just t
439 | Just (t, _, _) <- M.lookup (mn', ident) (E.names env) = Just t
463 | Just (t, _, _) <- M.lookup (mn', ident) (E.names env) = Just t
440 | otherwise = Nothing
464 | otherwise = Nothing
465+ Accessor (_, _, Nothing, Nothing) _ (Var _ (Qualified Nothing (Ident _)))
466+ | length args' == 2 || length args' == 3 -> do -- arity 2 optimization
468+ return $ CppApp f' args'
442 flip (foldl (\fn a -> CppApp fn [a])) args' <$> valueToCpp f
470 flip (foldl (\fn a -> CppApp fn [a])) args' <$> valueToCpp f