text
stringlengths
0
601k
let r_utf_8 s j l = let uchar c = ` Uchar ( Uchar . unsafe_of_int c ) in match l with | 1 -> uchar ( unsafe_byte s j ) | 2 -> let b0 = unsafe_byte s j in let b1 = unsafe_byte s ( j + 1 ) in if b1 lsr 6 != 0b10 then malformed s j l else uchar ( ( ( b0 land 0x1F ) lsl 6 ) lor ( b1 land 0x3F ) ) | 3 -> let b0 = unsafe_byt...
let r_utf_16 s j0 j1 = let b0 = unsafe_byte s j0 in let b1 = unsafe_byte s j1 in let u = ( b0 lsl 8 ) lor b1 in if u < 0xD800 || u > 0xDFFF then ` Uchar ( Uchar . unsafe_of_int u ) else if u > 0xDBFF then malformed s ( min j0 j1 ) 2 else ` Hi u
let r_utf_16_lo hi s j0 j1 = let b0 = unsafe_byte s j0 in let b1 = unsafe_byte s j1 in let lo = ( b0 lsl 8 ) lor b1 in if lo < 0xDC00 || lo > 0xDFFF then malformed_pair ( j0 < j1 ) hi s ( min j0 j1 ) 2 else ` Uchar ( Uchar . unsafe_of_int ( ( ( ( hi land 0x3FF ) lsl 10 ) lor ( lo land 0x3FF ) ) + 0x10000 ) )
let r_encoding s j l = let some i = if i < l then Some ( unsafe_byte s ( j + i ) ) else None in match ( some 0 ) , ( some 1 ) , ( some 2 ) with | Some 0xEF , Some 0xBB , Some 0xBF -> ` UTF_8 ` BOM | Some 0xFE , Some 0xFF , _ -> ` UTF_16BE ` BOM | Some 0xFF , Some 0xFE , _ -> ` UTF_16LE ` BOM | Some 0x00 , Some p , _ wh...
type src = [ ` Channel of in_channel | ` String of string | ` Manual ]
type nln = [ ` ASCII of Uchar . t | ` NLF of Uchar . t | ` Readline of Uchar . t ]
type decode = [ ` Await | ` End | ` Malformed of string | ` Uchar of Uchar . t ]
let pp_decode ppf = function let l = String . length bs in pp ppf " [ ` @ Malformed ( " ; if l > 0 then pp ppf " % 02X " ( Char . code ( bs . [ 0 ] ) ) ; for i = 1 to l - 1 do pp ppf " % 02X " ( Char . code ( bs . [ i ] ) ) done ; pp ppf " ) ] " @
type decoder = { src : src ; mutable encoding : decoder_encoding ; nln : nln option ; nl : Uchar . t ; mutable i : Bytes . t ; mutable i_pos : int ; mutable i_max : int ; t : Bytes . t ; mutable t_len : int ; mutable t_need : int ; mutable removed_bom : bool ; mutable last_cr : bool ; mutable line : int ; mutable col :...
let i_rem d = d . i_max - d . i_pos + 1
let eoi d = d . i <- Bytes . empty ; d . i_pos <- 0 ; d . i_max <- min_int
let src d s j l = if ( j < 0 || l < 0 || j + l > Bytes . length s ) then invalid_bounds j l else if ( l = 0 ) then eoi d else ( d . i <- s ; d . i_pos <- j ; d . i_max <- j + l - 1 )
let refill k d = match d . src with let rc = input ic d . i 0 ( Bytes . length d . i ) in ( src d d . i 0 rc ; k d )
let t_need d need = d . t_len <- 0 ; d . t_need <- need
let rec t_fill k d = let blit d l = unsafe_blit d . i d . i_pos d . t d . t_len l ; d . i_pos <- d . i_pos + l ; d . t_len <- d . t_len + l ; in let rem = i_rem d in if rem < 0 then k d else let need = d . t_need - d . t_len in if rem < need then ( blit d rem ; refill ( t_fill k ) d ) else ( blit d need ; k d )
let ret k v byte_count d = d . k <- k ; d . byte_count <- d . byte_count + byte_count ; d . pp d v
let rec decode_us_ascii d = let rem = i_rem d in if rem <= 0 then ( if rem < 0 then ` End else refill decode_us_ascii d ) else let j = d . i_pos in d . i_pos <- d . i_pos + 1 ; ret decode_us_ascii ( r_us_ascii d . i j ) 1 d
let rec decode_iso_8859_1 d = let rem = i_rem d in if rem <= 0 then ( if rem < 0 then ` End else refill decode_iso_8859_1 d ) else let j = d . i_pos in d . i_pos <- d . i_pos + 1 ; ret decode_iso_8859_1 ( r_iso_8859_1 d . i j ) 1 d
let rec t_decode_utf_8 d = if d . t_len < d . t_need then ret decode_utf_8 ( malformed d . t 0 d . t_len ) d . t_len d else ret decode_utf_8 ( r_utf_8 d . t 0 d . t_len ) d . t_len d let rem = i_rem d in if rem <= 0 then ( if rem < 0 then ` End else refill decode_utf_8 d ) else let need = unsafe_array_get utf_8_len ( u...
let rec t_decode_utf_16be_lo hi d = let bcount = d . t_len + 2 in if d . t_len < d . t_need then ret decode_utf_16be ( malformed_pair true hi d . t 0 d . t_len ) bcount d else ret decode_utf_16be ( r_utf_16_lo hi d . t 0 1 ) bcount d if d . t_len < d . t_need then ret decode_utf_16be ( malformed d . t 0 d . t_len ) d ....
let rec t_decode_utf_16le_lo hi d = let bcount = d . t_len + 2 in if d . t_len < d . t_need then ret decode_utf_16le ( malformed_pair false hi d . t 0 d . t_len ) bcount d else ret decode_utf_16le ( r_utf_16_lo hi d . t 1 0 ) bcount d if d . t_len < d . t_need then ret decode_utf_16le ( malformed d . t 0 d . t_len ) d ...
let guessed_utf_8 d = let b3 d = let b3 = unsafe_byte d . t 2 in match utf_8_len . ( b3 ) with | 0 -> ret decode_utf_8 ( malformed d . t 2 1 ) 1 d | n -> d . t_need <- n ; d . t_len <- 1 ; unsafe_set_byte d . t 0 b3 ; t_fill t_decode_utf_8 d in let b2 d = let b2 = unsafe_byte d . t 1 in let b3 = if d . t_len > 2 then b...
let guessed_utf_16 d be v = let decode_utf_16 , t_decode_utf_16 , t_decode_utf_16_lo , j0 , j1 = if be then decode_utf_16be , t_decode_utf_16be , t_decode_utf_16be_lo , 0 , 1 else decode_utf_16le , t_decode_utf_16le , t_decode_utf_16le_lo , 1 , 0 in let b3 k d = if d . t_len < 3 then decode_utf_16 d else begin d . t_ne...
let guess_encoding d = let setup d = match r_encoding d . t 0 d . t_len with | ` UTF_8 r -> d . encoding <- ` UTF_8 ; d . k <- decode_utf_8 ; begin match r with | ` BOM -> ret decode_utf_8 ( ` Uchar u_bom ) 3 d | ` Decode -> guessed_utf_8 d | ` End -> ` End end | ` UTF_16BE r -> d . encoding <- ` UTF_16BE ; d . k <- de...
let nline d = d . col <- 0 ; d . line <- d . line + 1
let ncol d = d . col <- d . col + 1
let ncount d = d . count <- d . count + 1
let cr d b = d . last_cr <- b
let pp_remove_bom utf16 pp d = function match Uchar . to_int u with | 0xFEFF -> if utf16 then ( d . encoding <- ` UTF_16BE ; d . k <- decode_utf_16be ) ; d . removed_bom <- true ; d . pp <- pp ; d . k d | 0xFFFE when utf16 -> d . encoding <- ` UTF_16LE ; d . k <- decode_utf_16le ; d . removed_bom <- true ; d . pp <- pp...
let pp_nln_none d = function match Uchar . to_int u with | 0x000A -> let last_cr = d . last_cr in cr d false ; ncount d ; if last_cr then v else ( nline d ; v ) | 0x000D -> cr d true ; ncount d ; nline d ; v | ( 0x0085 | 0x000C | 0x2028 | 0x2029 ) -> cr d false ; ncount d ; nline d ; v | _ -> cr d false ; ncount d ; nc...
let pp_nln_readline d = function match Uchar . to_int u with | 0x000A -> let last_cr = d . last_cr in cr d false ; if last_cr then d . k d else ( ncount d ; nline d ; ` Uchar d . nl ) | 0x000D -> cr d true ; ncount d ; nline d ; ` Uchar d . nl | ( 0x0085 | 0x000C | 0x2028 | 0x2029 ) -> cr d false ; ncount d ; nline d ;...
let pp_nln_nlf d = function match Uchar . to_int u with | 0x000A -> let last_cr = d . last_cr in cr d false ; if last_cr then d . k d else ( ncount d ; nline d ; ` Uchar d . nl ) | 0x000D -> cr d true ; ncount d ; nline d ; ` Uchar d . nl | 0x0085 -> cr d false ; ncount d ; nline d ; ` Uchar d . nl | ( 0x000C | 0x2028 ...
let pp_nln_ascii d = function match Uchar . to_int u with | 0x000A -> let last_cr = d . last_cr in cr d false ; if last_cr then d . k d else ( ncount d ; nline d ; ` Uchar d . nl ) | 0x000D -> cr d true ; ncount d ; nline d ; ` Uchar d . nl | ( 0x0085 | 0x000C | 0x2028 | 0x2029 ) -> cr d false ; ncount d ; nline d ; v ...
let decoder ? nln ? encoding src = let pp , nl = match nln with | None -> pp_nln_none , Uchar . unsafe_of_int 0x000A | Some ( ` ASCII nl ) -> pp_nln_ascii , nl | Some ( ` NLF nl ) -> pp_nln_nlf , nl | Some ( ` Readline nl ) -> pp_nln_readline , nl in let encoding , k = match encoding with | None -> ` UTF_8 , guess_enco...
let decode d = d . k d
let decoder_line d = d . line
let decoder_col d = d . col
let decoder_byte_count d = d . byte_count
let decoder_count d = d . count
let decoder_removed_bom d = d . removed_bom
let decoder_src d = d . src
let decoder_nln d = d . nln
let decoder_encoding d = d . encoding
let set_decoder_encoding d e = d . encoding <- ( e :> decoder_encoding ) ; d . k <- decode_fun e
type dst = [ ` Channel of out_channel | ` Buffer of Buffer . t | ` Manual ]
type encode = [ ` Await | ` End | ` Uchar of Uchar . t ]
type encoder = { dst : dst ; encoding : encoding ; mutable o : Bytes . t ; mutable o_pos : int ; mutable o_max : int ; t : Bytes . t ; mutable t_pos : int ; mutable t_max : int ; mutable k : encoder -> encode -> [ ` Ok | ` Partial ] }
let o_rem e = e . o_max - e . o_pos + 1
let dst e s j l = if ( j < 0 || l < 0 || j + l > Bytes . length s ) then invalid_bounds j l ; e . o <- s ; e . o_pos <- j ; e . o_max <- j + l - 1
let partial k e = function ` Await -> k e | ` Uchar _ | ` End -> invalid_encode ( )
let flush k e = match e . dst with let o = Bytes . unsafe_to_string e . o in Buffer . add_substring b o 0 e . o_pos ; e . o_pos <- 0 ; k e
let t_range e max = e . t_pos <- 0 ; e . t_max <- max
let rec t_flush k e = let blit e l = unsafe_blit e . t e . t_pos e . o e . o_pos l ; e . o_pos <- e . o_pos + l ; e . t_pos <- e . t_pos + l in let rem = o_rem e in let len = e . t_max - e . t_pos + 1 in if rem < len then ( blit e rem ; flush ( t_flush k ) e ) else ( blit e len ; k e )
let rec encode_utf_8 e v = let k e = e . k <- encode_utf_8 ; ` Ok in match v with | ` Await -> k e | ` End -> flush k e | ` Uchar u as v -> let u = Uchar . to_int u in let rem = o_rem e in if u <= 0x007F then if rem < 1 then flush ( fun e -> encode_utf_8 e v ) e else ( unsafe_set_byte e . o e . o_pos u ; e . o_pos <- e...
let rec encode_utf_16be e v = let k e = e . k <- encode_utf_16be ; ` Ok in match v with | ` Await -> k e | ` End -> flush k e | ` Uchar u -> let u = Uchar . to_int u in let rem = o_rem e in if u < 0x10000 then begin let s , j , k = if rem < 2 then ( t_range e 1 ; e . t , 0 , t_flush k ) else let j = e . o_pos in ( e . ...
let rec encode_utf_16le e v = let k e = e . k <- encode_utf_16le ; ` Ok in match v with | ` Await -> k e | ` End -> flush k e | ` Uchar u -> let u = Uchar . to_int u in let rem = o_rem e in if u < 0x10000 then begin let s , j , k = if rem < 2 then ( t_range e 1 ; e . t , 0 , t_flush k ) else let j = e . o_pos in ( e . ...
let encoder encoding dst = let o , o_pos , o_max = match dst with | ` Manual -> Bytes . empty , 1 , 0 | ` Buffer _ | ` Channel _ -> Bytes . create io_buffer_size , 0 , io_buffer_size - 1 in { dst = ( dst :> dst ) ; encoding = ( encoding :> encoding ) ; o ; o_pos ; o_max ; t = Bytes . create 4 ; t_pos = 1 ; t_max = 0 ; ...
let encode e v = e . k e ( v :> encode )
let encoder_encoding e = e . encoding
let encoder_dst e = e . dst
module Manual = struct let src = src let dst = dst let dst_rem = o_rem end
module String = struct let encoding_guess s = let s = Bytes . unsafe_of_string s in match r_encoding s 0 ( max ( Bytes . length s ) 3 ) with | ` UTF_8 d -> ` UTF_8 , ( d = ` BOM ) | ` UTF_16BE d -> ` UTF_16BE , ( d = ` BOM ) | ` UTF_16LE d -> ` UTF_16LE , ( d = ` BOM ) type ' a folder = ' a -> int -> [ ` Uchar of Uchar...
module Buffer = struct let add_utf_8 b u = let u = Uchar . to_int u in let w byte = Buffer . add_char b ( unsafe_chr byte ) in if u <= 0x007F then ( w u ) else if u <= 0x07FF then ( w ( 0xC0 lor ( u lsr 6 ) ) ; w ( 0x80 lor ( u land 0x3F ) ) ) else if u <= 0xFFFF then ( w ( 0xE0 lor ( u lsr 12 ) ) ; w ( 0x80 lor ( ( u ...
type ' a result = Ok of ' a | Error of error
type status = unit result
let ok : status = Ok ( )
let ok_exn = function Ok a -> a | Error e -> failwith ( error_to_string e )
let int_to_status = function i when i = 0 -> ok | i when i < 0 -> Error ( Uv_consts . int_to_error i ) | _ -> failwith " This should never happen . Status code returned > 0 . "
type iobuf = ( char , Bigarray . int8_unsigned_elt , Bigarray . c_layout ) Bigarray . Array1 . t
let make_buft buf = let buf_data = make C . uv_buf in let buf_ptr = bigarray_start array1 buf in let buf_len = Bigarray . Array1 . dim buf in let ( ) = setf buf_data C . _uv_buf_base buf_ptr in let ( ) = setf buf_data C . _uv_buf_len ( Unsigned . Size_t . of_int buf_len ) in buf_data
type timespec = { tv_sec : int64 ; tv_nsec : int64 }
let from_uv_timespec uv_t = let tv_sec = Signed . Long . to_int64 ( getf uv_t C . _tv_sec ) in let tv_nsec = Signed . Long . to_int64 ( getf uv_t C . _tv_nsec ) in { tv_sec ; tv_nsec }
module Loop = struct type t = C . uv_loop type run_mode = RunDefault | RunOnce | RunNoWait let run_mode_to_int = function RunDefault -> 0 | RunOnce -> 1 | RunNoWait -> 2 let default_loop = C . uv_default_loop let run ( ? loop = default_loop ( ) ) run_mode = let ret = C . uv_run loop ( run_mode_to_int run_mode ) in int_...
let default_loop = Loop . default_loop ( )
type stat = { st_dev : int64 ; st_mode : int64 ; st_nlink : int64 ; st_uid : int64 ; st_gid : int64 ; st_rdev : int64 ; st_ino : int64 ; st_size : int64 ; st_blksize : int64 ; st_blocks : int64 ; st_flags : int64 ; st_gen : int64 ; st_atim : timespec ; st_mtim : timespec ; st_ctim : timespec ; st_birthtim : timespec }
module Request = struct type ' a t = unit ptr type write_req type write = write_req t let cancel req = failwith " Not Implemented " end
module Handle = struct type ' a t = unit ptr let loop handle = let ptr = from_voidp C . uv_handle handle in C . get_uv_handle_t_loop ptr let close ? cb handle = let cb ' = match cb with None -> None | Some f -> Some ( fun x -> f ( to_voidp x ) ) in let handle_ptr = from_voidp C . uv_handle handle in let _ = C . uv_clos...
module Stream = struct type ' a stream type ' a t = ' a stream Handle . t let refs = Refcount . create ( ) let ref_incr = Refcount . incr refs let ref_decr = Refcount . decr refs let read_cb_refs = Refcount . create ( ) let read_cb_ref_incr = Refcount . incr read_cb_refs let read_cb_ref_decr = Refcount . decr read_cb_r...
module Shutdown = struct type shutdown type t = shutdown Request . t end
module FS = struct type fs type t = fs Request . t type iobuf = ( char , Bigarray . int8_unsigned_elt , Bigarray . c_layout ) Bigarray . Array1 . t let c_to_ocaml data = to_voidp data let ocaml_to_c data = from_voidp C . uv_fs data let coatCheck = Coat_check . create ( ) let alloc_uv_fs ( ) = let memory = allocate_n ch...
type mysock = C . uv_sockaddr structure ptr
let ip4_addr str_addr port = let data = addr ( make C . uv_sockaddr_in ) in let _ = C . uv_ip4_addr str_addr port data in coerce ( ptr C . uv_sockaddr_in ) ( ptr C . uv_sockaddr ) data
module TCP = struct type tcp type t = tcp Stream . t type connect type c = connect Request . t let alloc_uv_tcp ( ) = let memory = allocate_n char ~ count ( : sizeof C . uv_tcp ) in coerce ( ptr char ) ( ptr C . uv_tcp ) memory let alloc_uv_connect ( ) = let memory = allocate_n char ~ count ( : sizeof C . uv_connect ) ...
let ( ) = Random . self_init ( )
let src = Logs . Src . create " guit - v " ~ doc " : logs binary event "
module Log = ( val Logs . src_log src : Logs . LOG )
let pad n x = if String . length x > n then x else x ^ String . make ( n - String . length x ) ' '
let pp_header ppf ( level , header ) = let level_style = match level with | Logs . App -> Logs_fmt . app_style | Logs . Debug -> Logs_fmt . debug_style | Logs . Warning -> Logs_fmt . warn_style | Logs . Error -> Logs_fmt . err_style | Logs . Info -> Logs_fmt . info_style in let level = Logs . level_to_string ( Some lev...
let reporter ppf = let report src level ~ over k msgf = let k _ = over ( ) ; k ( ) in let with_src_and_stamp h _ k fmt = let dt = Mtime . Span . to_us ( Mtime_clock . elapsed ( ) ) in Fmt . kpf k ppf ( " % s % a % a : [ " @ ^^ fmt ^^ " ] . " ) @@ ( pad 10 ( Fmt . str " %+ 04 . 0fus " dt ) ) pp_header ( level , h ) Fmt ...
let setup_logs style_renderer level = let quiet = Option . is_none level in Fmt_tty . setup_std_outputs ? style_renderer ( ) ; Logs . set_level level ; Logs . set_reporter ( reporter Fmt . stderr ) ; quiet
let main quiet path = let root = match path with Some path -> path | None -> Fpath . v ( Sys . getcwd ( ) ) in let open Lwt . Infix in Store . v root >>= function | Ok _t when not quiet -> Fmt . pr " % a ready to be used as a Git store . \ n " %! Fpath . pp root ; Lwt . return_ok ( ) | Ok _ -> Lwt . return_ok ( ) | Err...
let main logs path = match Lwt_main . run ( main logs path ) with | Ok ( ) -> Ok ( ) | Error ( ` Msg err ) -> Error ( Fmt . str " % s . " err )
let fpath = Arg . conv ( Fpath . of_string , Fpath . pp )
let directory = let doc = " Indicate path to repository root containing ' . git ' folder " in Arg . ( value & opt ( some fpath ) None & info [ " r " ; " root " ] ~ doc ~ docv " :< directory " ) >
let setup_logs = let docs = Manpage . s_common_options in Term . ( const setup_logs $ Fmt_cli . style_renderer ~ docs ( ) $ Logs_cli . level ~ docs ( ) )
let command = let doc = " Make a Git repository . " in let info = Cmd . info " v " ~ doc in Cmd . v info Term . ( const main $ setup_logs $ directory )
let ( ) = exit @@ Cmd . eval_result command
type t = { name : string ; dest_dir : string ; ocamlc : string ; log : string -> unit ; mutable counter : int ; ext_obj : string ; c_compiler : string ; stdlib_dir : string ; ccomp_type : string ; c_libraries : string list ; ocamlc_config : Ocaml_config . Vars . t ; ocamlc_config_cmd : string }
let rec rm_rf dir = Array . iter ( Sys . readdir dir ) ~ f ( : fun fn -> let fn = dir ^/ fn in if Sys . is_directory fn then rm_rf fn else Unix . unlink fn ) ; Unix . rmdir dir
module Temp = struct let prng = lazy ( Random . State . make_self_init ( ) ) let gen_name ~ temp_dir ~ prefix ~ suffix = let rnd = Random . State . bits ( Lazy . force prng ) land 0xFFFFFF in temp_dir ^/ Printf . sprintf " % s % 06x % s " prefix rnd suffix let create ~ prefix ~ suffix ~ mk = let temp_dir = Filename . g...