text
stringlengths
12
786k
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 " ...
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...
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 (...
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 ...
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 | Illeg...
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 : Lambd...
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 . ...
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 = [ ] ...
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 ....
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_i...
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 ...
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 ...
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 Printt...
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...
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_t...
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...
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 ] = ' ' - ...
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_m...
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 ; ...
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 d...
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...
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 co...
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...
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 ...
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 ....
let exp x = let e = exp x . re in { re = e . * cos x . im ; im = e . * sin x . im }
let log x = { re = log ( norm x ) ; im = atan2 x . im x . re }
let pow x y = exp ( mul y ( log x ) )
let init_path ( ? dir " " ) = ( ) = let dirs = if ! Clflags . use_threads then " + threads " :: ! Clflags . include_dirs else ! Clflags . include_dirs in let dirs = ! Compenv . last_include_dirs @ dirs @ Config . flexdll_dirs @ ! Compenv . first_include_dirs in let exp_dirs =...
let initial_env ( ) = Ident . reinit ( ) ; Types . Uid . reinit ( ) ; let initially_opened_module = if ! Clflags . nopervasives then None else Some " Stdlib " in Typemod . initial_env ~ loc ( : Location . in_file " command line " ) ~ safe_string ( : Config . safe_strin...
let set_from_env flag Clflags . { parse ; usage ; env_var } = try match parse ( Sys . getenv env_var ) with | None -> Location . prerr_warning Location . none ( Warnings . Bad_env_variable ( env_var , usage ) ) | Some x -> match ! flag with | None -> flag := Some x | Some _ -...
let read_clflags_from_env ( ) = set_from_env Clflags . color Clflags . color_reader ; set_from_env Clflags . error_style Clflags . error_style_reader ; ( )
let with_ppf_dump ~ file_prefix f = let ppf_dump , finally = if not ! Clflags . dump_into_file then Format . err_formatter , ignore else let ch = open_out ( file_prefix ^ " . dump " ) in let ppf = Format . formatter_of_out_channel ch in ppf , ( fun ( ) -> Format . pp_print_flush pp...
let kernel_max ( ( spoc_var0 : ( ( ' a , ' b ) Vector . vector ) ) , ( spoc_var1 : ( ' c , ' d ) Vector . vector ) , ( spoc_var2 : int ) ) = Kernel . exec [ | Kernel . VFloat64 spoc_var0 ; Kernel . VFloat64 spoc_var1 ; Kernel . Int32 spoc_var2 ] | ob...
let spoc_max = new class_kernel_max object ( self ) inherit [ ' a , ' b ] Kernel . spoc_kernel " " " " method exec = failwith " dummy kernel " method args_to_list = failwith " dummy kernel " method list_to_args = failwith " dummy kernel " end
let spoc_dummy_kernel = new class_dummy_kernel
type application = object val env : ' a method env : unit -> ' a Devices . device list -> ( ' f , ' g ) Vector . vector -> ( ( ' d , ' e ) Vector . vector as ' c ) end val env = env ; method ker ( ) = ker ; method kind ( ) = ( kind : application ) method env...
let transfer_if_vector a device queue = | Kernel . VFloat32 v -> Mem . to_device v ~ queue_id : queue device ; val env = skeleton1 # env ( ) val ker = ( skeleton1 # ker ( ) :> ( ' a , ' b ) Kernel . spoc_kernel ) method env ( ) = env method kind ( ) = kind method ker ( ...
let run ( c : ( ' a , ' b , ' c ) # skeleton ) = c # run
let par_run ( c : ( ' a , ' b , ' c ) # skeleton ) = c # par_run
let pipe ( skeleton1 : ( ' a , ' b , ' c ) # skeleton ) ( skeleton2 : ( ' d , ' e , ' f ) # skeleton ) = new pipe skeleton1 skeleton2
let map ker out env = new map ker out env
let reduce reduction k = new reduce reduction k
module Make ( S : Compute_ranges_intf . S_functor ) = struct module Subrange_state = S . Subrange_state module Subrange_info = S . Subrange_info module Range_info = S . Range_info let rewrite_label env label = match Numbers . Int . Map . find label env with | exception Not_found -> label | la...
module type S_subrange_state = sig type t val create : unit -> t val advance_over_instruction : t -> L . instruction -> t end
module type S_subrange_info = sig type t type key type subrange_state val create : key -> subrange_state -> t end
module type S_range_info = sig type t type key type index val create : L . fundecl -> key -> start_insn : L . instruction -> ( index * t ) option end
module type S_functor = sig module Index : Identifiable . S module Key : sig type t module Set : sig include Set . S with type elt = t val print : Format . formatter -> t -> unit end module Map : Map . S with type key = t val print : Format . formatter -> t -> unit val all_parents : t -> t list...
module type S = sig module Index : Identifiable . S module Key : sig type t module Set : Set . S with type elt = t module Map : Map . S with type key = t end module Subrange_state : S_subrange_state module Subrange_info : S_subrange_info with type key := Key . t with type subrange_state := Subrange_s...
module P = struct value gloc bp strm = Grammar . loc_of_token_interval bp ( Stream . count strm ) ; value list0 symb = let rec loop al = parser [ [ : a = symb ; s ] : -> loop [ a :: al ] s | [ : ] : -> al ] in parser [ : a = loop [ ] ] : -> List . rev a ; value l...
let get_conflist = function | ` List obj -> obj | _ -> raise ( WrongFormat " must contain a list of confs " )