text
stringlengths
0
601k
let find_private_classless_static_route = find_option ( function Private_classless_static_route x -> Some x | _ -> None )
type response = { r_conditions : string option ; r_output : json option ; r_context : json option ; }
type slot = { s_prompt : output_def ; s_conditions : string ; s_variable : string ; s_context : json option ; s_match : response list ; s_nomatch : response list ; }
type node = { n_dialog_node : string ; n_description : string option ; n_conditions : string option ; n_prompt : output_def ; n_reactions : response list ; n_responses : response list ; n_slots : slot list ; n_metadata : json option ; n_next_step : next_step option ; n_created : string option ; n_updated : string optio...
type dialog = | D of ( node * dialog ) list
let ( ) >>= x f = match x with Ok x -> f x | ( Error _ ) as x -> x
let ( ) >|= x f = x >>= fun x -> Ok ( f x )
let rec map_bind f acc xs = match xs with | x :: xs -> f x >>= fun x -> map_bind f ( x :: acc ) xs | [ ] -> Ok ( List . rev acc )
type ' a error_or = ( ' a , string ) result
type workspace_ids = { ws_dispatch_id : string ; ws_when_id : string ; ws_cond_id : string ; ws_cond_continue_id : string ; ws_then_id : string ; ws_expr_id : string ; ws_actn_id : string ; ws_accept_id : string ; }
type ' a dispatch = { dsp_replace : bool ; dsp_abort : bool ; dsp_number : ' a option ; dsp_when : bool ; dsp_cond : bool ; dsp_then : bool ; }
let rec dispatch_to_yojson : ' a . ( ' a -> Yojson . Safe . json ) -> ' a dispatch -> Yojson . Safe . json = fun poly_a -> ( ( fun x -> let fields = [ ] in let fields = ( " dsp_then " , ( ( fun x -> ` Bool x ) x . dsp_then ) ) :: fields in let fields = ( " dsp_cond " , ( ( fun x -> ` Bool x ) x . dsp_cond ) ) :: fields...
let int_dispatch_of_yojson = dispatch_of_yojson ( fun json -> match json with | ` Int n -> Ok n | _ -> Error ( " int_dispatch_of_yojson : " ^ ( Yojson . Safe . pretty_to_string json ) ) )
let string_dispatch_to_yojson = dispatch_to_yojson ( fun x -> ` String x )
let bypass_expr input = try let regexp = Str . regexp " ` ( . ) ` " \\*\\ in let _ = Str . search_forward regexp input 0 in let quoted_string = Str . matched_group 1 input in try Some ( false , ( Parser_util . parse_cnl_expr_from_string quoted_string ) ) with | e -> ( Io_util . print_berl_error quoted_string ; None ) w...
let bypass_empty input = None
let match_string s = try try let regexp = Str . regexp " " ( . ) " " \\\*\\\ in let _ = Str . search_forward regexp s 0 in let string = Str . matched_group 1 s in let s_minus_string = Str . global_replace regexp " " s in Some ( s_minus_string , string ) with | Not_found -> let regexp = Str . regexp " ' ( . ) ' " \\*\\ ...
let debug_message req resp = Format . eprintf " request :@\ n % s @\ n " ( Wcs_j . string_of_message_request req ) ; Format . eprintf " response :@\ n % s . " @ ( Wcs_j . string_of_message_response resp )
let string str = unsafe_string str 0 ( String . length str )
let bytes b = string ( Bytes . unsafe_to_string b )
let substring str ofs len = if ofs < 0 || len < 0 || ofs > String . length str - len then invalid_arg " Digest . substring " else unsafe_string str ofs len
let subbytes b ofs len = substring ( Bytes . unsafe_to_string b ) ofs len
let file filename = let ic = open_in_bin filename in match channel ic ( - 1 ) with | d -> close_in ic ; d | exception e -> close_in ic ; raise e
let output chan digest = output_string chan digest
let input chan = really_input_string chan 16
let char_hex n = Char . unsafe_chr ( n + if n < 10 then Char . code ' 0 ' else ( Char . code ' a ' - 10 ) )
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 + 1 ) ( char_hex ( x land 0x0f ) ) ; done ; Bytes . unsa...
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 ' -> Char . code c - Char . code ' a ' + 10 | _ -> raise ( Invalid_argument "...
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 in let has_predecessors...
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 begin let sector = Cstruct . cre...
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 cstr ) ; Printf . fprintf out " t := Disk . write_...
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 . Header . init_with " Strict - Transport - Security " ...
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 >>= fun cert -> let conf = Tls . Config . server ~ cert...
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_and_read " tput cols " ) ) with | Failure _ -> 80 else 80 end ; ;
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 ; mutable ds_jobs : int ; mutab...
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 | Some fn -> let oc = open_out_gen [ Open_text ; Open_w...
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 ( m - k ) k ; end
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 ( Array . length ticker_animation ) in let ticker = ticke...
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 . " ( if how = ` Error then " Compilation unsuccessful ...
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_out oc ; di . di_log_channel <- None end ; match di . di_...
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 ] <- Char . uppercase c else if Tags . mem ta...
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_seen_tags <- Tags . union ds . ds_seen_tag...
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 " else " " ) ) ; match di . di_display_line with | Cla...
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 di . di_formatter fmt end else...
* . . . * 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 . t Ident . Map . t ; letbound : Ident . Set . t ; n...
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 -> { letrec with functions = ( current_...
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 ) def letrec ) bindings { blocks = [ ] ...
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 . " @ Printlambda . lambda ( Lletrec ( bindin...
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 )