text stringlengths 12 786k |
|---|
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 ... |
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 ; - ... |
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 ; 100000... |
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 ... |
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... |
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 fulln... |
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 ; Som... |
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 ; Lis... |
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 := t... |
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 " ~ in... |
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 " ( ... |
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_a... |
let docstring body loc = let ds = { ds_body = body ; ds_loc = loc ; ds_attached = Unattached ; ds_associated = Zero ; } in ds |
let register ds = docstrings := ds :: ! docstrings |
let docstring_body ds = ds . ds_body |
let docstring_loc ds = ds . ds_loc |
type docs = { docs_pre : docstring option ; docs_post : docstring option ; } |
let empty_docs = { docs_pre = None ; docs_post = None } |
let doc_loc = { txt = " ocaml . doc " ; loc = Location . none } |
let docs_attr ds = let open Parsetree in let body = ds . ds_body in let loc = ds . ds_loc in let exp = { pexp_desc = Pexp_constant ( Pconst_string ( body , loc , None ) ) ; pexp_loc = loc ; pexp_loc_stack = [ ] ; pexp_attributes = [ ] ; } in let item = { pstr_desc = Pstr_... |
let add_docs_attrs docs attrs = let attrs = match docs . docs_pre with | None | Some { ds_body " " ; = _ } -> attrs | Some ds -> docs_attr ds :: attrs in let attrs = match docs . docs_post with | None | Some { ds_body " " ; = _ } -> attrs | Some ds -> attrs @ [ docs_attr ds ... |
type info = docstring option |
let add_info_attrs info attrs = match info with | None | Some { ds_body " " ; = _ } -> attrs | Some ds -> attrs @ [ info_attr ds ] |
type text = docstring list |
let empty_text_lazy = lazy [ ] |
let text_loc = { txt = " ocaml . text " ; loc = Location . none } |
let text_attr ds = let open Parsetree in let body = ds . ds_body in let loc = ds . ds_loc in let exp = { pexp_desc = Pexp_constant ( Pconst_string ( body , loc , None ) ) ; pexp_loc = loc ; pexp_loc_stack = [ ] ; pexp_attributes = [ ] ; } in let item = { pstr_desc = Pstr_... |
let add_text_attrs dsl attrs = let fdsl = List . filter ( function { ds_body " " } = -> false | _ -> true ) dsl in ( List . map text_attr fdsl ) @ attrs |
let get_docstring ~ info dsl = let rec loop = function | [ ] -> None | { ds_attached = Info ; _ } :: rest -> loop rest | ds :: _ -> ds . ds_attached <- if info then Info else Docs ; Some ds in loop dsl |
let get_docstrings dsl = let rec loop acc = function | [ ] -> List . rev acc | { ds_attached = Info ; _ } :: rest -> loop acc rest | ds :: rest -> ds . ds_attached <- Docs ; loop ( ds :: acc ) rest in loop [ ] dsl |
let associate_docstrings dsl = List . iter ( fun ds -> match ds . ds_associated with | Zero -> ds . ds_associated <- One | ( One | Many ) -> ds . ds_associated <- Many ) dsl |
let pre_table : ( Lexing . position , docstring list ) Hashtbl . t = Hashtbl . create 50 |
let set_pre_docstrings pos dsl = if dsl <> [ ] then Hashtbl . add pre_table pos dsl |
let get_pre_docs pos = try let dsl = Hashtbl . find pre_table pos in associate_docstrings dsl ; get_docstring ~ info : false dsl with Not_found -> None |
let mark_pre_docs pos = try let dsl = Hashtbl . find pre_table pos in associate_docstrings dsl with Not_found -> ( ) |
let post_table : ( Lexing . position , docstring list ) Hashtbl . t = Hashtbl . create 50 |
let set_post_docstrings pos dsl = if dsl <> [ ] then Hashtbl . add post_table pos dsl |
let get_post_docs pos = try let dsl = Hashtbl . find post_table pos in associate_docstrings dsl ; get_docstring ~ info : false dsl with Not_found -> None |
let mark_post_docs pos = try let dsl = Hashtbl . find post_table pos in associate_docstrings dsl with Not_found -> ( ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.