text stringlengths 0 601k |
|---|
let get_build_exn buildtype = let dist = get_build_path buildtype in if not ( Filesystem . is_dir dist ) then raise ( MissingDestinationDirectory buildtype ) else dist |
let create_build buildtype = let _ = Filesystem . mkdirSafe ( get_build ( ) ) 0o755 in let dest = get_build_path buildtype in let _ = Filesystem . mkdirSafe dest 0o755 in dest |
let read_dist_file path = try let content = Filesystem . readFile path in hashtbl_fromList ( List . map ( fun l -> second ( default " " ) $ Utils . toKV l ) $ string_split ' \ n ' content ) with _ -> raise ( FileDoesntExist ( fp_to_string path ) ) |
let read_setup ( ) = read_dist_file setup_path |
let read_configure ( ) = read_dist_file configure_path |
let write_setup setup = let kv ( k , v ) = k ^ " : " ^ v in Filesystem . writeFile setup_path ( String . concat " \ n " $ List . map kv ( hashtbl_toList setup ) ) |
let remove_dead_links ( ) = let files = Sys . readdir " . " in let build_path = fp_to_string ( get_build ( ) ) in Array . iter ( fun fn -> try let l = Unix . readlink fn in if ( string_startswith build_path l ) then Sys . remove fn with _ -> ( ) ) files |
let eliom_template_dir = Findlib . package_directory " eliom . templates " |
let distillery_basic = " basic . ppx " , eliom_template_dir |
let template_path ( tname , tpath ) = tpath ^ " " / ^ tname |
let lines_of_file file = if not ( Sys . file_exists file ) then [ ] else let lines = ref [ ] in let in_file = open_in file in let rec aux ( ) = try lines := input_line in_file :: ! lines ; aux ( ) with End_of_file -> close_in in_file in aux ( ) ; ! lines |
let pp_list ( ) l = let f s = if s = fst distillery_basic then s ^ " ( default ) " else s in String . concat " , " ( List . map f l ) |
let gen_usage_msg l = Printf . sprintf " Welcome to the Eliom distillery !\ n \ nThis program generates the scaffold for your Eliom application \ nfrom a template . \ nAvailable templates : % a . \ n \ nCall it like this \ n \ $ % s - name < name > [ - template < template ] > [ - target - directory < dest ] >\ n \ $ % ... |
let rec yes_no : default : bool -> string -> bool = fun ~ default msg -> printf " % s ( % s /% s ) " msg ( if default then " YES " else " yes " ) ( if default then " no " else " NO " ) ; match String . ( lowercase_ascii ( read_line ( ) ) ) with | " yes " | " y " -> true | " no " | " n " -> false | " " -> default | _ ->... |
let split_path str = Str . ( split_delim ( regexp ( quote Filename . dir_sep ) ) str ) |
let join_path = function | [ " " ] -> failwith " join_path " | path -> String . concat Filename . dir_sep path |
let ifdef_regexp = Str . ( regexp " ^ *%%% ifdef ( [ +\\ A - Z0 - 9_ ] ) +\\%%% " ) *$ |
let endif_regexp = Str . ( regexp " ^ *%%% endif %%% " ) *$ |
let mkdir_p path_str = let rec aux sofar = function | [ ] -> ( ) | snippet :: rest -> let sofar ' = snippet :: sofar in ( if sofar ' <> [ " " ] then let dir = join_path ( List . rev sofar ' ) in if Sys . file_exists dir then ( if not ( Sys . is_directory dir ) then raise ( File_error ( sprintf " Cannot create directory... |
let copy_file_plain input_name output_name = mkdir_p ( Filename . dirname output_name ) ; let buffer_size = 8192 in let fd_in = Unix . openfile input_name [ O_RDONLY ] 0 and fd_out = let { Unix . st_perm } = Unix . stat input_name in Unix . openfile output_name [ O_WRONLY ; O_CREAT ; O_TRUNC ] st_perm and buffer = Byte... |
let copy_file ( ? env = [ ] ) ( ? preds = [ ] ) src_name dst_name = let line_counter = ref 0 in let include_line = let ifdef_stack = ref [ ] in let preds = List . map ( fun pred -> pred , Str . ( regexp ( " ^ *%%% ifdef " + ^ quote pred ^ " %%% " ) ) ) *$ preds in fun line -> let rec ifdef_pred = function | [ ] -> None... |
let expand_dest_path ~ name ~ dest_dir s = Str . ( global_replace ( regexp ( quote " PROJECT_NAME " ) ) name s ) |> Str . ( split ( regexp " " ) ) ! |> join_path |> Filename . concat dest_dir |
let create_project ? preds ~ without_asking ~ name ~ env ~ source_dir ~ dest_dir ( ) = let eliom_ignore_files = lines_of_file ( Filename . concat source_dir eliomignore_filename ) and eliom_verbatim_files = lines_of_file ( Filename . concat source_dir eliomverbatim_filename ) in if not ( Sys . file_exists dest_dir ) th... |
let env name = let db = if Utils . has_package " ocsipersist . dbm " then " dbm " else if Utils . has_package " ocsipersist . sqlite " then " sqlite " else if Utils . has_package " ocsipersist . pgsql " then " pgsql " else " dbm " in [ " PROJECT_NAME " , name ; " MODULE_NAME " , String . capitalize_ascii name ; " PROJE... |
let get_templatedirs ( ) = let distillery_path_dirs = try let paths = Sys . getenv " ELIOM_DISTILLERY_PATH " in Str . split ( Str . regexp " " ) : paths with Not_found -> [ ] in eliom_template_dir :: distillery_path_dirs |
let get_templates ( ) = let dirs = List . map ( fun d -> d , Unix . opendir d ) ( get_templatedirs ( ) ) in let rec aux rl ( path , dir ) = try let f = Unix . readdir dir in if f = " . . " || f = " . " then aux rl ( path , dir ) else aux ( ( f , path ) :: rl ) ( path , dir ) with End_of_file -> Unix . closedir dir ; rl... |
let check_reserve_project_name project_name template = Filename . concat ( template_path template ) reserve_project_name_filename |> lines_of_file |> List . mem project_name |
let init_project template name = env name , template_path template |
let compilation_unit_name_regexp = Str . regexp " [ ^ A - Za - z ] [ a - zA - Z0 - 9_ ' ] " *$ |
let main ( ) = let dir = ref false in let without_asking = ref false in let shown = ref false in let show_templates ( ) = List . iter ( fun ( name , path ) -> Printf . printf " % s [ % s ] \ n " name path ) ( get_templates ( ) ) ; shown := true in let bad fmt = Printf . ksprintf ( fun s -> raise ( Arg . Bad s ) ) fmt i... |
let ( ) = main ( ) |
let error = ref false |
let d = ref 0 |
let divref n = n / ! d |
let modref n = n mod ! d |
let test_one ( df : int -> int ) ( mf : int -> int ) x = if not ( df x = divref x && mf x = modref x ) then begin printf " mismatch for % d \ n " x ; error := true end |
let do_test divisor ( df : int -> int ) ( mf : int -> int ) = d := divisor ; List . iter ( test_one df mf ) [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 100 ; 1000 ; 10000 ; 100000 ; 1000000 ; max_int - 1 ; max_int ; - 1 ; - 2 ; - 3 ; - 4 ; - 5 ; - 6 ; - 7 ; - 8 ; - 9 ; - 10 ; - 100 ; - 1000 ; - 10000 ; - 100000 ; - ... |
let d = ref 0n |
let divref n = Nativeint . div n ! d |
let modref n = Nativeint . rem n ! d |
let test_one ( df : nativeint -> nativeint ) ( mf : nativeint -> nativeint ) x = if not ( df x = divref x && mf x = modref x ) then begin printf " mismatch for % nd \ n " x ; error := true end |
let do_test divisor ( df : nativeint -> nativeint ) ( mf : nativeint -> nativeint ) = d := Nativeint . of_int divisor ; List . iter ( test_one df mf ) [ 0n ; 1n ; 2n ; 3n ; 4n ; 5n ; 6n ; 7n ; 8n ; 9n ; 10n ; 100n ; 1000n ; 10000n ; 100000n ; 1000000n ; Nativeint . ( pred max_int ) ; Nativeint . max_int ; - 1n ; - 2n ;... |
let _ = printf " 1 int \ n " ; WithInt . do_test 1 ( fun x -> x / 1 ) ( fun x -> x mod 1 ) ; printf " 2 int \ n " ; WithInt . do_test 2 ( fun x -> x / 2 ) ( fun x -> x mod 2 ) ; printf " 3 int \ n " ; WithInt . do_test 3 ( fun x -> x / 3 ) ( fun x -> x mod 3 ) ; printf " 4 int \ n " ; WithInt . do_test 4 ( fun x -> x /... |
let f n = assert ( 1 mod n = 0 ) |
let ( ) = f 1 |
type t = { x : int ; y : int } |
let f x = { x ; y = x / 0 } . x |
let ( ) = try ignore ( f 1 ) ; assert false with Division_by_zero -> ( ) |
let check f n = assert ( try ignore ( ( Sys . opaque_identity f ) n ) ; false with Division_by_zero -> true ) |
let div_int n = n / 0 |
let div_int32 n = Int32 . div n 0l |
let div_int64 n = Int64 . div n 0L |
let div_nativeint n = Nativeint . div n 0n |
let mod_int n = n mod 0 |
let mod_int32 n = Int32 . rem n 0l |
let mod_int64 n = Int64 . rem n 0L |
let mod_nativeint n = Nativeint . rem n 0n |
let div_int_opaque n = n / ( Sys . opaque_identity 0 ) |
let div_int32_opaque n = Int32 . div n ( Sys . opaque_identity 0l ) |
let div_int64_opaque n = Int64 . div n ( Sys . opaque_identity 0L ) |
let div_nativeint_opaque n = Nativeint . div n ( Sys . opaque_identity 0n ) |
let mod_int_opaque n = n mod ( Sys . opaque_identity 0 ) |
let mod_int32_opaque n = Int32 . rem n ( Sys . opaque_identity 0l ) |
let mod_int64_opaque n = Int64 . rem n ( Sys . opaque_identity 0L ) |
let mod_nativeint_opaque n = Nativeint . rem n ( Sys . opaque_identity 0n ) |
let ( ) = check div_int 33 ; check div_int 0 ; check div_int32 33l ; check div_int32 0l ; check div_int64 33L ; check div_int64 0L ; check div_nativeint 33n ; check div_nativeint 0n ; check mod_int 33 ; check mod_int 0 ; check mod_int32 33l ; check mod_int32 0l ; check mod_int64 33L ; check mod_int64 0L ; check mod_nat... |
let ( ) = print_endline " ***** OK " ***** |
type dll_mode = For_checking | For_execution = " caml_dynlink_lookup_symbol " = " caml_dynlink_get_current_libs " |
let search_path = ref ( [ ] : string list ) |
type opened_dll = | Checking of Binutils . t | Execution of dll_handle |
let dll_close = function | Checking _ -> ( ) | Execution dll -> dll_close dll |
let opened_dlls = ref ( [ ] : opened_dll list ) |
let names_of_opened_dlls = ref ( [ ] : string list ) |
let add_path dirs = search_path := dirs @ ! search_path |
let remove_path dirs = search_path := List . filter ( fun d -> not ( List . mem d dirs ) ) ! search_path |
let extract_dll_name file = if Filename . check_suffix file Config . ext_dll then Filename . chop_suffix file Config . ext_dll else if String . length file >= 2 && String . sub file 0 2 = " - l " then " dll " ^ String . sub file 2 ( String . length file - 2 ) else file |
let open_dll mode name = let name = name ^ Config . ext_dll in let fullname = try let fullname = Misc . find_in_path ! search_path name in if Filename . is_implicit fullname then Filename . concat Filename . current_dir_name fullname else fullname with Not_found -> name in if not ( List . mem fullname ! names_of_opened... |
let open_dlls mode names = List . iter ( open_dll mode ) names |
let close_all_dlls ( ) = List . iter dll_close ! opened_dlls ; opened_dlls := [ ] ; names_of_opened_dlls := [ ] |
type primitive_address = | Prim_loaded of dll_address | Prim_exists |
let find_primitive prim_name = let rec find seen = function [ ] -> None | Execution dll as curr :: rem -> let addr = dll_sym dll prim_name in if addr == Obj . magic ( ) then find ( curr :: seen ) rem else begin if seen <> [ ] then opened_dlls := curr :: List . rev_append seen rem ; Some ( Prim_loaded addr ) end | Check... |
let linking_in_core = ref false |
let synchronize_primitive num symb = if ! linking_in_core then begin let actual_num = add_primitive symb in assert ( actual_num = num ) end |
let ld_conf_contents ( ) = let path = ref [ ] in begin try let ic = open_in ( Filename . concat Config . standard_library " ld . conf " ) in begin try while true do path := input_line ic :: ! path done with End_of_file -> ( ) end ; close_in ic with Sys_error _ -> ( ) end ; List . rev ! path |
let ld_library_path_contents ( ) = match Sys . getenv " CAML_LD_LIBRARY_PATH " with | exception Not_found -> [ ] | s -> Misc . split_path_contents s |
let split_dll_path path = Misc . split_path_contents ~ sep ' :\ 000 ' path |
let init_compile nostdlib = search_path := ld_library_path_contents ( ) @ ( if nostdlib then [ ] else ld_conf_contents ( ) ) |
let init_toplevel dllpath = search_path := ld_library_path_contents ( ) @ split_dll_path dllpath @ ld_conf_contents ( ) ; opened_dlls := List . map ( fun dll -> Execution dll ) ( Array . to_list ( get_current_dlls ( ) ) ) ; names_of_opened_dlls := [ ] ; linking_in_core := true |
let reset ( ) = search_path := [ ] ; opened_dlls [ ] ; := names_of_opened_dlls := [ ] ; linking_in_core := false |
let ocamldoc_wiki tags deps docout docdir = let tags = tags -- " extension : html " in Ocamlbuild_pack . Ocaml_tools . ocamldoc_l_dir tags deps docout docdir |
let ocamldoc_man tags deps docout docdir = let tags = tags in Ocamlbuild_pack . Ocaml_tools . ocamldoc_l_dir tags deps docout docdir |
let init_wikidoc ( ) = try let wikidoc_dir = let base = Ocamlbuild_pack . My_unix . run_and_read " ocamlfind query wikidoc " in String . sub base 0 ( String . length base - 1 ) in Ocamlbuild_pack . Rule . rule " ocamldoc : document ocaml project odocl & * odoc -> wikidocdir " ~ insert ` : top ~ prod " . :% wikidocdir /... |
let init_mandoc ( ) = Ocamlbuild_pack . Rule . rule " ocamldoc : document ocaml project odocl & * odoc -> mandocdir " ~ insert ` : top ~ prod " . :% mandocdir / man . ( % ext ) " ~ stamp " . :% mandocdir / man . ( % ext ) . stamp " ~ dep " . :% odocl " ( Ocamlbuild_pack . Ocaml_tools . document_ocaml_project ~ ocamldoc... |
let init ( ) = init_wikidoc ( ) ; init_mandoc ( ) ; pflag_and_dep [ " doc " ] " with_intro " ( fun f -> S [ A " - intro " ; P f ] ) |
type ds_attached = | Unattached | Info | Docs |
type ds_associated = | Zero | One | Many |
type docstring = { ds_body : string ; ds_loc : Location . t ; mutable ds_attached : ds_attached ; mutable ds_associated : ds_associated ; } |
let docstrings : docstring list ref = ref [ ] |
let warn_bad_docstrings ( ) = if Warnings . is_active ( Warnings . Unexpected_docstring true ) then begin List . iter ( fun ds -> match ds . ds_attached with | Info -> ( ) | Unattached -> prerr_warning ds . ds_loc ( Warnings . Unexpected_docstring true ) | Docs -> match ds . ds_associated with | Zero | One -> ( ) | Man... |
let docstring body loc = let ds = { ds_body = body ; ds_loc = loc ; ds_attached = Unattached ; ds_associated = Zero ; } in ds |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.