text
stringlengths
0
601k
let print_heterogenous_list fmt wrap = Pretty . to_formatter fmt ( make_heterogenous_list wrap )
let print_list_in_labels fmt wrap = Pretty . to_formatter fmt ( make_list_in_labels wrap )
let print_sum ? wrap fmt l = Pretty . to_formatter fmt ( format_sum ? wrap l )
let print_matrix ? align_closing1 ? align_closing2 ? wrap1 ? wrap2 m fmt ( ) = Pretty . to_formatter fmt ( format_matrix ? align_closing1 ? align_closing2 ? wrap1 ? wrap2 m )
let print_function_definition style name param fmt body = Pretty . to_formatter fmt ( format_function_definition style name param body )
let ( ) = let ints = Array . to_list ( Array . init 10 ( fun i -> i ) ) in with_margin 80 print_tuple ints ; with_margin 20 print_tuple ints ; with_margin 80 print_sum ints ; with_margin ~ html : true 80 print_sum ints ; with_margin 20 ( print_sum ~ wrap ` : Always_wrap ) ints ; with_margin 20 ( print_sum ~ wrap ` : Ne...
let __ocaml_lex_tables = { Lexing . lex_base = " \ 000 \ 000 \ 253 \ 255 \ 254 \ 255 \ 000 \ 000 \ 000 \ 000 \ 001 \ 000 \ 000 \ 000 \ 000 \ 000 \ \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 004 \ 000 \ 001 \ 000 \ 004 \ 000 \ 003 \ 000 \ \ 000 \ 000 \ 006 \ 000 \ 000 \ 000 \ 255 \ 255 " ; Lexing . lex_backtrk = ...
let rec translate lexbuf = __ocaml_lex_translate_rec lexbuf 0 match Lexing . engine __ocaml_lex_tables __ocaml_lex_state lexbuf with | 0 -> ( " . " ^ translate lexbuf ) | 1 -> let c ( String . make 1 c ^ translate lexbuf ) | 2 -> ( " " ) | __ocaml_lex_state -> lexbuf . Lexing . refill_buff lexbuf ; __ocaml_lex_translat...
let suites = Mt [ . " translate " , ( fun _ -> Eq ( translate ( Lexing . from_string " -- current_directory ) " , -- " -- . ) ) " -- ]
type ref = { src : string ; desc : string }
type paragraph = Normal of par_text | Pre of string * string option | Heading of int * par_text | Quote of paragraph list | Ulist of paragraph list * paragraph list list | Olist of paragraph list * paragraph list list Text of string | Emph of string | Bold of string | Struck of par_text | Code of string | Link of href ...
type parse_state = { max : int ; current : Buffer . t ; fragments : text list ; }
let string_of_paragraph p = Sexplib . Sexp . to_string_hum ( sexp_of_paragraph p )
let string_of_paragraphs ps = Sexplib . Sexp . to_string_hum ( sexp_of_par_list ps )
let indentation ( ? ts = 8 ) s = let rec loop n indent max = if n >= max then indent else match s . [ n ] with ' ' -> loop ( n + 1 ) ( indent + 1 ) max | ' \ t ' -> loop ( n + 1 ) ( indent + 8 ) max | _ -> indent in loop 0 0 ( String . length s )
let unescape s = let b = Buffer . create ( String . length s ) in let len = String . length s in let rec loop i = if i >= len then Buffer . contents b else match s . [ i ] with ' ' \\ when i < len - 1 -> Buffer . add_char b s . [ i + 1 ] ; loop ( i + 2 ) | c -> Buffer . add_char b c ; loop ( i + 1 ) in loop 0
let unescape_slice s ~ first ~ last = unescape ( String . strip ( String . slice ~ first ~ last s ) )
let snd_is s c = String . length s > 1 && s . [ 1 ] = c
let snd_is_space s = snd_is s ' ' || snd_is s ' \ t '
let collect f x = let rec loop acc = match f x with None -> List . rev acc | Some y -> loop ( y :: acc ) in loop [ ]
let push_remainder ( ? first = 2 ) indent s e = let s = String . slice ~ first s in let s ' = String . strip s in Enum . push e ( indent + first + indentation s , s ' , s ' = " " )
let new_fragment ( ) = Buffer . create 8
let push_current st = if Buffer . length st . current > 0 then Text ( Buffer . contents st . current ) :: st . fragments else st . fragments
let rec read_paragraph ( ? skip_blank = true ) indent e = match Enum . peek e with None -> None | Some ( indentation , line , isblank ) -> match isblank with true -> Enum . junk e ; if skip_blank then read_paragraph indent e else None | false -> if indentation < indent then None else begin Enum . junk e ; read_nonempty...
let parse_enum e = collect ( read_paragraph 0 ) ( Enum . map ( fun l -> let l ' = String . strip l in ( indentation l , l ' , l ' = " " ) ) e )
let parse_lines ls = parse_enum ( List . enum ls )
let parse_text s = parse_lines ( ( Str . split ( Str . regexp " \ n " ) s ) )
let do_chunk ~ drop_partial ( n : Timedesc . Span . t ) ( s : Time . Interval ' . t Seq . t ) : Time . Interval ' . t Seq . t = let open Timedesc . Span in let rec aux n s = match s ( ) with | Seq . Nil -> Seq . empty | Seq . Cons ( ( x , y ) , rest ) -> let size = y - x in if size >= n then fun ( ) -> Seq . Cons ( ( x...
let normalize ( s : Time . Interval ' . t Seq . t ) : Time . Interval ' . t Seq . t = let set = Seq . fold_left ( fun acc ( x , y ) -> Span_set . ( add ( Interval . make x y ) acc ) ) Span_set . empty s in Span_set . fold ( fun i l -> Span_set . Interval . ( x i , y i ) :: l ) set [ ] |> List . rev |> CCList . to_seq
let find_after ( bound : Timedesc . Span . t ) ( start : Timedesc . Span . t ) ( s2 : Timedesc . Span . t Seq . t ) : Timedesc . Span . t option = let open Timedesc . Span in let s = s2 |> OSeq . drop_while ( fun start ' -> start ' <= start ) |> OSeq . take_while ( fun start ' -> start ' - start <= bound ) in match s (...
let do_chunk_at_year_boundary tz ( s : Time . Interval ' . t Seq . t ) : Time . Interval ' . t Seq . t = let rec aux s = match s ( ) with | Seq . Nil -> Seq . empty | Seq . Cons ( ( t1 , t2 ) , rest ) -> let dt1 = CCOption . get_exn_or " Expected successful date time construction " @@ Timedesc . of_timestamp ~ tz_of_da...
let do_chunk_at_month_boundary tz ( s : Time . Interval ' . t Seq . t ) : Time . Interval ' . t Seq . t = let rec aux s = match s ( ) with | Seq . Nil -> Seq . empty | Seq . Cons ( ( t1 , t2 ) , rest ) -> let dt1 = CCOption . get_exn_or " Expected successful date time construction " @@ Timedesc . of_timestamp ~ tz_of_d...
let aux_iso_week_pattern_mem search_using_tz ( years : Int_set . t ) ( weeks : Int_set . t ) ( timestamp : int64 ) : bool = let dt = CCOption . get_exn_or " Expected successful date time construction " @@ Timedesc . of_timestamp ~ tz_of_date_time : search_using_tz ( Timedesc . Span . make ~ s : timestamp ( ) ) in let i...
let aux_iso_week_pattern ( search_start , search_end_exc ) search_using_tz years weeks : Span_set . t = let search_space_set = span_set_of_intervals @@ Seq . return ( search_start , search_end_exc ) in Seq_utils . a_to_b_inc_int64 ~ a ( : Timedesc . Span . get_s search_start ) ~ b ( : Timedesc . Span . get_s search_end...
let aux_pattern_mem search_using_tz ( pattern : Pattern . t ) ( timestamp : int64 ) : bool = let dt = CCOption . get_exn_or " Expected successful date time construction " @@ Timedesc . of_timestamp ~ tz_of_date_time : search_using_tz ( Timedesc . Span . make ~ s : timestamp ( ) ) in let weekday = Timedesc . weekday dt ...
let aux_pattern ( search_start , search_end_exc ) search_using_tz pattern : Span_set . t = let search_space_set = span_set_of_intervals @@ Seq . return ( search_start , search_end_exc ) in Seq_utils . a_to_b_inc_int64 ~ a ( : Timedesc . Span . get_s search_start ) ~ b ( : Timedesc . Span . get_s search_end_exc ) |> Seq...
let aux_points_mem search_using_tz ( { pick ; tz_info } : Points . t ) timestamp = let search_using_tz = match tz_info with | None -> search_using_tz | Some tz_info -> Timedesc . Time_zone_info . tz tz_info in aux_pattern_mem search_using_tz ( Points . to_pattern { pick ; tz_info } ) timestamp
let aux_points ( search_start , search_end_exc ) search_using_tz points : Timedesc . Span . t Seq . t = Seq_utils . a_to_b_inc_int64 ~ a ( : Timedesc . Span . get_s search_start ) ~ b ( : Timedesc . Span . get_s search_end_exc ) |> Seq . filter ( aux_points_mem search_using_tz points ) |> intervals_of_int64s |> Seq . m...
let resolve ( ? search_using_tz = Timedesc . Time_zone . utc ) ( ~ search_start : Timedesc . Span . t ) ( ~ search_end_exc : Timedesc . Span . t ) ( t : Time_ast . t ) : Time . Interval ' . t Seq . t = let default_result_space = Timedesc . ( Timestamp . min_val , Timestamp . max_val ) in let rec aux ( search_space : Ti...
module Alias_rules = struct let add sctx ~ alias ~ loc build = let dir = Alias . dir alias in SC . add_alias_action sctx alias ~ dir ~ loc build let add_empty sctx ~ loc ~ alias = let action = Action_builder . return ( Action . Full . make Action . empty ) in add sctx ~ loc ~ alias action end
let check_filename ~ kind = let not_in_dir ~ error_loc s = User_error . raise ~ loc : error_loc [ ( match kind with | Targets_spec . Kind . File -> Pp . textf " % S does not denote a file in the current directory . " s | Directory -> Pp . textf " Directory targets must have exactly one path component . " ) ] in fun ~ e...
type rule_kind = | Alias_only of Alias . Name . t | Alias_with_targets of Alias . Name . t * Path . Build . t | No_alias
let rule_kind ( ~ rule : Rule . t ) ( ~ action : _ Action_builder . With_targets . t ) = match rule . alias with | None -> No_alias | Some alias -> ( match Targets . head action . targets with | None -> Alias_only alias | Some target -> Alias_with_targets ( alias , target ) )
let interpret_and_add_locks ~ expander locks action = let + locks = Memo . List . map locks ~ f ( : Expander . No_deps . expand_path expander ) in match locks with | [ ] -> action | _ -> let open Action_builder . O in action >>| Action . Full . add_locks locks
let add_user_rule sctx ~ dir ( ~ rule : Rule . t ) ( ~ action : _ Action_builder . With_targets . t ) ~ expander = let * build = interpret_and_add_locks ~ expander rule . locks action . build in let action = { action with Action_builder . With_targets . build } in SC . add_rule_get_targets sctx ~ dir ~ mode : rule . mo...
let user_rule sctx ? extra_bindings ~ dir ~ expander ( rule : Rule . t ) = Expander . eval_blang expander rule . enabled_if >>= function | false -> ( match rule . alias with | None -> Memo . return None | Some name -> let alias = Alias . make ~ dir name in let + ( ) = Alias_rules . add_empty sctx ~ alias ~ loc ( : Some...
let copy_files sctx ~ dir ~ expander ~ src_dir ( def : Copy_files . t ) = let loc = String_with_vars . loc def . files in let * glob_in_src = let + src_glob = Expander . No_deps . expand_str expander def . files in if Filename . is_relative src_glob then Path . Source . relative src_dir src_glob ~ error_loc : loc |> Pa...
let copy_files sctx ~ dir ~ expander ~ src_dir ( def : Copy_files . t ) = Expander . eval_blang expander def . enabled_if >>= function | true -> copy_files sctx ~ dir ~ expander ~ src_dir def | false -> Memo . return Path . Set . empty
let alias sctx ? extra_bindings ~ dir ~ expander ( alias_conf : Alias_conf . t ) = let alias = Alias . make ~ dir alias_conf . name in let loc = Some alias_conf . loc in Expander . eval_blang expander alias_conf . enabled_if >>= function | false -> Alias_rules . add_empty sctx ~ loc ~ alias | true -> ( match alias_conf...
type ( ' ok , ' err ) result = Ok of ' ok | Error of ' err
type type_ = Type_arrow of type_ * type_ | Type_bool
let rec t_to_str type_ = match type_ with | Type_arrow ( ta , tr ) -> let ta2 = t_to_str ta in let tr2 = t_to_str tr in " ( lambda " ^ ta2 ^ " -> " ^ tr2 ^ " ) " | Type_bool -> " bool "
type t = | Term_var of info * int * int | Term_abs of info * string * type_ * t | Term_app of info * t * t | Term_true of info | Term_false of info | Term_if of info * t * t * t
type binding = Name_bind | Var_bind of type_
type ctx = ( string * binding ) list
let bind : ctx -> string -> binding -> ctx = fun ctx name binding -> ( name , binding ) :: ctx
let rec find_binding : ctx -> int -> binding option = fun ctx i -> match ctx with | [ ] -> None | ( _x , b ) :: rest -> if i = 0 then Some b else find_binding rest ( i - 1 )
let rec type_of : ctx -> t -> ( type_ , string ) result = fun ctx term -> match term with | Term_var ( _info , i , _ ) -> ( match find_binding ctx i with | None -> Error " Unbound_name " | Some ( Var_bind t ) -> Ok t | Some Name_bind -> Error " Untyped_binding " ) | Term_abs ( _info , name , arg_type , ret_type ) -> ( ...
let run ( ) = let print_result r = match r with | Error str -> Io . format " ERROR : ~ s \ n \ n " [ str ] | _ -> Io . format " ~ p \ n \ n " [ r ] in let f = Term_abs ( ( ) , " f " , Type_arrow ( Type_bool , Type_bool ) , Term_true ( ) ) in let app1 = Term_app ( ( ) , f , f ) in let app2 = Term_app ( ( ) , f , Term_ab...
type ' a boxed_int = | Int32 : int32 boxed_int | Int64 : int64 boxed_int | Nativeint : nativeint boxed_int
type value_string = { contents : string option ; size : int ; }
type unresolved_value = | Set_of_closures_id of Set_of_closures_id . t | Symbol of Symbol . t
type unknown_because_of = | Unresolved_value of unresolved_value | Other
type t = { descr : descr ; var : Variable . t option ; symbol : ( Symbol . t * int option ) option ; } | Value_block of Tag . t * t array | Value_int of int | Value_char of char | Value_constptr of int | Value_float of float option | Value_boxed_int : ' a boxed_int * ' a -> descr | Value_set_of_closures of value_set_of...
let descr t = t . descr
let print_value_set_of_closures ppf { function_decls = { funs } ; invariant_params ; freshening ; size ; _ } = Format . fprintf ppf " ( set_of_closures :@ % a invariant_params =% a freshening =% a size =% a ) " ( fun ppf -> Variable . Map . iter ( fun id _ -> Variable . print ppf id ) ) funs ( Variable . Map . print Va...
let print_unresolved_value ppf = function | Set_of_closures_id set -> Format . fprintf ppf " Set_of_closures_id % a " Set_of_closures_id . print set | Symbol symbol -> Format . fprintf ppf " Symbol % a " Symbol . print symbol
let print_function_declaration ppf var ( f : function_declaration ) = let param ppf p = Variable . print ppf ( Parameter . var p ) in let params ppf = List . iter ( Format . fprintf ppf " @ % a " param ) in match f . function_body with | None -> Format . fprintf ppf " [ @< 2 ( >% a @ =@ fun [ @< 2 >% a ] ) ] @@@ " Vari...
let print_function_declarations ppf ( fd : function_declarations ) = let funs ppf = Variable . Map . iter ( print_function_declaration ppf ) in Format . fprintf ppf " [ @< 2 ( >% a ) ] " @ funs fd . funs
let rec print_descr ppf = function | Value_int i -> Format . pp_print_int ppf i | Value_char c -> Format . fprintf ppf " % c " c | Value_constptr i -> Format . fprintf ppf " % ia " i | Value_block ( tag , fields ) -> let p ppf fields = Array . iter ( fun v -> Format . fprintf ppf " % a @ " print v ) fields in Format . ...
let approx descr = { descr ; var = None ; symbol = None }
let augment_with_variable t var = { t with var = Some var }
let augment_with_symbol t symbol = { t with symbol = Some ( symbol , None ) }
let augment_with_symbol_field t symbol field = match t . symbol with | None -> { t with symbol = Some ( symbol , Some field ) } | Some _ -> t
let replace_description t descr = { t with descr }
let augment_with_kind t ( kind : Lambda . value_kind ) = match kind with | Pgenval -> t | Pfloatval -> begin match t . descr with | Value_float _ -> t | Value_unknown _ | Value_unresolved _ -> { t with descr = Value_float None } | Value_block _ | Value_int _ | Value_char _ | Value_constptr _ | Value_boxed_int _ | Value...
let augment_kind_with_approx t ( kind : Lambda . value_kind ) : Lambda . value_kind = match t . descr with | Value_float _ -> Pfloatval | Value_int _ -> Pintval | Value_boxed_int ( Int32 , _ ) -> Pboxedintval Pint32 | Value_boxed_int ( Int64 , _ ) -> Pboxedintval Pint64 | Value_boxed_int ( Nativeint , _ ) -> Pboxedintv...
let value_unknown reason = approx ( Value_unknown reason )
let value_int i = approx ( Value_int i )
let value_char i = approx ( Value_char i )
let value_constptr i = approx ( Value_constptr i )
let value_float f = approx ( Value_float ( Some f ) )
let value_any_float = approx ( Value_float None )
let value_boxed_int bi i = approx ( Value_boxed_int ( bi , i ) )
let value_closure ? closure_var ? set_of_closures_var ? set_of_closures_symbol value_set_of_closures closure_id = let approx_set_of_closures = { descr = Value_set_of_closures value_set_of_closures ; var = set_of_closures_var ; symbol = Option . map ( fun s -> s , None ) set_of_closures_symbol ; } in let value_closure =...
let create_value_set_of_closures ( ~ function_decls : function_declarations ) ~ bound_vars ~ free_vars ~ invariant_params ~ recursive ~ specialised_args ~ freshening ~ direct_call_surrogates = let size = lazy ( let functions = Variable . Map . keys function_decls . funs in Variable . Map . fold ( fun fun_var function_d...
let update_freshening_of_value_set_of_closures value_set_of_closures ~ freshening = { value_set_of_closures with freshening ; }
let value_set_of_closures ? set_of_closures_var value_set_of_closures = { descr = Value_set_of_closures value_set_of_closures ; var = set_of_closures_var ; symbol = None ; }
let value_block t b = approx ( Value_block ( t , b ) )
let value_extern ex = approx ( Value_extern ex )
let value_symbol sym = { ( approx ( Value_symbol sym ) ) with symbol = Some ( sym , None ) }
let value_bottom = approx Value_bottom
let value_unresolved value = approx ( Value_unresolved value )
let value_string size contents = approx ( Value_string { size ; contents } )
let value_mutable_float_array ~ size = approx ( Value_float_array { contents = Unknown_or_mutable ; size ; } )
let value_immutable_float_array ( contents : t array ) = let size = Array . length contents in let contents = Array . map ( fun t -> augment_with_kind t Pfloatval ) contents in approx ( Value_float_array { contents = Contents contents ; size ; } )
let name_expr_fst ( named , thing ) ~ name = ( Flambda_utils . name_expr named ~ name ) , thing
let make_const_int_named n : Flambda . named * t = Const ( Int n ) , value_int n
let make_const_int ( n : int ) = let name = match n with | 0 -> Internal_variable_names . const_zero | 1 -> Internal_variable_names . const_one | _ -> Internal_variable_names . const_int in name_expr_fst ( make_const_int_named n ) ~ name
let make_const_char_named n : Flambda . named * t = Const ( Char n ) , value_char n