X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Fc%CE%BBash.git;a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FNormalize.hs;h=85be0d0ef61ae37050835a9784185a538db04990;hp=36990dffc5e3cb733c12604765739168001ae934;hb=cd796dfc08504e019813a812c0184a3d03ced4db;hpb=3d93e9c743beb2402f37eee8210ec9fcaaa43e18 diff --git "a/c\316\273ash/CLasH/Normalize.hs" "b/c\316\273ash/CLasH/Normalize.hs" index 36990df..85be0d0 100644 --- "a/c\316\273ash/CLasH/Normalize.hs" +++ "b/c\316\273ash/CLasH/Normalize.hs" @@ -128,6 +128,16 @@ castsimpltop = everywhere ("castsimpl", castsimpl) -- transformation ensures that the lambda abstractions always contain a -- recursive let and that, when the return value is representable, the -- let contains a local variable reference in its body. +retvalsimpl c expr | all (== LambdaBody) c && not (is_lam expr) && not (is_let expr) = do + local_var <- Trans.lift $ is_local_var expr + repr <- isRepr expr + if not local_var && repr + then do + id <- Trans.lift $ mkBinderFor expr "res" + change $ Let (Rec [(id, expr)]) (Var id) + else + return expr + retvalsimpl c expr@(Let (Rec binds) body) | all (== LambdaBody) c = do -- Don't extract values that are already a local variable, to prevent -- loops with ourselves. @@ -142,15 +152,6 @@ retvalsimpl c expr@(Let (Rec binds) body) | all (== LambdaBody) c = do else return expr -retvalsimpl c expr | all (== LambdaBody) c && not (is_lam expr) && not (is_let expr) = do - local_var <- Trans.lift $ is_local_var expr - repr <- isRepr expr - if not local_var && repr - then do - id <- Trans.lift $ mkBinderFor expr "res" - change $ Let (Rec [(id, expr)]) (Var id) - else - return expr -- Leave all other expressions unchanged retvalsimpl c expr = return expr