text
stringlengths
12
786k
let thread_main ( ) = try loop_id := Some ( Thread . id ( Thread . self ( ) ) ) ; ignore ( Protocol . openTk ( ) ) ; job_timer ( ) ; Protocol . mainLoop ( ) ; loop_id := None ; with exn -> loop_id := None ; raise exn
let start ( ) = let th = Thread . create thread_main ( ) in loop_id := Some ( Thread . id th ) ; th
let no_documentation = Printf . sprintf " ` % s ` documentation is not available . \ n Consider contributing Pull Request to https :// github . com / tldr - pages / tldr "
let display_page command platform update_cache = ignore update_cache ; match get_page command platform with | Missing -> Stdio . printf " % s \ n " ( no_documentation command ) | Error e -> Stdio . printf " % s \ n " e | Success page -> Display . display page
module Args = struct open Arg let command = let doc = " Display the tldr page for ( $ docv ) " in non_empty & pos_all string [ ] & info [ ] ~ docv " : COMMAND " ~ doc let platform = let doc = " Display the command for a given ( $ docv ) . Options can be one of [ linux , sunos...
let ( ) = let open Term in let info = let doc = " Simplified man pages " in let man = [ ` S Manpage . s_bugs ; ` P " Email bug reports to < rosaleschase . j @ gmail . com . " > ] in info " tldr " ~ version " : 0 . 3 . 0 " ~ doc ~ man in let run_t = const display_...
let try_to_close t = match % map Session . close_tls t with | Ok ( ) -> ( ) | Error tls_close_error -> Log . Global . error_s [ % sexp ( tls_close_error : Error . t ) ] ; ;
let pipe t = let b_reader = Cstruct . create 0x8000 in let rec f_reader writer = match % bind Session . read t b_reader with | Ok 0 -> Pipe . close writer ; return ( ) | Ok len -> let % bind ( ) = Pipe . write writer ( Cstruct . to_string ( Cstruct . sub b_reader 0 len ) ) in ...
let upgrade_connection tls_session ( ( _ : Reader . t ) , outer_writer ) = let pipe_r , pipe_w = pipe tls_session in let % bind inner_reader = Reader . of_pipe ( Info . of_string " tls_reader " ) pipe_r in let % map inner_writer , ` Closed_and_flushed_downstream inner_cafd = Writer...
let upgrade_server_reader_writer_to_tls config rw = let open Deferred . Or_error . Let_syntax in let % bind tls_session = Session . server_of_fd config rw in upgrade_connection tls_session rw |> Deferred . ok ; ;
let upgrade_client_reader_writer_to_tls ? host config rw = let open Deferred . Or_error . Let_syntax in let % bind tls_session = Session . client_of_fd ? host config rw in upgrade_connection tls_session rw |> Deferred . ok ; ;
let listen ? buffer_age_limit ? max_connections ? max_accepts_per_batch ? backlog ? socket ~ on_handler_error config where_to_listen handle_client = let tls_handler sock outer_reader outer_writer = let % bind ( tls_session , inner_reader , inner_writer , ` Tls_closed_and_flushed_downstream inner_cafd...
let connect ? socket ? buffer_age_limit ? interrupt ? reader_buffer_size ? writer_buffer_size ? timeout ? time_source config where_to_connect ~ host = let open Deferred . Or_error . Let_syntax in let % bind ( _ : ( [ ` Active ] , ' a ) Socket . t ) , outer_reader , outer_writer ...
let ( ) = Mirage_crypto_rng_async . initialize ( module Mirage_crypto_rng . Fortuna )
let ( . <> ) f g x = f ( g x )
module type FLOW = sig type t type error type ' + a io val read : t -> bytes -> int -> int -> ( [ ` End | ` Len of int ] , error ) result io val fully_write : t -> string -> int -> int -> ( unit , error ) result io val close : t -> unit io val bind : ' a io -> ( ' a -> ' ...
module Make ( Flow : FLOW ) = struct type error = | Alert of Tls . Packet . alert_type | Failure of Tls . Engine . failure | Flow_error of Flow . error | Closed let ( >>= ) = Flow . bind let ( >>| ) x f = Flow . map f x let return = Flow . return type t = { socket : Flow . ...
let o f g x = f ( g x )
let resolve host service = let open Lwt_unix in getprotobyname " tcp " >>= fun tcp -> getaddrinfo host service [ AI_PROTOCOL tcp . p_proto ] >>= function | [ ] -> let msg = Printf . sprintf " no address for % s :% s " host service in fail ( Invalid_argument msg ) | ai :: _ -> return...
module Lwt_cs = struct let naked ~ name f fd cs = Cstruct . ( f fd cs . buffer cs . off cs . len ) >>= fun res -> match Lwt_unix . getsockopt_error fd with | None -> return res | Some err -> fail @@ Unix . Unix_error ( err , name , " " ) let write = naked ~ name " : Tls_lwt . ...
module Unix = struct type t = { fd : Lwt_unix . file_descr ; mutable state : [ ` Active of Tls . Engine . state | ` Eof | ` Error of exn ] ; mutable linger : Cstruct . t option ; recv_buf : Cstruct . t ; } let safely th = Lwt . catch ( fun ( ) -> th >>= fun _ -> retu...
let of_t ? close t = let close = match close with | Some f -> ( fun ( ) -> Unix . safely ( f ( ) ) ) | None -> ( fun ( ) -> match Lwt_unix . state t . Unix . fd with | Lwt_unix . Closed -> Lwt . return_unit | Lwt_unix . Opened | Lwt_unix . Aborted _ -> Unix . ( s...
let accept_ext conf fd = Unix . accept conf fd >|= fun ( t , peer ) -> ( of_t t , peer ) Unix . connect conf addr >|= of_t
let accept certificate = let config = Tls . Config . server ~ certificates : certificate ( ) in accept_ext config let config = Tls . Config . client ~ authenticator ( ) in connect_ext config addr
let ( ) = Mirage_crypto_rng_lwt . initialize ( )
let ( ) = Printexc . register_printer ( function | Tls_alert typ -> Some ( " TLS alert from peer : " ^ Tls . Packet . alert_type_to_string typ ) | Tls_failure f -> Some ( " TLS failure : " ^ Tls . Engine . string_of_failure f ) | _ -> None )
module Make ( F : Mirage_flow . S ) = struct module FLOW = F type error = [ ` Tls_alert of Tls . Packet . alert_type | ` Tls_failure of Tls . Engine . failure | ` Read of F . error | ` Write of F . write_error ] type write_error = [ Mirage_flow . write_error | error ] let pp...
module X509 ( KV : Mirage_kv . RO ) ( C : Mirage_clock . PCLOCK ) = struct let ca_roots_file = Mirage_kv . Key . v " ca - roots . crt " let default_cert = " server " let err_fail pp = function | Ok x -> return x | Error e -> Fmt . kstr fail_with " % a " pp e let pp_msg ppf =...
type tmc_call_information = { loc : scoped_location ; explicit : bool ; }
type subterm_information = { tmc_calls : tmc_call_information list ; }
type ambiguous_arguments = { explicit : bool ; arguments : subterm_information list ; }
type error = | Ambiguous_constructor_arguments of ambiguous_arguments
type ' offset destination = { var : Ident . t ; offset : ' offset ; loc : Debuginfo . Scoped_location . t ; }
let offset_code ( Offset t ) = t
let add_dst_params ( { var ; offset } : Ident . t destination ) params = ( var , Pgenval ) :: ( offset , Pintval ) :: params
let add_dst_args ( { var ; offset } : offset destination ) args = Lvar var :: offset_code offset :: args
let assign_to_dst { var ; offset ; loc } lam = Lprim ( Psetfield_computed ( Pointer , Heap_initialization ) , [ Lvar var ; offset_code offset ; lam ] , loc )
module Constr : sig type t = { tag : int ; flag : Asttypes . mutable_flag ; shape : block_shape ; before : lambda list ; after : lambda list ; loc : Debuginfo . Scoped_location . t ; } val apply : t -> lambda -> lambda val with_placeholder : t -> ( offset destination -> lambda ) ...
module Dps : sig type ' a dps = tail : bool -> dst : offset destination -> ' a type ' a t val make : lambda dps -> lambda t val run : lambda t -> lambda dps val delay_constructor : Constr . t -> lambda t -> lambda t val lambda : lambda -> lambda t val map : ( ' a -> ' b ) -> ' a t -...
module Choice = struct type ' a t = { dps : ' a Dps . t ; direct : unit -> ' a ; tmc_calls : tmc_call_information list ; benefits_from_dps : bool ; explicit_tailcall_request : bool ; } let lambda ( v : lambda ) : lambda t = { dps = Dps . lambda v ; direct = ( fun ( ) ...
type context = { specialized : specialized Ident . Map . t ; } arity : int ; dps_id : Ident . t ; direct_kind : function_kind ; }
let llets lk vk bindings body = List . fold_right ( fun ( var , def ) body -> Llet ( lk , vk , var , def , body ) ) bindings body
let find_candidate = function | Lfunction lfun when lfun . attr . tmc_candidate -> Some lfun | _ -> None
let declare_binding ctx ( var , def ) = match find_candidate def with | None -> ctx | Some lfun -> let arity = List . length lfun . params in let dps_id = Ident . create_local ( Ident . name var ^ " _dps " ) in let direct_kind = lfun . kind in let cand = { arity ; dps_id ; direc...
let rec choice ctx t = let rec choice ctx ~ tail t = match t with | ( Lvar _ | Lmutvar _ | Lconst _ | Lfunction _ | Lsend _ | Lassign _ | Lfor _ | Lwhile _ ) -> let t = traverse ctx t in Choice . lambda t | Lprim ( prim , primargs , loc ) -> choice_prim ctx ~ tail prim primargs loc...
let rewrite t = let ctx = { specialized = Ident . Map . empty } in traverse ctx t
let ( ) = Location . register_error_of_exn ( function | Error ( loc , Ambiguous_constructor_arguments { explicit = false ; arguments } ) -> let print_msg ppf = Format . pp_print_text ppf " [ @ tail_mod_cons ] : this constructor application may be \ TMC - transformed in several diffe...
let type_declarations : type_declaration Hts . t = Hts . create 0
module Mstr = Map . Make ( String )
type namespace = { ns_ts : tysymbol Mstr . t ; ns_ls : lsymbol Mstr . t ; ns_fd : lsymbol Mstr . t ; ns_xs : xsymbol Mstr . t ; ns_ns : namespace Mstr . t ; ns_tns : namespace Mstr . t ; }
let empty_ns = { ns_ts = Mstr . empty ; ns_ls = Mstr . empty ; ns_fd = Mstr . empty ; ns_xs = Mstr . empty ; ns_ns = Mstr . empty ; ns_tns = Mstr . empty ; }
let add ~ allow_duplicate ~ equal ~ loc ns s x = if allow_duplicate then Mstr . add s x ns else match Mstr . find s ns with | t when not ( equal t x ) -> W . error ~ loc ( W . Name_clash s ) | _ | ( exception Not_found ) -> Mstr . add s x ns
let ns_add_ts ~ allow_duplicate ns s ts = let ns_ts = add ~ allow_duplicate ~ equal : ts_equal ~ loc : ts . ts_ident . id_loc ns . ns_ts s ts in { ns with ns_ts }
let ns_add_ls ~ allow_duplicate : _ ns s ls = let ns_ls = add ~ allow_duplicate : true ~ equal : ls_equal ~ loc : ls . ls_name . id_loc ns . ns_ls s ls in { ns with ns_ls }
let ns_add_fd ~ allow_duplicate : _ ns s fd = let ns_fd = add ~ allow_duplicate : true ~ equal : ls_equal ~ loc : fd . ls_name . id_loc ns . ns_fd s fd in { ns with ns_fd }
let ns_add_xs ~ allow_duplicate ns s xs = let ns_xs = add ~ allow_duplicate ~ equal : xs_equal ~ loc : xs . xs_ident . id_loc ns . ns_xs s xs in { ns with ns_xs }
let ns_add_ns ~ allow_duplicate : _ ns s new_ns = { ns with ns_ns = Mstr . add s new_ns ns . ns_ns }
let ns_add_tns ~ allow_duplicate : _ ns s tns = { ns with ns_tns = Mstr . add s tns ns . ns_tns }
let merge_ns from_ns to_ns = let choose_fst _ x _ = Some x in let union m1 m2 = Mstr . union choose_fst m1 m2 in { ns_ts = union from_ns . ns_ts to_ns . ns_ts ; ns_ls = union from_ns . ns_ls to_ns . ns_ls ; ns_fd = union from_ns . ns_fd to_ns . ns_fd ; ns_xs = union from_ns . ns_xs to_n...
let rec ns_find get_map ns = function | [ ] -> assert false | [ x ] -> Mstr . find x ( get_map ns ) | x :: xs -> ns_find get_map ( Mstr . find x ns . ns_ns ) xs
let ns_find_ts ns s = ns_find ( fun ns -> ns . ns_ts ) ns s
let ns_find_ls ns s = ns_find ( fun ns -> ns . ns_ls ) ns s
let ns_find_fd ns s = ns_find ( fun ns -> ns . ns_fd ) ns s
let ns_find_xs ns s = ns_find ( fun ns -> ns . ns_xs ) ns s
let ns_find_ns ns s = ns_find ( fun ns -> ns . ns_ns ) ns s
let ns_find_tns ns s = ns_find ( fun ns -> ns . ns_tns ) ns s
let ns_exists_ns ns s = Mstr . mem s ns . ns_ns
let rec ns_rm_ts ns = function | [ ] -> assert false | [ x ] -> { ns with ns_ts = Mstr . remove x ns . ns_ts } | x :: xs -> let x_ns = ns_rm_ts ( Mstr . find x ns . ns_ns ) xs in { ns with ns_ns = Mstr . add x x_ns ns . ns_ns }
let rec ns_replace_ts new_ts sl ns = match sl with | [ ] -> assert false | [ x ] -> { ns with ns_ts = Mstr . add x new_ts ns . ns_ts } | x :: xs -> let ns_ns = Mstr . find x ns . ns_ns in let ns_ns = ns_replace_ts new_ts xs ns_ns in { ns with ns_ns = Mstr . add x ns_ns ns . ns_ns }...
let rec ns_subst_ts old_ns new_ts { ns_ts ; ns_ls ; ns_fd ; ns_xs ; ns_ns ; ns_tns } = { ns_ts = Mstr . map ( ts_subst_ts old_ns new_ts ) ns_ts ; ns_ls = Mstr . map ( ls_subst_ts old_ns new_ts ) ns_ls ; ns_fd = Mstr . map ( ls_subst_ts old_ns new_ts ) ns_fd ; ns_xs = Mstr . ...
let rec ns_subst_ty old_ts new_ts ty { ns_ts ; ns_ls ; ns_fd ; ns_xs ; ns_ns ; ns_tns } = { ns_ts = Mstr . map ( ts_subst_ty old_ts new_ts ty ) ns_ts ; ns_ls = Mstr . map ( ls_subst_ty old_ts new_ts ty ) ns_ls ; ns_fd = Mstr . map ( ls_subst_ty old_ts new_ts ty ) ns_fd ; ns_x...
let mk_td ts kind = { Tast . td_ts = ts ; td_params = [ ] ; td_cstrs = [ ] ; td_kind = kind ; td_private = Tast . Public ; td_manifest = None ; td_attrs = [ ] ; td_spec = None ; td_loc = Location . none ; }
let mk_abstract_td ts = mk_td { Ttypes . ts_ident = ts . ts_ident ; ts_args = [ ] ; ts_alias = None } Tast . Pty_abstract
let ns_with_primitives = let primitive_tys = [ ( " integer " , ts_integer ) ; ( " int " , ts_int ) ; ( " char " , ts_char ) ; ( " bytes " , ts_bytes ) ; ( " string " , ts_string ) ; ( " float " , ts_float ) ; ( " bool " , ts_bool ) ; ...
module Mid = Map . Make ( Ident )
type known_ids = signature_item Mid . t
type file = { fl_nm : Ident . t ; fl_sigs : signature ; fl_export : namespace }
type module_uc = { muc_nm : Ident . t ; muc_sigs : signature list ; muc_prefix : string list ; muc_import : namespace list ; muc_export : namespace list ; muc_files : file Mstr . t ; muc_kid : known_ids ; muc_crcm : Coercion . t ; }
let muc_add ( ? export = false ) add muc s x = match ( muc . muc_import , muc . muc_export ) with | i0 :: il , e0 :: el -> let i = add ~ allow_duplicate : true i0 s x in let e = if export then add ~ allow_duplicate : false e0 s x else e0 in { muc with muc_import = i :: il ; muc_export...
let add_ts ( ? export = false ) = muc_add ~ export ns_add_ts
let add_ls ( ? export = false ) = muc_add ~ export ns_add_ls
let add_fd ( ? export = false ) = muc_add ~ export ns_add_fd
let add_xs ( ? export = false ) = muc_add ~ export ns_add_xs
let add_ns ( ? export = false ) = muc_add ~ export ns_add_ns
let add_tns ( ? export = false ) = muc_add ~ export ns_add_tns
let add_file muc s file = { muc with muc_files = Mstr . add s file muc . muc_files }
let get_file muc s = Mstr . find s muc . muc_files
let add_kid muc id s = { muc with muc_kid = Mid . add id s muc . muc_kid }
let add_sig muc sig_ = match muc . muc_sigs with | s0 :: sl -> { muc with muc_sigs = ( sig_ :: s0 ) :: sl } | _ -> assert false
let add_coer muc ls = { muc with muc_crcm = Coercion . add muc . muc_crcm ls }
let add_ns_top ( ? export = false ) muc ns = let add f muc map = Mstr . fold ( fun s v muc -> f muc s v ) map muc in let muc = add ( add_ts ~ export ) muc ns . ns_ts in let muc = add ( add_ls ~ export ) muc ns . ns_ls in let muc = add ( add_fd ~ export ) muc ns . ns_fd in let muc ...
let muc_replace_ts muc new_ts sl = match ( muc . muc_import , muc . muc_export ) with | i0 :: il , e0 :: el -> { muc with muc_import = ns_replace_ts new_ts sl i0 :: il ; muc_export = ns_replace_ts new_ts sl e0 :: el ; } | _ -> assert false
let muc_subst_ts muc old_ts new_ts = match ( muc . muc_import , muc . muc_export ) with | i0 :: il , e0 :: el -> { muc with muc_import = ns_subst_ts old_ts new_ts i0 :: il ; muc_export = ns_subst_ts old_ts new_ts e0 :: el ; } | _ -> assert false
let muc_subst_ty muc old_ts new_ts ty = match ( muc . muc_import , muc . muc_export ) with | i0 :: il , e0 :: el -> { muc with muc_import = ns_subst_ty old_ts new_ts ty i0 :: il ; muc_export = ns_subst_ty old_ts new_ts ty e0 :: el ; } | _ -> assert false
let muc_rm_ts muc sl = match ( muc . muc_import , muc . muc_export ) with | i0 :: il , e0 :: el -> { muc with muc_import = ns_rm_ts i0 sl :: il ; muc_export = ns_rm_ts e0 sl :: el ; } | _ -> assert false
let open_empty_module muc s = { muc with muc_prefix = s :: muc . muc_prefix ; muc_sigs = [ ] :: muc . muc_sigs ; muc_import = ns_with_primitives :: muc . muc_import ; muc_export = empty_ns :: muc . muc_export ; }
let close_module_file muc = match ( muc . muc_import , muc . muc_export , muc . muc_prefix , muc . muc_sigs ) with | _ :: i1 :: il , e0 :: e1 :: el , p0 :: pl , s0 :: sl -> let file = { fl_nm = Ident . create ~ loc : Location . none p0 ; fl_sigs = List . rev s0 ; fl_ex...
let open_module muc s = match muc . muc_import with | i0 :: _ -> { muc with muc_prefix = s :: muc . muc_prefix ; muc_sigs = [ ] :: muc . muc_sigs ; muc_import = i0 :: muc . muc_import ; muc_export = empty_ns :: muc . muc_export ; } | _ -> assert false
let close_module muc = match ( muc . muc_import , muc . muc_export , muc . muc_prefix , muc . muc_sigs ) with | _ :: i1 :: il , e0 :: e1 :: el , p0 :: pl , _ :: sl -> { muc with muc_prefix = pl ; muc_import = ns_add_ns ~ allow_duplicate : true i1 p0 e0 :: il ; muc_export =...
let close_module_functor muc = match ( muc . muc_import , muc . muc_export , muc . muc_prefix , muc . muc_sigs ) with | _ :: i1 :: il , e0 :: e1 :: el , p0 :: pl , _ :: sl -> { muc with muc_prefix = pl ; muc_import = ns_add_ns ~ allow_duplicate : true i1 p0 e0 :: il ; muc_e...