text
stringlengths
12
786k
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 : Loc...
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 ~ ...
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_...
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...
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 " ( ...
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_alia...
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 ....
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 " ...
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_c...
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...
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_st...
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 ;...
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
module type FUNCTOR_F = functor ( T : TYPE ) -> FUNCTOR with type ' a t = T . t * ' a
module type APPLY_F = functor ( S : SEMIGROUP ) -> APPLY with type ' a t = S . t * ' a
module type APPLICATIVE_F = functor ( M : MONOID ) -> APPLICATIVE with type ' a t = M . t * ' a
module type MONAD_F = functor ( M : MONOID ) -> MONAD with type ' a t = M . t * ' a
module type FOLDABLE_F = functor ( T : TYPE ) -> FOLDABLE with type ' a t = T . t * ' a
module type EQ_F = functor ( First : EQ ) ( Second : EQ ) -> EQ with type t = First . t * Second . t
module type SHOW_F = functor ( First : SHOW ) ( Second : SHOW ) -> SHOW with type t = First . t * Second . t
module type TRAVERSABLE_F = functor ( T : TYPE ) ( A : APPLICATIVE ) -> TRAVERSABLE with type ' a t = T . t * ' a and type ' a applicative_t = ' a A . t
module Magma : MAGMA_F = functor ( First : MAGMA ) ( Second : MAGMA ) -> struct type t = First . t * Second . t let append ( a , b ) ( a ' , b ' ) = First . append a a ' , Second . append b b ' end
module Semigroup : SEMIGROUP_F = functor ( First : SEMIGROUP ) ( Second : SEMIGROUP ) -> struct include Magma ( First ) ( Second ) end
module Monoid : MONOID_F = functor ( First : MONOID ) ( Second : MONOID ) -> struct include Semigroup ( First ) ( Second ) let empty = First . empty , Second . empty end
module Functor : FUNCTOR_F = functor ( T : TYPE ) -> struct type ' a t = T . t * ' a let map f ( a , b ) = a , f b end
module Apply : APPLY_F = functor ( S : SEMIGROUP ) -> struct include Functor ( S ) let apply ( a , f ) ( a ' , x ) = S . append a a ' , f x end
module Applicative : APPLICATIVE_F = functor ( M : MONOID ) -> struct include Apply ( M ) let pure a = M . empty , a end
module Monad : MONAD_F = functor ( M : MONOID ) -> struct include Applicative ( M ) let flat_map ( a , b ) f = match f b with | a ' , c -> M . append a a ' , c end
module Foldable : FOLDABLE_F = functor ( T : TYPE ) -> struct type ' a t = T . t * ' a let fold_left f init ( _ , x ) = f init x and fold_right f init ( _ , x ) = f x init module Fold = struct let fold_map f ( _ , x ) = f x end module Fold_Map ( M : MONOID ) = struct inclu...
module Traversable : TRAVERSABLE_F = functor ( T : TYPE ) ( A : APPLICATIVE ) -> struct type ' a t = T . t * ' a and ' a applicative_t = ' a A . t include ( Functor ( T ) : FUNCTOR with type ' a t := ' a t ) include ( Foldable ( T ) : FOLDABLE with type ' a t := ' a...
module Eq : EQ_F = functor ( First : EQ ) ( Second : EQ ) -> struct type t = First . t * Second . t let eq ( a , b ) ( a ' , b ' ) = First . eq a a ' && Second . eq b b ' end
module Semigroupoid : SEMIGROUPOID with type ( ' a , ' b ) t = ' a * ' b = struct type ( ' a , ' b ) t = ' a * ' b let compose ( _ , c ) ( a , _ ) = a , c end
module Show : SHOW_F = functor ( First : SHOW ) ( Second : SHOW ) -> struct type t = First . t * Second . t let show ( a , b ) = " ( " ^ First . show a ^ " , " ^ Second . show b ^ " ) " end
module Bifunctor : BIFUNCTOR with type ( ' a , ' b ) t = ' a * ' b = struct type ( ' a , ' b ) t = ' a * ' b let bimap f g ( a , b ) = f a , g b end
module Biapply : BIAPPLY with type ( ' a , ' b ) t = ' a * ' b = struct include Bifunctor let biapply ( f , g ) ( a , b ) = f a , g b end
module Biapplicative : BIAPPLICATIVE with type ( ' a , ' b ) t = ' a * ' b = struct include Biapply let bipure a b = a , b end
module Bifoldable : BIFOLDABLE with type ( ' a , ' b ) t = ' a * ' b = struct type ( ' a , ' b ) t = ' a * ' b let bifold_left f g init ( a , b ) = g ( f init a ) b and bifold_right f g init ( a , b ) = f a ( g b init ) module Fold_Map ( M : MONOID ) = struc...
module type BITRAVERSABLE_F = functor ( A : APPLICATIVE ) -> BITRAVERSABLE with type ' a applicative_t = ' a A . t and type ( ' a , ' b ) t = ' a * ' b
module Bitraversable : BITRAVERSABLE_F = functor ( A : APPLICATIVE ) -> struct type ( ' a , ' b ) t = ' a * ' b and ' a applicative_t = ' a A . t include ( Bifunctor : BIFUNCTOR with type ( ' a , ' b ) t := ( ' a , ' b ) t ) include ( Bifoldable : BIFOLDABLE w...
module Infix = struct include Infix . Biapply ( Biapply ) end
module T = Map . Make ( struct type t = name list let compare t1 t2 = Pervasives . compare t1 t2 end )
type result = { ty_name : name ; ty_labels : name list ; }
type return = { def_types : ( name * typ ) Zmisc . Env . t ; table : result T . t ; }
let empty = { def_types = Zmisc . Env . empty ; table = T . empty }
let recordtype ( { def_types = dtypes ; table = table } as return ) ty_list = let ( ty , l_list ) , return = try . find ty_list table , return with | Not_found -> let l_list = List . map ( fun _ -> Zident . fresh " l " ) ty_list in let l_ty_list = List . map2 ( fun l ty ...
let tuple_into_record return e_list = let ty_list = List . map ( fun e -> e . e_typ ) e_list in recordtype return ty_list
let tuplepat_into_record return e_list = recordtype return ty_list
let rec pattern return ( { p_desc = desc } as p ) = match desc with | Ewildpat | Econstpat _ | Econstr0pat _ | Evarpat _ -> p , return | Etuplepat ( p_list ) -> let p_list , return = Zmisc . map_fold pattern return p_list in tuplepat_into_recordpat return p_list | Etypeconstraintpat ( ...
let rec expression return ( { e_desc = desc } as e ) = match desc with | Elocal _ | Eglobal _ | Econst _ | Econstr0 _ | Elast _ -> e , return | Eapp ( app , e_arg , e_list ) -> let e_arg , return = expression return e_arg in let e_list , return = Zmisc . map_fold expression retu...
let rec equation return ( { eq_desc = desc } as eq ) = match desc with | EQeq ( p , e ) -> let return , e = expression return e in { eq with eq_desc = EQeq ( p , e ) } , return | EQinit ( x , e ) -> let return , e = expression return e in { eq with eq_desc = EQinit ( x ...