text stringlengths 0 601k |
|---|
let handle_state init f x = let rec loop : type a r . int -> ( a , r ) continuation -> a -> r * int = fun state k x -> continue_with k x { retc = ( fun result -> result , state ) ; exnc = ( fun e -> raise e ) ; effc = ( fun ( type b ) ( eff : b eff ) -> match eff with | Get -> Some ( fun ( k : ( b , r ) continuation ) ... |
let handle_print f = let rec loop : type r . ( unit , r ) continuation -> r = fun k -> continue_with k ( ) { retc = ( fun x -> x ) ; exnc = ( fun e -> raise e ) ; effc = ( fun ( type a ) ( eff : a eff ) -> match eff with | Print s -> Some ( fun ( k : ( a , r ) continuation ) -> print_string s ; loop k ) | e -> None ) }... |
let comp ( ) = perform ( Print ( Printf . sprintf " Initial state : % d \ n " ( perform Get ) ) ) ; perform ( Set 42 ) ; perform ( Print ( Printf . sprintf " Updated state : % d \ n " ( perform Get ) ) ) ; perform ( Set 43 ) |
let main ( ) = let ( ) , i = handle_print ( handle_state 0 comp ) in Printf . printf " Final state : % d \ n " i |
let _ = main ( ) |
module Shape = struct type radius = int type width = int type height = int type shape = | Circle of radius | Rectangle of ( width * height ) let eq l r = match ( l , r ) with | Circle x , Circle y -> x = y | Rectangle ( w , h ) , Rectangle ( w2 , h2 ) -> w = w2 && h = h2 | _ -> false ; ; let pp ppf = function | Circle ... |
let validation_shape_1 ( ) = let open Preface . Validate in let expected = valid ( Shape . circle 1 ) and computed = Shape . make ( valid true ) ( valid 1 ) ( invalid ( Nel . create ( Shape . Fail " width " ) ) ) ( invalid ( Nel . create ( Shape . Fail " width " ) ) ) in Alcotest . check Shape . testable " Should be a ... |
let validation_shape_2 ( ) = let open Preface . Validate in let expected = valid ( Shape . rectangle 2 3 ) and computed = Shape . make ( valid false ) ( invalid ( Nel . create ( Shape . Fail " radius " ) ) ) ( valid 2 ) ( valid 3 ) in Alcotest . check Shape . testable " Should be a valid rectangle " expected computed ;... |
let validation_shape_3 ( ) = let open Preface . Validate in let expected = invalid ( Nel . create ( Shape . Fail " height " ) ) and computed = Shape . make ( valid false ) ( invalid ( Nel . create ( Shape . Fail " radius " ) ) ) ( valid 2 ) ( invalid ( Nel . create ( Shape . Fail " height " ) ) ) in Alcotest . check Sh... |
let validation_shape_4 ( ) = let open Preface . Validate in let expected = invalid Nel . ( Shape . Fail " width " :: create ( Shape . Fail " height " ) ) and computed = Shape . make ( valid false ) ( invalid ( Nel . create ( Shape . Fail " radius " ) ) ) ( invalid ( Nel . create ( Shape . Fail " width " ) ) ) ( invalid... |
let cases = [ ( " Shape validation using Validate " , let open Alcotest in [ test_case " Simple validation of Circle " ` Quick validation_shape_1 ; test_case " Simple validation of Rectangle " ` Quick validation_shape_2 ; test_case " Simple validation of Rectangle with one failure " ` Quick validation_shape_3 ; test_ca... |
type drawable = < draw : unit > method virtual private contains : int -> int -> bool val mutable x : int = x method x = x val mutable y : int = y method y = y method on_click ? start ? stop f = on_click ? start ? stop ( fun ev -> if self # contains ev . mouse_x ev . mouse_y then f ev . mouse_x ev . mouse_y ) method on_... |
let pi = ( atan 1 . 0 ) . * 4 . 0 val virtual mutable updates : ( int -> unit ) list val virtual mutable x : int val virtual mutable y : int initializer let update step = let m = sin ( offset . + ( ( Float . of_int step ) . * ( pi . / 64 . ) ) ) in let x ' = Float . to_int ( m . * Float . of_int x ' ) in let y ' = Floa... |
let my_circle = object inherit circle 30 250 250 inherit animated ( Time . Span . minute ) inherit harmonic 0 . 0 10 0 inherit harmonic ( pi . / 2 . 0 ) 0 10 end |
let main ( ) = let shapes = [ ( my_circle :> drawable ) ; ( new my_square 50 350 :> drawable ) ; ( new my_square 50 200 :> drawable ) ; ( new growing_circle 20 70 70 :> drawable ) ; ] in let repaint ( ) = clear_graph ( ) ; List . iter ~ f ( : fun s -> s # draw ) shapes ; synchronize ( ) in open_graph " " ; auto_synchro... |
let ( ) = never_returns ( Scheduler . go_main ~ main ( ) ) |
let setup ( ) = let open Raylib in init_window width height " raylib [ shapes ] example - collision area " ; let box_a = Rectangle . create 10 . 0 ( Float . of_int ( ( get_screen_height ( ) / 2 ) - 50 ) ) 200 . 0 100 . 0 in let box_a_speed_x = 4 . 0 in let box_b = Rectangle . create ( Float . of_int ( ( get_screen_widt... |
let rec loop ( pause , box_a , box_a_speed_x , box_b , box_collision ) = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in ( if not pause then Rectangle . ( set_x box_a ( x box_a . + box_a_speed_x ) ) ) ; let box_a_speed_x = if Rectangle . ( x box_a . + width ... |
let ( ) = setup ( ) |> loop |
module type S0 = sig type key type value type z1 type z2 type z3 type z4 type z5 type z6 type z7 type z8 type z9 type z10 end |
module M0 = struct type key type value type z1 type z2 type z3 type z4 type z5 type z6 type z7 type z8 type z9 type z10 end |
module type S0 ' = sig include S0 type additional end |
module type S1 = ( S0 -> S0 ' ) -> S0 |
module M1 : S1 = functor ( P1 : S0 -> S0 ' ) -> P1 ( M0 ) |
module type S2 = ( S1 -> S0 ' ) -> S0 |
module M2 : S2 = functor ( P1 : S1 -> S0 ' ) -> P1 ( M1 ) |
module type S3 = ( S2 -> S0 ' ) -> S0 |
module M3 : S3 = functor ( P2 : S2 -> S0 ' ) -> P2 ( M2 ) |
module type S4 = ( S3 -> S0 ' ) -> S0 |
module M4 : S4 = functor ( P3 : S3 -> S0 ' ) -> P3 ( M3 ) |
module type S5 = ( S4 -> S0 ' ) -> S0 |
module M5 : S5 = functor ( P4 : S4 -> S0 ' ) -> P4 ( M4 ) |
module type S6 = ( S5 -> S0 ' ) -> S0 |
module M6 : S6 = functor ( P5 : S5 -> S0 ' ) -> P5 ( M5 ) |
module type S7 = ( S6 -> S0 ' ) -> S0 |
module M7 : S7 = functor ( P6 : S6 -> S0 ' ) -> P6 ( M6 ) |
let decompress src = let src ' = Bigstring . of_string src in let i = De . bigstring_create De . io_buffer_size in let o = De . bigstring_create De . io_buffer_size in let allocate bits = De . make_window ~ bits in let pos = ref 0 in let src_len = String . length src in let res = Buffer . create ( src_len ) in let refi... |
module Shard = struct type shard = { compress : bool ; id : int * int ; hb_interval : Time . Span . t Ivar . t ; hb_stopper : unit Ivar . t ; large_threshold : int ; pipe : Frame . t Pipe . Reader . t * Frame . t Pipe . Writer . t ; ready : unit Ivar . t ; seq : int ; session : string option ; url : string ; _internal ... |
type t = { shards : ( Shard . shard Shard . t ) list } |
let start ? count ? compress ? large_threshold ( ) = let module J = Yojson . Safe . Util in Http . get_gateway_bot ( ) >>= fun data -> let data = match data with | Ok d -> d | Error e -> Error . raise e in let url = J . ( member " url " data |> to_string ) in let count = match count with | Some c -> c | None -> J . ( m... |
let set_status ? status ? kind ? name ? since ? url sharder = Deferred . all @@ List . map ~ f ( : fun t -> Shard . set_status ? status ? kind ? name ? since ? url t . state ) sharder . shards |
let request_guild_members ? query ? limit ~ guild sharder = Deferred . all @@ List . map ~ f ( : fun t -> Shard . request_guild_members ~ guild ? query ? limit t . state ) sharder . shards |
let shutdown_all ? restart sharder = Deferred . all @@ List . map ~ f ( : fun t -> Shard . shutdown ~ clean : true ? restart t ) sharder . shards |
let shared dv l_env = let add x sort acc = match sort with | Sstatic | Sval -> acc | Svar _ | Smem _ -> S . add x acc in Env . fold ( fun x { t_sort = sort } acc -> add x sort acc ) l_env dv |
let remove_is_copy copies = Env . map ( fun ( x_copy , _ , ty ) -> ( x_copy , false , ty ) ) copies |
let add_equations_for_copies eq_list copies = Env . fold ( fun x ( x_copy , is_copy , ty ) acc -> if is_copy then ( eqmake ( EQeq ( varpat x ty , var x_copy ty ) ) ) :: acc else acc ) copies eq_list |
let add_locals_for_copies n_list n_env copies = let value ty = { t_sort = Deftypes . value ; t_typ = ty } in let n_env = Env . fold ( fun x ( x_copy , _ , ty ) acc -> Env . add x_copy ( value ty ) acc ) copies n_env in let n_copy_list = Env . fold ( fun _ ( x_copy , _ , ty ) acc -> ( Zaux . vardec_from_entry x_copy { t... |
let rec pattern dv copies pat = match pat . p_desc with | Ewildpat | Econstpat _ | Econstr0pat _ -> pat , copies | Etuplepat ( p_list ) -> let p_list , copies = Zmisc . map_fold ( pattern dv ) copies p_list in { pat with p_desc = Etuplepat ( p_list ) } , copies | Econstr1pat ( c , p_list ) -> let p_list , copies = Zmis... |
let rec equation dv copies ( { eq_desc = desc } as eq ) = match desc with | EQeq ( { p_desc = Evarpat ( n ) } , _ ) -> eq , copies | EQeq ( pat , e ) -> let pat , copies = pattern dv copies pat in { eq with eq_desc = EQeq ( pat , e ) } , copies | EQpluseq _ | EQder _ | EQinit _ -> eq , copies | EQmatch ( total , e , m_... |
let exp ( { e_desc = desc } as e ) = let desc = match desc with | Elet ( l , e_let ) -> Elet ( local l , e_let ) | _ -> desc in { e with e_desc = desc } |
let implementation impl = match impl . desc with | Eopen _ | Etypedecl _ | Econstdecl _ -> impl | Efundecl ( n , ( { f_body = e } as body ) ) -> { impl with desc = Efundecl ( n , { body with f_body = exp e } ) } |
let implementation_list impl_list = Zmisc . iter implementation impl_list |
type config = { global_size : int ; heap_size : int ; dep_table_pow : int ; hash_table_pow : int ; shm_dirs : string list ; shm_min_avail : int ; log_level : int ; } |
type handle = private { h_fd : Unix . file_descr ; h_global_size : int ; h_heap_size : int ; } |
let kind_of_int x = match x with | 0 -> ` ConstantK | 1 -> ` ClassK | 2 -> ` FuncK | _ when x < 0 -> failwith " kind_of_int : attempted to convert from negative int " | _ -> assert ( x > 0 ) ; failwith " kind_of_int : int too large , no corresponding kind " |
let ( ) = Callback . register_exception " out_of_shared_memory " Out_of_shared_memory ; Callback . register_exception " hash_table_full " Hash_table_full ; Callback . register_exception " dep_table_full " Dep_table_full ; Callback . register_exception " heap_full " Heap_full ; Callback . register_exception " revision_l... |
let anonymous_init config = hh_shared_init ~ config ~ shm_dir : None |
let rec shm_dir_init config = function | [ ] -> Hh_logger . log " We ' ve run out of filesystems to use for shared memory " ; raise Out_of_shared_memory | shm_dir :: shm_dirs -> let shm_min_avail = config . shm_min_avail in begin try if not ( Sys . file_exists shm_dir ) then raise ( Failed_to_use_shm_dir " shm_dir does... |
let init config = try anonymous_init config with Failed_anonymous_memfd_init -> EventLogger . ( log_if_initialized ( fun ( ) -> sharedmem_failed_anonymous_memfd_init ( ) ) ) ; if ! Utils . debug then Hh_logger . log " Failed to use anonymous memfd init " ; shm_dir_init config config . shm_dirs |
let loaded_dep_table_filename ( ) = let fn = loaded_dep_table_filename_c ( ) in if String . equal " " fn then None else Some fn |
let save_dep_table_sqlite : string -> string -> int = fun fn build_revision -> if ( loaded_dep_table_filename ( ) ) <> None then failwith " save_dep_table_sqlite not supported when server is loaded from a saved state " ; Hh_logger . log " Dumping a saved state deptable . " ; save_dep_table_sqlite_c fn build_revision |
let load_dep_table_sqlite : string -> bool -> int = fun fn ignore_hh_version -> load_dep_table_sqlite_c fn ignore_hh_version |
let save_table_sqlite filename = hh_save_table_sqlite filename " hh_save_table_keys_sqlite " |
let save_table_keys_sqlite filename keys = hh_save_table_keys_sqlite filename keys |
let load_table_sqlite filename verify = hh_load_table_sqlite filename verify |
let init_done ( ) = EventLogger . sharedmem_init_done ( heap_size ( ) ) |
type table_stats = { nonempty_slots : int ; used_slots : int ; slots : int ; } |
let dep_stats ( ) = let used = dep_used_slots ( ) in { nonempty_slots = used ; used_slots = used ; slots = dep_slots ( ) ; } |
let hash_stats ( ) = let used_slots , nonempty_slots = hash_used_slots ( ) in { nonempty_slots ; used_slots ; slots = hash_slots ( ) ; } |
let should_collect ( effort : [ ` gentle | ` aggressive | ` always_TEST ] ) = let overhead = match effort with | ` always_TEST -> 1 . 0 | ` aggressive -> 1 . 2 | ` gentle -> 2 . 0 in let used = heap_size ( ) in let wasted = wasted_heap_size ( ) in let reachable = used - wasted in used >= truncate ( ( float reachable ) ... |
let collect ( effort : [ ` gentle | ` aggressive | ` always_TEST ] ) = let old_size = heap_size ( ) in Stats . update_max_heap_size old_size ; let start_t = Unix . gettimeofday ( ) in if should_collect effort then hh_collect ( ) ; let new_size = heap_size ( ) in let time_taken = Unix . gettimeofday ( ) . - start_t in i... |
let is_heap_overflow ( ) = hh_check_heap_overflow ( ) |
module HeapSize = struct let rec traverse ( ( visited : ISet . t ) , acc ) r = if Obj . is_block r then begin let p : int = Obj . magic r in if ISet . mem p visited then ( visited , acc ) else begin let visited ' = ISet . add p visited in let n = Obj . size r in let acc ' = acc + 1 + n in if Obj . tag r < Obj . no_scan... |
module type Key = sig type userkey type t type old type md5 val make : Prefix . t -> userkey -> t val make_old : Prefix . t -> userkey -> old val to_old : t -> old val new_from_old : old -> t val md5 : t -> md5 val md5_old : old -> md5 val string_of_md5 : md5 -> string end |
module KeyFunctor ( UserKeyType : sig type t val to_string : t -> string end ) : Key with type userkey = UserKeyType . t = struct type userkey = UserKeyType . t type t = string type old = string type md5 = string let old_prefix = " old_ " let make prefix x = Prefix . make_key prefix ( UserKeyType . to_string x ) let ma... |
module Raw ( Key : Key ) ( Value : Value . Type ) : sig val add : Key . md5 -> Value . t -> unit val mem : Key . md5 -> bool val get : Key . md5 -> Value . t val remove : Key . md5 -> unit val move : Key . md5 -> Key . md5 -> unit module LocalChanges : sig val has_local_changes : unit -> bool val push_stack : unit -> u... |
module New : functor ( Key : Key ) -> functor ( Value : Value . Type ) -> sig val add : Key . t -> Value . t -> unit val get : Key . t -> Value . t option val find_unsafe : Key . t -> Value . t val remove : Key . t -> unit val mem : Key . t -> bool val oldify : Key . t -> unit module Raw : module type of Raw ( Key ) ( ... |
module Old : functor ( Key : Key ) -> functor ( Value : Value . Type ) -> functor ( Raw : module type of Raw ( Key ) ( Value ) ) -> sig val get : Key . old -> Value . t option val remove : Key . old -> unit val mem : Key . old -> bool val revive : Key . old -> unit end = functor ( Key : Key ) -> functor ( Value : Value... |
module type NoCache = sig type key type t module KeySet : Set . S with type elt = key module KeyMap : MyMap . S with type key = key val add : key -> t -> unit val get : key -> t option val get_old : key -> t option val get_old_batch : KeySet . t -> t option KeyMap . t val remove_old_batch : KeySet . t -> unit val find_... |
module type WithCache = sig include NoCache val write_through : key -> t -> unit val get_no_cache : key -> t option end |
module type UserKeyType = sig type t val to_string : t -> string val compare : t -> t -> int end |
module NoCache ( UserKeyType : UserKeyType ) ( Value : Value . Type ) = struct module Key = KeyFunctor ( UserKeyType ) module New = New ( Key ) ( Value ) module Old = Old ( Key ) ( Value ) ( New . Raw ) module KeySet = Set . Make ( UserKeyType ) module KeyMap = MyMap . Make ( UserKeyType ) type key = UserKeyType . t ty... |
module type ConfigType = sig type value val capacity : int end |
module type CacheType = sig type key type value val add : key -> value -> unit val get : key -> value option val remove : key -> unit val clear : unit -> unit val string_of_key : key -> string val get_size : unit -> int end |
module FreqCache ( Key : sig type t end ) ( Config : ConfigType ) : CacheType with type key := Key . t and type value := Config . value = struct type value = Config . value let string_of_key _key = failwith " FreqCache does not support ' string_of_key ' " let ( cache : ( Key . t , int ref * value ) Hashtbl . t ) = Hash... |
module OrderedCache ( Key : sig type t end ) ( Config : ConfigType ) : CacheType with type key := Key . t and type value := Config . value = struct let string_of_key _key = failwith " OrderedCache does not support ' string_of_key ' " let ( cache : ( Key . t , Config . value ) Hashtbl . t ) = Hashtbl . create Config . c... |
let invalidate_callback_list = ref [ ] |
let invalidate_caches ( ) = List . iter ! invalidate_callback_list ~ f : begin fun callback -> callback ( ) end |
module LocalCache ( UserKeyType : UserKeyType ) ( Value : Value . Type ) = struct type key = UserKeyType . t type value = Value . t module ConfValue = struct type value = Value . t let capacity = 1000 end module L1 = OrderedCache ( UserKeyType ) ( ConfValue ) module L2 = FreqCache ( UserKeyType ) ( ConfValue ) let stri... |
module WithCache ( UserKeyType : UserKeyType ) ( Value : Value . Type ) = struct module Direct = NoCache ( UserKeyType ) ( Value ) type key = Direct . key type t = Direct . t module KeySet = Direct . KeySet module KeyMap = Direct . KeyMap module Cache = LocalCache ( UserKeyType ) ( Value ) let string_of_key key = Direc... |
type config = { global_size : int ; heap_size : int ; dep_table_pow : int ; hash_table_pow : int ; shm_dirs : string list ; shm_min_avail : int ; log_level : int ; } |
type handle = private { h_fd : Unix . file_descr ; h_global_size : int ; h_heap_size : int ; } |
let kind_of_int x = match x with | 0 -> ` ConstantK | 1 -> ` ClassK | 2 -> ` FuncK | _ when x < 0 -> failwith " kind_of_int : attempted to convert from negative int " | _ -> assert ( x > 0 ) ; failwith " kind_of_int : int too large , no corresponding kind " |
let ( ) = Callback . register_exception " out_of_shared_memory " Out_of_shared_memory ; Callback . register_exception " hash_table_full " Hash_table_full ; Callback . register_exception " dep_table_full " Dep_table_full ; Callback . register_exception " heap_full " Heap_full ; Callback . register_exception " revision_l... |
let anonymous_init config = hh_shared_init ~ config ~ shm_dir : None |
let rec shm_dir_init config = function | [ ] -> Hh_logger . log " We ' ve run out of filesystems to use for shared memory " ; raise Out_of_shared_memory | shm_dir :: shm_dirs -> begin try if not ( Sys . file_exists shm_dir ) then raise ( Failed_to_use_shm_dir " shm_dir does not exist " ) ; hh_shared_init ~ config ~ shm... |
let init config = try anonymous_init config with Failed_anonymous_memfd_init -> if ! Utils . debug then Hh_logger . log " Failed to use anonymous memfd init " ; shm_dir_init config config . shm_dirs |
let loaded_dep_table_filename ( ) = let fn = loaded_dep_table_filename_c ( ) in if String . equal " " fn then None else Some fn |
let save_dep_table_sqlite : string -> string -> int = fun fn build_revision -> if ( loaded_dep_table_filename ( ) ) <> None then failwith " save_dep_table_sqlite not supported when server is loaded from a saved state " ; Hh_logger . log " Dumping a saved state deptable . " ; save_dep_table_sqlite_c fn build_revision |
let load_dep_table_sqlite : string -> bool -> int = fun fn ignore_hh_version -> load_dep_table_sqlite_c fn ignore_hh_version |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.