text
stringlengths
0
601k
let exported_constants = Hashtbl . create 17
let merged_environment = ref Export_info . empty
let default_ui_export_info = if Config . flambda then Cmx_format . Flambda Export_info . empty else Cmx_format . Clambda Value_unknown
let current_unit = { ui_name = " " ; ui_symbol = " " ; ui_defines = [ ] ; ui_imports_cmi = [ ] ; ui_imports_cmx = [ ] ; ui_curry_fun = [ ] ; ui_apply_fun = [ ] ; ui_send_fun = [ ] ; ui_force_link = false ; ui_export_info = default_ui_export_info }
let symbolname_for_pack pack name = match pack with | None -> name | Some p -> let b = Buffer . create 64 in for i = 0 to String . length p - 1 do match p . [ i ] with | ' . ' -> Buffer . add_string b " __ " | c -> Buffer . add_char b c done ; Buffer . add_string b " __ " ; Buffer . add_string b name ; Buffer . content...
let unit_id_from_name name = Ident . create_persistent name
let concat_symbol unitname id = unitname ^ " __ " ^ id
let make_symbol ( ? unitname = current_unit . ui_symbol ) idopt = let prefix = " caml " ^ unitname in match idopt with | None -> prefix | Some id -> concat_symbol prefix id
let current_unit_linkage_name ( ) = Linkage_name . create ( make_symbol ~ unitname : current_unit . ui_symbol None )
let reset ? packname name = Hashtbl . clear global_infos_table ; Set_of_closures_id . Tbl . clear imported_sets_of_closures_table ; let symbol = symbolname_for_pack packname name in current_unit . ui_name <- name ; current_unit . ui_symbol <- symbol ; current_unit . ui_defines <- [ symbol ] ; current_unit . ui_imports_...
let current_unit_infos ( ) = current_unit
let current_unit_name ( ) = current_unit . ui_name
let symbol_in_current_unit name = let prefix = " caml " ^ current_unit . ui_symbol in name = prefix || ( let lp = String . length prefix in String . length name >= 2 + lp && String . sub name 0 lp = prefix && name . [ lp ] = ' _ ' && name . [ lp + 1 ] = ' _ ' )
let read_unit_info filename = let ic = open_in_bin filename in try let buffer = really_input_string ic ( String . length cmx_magic_number ) in if buffer <> cmx_magic_number then begin close_in ic ; raise ( Error ( Not_a_unit_info filename ) ) end ; let ui = ( input_value ic : unit_infos ) in let crc = Digest . input ic...
let read_library_info filename = let ic = open_in_bin filename in let buffer = really_input_string ic ( String . length cmxa_magic_number ) in if buffer <> cmxa_magic_number then raise ( Error ( Not_a_unit_info filename ) ) ; let infos = ( input_value ic : library_infos ) in close_in ic ; infos
let get_global_info global_ident = ( let modname = Ident . name global_ident in if modname = current_unit . ui_name then Some current_unit else begin try Hashtbl . find global_infos_table modname with Not_found -> let ( infos , crc ) = if Env . is_imported_opaque modname then ( None , None ) else begin try let filename...
let cache_unit_info ui = Hashtbl . add global_infos_table ui . ui_name ( Some ui )
let get_clambda_approx ui = assert ( not Config . flambda ) ; match ui . ui_export_info with | Flambda _ -> assert false | Clambda approx -> approx
let toplevel_approx : ( string , Clambda . value_approximation ) Hashtbl . t = Hashtbl . create 16
let record_global_approx_toplevel ( ) = Hashtbl . add toplevel_approx current_unit . ui_name ( get_clambda_approx current_unit )
let global_approx id = if Ident . is_predef id then Clambda . Value_unknown else try Hashtbl . find toplevel_approx ( Ident . name id ) with Not_found -> match get_global_info id with | None -> Clambda . Value_unknown | Some ui -> get_clambda_approx ui
let symbol_for_global id = if Ident . is_predef id then " caml_exn_ " ^ Ident . name id else begin let unitname = Ident . name id in match try ignore ( Hashtbl . find toplevel_approx unitname ) ; None with Not_found -> get_global_info id with | None -> make_symbol ~ unitname ( : Ident . name id ) None | Some ui -> make...
let unit_for_global id = let sym_label = Linkage_name . create ( symbol_for_global id ) in Compilation_unit . create id sym_label
let predefined_exception_compilation_unit = Compilation_unit . create ( Ident . create_persistent " __dummy__ " ) ( Linkage_name . create " __dummy__ " )
let is_predefined_exception sym = Compilation_unit . equal predefined_exception_compilation_unit ( Symbol . compilation_unit sym )
let symbol_for_global ' id = let sym_label = Linkage_name . create ( symbol_for_global id ) in if Ident . is_predef id then Symbol . of_global_linkage predefined_exception_compilation_unit sym_label else Symbol . of_global_linkage ( unit_for_global id ) sym_label
let set_global_approx approx = assert ( not Config . flambda ) ; current_unit . ui_export_info <- Clambda approx
let get_flambda_export_info ui = assert ( Config . flambda ) ; match ui . ui_export_info with | Clambda _ -> assert false | Flambda ei -> ei
let set_export_info export_info = assert ( Config . flambda ) ; current_unit . ui_export_info <- Flambda export_info
let approx_for_global comp_unit = let id = Compilation_unit . get_persistent_ident comp_unit in if ( Compilation_unit . equal predefined_exception_compilation_unit comp_unit ) || Ident . is_predef id || not ( Ident . global id ) then invalid_arg ( Format . asprintf " approx_for_global % a " Ident . print id ) ; let mod...
let approx_env ( ) = ! merged_environment
let need_curry_fun arity = if not ( List . mem arity current_unit . ui_curry_fun ) then current_unit . ui_curry_fun <- arity :: current_unit . ui_curry_fun
let need_apply_fun n mode = assert ( n > 0 ) ; if not ( List . mem ( n , mode ) current_unit . ui_apply_fun ) then current_unit . ui_apply_fun <- ( n , mode ) :: current_unit . ui_apply_fun
let need_send_fun n mode = if not ( List . mem ( n , mode ) current_unit . ui_send_fun ) then current_unit . ui_send_fun <- ( n , mode ) :: current_unit . ui_send_fun
let write_unit_info info filename = let oc = open_out_bin filename in output_string oc cmx_magic_number ; output_value oc info ; flush oc ; let crc = Digest . file filename in Digest . output oc crc ; close_out oc
let save_unit_info filename = current_unit . ui_imports_cmi <- Env . imports ( ) ; write_unit_info current_unit filename
let current_unit ( ) = match Compilation_unit . get_current ( ) with | Some current_unit -> current_unit | None -> Misc . fatal_error " Compilenv . current_unit "
let current_unit_symbol ( ) = Symbol . of_global_linkage ( current_unit ( ) ) ( current_unit_linkage_name ( ) )
let const_label = ref 0
let new_const_symbol ( ) = incr const_label ; make_symbol ( Some ( Int . to_string ! const_label ) )
let snapshot ( ) = ! structured_constants
let backtrack s = structured_constants := s
let new_structured_constant cst ~ shared = let { strcst_shared ; strcst_all } = ! structured_constants in if shared then try CstMap . find cst strcst_shared with Not_found -> let lbl = new_const_symbol ( ) in structured_constants := { strcst_shared = CstMap . add cst lbl strcst_shared ; strcst_all = SymMap . add lbl cs...
let add_exported_constant s = Hashtbl . replace exported_constants s ( )
let clear_structured_constants ( ) = structured_constants := structured_constants_empty
let structured_constant_of_symbol s = SymMap . find_opt s ( ! structured_constants ) . strcst_all
let structured_constants ( ) = let provenance : Clambda . usymbol_provenance = { original_idents = [ ] ; module_path = Path . Pident ( Ident . create_persistent ( current_unit_name ( ) ) ) ; } in SymMap . bindings ( ! structured_constants ) . strcst_all |> List . map ( fun ( symbol , definition ) -> { Clambda . symbol ...
let closure_symbol fv = let compilation_unit = Closure_id . get_compilation_unit fv in let unitname = Linkage_name . to_string ( Compilation_unit . get_linkage_name compilation_unit ) in let linkage_name = concat_symbol unitname ( ( Closure_id . unique_name fv ) ^ " _closure " ) in Symbol . of_global_linkage compilatio...
let function_label fv = let compilation_unit = Closure_id . get_compilation_unit fv in let unitname = Linkage_name . to_string ( Compilation_unit . get_linkage_name compilation_unit ) in ( concat_symbol unitname ( Closure_id . unique_name fv ) )
let require_global global_ident = if not ( Ident . is_predef global_ident ) then ignore ( get_global_info global_ident : Cmx_format . unit_infos option )
let report_error ppf = function | Not_a_unit_info filename -> fprintf ppf " % a @ is not a compilation unit description . " Location . print_filename filename | Corrupted_unit_info filename -> fprintf ppf " Corrupted compilation unit description @ % a " Location . print_filename filename | Illegal_renaming ( name , mod...
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None )
type _ pass = | Parse_tree_intf : Parsetree . signature pass | Parse_tree_impl : Parsetree . structure pass | Typed_tree_intf : Typedtree . signature pass | Typed_tree_impl : ( Typedtree . structure * Typedtree . module_coercion ) pass | Raw_lambda : Lambda . program pass | Lambda : Lambda . program pass | Raw_flambda2...
type t = { mutable parse_tree_intf : ( Parsetree . signature -> unit ) list ; mutable parse_tree_impl : ( Parsetree . structure -> unit ) list ; mutable typed_tree_intf : ( Typedtree . signature -> unit ) list ; mutable typed_tree_impl : ( ( Typedtree . structure * Typedtree . module_coercion ) -> unit ) list ; mutable...
let hooks : t = { parse_tree_intf = [ ] ; parse_tree_impl = [ ] ; typed_tree_intf = [ ] ; typed_tree_impl = [ ] ; raw_lambda = [ ] ; lambda = [ ] ; raw_flambda2 = [ ] ; flambda2 = [ ] ; raw_flambda1 = [ ] ; flambda1 = [ ] ; raw_clambda = [ ] ; clambda = [ ] ; mach_combine = [ ] ; mach_cse = [ ] ; mach_spill = [ ] ; mac...
let execute_hooks : type a . ( a -> unit ) list -> a -> unit = fun hooks arg -> List . iter ( fun f -> f arg ) hooks
let register : type a . a pass -> ( a -> unit ) -> unit = fun representation f -> match representation with | Parse_tree_intf -> hooks . parse_tree_intf <- f :: hooks . parse_tree_intf | Parse_tree_impl -> hooks . parse_tree_impl <- f :: hooks . parse_tree_impl | Typed_tree_intf -> hooks . typed_tree_intf <- f :: hooks...
let execute : type a . a pass -> a -> unit = fun representation arg -> match representation with | Parse_tree_intf -> execute_hooks hooks . parse_tree_intf arg | Parse_tree_impl -> execute_hooks hooks . parse_tree_impl arg | Typed_tree_intf -> execute_hooks hooks . typed_tree_intf arg | Typed_tree_impl -> execute_hooks...
let execute_and_pipe r a = execute r a ; a
let clear : type a . a pass -> unit = function | Parse_tree_intf -> hooks . parse_tree_intf <- [ ] | Parse_tree_impl -> hooks . parse_tree_impl <- [ ] | Typed_tree_intf -> hooks . typed_tree_intf <- [ ] | Typed_tree_impl -> hooks . typed_tree_impl <- [ ] | Raw_lambda -> hooks . raw_lambda <- [ ] | Lambda -> hooks . lam...
type info = { source_file : string ; module_name : string ; output_prefix : string ; env : Env . t ; ppf_dump : Format . formatter ; tool_name : string ; native : bool ; }
let cmx i = i . output_prefix ^ " . cmx "
let obj i = i . output_prefix ^ Config . ext_obj
let cmo i = i . output_prefix ^ " . cmo "
let annot i = i . output_prefix ^ " . annot "
let with_info ~ native ~ tool_name ~ source_file ~ output_prefix ~ dump_ext k = Compmisc . init_path ( ) ; let module_name = Compenv . module_of_filename source_file output_prefix in Env . set_unit_name module_name ; let env = Compmisc . initial_env ( ) in let dump_file = String . concat " . " [ output_prefix ; dump_ex...
let parse_intf i = Pparse . parse_interface ~ tool_name : i . tool_name i . source_file |> print_if i . ppf_dump Clflags . dump_parsetree Printast . interface |> print_if i . ppf_dump Clflags . dump_source Pprintast . signature
let typecheck_intf info ast = Profile . ( record_call typing ) @@ fun ( ) -> let tsg = ast |> Typemod . type_interface info . env |> print_if info . ppf_dump Clflags . dump_typedtree Printtyped . interface in let sg = tsg . Typedtree . sig_type in if ! Clflags . print_types then Printtyp . wrap_printing_env ~ error : f...
let emit_signature info ast tsg = let sg = let alerts = Builtin_attributes . alerts_of_sig ast in Env . save_signature ~ alerts tsg . Typedtree . sig_type info . module_name ( info . output_prefix ^ " . cmi " ) in Typemod . save_signature info . module_name tsg info . output_prefix info . source_file info . env sg
let interface ~ hook_parse_tree ~ hook_typed_tree info = Profile . record_call info . source_file @@ fun ( ) -> let ast = parse_intf info in hook_parse_tree ast ; if Clflags . ( should_stop_after Compiler_pass . Parsing ) then ( ) else begin let tsg = typecheck_intf info ast in hook_typed_tree tsg ; if not ! Clflags . ...
let parse_impl i = Pparse . parse_implementation ~ tool_name : i . tool_name i . source_file |> print_if i . ppf_dump Clflags . dump_parsetree Printast . implementation |> print_if i . ppf_dump Clflags . dump_source Pprintast . structure
let typecheck_impl i parsetree = parsetree |> Profile . ( record typing ) ( Typemod . type_implementation i . source_file i . output_prefix i . module_name i . env ) |> print_if i . ppf_dump Clflags . dump_typedtree Printtyped . implementation_with_coercion
let implementation ~ hook_parse_tree ~ hook_typed_tree info ~ backend = Profile . record_call info . source_file @@ fun ( ) -> let exceptionally ( ) = let sufs = if info . native then [ cmx ; obj ] else [ cmo ] in List . iter ( fun suf -> remove_file ( suf info ) ) sufs ; in Misc . try_finally ? always : None ~ excepti...
let is_prefix_char = let chars = List . map int_of_char [ ' . ' ; ' _ ' ; ' ' ' ] \ in fun gchar -> Glib . Unichar . isalnum gchar || List . mem gchar chars
let utfify msg = let len = String . length msg in let buf = Buffer . create ( len + len / 2 ) in let rec replace i = if i >= len then Buffer . contents buf else if i = len - 1 then ( Buffer . add_char buf msg . [ i ] ; Buffer . contents buf ) else if msg . [ i ] = ' ' - && msg . [ i + 1 ] = ' ' > then ( Buffer . add_st...
let completion_start_iter ( iter : GText . iter ) : GText . iter = let limit = iter # set_line_offset 0 in let iter = iter # backward_find_char ~ limit ( fun c -> not ( is_prefix_char c ) ) in if iter # equal limit then iter else iter # forward_char
let completion_end_iter ( iter : GText . iter ) : GText . iter = let limit = iter # forward_to_line_end in iter # forward_find_char ~ limit ( fun c -> not ( is_prefix_char c ) )
let index_at_pos index buf = let scope = let gbuf = buf . OBuf . gbuffer in IndexScope . read_string ( gbuf # get_text ~ start : gbuf # start_iter ~ stop ( : gbuf # get_iter ` INSERT ) ( ) ) in List . fold_left ( fun info -> function | IndexScope . Open path -> LibIndex . open_module ~ cleanup_path : true info path | I...
let get_completions index buf ( context : GSourceView3 . source_completion_context ) = let candidates = try let stop = context # iter in let start = completion_start_iter stop in let word = buf . OBuf . gbuffer # get_text ~ start ~ stop ( ) in Tools . debug " Completing on % S " word ; LibIndex . complete ( index_at_po...
let merge_lines str = let len = String . length str in let buf = Buffer . create len in let rec aux i = try let j = String . index_from str i ' \ n ' in Buffer . add_substring buf str i ( j - i ) ; let k = ref ( j + 1 ) in while ! k < len && str . [ ! k ] = ' ' do incr k done ; if ! k < len then Buffer . add_char buf '...
let setup_show_type index buf message = let gbuf = buf . OBuf . gbuffer in let show_type pos = let iter = gbuf # get_iter ( ` OFFSET pos ) in let start = completion_start_iter iter in let stop = completion_end_iter start in let msg = if stop # offset > start # offset then let id = gbuf # get_text ~ start ~ stop ( ) in ...
let setup_completion index buf ( view : GSourceView3 . source_view ) = let ocaml_completion_provider = let provider_ref = ref None in let custom_provider : GSourceView3 . custom_completion_provider = object ( self ) method name = " Available library values " method icon = None method populate context = let provider = m...
let input_line ic = let s = input_line ic in let len = String . length s in if len > 0 && s . [ len - 1 ] = ' \ r ' then String . sub s 0 ( len - 1 ) else s
let setup buf ( view : GSourceView3 . source_view ) message = let index = let dirs = [ ! Cfg . datadir ] in let dirs = match Cfg . stdlib_dir with None -> dirs | Some d -> d :: dirs in let dirs = try let ic = Unix . open_process_in " ocamlc - where " in let dirs = ( try input_line ic :: dirs with End_of_file -> dirs ) ...
type t = { re : float ; im : float }
let zero = { re = 0 . 0 ; im = 0 . 0 }
let one = { re = 1 . 0 ; im = 0 . 0 }
let i = { re = 0 . 0 ; im = 1 . 0 }
let add x y = { re = x . re . + y . re ; im = x . im . + y . im }
let sub x y = { re = x . re . - y . re ; im = x . im . - y . im }
let neg x = { re = . - x . re ; im = . - x . im }
let conj x = { re = x . re ; im = . - x . im }
let mul x y = { re = x . re . * y . re . - x . im . * y . im ; im = x . re . * y . im . + x . im . * y . re }
let div x y = if abs_float y . re >= abs_float y . im then let r = y . im . / y . re in let d = y . re . + r . * y . im in { re = ( x . re . + r . * x . im ) . / d ; im = ( x . im . - r . * x . re ) . / d } else let r = y . re . / y . im in let d = y . im . + r . * y . re in { re = ( r . * x . re . + x . im ) . / d ; i...
let inv x = div one x
let norm2 x = x . re . * x . re . + x . im . * x . im
let norm x = let r = abs_float x . re and i = abs_float x . im in if r = 0 . 0 then i else if i = 0 . 0 then r else if r >= i then let q = i . / r in r . * sqrt ( 1 . 0 . + q . * q ) else let q = r . / i in i . * sqrt ( 1 . 0 . + q . * q )
let arg x = atan2 x . im x . re
let polar n a = { re = cos a . * n ; im = sin a . * n }
let sqrt x = if x . re = 0 . 0 && x . im = 0 . 0 then { re = 0 . 0 ; im = 0 . 0 } else begin let r = abs_float x . re and i = abs_float x . im in let w = if r >= i then begin let q = i . / r in sqrt ( r ) . * sqrt ( 0 . 5 . * ( 1 . 0 . + sqrt ( 1 . 0 . + q . * q ) ) ) end else begin let q = r . / i in sqrt ( i ) . * sq...