@@ -1,7 +1,7 @@
11{-# LANGUAGE PatternGuards #-}
22module IRTS.CodegenJava (codegenJava) where
33
4−import Core.TT
4+import Core.TT hiding (mkApp)
55import IRTS.BCImp
66import IRTS.CodegenCommon
77import IRTS.Java.ASTBuilding
@@ -313,12 +313,7 @@ mkExp :: SExp -> BlockResultTransformation -> CodeGeneration [BlockStmt]
313313mkExp (SV var) cont = Nothing <>@! var >>= cont []
314314
315315-- Applications
316−mkExp (SApp True 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 []
316+mkExp (SApp pushTail name args) cont = mkApp pushTail name args >>= cont []
322317
323318-- Bindings
324319mkExp (SLet var newExp inExp) cont = mkLet var newExp inExp cont
@@ -373,16 +368,18 @@ varPos (Glob name) = do
373368-----------------------------------------------------------------------
374369-- Application (wrap method calls in tail call closures)
375370
376−mkTailCallClosure :: Name -> [LVar] -> CodeGeneration Exp
377−mkTailCallClosure name args =
378− (\ methClosure ->
379− InstanceCreation [] (toClassType idrisTailCallClosureType) [methClosure] Nothing
371+mkApp :: Bool -> Name -> [LVar] -> CodeGeneration Exp
372+mkApp False name args =
373+ (\ methodName params ->
374+ (idrisClosureType ~> "unwrapTailCall") [call methodName params]
380375 )
381− <$> mkMethodCallClosure name args
376+ <$> mangleFull name
377+ <*> mapM (Nothing <>@!) args
378+mkApp True name args = mkMethodCallClosure name args
382379
383380mkMethodCallClosure :: Name -> [LVar] -> CodeGeneration Exp
384381mkMethodCallClosure name args =
385− (\ name args -> closure [localContext] (call name args))
382+ (\ name args -> closure (call name args))
386383 <$> mangleFull name
387384 <*> mapM (Nothing <>@!) args
388385
@@ -531,7 +528,6 @@ mkConstant c@(B16V x) = mkConstantArray (constType c) B16 x
531528mkConstant c@(B32V x) = mkConstantArray (constType c) B32 x
532529mkConstant c@(B64V x) = mkConstantArray (constType c) B64 x
533530mkConstant c@(AType x) = ClassLit (Just $ box (constType c))
534−mkConstant c@(ChType ) = ClassLit (Just $ box integerType)
535531mkConstant c@(StrType ) = ClassLit (Just $ stringType)
536532mkConstant c@(PtrType ) = ClassLit (Just $ objectType)
537533mkConstant c@(VoidType ) = ClassLit (Just $ voidType)
@@ -596,7 +592,7 @@ mkPrimitiveFunction op args =
596592
597593mkThread :: LVar -> CodeGeneration Exp
598594mkThread arg =
599− (\ closure -> (closure ~> "fork") []) <$> mkTailCallClosure (MN 0 "EVAL") [arg]
595+ (\ closure -> (closure ~> "fork") []) <$> mkMethodCallClosure (MN 0 "EVAL") [arg]
600596
601597-----------------------------------------------------------------------
602598-- Exceptions