text
stringlengths
0
601k
let add_waiter t cb = let w = Lwt_dllist . add_l cb t in Hook . Node w
let wake { enqueue ; ctx } r = if Cancel . Fiber_context . clear_cancel_fn ctx then ( enqueue ( Ok r ) ; true ) else false
let wake_all ( t : _ t ) v = try while true do let waiter = Lwt_dllist . take_r t in ignore ( wake waiter v : bool ) done with Lwt_dllist . Empty -> ( )
let rec wake_one t v = match Lwt_dllist . take_opt_r t with | None -> ` Queue_empty | Some waiter -> if wake waiter v then ` Ok else wake_one t v
let await_internal ~ mutex ( t ' : a t ) id ( ctx : Cancel . fiber_context ) enqueue = match Cancel . Fiber_context . get_error ctx with | Some ex -> Option . iter Mutex . unlock mutex ; enqueue ( Error ex ) | None -> let resolved_waiter = ref Hook . null in let enqueue x = Ctf . note_read ~ reader : id ctx . tid ; enq...
let await ~ mutex waiters id = Suspend . enter_unchecked ( await_internal ~ mutex waiters id )
let all_equal ~ equal ~ compare ls = Option . value_map ( List . hd ls ) ls ~ default : true ~ f ( : fun h -> List . equal equal [ h ] ( List . find_all_dups ~ compare ls ) ls )
module Make ( Engine : Intf . Engine . S ) S ( Event_router : Intf . Dsl . Event_router_intf with module Engine := Engine ) Engine ( Network_state : Intf . Dsl . Network_state_intf with module Engine := Engine and module Event_router := Event_router ) Event_router = struct open Network_state module Node = Engine . Netw...
let refl = Filename . concat Filename . current_dir_name " reflector . exe "
let ( ) = let oc = Unix . open_process_out ( refl ^ " - i2o " ) in let pid = Unix . process_out_pid oc in let ( pid1 , status1 ) = Unix . waitpid [ WNOHANG ] pid in assert ( pid1 = 0 ) ; assert ( status1 = WEXITED 0 ) ; output_string oc " aa \ n " ; close_out oc ; let rec busywait ( ) = let ( pid2 , status2 ) = Unix . ...
module Steps = struct type t = [ ` PerZ of float | ` Flat of int ] let to_int t z = match t with ` PerZ mm -> Int . max 2 ( Float . to_int ( z . / mm ) ) | ` Flat n -> n end
module Edge = struct type t = float -> Vec3 . t let translate p = Fn . compose ( Vec3 . add p ) let scale s = Fn . compose ( Vec3 . scale s ) let mirror ax = Fn . compose ( Vec3 . mirror ax ) let rotate r = Fn . compose ( Vec3 . rotate r ) let rotate_about_pt r p = Fn . compose ( Vec3 . rotate_about_pt r p ) let quater...
module EdgeDrawer = struct type drawer = Vec3 . t -> Edge . t type t = { top : drawer ; bot : drawer } let make ( ? max_iter = 100 ) ( ? tolerance = 0 . 001 ) ( ~ get_bez : bool -> Vec3 . t -> Edge . t ) Points . { top_left ; top_right ; bot_left ; bot_right ; _ } = let find_between lp rp ( x , y , _ ) = let ( ( dx , d...
module Edges = struct type t = { top_left : Edge . t ; top_right : Edge . t ; bot_left : Edge . t ; bot_right : Edge . t } [ @@ deriving scad ] let map ~ f t = { top_left = f t . top_left ; top_right = f t . top_right ; bot_left = f t . bot_left ; bot_right = f t . bot_right } let of_clockwise_list_exn = function | [ t...
type config = { d1 : float ; d2 : float ; z_off : float ; thickness : float ; clearance : float ; n_steps : Steps . t ; n_facets : int ; eyelet_config : Eyelet . config option }
let default = { d1 = 2 . ; d2 = 5 . ; z_off = 0 . ; thickness = 3 . 5 ; clearance = 1 . 5 ; n_steps = ` Flat 4 ; n_facets = 1 ; eyelet_config = None }
type t = { scad : Scad . d3 ; start : Points . t ; foot : Points . t ; edge_drawer : EdgeDrawer . t ; edges : Edges . t ; screw : Eyelet . t option }
let swing_face ( ? step = Float . pi . / 24 . ) key_origin face = let quat = Quaternion . make ( KeyHole . Face . direction face ) and free , pivot , rock_z , z_sign = let ortho = Vec3 . ( normalize ( face . points . centre <-> key_origin ) ) in if Float . ( Vec3 . get_z ortho > 0 . ) then ( face . points . top_right ,...
let poly_siding ( ? x_off = 0 . ) ( ? y_off = 0 . ) ( ? z_off = 0 . ) ( ? clearance = 1 . 5 ) ( ? n_steps = ` Flat 4 ) ( ? n_facets = 1 ) ( ? d1 = 2 . ) ( ? d2 = 5 . ) ? thickness ? eyelet_config side ( key : _ KeyHole . t ) = let start_face = KeyHole . Faces . face key . faces side and thickness = Option . value ~ def...
let poly_of_config ? x_off ? y_off { d1 ; d2 ; z_off ; thickness ; clearance ; n_steps ; n_facets ; eyelet_config } = poly_siding ~ d1 ~ d2 ? x_off ? y_off ~ z_off ~ thickness ~ clearance ~ n_steps ~ n_facets ? eyelet_config
let column_drop ? z_off ? clearance ? n_steps ? n_facets ? d1 ? d2 ? thickness ? eyelet_config ~ spacing ~ columns side idx = let key , face , hanging = let c : _ Column . t = Map . find_exn columns idx in match side with | ` North -> let key = snd @@ Map . max_elt_exn c . keys in let edge_y = Vec3 . get_y key . faces ...
let drop_of_config ~ spacing { d1 ; d2 ; z_off ; thickness ; clearance ; n_steps ; n_facets ; eyelet_config } = column_drop ~ d1 ~ d2 ~ z_off ~ thickness ~ clearance ~ n_steps ~ n_facets ~ spacing ? eyelet_config
let start_direction { start = { top_left ; top_right ; _ } ; _ } = Vec3 . normalize Vec3 . ( top_left <-> top_right )
let foot_direction { foot = { top_left ; top_right ; _ } ; _ } = Vec3 . normalize Vec3 . ( top_left <-> top_right )
let to_scad t = t . scad
module Mnemonic = struct let new_random = Bip39 . of_entropy ( Hacl . Rand . gen 32 ) let to_sapling_key mnemonic = let seed_64_to_seed_32 ( seed_64 : bytes ) : bytes = assert ( Bytes . length seed_64 = 64 ) ; let first_32 = Bytes . sub seed_64 0 32 in let second_32 = Bytes . sub seed_64 32 32 in let seed_32 = Bytes . ...
let to_uri unencrypted cctxt sapling_key = if unencrypted then Tezos_signer_backends . Unencrypted . make_sapling_key sapling_key >>?= return else Tezos_signer_backends . Encrypted . encrypt_sapling_key cctxt sapling_key
let from_uri ( cctxt : # Client_context . full ) uri = Tezos_signer_backends . Encrypted . decrypt_sapling_key cctxt uri
let register ( cctxt : # Client_context . full ) ( ? force = false ) ( ? unencrypted = false ) mnemonic name = let sk = Mnemonic . to_sapling_key mnemonic in to_uri unencrypted cctxt sk >>=? fun sk_uri -> let key = { sk = sk_uri ; path = [ Spending_key . child_index sk ] ; address_index = Viewing_key . default_index ; ...
let derive ( cctxt : # Client_context . full ) ( ? force = false ) ( ? unencrypted = false ) src_name dst_name child_index = Sapling_key . find cctxt src_name >>=? fun k -> from_uri cctxt k . sk >>=? fun src_sk -> let child_index = Int32 . of_int child_index in let dst_sk = Spending_key . derive_key src_sk child_index ...
let find_vk cctxt name = Sapling_key . find cctxt name >>=? fun k -> from_uri cctxt k . sk >>=? fun sk -> return ( Viewing_key . of_sk sk )
let new_address ( cctxt : # Client_context . full ) name index_opt = Sapling_key . find cctxt name >>=? fun k -> let index = match index_opt with | None -> k . address_index | Some i -> Viewing_key . index_of_int64 ( Int64 . of_int i ) in from_uri cctxt k . sk >>=? fun sk -> return ( Viewing_key . of_sk sk ) >>=? fun v...
let export_vk cctxt name = find_vk cctxt name >>=? fun vk -> return ( Data_encoding . Json . construct Viewing_key . encoding vk )
type locked_key = | Locked of string | Unlocked of ( string * Keypair . t ) t | Hd_account of Mina_numbers . Hd_index . t
type t = { cache : locked_key Public_key . Compressed . Table . t ; path : string }
let get_privkey_filename public_key = Public_key . Compressed . to_base58_check public_key
let get_path { path ; cache } public_key = let filename = Public_key . Compressed . Table . find cache public_key |> Option . bind ~ f ( : function | Locked file | Unlocked ( file , _ ) _ -> Option . return file | Hd_account _ -> Option . return ( Public_key . Compressed . to_base58_check public_key ^ " . index ) " ) |...
let decode_public_key key file path logger = match Or_error . try_with ( fun ( ) -> Public_key . of_base58_check_decompress_exn key ) key with | Ok pk -> Some pk | Error e -> [ % log error ] error " Error decoding public key at $ path /$ file : $ error " ~ metadata : [ ( " file " , ` String file ) file ; ( " path " , `...
let reload ~ logger { cache ; path } : unit Deferred . t = let logger = Logger . extend logger [ ( " wallets_context " , ` String " Wallets . get ) " ] in Public_key . Compressed . Table . clear cache ; let % bind ( ) = File_system . create_dir path in let % bind files = Sys . readdir path >>| Array . to_list in let % ...
let load ~ logger ~ disk_location = let t = { cache = Public_key . Compressed . Table . create ( ) ; path = disk_location ^/ " store " } in let % map ( ) = reload ~ logger t in t
let import_keypair_helper t keypair write_keypair = let compressed_pk = Public_key . compress keypair . Keypair . public_key in let privkey_path = get_path t compressed_pk in let % bind ( ) = write_keypair privkey_path in let % map ( ) = Unix . chmod privkey_path ~ perm : 0o600 in ignore ( Public_key . Compressed . Tab...
let import_keypair t keypair ~ password = import_keypair_helper t keypair ( fun privkey_path -> Secret_keypair . write_exn keypair ~ privkey_path ~ password )
let import_keypair_terminal_stdin t keypair = import_keypair_helper t keypair ( fun privkey_path -> Secret_keypair . Terminal_stdin . write_exn keypair ~ privkey_path )
let generate_new t ~ password : Public_key . Compressed . t Deferred . t = let keypair = Keypair . create ( ) in import_keypair t keypair ~ password
let create_hd_account t ~ hd_index : ( Public_key . Compressed . t , string ) string Deferred . Result . t = let open Deferred . Result . Let_syntax in let % bind public_key = Hardware_wallets . compute_public_key ~ hd_index in let compressed_pk = Public_key . compress public_key in let index_path = t . path ^/ Public_...
let delete ( { cache ; _ } as t : t ) t ( pk : Public_key . Compressed . t ) t : ( unit , [ ` Not_found ] ) Deferred . Result . t = Hashtbl . remove cache pk ; Deferred . Or_error . try_with ~ here [ :% here ] here ( fun ( ) -> Unix . remove ( get_path t pk ) pk ) |> Deferred . Result . map_error ~ f ( : fun _ -> ` Not...
let pks ( { cache ; _ } : t ) t = Public_key . Compressed . Table . keys cache
let find_unlocked ( { cache ; _ } : t ) t ~ needle = Public_key . Compressed . Table . find cache needle |> Option . bind ~ f ( : function | Locked _ -> None | Unlocked ( _ , kp ) kp -> Some kp | Hd_account _ -> None )
let find_identity ( { cache ; _ } : t ) t ~ needle = Public_key . Compressed . Table . find cache needle |> Option . bind ~ f ( : function | Locked _ -> None | Unlocked ( _ , kp ) kp -> Some ( ` Keypair kp ) kp | Hd_account index -> Some ( ` Hd_index index ) index )
let check_locked { cache ; _ } ~ needle = Public_key . Compressed . Table . find cache needle |> Option . map ~ f ( : function | Locked _ -> true | Unlocked _ -> false | Hd_account _ -> true )
let unlock { cache ; path } ~ needle ~ password = let unlock_keypair = function | Locked file -> Secret_keypair . read ~ privkey_path ( : path ^/ file ) file ~ password |> Deferred . Result . map_error ~ f ( : fun e -> ` Key_read_error e ) e |> Deferred . Result . map ~ f ( : fun kp -> Public_key . Compressed . Table ....
let lock { cache ; _ } ~ needle = Public_key . Compressed . Table . change cache needle ~ f ( : function | Some ( Unlocked ( file , _ ) _ ) _ -> Some ( Locked file ) file | k -> k )
let get_tracked_keypair ~ logger ~ which ~ read_from_env_exn ~ conf_dir pk = let % bind wallets = load ~ logger ~ disk_location ( : conf_dir ^/ " wallets ) " in let sk_file = get_path wallets pk in read_from_env_exn ~ which sk_file ( module struct let logger = Logger . create ( ) let password = lazy ( Deferred . return...
type presence = | No | Yes | Eye
module Side = struct type t = Wall . t Map . M ( Int ) . t [ @@ deriving scad_jane ] type config = int -> Wall . config option end
module Sides = struct type t = { west : Side . t ; north : Side . t ; east : Side . t ; south : Side . t } [ @@ deriving scad ] let manual_body ( ? spacing = 1 . ) ~ west ~ north ~ east ~ south ( columns : _ Columns . t ) = { west = Map . filter_mapi ~ f ( : fun ~ key ~ data -> Option . map ~ f ( : fun c -> Wall . poly...
let auto_body ? d1 ? d2 ? z_off ? thickness ? index_thickness ? north_clearance ? south_clearance ? side_clearance ? n_steps ? n_facets ? north_lookup ? south_lookup ? west_lookup ? east_lookup ? eyelet_config Plate . { config = { spacing ; _ } ; body ; _ } = Sides . auto ? d1 ? d2 ? z_off ? thickness ? index_thickness...
let auto_thumb ( ? d1 = 1 . ) ( ? d2 = 3 . ) ( ? z_off = 0 . ) ( ? thickness = 3 . 5 ) ? index_thickness ( ? north_clearance = 2 . 5 ) ( ? south_clearance = 2 . 5 ) ( ? side_clearance = 3 . 0 ) ( ? n_steps = ` PerZ 4 . ) ( ? n_facets = 1 ) ( ? north_lookup = fun i -> if i = 0 then Yes else No ) ( ? south_lookup = fun i...
type t = { body : Sides . t ; thumb : Sides . t }
let make ~ body ~ thumb = { body ; thumb }
let manual ~ body_west ~ body_north ~ body_east ~ body_south ~ thumb_south ~ thumb_north ~ thumb_east ~ thumb_west Plate . { config = { spacing ; _ } ; body ; thumb ; _ } = { body = Sides . manual_body ~ west : body_west ~ north : body_north ~ east : body_east ~ south : body_south ~ spacing body ; thumb = Sides . manua...
let to_scad { body ; thumb } = Scad . union [ Sides . to_scad body ; Sides . to_scad thumb ]
let collect_screws { body ; thumb } = Sides . collect_screws ~ init ( : Sides . collect_screws thumb ) body
let test_check_walrus_operator context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | ( x := True ) reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` typing_extensions . Literal [ True ] ` . " ] ; assert_type_errors { | if ( b := True ) : reveal_type ( b )...
let ( ) = " walrus " >::: [ " check_walrus_operator " >:: test_check_walrus_operator ] |> Test . run
this is a comment ) *
type t = Foo | Bar ; ;
let f = function | Foo -> print_string " 1 " | _ -> print_string " other than 1 "
let _ = print_string " hello " ; List . iter print_string ; print_string " world "
let ( ) = let iter ' ~ f xs = List . iter f xs in iter ' print_endline [ " hello " ; " world " ] method m = print_endline " hello " end inherit c method m = print_endline " bye " end
let g = function | true -> print_endline " hello "
type r = { x : int ; y : int }
let h = function | { x = 0 } -> 0 | { x = _ } -> 1
let f10 fd = let buf = Bytes . create 10 in Unix . read fd buf 0 10 ; buf
let x11 x = match x with | Some true -> 1 | Some false -> 0 | None -> 0 | Some _ -> 2
let w12 = function | ( Some _ | Some _ ) -> 1 | None -> 0 val mutable x = 1 method get_x = x end val mutable x = 10 inherit c13 method get_x ' = x end
let regexp = " ( [ \ A - Z ] [ + A - Za - z0 - 9 ] ) . " +\\ method private x = self # x + 1 end
module type DEPRECATED = sig end [ @@ ocaml . deprecated ]
module T = struct type deprecated [ @@ ocaml . deprecated ] end
let _ = let x = 1 in ( )
module A = struct let _ = let x = 1 in ( ) end
module rec B : sig type t end = struct type t = T . deprecated end
module type T = sig type t = T . deprecated end
module type S = sig val x : T . deprecated [ @@ ocaml . alert " - deprecated " ] module AA : sig type t = T . deprecated end [ @@ ocaml . alert " - deprecated " ] module rec BB : sig type t = T . deprecated end [ @@ ocaml . alert " - deprecated " ] module type T = sig type t = T . deprecated end [ @@ ocaml . alert " - ...
let foo ? x = ( ) [ %% expect { | ^ } ] |
let foo ? x ~ y = ( ) [ %% expect { | ^ } ] |
let foo ? x ( ) = ( ) [ %% expect { | } ] |
let foo ? x ~ y ( ) = ( ) [ %% expect { | } ] | [ %% expect { | ^ } ] | [ %% expect { | ^ } ] | [ %% expect { | } ] | [ %% expect { | } ] |
type loc = { loc_start : Lexing . position ; loc_end : Lexing . position ; loc_ghost : bool ; }
type t = | Comment_start | Comment_not_end | Fragile_match of string | Partial_application | Labels_omitted of string list | Method_override of string list | Partial_match of string | Non_closed_record_pattern of string | Statement_type | Unused_match | Unused_pat | Instance_variable_override of string list | Illegal_b...
type alert = { kind : string ; message : string ; def : loc ; use : loc }
let number = function | Comment_start -> 1 | Comment_not_end -> 2 | Fragile_match _ -> 4 | Partial_application -> 5 | Labels_omitted _ -> 6 | Method_override _ -> 7 | Partial_match _ -> 8 | Non_closed_record_pattern _ -> 9 | Statement_type -> 10 | Unused_match -> 11 | Unused_pat -> 12 | Instance_variable_override _ -> ...
let last_warning_number = 67 ; ;
let letter = function | ' a ' -> let rec loop i = if i = 0 then [ ] else i :: loop ( i - 1 ) in loop last_warning_number | ' b ' -> [ ] | ' c ' -> [ 1 ; 2 ] | ' d ' -> [ 3 ] | ' e ' -> [ 4 ] | ' f ' -> [ 5 ] | ' g ' -> [ ] | ' h ' -> [ ] | ' i ' -> [ ] | ' j ' -> [ ] | ' k ' -> [ 32 ; 33 ; 34 ; 35 ; 36 ; 37 ; 38 ; 39 ]...
type state = { active : bool array ; error : bool array ; alerts : ( Misc . Stdlib . String . Set . t * bool ) ; alert_errors : ( Misc . Stdlib . String . Set . t * bool ) ; }
let current = ref { active = Array . make ( last_warning_number + 1 ) true ; error = Array . make ( last_warning_number + 1 ) false ; alerts = ( Misc . Stdlib . String . Set . empty , false ) ; alert_errors = ( Misc . Stdlib . String . Set . empty , true ) ; }
let disabled = ref false
let without_warnings f = Misc . protect_refs [ Misc . R ( disabled , true ) ] f
let backup ( ) = ! current
let restore x = current := x