text
stringlengths
12
786k
let to_hex d = if String . length d <> 16 then invalid_arg " Digest . to_hex " ; let result = Bytes . create 32 in for i = 0 to 15 do let x = Char . code d . [ i ] in Bytes . unsafe_set result ( i * 2 ) ( char_hex ( x lsr 4 ) ) ; Bytes . unsafe_set result ( i * 2 +...
let from_hex s = if String . length s <> 32 then invalid_arg " Digest . from_hex " ; let digit c = match c with | ' 0 ' . . ' 9 ' -> Char . code c - Char . code ' 0 ' | ' A ' . . ' F ' -> Char . code c - Char . code ' A ' + 10 | ' a ' . . ' f '...
let update_predecessor ' s_terminators ( cfg : C . t ) ~ pred_block ~ being_disconnected ~ target_label = let replace_label l = if Label . equal l being_disconnected then target_label else l in C . replace_successor_labels cfg ~ normal : true ~ exn : false pred_block ~ f : replace_label
let disconnect cfg_with_layout label = let cfg = CL . cfg cfg_with_layout in let block = C . get_block_exn cfg label in if block . is_trap_handler then Misc . fatal_error " Removing trap handler blocks is not supported " ; let successors = C . successor_labels ~ normal : true ~ exn : false block...
module Int64Map = Map . Make ( struct type t = int64 let compare = Int64 . compare end )
type t = Cstruct . t Int64Map . t
let empty_sector = Bytes . make sector_size ' \ 000 '
let write t ofs cstr = Int64Map . add ofs cstr t
let write_string t ofs s = let cstr = Cstruct . create ( String . length s ) in Cstruct . blit_from_string s 0 cstr 0 ( String . length s ) ; write t ofs cstr
let of_file filename = Lwt_unix . openfile filename [ Unix . O_RDONLY ] 0o0 >>= fun fd -> let buf = Bytes . make sector_size ' \ 000 ' in let rec loop i result = Lwt_unix . read fd buf 0 sector_size >>= fun n -> let finished = n <> sector_size in let result = if buf <> empty_sector then b...
let print_ocaml out t = Printf . fprintf out " let disk =\ n " ; Printf . fprintf out " let t = ref Disk . empty in \ n " ; Int64Map . iter ( fun ofs cstr -> let buf = Bytes . make ( Cstruct . len cstr ) ' \ 000 ' in Cstruct . blit_to_bytes cstr 0 buf 0 ( Cstruct . len ...
module type HTTP = Cohttp_mirage . Server . S
let https_src = Logs . Src . create " https " ~ doc " : HTTPS server "
module Https_log = ( val Logs . src_log https_src : Logs . LOG )
let http_src = Logs . Src . create " http " ~ doc " : HTTP server "
module Http_log = ( val Logs . src_log http_src : Logs . LOG )
module Dispatch ( FS : Mirage_kv . RO ) ( S : HTTP ) = struct let failf fmt = Fmt . kstr Lwt . fail_with fmt let rec dispatcher fs uri = match Uri . path uri with | " " | " " / -> dispatcher fs ( Uri . with_path uri " index . html " ) | path -> let header = Cohttp . Hea...
module HTTPS ( Pclock : Mirage_clock . PCLOCK ) ( DATA : Mirage_kv . RO ) ( KEYS : Mirage_kv . RO ) ( Http : HTTP ) = struct module X509 = Tls_mirage . X509 ( KEYS ) ( Pclock ) module D = Dispatch ( DATA ) ( Http ) let tls_init kv = X509 . certificate kv ` Default >>...
module ANSI = struct let up oc n = fp oc " \ 027 [ % dA " n ; ; let clear_to_eol oc ( ) = fp oc " \ 027 [ K " ; ; let bol oc ( ) = fp oc " \ r " ; ; let get_columns ( ) = if Sys . os_type = " Unix " then try int_of_string ( String . chomp ( My_unix . run...
type tagline_description = ( string * char ) list ; ;
type sophisticated_display = { ds_channel : out_channel ; ds_start_time : float ; mutable ds_last_update : float ; mutable ds_last_target : string ; mutable ds_last_cached : bool ; mutable ds_last_tags : Tags . t ; mutable ds_changed : bool ; ds_update_interval : float ; ds_columns : int ;...
type display = { di_log_level : int ; mutable di_log_channel : ( Format . formatter * out_channel ) option ; di_channel : out_channel ; di_formatter : Format . formatter ; di_display_line : display_line ; mutable di_finished : bool ; } ; ;
let default_tagline_description = [ " ocaml " , ' O ' ; " native " , ' N ' ; " byte " , ' B ' ; " program " , ' P ' ; " pp " , ' R ' ; " debug " , ' D ' ; " interf " , ' I ' ; " link " , ' L ' ; ] ; ;
let ticker_animation = [ | " " ; \\ " " ; | " " ; / " " ; - ] ; ; |
let uncached = " " ; ;
let create_tagline description = String . make ( List . length description ) ' ' ; ; -
let create ( ? channel = stdout ) ( ? mode [ ` : Classic ` | Sophisticated ] = ` Sophisticated ) ? columns ( : _columns = 75 ) ( ? description = default_tagline_description ) ? log_file ( ? log_level = 1 ) ( ) = let log_channel = match log_file with | None -> None ...
let print_time oc t = let t = int_of_float t in let s = t mod 60 in let m = ( t / 60 ) mod 60 in let h = t / 3600 in fp oc " % 02d :% 02d :% 02d " h m s ; ;
let print_shortened_pathname length oc u = assert ( length >= 3 ) ; let m = String . length u in if m <= length then begin output_string oc u ; fp oc " %* s " ( length - m ) " " end else begin let n = String . length dots in let k = length - n in output_string oc dots ; output oc u (...
let redraw_sophisticated ds = let t = gettimeofday ( ) in let oc = ds . ds_channel in let dt = t . - ds . ds_start_time in ds . ds_last_update <- t ; fp oc " % a " ANSI . bol ( ) ; let ticker_phase = ( abs ( int_of_float ( ceil ( dt . / ticker_period ) ) ) ) mod ( ...
let redraw = function | Classic -> ( ) | Sophisticated ds -> redraw_sophisticated ds ; ;
let finish_sophisticated ( ? how ` = Success ) ds = let t = gettimeofday ( ) in let oc = ds . ds_channel in let dt = t . - ds . ds_start_time in match how with | ` Success ` | Error -> fp oc " % a " ANSI . bol ( ) ; fp oc " % s % d target % s ( % d cached ) in % a ....
let sophisticated_display ds f = fp ds . ds_channel " % a % a " %! ANSI . bol ( ) ANSI . clear_to_eol ( ) ; f ds . ds_channel ; ;
let call_if log_channel f = match log_channel with | None -> ( ) | Some x -> f x ; ;
let display di f = call_if di . di_log_channel ( fun ( _ , oc ) -> f oc ) ; match di . di_display_line with | Classic -> f di . di_channel | Sophisticated ds -> sophisticated_display ds f ; ;
let finish ( ? how ` = Success ) di = if not di . di_finished then begin di . di_finished <- true ; call_if di . di_log_channel begin fun ( fmt , oc ) -> Format . fprintf fmt " # Compilation % ssuccessful . . " @ ( if how = ` Error then " un " else " " ) ; close_ou...
let update_tagline_from_tags ds = let tagline = ds . ds_tagline in let tags = ds . ds_last_tags in let rec loop i = function | [ ] -> for j = i to String . length tagline - 1 do tagline . [ j ] <- ' ' - done | ( tag , c ) :: rest -> if Tags . mem tag tags then tagline . [ i...
let update_sophisticated ds = let t = gettimeofday ( ) in let dt = t . - ds . ds_last_update in if dt > ds . ds_update_interval then begin if ds . ds_changed then begin update_tagline_from_tags ds ; ds . ds_changed <- false end ; redraw_sophisticated ds end else ( ) ; ;
let set_target_sophisticated ds target tags cached = ds . ds_changed <- true ; ds . ds_last_target <- target ; ds . ds_last_tags <- tags ; ds . ds_jobs <- 1 + ds . ds_jobs ; if cached then ds . ds_jobs_cached <- 1 + ds . ds_jobs_cached ; ds . ds_last_cached <- cached ; ds . ds_s...
let print_tags f tags = let first = ref true in Tags . iter begin fun tag -> if ! first then begin first := false ; Format . fprintf f " % s " tag end else Format . fprintf f " , % s " tag end tags ; ;
let update di = match di . di_display_line with | Classic -> ( ) | Sophisticated ds -> update_sophisticated ds ; ;
let event di ( ? pretend = false ) command target tags = call_if di . di_log_channel ( fun ( fmt , _ ) -> Format . fprintf fmt " # Target : % s , tags : { % a } \ n " target print_tags tags ; Format . fprintf fmt " % s % s . " @ command ( if pretend then " # cached...
let dprintf ( ? log_level = 1 ) di fmt = if log_level > di . di_log_level then Discard_printf . discard_printf fmt else match di . di_display_line with | Classic -> Format . fprintf di . di_formatter fmt | Sophisticated _ -> if log_level < 0 then begin display di ignore ; Format . fprintf ...
* . . . * let v = caml_alloc_dummy n in * * . . . * let p = expr in * * . . . * let rec f x = . . . * and g x = . . . * and . . . * in * * caml_update_dummy v v_contents ; * * . . . * ] } ) *
module Ident = struct include Ident module Set = struct include Ident . Set let fixpoint f set = let rec aux acc set = if is_empty set then acc else let set ' = fold ( fun x -> union ( f x ) ) set empty in let acc = union acc set in aux acc ( diff set ' acc ) in aux empty set end end
type block_type = | Normal of int | Boxed_float
type block = { block_type : block_type ; size : int }
type letrec = { blocks : ( Ident . t * block ) list ; consts : ( Ident . t * Lambda . structured_constant ) list ; pre : tail : Lambda . lambda -> Lambda . lambda ; effects : Lambda . lambda ; functions : ( Ident . t * Lambda . lfunction ) list ; substitution : Ident ...
type let_def = { let_kind : Lambda . let_kind ; value_kind : Lambda . value_kind ; ident : Ident . t }
let ( ) = ignore Bug
let lsequence ( lam1 , lam2 ) = match lam1 with | Lsequence ( lam , Lconst ( Const_base ( Const_int 0 ) ) ) -> Lsequence ( lam , lam2 ) | Lconst ( Const_base ( Const_int 0 ) ) -> lam2 | _ -> Lsequence ( lam1 , lam2 )
let caml_update_dummy_prim = Primitive . simple ~ name " : caml_update_dummy " ~ arity : 2 ~ alloc : true
let update_dummy var expr = Lprim ( Pccall caml_update_dummy_prim , [ Lvar var ; expr ] , Loc_unknown )
let build_block let_def size block_type expr letrec = { letrec with blocks = ( let_def . ident , { block_type ; size } ) :: letrec . blocks ; effects = Lsequence ( update_dummy let_def . ident expr , letrec . effects ) }
let is_simple ( lam : Lambda . lambda ) = match lam with Lvar _ | Lconst _ -> true | _ -> false
let dead_code lam letrec = { letrec with effects = lsequence ( lam , letrec . effects ) }
let rec prepare_letrec ( recursive_set : Ident . Set . t ) ( current_let : let_def option ) ( lam : Lambda . lambda ) ( letrec : letrec ) = match lam with | Lfunction funct -> begin match current_let with | Some current_let when Ident . Set . mem current_let . ident recursive_set ->...
let dissect_letrec ~ bindings ~ body = let letbound = Ident . Set . of_list ( List . map fst bindings ) in let letrec = List . fold_right ( fun ( id , def ) letrec -> let let_def = { let_kind = Strict ; value_kind = Pgenval ; ident = id } in prepare_letrec letbound ( Some let_def...
type dissected = | Dissected of Lambda . lambda | Unchanged
let dissect_letrec ~ bindings ~ body = let is_a_function = function _ , Lfunction _ -> true | _ , _ -> false in if List . for_all is_a_function bindings then Unchanged else try Dissected ( dissect_letrec ~ bindings ~ body ) with Bug -> Misc . fatal_errorf " let - rec . @% a . " @ Pr...
type t = Autogen | Dot | Target of Target . Name . t
let to_string = function | Autogen -> " autogen " | Dot -> " dot " | Target n -> " target ( " ^ Target . Name . to_string n ^ " ) "
let to_filename = function | Target tn -> Target . Name . to_dirname tn | Dot -> fn ( " dot " ) | Autogen -> fn ( " autogen " )
let path = ref ( fp " dist " )
let set_path p = path := p
let get_path ( ) = ! path
let setup_path = get_path ( ) </> fn " setup "
let configure_path = get_path ( ) </> fn " configure "
let build_path = get_path ( ) </> fn " build "
let check_exn f = if Filesystem . exists ( get_path ( ) ) then ( if Sys . is_directory $ fp_to_string ( get_path ( ) ) then ( ) else raise NotADirectory ) else f ( )
let exist ( ) = check_exn ( fun ( ) -> raise DoesntExist )
let create_maybe ( ) = check_exn ( fun ( ) -> let _ = Filesystem . mkdirSafe ( get_path ( ) ) 0o755 in ( ) )
let get_build ( ) = get_path ( ) </> fn " build "
let get_build_path buildtype = get_build ( ) </> ( to_filename buildtype )
let get_build_exn buildtype = let dist = get_build_path buildtype in if not ( Filesystem . is_dir dist ) then raise ( MissingDestinationDirectory buildtype ) else dist
let create_build buildtype = let _ = Filesystem . mkdirSafe ( get_build ( ) ) 0o755 in let dest = get_build_path buildtype in let _ = Filesystem . mkdirSafe dest 0o755 in dest
let read_dist_file path = try let content = Filesystem . readFile path in hashtbl_fromList ( List . map ( fun l -> second ( default " " ) $ Utils . toKV l ) $ string_split ' \ n ' content ) with _ -> raise ( FileDoesntExist ( fp_to_string path ) )
let read_setup ( ) = read_dist_file setup_path
let read_configure ( ) = read_dist_file configure_path
let write_setup setup = let kv ( k , v ) = k ^ " : " ^ v in Filesystem . writeFile setup_path ( String . concat " \ n " $ List . map kv ( hashtbl_toList setup ) )
let remove_dead_links ( ) = let files = Sys . readdir " . " in let build_path = fp_to_string ( get_build ( ) ) in Array . iter ( fun fn -> try let l = Unix . readlink fn in if ( string_startswith build_path l ) then Sys . remove fn with _ -> ( ) ) files
let eliom_template_dir = Findlib . package_directory " eliom . templates "
let distillery_basic = " basic . ppx " , eliom_template_dir
let template_path ( tname , tpath ) = tpath ^ " " / ^ tname
let lines_of_file file = if not ( Sys . file_exists file ) then [ ] else let lines = ref [ ] in let in_file = open_in file in let rec aux ( ) = try lines := input_line in_file :: ! lines ; aux ( ) with End_of_file -> close_in in_file in aux ( ) ; ! lines
let pp_list ( ) l = let f s = if s = fst distillery_basic then s ^ " ( default ) " else s in String . concat " , " ( List . map f l )
let gen_usage_msg l = Printf . sprintf " Welcome to the Eliom distillery !\ n \ nThis program generates the scaffold for your Eliom application \ nfrom a template . \ nAvailable templates : % a . \ n \ nCall it like this \ n \ $ % s - name < name > [ - template < template ] > [ - targe...
let rec yes_no : default : bool -> string -> bool = fun ~ default msg -> printf " % s ( % s /% s ) " msg ( if default then " YES " else " yes " ) ( if default then " no " else " NO " ) ; match String . ( lowercase_ascii ( read_line ( ) ) ) with | " yes " |...
let split_path str = Str . ( split_delim ( regexp ( quote Filename . dir_sep ) ) str )
let join_path = function | [ " " ] -> failwith " join_path " | path -> String . concat Filename . dir_sep path
let ifdef_regexp = Str . ( regexp " ^ *%%% ifdef ( [ +\\ A - Z0 - 9_ ] ) +\\%%% " ) *$
let endif_regexp = Str . ( regexp " ^ *%%% endif %%% " ) *$
let mkdir_p path_str = let rec aux sofar = function | [ ] -> ( ) | snippet :: rest -> let sofar ' = snippet :: sofar in ( if sofar ' <> [ " " ] then let dir = join_path ( List . rev sofar ' ) in if Sys . file_exists dir then ( if not ( Sys . is_directory dir ) then rai...
let copy_file_plain input_name output_name = mkdir_p ( Filename . dirname output_name ) ; let buffer_size = 8192 in let fd_in = Unix . openfile input_name [ O_RDONLY ] 0 and fd_out = let { Unix . st_perm } = Unix . stat input_name in Unix . openfile output_name [ O_WRONLY ; O_CREAT ; ...
let copy_file ( ? env = [ ] ) ( ? preds = [ ] ) src_name dst_name = let line_counter = ref 0 in let include_line = let ifdef_stack = ref [ ] in let preds = List . map ( fun pred -> pred , Str . ( regexp ( " ^ *%%% ifdef " + ^ quote pred ^ " %%% " ) ) ) *$ ...
let expand_dest_path ~ name ~ dest_dir s = Str . ( global_replace ( regexp ( quote " PROJECT_NAME " ) ) name s ) |> Str . ( split ( regexp " " ) ) ! |> join_path |> Filename . concat dest_dir
let create_project ? preds ~ without_asking ~ name ~ env ~ source_dir ~ dest_dir ( ) = let eliom_ignore_files = lines_of_file ( Filename . concat source_dir eliomignore_filename ) and eliom_verbatim_files = lines_of_file ( Filename . concat source_dir eliomverbatim_filename ) in if not ( Sys ...
let env name = let db = if Utils . has_package " ocsipersist . dbm " then " dbm " else if Utils . has_package " ocsipersist . sqlite " then " sqlite " else if Utils . has_package " ocsipersist . pgsql " then " pgsql " else " dbm " in [ " PROJECT_NAME " , name ; " MO...
let get_templatedirs ( ) = let distillery_path_dirs = try let paths = Sys . getenv " ELIOM_DISTILLERY_PATH " in Str . split ( Str . regexp " " ) : paths with Not_found -> [ ] in eliom_template_dir :: distillery_path_dirs
let get_templates ( ) = let dirs = List . map ( fun d -> d , Unix . opendir d ) ( get_templatedirs ( ) ) in let rec aux rl ( path , dir ) = try let f = Unix . readdir dir in if f = " . . " || f = " . " then aux rl ( path , dir ) else aux ( ( f , path ) ...