text stringlengths 12 786k |
|---|
let exception_declarations env ed1 ed2 = Misc . for_all2 ( fun ty1 ty2 -> Ctype . equal env false [ ty1 ] [ ty2 ] ) ed1 ed2 |
let encode_val ( mut , ty ) rem = begin match mut with Asttypes . Mutable -> Predef . type_unit | Asttypes . Immutable -> Btype . newgenty Tvar end :: ty :: rem |
let meths meths1 meths2 = Meths . fold ( fun nam t2 ( ml1 , ml2 ) -> ( begin try Meths . find nam meths1 :: ml1 with Not_found -> ml1 end , t2 :: ml2 ) ) meths2 ( [ ] , [ ] ) |
let vars vars1 vars2 = Vars . fold ( fun lab v2 ( vl1 , vl2 ) -> ( begin try encode_val ( Vars . find lab vars1 ) vl1 with Not_found -> vl1 end , encode_val v2 vl2 ) ) vars2 ( [ ] , [ ] ) |
type error = Missing_field of Ident . t | Value_descriptions of Ident . t * value_description * value_description | Type_declarations of Ident . t * type_declaration * type_declaration * Includecore . type_mismatch list | Exception_declarations of Ident . t * exception_declaration * exception_decla... |
let value_descriptions env subst id vd1 vd2 = let vd2 = Subst . value_description subst vd2 in try Includecore . value_descriptions env vd1 vd2 with Includecore . Dont_match -> raise ( Error [ Value_descriptions ( id , vd1 , vd2 ) ] ) |
let type_declarations env subst id decl1 decl2 = let decl2 = Subst . type_declaration subst decl2 in let err = Includecore . type_declarations env id decl1 decl2 in if err <> [ ] then raise ( Error [ Type_declarations ( id , decl1 , decl2 , err ) ] ) |
let exception_declarations env subst id decl1 decl2 = let decl2 = Subst . exception_declaration subst decl2 in if Includecore . exception_declarations env decl1 decl2 then ( ) else raise ( Error [ Exception_declarations ( id , decl1 , decl2 ) ] ) |
let class_type_declarations env subst id decl1 decl2 = let decl2 = Subst . cltype_declaration subst decl2 in match Includeclass . class_type_declarations env decl1 decl2 with [ ] -> ( ) | reason -> raise ( Error [ Class_type_declarations ( id , decl1 , decl2 , reason ) ] ) |
let class_declarations env subst id decl1 decl2 = let decl2 = Subst . class_declaration subst decl2 in match Includeclass . class_declarations env decl1 decl2 with [ ] -> ( ) | reason -> raise ( Error [ Class_declarations ( id , decl1 , decl2 , reason ) ] ) |
let expand_module_path env path = try Env . find_modtype_expansion path env with Not_found -> raise ( Error [ Unbound_modtype_path path ] ) |
type field_desc = Field_value of string | Field_type of string | Field_exception of string | Field_module of string | Field_modtype of string | Field_class of string | Field_classtype of string |
let item_ident_name = function Tsig_value ( id , _ ) -> ( id , Field_value ( Ident . name id ) ) | Tsig_type ( id , _ , _ ) -> ( id , Field_type ( Ident . name id ) ) | Tsig_exception ( id , _ ) -> ( id , Field_exception ( Ident . name id ) ) | Tsig_mod... |
let simplify_structure_coercion cc = let rec is_identity_coercion pos = function | [ ] -> true | ( n , c ) :: rem -> n = pos && c = Tcoerce_none && is_identity_coercion ( pos + 1 ) rem in if is_identity_coercion 0 cc then Tcoerce_none else Tcoerce_structure cc |
let rec modtypes env subst mty1 mty2 = try try_modtypes env subst mty1 mty2 with Dont_match -> raise ( Error [ Module_types ( mty1 , Subst . modtype subst mty2 ) ] ) | Error reasons -> raise ( Error ( Module_types ( mty1 , Subst . modtype subst mty2 ) :: reasons ) ) match ( mty1 ,... |
let check_modtype_inclusion env mty1 path1 mty2 = try ignore ( modtypes env Subst . identity ( Mtype . strengthen env mty1 path1 ) mty2 ) with Error reasons -> raise Not_found |
let _ = Env . check_modtype_inclusion := check_modtype_inclusion |
let compunit impl_name impl_sig intf_name intf_sig = try signatures Env . initial Subst . identity impl_sig intf_sig with Error reasons -> raise ( Error ( Interface_mismatch ( impl_name , intf_name ) :: reasons ) ) |
let modtypes env mty1 mty2 = modtypes env Subst . identity mty1 mty2 |
let signatures env sig1 sig2 = signatures env Subst . identity sig1 sig2 |
let type_declarations env id decl1 decl2 = type_declarations env Subst . identity id decl1 decl2 |
let include_err ppf = function | Missing_field id -> fprintf ppf " The field ` % a ' is required but not provided " ident id | Value_descriptions ( id , d1 , d2 ) -> fprintf ppf " [ @< hv 2 > Values do not match :@ \ % a ; @< 1 - 2 > is not included in @ % a ] " @ ( value... |
let report_error ppf = function | [ ] -> ( ) | err :: errs -> let print_errs ppf errs = List . iter ( fun err -> fprintf ppf " @ % a " include_err err ) errs in fprintf ppf " [ @< v >% a % a ] " @ include_err err print_errs errs |
module A = struct type t = int let x = ( 1 : t ) let y = ( 2 : t ) let f ( z : t ) = ( x + z : t ) end |
module B = struct include A type u = t * t let p = ( ( x , y ) : u ) let g ( ( x , y ) : u ) = ( ( f x , f y ) : u ) end |
let _ = let print_pair ( x , y ) = print_int x ; print_string " , " ; print_int y ; print_newline ( ) in print_pair B . p ; print_pair ( B . g B . p ) ; print_pair ( B . g ( 123 , 456 ) ) |
module H = struct include A let f ( z : t ) = ( x - 1 : t ) end |
let _ = print_int ( H . f H . x ) ; print_newline ( ) |
module C = struct include ( A : sig type t val f : t -> int val x : t end ) let z = f x end |
let _ = print_int C . z ; print_newline ( ) ; print_int ( C . f C . x ) ; print_newline ( ) |
let _ = print_int x ; print_newline ( ) ; print_int ( f y ) ; print_newline ( ) |
module F ( X : sig end ) = struct let _ = print_string " F is called " ; print_newline ( ) type t = A | B of int let print_t = function A -> print_string " A " | B x -> print_int x end |
module D = struct include F ( struct end ) let test ( ) = print_t A ; print_newline ( ) ; print_t ( B 42 ) ; print_newline ( ) end |
let _ = D . test ( ) ; D . print_t D . A ; print_newline ( ) ; D . print_t ( D . B 42 ) ; print_newline ( ) |
module E = struct exception Exn of string class c = object method m = 1 end end |
module G = struct include E let _ = begin try raise ( Exn " foo " ) with Exn s -> print_string s end ; print_int ( ( new c ) # m ) ; print_newline ( ) end |
let _ = begin try raise ( G . Exn " foo " ) with G . Exn s -> print_string s end ; print_int ( ( new G . c ) # m ) ; print_newline ( ) let a = 10 module X = struct let x = 1 let z = 42 let y = 2 end exception XXX module X : sig val y : int val x : int end exception XXX val ... |
let ( ) = Printf . printf " % i / % i / % i \ n " %! X . x X . y a ; Printf . printf " % s \ n " %! ( Printexc . to_string XXX ) |
module Symbol_field = struct type t = Symbol . t * Int . t include Identifiable . Make ( Identifiable . Pair ( Symbol ) ( Int ) ) end |
type dep = | Closure of Set_of_closures_id . t | Var of Variable . t | Symbol of Symbol . t | Symbol_field of Symbol_field . t |
type state = | Not_constant | Implication of dep list |
type result = { id : state Variable . Tbl . t ; closure : state Set_of_closures_id . Tbl . t ; } |
module type Param = sig val program : Flambda . program val compilation_unit : Compilation_unit . t end |
module Inconstants ( P : Param ) ( Backend : Backend_intf . S ) = struct let program = P . program let compilation_unit = P . compilation_unit let imported_symbols = Flambda_utils . imported_symbols program let variables : state Variable . Tbl . t = Variable . Tbl . create 42 let closur... |
let inconstants_on_program ~ compilation_unit ~ backend ( program : Flambda . program ) = let module P = struct let program = program let compilation_unit = compilation_unit end in let module Backend = ( val backend : Backend_intf . S ) in let module I = Inconstants ( P ) ( Backend ) in I ... |
let variable var { id ; _ } = match Variable . Tbl . find id var with | Not_constant -> true | Implication _ -> false | exception Not_found -> false |
let closure cl { closure ; _ } = match Set_of_closures_id . Tbl . find closure cl with | Not_constant -> true | Implication _ -> false | exception Not_found -> false |
module LazyStream = struct type ' a t = Cons of ' a * ' a t Lazy . t | Nil let of_stream stream = let rec next stream = try Cons ( Stream . next stream , lazy ( next stream ) ) with Stream . Failure -> Nil in next stream let of_string str = str |> Stream . of_string |> of_stream let of... |
let implode l = String . concat " " ( List . map ( String . make 1 ) l ) |
let explode s = let l = ref [ ] in String . iter ( fun c -> l := c :: ! l ) s ; List . rev ! l |
let ( ) % f g = fun x -> g ( f x ) |
type ' token input = ' token LazyStream . t |
type ( ' token , ' result ) parser = ' token input -> ( ' result * ' token input ) option |
let parse parser input = match parser input with | Some ( res , _ ) -> Some res | None -> None |
let return x input = Some ( x , input ) |
let ( ) >>= x f = fun input -> match x input with | Some ( result ' , input ' ) -> f result ' input ' | None -> None |
let ( ) <|> x y = fun input -> match x input with | Some _ as ret -> ret | None -> y input |
let rec scan x input = match x input with | Some ( result ' , input ' ) -> LazyStream . Cons ( result ' , lazy ( scan x input ' ) ) | None -> LazyStream . Nil |
let mzero _ = None |
let any = function | LazyStream . Cons ( token , input ' ) -> Some ( token , Lazy . force input ' ) | LazyStream . Nil -> None |
let satisfy test = any >>= ( fun res -> if test res then return res else mzero ) |
let eof x = function LazyStream . Nil -> Some ( x , LazyStream . Nil ) | _ -> None |
let ( ) => x f = x >>= fun r -> return ( f r ) |
let ( ) >> x y = x >>= fun _ -> y |
let ( ) << x y = x >>= fun r -> y >>= fun _ -> return r |
let ( ) <~> x xs = x >>= fun r -> xs >>= fun rs -> return ( r :: rs ) |
let rec choice = function [ ] -> mzero | h :: t -> ( h <|> choice t ) |
let rec count n x = if n > 0 then x <~> count ( n - 1 ) x else return [ ] |
let between op ed x = op >> x << ed |
let option default x = x <|> return default |
let optional x = option ( ) ( x >> return ( ) ) |
let rec skip_many x = option ( ) ( x >>= fun _ -> skip_many x ) |
let skip_many1 x = x >> skip_many x |
let rec many x = option [ ] ( x >>= fun r -> many x >>= fun rs -> return ( r :: rs ) ) |
let many1 x = x <~> many x |
let sep_by1 x sep = x <~> many ( sep >> x ) |
let sep_by x sep = sep_by1 x sep <|> return [ ] |
let end_by1 x sep = sep_by1 x sep << sep |
let end_by x sep = end_by1 x sep <|> return [ ] |
let chainl1 x op = let rec loop a = ( op >>= fun f -> x >>= fun b -> loop ( f a b ) ) <|> return a in x >>= loop |
let chainl x op default = chainl1 x op <|> return default |
let rec chainr1 x op = x >>= fun a -> ( op >>= fun f -> chainr1 x op >>= f a ) <|> return a |
let chainr x op default = chainr1 x op <|> return default |
let exactly x = satisfy ( ( ) = x ) |
let one_of l = satisfy ( fun x -> List . mem x l ) |
let none_of l = satisfy ( fun x -> not ( List . mem l x ) ) |
let range l r = satisfy ( fun x -> l <= x && x <= r ) |
let space = one_of [ ' ' ; ' \ t ' ; ' \ r ' ; ' \ n ' ] |
let spaces = skip_many space |
let newline = exactly ' \ n ' |
let tab = exactly ' \ t ' |
let upper = range ' A ' ' Z ' |
let lower = range ' a ' ' z ' |
let digit = range ' 0 ' ' 9 ' |
let letter = lower <|> upper |
let alpha_num = letter <|> digit |
let hex_digit = range ' a ' ' f ' <|> range ' A ' ' F ' |
let oct_digit = range ' 0 ' ' 7 ' |
let lexeme x = spaces >> x |
let token s = let rec loop s i = if i >= String . length s then return s else exactly s . [ i ] >> loop s ( i + 1 ) in lexeme ( loop s 0 ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.