@@ -145,7 +145,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
145 | otherwise = ([], [])
145 | otherwise = ([], [])
146 farg = \x -> (x, Just $ CppAny [CppConst, CppRef])
146 farg = \x -> (x, Just $ CppAny [CppConst, CppRef])
147 fieldLambdas flds
147 fieldLambdas flds
148+ | (f' : fs') <- flds = [CppReturn . maybeRemCaps $
148− | (f' : fs') <- flds = [CppReturn $ CppLambda [CppCaptureAll] (farg <$> [f'])
149+ CppLambda [CppCaptureAll] (farg <$> [f'])
149 (Just $ CppAny [])
150 (Just $ CppAny [])
150 (CppBlock $ fieldLambdas fs')]
151 (CppBlock $ fieldLambdas fs')]
151 | otherwise = [CppReturn (CppObjectLiteral ((ctorKey, CppStringLiteral name) : zip fields' (CppVar <$> fields')))]
152 | otherwise = [CppReturn (CppObjectLiteral ((ctorKey, CppStringLiteral name) : zip fields' (CppVar <$> fields')))]
@@ -155,17 +156,17 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
155 return $ CppVariableIntroduction (identToCpp ident, Just $ CppAny [CppConst]) [] (Just val')
156 return $ CppVariableIntroduction (identToCpp ident, Just $ CppAny [CppConst]) [] (Just val')
157 -------------------------------------------------------------------------------------------------
158 -------------------------------------------------------------------------------------------------
158− toLambda :: [CppCaptureType] -> Cpp -> Cpp
159+ fnToLambda :: Cpp -> Cpp
159 -------------------------------------------------------------------------------------------------
160 -------------------------------------------------------------------------------------------------
160− toLambda cs (CppFunction name args _ qs body) =
161+ fnToLambda (CppFunction name args _ qs body) =
161 CppVariableIntroduction (name, Just $ CppAny [CppConst])
162 CppVariableIntroduction (name, Just $ CppAny [CppConst])
162 (filter (==CppStatic) qs)
163 (filter (==CppStatic) qs)
163− (Just (CppLambda cs' args (Just $ CppAny []) body))
164+ (Just (CppLambda cs args (Just $ CppAny []) body))
165− cs' | (not . null) (qs `intersect` [CppInline, CppStatic]) = []
166+ cs | (not . null) (qs `intersect` [CppInline, CppStatic]) = []
166− | otherwise = cs
167+ | otherwise = [CppCaptureAll]
167− toLambda cs (CppComment com cpp) = CppComment com (toLambda cs cpp)
168+ fnToLambda (CppComment com cpp) = CppComment com (fnToLambda cpp)
168− toLambda _ _ = error "Not a function!"
169+ fnToLambda _ = error "Not a function!"
170 -------------------------------------------------------------------------------------------------
171 -------------------------------------------------------------------------------------------------
171 asReturnBlock :: Cpp -> Cpp
172 asReturnBlock :: Cpp -> Cpp
@@ -178,8 +179,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
178 convertNestedLambdas = everywhereOnCpp go
179 convertNestedLambdas = everywhereOnCpp go
180 go :: Cpp -> Cpp
181 go :: Cpp -> Cpp
181− go f@(CppFunction {}) = toLambda [CppCaptureAll] f
182+ go f@(CppFunction {}) = maybeRemCaps $ fnToLambda f
182− go (CppLambda [] args rtyp body) = CppLambda [CppCaptureAll] args rtyp body
183+ go (CppLambda _ args rtyp body) = maybeRemCaps $ CppLambda [CppCaptureAll] args rtyp body
183 go cpp = cpp
184 go cpp = cpp
185 -------------------------------------------------------------------------------------------------
186 -------------------------------------------------------------------------------------------------
@@ -211,11 +212,12 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
212 toelem :: Cpp -> (String, Cpp)
213 toelem :: Cpp -> (String, Cpp)
213 toelem (CppFunction name args rtyp _ (CppBlock body)) =
214 toelem (CppFunction name args rtyp _ (CppBlock body)) =
215+ (name, withdict . maybeRemCaps $ CppLambda [CppCaptureAll]
214− (name, withdict $ CppLambda [CppCaptureAll] args rtyp (CppBlock $ (accessor localdict <$> fns) ++ body))
216+ args rtyp (CppBlock $ (accessor localdict <$> fns) ++ body))
215 toelem _ = error "not a function"
217 toelem _ = error "not a function"
217 withdict :: Cpp -> Cpp
219 withdict :: Cpp -> Cpp
218− withdict cpp' =
220+ withdict cpp' = maybeRemCaps $
219 CppLambda [CppCaptureAll] [(localdict, Just $ CppAny [CppConst, CppRef])]
221 CppLambda [CppCaptureAll] [(localdict, Just $ CppAny [CppConst, CppRef])]
220 (Just $ CppAny [])
222 (Just $ CppAny [])
221 (CppBlock [CppReturn cpp'])
223 (CppBlock [CppReturn cpp'])