@@ -3645,6 +3645,44 @@ and pp_block ppe fmt s =
36453645and pp_stmt ppe fmt s =
36463646 pp_list " @," (pp_instr ppe) fmt s.s_node
36473647
3648+ let pp_function ppe fmt (fun_ : function_ ) =
3649+ let pp_item ppe fmt = function
3650+ | `Var pv ->
3651+ Format. fprintf fmt " @[<hov 2>var %a;@]" (pp_pvdecl ppe) pv
3652+ | `Instr i ->
3653+ Format. fprintf fmt " %a" (pp_instr ppe) i
3654+ | `Return e ->
3655+ Format. fprintf fmt " @[<hov 2>return@ @[%a@];@]" (pp_expr ppe) e
3656+ in
3657+
3658+ let pp_funhdr ppe fmt fun_ =
3659+ let with_sig = match fun_.f_def with FBalias _ -> false | _ -> true in
3660+ Format. fprintf fmt " %a" (pp_funsig ~with_sig ppe) fun_.f_sig in
3661+
3662+ let pp_fundef ppe fmt fun_ =
3663+ match fun_.f_def with
3664+ | (FBdef def ) ->
3665+ let dummy_mem = EcIdent. create " &hr_dummy" in
3666+ let _, me = EcEnv.Fun. actmem_body dummy_mem fun_ in
3667+ let ppe = PPEnv. push_mem ppe ~active: true me in
3668+ let vars = List. map (fun x -> `Var x) def.f_locals in
3669+ let stmt = List. map (fun x -> `Instr x) def.f_body.s_node in
3670+ let ret = List. map (fun x -> `Return x) (otolist def.f_ret) in
3671+ let all = List. filter (fun x -> not (List. is_empty x)) [vars; stmt; ret] in
3672+
3673+ if List. is_empty all then Format. fprintf fmt " {}" else
3674+ Format. fprintf fmt " {@, @[<v>%a@]@,}"
3675+ (pp_list " @,@," (pp_list " @," (pp_item ppe))) all;
3676+
3677+ | FBalias g ->
3678+ Format. fprintf fmt " %a" (pp_funname ppe) g
3679+
3680+ | FBabs _ ->
3681+ Format. fprintf fmt " ?ABSTRACT?"
3682+ in
3683+
3684+ Format. fprintf fmt " @[<v>%a = %a@]" (pp_funhdr ppe) fun_ (pp_fundef ppe) fun_
3685+
36483686let rec pp_modexp ppe fmt (p , me ) =
36493687 let params =
36503688 match me.me_body with
@@ -3676,42 +3714,7 @@ and pp_moditem ppe fmt (p, i) =
36763714 Format. fprintf fmt " @[<hov 2>var %a@]" (pp_pvdecl ppe) v
36773715
36783716 | MI_Function f ->
3679- let pp_item ppe fmt = function
3680- | `Var pv ->
3681- Format. fprintf fmt " @[<hov 2>var %a;@]" (pp_pvdecl ppe) pv
3682- | `Instr i ->
3683- Format. fprintf fmt " %a" (pp_instr ppe) i
3684- | `Return e ->
3685- Format. fprintf fmt " @[<hov 2>return@ @[%a@];@]" (pp_expr ppe) e
3686- in
3687-
3688- let pp_funsig ppe fmt fun_ =
3689- let with_sig = match fun_.f_def with FBalias _ -> false | _ -> true in
3690- Format. fprintf fmt " %a" (pp_funsig ~with_sig ppe) fun_.f_sig in
3691-
3692- let pp_fundef ppe fmt fun_ =
3693- match fun_.f_def with
3694- | (FBdef def ) ->
3695- let dummy_mem = EcIdent. create " &hr_dummy" in
3696- let _, me = EcEnv.Fun. actmem_body dummy_mem fun_ in
3697- let ppe = PPEnv. push_mem ppe ~active: true me in
3698- let vars = List. map (fun x -> `Var x) def.f_locals in
3699- let stmt = List. map (fun x -> `Instr x) def.f_body.s_node in
3700- let ret = List. map (fun x -> `Return x) (otolist def.f_ret) in
3701- let all = List. filter (fun x -> not (List. is_empty x)) [vars; stmt; ret] in
3702-
3703- if List. is_empty all then Format. fprintf fmt " {}" else
3704- Format. fprintf fmt " {@, @[<v>%a@]@,}"
3705- (pp_list " @,@," (pp_list " @," (pp_item ppe))) all;
3706-
3707- | FBalias g ->
3708- Format. fprintf fmt " %a" (pp_funname ppe) g
3709-
3710- | FBabs _ ->
3711- Format. fprintf fmt " ?ABSTRACT?"
3712- in
3713-
3714- Format. fprintf fmt " @[<v>%a = %a@]" (pp_funsig ppe) f (pp_fundef ppe) f
3717+ pp_function ppe fmt f
37153718
37163719let pp_modexp ppe fmt (mp , me ) =
37173720 Format. fprintf fmt " %a." (pp_modexp ppe) (mp, me)
@@ -4103,6 +4106,31 @@ module ObjectInfo = struct
41034106
41044107 let pr_mod = pr_gen pr_mod_r
41054108
4109+ (* ------------------------------------------------------------------ *)
4110+ let pr_fun_r =
4111+ (* Prefer the substituting lookup so that a concrete or fully-applied
4112+ procedure prints with its instantiated names. When the enclosing
4113+ module still has functor parameters, that lookup fails; we then fall
4114+ back to the suspended view, which keeps the parameters abstract. *)
4115+ let lookup qs env =
4116+ try
4117+ let (xp, f) = EcEnv.Fun. lookup qs env in
4118+ (xp, { EcEnv. sp_target = f; sp_params = (0 , [] ); })
4119+ with EcEnv. LookupFailure _ -> EcEnv.Fun. sp_lookup qs env in
4120+ { od_name = " procedures" ;
4121+ od_lookup = lookup;
4122+ od_printer =
4123+ (fun ppe fmt (_ , susp ) ->
4124+ let (_, params) = susp.EcEnv. sp_params in
4125+ let (ppe, pp_params) = pp_mod_params ppe params in
4126+ if List. is_empty params then
4127+ pp_function ppe fmt susp.EcEnv. sp_target
4128+ else
4129+ Format. fprintf fmt " @[<v>(* in functor %t *)@ %a@]"
4130+ pp_params (pp_function ppe) susp.EcEnv. sp_target); }
4131+
4132+ let pr_fun = pr_gen pr_fun_r
4133+
41064134 (* ------------------------------------------------------------------ *)
41074135 let pr_mty_r =
41084136 { od_name = " module types" ;
@@ -4148,6 +4176,7 @@ module ObjectInfo = struct
41484176 pr_gen_r ~prcat: true pr_th_r ;
41494177 pr_gen_r ~prcat: true pr_ax_r ;
41504178 pr_gen_r ~prcat: true pr_mod_r;
4179+ pr_gen_r ~prcat: true pr_fun_r;
41514180 pr_gen_r ~prcat: true pr_mty_r;
41524181 pr_gen_r ~prcat: true pr_rw_r ;
41534182 pr_gen_r ~prcat: true pr_at_r ; ] in
0 commit comments