text stringlengths 12 786k |
|---|
let write t a ~ if_closed = in_async_unless_closed_wait t ~ if_closed ( fun ( ) -> Pipe . write t a ) ; ; |
let transfer_in_without_pushback ? wakeup_scheduler t ~ from ~ if_closed = in_async_unless_closed ? wakeup_scheduler t ~ if_closed ( fun ( ) -> Pipe . transfer_in_without_pushback t ~ from ) ; ; |
let write_without_pushback ? wakeup_scheduler t a ~ if_closed = in_async_unless_closed ? wakeup_scheduler t ~ if_closed ( fun ( ) -> Pipe . write_without_pushback t a ) ; ; |
let close t = in_async ( fun ( ) -> Pipe . close t ) |
let is_closed t = in_async ( fun ( ) -> Pipe . is_closed t ) |
let closed t = in_async_wait ( fun ( ) -> Pipe . closed t ) |
module Elt = struct type ' a t = { mutable value : ' a Uopt . t ; mutable next : ( ' a t Uopt . t [ @ sexp . opaque ] ) } [ @@ deriving sexp_of ] let create ( ) = { value = Uopt . none ; next = Uopt . none } end |
type ' a t = { mutable length : int ; mutable front : ' a Elt . t ; mutable back : ' a Elt . t ; mutable unused_elts : ' a Elt . t Uopt . t } |
let invariant _invariant_a t = Invariant . invariant [ % here ] t [ % sexp_of : _ t ] ( fun ( ) -> let check f = Invariant . check_field t f in Fields . iter ~ length ( : check ( fun length -> assert ( length >= 0 ) ) ) ~ front : ( check ( fun front -> let i = ref t ... |
let create ( ) = let elt = Elt . create ( ) in { front = elt ; back = elt ; length = 0 ; unused_elts = Uopt . none } ; ; |
let get_unused_elt t = if Uopt . is_some t . unused_elts then ( let elt = Uopt . unsafe_value t . unused_elts in t . unused_elts <- elt . next ; elt ) else Elt . create ( ) ; ; |
let enqueue ( type a ) ( t : a t ) ( a : a ) = let new_back = get_unused_elt t in t . length <- t . length + 1 ; t . back . value <- Uopt . some a ; t . back . next <- Uopt . some new_back ; t . back <- new_back ; ; |
let return_unused_elt t ( elt : _ Elt . t ) = elt . value <- Uopt . none ; elt . next <- t . unused_elts ; t . unused_elts <- Uopt . some elt ; ( ) ; ; failwiths ~ here [ :% here ] " Thread_safe_queue . dequeue_exn of empty queue " t [ % sexp_of : _ t ] ; ; |
let dequeue_exn t = if t . length = 0 then raise_dequeue_empty t ; let elt = t . front in let a = elt . value in t . front <- Uopt . unsafe_value elt . next ; t . length <- t . length - 1 ; return_unused_elt t elt ; Uopt . unsafe_value a ; ; |
let clear_internal_pool t = t . unused_elts <- Uopt . none |
module Private = struct module Uopt = Uopt end |
let create fn arg = thread_new ( fun ( ) -> try fn arg ; ( ) with Thread_exit -> ( ) | exn -> flush stdout ; flush stderr ; thread_uncaught_exception exn ) |
let exit ( ) = raise Thread_exit |
let kill th = invalid_arg " Thread . kill : not implemented " |
let preempt signal = yield ( ) |
let _ = ignore ( Sys . signal Sys . sigterm ( Sys . Signal_handle preempt ) ) ; thread_initialize ( ) |
let wait_read fd = ( ) |
let wait_write fd = ( ) |
let wait_timed_read fd delay = true |
let wait_timed_write fd delay = true |
let select rd wr ex delay = invalid_arg " Thread . select : not implemented " |
let wait_pid p = Unix . waitpid [ ] p |
let sigmask cmd set = invalid_arg " Thread . sigmask : not implemented " |
let wait_signal set = invalid_arg " Thread . wait_signal : not implemented " |
let with_mutex t ~ f = Mutex . lock t ; let res = f ( ) in Mutex . unlock t ; res |
type state = | Running | Stopped | Finished |
type t = { work : ( unit -> unit ) Queue . t ; mutable state : state ; mutex : Mutex . t ; work_available : Condition . t } |
let is_running t = match t . state with | Running -> true | Stopped | Finished -> false |
let run t = let rec loop ( ) = match t . state with | Stopped -> ( match Queue . pop t . work with | None -> t . state <- Finished | Some job -> do_work job ) | Finished -> ( ) | Running -> ( match Queue . pop t . work with | Some job -> do_work job | None -> while Queue . i... |
let create ~ spawn_thread = let t = { work = Queue . create ( ) ; state = Finished ; mutex = Mutex . create ( ) ; work_available = Condition . create ( ) } in t . state <- Running ; spawn_thread ( fun ( ) -> run t ) ; t |
let add_work t ~ f = with_mutex t . mutex ~ f ( : fun ( ) -> if is_running t then ( Queue . push t . work f ; Condition . signal t . work_available ; Ok ( ) ) else Error ` Stopped ) |
let stop t = with_mutex t . mutex ~ f ( : fun ( ) -> match t . state with | Running -> t . state <- Stopped ; Condition . signal t . work_available | Stopped | Finished -> ( ) ) |
let text_no_final_nl ( ) = print_string " one \ ntwo \ nthree " in text_no_final_nl ( ) ; [ % expect { | one two three } ] ; | let text ( ) = print_string " one \ ntwo \ nthree \ n " in text ( ) ; [ % expect { | one two three } ] ; | text ( ) ; [ % e... |
object val mutable message = " " method get_message = message method set_message s = message <- s end ; ; |
module Transport = struct type exn_type = | UNKNOWN | NOT_OPEN | ALREADY_OPEN | TIMED_OUT | END_OF_FILE ; ; exception E of exn_type * string class virtual t = object ( self ) method virtual isOpen : bool method virtual opn : unit method virtual close : unit method virtual read : bytes -> int -> i... |
module Protocol = struct type t_type = | T_STOP | T_VOID | T_BOOL | T_BINARY | T_BYTE | T_I08 | T_I16 | T_I32 | T_U64 | T_I64 | T_DOUBLE | T_STRING | T_UTF7 | T_STRUCT | T_MAP | T_SET | T_LIST | T_UTF8 | T_UTF16 [ @@ deriving show , eq ] let t_type_to_i = function T_STOP -> 0 | T_VOID -... |
module Processor = struct class virtual t = object method virtual process : Protocol . t -> Protocol . t -> bool end ; ; class factory ( processor : t ) = object val processor_ = processor method getProcessor ( _trans : Transport . t ) = processor_ end ; ; end |
module Application_Exn = struct type typ = | UNKNOWN | UNKNOWN_METHOD | INVALID_MESSAGE_TYPE | WRONG_METHOD_NAME | BAD_SEQUENCE_ID | MISSING_RESULT | INTERNAL_ERROR | PROTOCOL_ERROR | INVALID_TRANSFORM | INVALID_PROTOCOL | UNSUPPORTED_CLIENT_TYPE let typ_of_i = function 0l -> UNKNOWN | 1l -> UNKNOWN_... |
type ' a outcome = [ ` Ok of ' a | ` Aborted | ` Raised of exn ] |
module Internal_job : sig type ' a t [ @@ deriving sexp_of ] val create : ( ' a -> ' b Deferred . t ) -> ' a t * ' b outcome Deferred . t val run : ' a t -> ' a -> [ ` Ok | ` Raised ] Deferred . t val abort : _ t -> unit type ' a t = { start : [ ` Abort | ` ... |
type ' a t = { continue_on_error : bool ; max_concurrent_jobs : int ; job_resources_not_in_use : ' a Stack_or_counter . t ; jobs_waiting_to_start : ' a Internal_job . t Queue . t ; mutable num_jobs_running : int ; mutable capacity_available : unit Ivar . t option ; mutable is_dead : ... |
let invariant invariant_a t : unit = try let check f field = f ( Field . get field t ) in Fields . iter ~ continue_on_error : ignore ~ max_concurrent_jobs : ( check ( fun max_concurrent_jobs -> assert ( max_concurrent_jobs > 0 ) ) ) ~ job_resources_not_in_use : ( check ( fun job_reso... |
module T2 = struct type nonrec ( ' a , ' kind ) t = ' a t [ @@ deriving sexp_of ] let invariant invariant_a _ t = invariant invariant_a t end |
let num_jobs_waiting_to_start t = Queue . length t . jobs_waiting_to_start |
let clean_resource t a = Deferred . all_unit ( List . map t . cleans ~ f ( : fun f -> f a ) ) >>> fun ( ) -> t . num_resources_not_cleaned <- t . num_resources_not_cleaned - 1 ; if t . num_resources_not_cleaned = 0 then Ivar . fill t . cleaned ( ) ; ; |
let kill t = if not t . is_dead then ( t . is_dead <- true ; Queue . iter t . jobs_waiting_to_start ~ f : Internal_job . abort ; Queue . clear t . jobs_waiting_to_start ; Stack_or_counter . iter t . job_resources_not_in_use ~ f ( : fun a -> clean_resource t a ) ; Stack_or_counter ... |
let at_kill t f = let f = unstage ( Monitor . Exported_for_scheduler . preserve_execution_context ' f ) in t . cleans <- f :: t . cleans ; ; |
let cleaned t = Ivar . read t . cleaned |
let rec start_job t = assert ( not t . is_dead ) ; assert ( t . num_jobs_running < t . max_concurrent_jobs ) ; assert ( not ( Queue . is_empty t . jobs_waiting_to_start ) ) ; let job = Queue . dequeue_exn t . jobs_waiting_to_start in t . num_jobs_running <- t . num_jobs_runni... |
let create_internal ~ continue_on_error job_resources = let max_concurrent_jobs = Stack_or_counter . length job_resources in { continue_on_error ; max_concurrent_jobs ; job_resources_not_in_use = job_resources ; jobs_waiting_to_start = Queue . create ( ) ; num_jobs_running = 0 ; capacity_avai... |
let create_with ~ continue_on_error job_resources = create_internal ~ continue_on_error ( Stack_or_counter . of_list job_resources ) ; ; |
module Sequencer = struct type nonrec ' a t = ' a t [ @@ deriving sexp_of ] let create ( ? continue_on_error = false ) a = create_with ~ continue_on_error [ a ] end |
let create ~ continue_on_error ~ max_concurrent_jobs = if max_concurrent_jobs <= 0 then raise_s [ % message " Throttle . create requires positive max_concurrent_jobs , but got " ( max_concurrent_jobs : int ) ] ; create_internal ~ continue_on_error ( Stack_or_counter . create_counter ~ len... |
module Job = struct type ( ' a , ' b ) t = { internal_job : ' a Internal_job . t ; result : [ ` Ok of ' b | ` Aborted | ` Raised of exn ] Deferred . t } let result t = t . result let abort t = Internal_job . abort t . internal_job let create f = let internal_job , resu... |
let enqueue ' t f = let job = Job . create f in if t . is_dead then Job . abort job else ( Queue . enqueue t . jobs_waiting_to_start job . internal_job ; if t . num_jobs_running < t . max_concurrent_jobs then start_job t ) ; Job . result job ; ; |
let handle_enqueue_result result = match result with | ` Ok a -> a | ` Aborted -> raise_s [ % message " throttle aborted job " ] | ` Raised exn -> raise exn ; ; |
let enqueue t f = enqueue ' t f >>| handle_enqueue_result |
let enqueue_exclusive t f = let n = t . max_concurrent_jobs in if Int . ( >= ) n 1_000_000 then raise_s [ % sexp " [ enqueue_exclusive ] was called with a very large value of \ [ max_concurrent_jobs ] . This doesn ' t work . " ] ; let done_ = Ivar . create ( ) in assert ( ... |
let monad_sequence_how ( ? how = ` Sequential ) ~ f = stage ( match how with | ` Parallel -> f | ( ` Sequential | ` Max_concurrent_jobs _ ) as how -> let max_concurrent_jobs = match how with | ` Sequential -> 1 | ` Max_concurrent_jobs max_concurrent_jobs -> max_concurrent_jobs in l... |
let monad_sequence_how2 ( ? how = ` Sequential ) ~ f = stage ( match how with | ` Parallel -> f | ( ` Sequential | ` Max_concurrent_jobs _ ) as how -> let max_concurrent_jobs = match how with | ` Sequential -> 1 | ` Max_concurrent_jobs max_concurrent_jobs -> max_concurrent_jobs in ... |
let prior_jobs_done t = Deferred . create ( fun all_dummy_jobs_running -> let dummy_jobs_running = ref 0 in for _ = 1 to t . max_concurrent_jobs do don ' t_wait_for ( enqueue t ( fun _ -> incr dummy_jobs_running ; if ! dummy_jobs_running = t . max_concurrent_jobs then Ivar . fill all_dummy_... |
let capacity_available t = if num_jobs_running t < max_concurrent_jobs t then return ( ) else ( match t . capacity_available with | Some ivar -> Ivar . read ivar | None -> Deferred . create ( fun ivar -> t . capacity_available <- Some ivar ) ) ; ; |
let null = null ( ) " java is_null " " java is_not_null " |
type t = ( $ ocaml_short_name ) ocaml_short_name java_instance |
let make ( ? cause = null ) null ( ? message = JavaString . null ) null ( ) = if JavaString . is_null message then Java . make ( " $ java_short_name ) java_short_name ( java_short_nameThrowable ) java_short_nameThrowable " cause else Java . make ( " $ java_short_name ) java_short_n... |
let get_cause th = Java . call " Throwable . getCause ( getCause ) getCause " th |
let get_message th = Java . call " Throwable . getMessage ( getMessage ) getMessage " th |
let get_stack_trace th = Java . call " Throwable . getStackTrace ( getStackTrace ) getStackTrace " th |
let print_stack_trace th = Java . call " Throwable . printStackTrace ( printStackTrace ) printStackTrace " th |
let wrap x = if is_null x then None else Some x |
let unwrap = function | Some x -> x | None -> null |
let string_to_size = function | " xs " -> ` Xs | " s " -> ` S | " m " -> ` M | " l " -> ` L | " xl " -> ` Xl | _ -> invalid_arg " Size must be xs , s , m , l or xl . " |
let string_to_format = function | " jpeg " -> ` Jpeg | " jpg " -> ` Jpeg | " png " -> ` Png | " bmp " -> ` Bmp | _ -> invalid_arg " Format must be jpeg , jpg , png or bmp . " |
let download t ( ? format " = jpeg " ) ( ? size " = s " ) fn = D . thumbnails t ~ size ( : string_to_size size ) ~ format ( : string_to_format format ) fn >>= function | None -> Lwt_io . printlf " No image named % S . " fn | Some ( metadata , stream ) -> let fn = ... |
let main t args = match args with | [ ] -> Lwt_io . printlf " No file specified . " | [ fn ] -> download t fn | [ fn ; size ] -> download t ~ size fn | [ fn ; size ; format ] -> download t ~ format ~ size fn | _ -> Lwt_io . printlf " % s < path > [ size ] [ form... |
let ( ) = Common . run main |
[ %% error mechanism ] " [ %% endif ] endif [ %% else ] else [ %% endif ] endif |
module Field = struct open Core_kernel [ %% versioned_asserted module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V1 = struct type t = Pasta . Fp . t [ @@ deriving equal , compare , yojson , sexp , hash ] hash let to_latest x = x end module Tests = struct e... |
module Tock = struct module Field = struct type t = Pasta . Fq . t let unpack ( t : t ) t = Pasta . Fq . to_bits t let size_in_bits = Pasta . Fq . length_in_bits let project bits = Core_kernel . Option . value_exn ~ message " : Snark_params_nonconsensus . Tock . Field . project " ( Pasta . ... |
module Inner_curve = struct module C = Pasta . Pallas type t = C . t [ @@ deriving sexp ] sexp module Coefficients = C . Coefficients let find_y x = let open Field in let y2 = ( x * square x ) x + ( Coefficients . a * x ) x + Coefficients . b in if is_square y2 then Some ( sqrt y2 ) y2 ... |
let ticket_balance_key ctxt ~ owner ( Ticket_token . Ex_token { ticketer ; contents_type ; contents } ) = let loc = Micheline . dummy_location in Script_ir_translator . unparse_comparable_ty ~ loc ctxt contents_type >>?= fun ( cont_ty_unstripped , ctxt ) -> Gas . consume ctxt ( Script ... |
let add_ticket_balance contract ctxt ticket = let ( token , amount ) = Ticket_token . token_and_amount_of_ex_ticket ticket in Ticket_balance_key . ticket_balance_key ctxt ~ owner : contract token >>=? fun ( hash , ctxt ) -> Ticket_balance . adjust_balance ctxt hash ~ delta ( : Script_int . ... |
let update_contract_tickets ctxt contract = Contract . get_script ctxt contract >>=? fun ( ctxt , script ) -> match script with | None -> return ctxt | Some script -> Script_ir_translator . parse_script ctxt ~ legacy : true ~ allow_forged_in_storage : true script >>=? fun ( ex_script , ctxt ) ... |
let is_originated contract = match Contract . is_originated contract with Some _ -> true | _ -> false |
let init ctxt = Contract . list ctxt >>= fun contracts -> let contracts = List . filter is_originated contracts in List . fold_left_es update_contract_tickets ctxt contracts |
module Constants = struct let cost_collect_tickets_step = S . safe_int 360 let cost_has_tickets_of_ty type_size = S . mul ( S . safe_int 20 ) type_size let cost_token_and_amount_of_ticket = S . safe_int 30 let cost_compare_ticket_hash = S . safe_int 100 let cost_compare_key_contract = S . safe... |
let consume_gas_steps ctxt ~ step_cost ~ num_steps = let ( * ) = S . mul in if Compare . Int . ( num_steps <= 0 ) then Ok ctxt else let gas = Gas . atomic_step_cost ( step_cost * Saturation_repr . safe_int num_steps ) in Gas . consume ctxt gas |
let has_tickets_of_ty_cost ty = Constants . cost_has_tickets_of_ty Script_typed_ir . ( ty_size ty |> Type_size . to_int ) |
let negate_cost z = let size = ( 7 + Z . numbits z ) / 8 in Gas . ( S . safe_int 25 +@ S . shift_right ( S . safe_int size ) 4 ) |
let ( ) = register_error_kind ` Branch ~ id " : Failed_to_hash_node " ~ title " : Failed to hash node " ~ description " : Failed to hash node for a key in the ticket - balance table " ~ pp ( : fun ppf ( ) -> Format . fprintf ppf " Failed to hash node for a key in the ticket - bal... |
let hash_bytes_cost bytes = let module S = Saturation_repr in let ( + ) = S . add in let v0 = S . safe_int @@ Bytes . length bytes in let ( lsr ) = S . shift_right in S . safe_int 200 + ( v0 + ( v0 lsr 2 ) ) |> Gas_limit_repr . atomic_step_cost |
let hash_of_node ctxt node = Raw_context . consume_gas ctxt ( Script_repr . strip_locations_cost node ) >>? fun ctxt -> let node = Micheline . strip_locations node in match Data_encoding . Binary . to_bytes_opt Script_repr . expr_encoding node with | Some bytes -> Raw_context . consume_gas ctxt ... |
let make ctxt ~ ticketer ~ typ ~ contents ~ owner = hash_of_node ctxt @@ Micheline . Seq ( Micheline . dummy_location , [ ticketer ; typ ; contents ; owner ] ) |
type error += Failed_to_load_big_map_value_type of Big_map . Id . t |
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : Failed_to_load_big_map_value_type " ~ title " : Failed to load big - map value type " ~ description : " Failed to load big - map value type when computing ticket diffs . " ~ pp ( : fun ppf big_map_id -> Format... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.