text
stringlengths 0
601k
|
---|
let test_16 ( ) = Alcotest . ( check bool ) " test 16 " true ( To_test . test_16 ( ) ) |
let test_17 ( ) = Alcotest . ( check bool ) " test 17 " true ( To_test . test_17 ( ) ) |
let test_18 ( ) = Alcotest . ( check bool ) " test 18 " true ( To_test . test_18 ( ) ) |
let test_19 ( ) = Alcotest . ( check bool ) " test 19 " true ( To_test . test_19 ( ) ) |
let test_20 ( ) = Alcotest . ( check bool ) " test 20 " true ( To_test . test_20 ( ) ) |
let test_21 ( ) = Alcotest . ( check bool ) " test 21 " true ( To_test . test_21 ( ) ) |
let test_22 ( ) = Alcotest . ( check bool ) " test 22 " true ( To_test . test_22 ( ) ) |
let test_23 ( ) = Alcotest . ( check bool ) " test 23 " true ( To_test . test_23 ( ) ) |
let test_24 ( ) = Alcotest . ( check bool ) " test 24 " true ( To_test . test_24 ( ) ) |
let test_25 ( ) = Alcotest . ( check bool ) " test 25 " true ( To_test . test_25 ( ) ) |
let test_26 ( ) = Alcotest . ( check bool ) " test 26 " true ( To_test . test_26 ( ) ) |
let test_27 ( ) = Alcotest . ( check bool ) " test 27 " true ( To_test . test_27 ( ) ) |
let test_28 ( ) = Alcotest . ( check bool ) " test 28 " true ( To_test . test_28 ( ) ) |
let test_29 ( ) = Alcotest . ( check bool ) " test 29 " true ( To_test . test_29 ( ) ) |
let test_30 ( ) = Alcotest . ( check bool ) " test 30 " true ( To_test . test_30 ( ) ) |
let test_set = [ " test 01 " , ` Slow , test_01 ; " test 02 " , ` Slow , test_02 ; " test 03 " , ` Slow , test_03 ; " test 04 " , ` Slow , test_04 ; " test 05 " , ` Slow , test_05 ; " test 06 " , ` Slow , test_06 ; " test 07 " , ` Slow , test_07 ; " test 08 " , ` Slow , test_08 ; " test 09 " , ` Slow , test_09 ; " test 10 " , ` Slow , test_10 ; " test 11 " , ` Slow , test_11 ; " test 12 " , ` Slow , test_12 ; " test 13 " , ` Slow , test_13 ; " test 14 " , ` Slow , test_14 ; " test 15 " , ` Slow , test_15 ; " test 16 " , ` Slow , test_16 ; " test 17 " , ` Slow , test_17 ; " test 18 " , ` Slow , test_18 ; " test 19 " , ` Slow , test_19 ; " test 20 " , ` Slow , test_20 ; " test 21 " , ` Slow , test_21 ; " test 22 " , ` Slow , test_22 ; " test 23 " , ` Slow , test_23 ; " test 24 " , ` Slow , test_24 ; " test 25 " , ` Slow , test_25 ; " test 26 " , ` Slow , test_26 ; " test 27 " , ` Slow , test_27 ; " test 28 " , ` Slow , test_28 ; " test 29 " , ` Slow , test_29 ; " test 30 " , ` Slow , test_30 ] |
let clientlst = ref [ ] |
type ( ' a , ' b ) t = State of ' a | Bundle of ' a * ( iworld_t * ' b ) list * iworld_t list |
let rec sendmail lst1 = match lst1 with [ ] -> ( ) | ( first1 , first2 ) :: rest -> begin if List . mem_assoc first1 ! clientlst then Socket . send ( Some first2 ) first1 ; sendmail rest end |
let initial_new state iworld = State state |
let initial_msg state iworld sexp = State state |
let initial_tick state = State state |
let initial_disconnect state iworld = Bundle ( state , [ ] , [ iworld ] ) |
let universe ( ? on_new = initial_new ) ( ? on_msg = initial_msg ) ( ? rate = 1 . 0 ) ( ? on_tick = initial_tick ) ( ? on_disconnect = initial_disconnect ) initial_state = let rate = int_of_float ( 1000 . . * rate ) in let state = ref initial_state in let server_sockfd = Socket . make_sockfd ( ) in let cut_communication client_sockfd = if List . mem_assoc client_sockfd ! clientlst then begin clientlst := List . remove_assoc client_sockfd ! clientlst ; Socket . close client_sockfd ; ! clientlst = [ ] end else false in let rec update_and_send result = match result with State newstate -> state := newstate | Bundle ( newstate , maillst , iworldlst ) -> state := newstate ; match iworldlst with first :: rest -> Socket . send None first ; GMain . Io . remove ( List . assoc first ! clientlst ) ; if cut_communication first then state := initial_state else update_and_send ( Bundle ( ! state , maillst , rest ) ) | _ -> sendmail maillst in let makemail client_sockfd = if ( List . mem_assoc client_sockfd ! clientlst ) then let result = let message = try Socket . receive client_sockfd with _ -> None in match message with None -> on_disconnect ! state client_sockfd | Some m -> on_msg ! state client_sockfd m in update_and_send result ; in let msg_event _ = let readlst = Socket . select_read ( fst ( List . split ! clientlst ) ) in List . iter makemail readlst ; true in let new_event _ = let client_sockfd = Socket . new_client_sockfd server_sockfd in let wid = ( GMain . Io . add_watch ~ cond [ ` : IN ] ~ callback : msg_event ( GMain . Io . channel_of_descr client_sockfd ) ) in clientlst := ( client_sockfd , wid ) :: ! clientlst ; let result = on_new ! state client_sockfd in update_and_send result ; true in let time_event _ = let result = on_tick ! state in update_and_send result ; true in Socket . listen server_sockfd ; let port_number = Socket . portnum server_sockfd in print_endline ( string_of_int port_number ) ; flush stdout ; ignore ( GMain . Io . add_watch ~ cond [ ` : IN ] ~ callback : new_event ( GMain . Io . channel_of_descr server_sockfd ) ) ; ignore ( GMain . Timeout . add ~ ms : rate ~ callback : time_event ) ; GMain . Main . main ( ) |
module Key = struct module Witness = struct type ' a t = . . end module type T = sig type t type ' a Witness . t += T : t Witness . t val id : int val name : string val to_dyn : t -> Dyn . t end type ' a t = ( module T with type t = ' a ) let next = ref 0 let create ( type a ) ~ name to_dyn = let n = ! next in next := n + 1 ; let module M = struct type t = a type ' a Witness . t += T : t Witness . t let id = n let to_dyn = to_dyn let name = name end in ( module M : T with type t = a ) let id ( type a ) ( module M : T with type t = a ) = M . id let eq ( type a b ) ( module A : T with type t = a ) ( module B : T with type t = b ) : ( a , b ) Type_eq . t = match A . T with | B . T -> Type_eq . T | _ -> assert false end |
module Binding = struct type t = T : ' a Key . t * ' a -> t end |
type t = Binding . t Int . Map . t |
let set ( type a ) t ( key : a Key . t ) x = let ( module M ) = key in let data = Binding . T ( key , x ) in Int . Map . set t M . id data |
let add ( type a ) t ( key : a Key . t ) ( x : a ) : ( t , a ) Result . t = let ( module M ) = key in let data = Binding . T ( key , x ) in match Int . Map . add t M . id data with | Ok x -> Ok x | Error ( Binding . T ( key ' , x ) ) -> let eq = Key . eq key ' key in Error ( Type_eq . cast eq x ) |
let update ( type a ) t ( key : a Key . t ) ~ f = let ( module M ) = key in Int . Map . update t M . id ~ f ( : function | None -> f None |> Option . map ~ f ( : fun x -> Binding . T ( key , x ) ) | Some ( Binding . T ( key ' , x ) ) -> let eq = Key . eq key ' key in let x = Type_eq . cast eq x in f ( Some x ) |> Option . map ~ f ( : fun x -> Binding . T ( key , x ) ) ) |
let mem t key = Int . Map . mem t ( Key . id key ) |
let remove t key = Int . Map . remove t ( Key . id key ) |
let find t key = match Int . Map . find t ( Key . id key ) with | None -> None | Some ( Binding . T ( key ' , v ) ) -> let eq = Key . eq key ' key in Some ( Type_eq . cast eq v ) |
let find_exn t key = match Int . Map . find t ( Key . id key ) with | None -> failwith " Univ_map . find_exn " | Some ( Binding . T ( key ' , v ) ) -> let eq = Key . eq key ' key in Type_eq . cast eq v |
let singleton key v = Int . Map . singleton ( Key . id key ) ( Binding . T ( key , v ) ) |
let to_dyn ( t : t ) = let open Dyn . Encoder in Dyn . Map ( Int . Map . values t |> List . map ~ f ( : fun ( Binding . T ( key , v ) ) -> let ( module K ) = key in ( string K . name , K . to_dyn v ) ) ) |
module type S = sig type t module Key : sig type ' a t val create : name : string -> ( ' a -> Dyn . t ) -> ' a t end val empty : t val is_empty : t -> bool val mem : t -> ' a Key . t -> bool val set : t -> ' a Key . t -> ' a -> t val add : t -> ' a Key . t -> ' a -> ( t , ' a ) Result . t val update : t -> ' a Key . t -> f ( ' : a option -> ' a option ) -> t val remove : t -> ' a Key . t -> t val find : t -> ' a Key . t -> ' a option val find_exn : t -> ' a Key . t -> ' a val singleton : ' a Key . t -> ' a -> t val superpose : t -> t -> t val to_dyn : t -> Dyn . t val to_dyns : t -> ( string * Dyn . t ) list end |
let _ = startup ( ) ; at_exit cleanup |
type error = E2BIG | EACCES | EAGAIN | EBADF | EBUSY | ECHILD | EDEADLK | EDOM | EEXIST | EFAULT | EFBIG | EINTR | EINVAL | EIO | EISDIR | EMFILE | EMLINK | ENAMETOOLONG | ENFILE | ENODEV | ENOENT | ENOEXEC | ENOLCK | ENOMEM | ENOSPC | ENOSYS | ENOTDIR | ENOTEMPTY | ENOTTY | ENXIO | EPERM | EPIPE | ERANGE | EROFS | ESPIPE | ESRCH | EXDEV | EWOULDBLOCK | EINPROGRESS | EALREADY | ENOTSOCK | EDESTADDRREQ | EMSGSIZE | EPROTOTYPE | ENOPROTOOPT | EPROTONOSUPPORT | ESOCKTNOSUPPORT | EOPNOTSUPP | EPFNOSUPPORT | EAFNOSUPPORT | EADDRINUSE | EADDRNOTAVAIL | ENETDOWN | ENETUNREACH | ENETRESET | ECONNABORTED | ECONNRESET | ENOBUFS | EISCONN | ENOTCONN | ESHUTDOWN | ETOOMANYREFS | ETIMEDOUT | ECONNREFUSED | EHOSTDOWN | EHOSTUNREACH | ELOOP | EOVERFLOW | EUNKNOWNERR of int |
let _ = Callback . register_exception " Unix . Unix_error " ( Unix_error ( E2BIG , " " , " " ) ) |
let handle_unix_error f arg = try f arg with Unix_error ( err , fun_name , arg ) -> prerr_string Sys . argv . ( 0 ) ; prerr_string " : " " ; \ prerr_string fun_name ; prerr_string " " \ failed " ; if String . length arg > 0 then begin prerr_string " on " " ; \ prerr_string arg ; prerr_string " " " \ end ; prerr_string " : " ; prerr_endline ( error_message err ) ; exit 2 |
type process_status = WEXITED of int | WSIGNALED of int | WSTOPPED of int |
type wait_flag = WNOHANG | WUNTRACED |
let fork ( ) = invalid_arg " Unix . fork not implemented " |
let wait ( ) = invalid_arg " Unix . wait not implemented " |
let getppid ( ) = invalid_arg " Unix . getppid not implemented " |
let nice _ = invalid_arg " Unix . nice not implemented " |
let stdin = filedescr_of_fd 0 |
let stdout = filedescr_of_fd 1 |
let stderr = filedescr_of_fd 2 |
type open_flag = O_RDONLY | O_WRONLY | O_RDWR | O_NONBLOCK | O_APPEND | O_CREAT | O_TRUNC | O_EXCL | O_NOCTTY | O_DSYNC | O_SYNC | O_RSYNC | O_SHARE_DELETE | O_CLOEXEC | O_KEEPEXEC |
type file_perm = int = " unix_open " = " unix_read " = " unix_write " = " unix_single_write " |
let read fd buf ofs len = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . read " else unsafe_read fd buf ofs len |
let write fd buf ofs len = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . write " else unsafe_write fd buf ofs len |
let single_write fd buf ofs len = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . single_write " else unsafe_single_write fd buf ofs len |
let write_substring fd buf ofs len = write fd ( Bytes . unsafe_of_string buf ) ofs len |
let single_write_substring fd buf ofs len = single_write fd ( Bytes . unsafe_of_string buf ) ofs len = " win_inchannel_of_filedescr " = " win_outchannel_of_filedescr " = " win_filedescr_of_channel " = " win_filedescr_of_channel " |
type seek_command = SEEK_SET | SEEK_CUR | SEEK_END |
type file_kind = S_REG | S_DIR | S_CHR | S_BLK | S_LNK | S_FIFO | S_SOCK |
type stats = { st_dev : int ; st_ino : int ; st_kind : file_kind ; st_perm : file_perm ; st_nlink : int ; st_uid : int ; st_gid : int ; st_rdev : int ; st_size : int ; st_atime : float ; st_mtime : float ; st_ctime : float } |
module LargeFile = struct external lseek : file_descr -> int64 -> seek_command -> int64 = " unix_lseek_64 " external truncate : string -> int64 -> unit = " unix_truncate_64 " external ftruncate : file_descr -> int64 -> unit = " unix_ftruncate_64 " type stats = { st_dev : int ; st_ino : int ; st_kind : file_kind ; st_perm : file_perm ; st_nlink : int ; st_uid : int ; st_gid : int ; st_rdev : int ; st_size : int64 ; st_atime : float ; st_mtime : float ; st_ctime : float ; } external stat : string -> stats = " unix_stat_64 " external lstat : string -> stats = " unix_lstat_64 " external fstat : file_descr -> stats = " unix_fstat_64 " end file_descr -> ( ' a , ' b ) Stdlib . Bigarray . kind -> ' c Stdlib . Bigarray . layout -> bool -> int array -> int64 -> ( ' a , ' b , ' c ) Stdlib . Bigarray . Genarray . t = " caml_unix_map_file_bytecode " " caml_unix_map_file " |
let map_file fd ( ? pos = 0L ) kind layout shared dims = map_internal fd kind layout shared dims pos |
type access_permission = R_OK | W_OK | X_OK | F_OK |
let fchmod _fd _perm = invalid_arg " Unix . fchmod not implemented " |
let chown _file _perm = invalid_arg " Unix . chown not implemented " |
let fchown _fd _perm = invalid_arg " Unix . fchown not implemented " |
let umask _msk = invalid_arg " Unix . umask not implemented " ? cloexec : bool -> file_descr -> file_descr -> unit = " unix_dup2 " |
let chroot _ = invalid_arg " Unix . chroot not implemented " |
type dir_entry = Dir_empty | Dir_read of string | Dir_toread |
type dir_handle = { dirname : string ; mutable handle : int ; mutable entry_read : dir_entry } |
let opendir dirname = try let ( first_entry , handle ) = findfirst ( Filename . concat dirname " . " ) ** in { dirname = dirname ; handle = handle ; entry_read = Dir_read first_entry } with End_of_file -> { dirname = dirname ; handle = 0 ; entry_read = Dir_empty } |
let readdir d = match d . entry_read with Dir_empty -> raise End_of_file | Dir_read name -> d . entry_read <- Dir_toread ; name | Dir_toread -> findnext d . handle |
let closedir d = match d . entry_read with Dir_empty -> ( ) | _ -> win_findclose d . handle |
let rewinddir d = closedir d ; try let ( first_entry , handle ) = findfirst ( d . dirname ^ " . " ) \\** in d . handle <- handle ; d . entry_read <- Dir_read first_entry with End_of_file -> d . handle <- 0 ; d . entry_read <- Dir_empty ? cloexec : bool -> unit -> file_descr * file_descr = " unix_pipe " |
let mkfifo _name _perm = invalid_arg " Unix . mkfifo not implemented " |
let normalize_slashes path = if String . length path >= 4 && path . [ 0 ] = ' ' \\ && path . [ 1 ] = ' ' \\ && path . [ 2 ] = ' ' ? && path . [ 3 ] = ' ' \\ then path else String . init ( String . length path ) ( fun i -> match path . [ i ] with ' ' / -> ' ' \\ | c -> c ) |
let symlink ? to_dir source dest = let to_dir = match to_dir with Some to_dir -> to_dir | None -> try LargeFile . ( ( stat source ) . st_kind = S_DIR ) with _ -> false in let source = normalize_slashes source in symlink_stub to_dir source dest |
type lock_command = F_ULOCK | F_LOCK | F_TLOCK | F_TEST | F_RLOCK | F_TRLOCK |
let kill pid signo = if signo <> Sys . sigkill then invalid_arg " Unix . kill " else if not ( terminate_process pid ) then raise ( Unix_error ( ESRCH , " kill " , " " ) ) |
type sigprocmask_command = SIG_SETMASK | SIG_BLOCK | SIG_UNBLOCK |
let sigprocmask _cmd _sigs = invalid_arg " Unix . sigprocmask not implemented " |
let sigpending ( ) = invalid_arg " Unix . sigpending not implemented " |
let sigsuspend _sigs = invalid_arg " Unix . sigsuspend not implemented " |
let pause ( ) = invalid_arg " Unix . pause not implemented " |
type process_times = { tms_utime : float ; tms_stime : float ; tms_cutime : float ; tms_cstime : float } |
type tm = { tm_sec : int ; tm_min : int ; tm_hour : int ; tm_mday : int ; tm_mon : int ; tm_year : int ; tm_wday : int ; tm_yday : int ; tm_isdst : bool } |
let alarm _n = invalid_arg " Unix . alarm not implemented " |
let sleep n = sleepf ( float n ) |
type interval_timer = ITIMER_REAL | ITIMER_VIRTUAL | ITIMER_PROF |
type interval_timer_status = { it_interval : float ; it_value : float } |
let getitimer _it = invalid_arg " Unix . getitimer not implemented " |
let setitimer _it _tm = invalid_arg " Unix . setitimer not implemented " |
let getuid ( ) = 1 |
let setuid _id = invalid_arg " Unix . setuid not implemented " |
let getgid ( ) = 1 |
let setgid _id = invalid_arg " Unix . setgid not implemented " |
let getgroups ( ) = [ | 1 ] | |
let setgroups _ = invalid_arg " Unix . setgroups not implemented " |
let initgroups _ _ = invalid_arg " Unix . initgroups not implemented " |
type passwd_entry = { pw_name : string ; pw_passwd : string ; pw_uid : int ; pw_gid : int ; pw_gecos : string ; pw_dir : string ; pw_shell : string } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.