text stringlengths 12 786k |
|---|
let rec watch last_timestamp path ~ f = Unix . sleep 1 ; match has_changed last_timestamp path with | None -> watch last_timestamp path ~ f | Some new_timestamp -> printf " some changes were observed ( timestamp % f ) . Rebuilding . . . \ n " %! new_timestamp ; ( try f ( ) with so... |
let main path ~ f = let last_timestamp = highest_timestamp path in watch last_timestamp path ~ f |
let src = Logs . Src . create " sesame . watch " ~ doc " : Current sesame file watcer " |
module Log = ( val Logs . src_log src : Logs . LOG ) |
type t = ( Fpath . t , string list ) Hashtbl . t |
let create ( ) = Hashtbl . create 256 |
let record ~ path ~ job_id watcher = Hashtbl . replace watcher ( Fpath . normalize path ) job_id |
let get_job_id x = let open Current . Syntax in let + md = Current . Analysis . metadata x in match md with Some { Current . Metadata . job_id ; _ } -> job_id | None -> None |
let job_id ~ path watcher = Hashtbl . find_opt watcher ( Fpath . normalize path ) |
module FS = struct open Lwt . Infix type t = { f : unit -> unit Lwt . t ; cond : unit Lwt_condition . t ; unwatch : unit -> unit Lwt . t ; } let run_job ~ watcher ~ engine ~ dir path = let path = Fpath . ( v dir // path ) in Hashtbl . iter ( fun k _ -> print_endline ( Fpath ... |
module Js = struct let script ~ port = Fmt . str { |< script > var socket = new WebSocket ( ' ws :// localhost :% i / websocket ' ) ; socket . onopen = function ( ) { socket . send ( " Reload Me Please " ) ; ! } ; socket . onmessage = function ( e ) { window . ... |
module Raw = struct module Response = struct type t = | Ok of Yojson . Safe . t | EndOfStream | Error of string end module Connection = struct type t = { send : Yojson . Safe . t -> unit Lwt . t ; receive : unit -> Response . t Lwt . t ; shutdown : unit -> unit Lwt . t ; } let se... |
module Filter = struct type t = { base_names : string list ; whole_names : string list ; suffixes : string list ; } [ @@ deriving sexp , compare , hash ] let from_server_configurations ~ critical_files ~ extensions ~ source_paths ( ) = let base_name_of = function | CriticalFile . Bas... |
module Subscriber = struct module Setting = struct type t = { raw : Raw . t ; root : PyrePath . t ; filter : Filter . t ; } end type t = { setting : Setting . t ; connection : Raw . Connection . t ; initial_clock : string ; } let send_request ~ connection request = let open L... |
module SinceQuery = struct module Since = struct module SavedState = struct type t = { storage : string ; project_name : string ; project_metadata : string option ; } [ @@ deriving sexp , compare , hash ] let watchman_expression_of { storage ; project_name ; project_metadata } = let s... |
let test_low_level_apis _ = let open Lwt . Infix in let open Watchman . Raw in let test_connection connection = let assert_member_exists ~ key json = match Yojson . Safe . Util . member key json with | ` Null -> let message = Format . sprintf " Failed to find required JSON member : % s " key... |
let test_subscription _ = let open Lwt . Infix in let root = PyrePath . create_absolute " / fake / root " in let version_name = " fake_watchman_version " in let subscription_name = " my_subscription " in let initial_clock = " fake : clock : 0 " in let initial_success_response = ` Assoc... |
let test_filter_expression context = let assert_expression ~ expected filter = let actual = Watchman . Filter . watchman_expression_of filter in assert_equal ~ ctxt : context ~ cmp : Yojson . Safe . equal ~ printer : Yojson . Safe . pretty_to_string expected actual in assert_expression { Watchma... |
let test_filter_creation context = let assert_filter ~ expected : { Watchman . Filter . base_names = expected_base_names ; whole_names = expected_whole_names ; suffixes = expected_suffixes ; } { Watchman . Filter . base_names = actual_base_names ; whole_names = actual_whole_names ; suffi... |
let test_since_query_request context = let open Watchman . SinceQuery in let root = PyrePath . create_absolute " / fake / root " in let filter = { Watchman . Filter . base_names = [ " . pyre_configuration " ] ; whole_names = [ ] ; suffixes = [ " . py " ] } in let asse... |
let test_since_query_response context = let open Watchman . SinceQuery in let assert_response ~ expected response = let actual = Response . of_watchman_response response in assert_equal ~ ctxt : context ~ cmp [ :% compare . equal : Response . t option ] ~ printer ( : fun response -> [ % sex... |
let test_since_query _ = let open Lwt . Infix in let mock_raw = let send _ = Lwt . return_unit in let receive ( ) = Lwt . return_none in Watchman . Raw . create_for_testing ~ send ~ receive ( ) in Lwt . catch ( fun ( ) -> Watchman . Raw . with_connection mock_raw ~ f ( : fun c... |
let ( ) = " watchman_test " >::: [ " low_level " >:: OUnitLwt . lwt_wrapper test_low_level_apis ; " subscription " >:: OUnitLwt . lwt_wrapper test_subscription ; " filter_expression " >:: test_filter_expression ; " filter_creation " >:: test_filter_creation ; " since_query_... |
let uri = ref " http :// 127 . 0 . 0 . 1 " / |
let username = ref " root " |
let password = ref " password " |
let start = ref 0 |
let interval = ref 5 |
let exn_to_string = function | Api_errors . Server_error ( code , params ) -> Printf . sprintf " % s % s " code ( String . concat " " params ) | e -> Printexc . to_string e |
let main ( ) = let rpc = make ! uri in Session . login_with_password ~ rpc ~ uname :! username ~ pwd :! password ~ version " : 1 . 0 " ~ originator " : watch_metrics " >>= fun session_id -> Lwt . finalize ( fun ( ) -> Host . get_all ~ rpc ~ session_id >>= fun hosts -> let ... |
let _ = Arg . parse [ " - uri " , Arg . Set_string uri , ( Printf . sprintf " URI of server to connect to ( default % s ) " ! uri ) ; " - u " , Arg . Set_string username , ( Printf . sprintf " Username to log in with ( default % s ) " ! username ) ; " -... |
type watch = { name : string ; embed_path : string ; thumbnail_path : string ; description : string option ; published_at : string ; updated_at : string ; language : string ; category : string ; } |
type t = { watch : watch list } |
let get_publish_date json = match Ezjsonm . find json [ " originallyPublishedAt " ] with | ` Null -> ( match Ezjsonm . find json [ " publishedAt " ] with | ` String s -> s | _ -> failwith " Couldn ' t calculate the videos published date ) " | ` String s -> s | _ -> failwith... |
let get_update_date json = match Ezjsonm . find_opt json [ " updatedAt " ] with | Some ( ` String s ) s -> s | _ -> failwith " Couldn ' t find the video ' s updatedAt date " |
let get_language_category json = let label = Ezjsonm . find json [ " label " ] in Ezjsonm . get_string label |
let get_string_or_none = function ` String s -> Some s | _ -> None |
let of_json json = { name = Ezjsonm . find json [ " name " ] |> Ezjsonm . get_string ; description = Ezjsonm . find json [ " description " ] |> get_string_or_none ; embed_path = Ezjsonm . find json [ " embedPath " ] |> Ezjsonm . get_string ; thumbnail_path = Ezjsonm . find... |
let watch_to_yaml t = ` O ( [ ( " name " , ` String t . name ) name ] @ ( match t . description with | Some s -> [ ( " description " , ` String s ) s ] | None -> [ ] ) @ [ ( " embed_path " , ` String t . embed_path ) embed_path ; ( " thumbnail_path "... |
let to_yaml t = ` O [ ( " watch " , ` A ( List . map watch_to_yaml t . watch ) watch ) watch ] |
let videos_url = Uri . of_string " https :// watch . ocaml . org / api / v1 / videos " |
let get_videos ? start ( ) = let query_params = match start with | None -> [ ( " count " , [ string_of_int max_count_per_request ] ) ] | Some s -> [ ( " start " , [ string_of_int s ] ) ; ( " count " , [ string_of_int max_count_per_request ] ) ; ] in let * resp... |
let get_all_videos ( ) = let get_videos_or_err results = try Ok ( List . map ( function Ok v -> v | Error err -> failwith ( Error . to_string err ) err ) err results ) results with Failure m -> Error ( ` Msg m ) m in let * total , first = get_videos ( ) in let + rest = if total... |
let run ( ) = match Lwt_main . run @@ get_all_videos ( ) with | Ok v -> v | Error err -> Fmt . epr " % s " ( Error . to_string err ) err ; exit 1 |
let ( ) = let watch = run ( ) |> List . stable_sort ( fun w1 w2 -> String . compare w1 . name w2 . name ) name in let videos = { watch } in let yaml = to_yaml videos in Yaml . pp Format . std_formatter yaml |
let is_a_source_file path = ( match Path . extension path with | " . flv " | " . gif " | " . ico " | " . jpeg " | " . jpg " | " . mov " | " . mp3 " | " . mp4 " | " . otf " | " . pdf " | " . png " | " . ttf " | " . woff " ->... |
let subst_string s path ~ map = let len = String . length s in let longest_var = String . longest ( String . Map . keys map ) in let double_percent_len = String . length " " %% in let loc_of_offset ~ ofs ~ len = let rec loop lnum bol i = if i = ofs then let pos = { Lexing . pos_fname ... |
let subst_file path ~ map = let s = Io . read_file path in let s = if Path . is_root ( Path . parent_exn path ) && Package . is_opam_file path then " version : " " \%% ^ " VERSION_NUM " ^ " " %%\\ n " ^ s else s in match subst_string s ~ map path with | None -> ( ) | Some ... |
module Dune_project = struct include Dune_project type ' a simple_field = { loc : Loc . t ; loc_of_arg : Loc . t ; arg : ' a } type t = { contents : string ; name : Package . Name . t simple_field option ; version : string simple_field option ; project : Dune_project . t } let ... |
let make_watermark_map ~ commit ~ version ~ dune_project ~ info = let dune_project = Dune_project . project dune_project in let version_num = let open Option . O in let + version = version in Option . value ~ default : version ( String . drop_prefix version ~ prefix " : v " ) in let name =... |
let subst vcs = let + ( version , commit ) , files = Memo . run ( Memo . fork_and_join ( fun ( ) -> Memo . fork_and_join ( fun ( ) -> Vcs . describe vcs ) ( fun ( ) -> Vcs . commit_id vcs ) ) ( fun ( ) -> Vcs . files vcs ) ) in let dune_project : Dune_proj... |
let subst ( ) = match Sys . readdir " . " |> Array . to_list |> String . Set . of_list |> Vcs . Kind . of_dir_contents with | None -> Fiber . return ( ) | Some kind -> subst { kind ; root = Path . root } |
type exarray = { mutable len : int ; mutable data : t array ; } |
let make ( ) = { len = 0 ; data = [ ] ; || } |
let extend t = let len = Array . length t . data in t . data <- Array . init ( len + n ) ( fun i -> if i < len then t . data . ( i ) else empty ) |
let rec set a i v = if i >= Array . length a . data then begin extend a ; set a i v end else begin a . data . ( i ) <- v ; a . len <- max a . len ( i + 1 ) end |
let get a i = a . data . ( i ) |
let length a = a . len |
let data a = a . data |
type wave = { name : string ; nbits : int ; data : exarray ; } |
type waves = wave array |
let wrap sim = let ports p = List . map ( fun s -> { name = fst s ; nbits = B . width ( ! snd s ) ; data = make ( ) ; } ) p in let in_ports = ports sim . sim_in_ports in let out_ports = ports sim . sim_out_ports in let trace i x = List . iter2 ( fun a b -> set a . data i (... |
module Gui = struct module D = Dom_html let jstr = Js . string let jstri x = jstr ( string_of_int x ) let line ( ~ ctx : D . canvasRenderingContext2D Js . t ) ~ x0 ~ y0 ~ x1 ~ y1 = let f = float_of_int in ctx ( ## moveTo ( f x0 ) ( f y0 ) ) ; ctx ( ## lineTo ( f x1 ) ( ... |
type buffer = { data : Buffer . t ; mutable index : int ; size : int } |
let get ( buffer : buffer ) : char = let c = Buffer . nth buffer . data buffer . index in buffer . index <- buffer . index + 1 ; c |
let get_int ( buffer : buffer ) : int32 = Int32 . of_int ( Char . code ( get buffer ) ) |
let shift_or ( b1 : int32 ) ( b2 : int32 ) : int32 = Int32 . logor ( Int32 . shift_left b2 8 ) b1 |
let read2 ( buffer : buffer ) : int32 = let b1 = get_int buffer in let b2 = get_int buffer in shift_or b1 b2 |
let read3 ( buffer : buffer ) : int32 = let b1 = get_int buffer in let b2 = get_int buffer in let b3 = get_int buffer in b3 |> shift_or b2 |> shift_or b1 |
let read4 ( buffer : buffer ) : int32 = let b1 = get_int buffer in let b2 = get_int buffer in let b3 = get_int buffer in let b4 = get_int buffer in b4 |> shift_or b3 |> shift_or b2 |> shift_or b1 |
let read4_chars ( buffer : buffer ) : string = let c1 = get buffer in let c2 = get buffer in let c3 = get buffer in let c4 = get buffer in let result = Bytes . create 4 in Bytes . set result 0 c1 ; Bytes . set result 1 c2 ; Bytes . set result 2 c3 ; Bytes . set result 3 c4 ; Bytes . ... |
let searchData ( buffer : buffer ) : bool = let rec skipData n = if n = 0 then ( ) else let _ = get buffer in skipData ( n - 1 ) in let rec loop ( ) = if read4_chars buffer = " data " then true else let size = read4 buffer |> Int32 . to_int in let ( ) = skipData size in loop ( ... |
let max_16 = ( 2 . 0 ** 16 . 0 ) . / 2 . 0 |
let sign_16 = Int32 . shift_left Int32 . one 15 |
let mask_16 = Int32 . shift_left Int32 . minus_one 15 |
let readSample16 ( buffer : buffer ) : float = let v = read2 buffer in if Int32 . logand sign_16 v <> Int32 . zero then Int32 . to_float ( Int32 . logor mask_16 v ) . / max_16 else Int32 . to_float v . / max_16 |
let max_24 = ( 2 . 0 ** 24 . 0 ) . / 2 . 0 |
let sign_24 = Int32 . shift_left Int32 . one 23 |
let mask_24 = Int32 . shift_left Int32 . minus_one 23 |
let readSample24 ( buffer : buffer ) : float = let v = read2 buffer in if Int32 . logand sign_24 v <> Int32 . zero then Int32 . to_float ( Int32 . logor mask_24 v ) . / max_24 else Int32 . to_float v . / max_24 |
let getReadSampleFunction ( bits : int32 ) : ( buffer -> float , string ) result = match Int32 . to_int bits with | 16 -> Ok readSample16 | 24 -> Ok readSample24 | _ -> Error ( " Wave file encoded in an unsupported bits per sample : " ^ string_of_int ( Int32 . to_int bits ) ) |
let readSamples ( buffer : buffer ) ( channels : int ) ( size : int ) ( data : float array array ) ( read_fn : buffer -> float ) : int = let rec loop_channels index channel = if channel >= channels then true else try let value = read_fn buffer in let channel_data = data . ( channel )... |
let checkFormat ( buffer : buffer ) = if not ( read4_chars buffer = " RIFF " ) then Error " Not a valid file " else let chunk_size = read4 buffer in if chunk_size < Int32 . of_int 4 then Error " Invalid chunk size " else if not ( read4_chars buffer = " WAVE " ) then Error " Not a ... |
type wave = { channels : int ; samples : int ; data : float array array } |
let read ( file : string ) : ( wave , string ) result = match FileIO . read_bytes file with | None -> Error " failed to open the file " | Some data -> let buffer = { index = 0 ; size = Buffer . length data ; data } in ( match checkFormat buffer with | Error _ as error -> error ... |
let callback fn = object inherit [ _ ] Wayland_client . Wl_callback . v1 method on_done ~ callback_data = fn callback_data end |
let chars = ref 0 |
type state = Inside_word | Outside_word |
let count_channel in_channel = let rec count status = let c = input_char in_channel in incr chars ; match c with ' \ n ' -> incr lines ; count Outside_word | ' ' | ' \ t ' -> count Outside_word | _ -> if status = Outside_word then begin incr words ; ( ) end ; count Inside_word in tr... |
let count_file name = let ic = open_in name in count_channel ic ; close_in ic |
let print_result ( ) = print_int ! chars ; print_string " characters , " ; print_int ! words ; print_string " words , " ; print_int ! lines ; print_string " lines " ; print_newline ( ) |
let count name = count_file name ; print_result ( ) |
let _ = try if Array . length Sys . argv <= 1 then count_channel stdin else for i = 1 to Array . length Sys . argv - 1 do count_file Sys . argv . ( i ) done ; print_result ( ) print_string " I / O error : " ; print_string s ; print_newline ( ) |
type structured_code = { functions : func_block IMap . t ; } and func_block = { scope : cfg_scope ; block : block ; } and block = { loop_label : int option ; instructions : instruction array ; break_label : int option ; } and instruction = | Block of block | Label of int | Simple ... |
type trap_info = | Trap_push of int * int option | Trap_pop of int * int |
type try_info = | Try_entry of int | Try_exit |
type cfg_node = { cfg_scope : cfg_scope ; cfg_node_label : int ; cfg_try : try_info option ; cfg_trap : trap_info option ; mutable cfg_loops : int list ; cfg_succ : int list ; cfg_length : int ; cfg_final : I . instruction option ; cfg_next_main : int option ; } |
type cfg = { mutable nodes : cfg_node IMap . t ; mutable code : I . instruction array ; mutable labels : ISet . t ; } |
let string_of_scope s = sprintf " [ letrec =% s , func =% d , try =% s ] " ( match s . cfg_letrec_label with | None -> " none " | Some l -> string_of_int l ) s . cfg_func_label ( List . map string_of_int s . cfg_try_labels |> String . concat " , " ) |
let detect_loops ctx = let visited = ref ISet . empty in let trails = ref IMap . empty in let rec recurse exectrail label = let node = try IMap . find label ctx . nodes with Not_found -> assert false in if not ( ISet . mem label ! visited ) then ( visited := ISet . add label ! visited ; tra... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.