text stringlengths 0 601k |
|---|
let caml_bytes_equal = Primitive . simple ~ name " : caml_bytes_equal " ~ arity : 2 ~ alloc : false |
let caml_notequal = Primitive . simple ~ name " : caml_notequal " ~ arity : 2 ~ alloc : true |
let caml_string_notequal = Primitive . simple ~ name " : caml_string_notequal " ~ arity : 2 ~ alloc : false |
let caml_bytes_notequal = Primitive . simple ~ name " : caml_bytes_notequal " ~ arity : 2 ~ alloc : false |
let caml_lessequal = Primitive . simple ~ name " : caml_lessequal " ~ arity : 2 ~ alloc : true |
let caml_string_lessequal = Primitive . simple ~ name " : caml_string_lessequal " ~ arity : 2 ~ alloc : false |
let caml_bytes_lessequal = Primitive . simple ~ name " : caml_bytes_lessequal " ~ arity : 2 ~ alloc : false |
let caml_lessthan = Primitive . simple ~ name " : caml_lessthan " ~ arity : 2 ~ alloc : true |
let caml_string_lessthan = Primitive . simple ~ name " : caml_string_lessthan " ~ arity : 2 ~ alloc : false |
let caml_bytes_lessthan = Primitive . simple ~ name " : caml_bytes_lessthan " ~ arity : 2 ~ alloc : false |
let caml_greaterequal = Primitive . simple ~ name " : caml_greaterequal " ~ arity : 2 ~ alloc : true |
let caml_string_greaterequal = Primitive . simple ~ name " : caml_string_greaterequal " ~ arity : 2 ~ alloc : false |
let caml_bytes_greaterequal = Primitive . simple ~ name " : caml_bytes_greaterequal " ~ arity : 2 ~ alloc : false |
let caml_greaterthan = Primitive . simple ~ name " : caml_greaterthan " ~ arity : 2 ~ alloc : true |
let caml_string_greaterthan = Primitive . simple ~ name " : caml_string_greaterthan " ~ arity : 2 ~ alloc : false |
let caml_bytes_greaterthan = Primitive . simple ~ name " : caml_bytes_greaterthan " ~ arity : 2 ~ alloc : false |
let caml_compare = Primitive . simple ~ name " : caml_compare " ~ arity : 2 ~ alloc : true |
let caml_int_compare = Primitive . simple ~ name " : caml_int_compare " ~ arity : 2 ~ alloc : false |
let caml_float_compare = unboxed_compare " caml_float_compare " Unboxed_float |
let caml_string_compare = Primitive . simple ~ name " : caml_string_compare " ~ arity : 2 ~ alloc : false |
let caml_bytes_compare = Primitive . simple ~ name " : caml_bytes_compare " ~ arity : 2 ~ alloc : false |
let caml_nativeint_compare = unboxed_compare " caml_nativeint_compare " ( Unboxed_integer Pnativeint ) |
let caml_int32_compare = unboxed_compare " caml_int32_compare " ( Unboxed_integer Pint32 ) |
let caml_int64_compare = unboxed_compare " caml_int64_compare " ( Unboxed_integer Pint64 ) |
let comparison_primitive comparison comparison_kind = match comparison , comparison_kind with | Equal , Compare_generic -> Pccall caml_equal | Equal , Compare_ints -> Pintcomp Ceq | Equal , Compare_floats -> Pfloatcomp CFeq | Equal , Compare_strings -> Pccall caml_string_equal | Equal , Compare_bytes -> Pccall caml_byt... |
let lambda_of_loc kind loc = let loc_start = loc . Location . loc_start in let ( file , lnum , cnum ) = Location . get_pos_info loc_start in let file = if Filename . is_relative file then file else Location . rewrite_absolute_path file in let enum = loc . Location . loc_end . Lexing . pos_cnum - loc_start . Lexing . po... |
let caml_restore_raw_backtrace = Primitive . simple ~ name " : caml_restore_raw_backtrace " ~ arity : 2 ~ alloc : false |
let try_ids = Hashtbl . create 8 |
let add_exception_ident id = Hashtbl . replace try_ids id ( ) |
let remove_exception_ident id = Hashtbl . remove try_ids id |
let lambda_of_prim prim_name prim loc args arg_exps = match prim , args with | Primitive ( prim , arity ) , args when arity = List . length args -> Lprim ( prim , args , loc ) | External prim , args when prim = prim_sys_argv -> Lprim ( Pccall prim , Lconst ( Const_pointer 0 ) :: args , loc ) | External prim , args -> L... |
let check_primitive_arity loc p = let prim = lookup_primitive loc p in let ok = match prim with | Primitive ( _ , arity ) -> arity = p . prim_arity | External _ -> true | Comparison _ -> p . prim_arity = 2 | Raise _ -> p . prim_arity = 1 | Raise_with_backtrace -> p . prim_arity = 2 | Lazy_force -> p . prim_arity = 1 | ... |
let transl_primitive loc p env ty path = let prim = lookup_primitive_and_mark_used loc p env path in let has_constant_constructor = false in let prim = match specialize_primitive env ty ~ has_constant_constructor prim with | None -> prim | Some prim -> prim in let rec make_params n = if n <= 0 then [ ] else ( Ident . c... |
let primitive_is_ccall = function | Pccall _ | Pstringrefs | Pbytesrefs | Pbytessets | Parrayrefs _ | Parraysets _ | Pbigarrayref _ | Pbigarrayset _ | Pduprecord _ | Pdirapply | Prevapply -> true | _ -> false |
let primitive_needs_event_after = function | Primitive ( prim , _ ) -> primitive_is_ccall prim | External _ -> true | Comparison ( comp , knd ) -> primitive_is_ccall ( comparison_primitive comp knd ) | Lazy_force | Send | Send_self | Send_cache -> true | Raise _ | Raise_with_backtrace | Loc _ -> false |
let transl_primitive_application loc p env ty path exp args arg_exps = let prim = lookup_primitive_and_mark_used loc p env ( Some path ) in let has_constant_constructor = match arg_exps with | [ _ ; { exp_desc = Texp_construct ( _ , { cstr_tag = Cstr_constant _ } , _ ) } ] | [ { exp_desc = Texp_construct ( _ , { cstr_t... |
let report_error ppf = function | Unknown_builtin_primitive prim_name -> fprintf ppf " Unknown builtin primitive " \% s " " \ prim_name | Wrong_arity_builtin_primitive prim_name -> fprintf ppf " Wrong arity for builtin primitive " \% s " " \ prim_name |
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 ^ " unavailable . " | env -> env ) let st... |
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_class | Ins_not_sup... |
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_sequence_number of { expected : int ... |
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 " Transport level error : % a " pp_transport_... |
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 " -> REQ % a . " @ Cstruct . hexdump_pp ap... |
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 buf ) >>= fun ( ) -> begin match pp with ... |
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 . hexdump_pp payload ; Format . pp_print_flush pp ( ) end ;... |
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 , true , None -> Some 0x80 | true , 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 , [ ` Eof | ` Closed ] ) Result . t Deferred . t ... |
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 . t val send_bin_prot : t ->... |
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 := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ; |
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 ) ) in let mutable j = 0 in while j... |
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 1024 ) " ) in let arg2 = ( " - ny " , Arg . Int ( fun i -> ny := i... |
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 | Push _ -> t let rec rep_h ( h : h ) = m... |
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 . printf " now t2 is " ; print t2 |
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 ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.