text stringlengths 0 601k |
|---|
let rec convert_to_block_obj ( lst : obj_coord list ) ( context : Dom_html . canvasRenderingContext2D Js . t ) : collidable list = match lst with [ ] | -> [ ] | h :: t -> let sblock_typ = choose_sblock_typ ( fst h ) in let ob = Object . spawn ( SBlock sblock_typ ) context ( snd h ) in [ ob ] ( @ convert_to_block_obj t ... |
let rec convert_to_enemy_obj ( lst : obj_coord list ) ( context : Dom_html . canvasRenderingContext2D Js . t ) : collidable list = match lst with [ ] | -> [ ] | h :: t -> let senemy_typ = choose_enemy_typ ( fst h ) in let ob = Object . spawn ( SEnemy senemy_typ ) context ( snd h ) in [ ob ] ( @ convert_to_enemy_obj t c... |
let rec convert_to_coin_obj ( lst : obj_coord list ) ( context : Dom_html . canvasRenderingContext2D Js . t ) : collidable list = match lst with [ ] | -> [ ] | h :: t -> let sitem_typ = Coin in let ob = Object . spawn ( SItem sitem_typ ) context ( snd h ) in [ ob ] ( @ convert_to_coin_obj t context ) |
let generate_helper ( blockw : float ) ( blockh : float ) ( cx : float ) ( cy : float ) ( context : Dom_html . canvasRenderingContext2D Js . t ) : collidable list = let block_locs = generate_block_locs blockw blockh 0 . 0 . [ ] in let converted_block_locs = trim_edges ( convert_list block_locs ) blockw blockh in let ob... |
let generate ( w : float ) ( h : float ) ( context : Dom_html . canvasRenderingContext2D Js . t ) : ( collidable * collidable list ) = let blockw = w . / 16 . in let blockh = ( h . / 16 . ) . - 1 . in let collide_list = generate_helper blockw blockh 0 . 0 . context in let player = Object . spawn ( SPlayer ( SmallM , St... |
let init ( ) = Random . self_init ( ) ; |
module Public = struct module Ping = struct let v1 = Decl . Request . make_current_gen ~ req : Conv . unit ~ resp : Conv . unit ~ version : 1 let decl = Decl . Request . make ~ method_ " : ping " ~ generations [ : v1 ] end module Diagnostics = struct let v1 = Decl . Request . make_current_gen ~ req : Conv . unit ~ resp... |
module Server_side = struct module Abort = struct let v1 = Decl . Notification . make_current_gen ~ conv : Message . sexp ~ version : 1 let decl = Decl . Notification . make ~ method_ " : notify / abort " ~ generations [ : v1 ] end module Log = struct let v1 = Decl . Notification . make_current_gen ~ conv : Message . s... |
module Poll = struct let cancel_gen = Decl . Notification . make_current_gen ~ conv : Id . sexp ~ version : 1 module Name = struct type t = string let make t = t let compare = Stdune . String . compare end type ' a t = { poll : ( Id . t , ' a option ) Decl . request ; cancel : Id . t Decl . notification ; name : Name .... |
type echo = { queue : string ref Queue . t ; mutable lwt_channel : Lwt_io . input_channel option ; mutable closed : bool ; mutable pending : unit Lwt . u list ; } |
let wake_up_echo echo = let pending = echo . pending in echo . pending <- [ ] ; List . iter ( fun pending -> Lwt . wakeup_later pending ( ) ) pending |
let push_to_echo echo string = if String . length string > 0 then ( Queue . push ( ref string ) echo . queue ; wake_up_echo echo ) |
let close_echo echo = if not echo . closed then ( echo . closed <- true ; wake_up_echo echo ) |
let create_echo ( ) = let echo = { queue = Queue . create ( ) ; lwt_channel = None ; closed = false ; pending = [ ] } in let rec read bytes ofs len = match Queue . peek_opt echo . queue with | None -> if echo . closed then return 0 else let ( promise , resolver ) = Lwt . task ( ) in echo . pending <- resolver :: echo .... |
let get_echo_lwt_channel echo = match echo . lwt_channel with | None -> assert false | Some lwt_channel -> lwt_channel |
type hooks = { on_log : string -> unit ; on_spawn : string -> string list -> unit } |
type remote = { runner : Runner . t ; pid : int Lwt . t } |
type t = { id : int ; name : string ; command : string ; arguments : string list ; color : Log . Color . t ; lwt_process : Lwt_process . process_full ; log_status_on_exit : bool ; stdout : echo ; stderr : echo ; hooks : hooks option ; remote : remote option ; } |
type failed_info = { name : string ; command : string ; arguments : string list ; status : Unix . process_status option ; expect_failure : bool ; reason : String . t option ; } |
let status_to_reason = function | Unix . WEXITED code -> Format . sprintf " exited with code % d " code | Unix . WSIGNALED code -> Format . sprintf " was killed by signal % d " code | Unix . WSTOPPED code -> Format . sprintf " was stopped by signal % d " code |
let ( ) = Printexc . register_printer @@ function | Failed { name ; command ; arguments ; status ; expect_failure ; reason } -> let reason = Option . value ~ default : ( match status with | Some st -> status_to_reason st | None -> Printf . sprintf " exited " ) reason in Some ( Printf . sprintf " % s % s % s ( full comm... |
let get_unique_name = let name_counts = ref String_map . empty in fun name -> let index = match String_map . find_opt name ! name_counts with None -> 0 | Some i -> i in name_counts := String_map . add name ( index + 1 ) ! name_counts ; name ^ " " # ^ string_of_int index |
let fresh_id = let next = ref 0 in fun ( ) -> let id = ! next in incr next ; id |
module ID_map = Map . Make ( Int ) |
let live_processes = ref ID_map . empty |
let show_signal code = if code = Sys . sigabrt then " SIGABRT " else if code = Sys . sigalrm then " SIGALRM " else if code = Sys . sigfpe then " SIGFPE " else if code = Sys . sighup then " SIGHUP " else if code = Sys . sigill then " SIGILL " else if code = Sys . sigint then " SIGINT " else if code = Sys . sigkill then ... |
let wait process = let * status = process . lwt_process # status in if ID_map . mem process . id ! live_processes then ( live_processes := ID_map . remove process . id ! live_processes ; if process . log_status_on_exit then match status with | WEXITED code -> Log . debug " % s exited with code % d . " process . name co... |
let handle_process ~ log_output process = let rec handle_output name ( ch : Lwt_io . input_channel ) echo = let * line = Lwt_io . read_line_opt ch in match line with | None -> close_echo echo ; Lwt_io . close ch | Some line -> if log_output then ( Log . debug ~ prefix : name ~ color : process . color " % s " line ; Opt... |
let parse_current_environment : unit -> string String_map . t = fun ( ) -> let parse_env_kv key_value : ( string * string ) option = String . index_opt key_value ' ' = |> Option . map ( fun i -> ( Re . Str . string_before key_value i , Re . Str . string_after key_value ( i + 1 ) ) ) in Unix . environment ( ) |> Array .... |
let to_key_equal_value ( kv_map : string String_map . t ) : string array = kv_map |> String_map . to_seq |> Seq . map ( fun ( name , value ) -> name ^ " " = ^ value ) |> Array . of_seq |
let spawn_with_stdin ? runner ( ? log_status_on_exit = true ) ( ? log_output = true ) ? name ( ? color = Log . Color . FG . cyan ) ( ? env = String_map . empty ) ? hooks command arguments = let name = Option . value ~ default ( : get_unique_name command ) name in Option . iter ( fun hooks -> hooks . on_spawn command ar... |
let spawn ? runner ? log_status_on_exit ? log_output ? name ? color ? env ? hooks command arguments = let ( process , stdin ) = spawn_with_stdin ? runner ? log_status_on_exit ? log_output ? name ? color ? env ? hooks command arguments in Background . register ( Lwt_io . close stdin ) ; process |
let kill_remote_if_needed process = match process . remote with | None -> ( ) | Some { pid ; runner } -> let open Lwt in let open Infix in Background . register ( ( pid >|= fun pid -> let command = " kill " in let arguments = [ " - 9 " ; " - P " ; string_of_int pid ] in let shell = Runner . Shell . ( redirect_stderr ( ... |
let terminate ( process : t ) = Log . debug " Send SIGTERM to % s . " process . name ; kill_remote_if_needed process ; process . lwt_process # kill Sys . sigterm |
let kill ( process : t ) = Log . debug " Send SIGKILL to % s . " process . name ; kill_remote_if_needed process ; process . lwt_process # terminate |
let pid ( process : t ) = process . lwt_process # pid |
let validate_status ( ? expect_failure = false ) status = match status with | Unix . WEXITED n when ( n = 0 && not expect_failure ) || ( n <> 0 && expect_failure ) -> Ok ( ) | _ -> Error ( ` Invalid_status ( status_to_reason status ) ) |
let check ( ? expect_failure = false ) process = let * status = wait process in match validate_status ~ expect_failure status with | Ok ( ) -> unit | Error ( ` Invalid_status reason ) -> raise ( Failed { name = process . name ; command = process . command ; arguments = process . arguments ; status = Some status ; expec... |
let run ? log_status_on_exit ? name ? color ? env ? expect_failure command arguments = spawn ? log_status_on_exit ? name ? color ? env command arguments |> check ? expect_failure |
let clean_up ( ) = let list = ID_map . bindings ! live_processes |> List . map snd in List . iter terminate list ; Lwt_list . iter_p ( fun process -> let * _ = wait process in unit ) list |
let stdout process = get_echo_lwt_channel process . stdout |
let stderr process = get_echo_lwt_channel process . stderr |
let name ( process : t ) = process . name |
let check_and_read ? expect_failure ~ channel_getter process = let * ( ) = check ? expect_failure process and * output = Lwt_io . read ( channel_getter process ) in return output |
let check_and_read_both ? expect_failure process = let * ( ) = check ? expect_failure process and * out = Lwt_io . read ( stdout process ) and * err = Lwt_io . read ( stderr process ) in return ( out , err ) |
let check_and_read_stdout = check_and_read ~ channel_getter : stdout |
let check_and_read_stderr = check_and_read ~ channel_getter : stderr |
let run_and_read_stdout ? log_status_on_exit ? name ? color ? env ? expect_failure command arguments = let process = spawn ? log_status_on_exit ? name ? color ? env command arguments in check_and_read_stdout ? expect_failure process |
let run_and_read_stderr ? log_status_on_exit ? name ? color ? env ? expect_failure command arguments = let process = spawn ? log_status_on_exit ? name ? color ? env command arguments in check_and_read_stdout ? expect_failure process |
let check_error ? exit_code ? msg process = let * status = wait process in let * err_msg = Lwt_io . read ( stderr process ) in let error = { name = process . name ; command = process . command ; arguments = process . arguments ; status = Some status ; expect_failure = true ; reason = None ; } in match status with | WEX... |
let program_path program = Lwt . catch ( fun ( ) -> let * path = run_and_read_stdout " sh " [ " - c " ; " command - v " ^ program ] in return ( Some ( String . trim path ) ) ) ( fun _ -> return None ) |
let catchup_timeout_duration ( precomputed_values : Precomputed_values . t ) t = Block_time . Span . of_ms ( ( precomputed_values . genesis_constants . protocol . delta + 1 ) 1 * precomputed_values . constraint_constants . block_window_duration_ms |> Int64 . of_int ) |> Block_time . Span . min ( Block_time . Span . of_... |
let cached_transform_deferred_result ~ transform_cached ~ transform_result cached = Cached . transform cached ~ f : transform_cached |> Cached . sequence_deferred >>= Fn . compose transform_result Cached . sequence_result |
let add_and_finalize ~ logger ~ frontier ~ catchup_scheduler ~ processed_transition_writer ~ only_if_present ~ time_controller ~ source ~ valid_cb cached_breadcrumb ( ~ precomputed_values : Precomputed_values . t ) t = let breadcrumb = if Cached . is_pure cached_breadcrumb then Cached . peek cached_breadcrumb else Cach... |
let process_transition ~ logger ~ trust_system ~ verifier ~ frontier ~ catchup_scheduler ~ processed_transition_writer ~ time_controller ~ transition : cached_initially_validated_transition ~ valid_cb ~ precomputed_values = let enveloped_initially_validated_transition = Cached . peek cached_initially_validated_transiti... |
let run ~ logger ( ~ precomputed_values : Precomputed_values . t ) t ~ verifier ~ trust_system ~ time_controller ~ frontier ( ~ primary_transition_reader : ( [ ` Block of ( Mina_block . initial_valid_block Envelope . Incoming . t , State_hash . t ) Cached . t ] * [ ` Valid_cb of Mina_net2 . Validation_callback . t opti... |
let compiler_libref = ref false |
type config = { src_dir : string ; dst_dir : string ; title : string } |
let search_widget with_description = let search_decription = if with_description then { |< span class " = search_comment " ( > search values , type signatures , and descriptions - case sensitive ) < div class " = search_help " >< ul >< li > You may search bare values , like < code > map </ code , > or indicate the modu... |
let parsed_files = Hashtbl . create 50 |
let parse_file ( ? original = false ) file = match Hashtbl . find_opt parsed_files file with | Some soup -> if original then failwith ( sprintf " File % s was already processed " file ) else soup | None -> let soup = read_file file |> parse in Hashtbl . add parsed_files file soup ; soup |
let make_toc ~ version ~ search file config title body = let header = create_element ~ id " : sidebar " " header " in prepend_child body header ; let nav = create_element " nav " ~ class_ " : toc " in append_child header nav ; let ul = create_element " ul " in append_child nav ul ; let li_of_h ul h = let li_current = c... |
let process ( ? search = true ) ~ version config file out = dbg " Processing % s . . . " file ; let soup = parse_file ~ original : true file in update_head ~ search soup ; let body = wrap_body ~ classes [ " : api " ] soup in body $? " div . navbar " |> Option . iter delete ; let title = soup $ " title " |> R . leaf_tex... |
let process ( ? overwrite = false ) ~ version config file out = if overwrite || not ( Sys . file_exists out ) then Ok ( process ~ version config file out ) else Error ( sprintf " File % s already exists . " out ) |
let all_html_files config = Sys . readdir config . src_dir |> Array . to_list |> List . filter ( fun s -> Filename . extension s = " . html " ) |
module Index = struct type item = { html : string ; txt : string } type entry = { mdule : item ; value : item ; info : item ; signature : item option } let anon_t_regexp = Re . Str . regexp " \\ bt \\ b " let space_regexp = Re . Str . regexp " " + let newline_regexp = Re . Str . regexp_string " \ n " let one_line s = R... |
let process_html config overwrite version = print_endline ( sprintf " \ nProcessing version % s into % s . . . \ n " version config . dst_dir ) ; let processed = ref 0 in all_html_files config |> List . iter ( fun file -> match process config ~ overwrite ~ version ( config . src_dir // file ) ( config . dst_dir // file... |
let copy_files config = let ind = config . dst_dir // " index . js " in if not ( Sys . file_exists ind ) then Index . process config |
let ( ) = let version = find_version ( ) in let args = Sys . argv |> Array . to_list |> List . tl in let config = if List . mem " compiler " args then { src_dir = html_maindir // " compilerlibref " ; dst_dir = api_dir // " compilerlibref " ; title = " Compiler " } else { src_dir = html_maindir // " libref " ; dst_dir =... |
type point = { configuration : string ; parameter : int ; time : float ; time_err : float * float ; cycles : float ; cycles_err : float * float ; } |
let split_on_colon s = let i = String . index s ' ' : in String . sub s 0 i , String . sub s ( i + 1 ) ( String . length s - i - 1 ) |
let early_float s = Scanf . sscanf s " % f " ( fun x -> x ) |
let point_of_row row = let configuration , parameter = split_on_colon row . ( 0 ) in let parameter = int_of_string parameter in { configuration ; parameter ; time = early_float row . ( 2 ) ; time_err = early_float row . ( 3 ) , early_float row . ( 4 ) ; cycles = early_float row . ( 6 ) ; cycles_err = early_float row . ... |
let split_on_spaces s = let rec acc lst s = let t = String . trim s in match String . index t ' ' with | si -> let f = String . sub t 0 si in let r = String . sub t si ( String . length t - si ) in acc ( f :: lst ) r | exception Not_found -> List . rev ( t :: lst ) in acc [ ] s |
let print_pretty_point ( { configuration ; parameter ; time ; time_err ; cycles ; cycles_err } ) = Printf . printf " Configuration : % s \ nParameter : % d \ n " configuration parameter ; Printf . printf " Time : % f % f %+ f \ nCycles : % f % f %+ f \ n \ n " time ( fst time_err ) ( snd time_err ) cycles ( fst cycles_... |
let benchmark_names = [ " interpreted_local " ; " interpreted_shared " ; " staged_functor " ; " staged_no_functor " ; " traditional " ; " cowboy " ; |
let columns = 9 in else let data = ref [ ] in let path = Sys . argv . ( 1 ) in let ic = open_in path in try while true do let line = input_line ic in let prefix = String . sub line 0 6 in if prefix = " " ----- then while true do let line = input_line ic in data := line :: ! data done done with End_of_file -> close_in i... |
type process_status = Exited of int | Signaled of int | Stopped of int | CausedException of string |
let of_unix_status s = match s with | Unix . WEXITED n -> Exited n | Unix . WSIGNALED n -> Signaled n | Unix . WSTOPPED n -> Stopped n |
let log_process_outputs ( ? func = Logs . debug ) cmd out err = func @@ fun m -> m " Running " \% s " \ produced the following outputs :\ n Standard output :\ n % s \ nStandard error :\ n % s " cmd out err |
let exit_code_of_status s = match s with | Exited num -> num | Signaled num -> 128 + num | Stopped num -> 128 + num | CausedException _ -> 254 |
let string_of_status s = match s with | Exited 0 -> " process exited normally " | Exited num -> Printf . sprintf " process exited with code % d " num | Signaled num -> Printf . sprintf " process was killed by signal % d " num | Stopped num -> Printf . sprintf " process was stopped by signal % d " num | CausedException ... |
let format_error cmd status = match status with | Exited 0 -> Printf . sprintf " Command " \% s " \ has run successfully " cmd | _ -> Printf . sprintf " Failed to run command " \% s " \: % s " cmd ( string_of_status status ) |
let get_program_output_raw ( ? input = None ) ( ? debug = false ) ( ? env [ =| ] ) | command = let env = Array . append ( Unix . environment ( ) ) env in let ( res , output , err_output ) = begin try let std_out , std_in , std_err = Unix . open_process_full command env in let ( ) = begin match input with | None -> ( ) ... |
let get_program_output ( ? input = None ) ( ? debug = false ) ( ? env [ =| ] ) | command = let res = get_program_output_raw ~ input : input ~ debug : debug ~ env : env command in match res with | Ok _ as o -> o | Error e -> Error ( format_error command e ) |
let int_reg_name = [ | " eax " ; " ebx " ; " ecx " ; " edx " ; " esi " ; " edi " ; " ebp " ] | |
let float_reg_name = [ | " tos " ] | |
let register_class r = match r . typ with Int -> 0 | Addr -> 0 | Float -> 1 |
let num_available_registers = [ | 7 ; 0 ] | |
let first_available_register = [ | 0 ; 100 ] | |
let register_name r = if r < 100 then int_reg_name . ( r ) else float_reg_name . ( r - 100 ) |
let hard_int_reg = let v = Array . create 7 Reg . dummy in for i = 0 to 6 do v . ( i ) <- Reg . at_location Int ( Reg i ) done ; v |
let hard_float_reg = [ | Reg . at_location Float ( Reg 100 ) ] | |
let all_phys_regs = Array . append hard_int_reg hard_float_reg |
let phys_reg n = if n < 100 then hard_int_reg . ( n ) else hard_float_reg . ( n - 100 ) |
let eax = phys_reg 0 |
let ecx = phys_reg 2 |
let edx = phys_reg 3 |
let tos = phys_reg 100 |
let stack_slot slot ty = Reg . at_location ty ( Stack slot ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.