text
stringlengths
12
786k
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer ~ loc report_error err ) | _ -> None )
let string s = Lconst ( Const_base ( Const_string ( s , None ) ) )
let int i = Lconst ( Const_base ( Const_int i ) )
let marshal_loc ( x : Location . t ) = let s = Marshal . to_string x [ ] in string s
let true_ = Lconst ( Const_pointer 1 )
let false_ = Lconst ( Const_pointer 0 )
let quote_bool b = if b then true_ else false_
let none = Lconst ( Const_pointer 0 )
let some x = Lprim ( Pmakeblock ( 0 , Immutable , None ) , [ x ] , Location . none )
let option opt = match opt with | None -> none | Some x -> some x
let nil = Lconst ( Const_pointer 0 )
let cons hd tl = Lprim ( Pmakeblock ( 0 , Immutable , None ) , [ hd ; tl ] , Location . none )
let rec list l = match l with | [ ] -> nil | hd :: tl -> cons hd ( list tl )
let pair ( x , y ) = Lprim ( Pmakeblock ( 0 , Immutable , None ) , [ x ; y ] , Location . none )
module Lam = struct let stdmod_path = Ident . lift_string " CamlinternalQuote " let lambda_mod = " Lambda " let camlinternalQuote = lazy ( match Env . open_pers_signature stdmod_path Env . initial_safe_string with | exception Not_found -> fatal_error @@ " Module " ^ stdmod_path ^ " unavai...
let transl_close_expression _loc e = e
let wrap_local _loc _id _name lam = lam
let check_buflen cs = let cslen = Cstruct . len cs in if cslen < packet_length then invalid_arg ( " HID packets must be 64 bytes long , got " ^ string_of_int cslen )
module Status = struct type t = . . type t += | Invalid_pin of int | Incorrect_length | Incorrect_length_for_ins | Incompatible_file_structure | Security_status_unsatisfied | Hid_required | Conditions_of_use_not_satisfied | Incorrect_data | File_not_found | Parse_error | Incorrect_params | Incorrect_...
module Header = struct type t = { cmd : cmd ; seq : int ; } and cmd = Ping | Apdu let cmd_of_int = function | 0x05 -> Some Apdu | 0x02 -> Some Ping | _ -> None module Error = struct type t = | Header_too_short of int | Invalid_channel of int | Invalid_command_tag of int | Unexpected_sequen...
type transport_error = | Hidapi of string | Incomplete_write of int | Incomplete_read of int
let pp_transport_error ppf = function | Hidapi s -> Format . pp_print_string ppf s | Incomplete_write i -> Format . fprintf ppf " wrote % d bytes , expected to write 64 \ bytes " i | Incomplete_read i -> Format . fprintf ppf " read % d bytes , expected to read 64 \ bytes " i
type error = | AppError of { status : Status . t ; msg : string } | ApduError of Header . Error . t | TransportError of transport_error
let app_error ~ msg r = R . reword_error ( fun status -> AppError { status ; msg } ) r
let apdu_error r = R . reword_error ( fun e -> ApduError e ) r
let pp_error ppf = function | AppError { status ; msg } -> Format . fprintf ppf " Application level error ( % s ) : % a " msg Status . pp status | ApduError e -> Format . fprintf ppf " APDU level error : % a " Header . Error . pp e | TransportError e -> Format . fprintf ppf " ...
let check_nbwritten = function | n when n = packet_length -> R . ok ( ) | n -> R . error ( TransportError ( Incomplete_write n ) )
let check_nbread = function | n when n = packet_length -> R . ok ( ) | n -> R . error ( TransportError ( Incomplete_read n ) )
let write_hidapi h ? len buf = R . reword_error ( fun s -> TransportError ( Hidapi s ) ) ( Hidapi . write h ? len Cstruct . ( to_bigarray ( sub buf 0 packet_length ) ) ) >>= check_nbwritten
let read_hidapi ? timeout h buf = R . reword_error ( fun s -> TransportError ( Hidapi s ) ) ( Hidapi . read ? timeout h buf packet_length ) >>= check_nbread
let write_ping ( ? buf = Cstruct . create packet_length ) h = check_buflen buf ; let open Cstruct in BE . set_uint16 buf 0 channel ; set_uint8 buf 2 ping ; BE . set_uint16 buf 3 0 ; memset ( sub buf 5 59 ) 0 ; write_hidapi h buf
let write_apdu ? pp ( ? buf = Cstruct . create packet_length ) h p = check_buflen buf ; let apdu_len = Apdu . length p in let apdu_buf = Cstruct . create apdu_len in let _nb_written = Apdu . write apdu_buf p in begin match pp with | None -> ( ) | Some pp -> Format . fprintf pp " -> RE...
let read ? pp ( ? buf = Cstruct . create packet_length ) h = check_buflen buf ; let expected_seq = ref 0 in let full_payload = ref ( Cstruct . create 0 ) in let payload = ref ( Cstruct . create 0 ) in let rec inner ( ) = read_hidapi ~ timeout : 600_000 h ( Cstruct . to_bigarray...
let ping ? pp ? buf h = write_ping ? buf h >>= fun ( ) -> read ? pp ? buf h >>| ignore
let apdu ? pp ( ? msg " " ) = ? buf h apdu = write_apdu ? pp ? buf h apdu >>= fun ( ) -> read ? pp ? buf h >>= fun ( status , payload ) -> begin match pp with | None -> ( ) | Some pp -> Format . fprintf pp " <- RESP [ % a ] % a . " @ Status . pp status Cstruct . ...
let write_payload ? pp ( ? msg " = write_payload " ) ? buf ( ? mark_last = false ) ~ cmd ? p1 ? p2 h cs = let rec inner cs = let cs_len = Cstruct . len cs in let lc = min Apdu . max_data_length cs_len in let last = lc = cs_len in let p1 = match last , mark_last , p1 with | true , ...
type ' a message_handler = Bigstring . t -> pos : int -> len : int -> ' a
module Handler_result = struct type ' a t = | Stop of ' a | Continue | Wait of unit Deferred . t end
module type Reader = sig type t [ @@ deriving sexp_of ] val close : t -> unit Deferred . t val is_closed : t -> bool val read_forever : t -> on_message ( : Bigstring . t -> pos : int -> len : int -> ' a Handler_result . t ) -> on_end_of_batch ( : unit -> unit ) -> ( ' a , [ ...
module Send_result = struct type message_too_big = { size : int ; max_message_size : int } [ @@ deriving sexp_of ] type ' a t = | Sent of ' a | Closed | Message_too_big of message_too_big [ @@ deriving sexp_of ] end
module type Writer = sig type t [ @@ deriving sexp_of ] val close : t -> unit Deferred . t val is_closed : t -> bool val monitor : t -> Monitor . t val bytes_to_write : t -> int val stopped : t -> unit Deferred . t val flushed : t -> unit Deferred . t val ready_to_write : t -> unit Deferred ...
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s iter = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s time % d : % Fs -> average % Fs \ n " %! s ! cpt ( t1 . - t0 ) ( ( t1 . - t0 ) . / ( float iter ) ) ; tot_time := ! t...
let devices = measure_time Spoc . Devices . init " init " 1
let tile_dim = ref 32l
let block_rows = ref 8l
let transpose = kern idata odata -> let open Std in let mutable x = thread_idx_x + block_idx_x * @ tile_dim in let mutable y = thread_idx_y + block_idx_y * @ tile_dim in let width = grid_dim_x * @ tile_dim in let ( tile : float32 array ) = create_array ( @ tile_dim * ( @ tile_dim + 1 ) ) ...
let _ = let nx = ref 1024 and ny = ref 1024 in let dev_id = ref 0 in let arg0 = ( " - d " , Arg . Int ( fun i -> dev_id := i ) , " Choose the device ( default : 0 ) " ) in let arg1 = ( " - nx " , Arg . Int ( fun i -> nx := i ) , " Matrix width ( default 10...
module type D = sig type t val equal : t -> t -> bool val to_string : t -> string end
module type S = sig type d type t exception Unresolved val empty : unit -> t val unknown : unit -> t val pop : t -> t val push : t -> d -> t val to_list_exn : t -> d list val top_exn : t -> d option val unify : t -> t -> unit val print : t -> unit val print_pair : string -> t -> t -> unit end
module Make ( D : D ) = struct type d = D . t type t = stack ref and h = handler ref and stack = | Empty | Unknown | Link of t | Push of { h : h ; t : t } and handler = | Unknown | Link of h | Label of d let rec rep ( t : t ) = match ! t with | Link t -> rep t | Empty | Unknown |...
let ( ) = try let k = push emp 1 in let t1 = pop k in let t2 = pop ( push k 2 ) in unify t1 t2 ; assert false with _ -> ( )
let ( ) = let t1 = unknown ( ) in let t2 = emp in unify t1 t2
let ( ) = let t1 = unknown ( ) in let t2 = push emp 1 in unify t1 t2
let ( ) = let t1 = push ( unknown ( ) ) 1 in let t2 = push emp 1 in unify t1 t2
let ( ) = let t1 = pop ( unknown ( ) ) in let t2 = pop ( push emp 1 ) in unify t1 t2
let ( ) = let t1 = pop ( unknown ( ) ) in let t2 = pop ( push ( pop ( unknown ( ) ) ) 1 ) in unify t1 t2 ; unify t2 t1
let ( ) = let t1 = pop ( push ( unknown ( ) ) 1 ) in Printf . printf " t1 is " ; print t1 ; Printf . printf " rep t1 is " ; print ( rep t1 )
let ( ) = let t1 = pop ( pop ( push ( unknown ( ) ) 1 ) ) in Printf . printf " t1 is " ; print t1 ; Printf . printf " rep t1 is " ; print ( rep t1 )
let ( ) = let k = push emp 1 in let t1 = pop k in let t2 = pop ( push k 2 ) in Printf . printf " t2 is " ; print t2 ; Printf . printf " rep of t2 is " ; print t2 ; Printf . printf " t1 is " ; print t1 ; Printf . printf " rep t1 is " ; print ( rep t1 ) ; Printf ....
module Core ( Req : Preface_specs . Traversable . WITH_TRAVERSE ) = Req
module Core_over_applicative ( A : Preface_specs . APPLICATIVE ) ( Req : Preface_specs . Traversable . WITH_TRAVERSE with type ' a t = ' a A . t ) = Core ( Req )
module Core_over_monad ( M : Preface_specs . MONAD ) ( Req : Preface_specs . Traversable . CORE with type ' a t = ' a M . t ) = Core ( Req )
module Operation ( C : Preface_specs . Traversable . CORE ) = struct type ' a t = ' a C . t type ' a iter = ' a C . iter let sequence x = C . traverse id x end
module Via ( C : Preface_specs . Traversable . CORE ) ( O : Preface_specs . Traversable . OPERATION with type ' a t = ' a C . t and type ' a iter = ' a C . iter ) = struct include C include O end
module Over_applicative ( A : Preface_specs . APPLICATIVE ) ( Req : Preface_specs . Traversable . WITH_TRAVERSE with type ' a t = ' a A . t ) = struct module Core = Core_over_applicative ( A ) ( Req ) module Operation = Operation ( Core ) include Core include Operation end
module Over_monad ( M : Preface_specs . MONAD ) ( Req : Preface_specs . Traversable . WITH_TRAVERSE with type ' a t = ' a M . t ) = struct module Core = Core_over_monad ( M ) ( Req ) module Operation = Operation ( Core ) include Core include Operation end
module Join_with_monad ( I : Preface_specs . MONAD ) ( T : functor ( M : Preface_specs . MONAD ) -> Preface_specs . TRAVERSABLE with type ' a t = ' a M . t and type ' a iter = ' a I . t ) = struct module Traversable = T include I end
module Join_with_applicative ( I : Preface_specs . APPLICATIVE ) ( T : functor ( A : Preface_specs . APPLICATIVE ) -> Preface_specs . TRAVERSABLE with type ' a t = ' a A . t and type ' a iter = ' a I . t ) = struct module Traversable = T include I end
type ctx = { map_loc : source_position * source_position -> Result_structure . loc ; fragments : ( string , Graphql_ast . fragment ) Hashtbl . t ; schema : Schema . t ; errors : ( Result_structure . loc * string ) list ref ; warnings : ( Result_structure . loc * string ) li...
module type VisitorSig = sig type t val make_self : unit -> t val enter_document : t -> ctx -> document -> unit val exit_document : t -> ctx -> document -> unit val enter_operation_definition : t -> ctx -> operation spanning -> unit val exit_operation_definition : t -> ctx -> operation spanning -> un...
module AbstractVisitor = struct let enter_document _self _ctx _ = ( ) let exit_document _self _ctx _ = ( ) let enter_operation_definition _self _ctx _ = ( ) let exit_operation_definition _self _ctx _ = ( ) let enter_fragment_definition _self _ctx _ = ( ) let exit_fragment_defini...
module Context = struct let push_type ctx type_ref = { ctx with type_stack = Option . flat_map ( fun type_ref -> Schema . lookup_type ctx . schema ( Schema . innermost_name type_ref ) ) type_ref :: ctx . type_stack ; type_literal_stack = type_ref :: ctx . type_literal_stack ; } let pu...
let rec as_schema_type_ref = function | Tr_named { item ; _ } -> Schema . Named item | Tr_list { item ; _ } -> Schema . List ( as_schema_type_ref item ) | Tr_non_null_named { item ; _ } -> Schema . NonNull ( Schema . Named item ) | Tr_non_null_list { item ; _ } -> Sc...
module Visitor ( V : VisitorSig ) = struct let enter_input_value self ctx value = match value . item with | Iv_null -> V . enter_null_value self ctx ( Source_pos . replace value ( ) ) | Iv_int i -> V . enter_int_value self ctx ( Source_pos . replace value i ) | Iv_float f -> V . ent...
let find_fragments doc = let open Graphql_ast in let open Source_pos in let lookup = Hashtbl . create 1 in let ( ) = List . iter ( function | Fragment fragment -> Hashtbl . add lookup fragment . item . fg_name . item fragment . item | _ -> ( ) ) doc in lookup
let make_context config document = { map_loc = config . Generator_utils . map_loc ; fragments = find_fragments document ; schema = config . Generator_utils . schema ; errors = ref [ ] ; warnings = ref [ ] ; type_stack = [ ] ; type_literal_stack = [ ] ; input_type_stack =...
module type G = sig val is_directed : bool type t module V : Sig . COMPARABLE val iter_vertex : ( V . t -> unit ) -> t -> unit val fold_vertex : ( V . t -> ' a -> ' a ) -> t -> ' a -> ' a val iter_succ : ( V . t -> unit ) -> t -> V . t -> unit val fold_succ : ( V . t...
module Dfs ( G : G ) = struct module H = Hashtbl . Make ( G . V ) let fold f i g = let h = H . create 97 in let s = Stack . create ( ) in let push v = if not ( H . mem h v ) then begin H . add h v ( ) ; Stack . push v s end in let rec loop acc = if not ( Stack . is_empty...
module Bfs ( G : G ) = struct module H = Hashtbl . Make ( G . V ) let fold f i ( g : G . t ) = let h = H . create 97 in let q = Queue . create ( ) in let push v = if not ( H . mem h v ) then begin H . add h v ( ) ; Queue . add v q end in let rec loop s = if not ( Qu...
module type GM = sig type t module V : sig type t end val iter_vertex : ( V . t -> unit ) -> t -> unit val iter_succ : ( V . t -> unit ) -> t -> V . t -> unit module Mark : sig val clear : t -> unit val get : V . t -> int val set : V . t -> int -> unit end end
module Mark ( G : GM ) = struct let dfs g = G . Mark . clear g ; let n = ref 0 in let rec visit v = if G . Mark . get v = 0 then begin incr n ; G . Mark . set v ! n ; G . iter_succ visit g v end in G . iter_vertex visit g let has_cycle g = G . Mark . clear g ; let rec visit v ...
object ( self ) method virtual record : string -> ( string * ' res ) list -> ' res method virtual constr : string -> ( string * ' res ) list -> ' res method virtual tuple : ( string * ' res ) list -> ' res method virtual bool : bool -> ' res method virtual char : char -> ' ...
object ( self ) method virtual tuple : ( string * ( ' res , string ) result ) list -> ( ' res , string ) result method virtual option : ' a . ( ' a -> ' a -> ( ' res , string ) result ) -> ' a option -> ' a option -> ( ' res , string ) result method virtu...
let src = Logs . Src . create " git . traverse " ~ doc " : logs git ' s traverse event "
module Log = ( val Logs . src_log src : Logs . LOG )
module type STORE = sig module Hash : S . HASH module Value : Value . S with type hash = Hash . t type t val root : t -> Fpath . t val read_exn : t -> Hash . t -> Value . t Lwt . t val is_shallowed : t -> Hash . t -> bool Lwt . t end
module Make ( Store : STORE ) = struct let fold t ( f : ' acc -> ? name : Fpath . t -> length : int64 -> Store . Hash . t -> Store . Value . t -> ' acc Lwt . t ) ~ path acc hash = let names = Hashtbl . create 0x100 in let open Lwt . Infix in let rec walk close rest queue acc ...
type queue_elem = | Q_symbol of Symbol . t | Q_set_of_closures_id of Set_of_closures_id . t | Q_export_id of Export_id . t
type symbols_to_export = { symbols : Symbol . Set . t ; export_ids : Export_id . Set . t ; set_of_closure_ids : Set_of_closures_id . Set . t ; set_of_closure_ids_keep_declaration : Set_of_closures_id . Set . t ; relevant_imported_closure_ids : Closure_id . Set . t ; relevant_local_...
let traverse ( ~ sets_of_closures_map : Flambda . set_of_closures Set_of_closures_id . Map . t ) ( ~ closure_id_to_set_of_closures_id : Set_of_closures_id . t Closure_id . Map . t ) ( ~ function_declarations_map : A . function_declarations Set_of_closures_id . Map . t ) ( ~ values...
let extra_remotes = list ( getenv_default " EXTRA_REMOTES " ) " "
let pins = list ( getenv_default " PINS " ) " "
let dir = getenv_default " SRC_DIR " " . "
let add_remote = let layer = ref 0 in fun remote -> ?|~ " opam remote add extra % d % s " ! layer remote ; incr layer
let pin pin = match pair pin with | ( pkg , None ) None -> . ?| " opam pin add % s -- dev - repo - n " pkg | ( pkg , Some url ) url -> . ?| " opam pin add % s % s - n " pkg url ; ;
type ' a tree = Tree of ' a * ' a tree list
let mkt x ts = Tree ( x , ts )
let rec map f ( Tree ( info , children ) ) = Tree ( f info , List . map ( map f ) children )