text stringlengths 12 786k |
|---|
module Make ( ArtLib : ArtLib . S ) ( Name : Name . S ) ( Elt : Data . S ) ( St : SpreadTree . S with type name = Name . t and type elt = Elt . t ) = struct module List = St . List module Set = Trie . Set . Make ( Name ) ( ArtLib ) ( Elt ) let list_unique : ( El... |
let list_unique : List . Data . t -> List . Data . t = let loop = List . Art . mk_mfn ( Key . of_string " Unique # list_unique " ) ( module AdaptonTypes . Tuple3 ( Key ) ( List . Data ) ( Set ) ) ( fun loop ( nm , l , s ) -> match l with | ` Nil -> ` Nil ... |
let lthunk : List . Data . t -> List . Art . t = let ident = List . Art . mk_mfn ( Key . of_string " Unique # lthunk " ) ( module List . Data ) ( fun _ l -> l ) in ident . mfn_art |
let _ = let name l = ` Name ( Key . nondet ( ) , ` Art ( lthunk l ) ) in let al_of_l ( l : int list ) : List . Data . t = OList . fold_right ( fun n a -> name ( ` Cons ( n , a ) ) ) l ` Nil in let rec l_of_al : List . Data . t -> int list = function | ` N... |
module type Id = Id |
let rec race_free_create_loop cell make = let x = ! cell in let new_x = make x in if phys_equal ! cell x then ( cell := new_x ; x ) else race_free_create_loop cell make ; ; |
module Int ( ) = struct include Int let current = ref zero let create ( ) = race_free_create_loop current succ end |
module Int63 ( ) = struct include Int63 let current = ref zero let create ( ) = race_free_create_loop current succ end |
let test_reserved_identifiers ( ) = let u = U . init ~ reserved_identifiers [ " : y " ] ~ reserved_prefixes [ ] : ~ safe_prefix " : x_ " in Alcotest . ( check ( option string ) ) " equal " None ( U . translate_only u " a " ) ; Alcotest . ( check string ) " ... |
let test_reserved_prefixes ( ) = ( try U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " " ] : ~ safe_prefix " : x_ " |> ignore ; assert false with _ -> ( ) ) ; ( try U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " : x " ] ~ safe... |
let test_identifier_creation ( ) = let u = U . init ~ reserved_identifiers [ ] : ~ reserved_prefixes [ " : y_ " ] ~ safe_prefix " : x_ " in Alcotest . ( check string ) " equal " " y " ( U . translate u " y " ) ; Alcotest . ( check string ) " equal " " ... |
let test : unit Alcotest . test = " Unique_name " , [ " reserved identifiers " , ` Quick , test_reserved_identifiers ; " reserved prefixes " , ` Quick , test_reserved_prefixes ; " identifier creation " , ` Quick , test_identifier_creation ; ] |
module M = struct type t = B let f : t -> t = fun B -> x end ; ; [ %% expect { | |
type t = A ^ t / 1 Line 4 , characters 2 - 12 : Definition of type t / 1 Line 1 , characters 0 - 10 : Definition of type t / 2 } ] | |
module M = struct type t = B end |
module N = struct module M = struct type t = C end let f : M . t -> M . t = fun M . C -> y end ; ; [ %% expect { | |
module M : sig type t = B end ^ M / 1 . t Lines 4 - 6 , characters 2 - 5 : Definition of module M / 1 Line 1 , characters 0 - 32 : Definition of module M / 2 } ] | |
let f : t -> t = fun D -> x ; ; [ %% expect { | |
type t = D ^ t / 1 Line 1 , characters 0 - 10 : Definition of type t / 1 Line 1 , characters 0 - 10 : Definition of type t / 2 } ] | |
type ttt = A of ttt | B of uuu [ %% expect { | |
type ttt = A of ttt | B of uuu } ] | |
type nonrec ttt = X of ttt |
let x : ttt = let rec y = A y in y ; ; [ %% expect { | |
type nonrec ttt = X of ttt ^ ttt / 1 Line 1 , characters 0 - 26 : Definition of type ttt / 1 Line 2 , characters 0 - 30 : Definition of type ttt / 2 } ] | |
let safe_ascii c = ( c >= ' a ' && c <= ' z ' ) || ( c >= ' A ' && c <= ' Z ' ) || c = ' _ ' || ( c >= ' 0 ' && c <= ' 9 ' ) |
let safe_ascii_only s = CCString . filter_map ( fun c -> if safe_ascii c then Some c else None ) s |
let safe_ascii_only_ml s = CCString . filter_map ( fun c -> if safe_ascii c || c = ' ' ' \ then Some c else None ) s |
let unsuffixed_file_name ( ) = let loc = ! Ast_helper . default_loc in let name = Filename . basename loc . Lo . loc_start . Le . pos_fname in match CCString . split_on_char ' . ' name with | [ ] -> " " | s :: _ -> safe_ascii_only s |
let make_uniq_cnt htl s = let i = match Hashtbl . find htl s with exception Not_found -> 0 | n -> n in Hashtbl . replace htl s ( succ i ) ; i |
let htl_c = Hashtbl . create 128 |
let safe_cname = let cnt = make_uniq_cnt htl_c in fun ~ prefix -> let loc = ! Ast_helper . default_loc in let name = unsuffixed_file_name ( ) in let s = safe_ascii_only prefix in let cutmax s maxlen = let len = String . length s in if len > maxlen then String . sub s 0 maxlen else s in let s = cu... |
let htl_ml = Hashtbl . create 128 |
let safe_mlname = let cnt = make_uniq_cnt htl_ml in fun ( ? capitalize = false ) ? prefix ( ) -> let s , p = match prefix with | None -> ( " " , " " ) | Some s -> ( safe_ascii_only_ml s , " _ " ) in let loc = ! Ast_helper . default_loc in let line = loc . Lo . loc_... |
type merlin_state = { l_c : ( string * int ) list ; l_ml : ( string * int ) list ; } |
let merlin_save ( ) : merlin_state = { l_c = CCHashtbl . Poly . to_list htl_c ; l_ml = CCHashtbl . Poly . to_list htl_ml } |
let merlin_restore { l_c ; l_ml } = let f htl l = Hashtbl . clear htl ; List . iter ( fun ( a , b ) -> Hashtbl . replace htl a b ) l in f htl_c l_c ; f htl_ml l_ml |
let htl_ctypes = Hashtbl . create 64 |
type t = { mod_path : string list ; uniq_name : string ; short_name : string ; sref : string ; } |
type make_result = { id : t ; topmod_vb : structure_item ; topmod_ref : structure_item ; main_ref : expression ; } |
let attr ~ attr ~ cont = let loc = ! Ast_helper . default_loc in let x = U . mk_loc attr in let pl = PStr [ [ % stri [ % e U . str_expr cont ] ] ] in [ Ast_helper . Attr . mk x pl ] |
let vb ? constr ~ attrs n expr = let p = match constr with None -> U . mk_pat n | Some t -> U . mk_pat_pconstr t n in Str . value Nonrecursive [ Vb . mk ~ attrs p expr ] |
let make ? constr ? main_ref_attrs ~ retype mod_path short_name expr = let uniq_name = U . safe_mlname ~ prefix : short_name ( ) in let sref = String . concat " . " ( mod_path @ [ short_name ] ) in Hashtbl . add htl_ctypes sref ( ) ; let id = { mod_path ; uniq_name ; short_... |
let get_remove_string_exn name attr = let res = ref None in let attribs = List . filter attr ~ f ( : fun x -> if x . attr_name . txt <> name then true else match x . attr_payload with | PStr [ { pstr_desc = Pstr_eval ( { pexp_desc = Pexp_constant ( Pconst_string ( s , _ , _ ) ) ... |
let is_uniq_ctype orig = match Hashtbl . find_all htl_ctypes orig with | [ _ ] -> true | [ ] -> failwith " invalid parsetree generated " | _ -> false |
let get_final_name t = if is_uniq_ctype t . sref then t . short_name else t . uniq_name |
let replace_expr = function | { pexp_desc = Pexp_ident _ as orig ; pexp_attributes = _ :: _ as attribs ; _ } as expr when List . exists attribs ~ f ( : fun x -> x . attr_name . txt = a_reference_string ) -> let s , pexp_attributes = get_remove_string_exn a_reference_string attribs in ... |
let replace_stri = function | { pstr_desc = Pstr_value ( Nonrecursive , [ ( { pvb_attributes = _ :: _ as attribs ; _ } as a ) ] ) ; _ ; } as stri -> if List . exists attribs ~ f ( : fun x -> x . attr_name . txt = a_orig_name ) then let s , pvb_attributes = get_remo... |
let clear ( ) = Hashtbl . clear htl_ctypes |
type merlin_state = string list |
let merlin_save ( ) = CCHashtbl . Poly . to_list htl_ctypes |> List . split |> fst |
let merlin_restore l = clear ( ) ; List . iter l ~ f ( : fun x -> Hashtbl . add htl_ctypes x ( ) ) |
let desc = [ ` Path " lablgtk - 1 . 00 / config . make " ; ` Path " lablgtk - 1 . 00 / lablgtktop_t " ; ` Path " lablgtk - 1 . 00 / lablgtktop " ; ` Path " lablgtk - 1 . 00 / lablgtkrun " ; ` Path " lablgtk - 1 . 00 / lablgtk " ; ` Path " un... |
let paths = [ " These " ; " Xduce " ; " unison " ; " unison2 " ; " unison3 " ; " tinkertype " ; " lipe " ; " icfp2000 " ; " Views " ; " sync " ; " misc " ; " lablgtk - 1 . 00 " ; " mydb " ; " yacc " ; " db - papers " ; " ... |
let rec children p = let rec loop ch dir = try let file = Unix . readdir dir in let ch ' = if file = " . " || file = " . . " then ch else file :: ch in loop ch ' dir with End_of_file -> ch in let dir = Unix . opendir p in let result = loop [ ] dir in Unix . closedir dir ; result |
let is_dir p = try ( Unix . lstat p ) . Unix . st_kind = Unix . S_DIR with Unix . Unix_error _ -> false |
let count = ref 0 |
let hit = ref 0 |
let rec visit rx p = try ignore ( Re . exec ~ group : false rx p ) ; with Not_found -> let fp = prefix ^ p in if is_dir fp then List . iter ( fun n -> visit rx ( p ^ " " / ^ n ) ) ( children fp ) |
let _ = let rx = Re . seq [ Re . bos ; Re . alt ( List . map ( fun p -> match p with ` Path s -> Re . Glob . globx s | ` Name s -> Re . seq [ Re . no_group ( Re_posix . re " ( . ) " ) ; */? Re . Glob . globx s ] ) desc ) ; Re . eos ] in let rx = R... |
let desc = [ ` Path " lablgtk - 1 . 00 / config . make " ; ` Path " lablgtk - 1 . 00 / lablgtktop_t " ; ` Path " lablgtk - 1 . 00 / lablgtktop " ; ` Path " lablgtk - 1 . 00 / lablgtkrun " ; ` Path " lablgtk - 1 . 00 / lablgtk " ; ` Path " un... |
let paths = [ " These " ; " Xduce " ; " unison " ; " unison2 " ; " unison3 " ; " tinkertype " ; " lipe " ; " icfp2000 " ; " Views " ; " sync " ; " misc " ; " lablgtk - 1 . 00 " ; " mydb " ; " yacc " ; " db - papers " ; " ... |
let rec children p = let rec loop ch dir = try let file = Unix . readdir dir in let ch ' = if file = " . " || file = " . . " then ch else file :: ch in loop ch ' dir with End_of_file -> ch in let dir = Unix . opendir p in let result = loop [ ] dir in Unix . closedir dir ; result |
let is_dir p = try ( Unix . lstat p ) . Unix . st_kind = Unix . S_DIR with Unix . Unix_error _ -> false |
let rec visit rx p = if Rx . match_string rx p then ( ) let fp = prefix ^ p in if is_dir fp then List . iter ( fun n -> visit rx ( p ^ " " / ^ n ) ) ( children fp ) end |
let _ = let rx = Rx . alt ( List . map ( fun p -> match p with ` Path s -> Rx . globx s | ` Name s -> Rx . seq [ Rx . rx " ( . ) " ; */? Rx . globx s ] ) desc ) ; in List . iter ( fun p -> visit rx p ) paths |
let desc = [ ` Path " lablgtk - 1 . 00 / config . make " ; ` Path " lablgtk - 1 . 00 / lablgtktop_t " ; ` Path " lablgtk - 1 . 00 / lablgtktop " ; ` Path " lablgtk - 1 . 00 / lablgtkrun " ; ` Path " lablgtk - 1 . 00 / lablgtk " ; ` Path " un... |
let translate_char c = match c with ' . ' -> " . " \ | ' ' * -> " [ ] " ^/* | _ -> String . make 1 c |
let translate_str s = let res = ref " " in for i = 0 to String . length s - 1 do res := ! res ^ translate_char s . [ i ] done ; ! res |
let paths = [ " These " ; " Xduce " ; " unison " ; " unison2 " ; " unison3 " ; " tinkertype " ; " lipe " ; " icfp2000 " ; " Views " ; " sync " ; " misc " ; " lablgtk - 1 . 00 " ; " mydb " ; " yacc " ; " db - papers " ; " ... |
let rec children p = let rec loop ch dir = try let file = Unix . readdir dir in let ch ' = if file = " . " || file = " . . " then ch else file :: ch in loop ch ' dir with End_of_file -> ch in let dir = Unix . opendir p in let result = loop [ ] dir in Unix . closedir dir ; result |
let is_dir p = try ( Unix . lstat p ) . Unix . st_kind = Unix . S_DIR with Unix . Unix_error _ -> false |
let count = ref 0 |
let rec visit rx p = try ignore ( Re_pcre . exec ~ rex : rx p ) ; with Not_found -> let fp = prefix ^ p in if is_dir fp then List . iter ( fun n -> visit rx ( p ^ " " / ^ n ) ) ( children fp ) |
let _ = let l = List . map ( fun p -> match p with ` Path s -> translate_str s | ` Name s -> " ( . ) " ?:*/? ^ translate_str s ) desc in let rx = " ( " ^?: ^ begin match l with x :: r -> x ^ List . fold_right ( fun x rem -> " " | ^ x ^ rem ) r " " | [ ] -... |
module Access = struct type t = Unix . access_permission type defns = { r_ok : int ; w_ok : int ; x_ok : int ; f_ok : int ; } module Host = struct type t = defns let of_defns d = d and to_defns d = d end let _to_code ~ host = let defns = host in Unix . ( function | R_OK -> defns . r... |
module Seek = struct type t = SEEK_SET | SEEK_CUR | SEEK_END | SEEK_DATA | SEEK_HOLE type defns = { seek_set : int ; seek_cur : int ; seek_end : int ; seek_data : int option ; seek_hole : int option ; } type index = ( int , t ) Hashtbl . t module Host = struct type t = defns * inde... |
module Sysconf = struct type defns = { pagesize : int ; } module Host = struct type t = defns let of_defns d = d and to_defns d = d end let pagesize ~ host = host . pagesize end |
type host = { access : Access . Host . t ; seek : Seek . Host . t ; sysconf : Sysconf . Host . t ; } |
module Access = struct open Unistd . Access let host = Host . of_defns Type . Access . ( { r_ok ; w_ok ; x_ok ; f_ok } ) let view ~ host = Ctypes . ( view ~ read ( : of_code ~ host ) ~ write ( : to_code ~ host ) int ) end |
module Seek = struct open Unistd . Seek let host = Host . of_defns Type . Seek . ( { seek_set ; seek_cur ; seek_end ; seek_data = if seek_data = - 1 then None else Some seek_data ; seek_hole = if seek_hole = - 1 then None else Some seek_hole ; } ) end |
module Sysconf = struct open Unistd . Sysconf let host = Host . of_defns Type . Sysconf . ( { pagesize = _sc_pagesize } ) end |
let host = { Unistd . access = Access . host ; seek = Seek . host ; sysconf = Sysconf . host ; } |
let handle_error ? label call zero ( rv , errno ) = if rv < zero then Errno_unix . raise_errno ~ call ? label errno else rv |
let seek_code cmd = match Unistd . Seek . to_code ~ host : Seek . host cmd with | Some code -> code | None -> raise Unix . ( Unix_error ( EINVAL , " lseek " , " " ) ) |
let lseek fd offset whence = Off . to_int64 ( handle_error " lseek " Off . zero ( C . lseek fd ( Off . of_int64 offset ) ( seek_code whence ) ) ) |
let unlink path = ignore ( handle_error " unlink " 0 ~ label : path ( C . unlink path ) ) |
let rmdir path = ignore ( handle_error " rmdir " 0 ~ label : path ( C . rmdir path ) ) |
let write fd buf count = Ssize . to_int ( handle_error " write " Ssize . zero ( C . write fd buf ( Size . of_int count ) ) ) |
let pwrite fd buf count offset = Ssize . to_int ( handle_error " pwrite " Ssize . zero ( C . pwrite fd buf ( Size . of_int count ) ( Off . of_int64 offset ) ) ) |
let read fd buf count = Ssize . to_int ( handle_error " read " Ssize . zero ( C . read fd buf ( Size . of_int count ) ) ) |
let pread fd buf count offset = Ssize . to_int ( handle_error " pread " Ssize . zero ( C . pread fd buf ( Size . of_int count ) ( Off . of_int64 offset ) ) ) |
let close fd = ignore ( handle_error " close " 0 ( C . close fd ) ) |
let access pathname mode = ignore ( handle_error " access " 0 ~ label : pathname ( C . access pathname ( Unistd . Access . to_code ~ host : Access . host mode ) ) ) |
let readlink = let c ' path buf sz = handle_error " readlink " Ssize . zero ~ label : path ( C . readlink path buf sz ) in fun path -> let sz = ref ( Unistd . Sysconf . pagesize ~ host : Sysconf . host ) in let buf = ref ( allocate_n char ~ count :! sz ) in let len = ref ( Ssiz... |
let symlink target linkpath = ignore ( handle_error ~ label : linkpath " symlink " 0 ( C . symlink target linkpath ) ) |
let truncate path length = ignore ( handle_error " truncate " ~ label : path 0 ( C . truncate path ( Off . of_int64 length ) ) ) |
let ftruncate fd length = ignore ( handle_error " truncate " 0 ( C . ftruncate fd ( Off . of_int64 length ) ) ) |
let chown path owner group = ignore ( handle_error " chown " 0 ~ label : path ( C . chown path ( Uid . of_int owner ) ( Gid . of_int group ) ) ) |
let fchown fd owner group = ignore ( handle_error " fchown " 0 ( C . fchown fd ( Uid . of_int owner ) ( Gid . of_int group ) ) ) |
let seteuid euid = ignore ( handle_error " seteuid " 0 ( C . seteuid ( Posix_types . Uid . of_int euid ) ) ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.