text
stringlengths
0
601k
let cTKtoCAMLanimatedGif s = match splitlist s with | [ width ; height ; frames ; loop ] -> { frames = List . map cTKtoCAMLgifFrame ( splitlist frames ) ; animWidth = int_of_string width ; animHeight = int_of_string height ; loop = int_of_string loop } | _ -> raise ( Invalid_argument ( " cTKtoCAMLgifFrame : " ^ s ) )
let available ( ) = let packages = splitlist ( Protocol . tkEval [ | TkToken " package " ; TkToken " names " ] ) | in List . mem " Tkanim " packages
let create file = let s = Protocol . tkEval [ | TkToken " animation " ; TkToken " create " ; TkToken file ] | in let anmgif = cTKtoCAMLanimatedGif s in match anmgif . frames with | [ ] -> raise ( TkError " Null frame in a gif " ) ? | [ x ] -> Still ( ImagePhoto x . imagephoto ) | _ -> Animated anmgif
let delete anim = List . iter ( fun { imagephoto = i } -> Imagephoto . delete i ) anim . frames
let width anm = anm . animWidth
let height anm = anm . animHeight
let images anm = List . map ( fun x -> x . imagephoto ) anm . frames
let image_existence_check img = try ignore ( Imagephoto . height img ) with TkError s -> prerr_endline ( " tkanim : " ^ s ) ; raise ( TkError s )
let imagephoto_copy dst src opts = image_existence_check src ; Imagephoto . copy dst src opts
let animate_gen w i anim = let length = List . length anim . frames in let frames = Array . of_list anim . frames in let current = ref 0 in let loop = ref anim . loop in let f = frames . ( ! current ) in imagephoto_copy i f . imagephoto [ ImgTo ( f . left , f . top , f . left + f . frameWidth , f . top + f . frameHeigh...
let animate label anim = let i = Imagephoto . create [ Width ( Pixels anim . animWidth ) ; Height ( Pixels anim . animHeight ) ] in bind label [ [ ] , Destroy ] ( BindExtend ( [ ] , ( fun _ -> Imagephoto . delete i ) ) ) ; Label . configure label [ ImagePhoto i ] ; animate_gen label i anim
let animate_canvas_item canvas tag anim = let i = Imagephoto . create [ Width ( Pixels anim . animWidth ) ; Height ( Pixels anim . animHeight ) ] in bind canvas [ [ ] , Destroy ] ( BindExtend ( [ ] , ( fun _ -> Imagephoto . delete i ) ) ) ; Canvas . configure_image canvas tag [ ImagePhoto i ] ; animate_gen canvas i ani...
let gifdata s = let tmp_dir = ref Filename . temp_dir_name in let mktemp = let cnter = ref 0 and pid = Unix . getpid ( ) in ( function prefx -> incr cnter ; ( Filename . concat ! tmp_dir ( prefx ^ string_of_int pid ^ " . " ^ string_of_int ! cnter ) ) ) in let fname = mktemp " gifdata " in let oc = open_out_bin fname in...
let rec find_loc_expression char_start char_stop expr = if char_start = expr . Typedtree . exp_loc . Location . loc_start && char_stop = expr . Typedtree . exp_loc . Location . loc_end then raise ( Found expr ) ; if char_start >= expr . Typedtree . exp_loc . Location . loc_start && char_stop <= expr . Typedtree . exp_l...
let line_column_to_char_number lines_mappping line char = ( lines_mappping . ( line ) ) + char ; ;
let char_number_to_line_column lines_mappping char_number = let max_l = Array . length lines_mappping in let rec find l = if l > max_l then assert false ; if char_number < lines_mappping . ( l ) then begin let line = l - 1 in let char = char_number - lines_mappping . ( l - 1 ) in ( line , char ) end else find ( l + 1 )...
let create_mark_radical = let cpt = ref 0 in function ( ) -> let name = " MARK " ^ ( string_of_int ! cpt ) in incr cpt ; name ; ;
let create_popup parent_w expression = let new_window = Toplevel . create parent_w [ ] in Wm . title_set new_window " Zoom " ; let label0_w = Label . create new_window [ Text " Type of expression " ] in let text0_w = Text . create new_window [ Background ( NamedColor " LightSteelBlue " ) ; let label1_w = Label . create...
let make_callback widget lines_mappping syntax_tree _ = try begin let ( line , char ) = ( match Text . index widget ( TextIndex ( TagFirst " sel " , [ ] ) ) with LineChar ( l , c ) -> ( l - 1 , c ) | _ -> assert false ) in let char_start = line_column_to_char_number lines_mappping line char in let ( line ' , char ' ) =...
let load_source widget filename syntax_tree = let in_channel = Stdlibpath . open_in_with_path filename in let char_of_begin_line = ref 0 in let current_mapping = ref [ ] in try while true do current_mapping := ! char_of_begin_line :: ! current_mapping ; let l = ( input_line in_channel ) " ^\ n " in char_of_begin_line :...
let scan_string pcontext s pos num = let text_w = pcontext . Printcontext . widget in let tag_buffer = pcontext . Printcontext . tag_buffer in let tag_scan_flag = pcontext . Printcontext . tag_scan_flag in let start = ref pos in for i = pos to pos + num - 1 do match s . [ i ] with | ' \ 006 ' -> ( String . sub s ! star...
let scan_string_at pcontext index s pos num = let text_w = pcontext . Printcontext . widget in let tag_buffer = pcontext . Printcontext . tag_buffer in let tag_scan_flag = pcontext . Printcontext . tag_scan_flag in let left_indent = pcontext . Printcontext . left_indent in let start = ref pos in for i = pos to pos + nu...
let create_mark_radical = let cpt = ref 0 in function ( ) -> let name = " MARK " ^ ( string_of_int ! cpt ) in incr cpt ; name ; ;
let pp_label_description pcontext ppf lbl_desc = fprintf ppf " % a :@ % a " Printbasic . pp_mutable_flag lbl_desc . Typedtree . fld_mut ( Tkprinttypes . pp_ml_type_scheme pcontext ) lbl_desc . Typedtree . fld_scheme ; ;
let rec pp_signature pcontext ppf signature = let iter_pp_signature_item = Printbasic . iter_pp " " ( pp_signature_item pcontext ) in fprintf ppf " % a " iter_pp_signature_item signature | Typedtree . Tsig_value ( ident , scheme ) -> let mark_r = create_mark_radical ( ) in let pcontext ' = { pcontext with Printcontext ...
let jobs : ( unit -> unit ) Queue . t = Queue . create ( )
let m = Mutex . create ( )
let with_jobs f = Mutex . lock m ; let y = f jobs in Mutex . unlock m ; y
let loop_id = ref None
let gui_safe ( ) = ! loop_id = Some ( Thread . id ( Thread . self ( ) ) )
let running ( ) = ! loop_id <> None
let has_jobs ( ) = not ( with_jobs Queue . is_empty )
let n_jobs ( ) = with_jobs Queue . length
let do_next_job ( ) = with_jobs Queue . take ( )
let async j x = with_jobs ( Queue . add ( fun ( ) -> j x ) )
let sync f x = if ! loop_id = None then failwith " Tkthread . sync " ; if gui_safe ( ) then f x else let m = Mutex . create ( ) in let res = ref None in Mutex . lock m ; let c = Condition . create ( ) in let j x = let y = f x in Mutex . lock m ; res := Some y ; Mutex . unlock m ; Condition . signal c in async j x ; Con...
let rec job_timer ( ) = Timer . set ~ ms : 10 ~ callback : ( fun ( ) -> for i = 1 to n_jobs ( ) do do_next_job ( ) done ; job_timer ( ) )
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 , osx ] . " in value & opt string Environme...
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_page $ ( const ( String . concat ~ sep " " ) :- $ Args . ...
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 f_reader writer | Error read_error -> Log ....
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 . of_pipe ( Info . of_string " tls_wr...
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 ) = upgrade_server...
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 = Tcp . connect ? socket ? buffer_age_lim...
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 -> ' b io ) -> ' b io val map : ( ' a -> ' b ) -> ' 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 . t ; mutable state : [ ` Active of Tls . Engine...
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 ai . ai_addr
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 . write " Lwt_bytes . write and read = naked ...
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 _ -> return_unit ) ( fun _ -> return_unit ) let ( read_t , wri...
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 . ( safely ( close t ) ) ) in ( Lwt_io . make ~ close ~ mode :...
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_error ppf = function | ` Tls_failure f -> Fm...
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 = function ` Msg m -> Fmt . string ppf m let d...
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 ) -> lambda val delay_impure : block_id : ...
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 -> ' b t val pair : ' a t -> ' b 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 ( ) -> v ) ; tmc_calls = [ ] ; benefits_from_dps = false...
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 ; direct_kind ; } in { specialized = Ident . Map...
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 | Lapply apply -> choice_apply ctx ~ ...
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 different ways . Please \ disambiguate by ...
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_ns . ns_xs ; ns_ns = union from_ns...
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