text
stringlengths
12
786k
let empty = { top_level = true ; locals = M . empty } ; ;
let is_bound var env = M . mem var env . locals || H . mem globals var ; ;
let get_ref var env = try M . find var env . locals with | Not_found -> H . find globals var ; ;
let get_var var env = try ( ! get_ref var env ) with | Not_found -> unbound_var var ; ;
let get_global var = ( ! H . find globals var ) ; ;
let def_local var value env = { env with locals = M . add var ( ref value ) env . locals } ; ;
let def_global var value = with_mutex glb_mutex ( fun ( ) -> H . add globals var ( ref value ) ) ; ;
let set_var var value env = try get_ref var env := value with | Not_found -> unbound_var var ; ;
let bind_locals env var_assoc = L . fold_left ( fun m ( k , v ) -> def_local k v m ) env var_assoc ; ;
let bind_globals var_assoc = L . iter ( fun ( k , v ) -> def_global k v ) var_assoc ; ;
let init ( ) = with_mutex glb_mutex ( fun ( ) -> H . clear globals ) ; ;
type error = Module_not_found of Path . t
let env_cache = ( Hashtbl . create 59 : ( ( Env . summary * Subst . t ) , Env . t ) Hashtbl . t )
let reset_cache ( ) = Hashtbl . clear env_cache ; Env . reset_cache ( )
let extract_sig env mty = match Mtype . scrape env mty with Tmty_signature sg -> sg | _ -> fatal_error " Envaux . extract_sig "
let rec env_from_summary sum subst = try Hashtbl . find env_cache ( sum , subst ) with Not_found -> let env = match sum with Env_empty -> Env . empty | Env_value ( s , id , desc ) -> Env . add_value id ( Subst . value_description subst desc ) ( env_from_summary s subst ) | Env_type ...
let env_of_event = function None -> Env . empty | Some ev -> env_from_summary ev . Instruct . ev_typenv ev . Instruct . ev_typsubst
let report_error ppf = function | Module_not_found p -> fprintf ppf " [ @ Cannot find module % a ] . . " @@ Printtyp . path p
module VariableMap = Map . Make ( Variables )
type t = string VariableMap . t
let to_bindings env = let f variable value lst = ( variable , value ) :: lst in VariableMap . fold f env [ ]
let expand_aux env value = let bindings = to_bindings env in let f ( variable , value ) = ( ( Variables . name_of_variable variable ) , value ) in let simple_bindings = List . map f bindings in let subst s = try ( List . assoc s simple_bindings ) with Not_found -> " " in let b = Buf...
let rec expand env value = let expanded = expand_aux env value in if expanded = value then value else expand env expanded
let to_system_env env = let system_env = Array . make ( VariableMap . cardinal env ) " " in let i = ref 0 in let store variable value = system_env . ( ! i ) <- Variables . string_of_binding variable ( expand env value ) ; incr i in VariableMap . iter store env ; system_env
let lookup variable env = try Some ( expand env ( VariableMap . find variable env ) ) with Not_found -> None
let lookup_nonempty variable env = match lookup variable env with | None -> None | Some x as t -> if String . words x = [ ] then None else t
let lookup_as_bool variable env = match lookup variable env with | None -> None | Some " true " -> Some true | Some _ -> Some false
let safe_lookup variable env = match lookup variable env with | None -> " " | Some value -> value
let is_variable_defined variable env = VariableMap . mem variable env
let add variable value env = VariableMap . add variable value env
let add_if_undefined variable value env = if VariableMap . mem variable env then env else add variable value env
let append variable appened_value environment = let previous_value = safe_lookup variable environment in let new_value = previous_value ^ appened_value in VariableMap . add variable new_value environment
let add_bindings bindings env = let f env ( variable , value ) = add variable value env in List . fold_left f env bindings
let from_bindings bindings = add_bindings bindings empty
let dump_assignment log ( variable , value ) = Printf . fprintf log " % s = % s \ n " %! ( Variables . name_of_variable variable ) value
let dump log environment = List . iter ( dump_assignment log ) ( VariableMap . bindings environment )
type kind = Pre | Post
type env_initializer = out_channel -> t -> t
type initializers = { pre : ( string , env_initializer ) Hashtbl . t ; post : ( string , env_initializer ) Hashtbl . t ; }
let initializers = { pre = Hashtbl . create 10 ; post = Hashtbl . create 10 }
let get_initializers = function | Pre -> initializers . pre | Post -> initializers . post
let register_initializer kind name code = Hashtbl . add ( get_initializers kind ) name code
let apply_initializer _log _name code env = code _log env
let initialize kind log env = let f = apply_initializer log in Hashtbl . fold f ( get_initializers kind ) env
type modifier = | Include of string | Add of Variables . t * string | Append of Variables . t * string | Remove of Variables . t
type modifiers = modifier list
let ( registered_modifiers : ( string , modifiers ) Hashtbl . t ) = Hashtbl . create 20
let register_modifiers name modifiers = if name " " = then raise Empty_modifiers_name else if Hashtbl . mem registered_modifiers name then raise ( Modifiers_name_already_registered name ) else Hashtbl . add registered_modifiers name modifiers
let find_modifiers name = try Hashtbl . find registered_modifiers name with Not_found -> raise ( Modifiers_name_not_found name )
let rec apply_modifier environment = function | Include modifiers_name -> apply_modifiers environment ( find_modifiers modifiers_name ) | Add ( variable , value ) -> add variable value environment | Append ( variable , value ) -> append variable value environment | Remove variable -> remove var...
let shell cmd = let ch = Unix . open_process_in cmd in let output = input_line ch in close_in ch ; output
let os = ostype ( )
let arch = shell " uname - m "
let kernel = shell " uname - r "
let cpu = match os with | " Linux " -> shell " grep ' model name ' / proc / cpuinfo - m 1 \ | awk ' { $ 1 =$ 2 =$ 3 " " ; =\\ print $ 0 } ' \ | sed - e ' s /^ ' *// - e ' s / ' " *$// | " Darwin " -> shell " sysctl - n machdep . cpu . brand_string...
let version = string ( )
module type SeededS = sig include Hashtbl . SeededS val clean : ' a t -> unit val stats_alive : ' a t -> Hashtbl . statistics end
module type S = sig include Hashtbl . S val clean : ' a t -> unit val stats_alive : ' a t -> Hashtbl . statistics end
module GenHashTable = struct type equal = | ETrue | EFalse | EDead module MakeSeeded ( H : sig type t type ' a container val create : t -> ' a -> ' a container val hash : int -> t -> int val equal : ' a container -> t -> equal val get_data : ' a container -> ' a option val get_key : ' ...
let _obj_opt : Obj . t option -> ' a option = fun x -> match x with | None -> x | Some v -> Some ( Obj . obj v )
let obj_opt : Obj . t option -> ' a option = fun x -> Obj . magic x
module K1 = struct type ( ' k , ' d ) t = ObjEph . t let create ( ) : ( ' k , ' d ) t = ObjEph . create 1 let get_key ( t ( ' : k , ' d ) t ) : ' k option = obj_opt ( ObjEph . get_key t 0 ) let get_key_copy ( t ( ' : k , ' d ) t ) : ' k option...
module K2 = struct type ( ' k1 , ' k2 , ' d ) t = ObjEph . t let create ( ) : ( ' k1 , ' k2 , ' d ) t = ObjEph . create 2 let get_key1 ( t ( ' : k1 , ' k2 , ' d ) t ) : ' k1 option = obj_opt ( ObjEph . get_key t 0 ) let get_key1_copy ( t ( ' ...
module Kn = struct type ( ' k , ' d ) t = ObjEph . t let create n : ( ' k , ' d ) t = ObjEph . create n let length ( k ( ' : k , ' d ) t ) : int = ObjEph . length k let get_key ( t ( ' : k , ' d ) t ) ( n : int ) : ' k option = obj_opt ( ObjEph . ...
let test n check res = print_string " Test " ; print_int n ; if check res then print_string " passed . \ n " else print_string " FAILED . \ n " ; flush stderr
let eq0 = function 0 -> true | _ -> false
let eqm1 = function - 1 -> true | _ -> false
let eq1 = function 1 -> true | _ -> false
let eqtrue ( b : bool ) = b
let eqftffff = function ( false , true , false , false , false , false ) -> true | _ -> false
let eqfun delayed_check = match delayed_check ( ) with | exception Invalid_argument _ -> true | _ -> false
let f x = 1 :: 2 :: 3 :: x
let mklist len = let l = ref [ ] in for i = 1 to len do l := i :: ! l done ; ! l
type tree = Dummy | Leaf | Node of tree * tree
let rec mktree depth = if depth <= 0 then Leaf else Node ( mktree ( depth - 1 ) , mktree ( depth - 1 ) )
type ' a leftlist = Nil | Cons of ' a leftlist * ' a
let mkleftlist len = let l = ref Nil in for i = 1 to len do l := Cons ( ! l , i ) done ; ! l
type any = Any : ' a -> any
let _ = test 1 eq0 ( compare 0 0 ) ; test 2 eqm1 ( compare 0 1 ) ; test 3 eq1 ( compare 1 0 ) ; test 4 eq0 ( compare max_int max_int ) ; test 5 eqm1 ( compare min_int max_int ) ; test 6 eq1 ( compare max_int min_int ) ; test 7 eq0 ( compare " foo " " foo " ) ...
type rule = { number : int ; numvars : int ; lhs : term ; rhs : term }
let mk_rule num m n = let all_vars = union ( vars m ) ( vars n ) in let counter = ref 0 in let subst = List . map ( fun v -> incr counter ; ( v , Var ! counter ) ) ( List . rev all_vars ) in { number = num ; numvars = ! counter ; lhs = substitute subst m ; rhs = substitut...
let check_rules rules = let counter = ref 0 in List . iter ( fun r -> incr counter ; if r . number <> ! counter then failwith " Rule numbers not in sequence " ) rules ; ! counter
let pretty_rule rule = print_int rule . number ; print_string " : " ; pretty_term rule . lhs ; print_string " = " ; pretty_term rule . rhs ; print_newline ( )
let pretty_rules rules = List . iter pretty_rule rules
let reduce l m r = substitute ( matching l m ) r
let can_match l m = try let _ = matching l m in true with Failure _ -> false
let rec reducible l m = can_match l m || ( match m with | Term ( _ , sons ) -> List . exists ( reducible l ) sons | _ -> false )
let rec mreduce rules m = match rules with [ ] -> failwith " mreduce " | rule :: rest -> try reduce rule . lhs m rule . rhs with Failure _ -> mreduce rest m
let rec mrewrite1 rules m = try mreduce rules m with Failure _ -> match m with Var n -> failwith " mrewrite1 " | Term ( f , sons ) -> Term ( f , mrewrite1_sons rules sons ) [ ] -> failwith " mrewrite1 " | son :: rest -> try mrewrite1 rules son :: rest with Failure _ -> son :: mrewr...
let rec mrewrite_all rules m = try mrewrite_all rules ( mrewrite1 rules m ) with Failure _ -> m
module Lwt_error = struct open Lwt . Infix module Infix = struct let ( >>= ) m f = m >>= function | Ok x -> f x | Error ` Unimplemented -> Lwt . fail_with " Unimplemented " | Error ` Disconnected -> Lwt . fail_with " Disconnected " | Error _ -> Lwt . fail_with " Unknown error " ...
module Lwt_write_error = struct module Infix = struct open Lwt . Infix let ( >>= ) m f = m >>= function | Ok x -> f x | Error ` Is_read_only -> Lwt . fail_with " Is_read_only " | Error ` Unimplemented -> Lwt . fail_with " Unimplemented " | Error ` Disconnected -> Lwt . fail_with "...
module Infix = struct let ( ) >>= m f = m >>= function | Error e -> Lwt . return ( Error e ) | Ok x -> f x end
module FromResult = struct let ( ) >>= m f = match m with | Result . Error x -> Lwt . return ( Error x ) | Result . Ok x -> f x end
module ObjTools = struct value desc obj = if Obj . is_block obj then " tag = " ^ string_of_int ( Obj . tag obj ) else " int_val = " ^ string_of_int ( Obj . obj obj ) ; value rec to_string r = if Obj . is_int r then let i = ( Obj . magic r : int ) in string_of_int i ^ " | Cst...
module Register ( Error : Sig . Error ) = struct let current_handler = handler . val in handler . val := fun ppf default_handler -> fun [ Error . E x -> Error . print ppf x | x -> current_handler ppf default_handler x ] ; end ; fun [ Out_of_memory -> fprintf ppf " Out of memory " |...
type error_record = { msg : string ; ) * request_id : string option ; recoverable : bool }
type lambda_error = { error_message : string [ @ key " errorMessage " ] ; error_type : string [ @ key " errorType " ] }
type _ t = | RuntimeError : error_record -> [ ` unhandled ] t | ApiError : error_record -> [ ` unhandled ] t | HandlerError : lambda_error -> [ ` handled ] t
module Constants = struct let error_type_handled = " Handled " let error_type_unhandled = " Unhandled " end