text stringlengths 0 601k |
|---|
let rec rindex_rec s i c = if i < 0 then raise Not_found else if unsafe_get s i = c then i else rindex_rec s ( i - 1 ) c |
let rindex s c = rindex_rec s ( length s - 1 ) c |
let rindex_from s i c = if i < - 1 || i >= length s then invalid_arg " String . rindex_from / Bytes . rindex_from " else rindex_rec s i c |
let rec rindex_rec_opt s i c = if i < 0 then None else if unsafe_get s i = c then Some i else rindex_rec_opt s ( i - 1 ) c |
let rindex_opt s c = rindex_rec_opt s ( length s - 1 ) c |
let rindex_from_opt s i c = if i < - 1 || i >= length s then invalid_arg " String . rindex_from_opt / Bytes . rindex_from_opt " else rindex_rec_opt s i c |
let contains_from s i c = let l = length s in if i < 0 || i > l then invalid_arg " String . contains_from / Bytes . contains_from " else try ignore ( index_rec s l i c ) ; true with Not_found -> false |
let contains s c = contains_from s 0 c |
let rcontains_from s i c = if i < 0 || i >= length s then invalid_arg " String . rcontains_from / Bytes . rcontains_from " else try ignore ( rindex_rec s i c ) ; true with Not_found -> false |
let compare ( x : t ) ( y : t ) = Stdlib . compare x y |
let uppercase s = map Char . uppercase s |
let lowercase s = map Char . lowercase s |
let capitalize s = apply1 Char . uppercase s |
let uncapitalize s = apply1 Char . lowercase s |
let to_seq s = let rec aux i ( ) = if i = length s then Seq . Nil else let x = get s i in Seq . Cons ( x , aux ( i + 1 ) ) in aux 0 |
let to_seqi s = let rec aux i ( ) = if i = length s then Seq . Nil else let x = get s i in Seq . Cons ( ( i , x ) , aux ( i + 1 ) ) in aux 0 |
let of_seq i = let n = ref 0 in let buf = ref ( make 256 ' \ 000 ' ) in let resize ( ) = let new_len = min ( 2 * length ! buf ) Sys . max_string_length in if length ! buf = new_len then failwith " Bytes . of_seq : cannot grow bytes " ; let new_buf = make new_len ' \ 000 ' in blit ! buf 0 new_buf 0 ! n ; buf := new_buf ... |
let get_int8 b i = ( ( get_uint8 b i ) lsl ( Sys . int_size - 8 ) ) asr ( Sys . int_size - 8 ) |
let get_uint16_le b i = if Sys . big_endian then swap16 ( get_uint16_ne b i ) else get_uint16_ne b i |
let get_uint16_be b i = if not Sys . big_endian then swap16 ( get_uint16_ne b i ) else get_uint16_ne b i |
let get_int16_ne b i = ( ( get_uint16_ne b i ) lsl ( Sys . int_size - 16 ) ) asr ( Sys . int_size - 16 ) |
let get_int16_le b i = ( ( get_uint16_le b i ) lsl ( Sys . int_size - 16 ) ) asr ( Sys . int_size - 16 ) |
let get_int16_be b i = ( ( get_uint16_be b i ) lsl ( Sys . int_size - 16 ) ) asr ( Sys . int_size - 16 ) |
let get_int32_le b i = if Sys . big_endian then swap32 ( get_int32_ne b i ) else get_int32_ne b i |
let get_int32_be b i = if not Sys . big_endian then swap32 ( get_int32_ne b i ) else get_int32_ne b i |
let get_int64_le b i = if Sys . big_endian then swap64 ( get_int64_ne b i ) else get_int64_ne b i |
let get_int64_be b i = if not Sys . big_endian then swap64 ( get_int64_ne b i ) else get_int64_ne b i |
let set_int16_le b i x = if Sys . big_endian then set_int16_ne b i ( swap16 x ) else set_int16_ne b i x |
let set_int16_be b i x = if not Sys . big_endian then set_int16_ne b i ( swap16 x ) else set_int16_ne b i x |
let set_int32_le b i x = if Sys . big_endian then set_int32_ne b i ( swap32 x ) else set_int32_ne b i x |
let set_int32_be b i x = if not Sys . big_endian then set_int32_ne b i ( swap32 x ) else set_int32_ne b i x |
let set_int64_le b i x = if Sys . big_endian then set_int64_ne b i ( swap64 x ) else set_int64_ne b i x |
let set_int64_be b i x = if not Sys . big_endian then set_int64_ne b i ( swap64 x ) else set_int64_ne b i x |
type ' a ref = { mutable contents : ' a } = " caml_blit_bytes " [ @@ noalloc ] |
let extend len s left right r = let srcoff , dstoff = if left < 0 then - left , 0 else 0 , left in let cpylen = min ( length s - srcoff ) ( len - dstoff ) in if cpylen > 0 then unsafe_blit s srcoff r dstoff cpylen ; r |
let section_table = ref ( [ ] : ( string * int ) list ) |
let section_beginning = ref 0 |
let init_record outchan = section_beginning := pos_out outchan ; section_table := [ ] |
let record outchan name = let pos = pos_out outchan in section_table := ( name , pos - ! section_beginning ) :: ! section_table ; section_beginning := pos |
let write_toc_and_trailer outchan = List . iter ( fun ( name , len ) -> output_string outchan name ; output_binary_int outchan len ) ( List . rev ! section_table ) ; output_binary_int outchan ( List . length ! section_table ) ; output_string outchan Config . exec_magic_number ; section_table := [ ] ; |
let read_toc ic = let pos_trailer = in_channel_length ic - 16 in seek_in ic pos_trailer ; let num_sections = input_binary_int ic in let header = really_input_string ic ( String . length Config . exec_magic_number ) in if header <> Config . exec_magic_number then raise Bad_magic_number ; seek_in ic ( pos_trailer - 8 * n... |
let toc ( ) = List . rev ! section_table |
let seek_section ic name = let rec seek_sec curr_ofs = function [ ] -> raise Not_found | ( n , len ) :: rem -> if n = name then begin seek_in ic ( curr_ofs - len ) ; len end else seek_sec ( curr_ofs - len ) rem in seek_sec ( in_channel_length ic - 16 - 8 * List . length ! section_table ) ! section_table |
let read_section_string ic name = really_input_string ic ( seek_section ic name ) |
let read_section_struct ic name = ignore ( seek_section ic name ) ; input_value ic |
let pos_first_section ic = in_channel_length ic - 16 - 8 * List . length ! section_table - List . fold_left ( fun total ( _name , len ) -> total + len ) 0 ! section_table |
let reset ( ) = section_table := [ ] ; section_beginning := 0 |
type t = { names_to_types : ( Type_grammar . t * Binding_time . With_name_mode . t ) Name . Map . t ; aliases : Aliases . t ; symbol_projections : Symbol_projection . t Variable . Map . t } |
let print_kind_and_mode ~ min_binding_time ppf ( ty , binding_time_and_mode ) = let kind = Type_grammar . kind ty in let mode = Binding_time . With_name_mode . scoped_name_mode binding_time_and_mode ~ min_binding_time in Format . fprintf ppf " :: % a % a " Flambda_kind . print kind Name_mode . print mode |
let print_name_modes ~ restrict_to ~ min_binding_time ppf t = Name . Map . print ( print_kind_and_mode ~ min_binding_time ) ppf ( Name . Map . filter ( fun name _ -> Name . Set . mem name restrict_to ) t . names_to_types ) |
let empty = { names_to_types = Name . Map . empty ; aliases = Aliases . empty ; symbol_projections = Variable . Map . empty } |
let names_to_types t = t . names_to_types |
let aliases t = t . aliases |
let symbol_projections t = t . symbol_projections |
let add_or_replace_binding t ( name : Name . t ) ty binding_time name_mode = let binding_time_and_mode = Binding_time . With_name_mode . create binding_time name_mode in let names_to_types = Name . Map . add name ( ty , binding_time_and_mode ) t . names_to_types in { names_to_types ; aliases = t . aliases ; symbol_proj... |
let replace_variable_binding t var ty = let names_to_types = Name . Map . replace ( Name . var var ) ( function _old_ty , binding_time_and_mode -> ty , binding_time_and_mode ) t . names_to_types in { names_to_types ; aliases = t . aliases ; symbol_projections = t . symbol_projections } |
let with_aliases t ~ aliases = { t with aliases } |
let add_symbol_projection t var proj = let symbol_projections = Variable . Map . add var proj t . symbol_projections in { t with symbol_projections } |
let find_symbol_projection t var = match Variable . Map . find var t . symbol_projections with | exception Not_found -> None | proj -> Some proj |
let clean_for_export t ~ reachable_names = let current_compilation_unit = Compilation_unit . get_current_exn ( ) in let names_to_types = Name . Map . filter ( fun name _info -> Name_occurrences . mem_name reachable_names name && Compilation_unit . equal ( Name . compilation_unit name ) current_compilation_unit ) t . na... |
let apply_renaming { names_to_types ; aliases ; symbol_projections } renaming = let names_to_types = Name . Map . fold ( fun name ( ty , binding_time_and_mode ) acc -> Name . Map . add ( Renaming . apply_name renaming name ) ( Type_grammar . apply_renaming ty renaming , binding_time_and_mode ) acc ) names_to_types Name... |
let merge t1 t2 = let names_to_types = Name . Map . disjoint_union t1 . names_to_types t2 . names_to_types in let aliases = Aliases . merge t1 . aliases t2 . aliases in let symbol_projections = Variable . Map . union ( fun var proj1 proj2 -> if Symbol_projection . equal proj1 proj2 then Some proj1 else Misc . fatal_err... |
let canonicalise t simple = Simple . pattern_match simple ~ const ( : fun _ -> simple ) ~ name ( : fun name ~ coercion -> Simple . apply_coercion_exn ( Aliases . get_canonical_ignoring_name_mode t . aliases name ) coercion ) |
let remove_unused_value_slots_and_shortcut_aliases ( { names_to_types ; aliases ; symbol_projections } as t ) ~ used_value_slots = let canonicalise = canonicalise t in let names_to_types = Name . Map . map_sharing ( fun ( ( ty , binding_time_and_mode ) as info ) -> let ty ' = Type_grammar . remove_unused_value_slots_an... |
let free_function_slots_and_value_slots { names_to_types ; aliases = _ ; symbol_projections } = let from_projections = Variable . Map . fold ( fun _var proj free_names -> Name_occurrences . union free_names ( Name_occurrences . restrict_to_value_slots_and_function_slots ( Symbol_projection . free_names proj ) ) ) symbo... |
let mem_string ~ elt : c s = try for i = 0 to String . length s - 1 do if s . [ i ] = c then raise Exit done ; false with Exit -> true |
let ops = [ ' ' , ( . ) ; ++ ' ' , ( . ) ; -- ' ' , ( * . ) ; * ' ' , ( . ) ] // val variable = Textvariable . create ( ) val mutable x = 0 . 0 val mutable op = None val mutable displaying = true method set = Textvariable . set variable method get = Textvariable . get variable method insert s = calc # set ( calc # get ... |
let m = [ [ " | 7 " ; " 8 " ; " 9 " ; " " ] ; + [ " 4 " ; " 5 " ; " 6 " ; " " ] ; - [ " 1 " ; " 2 " ; " 3 " ; " " ] ; * [ " 0 " ; " . " ; " " ; " " ] ] =/| inherit calc ( ) as calc val label = Label . create ~ anchor ` : E ~ relief ` : Sunken ~ padx : 10 parent val frame = Frame . create parent initializer let buttons ... |
let top = openTk ( ) |
let applet = new calculator ~ parent : top |
let _ = mainLoop ( ) |
module Mode = struct type t = | Disabled | Top_of_stack | Full_trace end |
let mode = ref ( if Base . Exported_for_specific_uses . am_testing then Mode . Disabled else Top_of_stack ) ; ; |
let set_mode m = mode := m |
type t = | Top_of_stack of Printexc . location | Full_trace of Printexc . location option list |
let sexp_of_location ( t : Printexc . location ) = let loc = Printf . sprintf " % s :% i :% i " t . filename t . line_number t . start_char in [ % sexp ( loc : string ) ] ; ; |
let sexp_of_t ( t : t ) = match t with | Top_of_stack s -> [ % sexp ( s : location ) ] | Full_trace s -> [ % sexp ( s : location option list ) ] ; ; |
let get ( ? skip = [ ] ) ( ) = let skip = " list . ml " :: " list0 . ml " :: " array . ml " :: " comb . ml " :: " interface . ml " :: " signal . ml " :: " bits . ml " :: " with_valid . ml " :: " scope . ml " :: " parameter . ml " :: " hierarchy . ml " :: Caml . __FILE__ :: skip in let stack = Printexc . get_callstack 1... |
let check_arity arity = if Flambda_arity . With_subkinds . is_nullary arity then Misc . fatal_error " Invalid nullary arity " |
module Function_call = struct type t = | Direct of { code_id : Code_id . t ; return_arity : Flambda_arity . With_subkinds . t } | Indirect_unknown_arity | Indirect_known_arity of { param_arity : Flambda_arity . With_subkinds . t ; return_arity : Flambda_arity . With_subkinds . t } let [ @ ocamlformat " disable " ] prin... |
type method_kind = | Self | Public | Cached |
let print_method_kind ppf kind = match kind with | Self -> fprintf ppf " Self " | Public -> fprintf ppf " Public " | Cached -> fprintf ppf " Cached " |
let method_kind_from_lambda ( kind : Lambda . meth_kind ) = match kind with Self -> Self | Public -> Public | Cached -> Cached |
type t = | Function of { function_call : Function_call . t ; alloc_mode : Alloc_mode . t } | Method of { kind : method_kind ; obj : Simple . t ; alloc_mode : Alloc_mode . t } | C_call of { alloc : bool ; param_arity : Flambda_arity . t ; return_arity : Flambda_arity . t ; is_c_builtin : bool } |
let [ @ ocamlformat " disable " ] print ppf t = match t with | Function { function_call ; alloc_mode } -> fprintf ppf " [ @< hov 1 ( > Function @ \ [ @< hov 1 ( > function_call @ % a ) ] @@ \ [ @< hov 1 ( > alloc_mode @ % a ) ] @\ ) ] " @ Function_call . print function_call Alloc_mode . print alloc_mode | Method { kind... |
let direct_function_call code_id ~ return_arity alloc_mode = check_arity return_arity ; Function { function_call = Direct { code_id ; return_arity } ; alloc_mode } |
let indirect_function_call_unknown_arity alloc_mode = Function { function_call = Indirect_unknown_arity ; alloc_mode } |
let indirect_function_call_known_arity ~ param_arity ~ return_arity alloc_mode = check_arity return_arity ; Function { function_call = Indirect_known_arity { param_arity ; return_arity } ; alloc_mode } |
let method_call kind ~ obj alloc_mode = Method { kind ; obj ; alloc_mode } |
let c_call ~ alloc ~ param_arity ~ return_arity ~ is_c_builtin = begin match Flambda_arity . to_list return_arity with | [ ] | [ _ ] -> ( ) | _ :: _ :: _ -> Misc . fatal_errorf " Illegal return arity for C call : % a " Flambda_arity . print return_arity end ; C_call { alloc ; param_arity ; return_arity ; is_c_builtin } |
let return_arity t = match t with | Function { function_call ; _ } -> Function_call . return_arity function_call | Method _ -> Flambda_arity . With_subkinds . create [ Flambda_kind . With_subkind . any_value ] | C_call { return_arity ; _ } -> Flambda_arity . With_subkinds . of_arity return_arity |
let free_names t = match t with | Function { function_call = Direct { code_id ; return_arity = _ } ; alloc_mode = _ } -> Name_occurrences . add_code_id Name_occurrences . empty code_id Name_mode . normal | Function { function_call = Indirect_unknown_arity ; alloc_mode = _ } | Function { function_call = Indirect_known_a... |
let apply_renaming t perm = match t with | Function { function_call = Direct { code_id ; return_arity } ; alloc_mode } -> let code_id ' = Renaming . apply_code_id perm code_id in if code_id == code_id ' then t else Function { function_call = Direct { code_id = code_id ' ; return_arity } ; alloc_mode } | Function { func... |
let all_ids_for_export t = match t with | Function { function_call = Direct { code_id ; return_arity = _ } ; alloc_mode = _ } -> Ids_for_export . add_code_id Ids_for_export . empty code_id | Function { function_call = Indirect_unknown_arity ; alloc_mode = _ } | Function { function_call = Indirect_known_arity { param_ar... |
let speculative_inlining dacc ~ apply ~ function_type ~ simplify_expr ~ return_arity = let dacc = DA . set_do_not_rebuild_terms_and_disable_inlining dacc in let dacc , expr = Inlining_transforms . inline dacc ~ apply ~ unroll_to : None function_type in let scope = DE . get_continuation_scope ( DA . denv dacc ) in let d... |
let argument_types_useful dacc apply = if not ( Flambda_features . Inlining . speculative_inlining_only_if_arguments_useful ( ) ) then true else let typing_env = DE . typing_env ( DA . denv dacc ) in List . exists ( fun simple -> Simple . pattern_match simple ~ name ( : fun name ~ coercion : _ -> let ty = TE . find typ... |
let might_inline dacc ~ apply ~ code_or_metadata ~ function_type ~ simplify_expr ~ return_arity : Call_site_inlining_decision_type . t = let denv = DA . denv dacc in let env_prohibits_inlining = not ( DE . can_inline denv ) in let decision = Code_or_metadata . code_metadata code_or_metadata |> Code_metadata . inlining_... |
let get_rec_info dacc ~ function_type = let rec_info = FT . rec_info function_type in match Flambda2_types . prove_rec_info ( DA . typing_env dacc ) rec_info with | Proved rec_info -> rec_info | Unknown -> Rec_info_expr . unknown | Invalid -> Rec_info_expr . do_not_inline |
let make_decision dacc ~ simplify_expr ~ function_type ~ apply ~ return_arity : Call_site_inlining_decision_type . t = let rec_info = get_rec_info dacc ~ function_type in let inlined = Apply . inlined apply in match inlined with | Never_inlined -> Never_inlined_attribute | Default_inlined | Unroll _ | Always_inlined | ... |
type t = | Missing_code | Definition_says_not_to_inline | Environment_says_never_inline | Argument_types_not_useful | Unrolling_depth_exceeded | Max_inlining_depth_exceeded | Recursion_depth_exceeded | Never_inlined_attribute | Speculatively_not_inline of { cost_metrics : Cost_metrics . t ; evaluated_to : float ; thres... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.