text
stringlengths
12
786k
module rec Print : sig val to_string : ' a Typ . typ -> ' a -> string let to_string ( type s ) t x = match t with | Int eq -> string_of_int ( TypEq . apply eq x ) | String eq -> Printf . sprintf " % S " ( TypEq . apply eq x ) | Pair p -> let module P = ( val p : PAIR with typ...
let ( ) = print_endline ( Print . to_string int 10 ) ; print_endline ( Print . to_string ( pair int ( pair str int ) ) ( 123 , ( " A " , 456 ) ) )
type t ' a = { count : int ; data : Lazy . t ( data ' a ) } [ Nil | Cons of ' a and t ' a | App of t ' a and t ' a ] ; loop 0 where rec loop i = { count = 0 ; data = lazy ( match f i with [ Some x -> Cons x ( loop ( i + 1 ) ) | None -> Nil ] ) } ; let...
let finally fct clean_f = let result = try fct ( ) ; with exn -> clean_f ( ) ; raise exn in clean_f ( ) ; result
let maybe d f v = match v with None -> d | Some x -> f x
let may f v = maybe None ( fun x -> Some ( f x ) ) v
let default d v = maybe d ( fun x -> x ) v
let maybe_unit f v = maybe ( ) f v
let const v = ( fun _ -> v )
let rec maybes_to_list l = match l with | [ ] -> [ ] | None :: xs -> maybes_to_list xs | ( Some x ) :: xs -> x :: maybes_to_list xs
type ( ' a , ' b ) either = Left of ' a | Right of ' b
let ( ) $ f a = f a
let id = ( fun x -> x )
let char_is_alphanum c = ( c >= ' a ' && c <= ' z ' ) || ( c >= ' A ' && c <= ' Z ' ) || ( c >= ' 0 ' && c <= ' 9 ' )
let string_index_pred p s = let len = String . length s in let i = ref 0 in while ! i < len && not ( p s . [ ! i ] ) do i := ! i + 1 done ; if ! i == len then ( raise Not_found ) else ! i
let rec string_split ? limit ( : limit ( =- 1 ) ) c s = let i = try String . index s c with Not_found -> - 1 in let nlimit = if limit = - 1 || limit = 0 then limit else limit - 1 in if i = - 1 || nlimit = 0 then [ s ] else let a = String . sub s 0 i and b = String . sub s ( ...
let rec string_split_pred ? limit ( : limit ( =- 1 ) ) p s = let i = try string_index_pred p s with Not_found -> - 1 in let nlimit = if limit = - 1 || limit = 0 then limit else limit - 1 in if i = - 1 || nlimit = 0 then [ s ] else let a = String . sub s 0 i and b = String . su...
let string_startswith prefix x = let x_l = String . length x and prefix_l = String . length prefix in prefix_l <= x_l && String . sub x 0 prefix_l = prefix
let string_endswith suffix x = Filename . check_suffix x suffix
let string_stripPredicate p str = let len = String . length str in let s = ref 0 in let e = ref ( String . length str ) in while ! s < len && p str . [ ! s ] do s := ! s + 1 done ; let start = ! s in while ! e > start && p str . [ ! e - 1 ] do e := ! e - 1 done ; String ...
let string_stripSpaces = string_stripPredicate ( fun c -> c = ' ' || c = ' \ t ' || c = ' \ n ' )
let string_splitAt pos s = let len = String . length s in if pos > len then invalid_arg " splitAt " else ( String . sub s 0 pos , String . sub s pos ( len - pos ) )
let string_take n s = let len = String . length s in if n > len then invalid_arg " String . take " else String . sub s 0 n
let string_drop n s = let len = String . length s in if n > len then invalid_arg " String . drop " else String . sub s n ( len - n )
let string_init n s = let len = String . length s in if n > len then invalid_arg " String . init " else String . sub s 0 ( len - n )
let string_all p s = let len = String . length s in let rec loop i = if i = len then true else ( if not ( p s . [ i ] ) then false else loop ( i + 1 ) ) in loop 0
let string_lines s = string_split ' \ n ' s
let string_words s = string_split_pred ( fun c -> c = ' ' || c = ' \ n ' || c = ' \ t ' ) s
let no_empty emptyVal = List . filter ( fun x -> x <> emptyVal )
let string_words_noempty s = no_empty " " ( string_words s )
let string_lines_noempty s = no_empty " " ( string_lines s )
let list_singleton = fun x -> [ x ]
let rec list_init l = match l with | [ ] -> failwith " init empty list " | [ _ ] -> [ ] | x :: xs -> x :: list_init xs
let rec list_last l = match l with | [ ] -> failwith " last is empty " | [ x ] -> x | _ :: xs -> list_last xs
let list_remove e list = List . filter ( fun x -> x <> e ) list
let list_iteri f list = let rec loop i l = match l with | [ ] -> ( ) | x :: xs -> f i x ; loop ( i + 1 ) xs in loop 1 list
let list_eq_noorder ( l1 : ' a list ) ( l2 : ' a list ) : bool = List . for_all ( fun z -> List . mem z l2 ) l1
let list_filter_map ( f : ' a -> ' b option ) ( l : ' a list ) : ' b list = let rec loop ( z : ' a list ) : ' b list = match z with | [ ] -> [ ] | x :: xs -> match f x with | None -> loop xs | Some y -> y :: loop xs in loop l
let list_mem_many needles haystack = let rec loop l = match l with | [ ] -> false | x :: xs -> if List . mem x needles then true else loop xs in loop haystack
let rec list_uniq l = match l with | [ ] -> [ ] | x :: xs -> if List . mem x xs then list_uniq xs else x :: list_uniq xs
let rec list_findmap p l = match l with | [ ] -> raise Not_found | x :: xs -> match p x with | Some z -> z | None -> list_findmap p xs
let hashtbl_map f h = let newh = Hashtbl . create ( Hashtbl . length h ) in Hashtbl . iter ( fun k v -> Hashtbl . add newh k ( f v ) ) h ; newh
let hashtbl_keys h = Hashtbl . fold ( fun k _ l -> k :: l ) h [ ]
let hashtbl_modify_one f k h = let v = Hashtbl . find h k in Hashtbl . replace h k ( f v )
let hashtbl_modify_all f h = let keys = hashtbl_keys h in List . iter ( fun k -> let v = Hashtbl . find h k in Hashtbl . replace h k ( f v ) ) keys
let hashtbl_fromList l = let h = Hashtbl . create ( List . length l ) in List . iter ( fun ( k , v ) -> Hashtbl . add h k v ) l ; h
let hashtbl_toList h = Hashtbl . fold ( fun k v l -> ( k , v ) :: l ) h [ ]
let first f ( a , b ) = ( f a , b )
let second f ( a , b ) = ( a , f b )
let user_int_of_string loc s = try int_of_string s with _ -> raise ( ConversionIntFailed ( loc , s ) )
let user_bool_of_string loc s = try bool_of_string s with _ -> raise ( ConversionBoolFailed ( loc , s ) )
module StringSet = struct include Set . Make ( struct type t = string let compare = Pervasives . compare end ) let to_list t = fold ( fun elt l -> elt :: l ) t [ ]
let to_struct a = ( a : ' a Raylib . ctyp :> ' a Ctypes . structure )
let to_struct_ptr a = Ctypes . ( !@ ) a |> to_struct |> Ctypes . addr
let set_font fnt = _set_font @@ to_struct fnt
let get_font ( ) = Raylib . to_ctyp @@ _get_font ( )
let window_box bx = _window_box @@ to_struct bx
let group_box bx = _group_box @@ to_struct bx
let line bx = _line @@ to_struct bx
let panel bx = _panel @@ to_struct bx
let scroll_panel a b c = _scroll_panel ( to_struct a ) ( to_struct b ) ( to_struct_ptr c ) |> Raylib . to_ctyp
let label bx = _label @@ to_struct bx
let button bx = _button @@ to_struct bx
let label_button bx = _label_button @@ to_struct bx
let toggle rct = _toggle @@ to_struct rct
let toggle_group rct = _toggle_group @@ to_struct rct
let check_box rct = _check_box @@ to_struct rct
let combo_box rct = _combo_box @@ to_struct rct
let dropdown_box rct labels vl edit = let vl_ptr = Raylib . ptr_of_int vl in let rt = _dropdown_box ( to_struct rct ) labels vl_ptr edit in ( Ctypes . ( !@ vl_ptr ) , rt )
let spinner rct label vl ~ min ~ max edit = let vl_ptr = Raylib . ptr_of_int vl in let rt = _spinner ( to_struct rct ) label vl_ptr min max edit in ( Ctypes . ( !@ vl_ptr ) , rt )
let value_box rct label vl ~ min ~ max edit = let vl_ptr = Raylib . ptr_of_int vl in let rt = _value_box ( to_struct rct ) label vl_ptr min max edit in ( Ctypes . ( !@ vl_ptr ) , rt )
let text_box rct txt state = let open Ctypes in let str_arr = CArray . of_string txt in let rt = _text_box ( to_struct rct ) ( CArray . start str_arr ) ( CArray . length str_arr + 1 ) state in ( String . init ( CArray . length str_arr ) ( CArray . unsafe_get str_arr ) , rt )
let text_box_multi rct txt state = let open Ctypes in let str_arr = CArray . of_string txt in let rt = _text_box_multi ( to_struct rct ) ( CArray . start str_arr ) ( CArray . length str_arr + 1 ) state in ( String . init ( CArray . length str_arr ) ( CArray . unsafe_get str_arr ) ...
let slider rct label txt value ~ min ~ max = _slider ( to_struct rct ) label txt value min max
let slider_bar rct label txt value ~ min ~ max = _slider_bar ( to_struct rct ) label txt value min max
let progress_bar rct label txt value ~ min ~ max = _progress_bar ( to_struct rct ) label txt value min max
let status_bar rct = _status_bar @@ to_struct rct
let dummy_rec rct = _dummy_rec @@ to_struct rct
let scroll_bar rct value ~ min ~ max = _scroll_bar ( to_struct rct ) value min max
let grid rct b c = _grid ( to_struct rct ) b c |> Raylib . to_ctyp
let list_view rct label index active = let vl_ptr = Raylib . ptr_of_int index in let rt = _list_view ( to_struct rct ) label vl_ptr active in ( rt , Ctypes . ( !@ vl_ptr ) )
let list_view_ex rct strings focus index active = let open Ctypes in let str_arr = CArray . of_list Ctypes . string strings in let focus_ptr = Raylib . ptr_of_int focus in let index_ptr = Raylib . ptr_of_int index in let active = _list_view_ex ( to_struct rct ) ( CArray . start str_arr ) ( Lis...
let message_box rct = _message_box @@ to_struct rct
let text_input_box rct title message buttons text = let open Ctypes in let str_arr = CArray . of_string text in let rt = _text_input_box ( to_struct rct ) title message buttons ( CArray . start str_arr ) in ( String . init ( CArray . length str_arr ) ( CArray . unsafe_get str_arr ) , r...
let color_picker rct col = _color_picker ( to_struct rct ) ( to_struct col ) |> Raylib . to_ctyp
let color_panel rct col = _color_panel ( to_struct rct ) ( to_struct col ) |> Raylib . to_ctyp
let color_bar_alpha rct = _color_bar_alpha @@ to_struct rct
let color_bar_hue rct = _color_bar_hue @@ to_struct rct
type t = { funs : Code_id . t Function_slot . Map . t ; in_order : Code_id . t Function_slot . Lmap . t }
let empty = { funs = Function_slot . Map . empty ; in_order = Function_slot . Lmap . empty }
let is_empty { funs ; _ } = Function_slot . Map . is_empty funs
let create in_order = { funs = Function_slot . Map . of_list ( Function_slot . Lmap . bindings in_order ) ; in_order }
let funs t = t . funs
let funs_in_order t = t . in_order
let find ( { funs ; _ } : t ) function_slot = Function_slot . Map . find function_slot funs
let [ @ ocamlformat " disable " ] print ppf { in_order ; _ } = Format . fprintf ppf " [ @< hov 1 ( >% a ) ] " @ ( Function_slot . Lmap . print Code_id . print ) in_order
let free_names { funs ; _ } = Function_slot . Map . fold ( fun function_slot code_id syms -> Name_occurrences . add_code_id ( Name_occurrences . add_function_slot_in_declaration syms function_slot Name_mode . normal ) code_id Name_mode . normal ) funs Name_occurrences . empty
let apply_renaming ( { in_order ; _ } as t ) perm = let in_order ' = Function_slot . Lmap . map_sharing ( fun code_id -> Renaming . apply_code_id perm code_id ) in_order in if in_order == in_order ' then t else create in_order '
let all_ids_for_export { funs ; _ } = Function_slot . Map . fold ( fun _function_slot code_id ids -> Ids_for_export . add_code_id ids code_id ) funs Ids_for_export . empty
let compare { funs = funs1 ; _ } { funs = funs2 ; _ } = Function_slot . Map . compare Code_id . compare funs1 funs2