text
stringlengths
12
786k
type popen_process = Process of in_channel * out_channel | Process_in of in_channel | Process_out of out_channel | Process_full of in_channel * out_channel * in_channel
let popen_processes = ( Hashtbl . create 7 : ( popen_process , int ) Hashtbl . t )
let open_proc prog cmdline optenv proc input output error = let pid = win_create_process prog cmdline optenv input output error in Hashtbl . add popen_processes proc pid
let open_process_cmdline_in prog cmdline = let ( in_read , in_write ) = pipe ~ cloexec : true ( ) in let inchan = in_channel_of_descr in_read in begin try open_proc prog cmdline None ( Process_in inchan ) stdin in_write stderr with e -> close_in inchan ; close in_write ; raise e end ; close in...
let open_process_cmdline_out prog cmdline = let ( out_read , out_write ) = pipe ~ cloexec : true ( ) in let outchan = out_channel_of_descr out_write in begin try open_proc prog cmdline None ( Process_out outchan ) out_read stdout stderr with e -> close_out outchan ; close out_read ; raise e end ...
let open_process_cmdline prog cmdline = let ( in_read , in_write ) = pipe ~ cloexec : true ( ) in let ( out_read , out_write ) = try pipe ~ cloexec : true ( ) with e -> close in_read ; close in_write ; raise e in let inchan = in_channel_of_descr in_read in let outchan = out_channel_of_...
let open_process_cmdline_full prog cmdline env = let ( in_read , in_write ) = pipe ~ cloexec : true ( ) in let ( out_read , out_write ) = try pipe ~ cloexec : true ( ) with e -> close in_read ; close in_write ; raise e in let ( err_read , err_write ) = try pipe ~ cloexec : true ...
let open_process_args_in prog args = open_process_cmdline_in prog ( make_cmdline args )
let open_process_args_out prog args = open_process_cmdline_out prog ( make_cmdline args )
let open_process_args prog args = open_process_cmdline prog ( make_cmdline args )
let open_process_args_full prog args = open_process_cmdline_full prog ( make_cmdline args )
let open_process_shell fn cmd = let shell = try Sys . getenv " COMSPEC " with Not_found -> raise ( Unix_error ( ENOEXEC , " open_process_shell " , cmd ) ) in fn shell ( shell ^ " / c " ^ cmd )
let open_process_in cmd = open_process_shell open_process_cmdline_in cmd
let open_process_out cmd = open_process_shell open_process_cmdline_out cmd
let open_process cmd = open_process_shell open_process_cmdline cmd
let open_process_full cmd = open_process_shell open_process_cmdline_full cmd
let find_proc_id fun_name proc = try Hashtbl . find popen_processes proc with Not_found -> raise ( Unix_error ( EBADF , fun_name , " " ) )
let remove_proc_id proc = Hashtbl . remove popen_processes proc
let process_in_pid inchan = find_proc_id " process_in_pid " ( Process_in inchan )
let process_out_pid outchan = find_proc_id " process_out_pid " ( Process_out outchan )
let process_pid ( inchan , outchan ) = find_proc_id " process_pid " ( Process ( inchan , outchan ) )
let process_full_pid ( inchan , outchan , errchan ) = find_proc_id " process_full_pid " ( Process_full ( inchan , outchan , errchan ) )
let close_process_in inchan = let proc = Process_in inchan in let pid = find_proc_id " close_process_in " proc in remove_proc_id proc ; close_in inchan ; snd ( waitpid [ ] pid )
let close_process_out outchan = let proc = Process_out outchan in let pid = find_proc_id " close_process_out " proc in remove_proc_id proc ; close_out outchan ; snd ( waitpid [ ] pid )
let close_process ( inchan , outchan ) = let proc = Process ( inchan , outchan ) in let pid = find_proc_id " close_process " proc in remove_proc_id proc ; close_in inchan ; close_out outchan ; snd ( waitpid [ ] pid )
let close_process_full ( inchan , outchan , errchan ) = let proc = Process_full ( inchan , outchan , errchan ) in let pid = find_proc_id " close_process_full " proc in remove_proc_id proc ; close_in inchan ; close_out outchan ; close_in errchan ; snd ( waitpid [ ] pid ) file_descr...
let open_connection sockaddr = let sock = socket ~ cloexec : true ( domain_of_sockaddr sockaddr ) SOCK_STREAM 0 in try connect sock sockaddr ; ( in_channel_of_descr sock , out_channel_of_descr sock ) with exn -> close sock ; raise exn
let shutdown_connection inchan = shutdown ( descr_of_in_channel inchan ) SHUTDOWN_SEND
let establish_server _server_fun _sockaddr = invalid_arg " Unix . establish_server not implemented "
type terminal_io = { mutable c_ignbrk : bool ; mutable c_brkint : bool ; mutable c_ignpar : bool ; mutable c_parmrk : bool ; mutable c_inpck : bool ; mutable c_istrip : bool ; mutable c_inlcr : bool ; mutable c_igncr : bool ; mutable c_icrnl : bool ; mutable c_ixon : bool ; mutable c_ix...
type setattr_when = TCSANOW | TCSADRAIN | TCSAFLUSH
let tcgetattr _fd = invalid_arg " Unix . tcgetattr not implemented "
let tcsetattr _fd _wh = invalid_arg " Unix . tcsetattr not implemented "
let tcsendbreak _fd _n = invalid_arg " Unix . tcsendbreak not implemented "
let tcdrain _fd = invalid_arg " Unix . tcdrain not implemented "
type flush_queue = TCIFLUSH | TCOFLUSH | TCIOFLUSH
let tcflush _fd _q = invalid_arg " Unix . tcflush not implemented "
type flow_action = TCOOFF | TCOON | TCIOFF | TCION
let tcflow _fd _fl = invalid_arg " Unix . tcflow not implemented "
let setsid ( ) = invalid_arg " Unix . setsid not implemented "
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " UnmonitorInstances...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UnmonitorInstancesResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UnmonitorInstancesResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well ...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | N...
let debug = ref false
module Unpack_one = struct type ( ' a , ' state ) unpack_result = [ ` Ok of ' a * int | ` Not_enough_data of ' state * int | ` Invalid_data of Error . t ] type ( ' a , ' state ) unpack = state : ' state -> buf : Bigstring . t -> pos : int -> len : int -> ( ' a ...
type ( ' a , ' state ) alive = { mutable state : ' state ; mutable state_is_initial : bool ; initial_state : ' state ; unpack : ( ( ' a , ' state ) Unpack_one . unpack [ @ sexp . opaque ] ) ; mutable buf : Bigstring . t ; mutable pos : int ; mutable len : int...
type ' a alive_or_dead = | Alive : ( ' a , _ ) alive -> ' a alive_or_dead | Dead of Error . t
type ' a t = { mutable alive_or_dead : ' a alive_or_dead }
let invariant _ t = try match t . alive_or_dead with | Dead _ -> ( ) | Alive alive -> assert ( alive . pos >= 0 ) ; assert ( alive . len >= 0 ) ; if alive . len = 0 then assert ( alive . pos = 0 ) ; if alive . state_is_initial then assert ( phys_equal alive . state a...
let create ( Unpack_one . T { initial_state ; unpack } ) = { alive_or_dead = Alive { state = initial_state ; state_is_initial = true ; initial_state ; unpack ; buf = Bigstring . create 1 ; pos = 0 ; len = 0 } ; } ; ;
let create_bin_prot bin_prot_reader = create ( Unpack_one . create_bin_prot bin_prot_reader ) ; ;
let is_empty t = match t . alive_or_dead with | Dead error -> Error error | Alive alive -> Ok ( alive . state_is_initial && alive . len = 0 ) ; ;
let is_available t len = let input_start = t . pos + t . len in let available = Bigstring . length t . buf - input_start in available >= len ; ;
let ensure_available t len = if not ( is_available t len ) then begin let new_buf = Bigstring . create ( max ( t . len + len ) ( 2 * Bigstring . length t . buf ) ) in Bigstring . blito ~ src : t . buf ~ src_pos : t . pos ~ src_len : t . len ~ dst : new_buf ( ) ; t . ...
let feed_gen buf_length ( blit_buf_to_bigstring : ( _ , _ ) Blit . blito ) ? pos ? len t buf = if ! debug then invariant ignore t ; match t . alive_or_dead with | Dead e -> Error e | Alive t -> let ( src_pos , src_len ) = Ordered_collection_common . get_pos_len_exn ( ) ? pos ? ...
let feed ? pos ? len t buf = feed_gen Bigstring . length Bigstring . blito ? pos ? len t buf ; ;
let feed_string ? pos ? len t buf = feed_gen String . length Bigstring . From_string . blito ? pos ? len t buf ; ;
let feed_bytes ? pos ? len t buf = feed_gen Bytes . length Bigstring . From_bytes . blito ? pos ? len t buf ; ;
let error t e = t . alive_or_dead <- Dead e ; Error e ; ;
let consume alive ~ num_bytes = alive . pos <- alive . pos + num_bytes ; alive . len <- alive . len - num_bytes ; ; ;
let rec unpack_iter_loop t alive ~ f = if alive . len = 0 then begin alive . pos <- 0 ; Ok ( ) ; end else begin match alive . unpack ~ buf : alive . buf ~ pos : alive . pos ~ len : alive . len ~ state : alive . state with | exception exn -> error t ( Error . create " unpack e...
let unpack_iter t ~ f = if ! debug then invariant ignore t ; match t . alive_or_dead with | Dead e -> Error e | Alive alive -> unpack_iter_loop t alive ~ f ; ;
let unpack_into t q = unpack_iter t ~ f ( : Queue . enqueue q )
let input_closed_error = Error . of_string " input closed "
let input_closed_in_the_middle_of_data_error = Error . of_string " input closed in the middle of data " ; ;
let unpack_error error = Error . create " unpack error " error [ % sexp_of : Error . t ]
module Unpack_iter_result = struct type ' a t = | Input_closed | Input_closed_in_the_middle_of_data of ' a Unpack_buffer . t | Unpack_error of Error . t [ @@ deriving sexp_of ] let to_error : _ t -> Error . t = function | Input_closed -> input_closed_error | Input_closed_in_the_middle_of_data...
module Unpack_result = struct type ' a t = | Input_closed | Input_closed_in_the_middle_of_data of ' a Unpack_buffer . t | Output_closed | Unpack_error of Error . t [ @@ deriving sexp_of ] let to_error : _ t -> Error . t = function | Input_closed -> input_closed_error | Input_closed_in_the_mi...
module Unpack_from = struct type t = | Pipe of string Pipe . Reader . t | Reader of Reader . t end
module Unpack_to = struct type ' a t = | Iter of ( ' a -> unit ) | Pipe of ' a Pipe . Writer . t [ @@ deriving sexp_of ] end
let unpack_all ( ~ from : Unpack_from . t ) ( ~ to_ : _ Unpack_to . t ) ~ using : unpack_buffer = let unpack_all_available = match to_ with | Iter f -> fun ( ) -> ( match Unpack_buffer . unpack_iter unpack_buffer ~ f with | Ok ( ) -> return ` Continue | Error error -> return (...
let unpack_into_pipe ~ from ~ using = let output_reader , output_writer = Pipe . create ( ) in let result = unpack_all ~ from ~ to_ ( : Pipe output_writer ) ~ using >>| fun result -> Pipe . close output_writer ; result in output_reader , result ; ;
let unpack_iter ~ from ~ using ~ f = unpack_all ~ from ~ to_ ( : Iter f ) ~ using >>| function | Input_closed -> Unpack_iter_result . Input_closed | Input_closed_in_the_middle_of_data x -> Input_closed_in_the_middle_of_data x | Unpack_error x -> Unpack_error x | Output_closed as t -> failwiths ~...
let sexps = let a x = Sexp . Atom x in let l x = Sexp . List x in [ a " " ; a " hello " ; l [ ] ; l [ a " " ] ; l [ a " " ; a " hello " ] ] ; ;
let test ( ) = Unix . pipe ( Info . of_string " unpack_sequence_test " ) >>= fun ( ` Reader reader_fd , ` Writer writer_fd ) -> let string_writer = Writer . create writer_fd in let sexp_reader , unpack_result = Unpack_sequence . unpack_into_pipe ~ from ( : Reader ( Reader . ...
let tests = [ " Unpack_Sequence_test " , test ]
let display ( ) = glClear [ GL_COLOR_BUFFER_BIT ] ; glFlush ( ) ; ; ;
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluPerspective 45 . 0 ( float w . / float h ) 1 . 0 100 . 0 ; glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; ; ;
let mouse ~ button ~ state ~ x ~ y = match button with | GLUT_LEFT_BUTTON -> if state = GLUT_DOWN then begin let viewport = glGetInteger4 Get . GL_VIEWPORT in let a , b , c , d = viewport in let viewport = [ | a ; b ; c ; d ] | in let mvmatrix = glGetMatrix Get . GL_MODELVIEW_MATRIX in...
let keyboard ~ key ~ x ~ y = match key with | ' \ 027 ' -> exit ( 0 ) ; | _ -> ( ) ; ;
let ( ) = let _ = glutInit Sys . argv in glutInitDisplayMode [ GLUT_SINGLE ; GLUT_RGB ] ; glutInitWindowSize 500 500 ; glutInitWindowPosition 100 100 ; let _ = glutCreateWindow Sys . argv . ( 0 ) in glutDisplayFunc ~ display ; glutReshapeFunc ~ reshape ; glutKeyboardFunc ~ key...
module M : sig type t = private [ ` Bar of ' a | ` Foo ] as ' a val bar : t type t = [ ` Bar of ' a | ` Foo ] as ' a let bar = ` Bar ` Foo end ; ; [ %% expect { |
module M : sig type t = private [ ` Bar of ' a | ` Foo ] as ' a val bar : t end } ] |
let y = match ( M . bar :> [ ` Bar of ' a | ` Foo ] as ' a ) with | ` Bar x -> x | ` Foo -> assert false ; ; [ %% expect { | } ] |
let y = match ( M . bar :> [ ` Bar of M . t | ` Foo ] ) with | ` Bar x -> x | ` Foo -> assert false ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type M . t = [ ` Bar of M . t | ` Foo ] is not a subtype of M . t } ] |
module F ( X : sig end ) : sig type s = private [ ` Bar of ' a | ` Foo ] as ' a val from : M . t -> s val to_ : s -> M . t type s = M . t let from x = x let to_ x = x end ; ; [ %% expect { |
module F : functor ( X : sig end ) -> sig type s = private [ ` Bar of ' a | ` Foo ] as ' a val from : M . t -> s val to_ : s -> M . t end } ] |
module N = F ( struct end ) ; ; [ %% expect { |
module N : sig type s = private [ ` Bar of ' a | ` Foo ] as ' a val from : M . t -> s val to_ : s -> M . t end } ] |
let y = match ( N . from M . bar :> [ ` Bar of N . s | ` Foo ] ) with | ` Bar x -> N . to_ x | ` Foo -> assert false ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type N . s = [ ` Bar of N . s | ` Foo ] is not a subtype of N . s } ] |
let rec exp { e_desc = desc } = match desc with | Eapp ( _ , e , e_list ) -> ( not ( Ztypes . is_combinatorial ( List . length e_list ) e . e_typ ) ) || ( exp e ) || ( List . exists exp e_list ) | Erecord_access ( e , _ ) | Etypeconstraint ( e , _ ) -> exp...
let rec equation { eq_desc = desc } = match desc with | EQeq ( _ , e ) | EQinit ( _ , e ) | EQder ( _ , e , None , [ ] ) | EQpluseq ( _ , e ) -> exp e | EQmatch ( _ , e , m_h_list ) -> exp e || List . exists | EQreset ( eq_list , e ) -> exp e || List...
let ( ) = init ( )
module type Basics = sig type t val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val rem : t -> t -> t val max_int : t val logand : t -> t -> t val logor : t -> t -> t val logxor : t -> t -> t val shift_left : t -> int -> t val shift_right : t -> int...
module type Extras = sig type t val zero : t val one : t val lognot : t -> t val succ : t -> t val pred : t -> t val compare : t -> t -> int val equal : t -> t -> bool val max : t -> t -> t val min : t -> t -> t val of_string_opt : string -> t option val pp : Format . formatter -> t -> unit ...
module type Infix = sig type t val ( ) + : t -> t -> t val ( ) - : t -> t -> t val ( * ) : t -> t -> t val ( ) / : t -> t -> t val ( mod ) : t -> t -> t val ( land ) : t -> t -> t val ( lor ) : t -> t -> t val ( lxor ) : t -> t -> t val ( lsl ) : t -> i...
module type S = sig include Basics include Extras with type t := t module Infix : Infix with type t := t end
module MakeInfix ( B : Basics ) = struct open B let ( ) + = add let ( ) - = sub let ( * ) = mul let ( ) / = div let ( mod ) = rem let ( land ) = logand let ( lor ) = logor let ( lxor ) = logxor let ( lsl ) = shift_left let ( lsr ) = shift_right end
module Extras ( Basics : Basics ) : Extras with type t := Basics . t = struct open Basics let zero = of_int 0 let one = of_int 1 let succ n = add n one let pred n = sub n one let lognot n = logxor n max_int let compare ( x : t ) ( y : t ) = Stdlib . compare x y let equal ( x : t ) ( ...
module UInt8 : S with type t = private int = struct module B = struct type t = int let max_int = 255 let add : t -> t -> t = fun x y -> ( x + y ) land max_int let sub : t -> t -> t = fun x y -> ( x - y ) land max_int let mul : t -> t -> t = fun x y -> ( x * y ) land max_int let div ...