text
stringlengths
0
601k
let mangle ( ( nt , pos ) : label ) : nonterminal = if pos = [ ] then nt else Printf . sprintf " % s ( % s ) " nt ( Misc . separated_list_to_string mangle_po " , " pos )
type env = parameter Env . t
let subst_symbol env sym : parameter = try Env . find ( value sym ) env with Not_found -> ParameterVar sym
let apply ( param : parameter ) ( params : parameter list ) : parameter = match param with | ParameterVar sym -> assert ( params <> [ ] ) ; ParameterApp ( sym , params ) | ParameterApp _ -> assert false | ParameterAnonymous _ -> assert false
let rec subst_parameter env param : parameter = match param with | ParameterVar sym -> subst_symbol env sym | ParameterApp ( sym , params ) -> assert ( params <> [ ] ) ; apply ( subst_symbol env sym ) ( subst_parameters env params ) | ParameterAnonymous _ -> assert false List . map ( subst_parameter env ) params
module Run ( G : sig val mode : mode val sorts : SortInference . sorts val g : grammar
let sort symbol = try StringMap . find ( value symbol ) sorts with Not_found -> assert false
let sort param = match param with | ParameterVar sym -> sort sym | ParameterApp ( _ , params ) -> assert ( params <> [ ] ) ; star | ParameterAnonymous _ -> assert false
let global_attributes ( nt : symbol ) : attribute list = let param = ParameterVar ( unknown nt ) in List . concat ( List . map ( fun ( params , attrs ) -> if List . exists ( Parameters . equal param ) params then attrs else [ ] ) g . p_symbol_attributes )
let enqueue , repeatedly = let queue = Queue . create ( ) in let enqueue label = Queue . add label queue and repeatedly visit = Misc . qiter visit queue in enqueue , repeatedly
let mark , marked = let module H = Hashtbl . Make ( Label ) in let table = H . create 128 in let mark label = H . add table label ( ) and marked label = H . mem table label in mark , marked
let emit , rules = let rules = ref StringMap . empty in let emit rule = assert ( not ( StringMap . mem rule . pr_nt ! rules ) ) ; rules := StringMap . add rule . pr_nt rule ! rules and rules ( ) = ! rules in emit , rules
let new_claim ( ) : ( string -> unit ) = let names = ref StringSet . empty in let claim name = if StringSet . mem name ! names then Error . error [ ] " internal name clash over % s " name ; names := StringSet . add name ! names in claim
let mangle : label -> nonterminal = let ensure_fresh = new_claim ( ) in let module M = Fix . Memoize . ForHashedType ( Label ) in M . memoize ( fun label -> let name = mangle label in ensure_fresh ( Misc . normalize name ) ; name )
let rec recognize ( param : parameter ) : parameter = match param with | ParameterAnonymous _ -> assert false | ParameterVar _ -> param | ParameterApp ( sym , ps ) -> assert ( ps <> [ ] ) ; let x = value sym in let inst , residuals = match mode with | ExpandAll -> let inst = List . map ( fun p -> Some p ) ps and residu...
let subst_parameter env param = recognize ( subst_parameter env param )
let subst_producer env ( id , param , attrs ) = let param = subst_parameter env param in ( id , param , attrs )
let subst_producers env producers = List . map ( subst_producer env ) producers
let subst_branch env branch = { branch with pr_producers = subst_producers env branch . pr_producers }
let subst_branches env branches = List . map ( subst_branch env ) branches
let freshen : string -> string = let c = ref 0 in fun x -> Printf . sprintf " % s__menhir__ % d " x ( Misc . postincrement c )
let instantiation_env formals inst : env * symbol list = assert ( List . length formals = List . length inst ) ; let env , residuals = List . fold_right2 ( fun formal po ( env , residuals ) -> let param , residuals = match po with | Some param -> param , residuals | None -> let formal = freshen formal in ParameterVar (...
let visit label = if not ( marked label ) then begin mark label ; let ( nt , inst ) = label in let rule = StringMap . find nt g . p_rules in let formals = rule . pr_parameters in let env , residuals = instantiation_env formals inst in emit { rule with pr_nt = mangle label ; pr_parameters = residuals ; pr_branches = sub...
let ( ) = StringMap . iter ( fun nt prule -> if prule . pr_parameters = [ ] then let label = ( nt , [ ] ) in enqueue label ) g . p_rules
let subst_parameter param = subst_parameter Env . empty param
let subst_declaration ( param , info ) = assert ( sort param = star ) ; ( subst_parameter param , info )
let subst_declarations decls = List . map subst_declaration decls
type thing = | TargetParameterOfSortStar of parameter | SourceParameterOfHigherSort of parameter
let thingify_parameter param : thing = if sort param = star then TargetParameterOfSortStar ( subst_parameter param ) else SourceParameterOfHigherSort param
let thingify_attribute_declaration ( params , attrs ) = ( List . map thingify_parameter params , attrs )
let thingify_attribute_declarations decls = List . map thingify_attribute_declaration decls
let unthingify_parameter rules thing = match thing with | TargetParameterOfSortStar param -> Some param | SourceParameterOfHigherSort param -> let symbol = value ( Parameters . unvar param ) in if StringMap . mem symbol rules then Some param else None
let unthingify_attribute_declaration rules ( params , attrs ) = ( Misc . filter_map ( unthingify_parameter rules ) params , attrs )
let unthingify_attribute_declarations rules decls = List . map ( unthingify_attribute_declaration rules ) decls
let g = let p_types = subst_declarations g . p_types and p_on_error_reduce = subst_declarations g . p_on_error_reduce and things = thingify_attribute_declarations g . p_symbol_attributes in repeatedly visit ; let p_rules = rules ( ) in let p_symbol_attributes = unthingify_attribute_declarations p_rules things in { g wi...
let expand mode sorts g = let module G = Run ( struct let mode = mode let sorts = sorts let g = g end ) in G . g
module type Basic = sig include Applicative . Basic val select : ( ' a , ' b ) Either . t t -> ( ' a -> ' b ) t -> ' b t end
module type S = sig include Applicative . S val select : ( ' a , ' b ) Either . t t -> ( ' a -> ' b ) t -> ' b t val ( <*? ) : ( ' a , ' b ) Either . t t -> ( ' a -> ' b ) t -> ' b t val branch : ( ' a , ' b ) Either . t t -> ( ' a -> ' c ) t -> ( ' b -> ' c ) t -> ' c t val ifS : bool t -> ' a t -> ' a t -> ' a t val ...
type t = { descr_tables : ( File_descr . t , unit ) Table . t Read_write . t ; handle_fd_read_ready : File_descr . t -> unit ; handle_fd_read_bad : File_descr . t -> unit ; handle_fd_write_ready : File_descr . t -> unit ; handle_fd_write_bad : File_descr . t -> unit }
let invariant t : unit = try Read_write . iter t . descr_tables ~ f ( : Table . invariant ignore ignore ) with | exn -> raise_s [ % message " Select_file_descr_watcher . invariant failed " ( exn : exn ) ~ select_file_descr_watcher ( : t : t ) ] ; ;
type ' a additional_create_args = handle_fd_read_bad ( : File_descr . t -> unit ) -> handle_fd_write_bad ( : File_descr . t -> unit ) -> ' a
let create ~ handle_fd_read_bad ~ handle_fd_write_bad ~ num_file_descrs ~ handle_fd_read_ready ~ handle_fd_write_ready = { descr_tables = Read_write . create_fn ( fun ( ) -> Table . create ~ num_keys : num_file_descrs ~ key_to_int : File_descr . to_int ~ sexp_of_key : File_descr . sexp_of_t ( ) ) ; handle_fd_read_ready...
let reset_in_forked_process _ = ( )
let iter t ~ f = Read_write . iteri t . descr_tables ~ f ( : fun read_or_write table -> Table . iteri table ~ f ( : fun ~ key ~ data : _ -> f key read_or_write ) ) ; ;
module Pre = struct type t = File_descr . t list Read_write . t [ @@ deriving sexp_of ] end
let set t file_descr desired = Read_write . iteri t . descr_tables ~ f ( : fun read_or_write table -> if Read_write . get desired read_or_write then Table . set table ~ key : file_descr ~ data ( ) : else Table . remove table file_descr ) ; ;
let pre_check t = Read_write . map t . descr_tables ~ f : Table . keys
module Check_result = struct type t = { pre : Pre . t ; select_result : ( Unix . Select_fds . t , exn ) Result . t } [ @@ deriving sexp_of ] end
let thread_safe_check ( type a ) ( _ : t ) ( pre : Pre . t ) ( timeout : a Timeout . t ) ( span : a ) = let timeout = match timeout with | Never -> ` Never | Immediately -> ` Immediately | After -> ` After ( Time_ns . Span . min span Time_ns . Span . second ) in { Check_result . pre ; select_result = Result . try_with ...
let post_check t ( { Check_result . pre ; select_result } as check_result ) = try match select_result with | Error ( Unix . Unix_error ( ( EINTR | EUNKNOWNERR 514 ) , _ , _ ) ) -> ( ) | Ok { read ; write ; except } -> assert ( List . is_empty except ) ; List . iter write ~ f : t . handle_fd_write_ready ; List . iter re...
module type DataS = Data . S
module T = struct type atype type ' a thunk = { id : int ; mutable value : ' a ; meta : meta ; } and meta = { mid : int ; mutable enqueued : bool ; mutable onstack : bool ; mutable evaluate : unit -> unit ; mutable unmemo : unit -> unit ; mutable start_timestamp : TotalOrder . t ; mutable end_timestamp : TotalOrder . t...
module Eviction = struct let flush ( ) = ( ) let set_policy p = ( ) let set_limit n = ( ) end
module MakeArt ( Name : Name . S ) ( Data : Data . S ) : Art . S with type name = Name . t and type data = Data . t = struct include T type name = Name . t type data = Data . t type t = Data . t thunk let nop ( ) = ( ) let invalidator meta ts = ( if debug then Printf . printf " . . . marked invalid : % d \ n " %! ( Tot...
let tweak_gc ( ) = let open Gc in let control = get ( ) in set { control with minor_heap_size = max control . minor_heap_size ( 2 * 1024 * 1024 ) ; major_heap_increment = max control . minor_heap_size ( 4 * 1024 * 1024 ) ; } ) *
type venv = Enventry . t Symtable . t
type tenv = Types . t Symtable . t
type expty = { expr : Translate . expr ; typ : Types . t }
let assert_type expected actual = if not ( Types . check expected actual ) then failwith ( sprintf " % s expected , % s found " ( Types . to_string expected ) ( Types . to_string actual ) )
let find_type tenv type_sym = match Symtable . find type_sym tenv with | None -> failwith ( sprintf " type is not in scope : % s " ( Sym . to_string type_sym ) ) | Some t -> Types . actual_type t
let add_field venv tenv { field_name ; field_type ; _ } = Symtable . add field_name ( Enventry . VarEntry ( find_type tenv field_type ) ) venv
let add_fields venv tenv fields = List . fold_left ( fun curr_venv field -> add_field curr_venv tenv field ) venv fields
let check_nil tenv type_sym = let typ = find_type tenv type_sym in match typ with | Types . Record _ as r -> Some r | _ -> None
let fun_return_type tenv type_sym = match type_sym with | None -> Types . Unit | Some sym -> find_type tenv sym
let rec trans_expr venv tenv ( expr , pos ) = match expr with | VarExpr v -> trans_var venv tenv v | NilExpr -> { typ = Types . Nil ; expr ( ) = } | IntExpr n -> { typ = Types . Int ; expr ( ) = } | StringExpr s -> { typ = Types . String ; expr ( ) = } | CallExpr call_rec -> let typ = check_call venv tenv call_rec in {...
type typesTable = Ast . primitiveType NameMap . t ; ;
type typeEnv = typesTable * typesTable ; ;
let keywords = [ " break " ; " case " ; " class " ; " catch " ; " const " ; " continue " ; " debugger " ; " default " ; " delete " ; " do " ; " else " ; " export " ; " extends " ; " finally " ; " for " ; " function " ; " if " ; " import " ; " in " ; " instanceof " ; " new " ; " return " ; " super " ; " switch " ; " thi...
let js_keywords_set = List . fold_left ( fun acc x -> KeywordsSet . add x acc ) KeywordsSet . empty keywords ; ;
let build_map ( formals : ( string * primitiveType ) list ) = List . fold_left ( fun acc_map ( id , t ) -> NameMap . add id t acc_map ) ( NameMap . empty ) formals ; ;
let rec resolve map ft at = match ft with | T ( c ) -> if GenericMap . mem c map then ( match GenericMap . find c map with | TAny -> GenericMap . add c at map | t -> if t = at then map else raise ( MismatchedTypes ( t , at ) ) ) else raise ( UndefinedType ( c ) ) | TFun ( formals_types , ret_type ) -> ( match at with |...
let rec is_generic_type = function | TString | TExn | TNum | TBool | TUnit | TAny | TFun ( _ ) -> false | T ( _ ) -> true | TList ( t ) -> is_generic_type t | TMap ( kt , vt ) -> is_generic_type kt || is_generic_type vt | TFunGeneric ( _ ) -> true ; ;
let rec generate_ret_types map = function | T ( c ) -> if GenericMap . mem c map then ( GenericMap . find c map ) else raise ( UndefinedType ( c ) ) | TFun ( formals_types , ret_type ) -> let ftypes = List . map ( generate_ret_types map ) ( ret_type :: formals_types ) in TFun ( List . tl ftypes , List . hd ftypes ) | T...
let rec validate_types type1 type2 : ( Ast . primitiveType option ) = match ( type1 , type2 ) with | TList ( t1 ) , TList ( t2 ) -> ( match ( validate_types t1 t2 ) with | Some ( t ) -> Some ( TList ( t ) ) | None -> None ) | TMap ( k1 , v1 ) , TMap ( k2 , v2 ) -> ( match validate_types k1 k2 with | Some ( k ) -> ( mat...
let rec type_of_expr ( env : typeEnv ) = function | UnitLit -> TUnit , env | NumLit ( _ ) -> TNum , env | BoolLit ( _ ) -> TBool , env | StrLit ( _ ) -> TString , env | Binop ( e1 , op , e2 ) -> let t1 , _ = type_of_expr env e1 and t2 , _ = type_of_expr env e2 in if op = Cons then ( match t1 , t2 with | x , TList ( y )...
let type_check ( program : Ast . program ) = let predefined = Lib . predefined in List . fold_left ( fun env expr -> try let _ , env = type_of_expr env expr in env with | InvalidGenericFunctionDefinition -> raise ( TypeError ( Printf . sprintf " Error : Generic type found . Use [ Type ] to declare generic functions . "...
module type Lambda_calculus = sig type ' a repr val lambda : ( ' a repr -> ' b repr ) -> ( ' a -> ' b ) repr val apply : ( ' a -> ' b ) repr -> ' a repr -> ' b repr type ' a observation val observe : ( unit -> ' a repr ) -> ' a observation end
module type Lambda_with_list_operations = sig include Lambda_calculus val list : ( ' a repr ) list -> ' a list repr val list_map : ( ' a list repr ) -> f ( ' : a -> ' b ) repr -> ( ' b list repr ) end
module type Bioinformatics_base = sig include Lambda_with_list_operations open Biokepi_bfx_tools val pair : ' a repr -> ' b repr -> ( ' a * ' b ) repr val pair_first : ( ' a * ' b ) repr -> ' a repr val pair_second : ( ' a * ' b ) repr -> ' b repr val to_unit : ' a repr -> unit repr val input_url : string -> [ ` Raw_fi...
type effects = No_effects | Only_generative_effects | Arbitrary_effects
type coeffects = No_coeffects | Has_coeffects
let for_primitive ( prim : Clambda_primitives . primitive ) = match prim with | Pmakeblock _ | Pmakearray ( _ , Mutable ) -> Only_generative_effects , No_coeffects | Pmakearray ( _ , Immutable ) -> No_effects , No_coeffects | Pduparray ( _ , Immutable ) -> No_effects , No_coeffects | Pduparray ( _ , Mutable ) | Pduprec...
type return_type = | Float | Other
let return_type_of_primitive ( prim : Clambda_primitives . primitive ) = match prim with | Pfloatofint | Pnegfloat | Pabsfloat | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatfield _ | Parrayrefu Pfloatarray | Parrayrefs Pfloatarray -> Float | _ -> Other
type t = { mutable n : int ; m : Mutex . t ; c : Condition . t ; }
let create n = if n <= 0 then invalid_arg ( Printf . sprintf " Semaphore value must be positive , got % d " n ) ; let m = Mutex . create ( ) and c = Condition . create ( ) in { n ; m ; c ; }
let inconsistent_state fmt = Printf . kprintf ( fun msg -> raise ( Inconsistent_state msg ) ) fmt
let acquire s k = if k <= 0 then invalid_arg ( Printf . sprintf " Semaphore acquisition requires a positive value , got % d " k ) ; Mutex . lock s . m ; while s . n < k do Condition . wait s . c s . m ; done ; if not ( s . n >= k ) then inconsistent_state " Semaphore value cannot be smaller than % d , got % d " k s . n...
let release s k = if k <= 0 then invalid_arg ( Printf . sprintf " Semaphore release requires a positive value , got % d " k ) ; Mutex . lock s . m ; s . n <- s . n + k ; Condition . signal s . c ; Mutex . unlock s . m
let execute_with_weight s k f = acquire s k ; Xapi_stdext_pervasives . Pervasiveext . finally f ( fun ( ) -> release s k )
let execute s f = execute_with_weight s 1 f
module Core ( Req : Preface_specs . Semigroupoid . WITH_COMPOSE ) = Req
module Operation ( Core : Preface_specs . Semigroupoid . CORE ) = struct type ( ' a , ' b ) t = ( ' a , ' b ) Core . t let compose_right_to_left f g = Core . compose f g let compose_left_to_right f g = Core . compose g f end
module Infix ( Core : Preface_specs . Semigroupoid . CORE ) = struct type ( ' a , ' b ) t = ( ' a , ' b ) Core . t let ( % ) f g = Core . compose f g let ( <% ) f g = Core . compose f g let ( %> ) f g = Core . compose g f let ( <<< ) f g = Core . compose f g let ( >>> ) f g = Core . compose g f end
module Via_compose ( Req : Preface_specs . Semigroupoid . WITH_COMPOSE ) = struct module Core = Core ( Req ) include Core include Operation ( Core ) module Infix = Infix ( Core ) include Infix end
module Via ( Core : Preface_specs . Semigroupoid . CORE ) ( Operation : Preface_specs . Semigroupoid . OPERATION ) ( Infix : Preface_specs . Semigroupoid . INFIX ) = struct include Core include Operation include Infix module Infix = Infix end
module From_monad ( Monad : Preface_specs . Monad . CORE ) = Via_compose ( struct type ( ' a , ' b ) t = ' a -> ' b Monad . t let compose f g = Monad . compose_left_to_right g f end )
module Product ( F : Preface_specs . SEMIGROUPOID ) ( G : Preface_specs . SEMIGROUPOID ) = type ( ' a , ' b ) t = ( ' a , ' b ) F . t * ( ' a , ' b ) G . t let compose ( x1 , y1 ) ( x2 , y2 ) = ( F . compose x1 x2 , G . compose y1 y2 ) end )
type t = { major : int ; minor : int ; patch : int ; prerelease : string list ; build : string list ; }
let mk_version major minor patch prerelease build = { major ; minor ; patch ; prerelease ; build }