module UHC.Light.Compiler.CoreRun.Pretty(ppMod', ppExp') where
import UHC.Util.Pretty
import UHC.Light.Compiler.Base.Common
import UHC.Light.Compiler.Opts
import UHC.Light.Compiler.Base.Target
import UHC.Light.Compiler.Ty
import UHC.Light.Compiler.CoreRun
import UHC.Light.Compiler.Ty.Pretty
import qualified Data.Vector as V
import UHC.Light.Compiler.Foreign
import UHC.Light.Compiler.Foreign.Pretty
data InhPP
= InhPP
{ r2nInhPP :: Ref2Nm
, optsInhPP :: EHCOpts
}
mkEmptyInhPP :: EHCOpts -> InhPP
mkEmptyInhPP opts = InhPP ref2nmEmpty opts
r2nAdd :: Ref2Nm -> InhPP -> InhPP
r2nAdd r2n i@(InhPP {r2nInhPP=r2n', optsInhPP=opts})
| CoreOpt_RunPPNames `elem` ehcOptCoreOpts opts = i {r2nInhPP = ref2nmUnion r2n r2n'}
| otherwise = i
ppRRef :: InhPP -> RRef -> PP_Doc
ppRRef inhpp r = ppMbPost ppCurly (r2nInhPP inhpp r) r
ppMod'' :: InhPP -> Mod -> PP_Doc
ppMod'' inhpp x = pp_Syn_Mod $ wrap_Mod (sem_Mod x) (Inh_Mod {inhpp_Inh_Mod=inhpp})
ppExp'' :: InhPP -> Exp -> PP_Doc
ppExp'' inhpp x = pp_Syn_Exp $ wrap_Exp (sem_Exp x) (Inh_Exp {inhpp_Inh_Exp=inhpp})
ppSExp'' :: InhPP -> SExp -> PP_Doc
ppSExp'' inhpp x = ppExp'' inhpp (Exp_SExp x)
ppAlt'' :: InhPP -> Alt -> PP_Doc
ppAlt'' inhpp x = pp_Syn_Alt $ wrap_Alt (sem_Alt x) (Inh_Alt {inhpp_Inh_Alt=inhpp})
ppMod' :: EHCOpts -> Mod -> PP_Doc
ppMod' opts = ppMod'' (mkEmptyInhPP opts)
ppExp' :: EHCOpts -> Exp -> PP_Doc
ppExp' opts = ppExp'' (mkEmptyInhPP opts)
ppSExp' :: EHCOpts -> SExp -> PP_Doc
ppSExp' opts = ppSExp'' (mkEmptyInhPP opts)
ppAlt' :: EHCOpts -> Alt -> PP_Doc
ppAlt' opts = ppAlt'' (mkEmptyInhPP opts)
instance Show Mod where
show _ = "Mod"
instance Show Exp where
show _ = "Exp"
instance Show SExp where
show _ = "SExp"
instance Show Alt where
show _ = "Alt"
instance PP Mod where
pp = ppMod' defaultEHCOpts
instance PP Exp where
pp = ppExp' defaultEHCOpts
instance PP SExp where
pp = ppSExp' defaultEHCOpts
instance PP Alt where
pp = ppAlt' defaultEHCOpts
instance PP RRef where
pp (RRef_Glb m e) = "#g" >|< ppDots [m,e]
pp (RRef_Loc l e) = "#l" >|< ppDots [l,e]
pp (RRef_Tag r ) = ppDots [pp r, pp "tg"]
pp (RRef_Fld r e) = ppDots [pp r, pp e]
pp (RRef_Dbg n ) = "##" >|< n
ppBinds'' :: InhPP -> (Int -> RRef) -> Int -> CRArray Bind -> PP_Doc
ppBinds'' inhpp mkr off bs = vlist [ (ppRRef inhpp $ mkr $ off+i) >|< ":" >#< ppExp'' inhpp e | (i,e) <- craAssocs bs ]
sem_Alt :: Alt ->
T_Alt
sem_Alt (Alt_Alt _ref2nm _pat _expr) =
(sem_Alt_Alt _ref2nm (sem_Pat _pat) (sem_Exp _expr))
type T_Alt = InhPP ->
( PP_Doc)
data Inh_Alt = Inh_Alt {inhpp_Inh_Alt :: !(InhPP)}
data Syn_Alt = Syn_Alt {pp_Syn_Alt :: !(PP_Doc)}
wrap_Alt :: T_Alt ->
Inh_Alt ->
Syn_Alt
wrap_Alt sem (Inh_Alt _lhsIinhpp) =
(let ( _lhsOpp) = sem _lhsIinhpp
in (Syn_Alt _lhsOpp))
sem_Alt_Alt :: Ref2Nm ->
T_Pat ->
T_Exp ->
T_Alt
sem_Alt_Alt ref2nm_ pat_ expr_ =
(\ _lhsIinhpp ->
(case (r2nAdd ref2nm_ _lhsIinhpp) of
{ _inhpp ->
(case (_inhpp) of
{ _exprOinhpp ->
(case (_inhpp) of
{ _patOinhpp ->
(case (expr_ _exprOinhpp) of
{ ( _exprIpp) ->
(case (pat_ _patOinhpp) of
{ ( _patIpp) ->
(case (_patIpp >#< "->" >#< _exprIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }) }) }) }))
sem_Exp :: Exp ->
T_Exp
sem_Exp (Exp_SExp _sexpr) =
(sem_Exp_SExp (sem_SExp _sexpr))
sem_Exp (Exp_Tup _tag _args) =
(sem_Exp_Tup _tag _args)
sem_Exp (Exp_Let _lev _firstOff _ref2nm _binds _body) =
(sem_Exp_Let _lev _firstOff _ref2nm _binds (sem_Exp _body))
sem_Exp (Exp_App _func _args) =
(sem_Exp_App (sem_Exp _func) _args)
sem_Exp (Exp_Lam _mbNm _lev _nrArgs _nrBinds _stkDepth _ref2nm _body) =
(sem_Exp_Lam _mbNm _lev _nrArgs _nrBinds _stkDepth _ref2nm (sem_Exp _body))
sem_Exp (Exp_Force _expr) =
(sem_Exp_Force (sem_Exp _expr))
sem_Exp (Exp_RetCase _nrBinds _expr) =
(sem_Exp_RetCase _nrBinds (sem_Exp _expr))
sem_Exp (Exp_Tail _expr) =
(sem_Exp_Tail (sem_Exp _expr))
sem_Exp (Exp_Case _expr _alts) =
(sem_Exp_Case (sem_SExp _expr) _alts)
sem_Exp (Exp_FFI _prim _args) =
(sem_Exp_FFI _prim _args)
sem_Exp (Exp_Dbg _msg) =
(sem_Exp_Dbg _msg)
type T_Exp = InhPP ->
( PP_Doc)
data Inh_Exp = Inh_Exp {inhpp_Inh_Exp :: !(InhPP)}
data Syn_Exp = Syn_Exp {pp_Syn_Exp :: !(PP_Doc)}
wrap_Exp :: T_Exp ->
Inh_Exp ->
Syn_Exp
wrap_Exp sem (Inh_Exp _lhsIinhpp) =
(let ( _lhsOpp) = sem _lhsIinhpp
in (Syn_Exp _lhsOpp))
sem_Exp_SExp :: T_SExp ->
T_Exp
sem_Exp_SExp sexpr_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _sexprOinhpp ->
(case (sexpr_ _sexprOinhpp) of
{ ( _sexprIpp) ->
(case (_sexprIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_Exp_Tup :: CTag ->
(CRArray Exp) ->
T_Exp
sem_Exp_Tup tag_ args_ =
(\ _lhsIinhpp ->
(case ("alloc" >#< ctagTag tag_ >|< ppParensCommas (map (ppExp'' _lhsIinhpp) $ V.toList args_)) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_Exp_Let :: Int ->
Int ->
Ref2Nm ->
(CRArray Bind) ->
T_Exp ->
T_Exp
sem_Exp_Let lev_ firstOff_ ref2nm_ binds_ body_ =
(\ _lhsIinhpp ->
(case (r2nAdd ref2nm_ _lhsIinhpp) of
{ _inhpp ->
(case (_inhpp) of
{ _bodyOinhpp ->
(case (body_ _bodyOinhpp) of
{ ( _bodyIpp) ->
(case ("let" >#< ppBinds'' _inhpp (RRef_Loc lev_) firstOff_ binds_ >#< "in" >-< _bodyIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }) }))
sem_Exp_App :: T_Exp ->
(CRArray Exp) ->
T_Exp
sem_Exp_App func_ args_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _funcOinhpp ->
(case (func_ _funcOinhpp) of
{ ( _funcIpp) ->
(case ("app" >#< ppParens _funcIpp >|< ppParensCommas (map (ppExp'' _lhsIinhpp) $ V.toList args_)) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_Exp_Lam :: (Maybe HsName) ->
Int ->
Int ->
Int ->
Int ->
Ref2Nm ->
T_Exp ->
T_Exp
sem_Exp_Lam mbNm_ lev_ nrArgs_ nrBinds_ stkDepth_ ref2nm_ body_ =
(\ _lhsIinhpp ->
(case (r2nAdd ref2nm_ _lhsIinhpp) of
{ _inhpp ->
(case (_inhpp) of
{ _bodyOinhpp ->
(case (body_ _bodyOinhpp) of
{ ( _bodyIpp) ->
(case ("\\" >|< "@" >|< lev_ >#< ppCommas [if nrArgs_ > 0 then pp nrArgs_ else pp "thk", pp nrBinds_, pp stkDepth_] >#< "->" >#< _bodyIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }) }))
sem_Exp_Force :: T_Exp ->
T_Exp
sem_Exp_Force expr_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _exprOinhpp ->
(case (expr_ _exprOinhpp) of
{ ( _exprIpp) ->
(case ("eval" >|< ppParens _exprIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_Exp_RetCase :: Int ->
T_Exp ->
T_Exp
sem_Exp_RetCase nrBinds_ expr_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _exprOinhpp ->
(case (expr_ _exprOinhpp) of
{ ( _exprIpp) ->
(case ("retcase" >|< nrBinds_ >|< ppParens _exprIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_Exp_Tail :: T_Exp ->
T_Exp
sem_Exp_Tail expr_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _exprOinhpp ->
(case (expr_ _exprOinhpp) of
{ ( _exprIpp) ->
(case ("tail" >|< ppParens _exprIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_Exp_Case :: T_SExp ->
(CRArray Alt) ->
T_Exp
sem_Exp_Case expr_ alts_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _exprOinhpp ->
(case (expr_ _exprOinhpp) of
{ ( _exprIpp) ->
(case ("case" >#< _exprIpp >#< "of"
>-< indent 1 (vlist $ map (ppAlt'' _lhsIinhpp) $ V.toList alts_)) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_Exp_FFI :: RunPrim ->
(CRArray Exp) ->
T_Exp
sem_Exp_FFI prim_ args_ =
(\ _lhsIinhpp ->
(case ("ffi" >#< show prim_ >|< ppParensCommas (map (ppExp'' _lhsIinhpp) $ V.toList args_)) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_Exp_Dbg :: String ->
T_Exp
sem_Exp_Dbg msg_ =
(\ _lhsIinhpp ->
(case (ppCurly $ "dbg:" >#< msg_) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_Mod :: Mod ->
T_Mod
sem_Mod (Mod_Mod _ref2nm _moduleNm _moduleNr _stkDepth _binds _body) =
(sem_Mod_Mod _ref2nm _moduleNm _moduleNr _stkDepth _binds (sem_Exp _body))
type T_Mod = InhPP ->
( PP_Doc)
data Inh_Mod = Inh_Mod {inhpp_Inh_Mod :: !(InhPP)}
data Syn_Mod = Syn_Mod {pp_Syn_Mod :: !(PP_Doc)}
wrap_Mod :: T_Mod ->
Inh_Mod ->
Syn_Mod
wrap_Mod sem (Inh_Mod _lhsIinhpp) =
(let ( _lhsOpp) = sem _lhsIinhpp
in (Syn_Mod _lhsOpp))
sem_Mod_Mod :: Ref2Nm ->
HsName ->
Int ->
Int ->
(CRArray Bind) ->
T_Exp ->
T_Mod
sem_Mod_Mod ref2nm_ moduleNm_ moduleNr_ stkDepth_ binds_ body_ =
(\ _lhsIinhpp ->
(case (r2nAdd ref2nm_ _lhsIinhpp) of
{ _inhpp ->
(case (_inhpp) of
{ _bodyOinhpp ->
(case (body_ _bodyOinhpp) of
{ ( _bodyIpp) ->
(case ("module" >#< moduleNm_ >#< ppCommas [moduleNr_, stkDepth_] >|< ":" >#< _bodyIpp
>-< ppBinds'' _inhpp (RRef_Glb moduleNr_) 0 binds_) of
{ _lhsOpp ->
( _lhsOpp) }) }) }) }))
sem_Pat :: Pat ->
T_Pat
sem_Pat (Pat_Con _tag) =
(sem_Pat_Con _tag)
sem_Pat (Pat_BoolExpr _expr) =
(sem_Pat_BoolExpr (sem_Exp _expr))
type T_Pat = InhPP ->
( PP_Doc)
sem_Pat_Con :: CTag ->
T_Pat
sem_Pat_Con tag_ =
(\ _lhsIinhpp ->
(case (pp $ ctagTag tag_) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_Pat_BoolExpr :: T_Exp ->
T_Pat
sem_Pat_BoolExpr expr_ =
(\ _lhsIinhpp ->
(case (_lhsIinhpp) of
{ _exprOinhpp ->
(case (expr_ _exprOinhpp) of
{ ( _exprIpp) ->
(case (_exprIpp) of
{ _lhsOpp ->
( _lhsOpp) }) }) }))
sem_SExp :: SExp ->
T_SExp
sem_SExp (SExp_Var _ref) =
(sem_SExp_Var _ref)
sem_SExp (SExp_Int _int) =
(sem_SExp_Int _int)
sem_SExp (SExp_Char _char) =
(sem_SExp_Char _char)
sem_SExp (SExp_String _str) =
(sem_SExp_String _str)
sem_SExp (SExp_Integer _integer) =
(sem_SExp_Integer _integer)
type T_SExp = InhPP ->
( PP_Doc)
sem_SExp_Var :: RRef ->
T_SExp
sem_SExp_Var ref_ =
(\ _lhsIinhpp ->
(case (ppRRef _lhsIinhpp ref_) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_SExp_Int :: Int ->
T_SExp
sem_SExp_Int int_ =
(\ _lhsIinhpp ->
(case (pp int_) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_SExp_Char :: Char ->
T_SExp
sem_SExp_Char char_ =
(\ _lhsIinhpp ->
(case (pp $ show char_) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_SExp_String :: String ->
T_SExp
sem_SExp_String str_ =
(\ _lhsIinhpp ->
(case (pp $ show str_) of
{ _lhsOpp ->
( _lhsOpp) }))
sem_SExp_Integer :: Integer ->
T_SExp
sem_SExp_Integer integer_ =
(\ _lhsIinhpp ->
(case (pp integer_) of
{ _lhsOpp ->
( _lhsOpp) }))