@@ -1,7 +1,7 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
2module IRTS.CodegenJava (codegenJava) where
2module IRTS.CodegenJava (codegenJava) where
4−import Core.TT
4+import Core.TT hiding (mkApp)
5import IRTS.BCImp
5import IRTS.BCImp
6import IRTS.CodegenCommon
6import IRTS.CodegenCommon
7import IRTS.Java.ASTBuilding
7import IRTS.Java.ASTBuilding
@@ -313,12 +313,7 @@ mkExp :: SExp -> BlockResultTransformation -> CodeGeneration [BlockStmt]
313mkExp (SV var) cont = Nothing <>@! var >>= cont []
313mkExp (SV var) cont = Nothing <>@! var >>= cont []
315-- Applications
315-- Applications
316−mkExp (SApp True name args) cont =
316+mkExp (SApp pushTail name args) cont = mkApp pushTail name args >>= cont []
317− ((\ name args -> call name args) <$> mangleFull name <*> mapM (Nothing <>@!) args) >>= cont []
318− --mkTailCallClosure name args >>= cont []
319−mkExp (SApp False name args) cont =
320− ((\ name args -> call name args) <$> mangleFull name <*> mapM (Nothing <>@!) args) >>= cont []
321− --((\ closure -> (closure ~> "call") []) <$> mkTailCallClosure name args) >>= cont []
323-- Bindings
318-- Bindings
324mkExp (SLet var newExp inExp) cont = mkLet var newExp inExp cont
319mkExp (SLet var newExp inExp) cont = mkLet var newExp inExp cont
@@ -373,16 +368,18 @@ varPos (Glob name) = do
373-----------------------------------------------------------------------
368-----------------------------------------------------------------------
374-- Application (wrap method calls in tail call closures)
369-- Application (wrap method calls in tail call closures)
376−mkTailCallClosure :: Name -> [LVar] -> CodeGeneration Exp
371+mkApp :: Bool -> Name -> [LVar] -> CodeGeneration Exp
377−mkTailCallClosure name args =
372+mkApp False name args =
378− (\ methClosure ->
373+ (\ methodName params ->
379− InstanceCreation [] (toClassType idrisTailCallClosureType) [methClosure] Nothing
374+ (idrisClosureType ~> "unwrapTailCall") [call methodName params]
377+ <*> mapM (Nothing <>@!) args
381− <$> mkMethodCallClosure name args
378+mkApp True name args = mkMethodCallClosure name args
383mkMethodCallClosure :: Name -> [LVar] -> CodeGeneration Exp
380mkMethodCallClosure :: Name -> [LVar] -> CodeGeneration Exp
384mkMethodCallClosure name args =
381mkMethodCallClosure name args =
385− (\ name args -> closure [localContext] (call name args))
382+ (\ name args -> closure (call name args))
386 <$> mangleFull name
383 <$> mangleFull name
387 <*> mapM (Nothing <>@!) args
384 <*> mapM (Nothing <>@!) args
@@ -531,7 +528,6 @@ mkConstant c@(B16V x) = mkConstantArray (constType c) B16 x
531mkConstant c@(B32V x) = mkConstantArray (constType c) B32 x
528mkConstant c@(B32V x) = mkConstantArray (constType c) B32 x
532mkConstant c@(B64V x) = mkConstantArray (constType c) B64 x
529mkConstant c@(B64V x) = mkConstantArray (constType c) B64 x
533mkConstant c@(AType x) = ClassLit (Just $ box (constType c))
530mkConstant c@(AType x) = ClassLit (Just $ box (constType c))
534−mkConstant c@(ChType ) = ClassLit (Just $ box integerType)
535mkConstant c@(StrType ) = ClassLit (Just $ stringType)
531mkConstant c@(StrType ) = ClassLit (Just $ stringType)
536mkConstant c@(PtrType ) = ClassLit (Just $ objectType)
532mkConstant c@(PtrType ) = ClassLit (Just $ objectType)
537mkConstant c@(VoidType ) = ClassLit (Just $ voidType)
533mkConstant c@(VoidType ) = ClassLit (Just $ voidType)
@@ -596,7 +592,7 @@ mkPrimitiveFunction op args =
597mkThread :: LVar -> CodeGeneration Exp
593mkThread :: LVar -> CodeGeneration Exp
598mkThread arg =
594mkThread arg =
599− (\ closure -> (closure ~> "fork") []) <$> mkTailCallClosure (MN 0 "EVAL") [arg]
595+ (\ closure -> (closure ~> "fork") []) <$> mkMethodCallClosure (MN 0 "EVAL") [arg]
601-----------------------------------------------------------------------
597-----------------------------------------------------------------------
602-- Exceptions
598-- Exceptions