@@ -1,9 +1,9 @@
11-- | This module generates code in the core imperative representation from
22-- elaborated PureScript code.
3−module CodeGen.Cpp
3+module CodeGen.IL
44 ( module AST
55 , module Common
6− , moduleToCpp
6+ , moduleToIL
77 ) where
88
99import Prelude.Compat
@@ -35,39 +35,39 @@ import qualified Language.PureScript.Constants as C
3535
3636import System.FilePath.Posix ((</>))
3737
38−import CodeGen.Cpp.Common as Common
39−import CodeGen.Cpp.Optimizer
40−import CodeGen.Cpp.Printer
38+import CodeGen.IL.Common as Common
39+import CodeGen.IL.Optimizer
40+import CodeGen.IL.Printer
4141
4242data DeclType = ModuleDecl | LetDecl | RecLetDecl deriving (Eq)
4343
4444-- | Generate code in the simplified intermediate representation for all declarations in a
4545-- module.
46−moduleToCpp
46+moduleToIL
4747 :: forall m
4848 -- . (Monad m, MonadReader Options m, MonadSupply m, MonadError MultipleErrors m)
4949 . (Monad m, MonadSupply m)
5050 => Module Ann
5151 -> Maybe AST
5252 -> m (Text, [Text], [AST], Text, Text)
53−moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
53+moduleToIL (Module _ coms mn _ imps _ foreigns decls) _ =
5454 do
5555 let usedNames = concatMap getNames decls
5656 let mnLookup = renameImports usedNames imps
57− cppImports <- traverse (importToCpp mnLookup) . (\\ (mn : C.primModules)) . (\\ [mn]) $ ordNub $ map snd imps
58− interfaceImport <- importToCpp (renameImports [] [(emptyAnn, mn)]) mn
57+ ilImports <- traverse (importToIL mnLookup) . (\\ (mn : C.primModules)) . (\\ [mn]) $ ordNub $ map snd imps
58+ interfaceImport <- importToIL (renameImports [] [(emptyAnn, mn)]) mn
5959 let decls' = renameModules mnLookup decls
60− cppDecls <- mapM (bindToCpp ModuleDecl) decls'
61− optimized <- traverse (traverse (optimize modName')) cppDecls
60+ ilDecls <- mapM (bindToIL ModuleDecl) decls'
61+ optimized <- traverse (traverse (optimize modName')) ilDecls
6262 let optimized' = concat optimized
6363 values = annotValue <$> optimized'
64− foreigns' = identToCpp <$> foreigns
64+ foreigns' = identToIL <$> foreigns
6565 interface = interfaceSource modName values foreigns
66− implHeader = implHeaderSource modName cppImports interfaceImport
66+ implHeader = implHeaderSource modName ilImports interfaceImport
6767 implFooter = implFooterSource modName foreigns
6868 return $ (interface, foreigns', optimized', implHeader, implFooter)
6969 where
70− modName = moduleNameToCpp mn
70+ modName = moduleNameToIL mn
7171 modName' = AST.Var Nothing modName
7272
7373 annotValue :: AST -> (Text, Bool)
@@ -104,10 +104,10 @@ moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
104104
105105 -- | Generates C++ code for a module import, binding the required module
106106 -- to the alternative
107− importToCpp :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m Text
108− importToCpp mnLookup mn' = do
107+ importToIL :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m Text
108+ importToIL mnLookup mn' = do
109109 let ((_, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
110− mname = moduleNameToCpp mnSafe
110+ mname = moduleNameToIL mnSafe
111111 pure $ "#include \"" <> mname <> "/" <> mname <> ".h\"\n"
112112
113113 -- | Replaces the `ModuleName`s in the AST so that the generated code refers to
@@ -132,9 +132,9 @@ moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
132132 -- |
133133 -- Generate code in the simplified intermediate representation for a declaration
134134 --
135− bindToCpp :: DeclType -> Bind Ann -> m [AST]
136− bindToCpp dt (NonRec ann ident val) = return <$> nonRecToCpp dt ann ident val
137− bindToCpp dt (Rec vals) = forM vals (uncurry . uncurry $ nonRecToCpp dt')
135+ bindToIL :: DeclType -> Bind Ann -> m [AST]
136+ bindToIL dt (NonRec ann ident val) = return <$> nonRecToIL dt ann ident val
137+ bindToIL dt (Rec vals) = forM vals (uncurry . uncurry $ nonRecToIL dt')
138138 where
139139 dt' = if dt == LetDecl then RecLetDecl else dt
140140
@@ -142,39 +142,39 @@ moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
142142 -- declaration.
143143 --
144144 -- The main purpose of this function is to handle code generation for comments.
145− nonRecToCpp :: DeclType -> Ann -> Ident -> Expr Ann -> m AST
146− nonRecToCpp dt a i e@(extractAnn -> (_, com, _, _)) | not (null com) = do
145+ nonRecToIL :: DeclType -> Ann -> Ident -> Expr Ann -> m AST
146+ nonRecToIL dt a i e@(extractAnn -> (_, com, _, _)) | not (null com) = do
147147 -- withoutComment <- asks optionsNoComments
148148 let withoutComment = False
149149 if withoutComment
150− then nonRecToCpp dt a i (modifyAnn removeComments e)
151− else AST.Comment Nothing com <$> nonRecToCpp dt a i (modifyAnn removeComments e)
152− nonRecToCpp ModuleDecl (ss, _, _, _) ident val = do
153− cpp <- valueToCpp val
154− pure $ AST.Function Nothing (Just $ identToCpp ident) [] (AST.Block Nothing [AST.Return Nothing cpp])
155− nonRecToCpp RecLetDecl (ss, _, _, _) ident val = do
156− cpp <- valueToCpp val
150+ then nonRecToIL dt a i (modifyAnn removeComments e)
151+ else AST.Comment Nothing com <$> nonRecToIL dt a i (modifyAnn removeComments e)
152+ nonRecToIL ModuleDecl (ss, _, _, _) ident val = do
153+ il <- valueToIL val
154+ pure $ AST.Function Nothing (Just $ identToIL ident) [] (AST.Block Nothing [AST.Return Nothing il])
155+ nonRecToIL RecLetDecl (ss, _, _, _) ident val = do
156+ il <- valueToIL val
157157 pure $
158− let retainedName = identToCpp ident
158+ let retainedName = identToIL ident
159159 retained = AST.Var Nothing $ retainedName
160160 unretainedName = retainedName <> unretainedSuffix
161161 unretained = AST.Var Nothing $ unretainedName
162162 boxed = AST.Var Nothing . -- Note: prevents optimizer from eliminating this
163− prettyPrintCpp1 $
163+ prettyPrintIL1 $
164164 AST.VariableIntroduction
165165 Nothing
166166 retainedName
167167 (Just unretained)
168168 alias = AST.Var Nothing $ "auto& " <> retainedName <> " = " <> unretainedName
169169 in
170− case cpp of
171− AST.Function _ name args (AST.Block Nothing cpps) ->
170+ case il of
171+ AST.Function _ name args (AST.Block Nothing ils) ->
172172 AST.Assignment Nothing
173173 retained
174174 (AST.Function Nothing
175175 name
176176 args
177− (AST.Block Nothing (boxed : cpps)))
177+ (AST.Block Nothing (boxed : ils)))
178178 _ ->
179179 AST.Assignment Nothing
180180 retained
@@ -183,80 +183,80 @@ moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
183183 Nothing
184184 []
185185 (AST.Block Nothing ([ alias
186− , AST.Return Nothing cpp
186+ , AST.Return Nothing il
187187 ])))
188188 [])
189− nonRecToCpp _ (ss, _, _, _) ident val = do
190− cpp <- valueToCpp val
191− pure $ AST.VariableIntroduction Nothing (identToCpp ident) (Just cpp)
189+ nonRecToIL _ (ss, _, _, _) ident val = do
190+ il <- valueToIL val
191+ pure $ AST.VariableIntroduction Nothing (identToIL ident) (Just il)
192192
193193 -- | Generate code in the simplified intermediate representation for a variable based on a
194194 -- PureScript identifier.
195195 var :: Ident -> AST
196− var = AST.Var Nothing . identToCpp
196+ var = AST.Var Nothing . identToIL
197197
198198 accessorString :: PSString -> AST -> AST
199199 accessorString prop = AST.Indexer Nothing (AST.StringLiteral Nothing prop)
200200
201201 -- | Generate code in the simplified intermediate representation for a value or expression.
202202
203− valueToCpp :: Expr Ann -> m AST
204− valueToCpp (Literal (pos, _, _, _) l) = literalToValueCpp pos l
205− valueToCpp (Accessor _ prop val) =
206− accessorString prop <$> valueToCpp val
207− valueToCpp (ObjectUpdate _ o ps) = do
208− obj <- valueToCpp o
209− updates <- mapM (sndM valueToCpp) ps
203+ valueToIL :: Expr Ann -> m AST
204+ valueToIL (Literal (pos, _, _, _) l) = literalToValueIL pos l
205+ valueToIL (Accessor _ prop val) =
206+ accessorString prop <$> valueToIL val
207+ valueToIL (ObjectUpdate _ o ps) = do
208+ obj <- valueToIL o
209+ updates <- mapM (sndM valueToIL) ps
210210 obj' <- freshName'
211211 let objVar = AST.Var Nothing obj'
212212 copy = AST.VariableIntroduction Nothing obj' (Just $ AST.App Nothing (AST.Var Nothing (unbox dictType)) [obj])
213213 assign (k, v) = AST.Assignment Nothing (accessorString k objVar) v
214214 sts = copy : (assign <$> updates) ++ [AST.Return Nothing objVar]
215215 return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing sts)) []
216− valueToCpp (Abs _ arg val) = do
217− ret <- valueToCpp val
218− let cppArg = case arg of
216+ valueToIL (Abs _ arg val) = do
217+ ret <- valueToIL val
218+ let ilArg = case arg of
219219 UnusedIdent -> []
220− _ -> [identToCpp arg]
221− return $ AST.Function Nothing Nothing cppArg (AST.Block Nothing [AST.Return Nothing ret])
222− valueToCpp e@App{} = do
220+ _ -> [identToIL arg]
221+ return $ AST.Function Nothing Nothing ilArg (AST.Block Nothing [AST.Return Nothing ret])
222+ valueToIL e@App{} = do
223223 let (f, args) = unApp e []
224− args' <- mapM valueToCpp args
224+ args' <- mapM valueToIL args
225225 case f of
226226 Var (_, _, _, Just IsNewtype) _ -> return (head args')
227− _ -> flip (foldl (\fn a -> AST.App Nothing fn [a])) args' <$> valueToCpp f
227+ _ -> flip (foldl (\fn a -> AST.App Nothing fn [a])) args' <$> valueToIL f
228228 where
229229 unApp :: Expr Ann -> [Expr Ann] -> (Expr Ann, [Expr Ann])
230230 unApp (App _ val arg) args = unApp val (arg : args)
231231 unApp other args = (other, args)
232− -- valueToCpp (Var (_, _, _, Just IsForeign) qi@(Qualified (Just mn') ident)) =
232+ -- valueToIL (Var (_, _, _, Just IsForeign) qi@(Qualified (Just mn') ident)) =
233233 -- return $ if mn' == mn
234− -- then AST.Var Nothing (moduleNameToCpp mn' <> "::" <> identToCpp ident)
235− -- else varToCpp qi
236− -- valueToCpp (Var (_, _, _, Just IsForeign) (Qualified (Just mn') ident)) =
237− -- return $ AST.Var Nothing (moduleNameToCpp mn' <> "::" <> identToCpp ident)
238− -- valueToCpp (Var (_, _, _, Just IsForeign) qi@(Qualified (Just mn') ident)) =
234+ -- then AST.Var Nothing (moduleNameToIL mn' <> "::" <> identToIL ident)
235+ -- else varToIL qi
236+ -- valueToIL (Var (_, _, _, Just IsForeign) (Qualified (Just mn') ident)) =
237+ -- return $ AST.Var Nothing (moduleNameToIL mn' <> "::" <> identToIL ident)
238+ -- valueToIL (Var (_, _, _, Just IsForeign) qi@(Qualified (Just mn') ident)) =
239239 -- return $ if mn' == mn
240240 -- then foreignIdent ident
241− -- else varToCpp qi
242− -- valueToCpp (Var (_, _, _, Just IsForeign) ident) =
241+ -- else varToIL qi
242+ -- valueToIL (Var (_, _, _, Just IsForeign) ident) =
243243 -- internalError $ "Encountered an unqualified reference to a foreign ident " ++ T.unpack (showQualified showIdent ident)
244− valueToCpp (Var _ ident) = return $ varToCpp ident
245− valueToCpp (Case (ss, _, _, _) values binders) = do
246− vals <- mapM valueToCpp values
247− bindersToCpp ss binders vals
248− valueToCpp (Let _ ds val) = do
244+ valueToIL (Var _ ident) = return $ varToIL ident
245+ valueToIL (Case (ss, _, _, _) values binders) = do
246+ vals <- mapM valueToIL values
247+ bindersToIL ss binders vals
248+ valueToIL (Let _ ds val) = do
249249 let recurs = concatMap getNames $ filter isRec ds
250− recurDs = (\v -> AST.Var Nothing $ "boxed::recur " <> identToCpp v) <$> recurs
250+ recurDs = (\v -> AST.Var Nothing $ "boxed::recur " <> identToIL v) <$> recurs
251251 recurDsWeak = (\v -> AST.Var
252252 Nothing
253− ("boxed::recur::weak " <> identToCpp v <> unretainedSuffix <> "(" <> identToCpp v <> ")")
253+ ("boxed::recur::weak " <> identToIL v <> unretainedSuffix <> "(" <> identToIL v <> ")")
254254 ) <$> recurs
255255 mutualRecurWarning = if any isMutRec $ filter isRec ds
256256 then [AST.Var Nothing "#pragma message(\"Mutually recursive lets will cause retain cycles (memory leaks)\") //"]
257257 else []
258− ds' <- concat <$> mapM (bindToCpp LetDecl) ds
259− ret <- valueToCpp val
258+ ds' <- concat <$> mapM (bindToIL LetDecl) ds
259+ ret <- valueToIL val
260260 return $
261261 AST.App Nothing
262262 (AST.Function Nothing
@@ -271,92 +271,92 @@ moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
271271 isMutRec :: Bind Ann -> Bool
272272 isMutRec b | (length . nub $ getNames b) > 1 = True
273273 | otherwise = False
274− valueToCpp (Constructor (_, _, _, Just IsNewtype) _ (ProperName ctor) _) = error "IsNewtype"
275− valueToCpp (Constructor _ _ (ProperName ctor) fields) =
274+ valueToIL (Constructor (_, _, _, Just IsNewtype) _ (ProperName ctor) _) = error "IsNewtype"
275+ valueToIL (Constructor _ _ (ProperName ctor) fields) =
276276 let body = AST.ObjectLiteral Nothing $ (mkString ctor, AST.BooleanLiteral Nothing True) :
277− ((\field -> (mkString (identToCpp field), var field)) `map` fields)
278− fn = foldr (\f inner -> AST.Function Nothing Nothing [identToCpp f] (AST.Block Nothing [AST.Return Nothing inner])) body fields
277+ ((\field -> (mkString (identToIL field), var field)) `map` fields)
278+ fn = foldr (\f inner -> AST.Function Nothing Nothing [identToIL f] (AST.Block Nothing [AST.Return Nothing inner])) body fields
279279 in return fn
280280
281281
282282 iife :: Text -> [AST] -> AST
283283 iife v exprs = AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing $ exprs ++ [AST.Return Nothing $ AST.Var Nothing v])) []
284284
285− literalToValueCpp :: SourceSpan -> Literal (Expr Ann) -> m AST
286− literalToValueCpp ss (NumericLiteral (Left i)) = return $ AST.NumericLiteral (Just ss) (Left i)
287− literalToValueCpp ss (NumericLiteral (Right n)) = return $ AST.NumericLiteral (Just ss) (Right n)
288− literalToValueCpp ss (StringLiteral s) = return $ AST.StringLiteral (Just ss) s
289− literalToValueCpp ss (CharLiteral c) = return $ AST.StringLiteral (Just ss) (fromString [c])
290− literalToValueCpp ss (BooleanLiteral b) = return $ AST.BooleanLiteral (Just ss) b
291− literalToValueCpp ss (ArrayLiteral xs) = AST.ArrayLiteral (Just ss) <$> mapM valueToCpp xs
292− literalToValueCpp ss (ObjectLiteral ps) = AST.ObjectLiteral (Just ss) <$> mapM (sndM valueToCpp) ps
285+ literalToValueIL :: SourceSpan -> Literal (Expr Ann) -> m AST
286+ literalToValueIL ss (NumericLiteral (Left i)) = return $ AST.NumericLiteral (Just ss) (Left i)
287+ literalToValueIL ss (NumericLiteral (Right n)) = return $ AST.NumericLiteral (Just ss) (Right n)
288+ literalToValueIL ss (StringLiteral s) = return $ AST.StringLiteral (Just ss) s
289+ literalToValueIL ss (CharLiteral c) = return $ AST.StringLiteral (Just ss) (fromString [c])
290+ literalToValueIL ss (BooleanLiteral b) = return $ AST.BooleanLiteral (Just ss) b
291+ literalToValueIL ss (ArrayLiteral xs) = AST.ArrayLiteral (Just ss) <$> mapM valueToIL xs
292+ literalToValueIL ss (ObjectLiteral ps) = AST.ObjectLiteral (Just ss) <$> mapM (sndM valueToIL) ps
293293
294294 -- | Generate code in the simplified intermediate representation for a reference to a
295295 -- variable.
296− varToCpp :: Qualified Ident -> AST
297− varToCpp (Qualified Nothing ident) = var ident
298− varToCpp qual = qualifiedToCpp id qual
296+ varToIL :: Qualified Ident -> AST
297+ varToIL (Qualified Nothing ident) = var ident
298+ varToIL qual = qualifiedToIL id qual
299299
300300 -- | Generate code in the simplified intermediate representation for a reference to a
301301 -- variable that may have a qualified name.
302− qualifiedToCpp :: (a -> Ident) -> Qualified a -> AST
303− qualifiedToCpp f (Qualified (Just (ModuleName [ProperName mn'])) a) | mn' == C.prim = AST.Var Nothing . runIdent $ f a
304− qualifiedToCpp f (Qualified (Just mn') a) = AST.Indexer Nothing (AST.Var Nothing . identToCpp $ f a) (AST.Var Nothing (moduleNameToCpp mn'))
305− qualifiedToCpp f (Qualified _ a) = AST.Var Nothing $ identToCpp (f a)
302+ qualifiedToIL :: (a -> Ident) -> Qualified a -> AST
303+ qualifiedToIL f (Qualified (Just (ModuleName [ProperName mn'])) a) | mn' == C.prim = AST.Var Nothing . runIdent $ f a
304+ qualifiedToIL f (Qualified (Just mn') a) = AST.Indexer Nothing (AST.Var Nothing . identToIL $ f a) (AST.Var Nothing (moduleNameToIL mn'))
305+ qualifiedToIL f (Qualified _ a) = AST.Var Nothing $ identToIL (f a)
306306
307307 -- foreignIdent :: Ident -> AST
308308 -- foreignIdent ident = accessorString (mkString $ runIdent ident) (AST.Var Nothing "$foreign")
309309
310310 -- | Generate code in the simplified intermediate representation for pattern match binders
311311 -- and guards.
312− bindersToCpp :: SourceSpan -> [CaseAlternative Ann] -> [AST] -> m AST
313− bindersToCpp ss binders vals = do
312+ bindersToIL :: SourceSpan -> [CaseAlternative Ann] -> [AST] -> m AST
313+ bindersToIL ss binders vals = do
314314 valNames <- replicateM (length vals) freshName'
315315 let assignments = zipWith (AST.VariableIntroduction Nothing) valNames (map Just vals)
316− cpps <- forM binders $ \(CaseAlternative bs result) -> do
317− ret <- guardsToCpp result
316+ ils <- forM binders $ \(CaseAlternative bs result) -> do
317+ ret <- guardsToIL result
318318 go valNames ret bs
319− return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing (assignments ++ concat cpps ++ [AST.Throw Nothing (AST.StringLiteral Nothing $ mkString failedPatternMessage)])))
319+ return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing (assignments ++ concat ils ++ [AST.Throw Nothing (AST.StringLiteral Nothing $ mkString failedPatternMessage)])))
320320 []
321321 where
322322 go :: [Text] -> [AST] -> [Binder Ann] -> m [AST]
323323 go _ done [] = return done
324324 go (v:vs) done' (b:bs) = do
325325 done'' <- go vs done' bs
326− binderToCpp v done'' b
327− go _ _ _ = internalError "Invalid arguments to bindersToCpp"
326+ binderToIL v done'' b
327+ go _ _ _ = internalError "Invalid arguments to bindersToIL"
328328
329329 failedPatternMessage :: Text
330330 failedPatternMessage = "Failed pattern match at " <> runModuleName mn <> " " <> displayStartEndPos ss <> ": "
331331
332− guardsToCpp :: Either [(Guard Ann, Expr Ann)] (Expr Ann) -> m [AST]
333− guardsToCpp (Left gs) = traverse genGuard gs where
332+ guardsToIL :: Either [(Guard Ann, Expr Ann)] (Expr Ann) -> m [AST]
333+ guardsToIL (Left gs) = traverse genGuard gs where
334334 genGuard (cond, val) = do
335− cond' <- valueToCpp cond
336− val' <- valueToCpp val
335+ cond' <- valueToIL cond
336+ val' <- valueToIL val
337337 return
338338 (AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo cond' (AST.BooleanLiteral Nothing True))
339339 (AST.Block Nothing [AST.Return Nothing val']) Nothing)
340340
341− guardsToCpp (Right v) = return . AST.Return Nothing <$> valueToCpp v
341+ guardsToIL (Right v) = return . AST.Return Nothing <$> valueToIL v
342342
343343 -- | Generate code in the simplified intermediate representation for a pattern match
344344 -- binder.
345− binderToCpp :: Text -> [AST] -> Binder Ann -> m [AST]
346− binderToCpp _ done NullBinder{} = return done
347− binderToCpp varName done (LiteralBinder _ l) =
348− literalToBinderCpp varName done l
349− binderToCpp varName done (VarBinder _ ident) =
350− return (AST.VariableIntroduction Nothing (identToCpp ident) (Just (AST.Var Nothing varName)) : done)
351− binderToCpp varName done (ConstructorBinder (_, _, _, Just IsNewtype) _ _ [b]) =
352− binderToCpp varName done b
353− binderToCpp varName done (ConstructorBinder (_, _, _, Just (IsConstructor ctorType fields)) _ (Qualified _ (ProperName ctor)) bs) = do
354− cpp <- go (zip fields bs) done
345+ binderToIL :: Text -> [AST] -> Binder Ann -> m [AST]
346+ binderToIL _ done NullBinder{} = return done
347+ binderToIL varName done (LiteralBinder _ l) =
348+ literalToBinderIL varName done l
349+ binderToIL varName done (VarBinder _ ident) =
350+ return (AST.VariableIntroduction Nothing (identToIL ident) (Just (AST.Var Nothing varName)) : done)
351+ binderToIL varName done (ConstructorBinder (_, _, _, Just IsNewtype) _ _ [b]) =
352+ binderToIL varName done b
353+ binderToIL varName done (ConstructorBinder (_, _, _, Just (IsConstructor ctorType fields)) _ (Qualified _ (ProperName ctor)) bs) = do
354+ il <- go (zip fields bs) done
355355 return $ case ctorType of
356− ProductType -> cpp
356+ ProductType -> il
357357 SumType ->
358358 [AST.IfElse Nothing (AST.InstanceOf Nothing (AST.Var Nothing varName) (AST.StringLiteral Nothing (mkString ctor)))
359− (AST.Block Nothing cpp)
359+ (AST.Block Nothing il)
360360 Nothing]
361361 where
362362 go :: [(Ident, Binder Ann)] -> [AST] -> m [AST]
@@ -364,50 +364,50 @@ moduleToCpp (Module _ coms mn _ imps _ foreigns decls) _ =
364364 go ((field, binder) : remain) done' = do
365365 argVar <- freshName'
366366 done'' <- go remain done'
367− cpp <- binderToCpp argVar done'' binder
368− return (AST.VariableIntroduction Nothing argVar (Just $ accessorString (mkString $ identToCpp field) $ AST.Var Nothing varName) : cpp)
367+ il <- binderToIL argVar done'' binder
368+ return (AST.VariableIntroduction Nothing argVar (Just $ accessorString (mkString $ identToIL field) $ AST.Var Nothing varName) : il)
369369
370− binderToCpp _ _ ConstructorBinder{} =
371− internalError "binderToCpp: Invalid ConstructorBinder in binderToCpp"
372− binderToCpp varName done (NamedBinder _ ident binder) = do
373− cpp <- binderToCpp varName done binder
374− return (AST.VariableIntroduction Nothing (identToCpp ident) (Just (AST.Var Nothing varName)) : cpp)
370+ binderToIL _ _ ConstructorBinder{} =
371+ internalError "binderToIL: Invalid ConstructorBinder in binderToIL"
372+ binderToIL varName done (NamedBinder _ ident binder) = do
373+ il <- binderToIL varName done binder
374+ return (AST.VariableIntroduction Nothing (identToIL ident) (Just (AST.Var Nothing varName)) : il)
375375
376− literalToBinderCpp :: Text -> [AST] -> Literal (Binder Ann) -> m [AST]
377− literalToBinderCpp varName done (NumericLiteral num) =
376+ literalToBinderIL :: Text -> [AST] -> Literal (Binder Ann) -> m [AST]
377+ literalToBinderIL varName done (NumericLiteral num) =
378378 return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.NumericLiteral Nothing num)) (AST.Block Nothing done) Nothing]
379− literalToBinderCpp varName done (CharLiteral c) =
379+ literalToBinderIL varName done (CharLiteral c) =
380380 return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.StringLiteral Nothing (fromString [c]))) (AST.Block Nothing done) Nothing]
381− literalToBinderCpp varName done (StringLiteral str) =
381+ literalToBinderIL varName done (StringLiteral str) =
382382 return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.StringLiteral Nothing str)) (AST.Block Nothing done) Nothing]
383− literalToBinderCpp varName done (BooleanLiteral True) =
383+ literalToBinderIL varName done (BooleanLiteral True) =
384384 return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.BooleanLiteral Nothing True)) (AST.Block Nothing done) Nothing]
385− literalToBinderCpp varName done (BooleanLiteral False) =
385+ literalToBinderIL varName done (BooleanLiteral False) =
386386 return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.BooleanLiteral Nothing False)) (AST.Block Nothing done) Nothing]
387387 -- return [AST.IfElse Nothing (AST.Unary Nothing AST.Not (AST.Var Nothing varName)) (AST.Block Nothing done) Nothing]
388− literalToBinderCpp varName done (ObjectLiteral bs) = go done bs
388+ literalToBinderIL varName done (ObjectLiteral bs) = go done bs
389389 where
390390 go :: [AST] -> [(PSString, Binder Ann)] -> m [AST]
391391 go done' [] = return done'
392392 go done' ((prop, binder):bs') = do
393393 propVar <- freshName'
394394 done'' <- go done' bs'
395− cpp <- binderToCpp propVar done'' binder
396− return (AST.VariableIntroduction Nothing propVar (Just (accessorString prop (AST.Var Nothing varName))) : cpp)
397− literalToBinderCpp varName done (ArrayLiteral bs) = do
398− cpp <- go done 0 bs
395+ il <- binderToIL propVar done'' binder
396+ return (AST.VariableIntroduction Nothing propVar (Just (accessorString prop (AST.Var Nothing varName))) : il)
397+ literalToBinderIL varName done (ArrayLiteral bs) = do
398+ il <- go done 0 bs
399399 return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo
400400 (arrayLength $ AST.Var Nothing varName)
401401 (AST.NumericLiteral Nothing (Left (fromIntegral $ length bs))))
402− (AST.Block Nothing cpp) Nothing]
402+ (AST.Block Nothing il) Nothing]
403403 where
404404 go :: [AST] -> Integer -> [Binder Ann] -> m [AST]
405405 go done' _ [] = return done'
406406 go done' index (binder:bs') = do
407407 elVar <- freshName'
408408 done'' <- go done' (index + 1) bs'
409− cpp <- binderToCpp elVar done'' binder
410− return (AST.VariableIntroduction Nothing elVar (Just (AST.Indexer Nothing (AST.NumericLiteral Nothing (Left index)) (AST.Var Nothing varName))) : cpp)
409+ il <- binderToIL elVar done'' binder
410+ return (AST.VariableIntroduction Nothing elVar (Just (AST.Indexer Nothing (AST.NumericLiteral Nothing (Left index)) (AST.Var Nothing varName))) : il)
411411
412412emptyAnn :: Ann
413413emptyAnn = (SourceSpan "" (SourcePos 0 0) (SourcePos 0 0), [], Nothing, Nothing)