text stringlengths 0 601k |
|---|
let exp x = let e = exp x . re in { re = e . * cos x . im ; im = e . * sin x . im } |
let log x = { re = log ( norm x ) ; im = atan2 x . im x . re } |
let pow x y = exp ( mul y ( log x ) ) |
let init_path ( ? dir " " ) = ( ) = let dirs = if ! Clflags . use_threads then " + threads " :: ! Clflags . include_dirs else ! Clflags . include_dirs in let dirs = ! Compenv . last_include_dirs @ dirs @ Config . flexdll_dirs @ ! Compenv . first_include_dirs in let exp_dirs = List . map ( Misc . expand_directory Config... |
let initial_env ( ) = Ident . reinit ( ) ; Types . Uid . reinit ( ) ; let initially_opened_module = if ! Clflags . nopervasives then None else Some " Stdlib " in Typemod . initial_env ~ loc ( : Location . in_file " command line " ) ~ safe_string ( : Config . safe_string || not ! Clflags . unsafe_string ) ~ initially_op... |
let set_from_env flag Clflags . { parse ; usage ; env_var } = try match parse ( Sys . getenv env_var ) with | None -> Location . prerr_warning Location . none ( Warnings . Bad_env_variable ( env_var , usage ) ) | Some x -> match ! flag with | None -> flag := Some x | Some _ -> ( ) with Not_found -> ( ) |
let read_clflags_from_env ( ) = set_from_env Clflags . color Clflags . color_reader ; set_from_env Clflags . error_style Clflags . error_style_reader ; ( ) |
let with_ppf_dump ~ file_prefix f = let ppf_dump , finally = if not ! Clflags . dump_into_file then Format . err_formatter , ignore else let ch = open_out ( file_prefix ^ " . dump " ) in let ppf = Format . formatter_of_out_channel ch in ppf , ( fun ( ) -> Format . pp_print_flush ppf ( ) ; close_out ch ) in Misc . try_f... |
let kernel_max ( ( spoc_var0 : ( ( ' a , ' b ) Vector . vector ) ) , ( spoc_var1 : ( ' c , ' d ) Vector . vector ) , ( spoc_var2 : int ) ) = Kernel . exec [ | Kernel . VFloat64 spoc_var0 ; Kernel . VFloat64 spoc_var1 ; Kernel . Int32 spoc_var2 ] | object ( self ) inherit [ ( ( float , Bigarray . float64_elt ) Vector . ... |
let spoc_max = new class_kernel_max object ( self ) inherit [ ' a , ' b ] Kernel . spoc_kernel " " " " method exec = failwith " dummy kernel " method args_to_list = failwith " dummy kernel " method list_to_args = failwith " dummy kernel " end |
let spoc_dummy_kernel = new class_dummy_kernel |
type application = object val env : ' a method env : unit -> ' a Devices . device list -> ( ' f , ' g ) Vector . vector -> ( ( ' d , ' e ) Vector . vector as ' c ) end val env = env ; method ker ( ) = ker ; method kind ( ) = ( kind : application ) method env ( ) = env fun ? queue_id ( : q = 0 ) device -> fun inp -> in ... |
let transfer_if_vector a device queue = | Kernel . VFloat32 v -> Mem . to_device v ~ queue_id : queue device ; val env = skeleton1 # env ( ) val ker = ( skeleton1 # ker ( ) :> ( ' a , ' b ) Kernel . spoc_kernel ) method env ( ) = env method kind ( ) = kind method ker ( ) = ker method run : ' e ' f ' g ' i ' j . ? queue... |
let run ( c : ( ' a , ' b , ' c ) # skeleton ) = c # run |
let par_run ( c : ( ' a , ' b , ' c ) # skeleton ) = c # par_run |
let pipe ( skeleton1 : ( ' a , ' b , ' c ) # skeleton ) ( skeleton2 : ( ' d , ' e , ' f ) # skeleton ) = new pipe skeleton1 skeleton2 |
let map ker out env = new map ker out env |
let reduce reduction k = new reduce reduction k |
module Make ( S : Compute_ranges_intf . S_functor ) = struct module Subrange_state = S . Subrange_state module Subrange_info = S . Subrange_info module Range_info = S . Range_info let rewrite_label env label = match Numbers . Int . Map . find label env with | exception Not_found -> label | label -> label module Subrang... |
module type S_subrange_state = sig type t val create : unit -> t val advance_over_instruction : t -> L . instruction -> t end |
module type S_subrange_info = sig type t type key type subrange_state val create : key -> subrange_state -> t end |
module type S_range_info = sig type t type key type index val create : L . fundecl -> key -> start_insn : L . instruction -> ( index * t ) option end |
module type S_functor = sig module Index : Identifiable . S module Key : sig type t module Set : sig include Set . S with type elt = t val print : Format . formatter -> t -> unit end module Map : Map . S with type key = t val print : Format . formatter -> t -> unit val all_parents : t -> t list end module Range_info : ... |
module type S = sig module Index : Identifiable . S module Key : sig type t module Set : Set . S with type elt = t module Map : Map . S with type key = t end module Subrange_state : S_subrange_state module Subrange_info : S_subrange_info with type key := Key . t with type subrange_state := Subrange_state . t module Ran... |
module P = struct value gloc bp strm = Grammar . loc_of_token_interval bp ( Stream . count strm ) ; value list0 symb = let rec loop al = parser [ [ : a = symb ; s ] : -> loop [ a :: al ] s | [ : ] : -> al ] in parser [ : a = loop [ ] ] : -> List . rev a ; value list0sep symb sep = let rec kont al = parser [ [ : v = sep... |
let get_conflist = function | ` List obj -> obj | _ -> raise ( WrongFormat " must contain a list of confs " ) |
let unwrap_assoc = function | ` Assoc lst -> lst | _ -> raise ( WrongFormat " conf must be a valid JSON object " ) |
let parse_cmds cmds args = let mapper = function | ` String cmd -> cmd | _ -> raise ( WrongFormat " invalid cmd arg " ) in if List . length cmds > 0 then raise ( WrongFormat " duplicated cmds " ) else List . map mapper args |
let get_cmds cmds = if List . length cmds = 0 then raise ( WrongFormat " cmds not given " ) else cmds |
let cmdopt name = function | None -> raise ( WrongFormat ( name " ^ not given " ) ) | Some arg -> arg |
let construct_conf id cmds filearg mratio_s mratio_e seed_file = let cmds = get_cmds cmds |> to_abs_cmds in let prog = List . hd cmds in let filearg = cmdopt " filearg " filearg in let mratio_s = cmdopt " mratiostart " mratio_s in let mratio_e = try cmdopt " mratioend " mratio_e with _ -> mratio_s in let seed_file = cm... |
let parse_conf json id = let assoc = unwrap_assoc json in let rec parse_loop cmds filearg ratio_s ratio_e seedfile = function | ( " cmds " , ` List args ) :: tl -> parse_loop ( parse_cmds cmds args ) filearg ratio_s ratio_e seedfile tl | ( " filearg " , ` Int idx ) :: tl -> parse_loop cmds ( Some idx ) ratio_s ratio_e ... |
let parse_json json = let per_conf acc obj = let conf = parse_conf obj ( List . length acc ) in conf :: acc in let lst = get_conflist json in List . fold_left per_conf [ ] lst |
let parse file = if not ( Sys . file_exists file ) then raise Not_found else ( ) ; let ch = open_in file in let json = from_channel ch in close_in ch ; parse_json json |
type function_settings = { function_name : string ; memory_size : int ; version : string ; log_stream : string ; log_group : string } |
module Env_vars = struct let runtime_endpoint_var = " AWS_LAMBDA_RUNTIME_API " let lambda_function_name = " AWS_LAMBDA_FUNCTION_NAME " let lambda_function_version = " AWS_LAMBDA_FUNCTION_VERSION " let lambda_function_memory_size = " AWS_LAMBDA_FUNCTION_MEMORY_SIZE " let lambda_log_stream_name = " AWS_LAMBDA_LOG_STREAM_... |
let env = let env_lst = Array . to_list ( Unix . environment ( ) ) in List . fold_left ( fun m var -> match String . split_on_char ' ' = var with | k :: v :: _ -> StringMap . add k v m | _ -> m ) StringMap . empty env_lst |
let get_runtime_api_endpoint ( ) = let var = Env_vars . runtime_endpoint_var in match StringMap . find_opt var env with | Some v -> Ok v | None -> Error ( Printf . sprintf " Could not find runtime API env var : % s " var ) |
let get_function_settings ( ? env = env ) ( ) = let get_env_vars ( ) = let function_name = StringMap . find_opt Env_vars . lambda_function_name env in let version = StringMap . find_opt Env_vars . lambda_function_version env in let memory_str = StringMap . find_opt Env_vars . lambda_function_memory_size env in let log_... |
let acknowledge_config config = List . iter ( fun ( _ , config ) -> List . iter Param_tags . acknowledge config . plus_tags ) config |
let cache = Hashtbl . create 107 |
let ( configs , add_config ) = let configs = ref [ ] in ( fun ( ) -> ! configs ) , ( fun config -> acknowledge_config config ; configs := config :: ! configs ; Hashtbl . clear cache ) |
let parse_string s = let conf = Lexers . conf_lines None 1 ( Printf . sprintf " string : % S " s ) ( Lexing . from_string s ) in add_config conf |
let parse_file ? dir file = try with_input_file file begin fun ic -> let conf = Lexers . conf_lines dir 1 ( Printf . sprintf " file : % S " file ) ( Lexing . from_channel ic ) in add_config conf end with Lexers . Error msg -> raise ( Lexers . Error ( file ^ " : " ^ msg ) ) |
let apply_config s ( config : t ) init = List . fold_left begin fun tags ( key , v ) -> if key_match key s then List . fold_right Tags . add v . plus_tags ( List . fold_right Tags . remove v . minus_tags tags ) else tags end init config |
let apply_configs s = List . fold_right ( apply_config s ) ( configs ( ) ) Tags . empty |
let tags_of_filename s = try Hashtbl . find cache s with Not_found -> let res = apply_configs s in let ( ) = Hashtbl . replace cache s res in res |
let has_tag tag = Tags . mem tag ( tags_of_filename " " ) |
let tag_file file tags = if tags <> [ ] then parse_string ( Printf . sprintf " % S : % s " file ( String . concat " , " tags ) ) ; ; |
let tag_any tags = if tags <> [ ] then parse_string ( Printf . sprintf " true : % s " ( String . concat " , " tags ) ) ; ; |
type flag_action = SetFlag of string | ClearFlag of string |
let getDigestKV ( ) = let digest = Project . digest ( ) in [ ( " obuild - digest " , digest ) ] |
let generateMlFile project file flags = Utils . generateFile file ( fun add -> add " \ n " ; add ( sprintf " let project_name = " \% s " \\ n " project . Analyze . project_file . Project . name ) ; add ( sprintf " let project_version = " \% s " \\ n " project . Analyze . project_file . Project . version ) ; List . iter... |
let generateCFile project file flags = Utils . generateFile file ( fun add -> add " /* autogenerated file by obuild . do not modify */\ n " ; add ( sprintf " # define PROJECT_NAME " \% s " \\ n " project . Analyze . project_file . Project . name ) ; add ( sprintf " # define PROJECT_VERSION " \% s " \\ n " project . Ana... |
let makeSetup digestKV project flags = hashtbl_fromList ( digestKV @ hashtbl_toList project . Analyze . project_ocamlcfg @ List . map ( fun ( opt , v ) -> ( opt , string_of_bool v ) ) ( Gconf . get_target_options ( ) ) @ List . map ( fun ( flagname , flagval ) -> ( " flag " - ^ flagname , string_of_bool flagval ) ) fla... |
let sanityCheck ( ) = let ( _ : string ) = Prog . getOcamlOpt ( ) in let ( _ : string ) = Prog . getOcamlC ( ) in let ( _ : string ) = Prog . getOcamlDep ( ) in ( ) |
let comparekvs reason setup l = List . iter ( fun ( k , v ) -> try let v ' = Hashtbl . find setup k in if v ' <> v then raise ( ConfigChanged reason ) with Not_found -> raise ( ConfigChanged reason ) ) l |
let comparekvs_hashtbl reason setup l = Hashtbl . iter ( fun k v -> try let v ' = Hashtbl . find setup k in if v ' <> v then raise ( ConfigChanged reason ) with Not_found -> raise ( ConfigChanged reason ) ) l |
let execute_configure_script proj_file = match proj_file . Project . configure_script with | None -> ( ) | Some script -> let args = [ ( Prog . getOcaml ( ) ) ; ( fp_to_string script ) ] in ( match Process . run args with | Process . Success ( _ , warnings , _ ) -> print_warnings warnings | Process . Failure er -> rais... |
let create_dist project flags = verbose Verbose " configuration changed , deleting dist \ n " ; %! Filesystem . removeDirContent ( Dist . build_path ) ; Dist . remove_dead_links ( ) ; verbose Verbose " auto - generating configuration files \ n " ; %! let autogenDir = Dist . create_build Dist . Autogen in generateMlFile... |
let get_assoc name assoc = try let v = List . assoc name assoc in Some v with Not_found -> None |
let get_flags_value proj_file setup_flags user_flags = List . map ( fun flag -> let name = flag . Project . Flag . name in let def = flag . Project . Flag . default in let override = ref ( get_assoc name setup_flags ) in List . iter ( fun tw -> match tw with | ClearFlag s -> if s = name then override := Some false | Se... |
let check_extra_tools proj_file = let syspath = Utils . get_system_paths ( ) in List . iter ( fun tool -> try let _ = Utils . find_in_paths syspath tool in ( ) with Utils . FileNotFoundInPaths _ -> raise ( ToolNotFound tool ) ) proj_file . Project . extra_tools |
let get_flags hash = Hashtbl . fold ( fun k v acc -> if string_startswith " flag " - k then ( string_drop 5 k , bool_of_string v ) :: acc else acc ) hash [ ] |
let bool_of_opt hashtable k = let get_opt k = try Hashtbl . find hashtable k with Not_found -> raise ( ConfigurationMissingKey k ) in let v = get_opt k in try bool_of_string v with Failure _ -> raise ( ConfigurationTypeMismatch ( k , " bool " , v ) ) |
let set_opts hashtable = let opts = Gconf . get_target_options_keys ( ) in List . iter ( fun k -> Gconf . set_target_options k ( bool_of_opt hashtable k ) ) opts |
let check_ocaml ( ) = let ocamlCfg = Prog . getOcamlConfig ( ) in let ocaml_ver = Hashtbl . find ocamlCfg " version " in let ver = string_split ' . ' ocaml_ver in ( match ver with | major :: minor :: _ -> ( if int_of_string major < 4 then gconf . bin_annot <- false ; if int_of_string major > 4 && int_of_string minor > ... |
let run proj_file user_flags user_opts = Dist . create_maybe ( ) ; let _ = check_ocaml ( ) in let digestKV = getDigestKV ( ) in execute_configure_script proj_file ; let configure = try Some ( Dist . read_configure ( ) ) with _ -> None in let configure_flags = match configure with | None -> [ ] | Some h -> Hashtbl . ite... |
let check proj_file reconf setup = let ocamlCfg = check_ocaml ( ) in let digestKV = getDigestKV ( ) in comparekvs_hashtbl " ocaml config " setup ocamlCfg ; let reconfigure = try comparekvs " digest " setup digestKV ; false with e -> if reconf then true else raise e in let setup_flags = get_flags setup in let flags = ge... |
let set_endpoint_env_var ( ) = let open Config in Unix . putenv Env_vars . runtime_endpoint_var " localhost : 8080 " ; ( ) |
let set_lambda_env_vars ( ) = let open Config in Unix . putenv Env_vars . lambda_function_name " test_func " ; Unix . putenv Env_vars . lambda_function_version " $ LATEST " ; Unix . putenv Env_vars . lambda_function_memory_size " 128 " ; Unix . putenv Env_vars . lambda_log_stream_name " LogStreamName " ; Unix . putenv ... |
let unset_env_vars ( ) = let open Config in Unix . putenv Env_vars . runtime_endpoint_var " " ; Unix . putenv Env_vars . lambda_function_name " " ; Unix . putenv Env_vars . lambda_function_version " " ; Unix . putenv Env_vars . lambda_function_memory_size " " ; Unix . putenv Env_vars . lambda_log_stream_name " " ; Unix... |
let get_env ( ) = let env_lst = Array . to_list ( Unix . environment ( ) ) in List . fold_left ( fun m var -> match String . split_on_char ' ' = var with | k :: v :: _ -> StringMap . add k v m | _ -> m ) StringMap . empty env_lst |
let setup_and_run f ( ) = unset_env_vars ( ) ; set_endpoint_env_var ( ) ; set_lambda_env_vars ( ) ; f ( ) |
let suite = [ ( " config from env vars " , ` Quick , setup_and_run @@ fun ( ) -> match Config . get_function_settings ~ env ( : get_env ( ) ) ( ) with | Ok env_settings -> Alcotest . ( check int " memory size read from env " 128 env_settings . Config . memory_size ) | Error e -> Alcotest . fail e ) ; ( " errors when va... |
type t = ( string , Digest . t * string ) Hashtbl . t |
let create ( ) = Hashtbl . create 13 |
let check tbl name crc source = try let ( old_crc , old_source ) = Hashtbl . find tbl name in if crc <> old_crc then raise ( Inconsistency ( name , source , old_source ) ) with Not_found -> Hashtbl . add tbl name ( crc , source ) |
let check_noadd tbl name crc source = try let ( old_crc , old_source ) = Hashtbl . find tbl name in if crc <> old_crc then raise ( Inconsistency ( name , source , old_source ) ) with Not_found -> raise ( Not_available name ) |
let set tbl name crc source = Hashtbl . add tbl name ( crc , source ) |
let source tbl name = snd ( Hashtbl . find tbl name ) |
let extract tbl = Hashtbl . fold ( fun name ( crc , auth ) accu -> ( name , crc ) :: accu ) tbl [ ] |
let filter p tbl = let to_remove = ref [ ] in Hashtbl . iter ( fun name ( crc , auth ) -> if not ( p name ) then to_remove := name :: ! to_remove ) tbl ; List . iter ( fun name -> while Hashtbl . mem tbl name do Hashtbl . remove tbl name done ) ! to_remove |
module Id = struct let name = " Camlp4Parsers . LoadCamlp4Ast " let version = Sys . ocaml_version end |
module Make ( Ast : Camlp4 . Sig . Camlp4Ast . S ) = struct module Ast = Ast open Ast let _loc = Loc . ghost let parse_implem ? directive_handler ( : _ ) _ _ = let e = Ast . ExApp ( _loc , Ast . ExApp ( _loc , Ast . ExId ( _loc , Ast . IdAcc ( _loc , Ast . IdUid ( _loc , " G " ) , Ast . IdLid ( _loc , " extend " ) ) ) ... |
let module M = Camlp4 . Register . OCamlParser ( Id ) ( Make ) in ( ) |
let char_zero = Char . to_int ' 0 ' |
let char_a = Char . to_int ' a ' |
let char_A = Char . to_int ' A ' |
module Signedness = struct type t = | Signed | Unsigned [ @@ deriving sexp_of ] end |
module Raw = struct let of_bytes bytes ~ width = init_byte ~ width ~ f ( : fun i -> try Bytes . get bytes i with | _ -> ' \ 000 ' ) ; ; let of_string string ~ width = init_byte ~ width ~ f ( : fun i -> try string . [ i ] with | _ -> ' \ 000 ' ) ; ; let to_bytes ( t : t ) = let len = ( width t + 7 ) / 8 in Bytes . subo ... |
let rec rsplit_into_n ~ n string = let len = String . length string in if len <= n then [ string ] else String . drop_prefix string ( len - n ) :: rsplit_into_n ~ n ( String . drop_suffix string n ) ; ; |
let int_of_hex_char c = match c with | ' 0 ' . . ' 9 ' -> Char . to_int c - char_zero | ' a ' . . ' f ' -> Char . to_int c - char_a + 10 | ' A ' . . ' F ' -> Char . to_int c - char_A + 10 | _ -> raise_s [ % message " Invalid hex char " ~ _ ( : c : char ) ] ; ; |
let hex_char_of_int i = if i >= 0 && i <= 9 then Char . of_int_exn ( i + char_zero ) else if i >= 10 && i <= 15 then Char . of_int_exn ( i - 10 + char_a ) else raise_s [ % message " Cannot convert int to hex char " ~ int_value ( : i : int ) ] ; ; |
let to_hum x = rsplit_into_n ~ n : 4 x |> List . rev |> String . concat ~ sep " : _ " |
let to_binary_string t = let width = width t in String . init width ~ f ( : fun j -> let j = width - j - 1 in let byte = j lsr 3 in let bit = j land 7 in let char = unsafe_get_byte t byte |> Char . to_int in let bit = ( char land ( 1 lsl bit ) ) lsr bit in Char . of_int_exn ( bit + char_zero ) ) ; ; |
let to_binary_string_hum t = to_binary_string t |> to_hum |
let to_int64 t = unsafe_get_int64 t 0 |
let to_int t = Int64 . to_int_trunc ( to_int64 t ) |
let to_int32 t = Int64 . to_int32_trunc ( to_int64 t ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.