open Ident;; open Env;; let get_value_bindings env = let rec get_val acc = function | Env_empty -> acc | Env_value (next, ident, val_descr) -> get_val ((ident,val_descr)::acc) next | Env_type (next,_,_) -> get_val acc next | Env_exception (next,_,_) -> get_val acc next | Env_module (next,_,_) -> get_val acc next | Env_modtype (next,_,_) -> get_val acc next | Env_class (next,_,_) -> get_val acc next | Env_cltype (next,_,_) -> get_val acc next | Env_open (next,_) -> get_val acc next in get_val [] (summary env); ;; let print_bindings ppf bindings = List.iter (fun (ident,val_descr) -> Format.fprintf ppf "@\nbinding: "; Ident.print ppf ident; Format.fprintf ppf "@ @ @ "; Printtyp.value_description ident ppf val_descr) bindings; Format.fprintf ppf "@\nDone@." ;; print_bindings Format.std_formatter (get_value_bindings (!Toploop.toplevel_env));; let type_to_str (x : Types.type_expr) = Printtyp.type_expr Format.str_formatter x; Format.flush_str_formatter ();; (* Print all top-level int bindings *) let print_int_toplevel ppf bindings = let print_int_binding (ident,val_descr) = if type_to_str val_descr.Types.val_type = "int" then begin Format.fprintf ppf "@\nbinding: "; Ident.print ppf ident; Format.fprintf ppf " value: %d" (Obj.obj (Toploop.getvalue (name ident))); end else () in List.iter print_int_binding bindings; Format.fprintf ppf "@\nDone@." ;; print_int_toplevel Format.std_formatter (get_value_bindings (!Toploop.toplevel_env));;