text stringlengths 0 601k |
|---|
let set_char t char class_ flags = set t ( char |> Char_code . of_char_exn ) class_ flags |
object method set_volume : float -> unit method note_on : int -> float -> unit method note_off : int -> float -> unit method fill_add : Audio . buffer -> int -> int -> unit method play_add : MIDI . buffer -> int -> Audio . buffer -> int -> int -> unit method play : MIDI . buffer -> int -> Audio . buffer -> int -> int -... |
type note = { note : int ; volume : float ; generator : Audio . Generator . t } object ( self ) method virtual private generator : float -> float -> Audio . Generator . t val mutable vol : float = 1 . method set_volume v = vol <- v val mutable notes : note list = [ ] method note_on n v = let note = { note = n ; volume ... |
let might_adsr adsr g = match adsr with None -> g | Some a -> new Audio . Mono . Generator . adsr a g create_mono ( fun f v -> might_adsr adsr ( new Audio . Mono . Generator . sine sr ~ volume : v f ) ) create_mono ( fun f v -> might_adsr adsr ( new Audio . Mono . Generator . square sr ~ volume : v f ) ) create_mono ( ... |
module Multitrack = struct class type t = object method play_add : MIDI . Multitrack . buffer -> int -> Audio . buffer -> int -> int -> unit method play : MIDI . Multitrack . buffer -> int -> Audio . buffer -> int -> int -> unit end class create n ( f : int -> synth ) = object ( self ) val synth = Array . init n f meth... |
module type SYNTHESIZER = sig module G : GRAMMAR type variable = | Head of G . lr1 * G . nonterminal | Tail of G . lr1 * G . production * int | expr PLUS expr { $ 1 + $ 2 } Synthesizing ` Head ( st0 , expr ) ` when ` expr PLUS . expr ` is in ` st0 ` will output the actions to get to the state ` st ' ` containing ` expr... |
module Synthesizer ( G : GRAMMAR ) ( A : ATTRIBUTES with module G = G ) : SYNTHESIZER with module G := G = struct open G type variable = Head of lr1 * nonterminal | Tail of lr1 * production * int let variable_to_string = function | Head ( st , n ) -> Printf . sprintf " Head ( #% d , % s ) " ( Lr1 . to_int st ) ( Nonter... |
let ( executable_name , argv ) = get_argv ( ) |
let ( os_type , _ , _ ) = get_config ( ) |
let big_endian = big_endian ( ) |
let word_size = word_size ( ) |
let int_size = int_size ( ) |
let unix = unix ( ) |
let win32 = win32 ( ) |
let cygwin = cygwin ( ) |
let max_array_length = max_wosize ( ) |
let max_string_length = word_size / 8 * max_array_length - 1 " caml_sys_time " " caml_sys_time_unboxed " [ @@ noalloc ] |
let interactive = ref false |
type signal_behavior = Signal_default | Signal_ignore | Signal_handle of ( int -> unit ) = " caml_install_signal_handler " |
let set_signal sig_num sig_beh = ignore ( signal sig_num sig_beh ) |
let catch_break on = if on then set_signal sigint ( Signal_handle ( fun _ -> raise Break ) ) else set_signal sigint Signal_default " caml_ml_enable_runtime_warnings " " caml_ml_runtime_warnings_enabled " |
type backend_type = Caml . Sys . backend_type = | Native | Bytecode | Other of string |
let get_argv ( ) = Caml . Sys . argv |
let getenv_exn var = try Caml . Sys . getenv var with | Caml . Not_found -> Printf . failwithf " Sys . getenv_exn : environment variable % s is not set " var ( ) ; ; |
let getenv var = match Caml . Sys . getenv var with | x -> Some x | exception Caml . Not_found -> None ; ; |
let too_many_tries = Error . to_exn ( Error . create " syscall interrupted too many times " max_tries [ % sexp_of : int ] ) ; ; |
let too_many_tries_error = Error too_many_tries |
let syscall = let rec loop f n = if n >= max_tries then too_many_tries_error else ( match f ( ) with | x -> Ok x | exception Unix . Unix_error ( EINTR , _ , _ ) -> loop f ( n + 1 ) | exception exn -> Error exn ) in fun f -> loop f 0 ; ; |
let is_eintr r = Syscall_result . is_error r && Syscall_result . error_exn r = EINTR |
let syscall_result = let rec loop a f n = if n >= max_tries then raise too_many_tries else ( let r = f a in if not ( is_eintr r ) then r else loop a f ( n + 1 ) ) in fun a f -> loop a f 0 ; ; |
let syscall_result2 = let rec loop a b f n = if n >= max_tries then raise too_many_tries else ( let r = f a b in if not ( is_eintr r ) then r else loop a b f ( n + 1 ) ) in fun a b f -> loop a b f 0 ; ; |
type ' a t = int |
module type S = Syscall_result_intf . S with type ' a syscall_result := ' a t |
module type Arg = Syscall_result_intf . Arg |
let create_error err = - ( Unix_error . to_errno err ) |
let is_ok t = Int . O . ( t >= 0 ) |
let is_error t = Int . O . ( t < 0 ) |
let error_code_exn t = if is_ok t then failwiths ~ here [ :% here ] " Syscall_result . error_code_exn received success value " t [ % sexp_of : int ] else - t ; ; |
let error_exn t = Unix_error . of_errno ( error_code_exn t ) |
module Make ( M : Arg ) ( ) = struct let preallocated_errnos : ( _ , Unix_error . t ) Result . t array = Array . init 64 ~ f ( : fun i -> Error ( Unix_error . of_errno i ) ) ; ; let % test " no 0 errno " = preallocated_errnos . ( 0 ) = Error ( Unix_error . EUNKNOWNERR 0 ) let num_preallocated_errnos = Array . length pr... |
module Int = Make ( Int ) ( ) |
module Unit = Make ( struct type t = unit [ @@ deriving sexp_of , compare ] let of_int_exn n = assert ( n = 0 ) let to_int ( ) = 0 end ) ( ) |
let unit = Unit . create_ok ( ) |
let ignore_ok_value t = Core_kernel . Int . min t 0 |
module type S = sig type ok_value type ' a syscall_result type t = ok_value syscall_result [ @@ deriving compare , sexp_of ] include Equal . S with type t := t val create_ok : ok_value -> t val create_error : Unix_error . t -> t val is_ok : t -> bool val is_error : t -> bool val to_result : t -> ( ok_value , Unix_error... |
module type Arg = sig type t [ @@ deriving sexp_of , compare ] val to_int : t -> int val of_int_exn : int -> t end |
module Open_option = struct type t = | PID | CONS | ODELAY | NDELAY | NOWAIT | PERROR [ @@ deriving sexp ] external to_int : t -> int = " core_syslog_open_option_to_int " let collect_mask i t = to_int t lor i let mask ts = List . fold ~ f : collect_mask ~ init : 0 ts end |
module Facility = struct module T = struct type t = | KERN | USER | MAIL | DAEMON | AUTH | SYSLOG | LPR | NEWS | UUCP | CRON | AUTHPRIV | FTP | LOCAL0 | LOCAL1 | LOCAL2 | LOCAL3 | LOCAL4 | LOCAL5 | LOCAL6 | LOCAL7 [ @@ deriving sexp ] external to_int : t -> int = " core_syslog_facility_to_int " end include T include Se... |
module Level = struct module T = struct type t = | EMERG | ALERT | CRIT | ERR | WARNING | NOTICE | INFO | DEBUG [ @@ deriving sexp , enumerate , compare ] let compare a b = compare b a let % test_unit _ = [ % test_result : int ] ~ expect : 1 ( compare EMERG DEBUG ) external to_int : t -> int = " core_syslog_level_to_in... |
let openlog ? id ( ? options = [ ] ) ( ? facility = Facility . USER ) ( ) = core_syslog_openlog id ( Open_option . mask options ) ( Facility . to_int facility ) |
let syslog ( ? facility = Facility . USER ) ( ? level = Level . INFO ) message = core_syslog_syslog ( Level . to_int level lor Facility . to_int facility ) message |
let syslogf ? facility ? level format = ksprintf ( fun message -> syslog ? facility ? level message ) format |
let logmask_range ( ? to_level = Level . EMERG ) from_level = List . fold Level . all ~ init : 0 ~ f ( : fun logmask level -> if Level . compare from_level level < 1 && Level . compare level to_level < 1 then Level . to_int level lor logmask else logmask ) |
let setlogmask ( ? allowed_levels = [ ] ) ( ? from_level = Level . DEBUG ) ? to_level ( ) = core_syslog_setlogmask ( Level . mask allowed_levels lor logmask_range ? to_level from_level ) |
let ( let * ) = Result . bind |
type facility = | Kernel_Message | User_Level_Messages | Mail_System | System_Daemons | Security_Authorization_Messages | Messages_Generated_Internally_By_Syslogd | Line_Printer_Subsystem | Network_News_Subsystem | UUCP_subsystem | Clock_Daemon | Security_Authorization_Messages_10 | Ftp_Daemon | Ntp_Subsystem | Log_Aud... |
let int_of_facility = function | Kernel_Message -> 0 | User_Level_Messages -> 1 | Mail_System -> 2 | System_Daemons -> 3 | Security_Authorization_Messages -> 4 | Messages_Generated_Internally_By_Syslogd -> 5 | Line_Printer_Subsystem -> 6 | Network_News_Subsystem -> 7 | UUCP_subsystem -> 8 | Clock_Daemon -> 9 | Security... |
let facility_of_int = function | 0 -> Some Kernel_Message | 1 -> Some User_Level_Messages | 2 -> Some Mail_System | 3 -> Some System_Daemons | 4 -> Some Security_Authorization_Messages | 5 -> Some Messages_Generated_Internally_By_Syslogd | 6 -> Some Line_Printer_Subsystem | 7 -> Some Network_News_Subsystem | 8 -> Some ... |
let string_of_facility = function | Kernel_Message -> " kern " | User_Level_Messages -> " user " | Mail_System -> " mail " | System_Daemons -> " daemon " | Security_Authorization_Messages -> " security / auth " | Messages_Generated_Internally_By_Syslogd -> " syslog " | Line_Printer_Subsystem -> " lpr " | Network_News_S... |
let pp_print_facility ppf f = Format . fprintf ppf " % s " ( string_of_facility f ) |
type severity = | Emergency | Alert | Critical | Error | Warning | Notice | Informational | Debug |
let int_of_severity = function | Emergency -> 0 | Alert -> 1 | Critical -> 2 | Error -> 3 | Warning -> 4 | Notice -> 5 | Informational -> 6 | Debug -> 7 |
let severity_of_int = function | 0 -> Some Emergency | 1 -> Some Alert | 2 -> Some Critical | 3 -> Some Error | 4 -> Some Warning | 5 -> Some Notice | 6 -> Some Informational | 7 -> Some Debug | _ -> None |
let string_of_severity = function | Emergency -> " emerg " | Alert -> " alert " | Critical -> " crit " | Error -> " err " | Warning -> " warning " | Notice -> " notice " | Informational -> " info " | Debug -> " debug " |
let pp_print_severity ppf s = Format . fprintf ppf " % s " ( string_of_severity s ) |
type ctx = { timestamp : Ptime . t ; hostname : string ; set_hostname : bool } |
type t = { facility : facility ; severity : severity ; timestamp : Ptime . t ; hostname : string ; tag : string ; content : string } |
module Rfc3164_Timestamp = struct let int_of_month_name = function | " Jan " -> Some 1 | " Feb " -> Some 2 | " Mar " -> Some 3 | " Apr " -> Some 4 | " May " -> Some 5 | " Jun " -> Some 6 | " Jul " -> Some 7 | " Aug " -> Some 8 | " Sep " -> Some 9 | " Oct " -> Some 10 | " Nov " -> Some 11 | " Dec " -> Some 12 | _ -> Non... |
let to_string msg = let facility = string_of_facility msg . facility and severity = string_of_severity msg . severity and timestamp = Rfc3164_Timestamp . encode msg . timestamp in Printf . sprintf " Facility : % s Severity : % s Timestamp : % s Hostname : % s Tag : % s Content : % s \ n " %! facility severity timestamp... |
let pp ppf msg = Format . pp_print_string ppf ( to_string msg ) |
let encode_gen encode ? len msg = let facse = int_of_facility msg . facility * 8 + int_of_severity msg . severity and ts = Rfc3164_Timestamp . encode msg . timestamp in let msgstr = encode facse ts msg . hostname msg . tag msg . content in match len with | None -> msgstr | Some max_len -> if String . length msgstr > ma... |
let separator s = match String . head s with | Some c when not ( Char . Ascii . is_alphanum c ) -> " " | Some _ | None -> " " |
let encode ? len msg = let encode facse ts hostname tag content = Printf . sprintf " <% d >% s % s % s % s % s " facse ts hostname tag ( separator content ) content in encode_gen encode ? len msg |
let encode_local ? len msg = let encode facse ts _ tag content = Printf . sprintf " <% d >% s % s % s % s " facse ts tag ( separator content ) content in encode_gen encode ? len msg |
let parse_priority_value s : ( facility * severity * string , [ > ` Msg of string ] ) result = match String . cut ~ sep " " :< s with | None -> Error ( ` Msg " couldn ' t parse priority : expected ' ' " ) < | Some ( x , data ) -> if x <> " " then Error ( ` Msg " couldn ' t parse priority : expected ' ' " ) < else match... |
let parse_hostname s ( ctx : ctx ) : ( string * string , [ > ` Msg of string ] ) result = if ctx . set_hostname then Ok ( ctx . hostname , s ) else match String . cut ~ sep " : " s with | None | Some ( " " , _ ) -> Error ( ` Msg " invalid or empty hostname " ) | Some ( host , data ) -> let * hostname = match String . c... |
let parse_timestamp s ( ctx : ctx ) = let ( ( year , _ , _ ) , _ ) = Ptime . to_date_time ctx . timestamp in match Rfc3164_Timestamp . decode s year with | Ok ( timestamp , data ) -> Ok ( timestamp , data , ctx ) | Error _ -> let ctx = { ctx with set_hostname = true } in Ok ( ctx . timestamp , s , ctx ) |
let parse_tag s : ( string * string , [ > ` Msg of string ] ) result = let tag , msg = String . span ~ sat : Char . Ascii . is_alphanum s in if String . length tag > 32 then Error ( ` Msg " tag exceeds 32 characters " ) else Ok ( tag , msg ) |
let decode ~ ctx data : ( t , [ > ` Msg of string ] ) result = let * facility , severity , data = parse_priority_value data in let * timestamp , data , ctx = parse_timestamp data ctx in let * hostname , data = parse_hostname data ctx in let * tag , content = parse_tag data in Ok { facility ; severity ; timestamp ; host... |
compile_and_run { | ( match Sys . command " printf hello " with | 0 -> ( ) | _ -> print_endline " BUG " ) } ; | [ % expect { | hello } ] | compile_and_run { | ( match Sys . command " printf hello >& 2 " with | 0 -> ( ) | _ -> print_endline " BUG " ) } ; | [ % expect { | hello } ] | |
let f ( ) = Sys . mkdir " aaa " 0o777 ; let oc = open_out " aaa / bbb " in close_out oc ; ( try ignore ( Sys . readdir " aaa / bb " ) with | Sys_error _ -> ( ) | e -> print_endline ( Printexc . to_string e ) ) ; ( try ignore ( Sys . readdir " aaa / bbb " ) with | Sys_error _ -> ( ) | e -> print_endline ( Printexc . to_... |
let f ( ) = Sys . mkdir " aaa " 0o777 ; Sys . mkdir " aaa / bbb " 0o777 ; let l = Sys . readdir " aaa " |> Array . to_list in List . iter print_endline l ; ( match Sys . rmdir " aaa " with | exception _ -> ( ) | _ -> print_endline " BUG " ) ; Sys . rmdir " aaa / bbb " ; Sys . rmdir " aaa " in } ; | [ % expect { | bbb b... |
type Error_monad . error += Unix_system_info_failure of string |
let ( ) = Error_monad . register_error_kind ` Temporary ~ id " : unix . system_info " ~ title " : Unix System_info failure " ~ description " : Unix System_info failure " ~ pp ( : fun ppf s -> Format . fprintf ppf " [ @< v 2 > Unix system_info failure % s ] " @ s ) Data_encoding . ( obj1 ( req " failure " string ) ) ( f... |
let error_info process error = Unix_system_info_failure ( Format . asprintf " Unix_system_info_failure ( % s : % s ) " process error ) |
type sysname = Linux | Darwin | Unknown of string |
let uname ( ) = Lwt . catch ( fun ( ) -> Lwt_process . with_process_in ~ env [ " :| LC_ALL = C " ] | ( " uname " , [ " | uname " ] ) | ( fun pc -> Lwt_io . read_line pc # stdout ) >>= function | " Linux " -> Lwt . return_ok Linux | " Darwin " -> Lwt . return_ok Darwin | os -> Lwt . return_ok ( Unknown os ) ) ( function... |
let page_size sysname = let get_conf_process = match sysname with | Linux -> Ok ( " getconf " , [ " | getconf " ; " PAGE_SIZE " ] ) | | Darwin -> Ok ( " pagesize " , [ " | pagesize " ] ) | | Unknown _ -> Error ( error_info " pagesize " " Unknown unix system " ) in get_conf_process >>?= fun process -> Lwt . catch ( fun ... |
let linux_statm pid = Lwt . catch ( fun ( ) -> let fname = Format . asprintf " / proc /% d / statm " pid in Lwt_unix . file_exists fname >>= function | true -> Lwt_io . with_file ~ mode : Input fname ( fun ic -> Lwt_io . read_line ic >>= fun line -> match List . map Int64 . of_string @@ TzString . split ' ' line with |... |
let darwin_ps pid = Lwt . catch ( fun ( ) -> Lwt_process . with_process_in ~ env [ " :| LC_ALL = C " ] | ( " ps " , [ " | ps " ; " - o " ; " pid , % mem , rss " ; " - p " ; string_of_int pid ] ) | ( fun pc -> Lwt_io . read_line_opt pc # stdout >>= function | None -> Lwt . return_error ( error_info " ps " " Unexpected p... |
let memory_stats ( ) = let pid = Unix . getpid ( ) in uname ( ) >>= function | Error e -> Lwt . return_error e | Ok Linux -> linux_statm pid | Ok Darwin -> darwin_ps pid | _ -> Lwt . return_error ( error_info " memory_stats " " Unknown unix system " ) |
let update_file ~ name ~ content = let oc = open_out name in output_string oc content ; close_out oc out_channel -> ( Js . js_string Js . t -> unit ) Js . callback -> unit = " caml_ml_set_channel_output " = " caml_ml_set_channel_refill " |
let set_channel_flusher ( out_channel : out_channel ) ( f : string -> unit ) = let f ' : ( Js . js_string Js . t -> unit ) Js . callback = Js . wrap_callback ( fun s -> f ( Js . to_bytestring s ) ) in set_channel_output ' out_channel f ' |
let set_channel_filler ( in_channel : in_channel ) ( f : unit -> string ) = let f ' : ( unit -> string ) Js . callback = Js . wrap_callback f in set_channel_input ' in_channel f ' string -> ( string -> string -> string option ) Js . callback -> unit = " caml_mount_autoload " |
let mount ~ path f = mount_autoload path ( Js . wrap_callback ( fun prefix path -> f ~ prefix ~ path ) ) |
let unmount ~ path = unmount path |
let js_of_ocaml_version = if String . equal Lib_version . git_version " " then Lib_version . s else Lib_version . s ^ " " + ^ Lib_version . git_version |
let get_env name = try Some ( Sys . getenv name ) with | Not_found -> None |
let getenv_user ( ) = let user_var = if Sys . win32 then " USERNAME " else " USER " in let logname_var = " LOGNAME " in let user = get_env user_var in let logname = get_env logname_var in Hack_option . first_some user logname |
let getenv_home ( ) = let home_var = if Sys . win32 then " APPDATA " else " HOME " in get_env home_var |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.