text
stringlengths
12
786k
let map_fst f ( x , y ) = ( f x , y )
let map_snd f ( x , y ) = ( x , f y )
let map_tuple f1 f2 ( x , y ) = ( f1 x , f2 y )
let map_tuple3 f1 f2 f3 ( x , y , z ) = ( f1 x , f2 y , f3 z )
let map_opt f = function None -> None | Some x -> Some ( f x )
let map_loc sub { loc ; txt } = { loc = sub . location sub loc ; txt }
module C = struct let map sub c = match c with | Pconst_integer _ | Pconst_char _ | Pconst_float _ -> c | Pconst_string ( s , loc , quotation_delimiter ) -> let loc = sub . location sub loc in Const . string ~ loc ? quotation_delimiter s end
module T = struct let row_field sub { prf_desc ; prf_loc ; prf_attributes ; } = let loc = sub . location sub prf_loc in let attrs = sub . attributes sub prf_attributes in let desc = match prf_desc with | Rtag ( l , b , tl ) -> Rtag ( map_loc sub l , b , List . map ( sub . typ su...
module CT = struct let map sub { pcty_loc = loc ; pcty_desc = desc ; pcty_attributes = attrs } = let open Cty in let loc = sub . location sub loc in let attrs = sub . attributes sub attrs in match desc with | Pcty_constr ( lid , tys ) -> constr ~ loc ~ attrs ( map_loc sub lid ) ( List...
let map_functor_param sub = function | Unit -> Unit | Named ( s , mt ) -> Named ( map_loc sub s , sub . module_type sub mt )
module MT = struct let map sub { pmty_desc = desc ; pmty_loc = loc ; pmty_attributes = attrs } = let open Mty in let loc = sub . location sub loc in let attrs = sub . attributes sub attrs in match desc with | Pmty_ident s -> ident ~ loc ~ attrs ( map_loc sub s ) | Pmty_alias s -> alias ~ l...
module M = struct let map sub { pmod_loc = loc ; pmod_desc = desc ; pmod_attributes = attrs } = let open Mod in let loc = sub . location sub loc in let attrs = sub . attributes sub attrs in match desc with | Pmod_ident x -> ident ~ loc ~ attrs ( map_loc sub x ) | Pmod_structure str -> struc...
module E = struct let map sub { pexp_loc = loc ; pexp_desc = desc ; pexp_attributes = attrs } = let open Exp in let loc = sub . location sub loc in let attrs = sub . attributes sub attrs in match desc with | Pexp_ident x -> ident ~ loc ~ attrs ( map_loc sub x ) | Pexp_constant x -> constant...
module P = struct let map sub { ppat_desc = desc ; ppat_loc = loc ; ppat_attributes = attrs } = let open Pat in let loc = sub . location sub loc in let attrs = sub . attributes sub attrs in match desc with | Ppat_any -> any ~ loc ~ attrs ( ) | Ppat_var s -> var ~ loc ~ attrs ( map_loc s...
module CE = struct let map sub { pcl_loc = loc ; pcl_desc = desc ; pcl_attributes = attrs } = let open Cl in let loc = sub . location sub loc in let attrs = sub . attributes sub attrs in match desc with | Pcl_constr ( lid , tys ) -> constr ~ loc ~ attrs ( map_loc sub lid ) ( List . ...
let default_mapper = { constant = C . map ; structure = ( fun this l -> List . map ( this . structure_item this ) l ) ; structure_item = M . map_structure_item ; module_expr = M . map ; signature = ( fun this l -> List . map ( this . signature_item this ) l ) ; signatur...
let extension_of_error { kind ; main ; sub } = if kind <> Location . Report_error then raise ( Invalid_argument " extension_of_error : expected kind Report_error " ) ; let str_of_pp pp_msg = Format . asprintf " % t " pp_msg in let extension_of_sub sub = { loc = sub . loc ; txt = ...
let attribute_of_warning loc s = Attr . mk { loc ; txt = " ocaml . ppwarning " } ( PStr ( [ Str . eval ~ loc ( Exp . constant ( Pconst_string ( s , loc , None ) ) ) ] ) )
let cookies = ref String . Map . empty
let get_cookie k = try Some ( String . Map . find k ! cookies ) with Not_found -> None
let set_cookie k v = cookies := String . Map . add k v ! cookies
let tool_name_ref = ref " _none_ "
let tool_name ( ) = ! tool_name_ref
module PpxContext = struct open Longident open Asttypes open Ast_helper let lid name = { txt = Lident name ; loc = Location . none } let make_string s = Exp . constant ( Const . string s ) let make_bool x = if x then Exp . construct ( lid " true " ) None else Exp . construct ( lid " ...
let extension_of_exn exn = match error_of_exn exn with | Some ( ` Ok error ) -> extension_of_error error | Some ` Already_displayed -> { loc = Location . none ; txt = " ocaml . error " } , PStr [ ] | None -> raise exn
let apply_lazy ~ source ~ target mapper = let implem ast = let fields , ast = match ast with | { pstr_desc = Pstr_attribute ( { attr_name = { txt = " ocaml . ppx . context " } ; attr_payload = x } ) } :: l -> PpxContext . get_fields x , l | _ -> [ ] , ast in PpxConte...
let drop_ppx_context_str ~ restore = function | { pstr_desc = Pstr_attribute { attr_name = { Location . txt = " ocaml . ppx . context " } ; attr_payload = a ; attr_loc = _ } } :: items -> if restore then PpxContext . restore ( PpxContext . get_fields a ) ; items | items ...
let drop_ppx_context_sig ~ restore = function | { psig_desc = Psig_attribute { attr_name = { Location . txt = " ocaml . ppx . context " } ; attr_payload = a ; attr_loc = _ } } :: items -> if restore then PpxContext . restore ( PpxContext . get_fields a ) ; items | items ...
let add_ppx_context_str ~ tool_name ast = Ast_helper . Str . attribute ( ppx_context ~ tool_name ( ) ) :: ast
let add_ppx_context_sig ~ tool_name ast = Ast_helper . Sig . attribute ( ppx_context ~ tool_name ( ) ) :: ast
let apply ~ source ~ target mapper = apply_lazy ~ source ~ target ( fun ( ) -> mapper )
let run_main mapper = try let a = Sys . argv in let n = Array . length a in if n > 2 then let mapper ( ) = try mapper ( Array . to_list ( Array . sub a 1 ( n - 3 ) ) ) with exn -> let f _ _ = raise exn in { default_mapper with structure = f ; signature = f } in apply_lazy ~...
let register_function = ref ( fun _name f -> run_main f )
let register name f = ! register_function name f
let output_line ch s = output_string ch s ; output_char ch ' \ n '
let ( ) = if Array . length Sys . argv <> 2 then failwith ( " usage : " ^ Sys . argv . ( 0 ) " ^ file_t . mli " ) ; let input_file_name = Sys . argv . ( 1 ) in let ouput_file_name = if Filename . check_suffix input_file_name " . mli " then ( Filename . chop_...
type error = | Multiple_attributes of string | No_payload_expected of string
let get_no_payload_attribute alt_names attrs = match List . filter ( fun a -> List . mem a . attr_name . txt alt_names ) attrs with | [ ] -> None | [ { attr_name = name ; attr_payload = PStr [ ] ; attr_loc = _ } ] -> Some name | [ { attr_name = name ; _ } ] -> rai...
let has_no_payload_attribute alt_names attrs = match get_no_payload_attribute alt_names attrs with | None -> false | Some _ -> true
let report_error ppf = function | Multiple_attributes name -> fprintf ppf " Too many ` % s ' attributes " name | No_payload_expected name -> fprintf ppf " Attribute ` % s ' does not accept a payload " name
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer ~ loc report_error err ) | _ -> None )
let position = Raylib . Vector3 . create 0 . 0 0 . 0 0 . 0
type circle_wave = { position : Raylib . Vector2 . t ; radius : float ; alpha : float ; speed : float ; color : Raylib . Color . t ; }
let colors = Raylib . [ | Color . orange ; Color . red ; Color . gold ; Color . lime ; Color . blue ; Color . violet ; Color . brown ; Color . lightgray ; Color . pink ; Color . yellow ; Color . green ; Color . skyblue ; Color . purple ; Color . beige ; ] ...
let random_circle ( ) = Raylib . ( let radius = get_random_value 10 40 in { alpha = 0 . 0 ; radius = Float . of_int radius ; position = Vector2 . create ( Float . of_int ( get_random_value radius ( width - radius ) ) ) ( Float . of_int ( get_random_value radius ( heig...
let setup ( ) = let open Raylib in set_config_flags [ ConfigFlags . Msaa_4x_hint ] ; init_window width height " raylib [ audio ] example - module playing ( streaming ) " ; init_audio_device ( ) ; let circles = Array . init max_circles ( fun _ -> random_circle ( ) ) in let ...
let rec loop circles music pause = match Raylib . window_should_close ( ) with | true -> let open Raylib in unload_music_stream music ; close_audio_device ( ) ; close_window ( ) | false -> let open Raylib in update_music_stream music ; if is_key_pressed Key . Space then ( stop_music_stream ...
let ( ) = let circles , music = setup ( ) in loop circles music false
let setup ( ) = let open Raylib in init_window width height " raylib [ audio ] example - music playing ( streaming ) " ; init_audio_device ( ) ; let music = load_music_stream " resources / country . mp3 " in play_music_stream music ; set_target_fps 60 ; music
let rec loop music pause = let open Raylib in match window_should_close ( ) with | true -> unload_music_stream music ; close_audio_device ( ) ; close_window ( ) | false -> update_music_stream music ; if is_key_pressed Key . Space then ( stop_music_stream music ; play_music_stream music ) ...
let ( ) = let music = setup ( ) in loop music false
module Definition = struct type t = | Existing_inner_free_var of Variable . t | Projection_from_existing_specialised_arg of Projection . t include Identifiable . Make ( struct type nonrec t = t let compare t1 t2 = match t1 , t2 with | Existing_inner_free_var var1 , Existing_inner_free_var var2 -> Va...
module What_to_specialise = struct type t = { definitions : Definition . t list Variable . Pair . Map . t ; set_of_closures : Flambda . set_of_closures ; make_direct_call_surrogates_for : Variable . Set . t ; } let create ~ set_of_closures = { definitions = Variable . Pair . Map . ...
module type S = sig val pass_name : string val what_to_specialise : env : Inline_and_simplify_aux . Env . t -> set_of_closures : Flambda . set_of_closures -> What_to_specialise . t end
module Processed_what_to_specialise = struct type for_one_function = { fun_var : Variable . t ; function_decl : Flambda . function_declaration ; make_direct_call_surrogates : bool ; new_definitions_indexed_by_new_inner_vars : Definition . t Variable . Map . t ; all_new_definitions : Definitio...
let check_invariants ~ pass_name ( ~ set_of_closures : Flambda . set_of_closures ) ~ original_set_of_closures = if ! Clflags . flambda_invariant_checks then begin Variable . Map . iter ( fun fun_var ( function_decl : Flambda . function_declaration ) -> let params = Parameter . Set . var...
module Make ( T : S ) = struct let ( ) = Pass_wrapper . register ~ pass_name : T . pass_name let rename_function_and_parameters ~ fun_var ( ~ function_decl : Flambda . function_declaration ) = let new_fun_var = Variable . rename fun_var in let params_renaming_list = List . map ( fun p...
let avail_at_exit = Hashtbl . create 42
let avail_at_raise = ref RAS . Unreachable
let augment_availability_at_raise avail = avail_at_raise := RAS . inter avail ! avail_at_raise
let check_invariants ( instr : M . instruction ) ( ~ avail_before : RAS . t ) = match avail_before with | Unreachable -> ( ) | Ok avail_before -> if not ( R . Set . subset instr . live ( RD . Set . forget_debug_info avail_before ) ) then begin Misc . fatal_errorf " Live reg...
let rec available_regs ( instr : M . instruction ) ( ~ avail_before : RAS . t ) : RAS . t = check_invariants instr ~ avail_before ; instr . available_before <- avail_before ; let avail_across , avail_after = let ok set = RAS . Ok set in let unreachable = RAS . Unreachable in match av...
let fundecl ( f : M . fundecl ) = if ! Clflags . debug && ! Clflags . debug_runavail then begin assert ( Hashtbl . length avail_at_exit = 0 ) ; avail_at_raise := RAS . Unreachable ; let fun_args = R . set_of_array f . fun_args in let avail_before = RAS . Ok ( RD . Set . witho...
type ' a ref = { mutable contents : ' a } [ @@ noalloc ] = " caml_blit_bytes " [ @@ noalloc ] = " caml_blit_string " [ @@ noalloc ]
let extend s left right = let invalid_arg s = raise ( Invalid_argument s ) in let ( ++ ) a b = match a < 0 , b < 0 with true , true -> 42 | _ -> invalid_arg " foo " in let x = s ++ left ++ right in if left < 0 then 0 else x
let unix = B0_ocaml . libname " unix "
let compiler_libs_toplevel = B0_ocaml . libname " compiler - libs . toplevel "
let rresult = B0_ocaml . libname " rresult "
let rresult_top = B0_ocaml . libname " rresult . top "
let astring = B0_ocaml . libname " astring "
let astring_top = B0_ocaml . libname " astring . top "
let fpath = B0_ocaml . libname " fpath "
let fpath_top = B0_ocaml . libname " fpath . top "
let fmt = B0_ocaml . libname " fmt "
let fmt_top = B0_ocaml . libname " fmt . tty "
let fmt_tty = B0_ocaml . libname " fmt . tty "
let logs = B0_ocaml . libname " logs "
let logs_fmt = B0_ocaml . libname " logs . fmt "
let logs_top = B0_ocaml . libname " logs . top "
let mtime = B0_ocaml . libname " mtime "
let mtime_clock_os = B0_ocaml . libname " mtime . clock . os "
let bos = B0_ocaml . libname " bos "
let bos_setup = B0_ocaml . libname " bos . setup "
let bos_top = B0_ocaml . libname " bos . top "
let bos_lib = let srcs = Fpath . [ ` Dir ( v " src " ) ; ` X ( v " src / bos_setup . ml " ) ; ` X ( v " src / bos_setup . mli " ) ; ` X ( v " src / bos_top . ml " ) ; ` X ( v " src / bos_top_init . ml " ) ] in let requires = [ astring ; ...
let bos_setup_lib = let srcs = Fpath . [ ` File ( v " src / bos_setup . ml " ) ; ` File ( v " src / bos_setup . mli " ) ] in let requires = [ rresult ; fmt_tty ; logs_fmt ; astring ; fpath ; logs ; fmt ; bos ] in B0_ocaml . lib bos_setup ~ doc " : The bos . ...
let bos_top_lib = let srcs = Fpath . [ ` File ( v " src / bos_top . ml " ) ] in let requires = [ rresult_top ; astring_top ; fpath_top ; fmt_top ; logs_top ; compiler_libs_toplevel ] in B0_ocaml . lib bos_top ~ doc " : The bos . top library " ~ srcs ~ requires
let test = let srcs = Fpath . [ ` File ( v " test / testing . mli " ) ; ` File ( v " test / testing . ml " ) ; ` File ( v " test / test . ml " ) ; ` File ( v " test / test_cmd . ml " ) ; ` File ( v " test / test_os_cmd . ml " ) ; ` File ...
let test_arg = let srcs = Fpath . [ ` File ( v " test / test_arg . ml " ) ] in let meta = B0_meta . ( empty |> tag test ) in let requires = [ astring ; fmt ; fpath ; logs_fmt ; bos ] in B0_ocaml . exe " test - arg " ~ doc " : Test argument parsing " ~ srcs ~ meta...
let test_arg_pos = let srcs = Fpath . [ ` File ( v " test / test_arg_pos . ml " ) ] in let meta = B0_meta . ( empty |> tag test ) in let requires = [ fmt ; logs_fmt ; bos ] in B0_ocaml . exe " test - arg - pos " ~ doc " : Test argument parsing " ~ srcs ~ meta ~ req...
let watch = let srcs = Fpath . [ ` File ( v " test / watch . ml " ) ] in let meta = B0_meta . ( empty |> tag test ) in let requires = [ logs_fmt ; fmt_tty ; mtime ; mtime_clock_os ; rresult ; fpath ; bos ; bos_setup ] in B0_ocaml . exe " watch " ~ doc " : Watch ...
let default = let meta = let open B0_meta in empty |> add authors [ " The bos programmers " ] |> add maintainers [ " Daniel Bünzli < daniel . buenzl i @ erratique . ch " ] > |> add homepage " https :// erratique . ch / software / bos " |> add online_doc " https :// erratique . ...
module Provenance = struct type t = { module_path : Path . t ; location : Debuginfo . t ; original_ident : Ident . t ; } let print ppf { module_path ; location ; original_ident ; } = let printf fmt = Format . fprintf ppf fmt in printf " [ @< hov 1 ( " ; > printf " [ ...
module With_provenance = struct type t = | Without_provenance of backend_var | With_provenance of { var : backend_var ; provenance : Provenance . t ; } let create ? provenance var = match provenance with | None -> Without_provenance var | Some provenance -> With_provenance { var ; provenance ;...
let test_Error msg = let rec f msg n = if n = 0 then raise ( Error msg ) else 1 + f msg ( n - 1 ) in let exception_raised_internally ( ) = try Hashtbl . find ( Hashtbl . create 3 ) 0 with Not_found -> false in try f msg 5 with Error " a " -> print_string " a " ; print_newline...
let test_Not_found ( ) = let rec aux n = if n = 0 then raise Not_found else 1 + aux ( n - 1 ) in try aux 5 with exn -> print_string " test_Not_found " ; print_newline ( ) ; ( try Hashtbl . find ( Hashtbl . create 3 ) 0 with Not_found -> raise exn )
let test_lazy = let rec aux n = if n = 0 then raise Not_found else 1 + aux ( n - 1 ) in let exception_raised_internally ( ) = try Hashtbl . find ( Hashtbl . create 3 ) 0 with Not_found -> ( ) in let l = lazy ( aux 5 ) in fun ( ) -> exception_raised_internally ( ) ; Lazy ...
let run g args = try ignore ( g args . ( 0 ) ) ; print_string " No exception \ n " with exn -> Printf . printf " Uncaught exception % s \ n " ( Printexc . to_string exn ) ; Printexc . print_backtrace stdout
let _ = run test_Error [ | " a " ] ; | run test_Error [ | " b " ] ; | run test_Error [ | " c " ] ; | run test_Error [ | " d " ] ; | run test_Error [ | " e " ] ; | run test_Error [ | " f " ] ; | run test_Error [ | ] ; | run test_Not_found ...
let rec f msg n = if n = 0 then raise ( Error msg ) else 1 + f msg ( n - 1 )