Packages

Erlang code generator for Idris 2

Current section

Files

Jump to
idris2 src Idris.Idris2.Compiler.ES.TailRec.erl
Raw

src/Idris.Idris2.Compiler.ES.TailRec.erl

-module('Idris.Idris2.Compiler.ES.TailRec').
-compile('no_auto_import').
-compile('inline').
-compile({'inline_size',24}).
-export([
'case--tailRecOptim-7447'/5,
'case--replaceTailCall-7355'/5,
'case--case block in replaceTailCall-7310'/6,
'case--replaceTailCall-7298'/3,
'case--hasTailCall-7235'/5,
'case--hasTailCall-7206'/2,
'un--tailRecOptim'/1,
'un--stepFnName'/0,
'un--replaceTailCall'/2,
'un--makeTailOptimToBody'/3,
'un--hasTailCall'/2,
'un--createNewArgs'/1,
'un--createArgInit'/1,
'un--argsName'/0
]).
'case--tailRecOptim-7447'(V0, V1, V2, V3, V4) -> case V4 of 0 -> ('un--makeTailOptimToBody'(V2, V1, V0)); 1 -> V0; _ -> ('erlang':'throw'("Error: Unreachable branch")) end.
'case--replaceTailCall-7355'(V0, V1, V2, V3, V4) -> case V4 of {'Idris.Builtin.MkPair', E0, E1} -> (fun (V5, V6) -> {'Idris.Builtin.MkPair', V5, ('un--replaceTailCall'(V3, V6))} end(E0, E1)); _ -> ('erlang':'throw'("Error: Unreachable branch")) end.
'case--case block in replaceTailCall-7310'(V0, V1, V2, V3, V4, V5) -> case V5 of 0 -> {'Idris.Compiler.ES.ImperativeAst.ReturnStatement', ('un--createNewArgs'(V3))}; 1 -> V1; _ -> ('erlang':'throw'("Error: Unreachable branch")) end.
'case--replaceTailCall-7298'(V0, V1, V2) -> case V0 of {'Idris.Compiler.ES.ImperativeAst.IEApp', E0, E1} -> (fun (V3, V4) -> case V3 of {'Idris.Compiler.ES.ImperativeAst.IEVar', E2} -> (fun (V5) -> begin (V6 = {'Idris.Compiler.ES.ImperativeAst.IEApp', {'Idris.Compiler.ES.ImperativeAst.IEVar', V5}, V4}), ('case--case block in replaceTailCall-7310'(V1, V2, V5, V4, V6, ('Idris.Idris2.Core.Name':'dn--un--==_Eq__Name'(V1, V5)))) end end(E2)); _ -> V2 end end(E0, E1)); _ -> V2 end.
'case--hasTailCall-7235'(V0, V1, V2, V3, V4) -> case V4 of {'Idris.Builtin.MkPair', E0, E1} -> (fun (V5, V6) -> ('un--hasTailCall'(V3, V6)) end(E0, E1)); _ -> ('erlang':'throw'("Error: Unreachable branch")) end.
'case--hasTailCall-7206'(V0, V1) -> case V0 of {'Idris.Compiler.ES.ImperativeAst.IEApp', E0, E1} -> (fun (V2, V3) -> case V2 of {'Idris.Compiler.ES.ImperativeAst.IEVar', E2} -> (fun (V4) -> ('Idris.Idris2.Core.Name':'dn--un--==_Eq__Name'(V1, V4)) end(E2)); _ -> 1 end end(E0, E1)); _ -> 1 end.
'un--tailRecOptim'(V0) -> case V0 of {'Idris.Compiler.ES.ImperativeAst.SeqStatement', E0, E1} -> (fun (V1, V2) -> {'Idris.Compiler.ES.ImperativeAst.SeqStatement', ('un--tailRecOptim'(V1)), ('un--tailRecOptim'(V2))} end(E0, E1)); {'Idris.Compiler.ES.ImperativeAst.FunDecl', E2, E3, E4, E5} -> (fun (V3, V4, V5, V6) -> begin (V7 = ('case--tailRecOptim-7447'(V6, V5, V4, V3, ('un--hasTailCall'(V4, V6))))), {'Idris.Compiler.ES.ImperativeAst.FunDecl', V3, V4, V5, V7} end end(E2, E3, E4, E5)); _ -> V0 end.
'un--stepFnName'() -> {'Idris.Core.Name.MN', <<"tailRecOptimStep"/utf8>>, 0}.
'un--replaceTailCall'(V0, V1) -> case V1 of {'Idris.Compiler.ES.ImperativeAst.SeqStatement', E0, E1} -> (fun (V2, V3) -> {'Idris.Compiler.ES.ImperativeAst.SeqStatement', V2, ('un--replaceTailCall'(V0, V3))} end(E0, E1)); {'Idris.Compiler.ES.ImperativeAst.ReturnStatement', E2} -> (fun (V4) -> begin (V5 = {'Idris.Compiler.ES.ImperativeAst.ReturnStatement', {'Idris.Compiler.ES.ImperativeAst.IEConstructor', {'Idris.Prelude.Types.Left', 1}, [V4 | []]}}), case V4 of {'Idris.Compiler.ES.ImperativeAst.IEApp', E3, E4} -> (fun (V6, V7) -> case V6 of {'Idris.Compiler.ES.ImperativeAst.IEVar', E5} -> (fun (V8) -> begin (V9 = {'Idris.Compiler.ES.ImperativeAst.IEApp', {'Idris.Compiler.ES.ImperativeAst.IEVar', V8}, V7}), ('case--case block in replaceTailCall-7310'(V0, V5, V8, V7, V9, ('Idris.Idris2.Core.Name':'dn--un--==_Eq__Name'(V0, V8)))) end end(E5)); _ -> V5 end end(E3, E4)); _ -> V5 end end end(E2)); {'Idris.Compiler.ES.ImperativeAst.SwitchStatement', E6, E7, E8} -> (fun (V10, V11, V12) -> {'Idris.Compiler.ES.ImperativeAst.SwitchStatement', V10, ('Idris.Idris2.Prelude.Types':'dn--un--map_Functor__List'('erased', 'erased', fun (V13) -> case V13 of {'Idris.Builtin.MkPair', E9, E10} -> (fun (V14, V15) -> {'Idris.Builtin.MkPair', V14, ('un--replaceTailCall'(V0, V15))} end(E9, E10)); _ -> ('erlang':'throw'("Error: Unreachable branch")) end end, V11)), ('Idris.Idris2.Prelude.Types':'dn--un--map_Functor__Maybe'('erased', 'erased', fun (V16) -> ('un--replaceTailCall'(V0, V16)) end, V12))} end(E6, E7, E8)); {'Idris.Compiler.ES.ImperativeAst.ForEverLoop', E11} -> (fun (V17) -> {'Idris.Compiler.ES.ImperativeAst.ForEverLoop', ('un--replaceTailCall'(V0, V17))} end(E11)); _ -> V1 end.
'un--makeTailOptimToBody'(V0, V1, V2) -> begin (V3 = ('Idris.Idris2.Prelude.Types':'dn--un--+_Num__Nat'(('Idris.Idris2.Prelude.Types.List':'un--length'('erased', V1)), (1 + 0)))), begin (V5 = ('Idris.Idris2.Prelude.Types':'dn--un--map_Functor__List'('erased', 'erased', fun (V4) -> {'Idris.Compiler.ES.ImperativeAst.IEConstructorArg', ('Idris.Idris2.Prelude.Types':'dn--un--cast_Cast__Nat_Int'(V4)), {'Idris.Compiler.ES.ImperativeAst.IEVar', ('un--argsName'())}} end, ('Idris.Idris2.Prelude.Types':'dn--un--rangeFromTo_Range__Nat'((1 + 0), V3))))), begin (V6 = ('Idris.Idris2.Compiler.ES.ImperativeAst':'un--replaceNamesExpS'(('Idris.Idris2.Data.List':'un--zip'('erased', 'erased', V1, V5)), V2))), begin (V7 = ('un--replaceTailCall'(V0, V6))), begin (V8 = {'Idris.Compiler.ES.ImperativeAst.FunDecl', {'Idris.Core.FC.EmptyFC'}, ('un--stepFnName'()), [('un--argsName'()) | []], V7}), begin (V9 = {'Idris.Compiler.ES.ImperativeAst.MutateStatement', ('un--argsName'()), {'Idris.Compiler.ES.ImperativeAst.IEApp', {'Idris.Compiler.ES.ImperativeAst.IEVar', ('un--stepFnName'())}, [{'Idris.Compiler.ES.ImperativeAst.IEVar', ('un--argsName'())} | []]}}), begin (V10 = {'Idris.Compiler.ES.ImperativeAst.ReturnStatement', {'Idris.Compiler.ES.ImperativeAst.IEConstructorArg', 1, {'Idris.Compiler.ES.ImperativeAst.IEVar', ('un--argsName'())}}}), begin (V11 = {'Idris.Compiler.ES.ImperativeAst.ForEverLoop', {'Idris.Compiler.ES.ImperativeAst.SwitchStatement', {'Idris.Compiler.ES.ImperativeAst.IEConstructorHead', {'Idris.Compiler.ES.ImperativeAst.IEVar', ('un--argsName'())}}, [{'Idris.Builtin.MkPair', {'Idris.Compiler.ES.ImperativeAst.IEConstructorTag', {'Idris.Prelude.Types.Left', 0}}, V9} | []], {'Idris.Prelude.Types.Just', V10}}}), ('Idris.Idris2.Compiler.ES.ImperativeAst':'dn--un--<+>_Semigroup__ImperativeStatement'(('Idris.Idris2.Compiler.ES.ImperativeAst':'dn--un--<+>_Semigroup__ImperativeStatement'(V8, ('un--createArgInit'(V1)))), V11)) end end end end end end end end.
'un--hasTailCall'(V0, V1) -> case V1 of {'Idris.Compiler.ES.ImperativeAst.SeqStatement', E0, E1} -> (fun (V2, V3) -> ('un--hasTailCall'(V0, V3)) end(E0, E1)); {'Idris.Compiler.ES.ImperativeAst.ReturnStatement', E2} -> (fun (V4) -> case V4 of {'Idris.Compiler.ES.ImperativeAst.IEApp', E3, E4} -> (fun (V5, V6) -> case V5 of {'Idris.Compiler.ES.ImperativeAst.IEVar', E5} -> (fun (V7) -> ('Idris.Idris2.Core.Name':'dn--un--==_Eq__Name'(V0, V7)) end(E5)); _ -> 1 end end(E3, E4)); _ -> 1 end end(E2)); {'Idris.Compiler.ES.ImperativeAst.SwitchStatement', E6, E7, E8} -> (fun (V8, V9, V10) -> ('Idris.Idris2.Prelude.Basics':'un--||'((('Idris.Idris2.Prelude.Interfaces':'un--any'('erased', 'erased', {'Idris.Prelude.Interfaces.dn--un--__mkFoldable', fun (V11) -> fun (V12) -> fun (V13) -> fun (V14) -> fun (V15) -> ('Idris.Idris2.Prelude.Types':'dn--un--foldr_Foldable__List'('erased', 'erased', V13, V14, V15)) end end end end end, fun (V16) -> fun (V17) -> fun (V18) -> fun (V19) -> fun (V20) -> ('Idris.Idris2.Prelude.Types':'dn--un--foldl_Foldable__List'('erased', 'erased', V18, V19, V20)) end end end end end}, fun (V21) -> case V21 of {'Idris.Builtin.MkPair', E9, E10} -> (fun (V22, V23) -> ('un--hasTailCall'(V0, V23)) end(E9, E10)); _ -> ('erlang':'throw'("Error: Unreachable branch")) end end))(V9)), fun () -> ('Idris.Idris2.Prelude.Types':'un--maybe'('erased', 'erased', fun () -> 1 end, fun () -> fun (V24) -> ('un--hasTailCall'(V0, V24)) end end, V10)) end)) end(E6, E7, E8)); {'Idris.Compiler.ES.ImperativeAst.ForEverLoop', E11} -> (fun (V25) -> ('un--hasTailCall'(V0, V25)) end(E11)); _ -> 1 end.
'un--createNewArgs'(V0) -> {'Idris.Compiler.ES.ImperativeAst.IEConstructor', {'Idris.Prelude.Types.Left', 0}, V0}.
'un--createArgInit'(V0) -> {'Idris.Compiler.ES.ImperativeAst.LetDecl', ('un--argsName'()), {'Idris.Prelude.Types.Just', {'Idris.Compiler.ES.ImperativeAst.IEConstructor', {'Idris.Prelude.Types.Left', 0}, ('Idris.Idris2.Prelude.Types':'dn--un--map_Functor__List'('erased', 'erased', fun (V1) -> {'Idris.Compiler.ES.ImperativeAst.IEVar', V1} end, V0))}}}.
'un--argsName'() -> {'Idris.Core.Name.MN', <<"tailRecOptimArgs"/utf8>>, 0}.