text
stringlengths
0
601k
let serialize_version ( v : version ) = } ] | ; ;
let serialize_ping p = [ % bitstring { | p : 8 * 8 : littleendian } ] ; ; |
let serialize_pong p = [ % bitstring { | p : 8 * 8 : littleendian } ] ; ; |
let serialize_getdata gd = } ] | in in } ] | ; ;
let serialize_inv gd = serialize_getdata gd ; ;
let serialize_notfound nf = serialize_getdata nf ; ;
let serialize_header header = ; ;
let serialize_message message = ; ;
let serialize params message = ; ;
let min_int_as_int32 , max_int_as_int32 = Int32 . of_int min_int , Int32 . of_int max_int
let min_int_as_int64 , max_int_as_int64 = Int64 . of_int min_int , Int64 . of_int max_int
let min_int32_as_int64 , max_int32_as_int64 = Int64 . of_int32 Int32 . min_int , Int64 . of_int32 Int32 . max_int
let min_int32_as_int , max_int32_as_int = if Sys . word_size = 64 then Int32 . to_int Int32 . min_int , Int32 . to_int Int32 . max_int else 0 , 0
module Decoder = struct type error = | Incomplete | Overlong_varint | Malformed_field | Overflow of string | Unexpected_payload of string * payload_kind | Missing_field of string | Malformed_variant of string let error_to_string e = match e with | Incomplete -> " Incomplete " | Overlong_varint -> " Overlong_varint " | ...
module Encoder = struct type error = | Overflow of string let error_to_string e = match e with | Overflow fld -> Printf . sprintf " Overflow ( % S ) " fld exception Failure of error let ( ) = Printexc . register_printer ( fun exn -> match exn with | Failure e -> Some ( Printf . sprintf " Protobuf . Encoder . Failure ( ...
let failf fmt = Printf . kprintf failwith fmt
module type GEN = sig type message val message : string -> message type enum val enum : string -> enum val constant : string -> enum -> int32 -> unit type field val enum_field : enum -> field val message_field : message -> field val bool : field val int32 : field val sint32 : field val sfixed32 : field val int64 : fiel...
module Generate : sig include GEN val write : Format . formatter -> message list -> enum list -> unit struct [ @@@ ocaml . warning " - 34 " ] let ocaml_keywords = [ " and " ; " as " ; " assert " ; " asr " ; " begin " ; " class " ; " constraint " ; " do " ; " done " ; " downto " ; " effect " ; " else " ; " end " ; " exc...
type callback_buffer = string list
type tkArgs = TkToken of string | TkTokenList of tkArgs list | TkQuote of tkArgs
type cbid = int = " camltk_opentk " = " camltk_tcl_eval " = " camltk_tk_mainloop " = " camltk_tcl_direct_eval " = " camltk_splitlist " = " camltk_return " = " camltk_init " = " camltk_finalize "
let tcl_command s = ignore ( tcl_eval s ) ; ;
type event_flag = DONT_WAIT | X_EVENTS | FILE_EVENTS | TIMER_EVENTS | IDLE_EVENTS | ALL_EVENTS
let do_pending ( ) = while do_one_event [ DONT_WAIT ] do ( ) done
let ( ) = Callback . register_exception " tkerror " ( TkError " " )
let cltclinterp = ref Nativeint . zero
let ( ) = Callback . register " cltclinterp " cltclinterp
let debug = ref ( try ignore ( Sys . getenv " CAMLTKDEBUG " ) ; true with Not_found -> false )
let dump_args args = let rec print_arg = function TkToken s -> prerr_string s ; prerr_string " " | TkTokenList l -> List . iter print_arg l | TkQuote a -> prerr_string " { " ; print_arg a ; prerr_string " } " in Array . iter print_arg args ; prerr_newline ( )
let tkEval args = if ! debug then dump_args args ; let res = tcl_direct_eval args in if ! debug then begin prerr_string " " ; ->> prerr_endline res end ; res
let tkCommand args = ignore ( tkEval args )
let cCAMLtoTKwidget w = ) * TkToken ( Widget . name w )
let cTKtoCAMLwidget = function " " -> raise ( Invalid_argument " cTKtoCAMLwidget " ) | s -> Widget . get_atom s
let callback_naming_table = ( Hashtbl . create 401 : ( int , callback_buffer -> unit ) Hashtbl . t )
let callback_memo_table = ( Hashtbl . create 401 : ( any widget , int ) Hashtbl . t )
let new_function_id = let counter = ref 0 in function ( ) -> incr counter ; ! counter
let register_callback w ~ callback : f = let id = new_function_id ( ) in Hashtbl . add callback_naming_table id f ; if ( forget_type w ) <> ( forget_type Widget . dummy ) then Hashtbl . add callback_memo_table ( forget_type w ) id ; ( string_of_cbid id )
let clear_callback id = Hashtbl . remove callback_naming_table id
let remove_callbacks w = let w = forget_type w in let cb_ids = Hashtbl . find_all callback_memo_table w in List . iter clear_callback cb_ids ; for i = 1 to List . length cb_ids do Hashtbl . remove callback_memo_table w done
let destroy_hooks = ref [ ]
let add_destroy_hook f = destroy_hooks := f :: ! destroy_hooks
let _ = add_destroy_hook ( fun w -> remove_callbacks w ; Widget . remove w )
let install_cleanup ( ) = let call_destroy_hooks = function [ wname ] -> let w = cTKtoCAMLwidget wname in List . iter ( fun f -> f w ) ! destroy_hooks | _ -> raise ( TkError " bad cleanup callback " ) in let fid = new_function_id ( ) in Hashtbl . add callback_naming_table fid call_destroy_hooks ; tcl_command ( " bind a...
let prerr_cbid id = prerr_string " camlcb " ; prerr_int id
let dispatch_callback id args = if ! debug then begin prerr_cbid id ; List . iter ( fun x -> prerr_string " " ; prerr_string x ) args ; prerr_newline ( ) end ; ( Hashtbl . find callback_naming_table id ) args ; if ! debug then prerr_endline " " <<-
let protected_dispatch id args = try dispatch_callback id args with e -> Printf . eprintf " Uncaught exception : % s \ n " ( Printexc . to_string e ) ; flush stderr
let _ = Callback . register " camlcb " protected_dispatch
let _ = callback_init ( )
let default_display_name = ref " "
let default_display ( ) = ! default_display_name
let camltk_argv = ref [ ]
let keywords = [ " - display " , Arg . String ( fun s -> camltk_argv := " - display " :: s :: ! camltk_argv ) , " < disp > : X server to contact ( CamlTk ) " ; " - colormap " , Arg . String ( fun s -> camltk_argv := " - colormap " :: s :: ! camltk_argv ) , " < colormap > : colormap to use ( CamlTk ) " ; " - geometry " ...
let opentk_with_args argv = let argv0 = Sys . argv . ( 0 ) in let rec find_display = function | " - display " :: s :: xs -> s | " - colormap " :: s :: xs -> find_display xs | " - geometry " :: s :: xs -> find_display xs | " - name " :: s :: xs -> find_display xs | " - sync " :: xs -> find_display xs | " - use " :: s ::...
let opentk ( ) = opentk_with_args ! camltk_argv ; ;
let openTkClass s = opentk_with_args [ " - name " ; s ]
let openTkDisplayClass disp cl = opentk_with_args [ " - display " ; disp ; " - name " ; cl ]
let openTk ( ? display = " " ) ( ? clas = " LablTk " ) ( ) = let dispopt = match display with | " " -> [ ] | _ -> [ " - display " ; display ] in opentk_with_args ( dispopt @ [ " - name " ; clas ] )
let closeTk ( ) = tcl_command " destroy . "
let register tclname ~ callback = let s = register_callback Widget . default_toplevel ~ callback in tcl_command ( Printf . sprintf " proc % s { args } { eval { camlcb % s } $ args } " tclname s )
let test_check_protocol context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | import typing class P ( typing . Protocol ) : def foo ( self ) -> int : . . . class Alpha : def foo ( self ) -> int : return 9 def fo...
let test_check_generic_protocols context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing T = typing . TypeVar ( " T " , int , str ) class P ( typing . Protocol [ T ] ) : def foo ( self ) -> T : . . . class Alpha ( ) : def foo ( self ) -> int : return 7 def foo ( p : P [ i...
let test_check_generic_implementors context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing def foo ( l : typing . List [ int ] ) -> int : return len ( l ) } | [ ] ; assert_type_errors { | import typing class P ( typing . Protocol ) : def foo ( self ) -> typing . Union [ ...
let test_callback_protocols context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing class P ( typing . Protocol ) : def __call__ ( self , x : int , y : str ) -> bool : . . . def takesP ( f : P ) -> bool : return f ( x = 1 , y = " one " ) def exactMatch ( x : int , y : str...
let test_hash_protocol context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Hashable def foo ( h : Hashable ) -> int : return hash ( h ) foo ( None ) } | [ ] ; ( )
let ( ) = " protocol " >::: [ " check_protocols " >:: test_check_protocol ; " check_generic_implementors " >:: test_check_generic_implementors ; " check_generic_protocols " >:: test_check_generic_protocols ; " callback_protocols " >:: test_callback_protocols ; " hash_protocol " >:: test_hash_protocol ; ] |> Test . run
module Make ( MakeLog : Protocol_9p_s . LOG ) LOG ( LOGFLOW : Mirage_flow . S ) S = struct module C = Mirage_channel . Make ( MakeFLOW ) MakeFLOW type t = { channel : C . t ; read_m : Lwt_mutex . t ; mutable input_buffer : Cstruct . t ; } let create flow = let channel = C . create flow in let read_m = Lwt_mutex . creat...
module type S = sig type t val after_disconnect : t -> unit Lwt . t val disconnect : t -> unit Lwt . t val create : t -> string list -> string -> Types . FileMode . t -> unit Error . t Lwt . t val write : t -> string list -> int64 -> Cstruct . t -> unit Protocol_9p_error . t Lwt . t val read : t -> string list -> int64...
module Make ( MakeLog : Protocol_9p_s . LOG ) LOG ( LOGFLOW : Mirage_flow . S ) S = struct module Reader = Protocol_9p_buffered9PReader . Make ( MakeLog ) MakeLog ( MakeLogFLOW ) MakeLogFLOW open Log type fid = Types . Fid . t type t = { reader : Reader . t ; writer : FLOW . flow ; root : fid ; msize : int32 ; upgraded...
type ' a or_error = ( ' a , Protocol_9p_response . Err . t ) t result
module type S = sig type t type connection val connect : t -> Protocol_9p_info . t -> connection val attach : connection -> cancel : unit Lwt . t -> Protocol_9p_request . Attach . t -> Protocol_9p_response . Attach . t or_error Lwt . t val walk : connection -> cancel : unit Lwt . t -> Protocol_9p_request . Walk . t -> ...
module Version = struct type t = { msize : int32 ; version : Types . Version . t ; } [ @@ deriving sexp ] sexp let sizeof t = 4 + ( Types . Version . sizeof t . version ) version let write t rest = Int32 . write t . msize rest >>= fun rest -> Types . Version . write t . version rest let read rest = Int32 . read rest >>...
module Auth = struct type t = { afid : Fid . t ; uname : string ; aname : string ; n_uname : int32 option ; } [ @@ deriving sexp ] sexp let sizeof t = ( Fid . sizeof t . afid ) afid + 2 + ( String . length t . uname ) uname + 2 + ( String . length t . aname ) aname + ( match t . n_uname with Some _ -> 4 | None -> 0 ) 0...
module Flush = struct type t = { oldtag : Types . Tag . t ; } [ @@ deriving sexp ] sexp let sizeof _ = 2 let write t rest = Types . Tag . write t . oldtag rest let read buf = Types . Tag . read buf >>= fun ( oldtag , rest ) rest -> return ( { oldtag } , rest ) rest end
module Attach = struct type t = { fid : Fid . t ; afid : Fid . t ; uname : string ; aname : string ; n_uname : int32 option ; } [ @@ deriving sexp ] sexp let sizeof t = ( Fid . sizeof t . fid ) fid + ( Fid . sizeof t . afid ) afid + 2 + ( String . length t . uname ) uname + 2 + ( String . length t . aname ) aname + ( m...
module Walk = struct type t = { fid : Fid . t ; newfid : Fid . t ; wnames : string list ; } [ @@ deriving sexp ] sexp let sizeof t = ( Fid . sizeof t . fid ) fid + ( Fid . sizeof t . newfid ) newfid + 2 + ( List . fold_left ( ) + 0 ( List . map ( fun x -> 2 + ( String . length x ) x ) x t . wnames ) wnames ) wnames let...
module Open = struct type t = { fid : Fid . t ; mode : OpenMode . t ; } [ @@ deriving sexp ] sexp let sizeof _ = 5 let write t rest = Fid . write t . fid rest >>= fun rest -> OpenMode . write t . mode rest let read rest = Fid . read rest >>= fun ( fid , rest ) rest -> OpenMode . read rest >>= fun ( mode , rest ) rest -...
module Create = struct type t = { fid : Fid . t ; name : string ; perm : FileMode . t ; mode : OpenMode . t ; extension : string option ; } [ @@ deriving sexp ] sexp let sizeof t = ( Fid . sizeof t . fid ) fid + 2 + ( String . length t . name ) name + 4 + 1 + ( match t . extension with Some x -> 2 + ( String . length x...
module Read = struct type t = { fid : Fid . t ; offset : int64 ; count : int32 ; } [ @@ deriving sexp ] sexp let sizeof t = ( Fid . sizeof t . fid ) fid + 8 + 4 let write t rest = Fid . write t . fid rest >>= fun rest -> Int64 . write t . offset rest >>= fun rest -> Int32 . write t . count rest let read rest = Fid . re...
module Write = struct type t = { fid : Fid . t ; offset : int64 ; data : Cstruct_sexp . t ; } [ @@ deriving sexp ] sexp let equal a b = a . fid = b . fid && a . offset = b . offset && Cstruct . equal a . data b . data let sizeof_header = 4 + 8 + 4 let sizeof t = ( Fid . sizeof t . fid ) fid + 8 + 4 + ( Cstruct . length...
module Clunk = struct type t = { fid : Fid . t } [ @@ deriving sexp ] sexp let sizeof t = Fid . sizeof t . fid let write t rest = Fid . write t . fid rest let read rest = Fid . read rest >>= fun ( fid , rest ) rest -> return ( { fid } , rest ) end
module Wstat = struct type t = { fid : Fid . t ; stat : Types . Stat . t ; } [ @@ deriving sexp ] sexp let sizeof t = ( Fid . sizeof t . fid ) fid + 2 + ( Types . Stat . sizeof t . stat ) stat let write t rest = Fid . write t . fid rest >>= fun rest -> Int16 . write ( Types . Stat . sizeof t . stat ) stat rest >>= fun ...
type payload = | Version of Version . t | Auth of Auth . t | Flush of Flush . t | Attach of Attach . t | Walk of Walk . t | Open of Open . t | Create of Create . t | Read of Read . t | Write of Write . t | Clunk of Clunk . t | Remove of Remove . t | Stat of Stat . t | Wstat of Wstat . t
let equal_payload a b = match a , b with | Write a , Write b -> Write . equal a b | _ -> a = b
type t = { tag : Types . Tag . t ; payload : payload
let equal a b = Types . Tag . equal a . tag b . tag && equal_payload a . payload b . payload
let sizeof t = 4 + 1 + 2 + ( match t . payload with | Version x -> Version . sizeof x | Auth x -> Auth . sizeof x | Flush x -> Flush . sizeof x | Attach x -> Attach . sizeof x | Walk x -> Walk . sizeof x | Open x -> Open . sizeof x | Create x -> Create . sizeof x | Read x -> Read . sizeof x | Write x -> Write . sizeof ...
let write t rest = let needed = sizeof t in big_enough_for " Request " rest needed >>= fun ( ) -> let ty = match t . payload with | Version _ -> 100 | Auth _ -> 102 | Flush _ -> 108 | Attach _ -> 104 | Walk _ -> 110 | Open _ -> 112 | Create _ -> 114 | Read _ -> 116 | Write _ -> 118 | Clunk _ -> 120 | Remove _ -> 122 | ...
let read_header rest = Int8 . read rest >>= fun ( ty , rest ) rest -> Tag . read rest >>= fun ( tag , rest ) rest -> return ( ty , tag , rest ) rest
let sizeof_header = 4 + 1 + 2
let read rest = read_header rest >>= fun ( ty , tag , rest ) rest -> ( match ty with | 100 -> Version . read rest >>= fun ( x , rest ) rest -> return ( ( Version x ) x , rest ) rest | 102 -> Auth . read rest >>= fun ( x , rest ) rest -> return ( ( Auth x ) x , rest ) rest | 108 -> Flush . read rest >>= fun ( x , rest )...
let pp ppf = function | { tag ; payload = Write { Write . fid ; offset ; data } } -> let tag = Types . Tag . to_int tag in let fid = Types . Fid . to_int32 fid in let len = Cstruct . length data in Format . fprintf ppf " tag % d Write ( Writefid : % ld , offset : % Ld , len ( lendata ) lendata : % d ) d " tag fid offse...
module Auth = struct type t = { aqid : Qid . t ; } [ @@ deriving sexp ] sexp let sizeof t = Qid . sizeof t . aqid let write t buf = Qid . write t . aqid buf let read buf = Qid . read buf >>= fun ( aqid , rest ) rest -> return ( { aqid } , rest ) end
module Err = struct type t = { ename : string ; errno : int32 option ; } [ @@ deriving sexp ] sexp let sizeof t = 2 + ( String . length t . ename ) ename + ( match t . errno with Some _ -> 4 | None -> 0 ) 0 let write t buf = let ename = Data . of_string t . ename in Data . write ename buf >>= fun rest -> match t . errn...
module Flush = struct type t = unit [ @@ deriving sexp ] sexp let sizeof _ = 0 let write ( ) buf = return buf let read buf = return ( ( ) , buf ) buf end
module Attach = struct type t = { qid : Qid . t } [ @@ deriving sexp ] sexp let sizeof t = Qid . sizeof t . qid let write t buf = Qid . write t . qid buf let read buf = Qid . read buf >>= fun ( qid , rest ) rest -> return ( { qid } , rest ) rest end
module Walk = struct type t = { wqids : Qid . t list } [ @@ deriving sexp ] sexp let sizeof t = 2 + ( List . fold_left ( ) + 0 ( List . map ( fun q -> Qid . sizeof q ) q t . wqids ) wqids ) wqids let write t rest = Int16 . write ( List . length t . wqids ) wqids rest >>= fun rest -> let rec loop rest = function | [ ] -...
module Open = struct type t = { qid : Qid . t ; iounit : int32 } [ @@ deriving sexp ] sexp let sizeof t = Qid . sizeof t . qid + 4 let write t rest = Qid . write t . qid rest >>= fun rest -> Int32 . write t . iounit rest let read rest = Qid . read rest >>= fun ( qid , rest ) rest -> Int32 . read rest >>= fun ( iounit ,...
module Create = struct type t = { qid : Qid . t ; iounit : int32 ; } [ @@ deriving sexp ] sexp let sizeof t = Qid . sizeof t . qid + 4 let write t rest = Qid . write t . qid rest >>= fun rest -> Int32 . write t . iounit rest let read rest = Qid . read rest >>= fun ( qid , rest ) rest -> Int32 . read rest >>= fun ( ioun...
module Read = struct type t = { data : Cstruct . t } let equal a b = Cstruct . equal a . data b . data type _t = string [ @@ deriving sexp ] sexp let sexp_of_t t = sexp_of__t ( Cstruct . to_string t . data ) data let t_of_sexp s = let _t = _t_of_sexp s in let len = String . length _t in let buf = Cstruct . create len i...
module Write = struct type t = { count : int32 } [ @@ deriving sexp ] sexp let sizeof _ = 4 let write t rest = Int32 . write t . count rest let read rest = Int32 . read rest >>= fun ( count , rest ) rest -> return ( { count } , rest ) rest end