text
stringlengths
0
601k
let ts_equal x y = Ident . equal x . ts_ident y . ts_ident
let rec ty_equal x y = match ( x . ty_node , y . ty_node ) with | Tyvar tvx , Tyvar tvy -> tv_equal tvx tvy | Tyapp ( tsx , tylx ) , Tyapp ( tsy , tyly ) -> ts_equal tsx tsy && List . for_all2 ty_equal tylx tyly | _ -> false
module Ts = struct type t = tysymbol let equal = ts_equal let hash x = x . ts_ident . id_tag let compare x y = Ident . compare x . ts_ident y . ts_ident end
module Mts = Map . Make ( Ts )
module Hts = Hashtbl . Make ( Ts )
let ts id args = { ts_ident = id ; ts_args = args ; ts_alias = None }
let mk_ts id args alias = { ts_ident = id ; ts_args = args ; ts_alias = alias }
let ts_ident ts = ts . ts_ident
let ts_args ts = ts . ts_args
let ts_alias ts = ts . ts_alias
let ts_arity ts = List . length ts . ts_args
let fresh_ty_var ( ? loc = Location . none ) s = { ty_node = Tyvar { tv_name = Ident . create ~ loc s } }
let ty_of_var tv = { ty_node = Tyvar tv }
let ty_app ts tyl = if ts_arity ts = List . length tyl then { ty_node = Tyapp ( ts , tyl ) } else W . error ~ loc : ts . ts_ident . id_loc ( W . Bad_type_arity ( ts . ts_ident . id_str , ts_arity ts , List . length tyl ) )
let rec ty_full_inst m ty = match ty . ty_node with | Tyvar tv -> Mtv . find tv m | Tyapp ( ts , tyl ) -> ty_app ts ( List . map ( ty_full_inst m ) tyl )
let ts_match_args ts tl = try List . fold_right2 Mtv . add ts . ts_args tl Mtv . empty with Invalid_argument _ -> W . error ~ loc : ts . ts_ident . id_loc ( W . Bad_type_arity ( ts . ts_ident . id_str , ts_arity ts , List . length tl ) )
let ty_app ts tyl = match ts . ts_alias with | None -> ty_app ts tyl | Some ty -> ty_full_inst ( ts_match_args ts tyl ) ty
let rec ts_subst_ts old_ts new_ts ( { ts_ident ; ts_args ; ts_alias } as ts ) = if ts_equal old_ts ts then new_ts else let ts_alias = Option . map ( ty_subst_ts old_ts new_ts ) ts_alias in mk_ts ts_ident ts_args ts_alias match ty . ty_node with | Tyvar _ -> ty | Tyapp ( ts , tyl ) -> let ts = if ts_equal old_ts ts then...
let rec ty_subst_ty old_ts new_ts new_ty ty = match ty . ty_node with | Tyvar _ -> ty | Tyapp ( ts , tyl ) -> if ts_equal old_ts ts then ty_full_inst ( ts_match_args new_ts tyl ) new_ty else let subst ty = ty_subst_ty old_ts new_ts new_ty ty in let tyl = List . map subst tyl in ty_app ts tyl let subst ty = ty_subst_ty ...
let rec ty_match mtv ty1 ty2 = let set = function | None -> Some ty2 | Some ty1 as r when ty_equal ty1 ty2 -> r | _ -> raise Exit in match ( ty1 . ty_node , ty2 . ty_node ) with | Tyvar tv1 , _ -> Mtv . update tv1 set mtv | Tyapp ( ts1 , tyl1 ) , Tyapp ( ts2 , tyl2 ) when ts_equal ts1 ts2 -> List . fold_left2 ty_match ...
let ty_match mtv ty1 ty2 = let rec ty_inst mtv ty = match ty . ty_node with | Tyvar n -> ( try Mtv . find n mtv with Not_found -> ty ) | Tyapp ( ts , tyl ) -> { ty_node = Tyapp ( ts , List . map ( ty_inst mtv ) tyl ) } in try ty_match mtv ty1 ty2 with Exit -> raise ( TypeMismatch ( ty_inst mtv ty1 , ty2 ) )
let ty_equal_check ty1 ty2 = if not ( ty_equal ty1 ty2 ) then raise ( TypeMismatch ( ty1 , ty2 ) )
let ts_unit = ts ( Ident . create ~ loc : Location . none " unit " ) [ ]
let ts_integer = ts ( Ident . create ~ loc : Location . none " integer " ) [ ]
let ts_int = ts ( Ident . create ~ loc : Location . none " int " ) [ ]
let ts_char = ts ( Ident . create ~ loc : Location . none " char " ) [ ]
let ts_bytes = ts ( Ident . create ~ loc : Location . none " bytes " ) [ ]
let ts_string = ts ( Ident . create ~ loc : Location . none " string " ) [ ]
let ts_float = ts ( Ident . create ~ loc : Location . none " float " ) [ ]
let ts_bool = ts ( Ident . create ~ loc : Location . none " bool " ) [ ]
let ts_exn = ts ( Ident . create ~ loc : Location . none " exn " ) [ ]
let ts_array = ts ( Ident . create ~ loc : Location . none " array " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_list = ts ( Ident . create ~ loc : Location . none " list " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_option = ts ( Ident . create ~ loc : Location . none " option " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_int32 = ts ( Ident . create ~ loc : Location . none " int32 " ) [ ]
let ts_int64 = ts ( Ident . create ~ loc : Location . none " int64 " ) [ ]
let ts_nativeint = ts ( Ident . create ~ loc : Location . none " nativeint " ) [ ]
let ts_format6 = ts ( Ident . create ~ loc : Location . none " format6 " ) [ fresh_tv ~ loc : Location . none " a " ; fresh_tv ~ loc : Location . none " b " ; fresh_tv ~ loc : Location . none " c " ; fresh_tv ~ loc : Location . none " d " ; fresh_tv ~ loc : Location . none " e " ; fresh_tv ~ loc : Location . none " f "...
let ts_lazy = ts ( Ident . create ~ loc : Location . none " lazy " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_tuple = let ts_tuples = Hashtbl . create 0 in Hashtbl . add ts_tuples 0 ts_unit ; fun n -> try Hashtbl . find ts_tuples n with Not_found -> let ts_id = Ident . create ~ loc : Location . none ( " tuple " ^ string_of_int n ) in let ts_args = List . init n ( fun x -> fresh_tv ~ loc : Location . none ( " a " ^ strin...
let ts_arrow = let ta = fresh_tv ~ loc : Location . none " a " in let tb = fresh_tv ~ loc : Location . none " b " in let id = Ident . create ~ loc : Location . none " " -> in ts id [ ta ; tb ]
let is_ts_tuple ts = let ts_tuple = ts_tuple ( ts_arity ts ) in Ident . equal ts_tuple . ts_ident ts . ts_ident
let is_ts_arrow ts = Ident . equal ts_arrow . ts_ident ts . ts_ident
let ty_unit = ty_app ts_unit [ ]
let ty_integer = ty_app ts_integer [ ]
let ty_int = ty_app ts_int [ ]
let ty_bool = ty_app ts_bool [ ]
let ty_float = ty_app ts_float [ ]
let ty_char = ty_app ts_char [ ]
let ty_string = ty_app ts_string [ ]
let ty_option ty = ty_app ts_option [ ty ]
let ty_list ty = ty_app ts_list [ ty ]
let ty_tuple = function | [ ] -> ty_unit | [ ty ] -> ty | tyl -> ty_app ( ts_tuple ( List . length tyl ) ) tyl
type exn_type = | Exn_tuple of ty list | Exn_record of ( Ident . t * ty ) list
type xsymbol = { xs_ident : Ident . t ; xs_type : exn_type } [ @@ deriving show ]
let xsymbol id ty = { xs_ident = id ; xs_type = ty }
let xs_equal x y = Ident . equal x . xs_ident y . xs_ident
module Xs = struct type t = xsymbol let equal = xs_equal let compare x y = Ident . compare x . xs_ident y . xs_ident end
module Mxs = Map . Make ( Xs )
let xs_subst_ts old_ts new_ts { xs_ident ; xs_type } = let subst = function | Exn_tuple tyl -> Exn_tuple ( List . map ( ty_subst_ts old_ts new_ts ) tyl ) | Exn_record l -> Exn_record ( List . map ( fun ( id , ty ) -> ( id , ty_subst_ts old_ts new_ts ty ) ) l ) in xsymbol xs_ident ( subst xs_type )
let xs_subst_ty old_ts new_ts new_ty xs = let subst = function | Exn_tuple tyl -> let subst ty = ty_subst_ty old_ts new_ts new_ty ty in Exn_tuple ( List . map subst tyl ) | Exn_record l -> let subst ( id , ty ) = ( id , ty_subst_ty old_ts new_ts new_ty ty ) in Exn_record ( List . map subst l ) in { xs with xs_type = su...
let print_tv fmt tv = pp fmt ( if tv . tv_name . id_str = " _ " then " % a " else " ' % a " ) Ident . pp tv . tv_name
let print_ts_name fmt ts = pp fmt " [ @% a ] " @ Ident . pp ( ts_ident ts )
let rec print_ty fmt { ty_node } = print_ty_node fmt ty_node | Tyvar v -> pp fmt " % a " print_tv v | Tyapp ( ts , [ ] ) -> print_ts_name fmt ts | Tyapp ( ts , tys ) when is_ts_arrow ts -> print_arrow_ty fmt tys | Tyapp ( ts , tyl ) when is_ts_tuple ts -> pp fmt " % a " ( list ~ sep : star print_ty ) tyl | Tyapp ( ts ,...
let print_ts fmt ts = pp fmt " [ @% a % a % a ] " @ ( list ~ sep : comma ~ first : lparens ~ last : rparens print_tv ) ts . ts_args Ident . pp ( ts_ident ts ) ( fun fmt alias -> match alias with None -> ( ) | Some ty -> pp fmt " [ =% a ] " print_ty ty ) ts . ts_alias
let print_exn_type f = function | Exn_tuple tyl -> list ~ sep : star print_ty f tyl | Exn_record args -> let print_arg f ( id , ty ) = pp f " % a :% a " Ident . pp id print_ty ty in list ~ sep : semi ~ first : rbrace ~ last : lbrace print_arg f args
let print_xs f x = pp f " % a " Ident . pp x . xs_ident
module User_input = struct type t = | Ctrl_c | Escape | Backspace | Return | Char of char [ @@ deriving sexp_of ] end
module Configure_terminal = struct type t = { attr_in : Unix . Terminal_io . t ; attr_out : Unix . Terminal_io . t ; } let setattr_out fd ~ attr_out = Unix . Terminal_io . tcsetattr attr_out ~ mode : Unix . Terminal_io . TCSAFLUSH fd let setattr_in fd ~ attr_in = Unix . Terminal_io . tcsetattr attr_in ~ mode : Unix . T...
let esc rest = " \ x1b [ " ^ rest ; ;
module Direction = struct type t = | Up | Down | Left | Right [ @@ deriving enumerate ] let escape = function | Up -> esc " A " | Down -> esc " B " | Right -> esc " C " | Left -> esc " D " end
module Action = struct type t = | Clear_screen | Move_cursor_to_home | Next_line | Move of Direction . t | Switch_to_alternate_buffer | Switch_from_alternate_buffer | Erase_to_end_of_line let _compilation_fix_for_unused_constructor = Move Left let to_string = function | Clear_screen -> esc " 2J " | Erase_to_end_of_line...
let do_action writer action = Writer . write writer ( Action . to_string action ) ; Writer . flushed writer ; ;
type t = { dimensions : Screen_dimensions . t ; writer : Writer . t }
let screen_dimensions { dimensions ; _ } = dimensions
let stop_rendering t = do_action t Switch_from_alternate_buffer ; ;
let with_rendering f = let % bind tty_reader = Reader . open_file ~ buf_len : 1 " / dev / tty " in let % bind tty_writer = Writer . open_file " / dev / tty " in let input = Reader . fd tty_reader in let output = Writer . fd tty_writer in let % bind original = Configure_terminal . get_current_settings ~ input ~ output (...
module Widget = struct type t = | Text of string | Group_horizontally of t list | Stack_vertically of t list let text text = Text text let horizontal_group ts = Group_horizontally ts let vertical_group ts = Stack_vertically ts let render elts writer = let rec process = function | Text x -> Writer . writef writer " % s ...
let render t w = Widget . render w t . writer ; ;
type kind = Tap | Tun -> int -> int -> Unix . file_descr * string = " tun_opendev_byte " " tun_opendev "
let open_ kind ( ? pi = false ) false ? persist ( ? user = - 1 ) 1 ( ? group = - 1 ) 1 ( ? devname ) " " = ( ) = let persist_int = match persist with | None -> - 1 | Some false -> 0 | Some true -> 1 in opentun_stub devname kind pi persist_int user group
let opentun = open_ Tun
let opentap = open_ Tap
let closetun devname = ignore ( opentun ~ devname ~ persist : false ( ) )
let closetap devname = ignore ( opentap ~ devname ~ persist : false ( ) )
let set_ipv4 ( ? netmask = Ipaddr . V4 . Prefix . global ) global devname v4addr = let open Ipaddr . V4 in set_ipv4 devname ( to_octets v4addr ) v4addr ( to_octets ( Prefix . netmask netmask ) netmask ) netmask
let get_macaddr iface = Macaddr . of_octets_exn ( get_macaddr iface ) iface
module Opt = struct let ( ) >|= x f = match x with Some v -> Some ( f v ) v | None -> None let run = function | Some x -> x | None -> raise Not_found end
module Struct_ifaddrs = struct type t = { name : string ; sa_family : int ; addr : string option ; mask : string option ; brd : string option ; } type ptr_t external getifaddrs_stub : unit -> ptr_t option = " getifaddrs_stub " external freeifaddrs_stub : ptr_t -> unit = " freeifaddrs_stub " external iface_get : ptr_t -...
let getifaddrs ( ) = let open Struct_ifaddrs in match getifaddrs_stub ( ) with | None -> [ ] | Some start -> let rec loop acc ptr = let acc = match to_t ' ( iface_get ptr ) ptr with | None -> acc | Some t ' -> t ' :: acc in match iface_next ptr with | None -> freeifaddrs_stub start ; acc | Some p -> loop acc p in loop ...
let filter_map f l = List . fold_left ( fun a v -> match f v with Some v ' -> v ' :: a | None -> a ) a [ ] l
let getifaddrs_v4 ( ) = filter_map ( function ( ifn , ` V4 a ) a -> Some ( ifn , a ) a | _ -> None ) None @@ getifaddrs ( )
let getifaddrs_v6 ( ) = filter_map ( function ( ifn , ` V6 a ) a -> Some ( ifn , a ) | _ -> None ) None @@ getifaddrs ( )
let addrs_of_ifname ifname = filter_map ( fun ( ifn , a ) a -> if ifn = ifname then Some a else None ) None @@ getifaddrs ( )
let v4_of_ifname ifname = filter_map ( fun ( ifn , a ) a -> if ifn = ifname then Some a else None ) None @@ getifaddrs_v4 ( )
let v6_of_ifname ifname = filter_map ( fun ( ifn , a ) a -> if ifn = ifname then Some a else None ) None @@ getifaddrs_v6 ( )
let first ( a , _ ) = a
module type MAGMA_F = functor ( First : MAGMA ) ( Second : MAGMA ) -> MAGMA with type t = First . t * Second . t
module type SEMIGROUP_F = functor ( First : SEMIGROUP ) ( Second : SEMIGROUP ) -> SEMIGROUP with type t = First . t * Second . t
module type MONOID_F = functor ( First : MONOID ) ( Second : MONOID ) -> MONOID with type t = First . t * Second . t