text
stringlengths
0
601k
let short_match x = match x with Some x -> x | Nnoe -> 0 | A -> 1 | B -> 2 | C -> 3 | D -> 4 | E -> 5
let f = function ( Some x as y as z ) -> z ; ;
let f = fun ( ` a ( Some _ | None ) ) -> 3 ; ;
let f = fun ` a ( Some _ | None ) -> 3 ; ;
let f = fun ( ` a ( Some x ) | x ) -> 3 ; ;
let f = fun ( ` a ` b ` c ) -> 3 ; ;
let u = for i = 0 to 11 do print_int a long line ; print_int i ; print_string ; done
let u = while true do this is ; a test ; ha statement ; done
let g = f a g b b c d gh g g g g b
let f ( ) = if f a g then 3 else 4
let _ = mod_runtime := " Run_mikmatch_str " ; mod_runtime_mt := " Run_mikmatch_str_mt "
let special_regexps = let _loc = Constants . dummy_loc in [ " bol " , Special ( _loc , " " , ^ ( " bol " , Some 0 ) ) ; " eol " , Special ( _loc , " " , $ ( " eol " , Some 0 ) ) ; " bnd " , Special ( _loc , " \\ b " , ( " bnd " , Some 0 ) ) ; " any " , Special ( _loc , " . " , ( " any " , Some 1 ) ) ; ]
let string c = String . make 1 c
let quote_char = function ' [ ' | ' ] ' | ' ' * | ' . ' | ' ' \\ | ' ' ? | ' ' + | ' ' ^ | ' ' $ as c -> let s = Bytes . create 2 in Bytes . set s 0 ' ' ; \\ Bytes . set s 1 c ; Bytes . unsafe_to_string s | c -> string c
let reorder_charset l = if l = [ ] then invalid_arg " reorder_charset " ; List . sort ( fun c1 c2 -> if c1 = c2 then invalid_arg " reorder_charset : repeated char " else if c1 = ' ] ' then - 1 else if c2 = ' ] ' then 1 else if c1 = ' ' - then 1 else if c2 = ' ' - then - 1 else if c1 = ' ' ^ then 1 else if c2 = ' ' ^ th...
let compact l = let finish first last = match Char . code last - Char . code first with | 1 -> string first ^ string last | _ -> string first ^ " " - ^ string last in let rec extend first last = function | c :: rest -> match l with [ ] -> [ ] | hd :: tl -> extend hd hd tl
let compact_charset l = let rbracket = ref false and dash = ref false and caret = ref false in let normal = List . filter ( function let sorted = List . sort Char . compare normal in let special_tail = let tail = if ! dash then [ " " ] - else [ ] in if ! caret then " " ^ :: tail else tail in let tail = compact sorted @...
let add_const accu s = accu := ` String s :: ! accu
let add_var accu e = accu := ` Var ( e , false ) :: ! accu
let add_var_nocase accu e = accu := ` Var ( e , true ) :: ! accu
let rec rm_closed = function Closed ast -> rm_closed ast | ast -> ast
let rec to_string ( ? top = false ) ( ( last_group , named_groups ) as groups ) accu = function Epsilon _loc -> groups | Special ( _loc , s , _ ) -> add_const accu s ; groups | Characters ( _loc , set ) -> | Sequence ( _loc , re1 , re2 ) -> | Alternative ( _loc , re , Epsilon _ , _ , _ ) -> groups | Alternative ( _loc ...
let nocasify e = let _loc = Ast . loc_of_expr e in <: expr < $ uid : ! mod_runtime . $ nocase $ e $ >>
let process_regexp _loc ~ sharing re re_name = let accu = ref [ ] in let ( last_group , named_groups ) = to_string ~ top : true ( 0 , ( Named_groups . empty , Named_groups . empty ) ) accu re in let re_args , re_source = Match . get_re_source ~ quote_expr : <: expr < Str . quote >> ~ nocasify accu in ( re_args , re_sou...
let expr_mutex _loc = <: expr < $ uid : ! mod_runtime_mt . $$ lid : str_mutex $ >>
let unlock _loc = <: expr < Mutex . unlock $ expr_mutex _loc $ >>
let lock _loc = <: expr < Mutex . lock $ expr_mutex _loc $ >>
let lock_unlock e = let _loc = Ast . loc_of_expr e in <: expr < do { $ lock _loc ; $ with [ exn -> do { $ unlock _loc ; $ raise exn } ] } >>
let unlock_lock e = let _loc = Ast . loc_of_expr e in <: expr < do { $ unlock _loc ; $ with [ exn -> do { $ lock _loc ; $ raise exn } ] } >>
let string_match _loc re_name get_re target pos = <: expr < Str . string_match $ get_re $ $ target $ $ int : string_of_int pos $ >>
let matched_group _loc n target = <: expr < Str . matched_group $ int : string_of_int n $ $ target $ >>
let matched_position _loc n target = <: expr < Str . group_beginning $ int : string_of_int n $ >>
let compile_regexp ~ mt _loc re_args re_source = let compile_string e = <: expr < Str . regexp $ e $ >> in match re_args with [ ] -> | _ ->
let convert _loc conv e = match conv with None -> e | Some f ->
let insert_bindings_poly make_expr _loc target set e = Named_groups . fold ( fun name l e -> match l with set e
let insert_group_bindings = insert_bindings_poly matched_group
let insert_position_bindings = insert_bindings_poly matched_position
let insert_bindings _loc target ( group_bindings , position_bindings ) e = insert_group_bindings _loc target group_bindings ( insert_position_bindings _loc target position_bindings e )
let match_and_bind _loc re_name get_re target named_groups success failure = <: expr < if $ string_match _loc re_name get_re target 0 $ then $ insert_bindings _loc target named_groups success $ else $ failure $ >>
let macro_replace _loc re_name target_name named_groups expr = let target = <: expr < $ lid : target_name $ >> in <: expr < fun $ lid : target_name $ -> Str . global_substitute $ lid : re_name $ ( fun _ -> $ insert_bindings _loc target named_groups expr ) $ $ target $ >>
let lib = { predefined_regexps = special_regexps ;
let lib_mt = { predefined_regexps = special_regexps ;
let quotexpander str = [ " 1 ; 2 ; 3 ] 3 "
let patt_quotexpander loc _loc_name_opt str = Gram . parse_string Syntax . patt loc ( quotexpander str ) str
let expr_quotexpander loc _loc_name_opt str = Gram . parse_string Syntax . expr loc ( quotexpander str ) str
let str_item_quotexpander loc loc_name_opt str = <: str_item @ loc < $ exp : expr_quotexpander loc loc_name_opt str $ >>
let ( ) = Syntax . Quotation . add " " Syntax . Quotation . DynAst . expr_tag expr_quotexpander ; Syntax . Quotation . add " " Syntax . Quotation . DynAst . str_item_tag str_item_quotexpander ; Syntax . Quotation . add " " Syntax . Quotation . DynAst . patt_tag patt_quotexpander
module Compact = struct [ @@@ ocamlformat " let - binding - spacing = compact " ] let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd...
module Nl = struct [ @@@ ocamlformat " let - binding - spacing = sparse " ] let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd ddddd...
module Double = struct [ @@@ ocamlformat " let - binding - spacing = double - semicolon " ] let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd dddddddddd dddddddddd dddddddddddd ddddddddd dddddddddd let f x = dddd ...
let wrap_exn s f = try f ( ) with _ -> Stdlib . failwith s
let wrap_cmd f = try ` Ok ( f ( ) ) with | Failure s -> ` Error ( false , s )
let stabilize_gc ( ) = let rec loop failsafe last_heap_live_words = if failsafe <= 0 then Stdlib . failwith " unable to stabilize the number of live words in the major heap " ; Gc . compact ( ) ; let stat = Gc . stat ( ) in if stat . live_words <> last_heap_live_words then loop ( failsafe - 1 ) stat . live_words in loo...
module Cache = struct external flush_cache : int64 -> unit = " stub_flush_cache " end
module Affinity = struct exception Failed_to_set_affinity of int external raw_sched_setaffinity : int -> int = " stub_sched_setaffinity " let set pid = if not ( raw_sched_setaffinity pid = 0 ) then raise ( Failed_to_set_affinity pid ) end
module Time = struct external get_time_ns : unit -> int64 = " stub_get_time_ns " let duration f = let before ' = get_time_ns ( ) in let res = f ( ) in let after ' = get_time_ns ( ) in let diff = Int64 . ( to_int ( sub after ' before ' ) ) in res , diff let fold duration_ns acc f = let start = get_time_ns ( ) in let dif...
let requests_and_responses = [ " \ 002 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 001 \ 000 \ 000 \ 000 \ 000 " , " \ 024 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 007 \ 000 \ 000 \ 000EINVAL \ 000 " ; " \ 013 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000...
module FakeServer = struct end
include [ % css . raw { | * { box - sizing : border - box ; font - family : sans - serif ; } . pre_for_display { height : 50px ; } . primary { background - color : rgb ( 30 , 30 , 30 ) ; color : rgb ( 240 , 240 , 240 ) ; } . resizable_using_css { background - color : rgb ( 30 , 30 , 30 ) ; color : rgb ( 240 , 240 , 240...
module Format = struct type t = { apply_alignment : bool option ; apply_border : bool option ; apply_fill : bool option ; apply_font : bool option ; apply_number_format : bool option ; apply_protection : bool option ; border_id : uint32 option ; fill_id : uint32 option ; font_id : uint32 option ; number_format_id : uin...
module Number_format = struct type t = { id : uint32 ; format : string } [ @@ deriving fields , sexp_of ] let of_xml = function | Xml . Element ( " numFmt " , attrs , _ ) -> let id = ref None in let format = ref None in List . iter attrs ~ f ( : function | " numFmtId " , v -> id := Some ( Uint32 . of_string v ) | " for...
type t = { cell_formats : Format . t list ; formatting_records : Format . t list ; number_formats : Number_format . t list } [ @@ deriving fields , sexp_of ]
let empty = { cell_formats = [ ] ; formatting_records = [ ] ; number_formats = [ ] }
let of_xml = expect_element " styleSheet " ( fun _ -> List . fold ~ init : empty ~ f ( : fun acc -> let open Xml in function | Element ( " cellStyleXfs " , _ , children ) -> let formatting_records = List . filter_map children ~ f : Format . of_xml in { acc with formatting_records } | Element ( " cellXfs " , _ , childre...
let subst params types target = let bindings = combine params types in let visited = ref [ ] in let rec subst t = try match ( ! assq t ! visited ) with | ` Linked t -> t | _ -> assert false with Not_found -> let res = ref ( ` Linked Nil ) in visited +::= ( t , res ) ; let t = match t with | Nil | VariantClosed _ | Any ...
let get_arrows ty = let rec get_arrows acc ty = match ty with | Arrow ( l , t , t ' ) -> get_arrows ( ( l , t ) :: acc ) t ' | _ -> rev acc , ty in get_arrows [ ] ty
let rec size_type = function | Link _ -> 1 | Nil -> 0 | VariantClosed _ -> 0 | Attr ( _ , t ) -> size_type t | Any -> 0 | ( Var _ | VarNamed _ | Univar _ | UnivarNamed _ ) -> 0 | Arrow ( _ , t1 , t2 ) -> size_type t1 + size_type t2 + 1 | Tuple tys -> sum & map size_type tys | Constr ( _ , tys ) -> 1 + sum ( map size_ty...
let short_look t = let nodes = ref [ ] in let stubs = ref [ ] in let rec f ex t = let r = ref None in nodes +::= ( t , r ) ; f_ ex t |- fun t ' -> r := Some t ' and f_ ex t = match t with | Link { contents = ` Stub } -> assert false | Link { contents = ` Linked t ' } -> if List . mem_assq t ' ! nodes then begin let stu...
let output_int oc i = output_string oc ( Int . to_string i )
type annotation = | Ti_pat of pattern | Ti_expr of expression | Ti_class of class_expr | Ti_mod of module_expr | An_call of Location . t * Annot . call | An_ident of Location . t * string * Annot . ident ; ;
let get_location ti = match ti with Ti_pat p -> p . pat_loc | Ti_expr e -> e . exp_loc | Ti_class c -> c . cl_loc | Ti_mod m -> m . mod_loc | An_call ( l , _k ) -> l | An_ident ( l , _s , _k ) -> l ; ;
let annotations = ref ( [ ] : annotation list ) ; ;
let phrases = ref ( [ ] : Location . t list ) ; ;
let record ti = if ! Clflags . annotations && not ( get_location ti ) . Location . loc_ghost then annotations := ti :: ! annotations ; ;
let record_phrase loc = if ! Clflags . annotations then phrases := loc :: ! phrases ; ; ;
let cmp_loc_inner_first loc1 loc2 = match compare loc1 . loc_end . pos_cnum loc2 . loc_end . pos_cnum with | 0 -> compare loc2 . loc_start . pos_cnum loc1 . loc_start . pos_cnum | x -> x ; ;
let cmp_ti_inner_first ti1 ti2 = cmp_loc_inner_first ( get_location ti1 ) ( get_location ti2 ) ; ;
let print_position pp pos = if pos = dummy_pos then output_string pp " " -- else begin output_char pp ' " ' ; \ output_string pp ( String . escaped pos . pos_fname ) ; output_string pp " " \ " ; output_int pp pos . pos_lnum ; output_char pp ' ' ; output_int pp pos . pos_bol ; output_char pp ' ' ; output_int pp pos . po...
let print_location pp loc = print_position pp loc . loc_start ; output_char pp ' ' ; print_position pp loc . loc_end ; ; ;
let sort_filter_phrases ( ) = let ph = List . sort ( fun x y -> cmp_loc_inner_first y x ) ! phrases in let rec loop accu cur l = match l with | [ ] -> accu | loc :: t -> if cur . loc_start . pos_cnum <= loc . loc_start . pos_cnum && cur . loc_end . pos_cnum >= loc . loc_end . pos_cnum then loop accu cur t else loop ( l...
let rec printtyp_reset_maybe loc = match ! phrases with | cur :: t when cur . loc_start . pos_cnum <= loc . loc_start . pos_cnum -> Printtyp . reset ( ) ; phrases := t ; printtyp_reset_maybe loc ; | _ -> ( ) ; ;
let call_kind_string k = match k with | Tail -> " tail " | Stack -> " stack " | Inline -> " inline " ; ;
let print_ident_annot pp str k = match k with | Idef l -> output_string pp " def " ; output_string pp str ; output_char pp ' ' ; print_location pp l ; output_char pp ' \ n ' | Iref_internal l -> output_string pp " int_ref " ; output_string pp str ; output_char pp ' ' ; print_location pp l ; output_char pp ' \ n ' | Ire...
let print_info pp prev_loc ti = match ti with | Ti_class _ | Ti_mod _ -> prev_loc | Ti_pat { pat_loc = loc ; pat_type = typ ; pat_env = env } | Ti_expr { exp_loc = loc ; exp_type = typ ; exp_env = env } -> if loc <> prev_loc then begin print_location pp loc ; output_char pp ' \ n ' end ; output_string pp " type ( \ n "...
let get_info ( ) = let info = List . fast_sort cmp_ti_inner_first ! annotations in annotations := [ ] ; info ; ;
let dump filename = if ! Clflags . annotations then begin let do_dump _temp_filename pp = let info = get_info ( ) in sort_filter_phrases ( ) ; ignore ( List . fold_left ( print_info pp ) Location . none info ) in begin match filename with | None -> do_dump " " stdout | Some filename -> Misc . output_to_file_via_tempora...
let is_recursive ty = let rec f = function | Link { contents = ` Stub } -> assert false | Link { contents = ` Linked _ } -> raise Exit | Nil | VariantClosed _ | Any | VarNamed _ | UnivarNamed _ | Var _ | Univar _ -> ( ) | Arrow ( _ , t1 , t2 ) -> f t1 ; f t2 | Tuple ts | Constr ( _ , ts ) -> iter f ts | Object ( fields...
let of_core_type cty = let closed_cntr = ref 0 in let var_cntr = ref 0 in let vars = Hashtbl . create 107 in let rec of_core_type cty = match cty . ptyp_desc with | Ptyp_any -> Any | Ptyp_var s -> Hashtbl . find_or_add ( fun s -> VarNamed ( Hashtbl . hash s , s ) ) vars s | Ptyp_arrow ( l , cty1 , cty2 ) -> let ty1 = o...
let _format_core_type_via_type_expr ppf cty = Stype_core . format_via_type_expr ppf & of_core_type cty
let of_type_expr pathconv ty = normalize_type Env . empty ty ; let visited = Hashtbl . create 1023 in let var_cntr = ref 0 in let closed_cntr = ref 0 in let rec f ty = let ty = repr ty in try let ty = Hashtbl . find visited ty . id in let rec repr = function | Link { contents = ` Linked ty } -> repr ty | ( Link { conte...
let to_string = Format . to_string Stype_core . format_via_type_expr
let of_type_expr pathconv ty = let xty = of_type_expr pathconv ty in let ty ' = to_type_expr Spath . to_path xty in let xty ' = of_type_expr Spath . of_path ty ' in let sty = to_string xty in let sty ' = to_string xty ' in if xty != xty ' && not ( is_recursive xty ) then begin !!% " ERROR hcons [ [ @@% a ] @@ => [ @% a...
let of_type_exprs pathconv tys = match of_type_expr pathconv ( newgenty ( Ttuple tys ) ) with | Tuple tys -> tys | _ -> assert false
type ' a loop = ' a
let ocaml_of_loop _ocaml_of_a _a = OCaml . String " loop "
type t = | Link of [ ` Linked of t loop | ` Stub ] ref | Nil | VariantClosed of int | Any | VarNamed of int * string | UnivarNamed of int * string | Var of int | Univar of int | Arrow of string * t * t | Tuple of t list | Constr of datatype * t list | Object of ( ( string * t ) list * [ ` Closed | ` Open of t ] ) optio...
let oformat = Ocaml . format_with ocaml_of_t
let rec is_option = function | Constr ( { dt_path = Spath . SPdot ( Spath . SPpredef , " option " ) } , [ t2 ] ) -> Some t2 | Attr ( _ , t ) -> is_option t | _ -> None
module HXTypes = Hashtbl . Make ( struct type _t = t type t = _t let equal t1 t2 = t1 == t2 let hash = Hashtbl . hash end )
let to_type_expr ( ? anon_parameter_as_constr = false ) pathfix ty = let visited = HXTypes . create 1023 in let rec f ty = try HXTypes . find visited ty with Not_found -> let link = newgenvar ~ name " : link " ( ) in HXTypes . replace visited ty link ; let rec g = function | Attr ( _ , t ) -> g t | Link { contents = ` ...