text
stringlengths
0
601k
let compare_minimum s1 s2 = match s1 , s2 with | N , N -> 0 | N , _ -> - 1 | _ , N -> 1 | C ( addr1 , ss1 , _ ) , C ( addr2 , ss2 , _ ) -> match Int . compare addr1 addr2 with | 0 -> AtomicBitSet . compare_minimum ss1 ss2 | n -> n
let sorted_union xs = List . fold_right union xs empty
let rec extract_unique_prefix addr2 ss2 = function | N -> N , N | C ( addr1 , ss1 , qs1 ) as self -> if addr1 < addr2 then let prefix , suffix = extract_unique_prefix addr2 ss2 qs1 in C ( addr1 , ss1 , prefix ) , suffix else if addr1 > addr2 || AtomicBitSet . equal ss1 ss2 then N , self else let ss0 , ss1 = AtomicBitSe...
let extract_unique_prefix l r = match l , r with | N , _ -> N , N | _ , N -> invalid_arg " extract_unique_prefix : r < l " | l , C ( addr2 , ss2 , _ ) -> extract_unique_prefix addr2 ss2 l
let rec extract_shared_prefix = function | C ( addr1 , ss1 , qs1 ) , C ( addr2 , ss2 , qs2 ) when addr1 = addr2 -> if AtomicBitSet . equal ss1 ss2 then let common , rest = extract_shared_prefix ( qs1 , qs2 ) in ( C ( addr1 , ss1 , common ) , rest ) else let common , ( ss1 , ss2 ) = AtomicBitSet . extract_shared_prefix ...
let extract_shared_prefix l r = extract_shared_prefix ( l , r )
let min_depth : int ref = ref 1
let art_ifreq : Trie . Meta . Freq . t ref = ref ( ` Const 1 . )
let size : int ref = ref 10
let data_type : string ref = ref " ocaml - set "
let verbose : bool ref = ref false
module Set = struct let nm = Name . gensym module type TSET = sig type t type elt val mt : unit -> t val add : t -> elt -> t val mem : t -> elt -> bool val cardinal : t -> int val fold : ( ' a -> elt -> ' a ) -> ' a -> t -> ' a val to_list : t -> elt list val name : string val show : t -> string end module NTrie = stru...
let main ( ) = let cmd_name = Sys . argv . ( 0 ) in let usage = Printf . sprintf " Usage : % s [ - size pos - int ] [ - min - depth pos - int ] [ - art - ifreq ( depth | pos - int ) ] [ - type ( trie set | ntrie set | ocaml set ) ] \ n " cmd_name in let handle_ifreq s = let ifreq = try let len = String . length s in if...
let tune_gc ( ) = ( )
let _ = tune_gc ( ) ; main ( )
module Tree = struct [ %% versioned module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V1 = struct type ( ' hash , ' account ) ' account t = | Account of ' account | Hash of ' hash | Node of ' hash * ( ' hash , ' account ) ' account t * ( ' hash , ' account ) ' account t [ @@ deriving...
module T = struct [ %% versioned module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V2 = struct type ( ' hash , ' key , ' account ) ' account t = { indexes : ( ' key * int ) int list ; depth : int ; tree : ( ' hash , ' account ) ' account Tree . Stable . V1 . t } [ @@ deriving sexp , ...
module type S = sig type hash type account_id type account type t = ( hash , account_id , account ) account T . t [ @@ deriving sexp , yojson ] yojson val of_hash : depth : int -> hash -> t val get_exn : t -> int -> account val path_exn : t -> int -> [ ` Left of hash | ` Right of hash ] list val set_exn : t -> int -> a...
let tree { T . tree ; _ } = tree
let of_hash ~ depth h = { T . indexes = [ ] ; depth ; tree = Hash h }
module Make ( Hash : sig type t [ @@ deriving equal , sexp , yojson , compare ] compare val merge : height : int -> t -> t -> t type t [ @@ deriving equal , sexp , yojson ] yojson type t [ @@ deriving equal , sexp , yojson ] yojson val data_hash : t -> Hash . t include S with type hash := Hash . t and type account_id :...
type ( ' hash , ' key , ' account ) ' account t = ( ' hash , ' key , ' account ) ' account T . t [ @@ deriving yojson ] yojson ( module struct module Hash = struct type t = Core_kernel . Md5 . t [ @@ deriving sexp , compare ] compare let equal h1 h2 = Int . equal ( compare h1 h2 ) h2 0 let to_yojson md5 = ` String ( Co...
module Stable = struct module V2 = struct type t = ( Ledger_hash . Stable . V1 . t , Account_id . Stable . V2 . t , Account . Stable . V2 . t ) Sparse_ledger_lib . Sparse_ledger . T . Stable . V2 . t [ @@ deriving yojson , sexp ] sexp let to_latest = Fn . id end end ] end
type sparse_ledger = t [ @@ deriving sexp , to_yojson ] to_yojson
module Hash = struct include Ledger_hash let merge = Ledger_hash . merge end
module Account = struct include Account let data_hash = Fn . compose Ledger_hash . of_digest Account . digest end
module Global_state = struct type t = { ledger : sparse_ledger ; fee_excess : Currency . Amount . Signed . t ; protocol_state : Zkapp_precondition . Protocol_state . View . t } [ @@ deriving sexp , to_yojson ] to_yojson end
module M = Sparse_ledger_lib . Sparse_ledger . Make ( Hash ) Hash ( Account_id ) Account_id ( Account ) Account
type account_state = [ ` Added | ` Existed ] [ @@ deriving equal ] equal
let empty ~ depth ( ) = M . of_hash ~ depth Outside_hash_image . t
module L = struct type t = M . t ref type location = int let get : t -> location -> Account . t option = fun t loc -> Option . try_with ( fun ( ) -> let account = M . get_exn ! t loc in if Public_key . Compressed ( . equal empty account . public_key ) public_key then None else Some account ) |> Option . bind ~ f : Fn ....
let of_root ~ depth ( h : Ledger_hash . t ) t = of_hash ~ depth ( Ledger_hash . of_digest ( h :> Random_oracle . Digest . t ) t ) t
let get_or_initialize_exn account_id t idx = let account = get_exn t idx in if Public_key . Compressed ( . equal empty account . public_key ) public_key then let public_key = Account_id . public_key account_id in let token_id = Account_id . token_id account_id in let delegate = if Token_id ( . equal default ) default t...
let has_locked_tokens_exn ~ global_slot ~ account_id t = let idx = find_index_exn t account_id in let _ , account = get_or_initialize_exn account_id t idx in Account . has_locked_tokens ~ global_slot account
let merkle_root t = Ledger_hash . of_hash ( merkle_root t :> Random_oracle . Digest . t ) t
let depth t = M . depth t
let handler t = let ledger = ref t in let path_exn idx = List . map ( path_exn ! ledger idx ) idx ~ f ( : function ` Left h -> h | ` Right h -> h ) h in stage ( fun ( With { request ; respond } ) -> match request with | Ledger_hash . Get_element idx -> let elt = get_exn ! ledger idx in let path = ( path_exn idx :> Rand...
type t = | SPpredef | SPpack of OCamlFind . Packages . t | SPident of string | SPdot of t * string | SPapply of t * t | SPattr of attr * t [ ` Pack of t * ( OCamlFind . Packages . t * ( string * string option ) ) | ` Ident of t * ( string * string option ) | ` AfterDot of string * string option ]
let rec strip_attr = function | SPdot ( t , s ) -> SPdot ( strip_attr t , s ) | SPapply ( t1 , t2 ) -> SPapply ( strip_attr t1 , strip_attr t2 ) | SPattr ( _ , t ) -> strip_attr t | ( SPpredef | SPpack _ | SPident _ as p ) -> p
let rec is_attred = function | SPattr _ -> true | SPapply ( t1 , t2 ) -> is_attred t1 || is_attred t2 | SPdot ( t , _ ) -> is_attred t | SPpredef | SPpack _ | SPident _ -> false
module H = Hashcons . Make ( struct type t = t_ let name = " Spath . t " let equal p1 p2 = match p1 , p2 with | SPpredef , SPpredef -> true | SPpack ps1 , SPpack ps2 -> ps1 == ps2 | SPident s1 , SPident s2 -> s1 == s2 | SPdot ( t1 , s1 ) , SPdot ( t2 , s2 ) -> t1 == t2 && s1 == s2 | SPapply ( t11 , t12 ) , SPapply ( t2...
let pack pks = non_rec_hcons & SPpack pks
let ident s = non_rec_hcons & SPident ( Hcons . string s )
let dot t s = non_rec_hcons & SPdot ( t , Hcons . string s )
let apply t1 t2 = non_rec_hcons & SPapply ( t1 , t2 )
let nhc_pack pks = SPpack pks
let nhc_ident s = SPident s
let nhc_dot t s = SPdot ( t , s )
let nhc_apply t1 t2 = SPapply ( t1 , t2 )
let nhc_attr a t = SPattr ( a , t )
let rec rec_hcons = function | SPpredef -> predef | SPpack pks -> pack & OCamlFind . Packages . hcons pks | SPident s -> ident s | SPdot ( t , s ) -> dot ( rec_hcons t ) s | SPapply ( t1 , t2 ) -> apply ( rec_hcons t1 ) ( rec_hcons t2 ) | SPattr _ as p -> p
let rec of_path = function | Pident id -> let name = Ident . name id in begin match name with | " * predef " * | " { * predef } " * -> predef | _ when name . [ 0 ] = ' { ' -> pack ( OCamlFind . Packages . of_id & String . ( sub name 1 & length name - 2 ) ) | _ -> ident name end | Pdot ( t , n , _pos ) -> dot ( of_path ...
let package_path name = let name = " { " ^ name ^ " } " in let id = Ident . create_persistent name in Path . Pident id
let rec to_path = function | SPpack pks -> package_path & OCamlFind . Packages . to_id pks | SPident s -> Pident ( Ident . create_persistent s ) | SPdot ( t , n ) -> Pdot ( to_path t , n , 0 ) | SPapply ( t1 , t2 ) -> Papply ( to_path t1 , to_path t2 ) | SPpredef -> Pident ( Ident . create_persistent " { * predef } " *...
let rec look_same p1 p2 = if p1 == p2 then true else match p1 , p2 with | SPpredef , SPpredef -> true | SPpack pks1 , SPpack pks2 -> pks1 = pks2 | SPident s1 , SPident s2 -> s1 = s2 | SPdot ( p1 , s1 ) , SPdot ( p2 , s2 ) -> s1 = s2 && look_same p1 p2 | SPapply ( p11 , p12 ) , SPapply ( p21 , p22 ) -> look_same p11 p21...
let rec of_longident = function | Lident ( " * predef " * | " { * predef } " ) * -> SPpredef | Lident s when s <> " " && s . [ 0 ] = ' { ' -> let id = String . ( sub s 1 ( length s - 2 ) ) in if id <> " " && id . [ 0 ] = ' [ ' then let packs = String . ( sub id 1 ( length id - 2 ) ) in non_rec_hcons & SPpack ( OCamlFin...
let rec to_longident = function | SPident s -> Lident s | SPpredef -> Lident " { * predef } " * | SPdot ( p , s ) -> Ldot ( to_longident p , s ) | SPapply ( p1 , p2 ) -> Lapply ( to_longident p1 , to_longident p2 ) | SPpack _ -> assert false | SPattr ( _ , p ) -> to_longident p
let print ( ? packages ` = ID ) ( ? remove_package_names = false ) ( ? just_postfix = false ) ? opened ( ? predef = false ) p0 = let name s = string & match s with | " " -> assert false | " or " | " mod " | " land " | " lor " | " lxor " | " lsl " | " lsr " | " asr " -> " ( " ^ s ^ " ) " | _ when s . [ 0 ] = ' _ ' || ( ...
let format ? packages ? remove_package_names ? just_postfix ? opened ? predef ( ) ppf p = Printer . format ( print ? packages ? remove_package_names ? just_postfix ? opened ? predef ) ppf p
let show p = Format . sprintf " % a " ( format ~ packages ` : Exact ~ predef : true ( ) ) p
let read s = Util . ParseError . catch ( fun lexbuf -> lexbuf |> XParser . pattern_longident Lexer . token |> of_longident |> fun x -> ` Ok x ) ( Lexing . from_string s )
let is_bizarre_id = function | " * dummy method " * -> true | " " -> true | s when s . [ 0 ] = ' ' # -> true | _ -> false
let rec is_bizarre = function | SPdot ( t , s ) -> is_bizarre_id s || is_bizarre t | SPapply ( t1 , t2 ) -> is_bizarre t1 || is_bizarre t2 | SPattr ( _ , t ) -> is_bizarre t | SPpredef | SPpack _ -> false | SPident s -> is_bizarre_id s
let test_read t = if not & is_bizarre t then let s = show t in match read s with | ` Error e -> !!% " Spath : % s : % S : % a . " @ e s ( Ocaml . format_with ocaml_of_t ) t ; assert false | ` Ok t ' when t = t ' -> let t = rec_hcons t in let t ' = rec_hcons t ' in if t != t ' then begin !!% " Spath : hcons : % S : % a ...
let too_short_name = function | " " -> assert false | x when String . length x > 1 -> false | x -> match x . [ 0 ] with | ' a ' . . ' z ' | ' A ' . . ' Z ' -> true | _ -> false
let short_look p = let rec f1 p = match p with | SPident _ | SPpredef -> p | SPpack pkgs -> SPident ( OCamlFind . Packages . to_id pkgs ) | SPdot ( p , name ) when too_short_name name -> SPdot ( f1 p , name ) | SPdot ( p , name ) -> begin match f0 p with | None -> SPident name | Some p -> SPdot ( p , name ) end | SPapp...
let err = T . err Spatial_reference_error
let new_spatial_reference = Lib . c " OSRNewSpatialReference " ( ptr_opt string @-> returning t )
let import_from_proj4 = Lib . c " OSRImportFromProj4 " ( t @-> string @-> returning err )
let import_from_wkt = Lib . c " OSRImportFromWkt " ( t @-> ptr string @-> returning err )
let set_well_known_geog_cs = Lib . c " OSRSetWellKnownGeogCS " ( t @-> string @-> returning err )
let destroy_spatial_reference = Lib . c " OSRDestroySpatialReference " ( t @-> returning void )
let export_to_proj4 = Lib . c " OSRExportToProj4 " ( t @-> ptr ( ptr char ) @-> returning err )
let export_to_wkt = Lib . c " OSRExportToWkt " ( t @-> ptr ( ptr char ) @-> returning err )
let export_to_pretty_wkt = Lib . c " OSRExportToPrettyWkt " ( t @-> ptr ( ptr char ) @-> int @-> returning err )
let free = Lib . c " OGRFree " ( ptr void @-> returning void )
let make kind spec = let sr = new_spatial_reference None in Gc . finalise destroy_spatial_reference sr ; let ( ) = match kind with | ` proj4 -> import_from_proj4 sr spec | ` wkt -> let spec_ptr = allocate string spec in import_from_wkt sr spec_ptr | ` name -> set_well_known_geog_cs sr spec in sr
let string_of_char_ptr p = let b = Buffer . create 256 in let continue = ref true in let i = ref 0 in while ! continue do let c = ( !@ p +@ ! i ) in if c = ' \ x00 ' then continue := false else Buffer . add_char b c ; incr i done ; Buffer . contents b
let to_proj4 sr = let s = allocate ( ptr char ) ( from_voidp char null ) in export_to_proj4 sr s ; let result = string_of_char_ptr !@ s in free ( to_voidp !@ s ) ; result
let to_wkt ( ? pretty = false ) ( ? simplify = false ) sr = let s = allocate ( ptr char ) ( from_voidp char null ) in let f x = if pretty then ( export_to_pretty_wkt sr x ( if simplify then 1 else 0 ) ) else ( export_to_wkt sr x ) in f s ; let result = string_of_char_ptr !@ s in free ( to_voidp !@ s ) ; result
type process = { pid : int ; inchan : in_channel ; outchan : out_channel ; errchan : in_channel ; }
type result = [ ` PID of int | ` ERROR of exn | ` SUCCESS ]
let create_process ? wd ? env program args = let ( in_read , in_write ) = Unix . pipe ( ) in let ( out_read , out_write ) = Unix . pipe ( ) in let ( err_read , err_write ) = Unix . pipe ( ) in let inchan = Unix . in_channel_of_descr in_read in let outchan = Unix . out_channel_of_descr out_write in let errchan = Unix . ...
let loop ( f : in_channel -> unit ) chan = try while true do f chan done with End_of_file -> ( )
let redirect_to_stdout = loop ( fun chan -> input_line chan |> print_endline )
let redirect_to_stderr = loop ( fun chan -> input_line chan |> prerr_endline )
let redirect_to_ignore = loop ( fun chan -> input_line chan |> ignore )
let exec mode ? working_directory ? env ? at_exit ? process_in ? process_out ? process_err ( ? binary = false ) program args = try let proc = create_process ? wd : working_directory ? env program args in set_binary_mode_in proc . inchan binary ; set_binary_mode_in proc . errchan binary ; set_binary_mode_out proc . outc...
let sync ? working_directory ? env ? at_exit ? process_in ? process_out ? process_err ? binary program args = match exec ` SYNC ? working_directory ? env ? at_exit ? process_in ? process_out ? process_err ? binary program args with | ` SUCCESS -> None | ` ERROR ex -> Some ex | ` PID _ -> assert false
let async ? working_directory ? env ? at_exit ? process_in ? process_out ? process_err ? binary program args = match exec ` ASYNC ? working_directory ? env ? at_exit ? process_in ? process_out ? process_err ? binary program args with | ` SUCCESS -> assert false | ( ` ERROR _ ) as x -> x | ( ` PID _ ) as x -> x
type result = Ok | Fail of int * int | Err of int | Pending
type example = { mutable description : string ; result : result }
type expectation_kind = Positive | Negative
type failure = { failure_id : int ; operation : string ; actual : string ; expected : string option ; kind : expectation_kind }
type error = { error_id : int ; message : string }
type problem = Failure of failure | Error of error
type t = { name : string ; examples : example Queue . t ; subspecs : t Queue . t ; mutable before_each : ( unit -> unit ) Queue . t ; mutable before_all : ( unit -> unit ) Queue . t ; mutable after_each : ( unit -> unit ) Queue . t ; mutable after_all : ( unit -> unit ) Queue . t }
type root_spec = { mutable spec : t ; mutable num_examples : int ; mutable num_pending : int ; problems : problem Queue . t }
let spec_stack = Stack . create ( )
let spec_queue = Queue . create ( )