text
stringlengths
12
786k
type style = { tag_open : string ; tag_close : string }
type atom_param = { atom_style : style_name option ; }
let atom = { atom_style = None }
type list_param = { space_after_opening : bool ; space_after_separator : bool ; space_before_separator : bool ; separators_stick_left : bool ; space_before_closing : bool ; stick_to_label : bool ; align_closing : bool ; wrap_body : wrap ; indent_body : int ; list_style : style_name option...
let list = { space_after_opening = true ; space_after_separator = true ; space_before_separator = false ; separators_stick_left = true ; space_before_closing = true ; stick_to_label = true ; align_closing = true ; wrap_body = ` Wrap_atoms ; indent_body = 2 ; list_style = None ; openi...
type label_param = { label_break : label_break ; space_after_label : bool ; indent_after_label : int ; label_style : style_name option ; }
let label = { label_break = ` Auto ; space_after_label = true ; indent_after_label = 2 ; label_style = None ; }
type t = Atom of string * atom_param | List of ( string * string * string * list_param ) * t list | Label of ( t * label_param ) * t | Custom of ( Format . formatter -> unit )
type escape = [ ` None | ` Escape of ( ( string -> int -> int -> unit ) -> string -> int -> int -> unit ) | ` Escape_string of ( string -> string ) ]
type styles = ( style_name * style ) list
let propagate_from_leaf_to_root ~ init_acc ~ merge_acc ~ map_node x = let rec aux x = match x with | Atom _ -> let acc = init_acc x in map_node x acc | List ( param , children ) -> let new_children , accs = rev_split ( List . rev_map aux children ) in let acc = List . fold_left merge_acc ( ...
let propagate_forced_breaks x = let init_acc = function | List ( ( _ , _ , _ , { wrap_body = ` Force_breaks_rec ; _ } ) , _ ) | Label ( ( _ , { label_break = ` Always_rec ; _ } ) , _ ) -> true | Atom _ | Label _ | Custom _ | List _ -> false in let merg...
module Pretty = struct let rewrite x = propagate_forced_breaks x let set_escape fmt escape = let print0 , flush0 = Format . pp_get_formatter_output_functions fmt ( ) in let tagf0 = Format . pp_get_formatter_stag_functions fmt ( ) in let is_tag = ref false in let mot tag = is_tag := true ; tagf0 ...
module Compact = struct open Printf let rec fprint_t buf = function Atom ( s , _ ) -> Buffer . add_string buf s | List ( param , l ) -> fprint_list buf param l | Label ( label , x ) -> fprint_pair buf label x | Custom f -> let fmt = Format . formatter_of_buffer buf in f fmt ; Format ....
module Param = struct let list_true = { space_after_opening = true ; space_after_separator = true ; space_before_separator = true ; separators_stick_left = true ; space_before_closing = true ; stick_to_label = true ; align_closing = true ; wrap_body = ` Wrap_atoms ; indent_body = 2 ; l...
let lex_on_load = ref true
let compiler_preferences master = let tl = Jg_toplevel . titled " Compiler " in Wm . transient_set tl ~ master ; let mk_chkbutton ~ text ~ ref ~ invert = let variable = Textvariable . create ~ on : tl ( ) in if ( if invert then not ! ref else ! ref ) then Textvariable . set variable " ...
let rec exclude txt = function [ ] -> [ ] | x :: l -> if txt . number = x . number then l else x :: exclude txt l
let goto_line tw = let tl = Jg_toplevel . titled " Go to " in Wm . transient_set tl ~ master ( : Winfo . toplevel tw ) ; Jg_bind . escape_destroy tl ; let ef = Frame . create tl in let fl = Frame . create ef and fi = Frame . create ef in let ll = Label . create fl ~ text " : Line...
let select_shell txt = let shells = Shell . get_all ( ) in let shells = List . sort shells ~ cmp : compare in let tl = Jg_toplevel . titled " Select Shell " in Jg_bind . escape_destroy tl ; Wm . transient_set tl ~ master ( : Winfo . toplevel txt . tw ) ; let label = Label . crea...
let send_phrase txt = if txt . shell = None then begin match Shell . get_all ( ) with [ ] -> ( ) | [ sh ] -> txt . shell <- Some sh | l -> select_shell txt end ; match txt . shell with None -> ( ) | Some ( _ , sh ) -> try let i1 , i2 = Text . tag_nextrange txt . tw...
let search_pos_window txt ~ x ~ y = if txt . type_info = [ ] && txt . psignature = [ ] then ( ) else let ` Linechar ( l , c ) = Text . index txt . tw ~ index ( ` : Atxy ( x , y ) , [ ] ) in let text = Jg_text . get_all txt . tw in let pos = Searchpos . line...
let search_pos_menu txt ~ x ~ y = if txt . type_info = [ ] && txt . psignature = [ ] then ( ) else let ` Linechar ( l , c ) = Text . index txt . tw ~ index ( ` : Atxy ( x , y ) , [ ] ) in let text = Jg_text . get_all txt . tw in let pos = Searchpos . lines_...
let string_width s = let width = ref 0 in for i = 0 to String . length s - 1 do if s . [ i ] = ' \ t ' then width := ( ! width / 8 + 1 ) * 8 else incr width done ; ! width
let indent_line = let ins = ` Mark " insert " and reg = Str . regexp " [ \ t ] " * in fun tw -> let ` Linechar ( l , c ) = Text . index tw ~ index ( : ins , [ ] ) and line = Text . get tw ~ start ( : ins , [ ` Linestart ] ) ~ stop ( : ins , [ ` Lin...
let already_open : editor list ref = ref [ ]
let editor ? file ( ? pos = 0 ) ( ? reuse = false ) ( ) = if ! already_open <> [ ] && let ed = List . hd ! already_open in try ed # reopen ~ file ~ pos ; true with Protocol . TkError _ -> already_open := [ ] ; false then ( ) else let top = Jg_toplevel . titled " OC...
let f ? file ? pos ( ? opendialog = false ) ( ) = if opendialog then Fileselect . f ~ title " : Open File " ~ action ( : function [ file ] -> editor ~ file ( ) | _ -> ( ) ) ~ filter ( " . { :* ml , mli } " ) ~ sync : true ( ) else editor ? file ? pos...
type t = | No_effects | Only_generative_effects of Mutability . t | Arbitrary_effects
let [ @ ocamlformat " disable " ] print ppf eff = match eff with | No_effects -> Format . fprintf ppf " no effects " | Only_generative_effects mut -> Format . fprintf ppf " only generative effects % a " Mutability . print mut | Arbitrary_effects -> Format . fprintf ppf " Arbitrary eff...
let compare eff1 eff2 = match eff1 , eff2 with | No_effects , No_effects -> 0 | No_effects , ( Only_generative_effects _ | Arbitrary_effects ) -> - 1 | Only_generative_effects mut1 , Only_generative_effects mut2 -> Mutability . compare mut1 mut2 | Only_generative_effects _ , No_effects ->...
let join eff1 eff2 = match eff1 , eff2 with | No_effects , No_effects | No_effects , Only_generative_effects _ | No_effects , Arbitrary_effects -> eff2 | Only_generative_effects _ , No_effects -> eff1 | Only_generative_effects mut1 , Only_generative_effects mut2 -> Only_generative_effects ( Mut...
let no_effects_prim ( prim : Clambda_primitives . primitive ) = match Semantics_of_primitives . for_primitive prim with | ( No_effects | Only_generative_effects ) , ( No_coeffects | Has_coeffects ) -> true | _ -> false
let rec no_effects ( flam : Flambda . t ) = match flam with | Var _ -> true | Let { defining_expr ; body ; _ } -> no_effects_named defining_expr && no_effects body | Let_mutable { body } -> no_effects body | Let_rec ( defs , body ) -> no_effects body && List . for_all ( fun ( ...
type ( ' a , ' b ) t = Left of ' a | Right of ' b
let left v = Left v
let right v = Right v
let map_left f = function
let map_right f = function
let map ~ left ~ right = function
let fold ~ left ~ right = function
let equal ~ left ~ right e1 e2 = match e1 , e2 with
let compare ~ left ~ right e1 e2 = match e1 , e2 with
let block_is_dead cfg_with_layout ( block : C . basic_block ) = let cfg = CL . cfg cfg_with_layout in Label . Set . is_empty block . predecessors && ( not block . is_trap_handler ) && not ( Label . equal cfg . entry_label block . start )
let rec eliminate_dead_blocks cfg_with_layout = let cfg = CL . cfg cfg_with_layout in if CL . preserve_orig_labels cfg_with_layout then Misc . fatal_error " Won ' t eliminate dead blocks when [ preserve_orig_labels ] is set " ; let found_dead = Label . Tbl . fold ( fun label block found -> i...
let run cfg_with_layout = eliminate_dead_blocks cfg_with_layout
module Domain = struct type t = | Reachable | Unreachable let top = Reachable let bot = Unreachable let compare left right = match left , right with | Reachable , Reachable -> 0 | Reachable , Unreachable -> 1 | Unreachable , Reachable -> - 1 | Unreachable , Unreachable -> 0 let join left r...
module Transfer = struct type domain = Domain . t type t = { normal : domain ; exceptional : domain } let basic value _ = { normal = value ; exceptional = value } let terminator value _ = { normal = value ; exceptional = value } end
module Dataflow = Cfg_dataflow . Forward ( Domain ) ( Transfer )
let run_dead_block : Cfg_with_layout . t -> unit = fun cfg_with_layout -> let cfg = Cfg_with_layout . cfg cfg_with_layout in match Dataflow . run cfg ( ) with | Result . Error _ -> Misc . fatal_error " Dataflow . run_dead_code : forward analysis did not reach a fix - point " | Result . ...
let is_fallthrough_block cfg_with_layout ( block : C . basic_block ) = let cfg = CL . cfg cfg_with_layout in if Label . equal cfg . entry_label block . start || block . is_trap_handler || List . length block . body > 0 || not ( C . is_pure_terminator block . terminator . desc ) the...
let rec disconnect_fallthrough_blocks cfg_with_layout = let cfg = CL . cfg cfg_with_layout in let found = Label . Tbl . fold ( fun label block found -> match is_fallthrough_block cfg_with_layout block with | None -> found | Some target_label -> if ! C . verbose then Printf . printf " block at % ...
let run cfg_with_layout = let cfg = CL . cfg cfg_with_layout in let len = Label . Tbl . length cfg . blocks in if ! C . verbose then CL . save_as_dot cfg_with_layout " before_elim_ft " ; disconnect_fallthrough_blocks cfg_with_layout ; Eliminate_dead_code . run_dead_block cfg_with_layout ; le...
let force_link_all = ref true
let link_all ( ) = if ! force_link_all then [ " - linkall " ] else [ ]
let usage ( ) = Printf . eprintf " Usage : % s < options > < files >\ n " ( Filename . basename Sys . argv . ( 0 ) ) ; Printf . eprintf " SPECIFIC OPTIONS :\ n " ; Printf . eprintf " - package < name >\ tRefer to package when compiling \ n " ; Printf . eprintf " ...
let jsopt : string list ref = ref [ ]
let output_name : string option ref = ref None
type mode = [ ` Link | ` Compile | ` Infer | ` Library | ` Pack | ` Obj | ` Shared | ` Interface ]
let mode : mode ref = ref ` Link
let do_compile ( ) = ! mode <> ` Infer
let do_interface ( ) = ! mode = ` Interface
let do_dump = ref false
let create_process ? in_ ? out ? err ? on_error name args = wait ? on_error ( create_process ? in_ ? out ? err name args )
let rec check_or_create_dir name = if name <> " " / then try ignore ( Unix . stat name ) with Unix . Unix_error _ -> ( check_or_create_dir ( Filename . dirname name ) ; try Unix . mkdir name 0o777 with | Unix . Unix_error ( Unix . EEXIST , _ , _ ) -> ( ) | Unix . Uni...
let prefix_output_dir name = match ! build_dir with " " -> name | d -> d ^ " " / ^ name
let chop_extension_if_any name = try Filename . chop_extension name with Invalid_argument _ -> name
let output_prefix ( ? ty = false ) name = let name = match ! output_name with | None -> if ! mode = ` Infer || ty then prefix_type_dir name else prefix_output_dir name | Some n -> if ! mode = ` Compile || ! mode = ` Infer then ( output_name := None ; n ) else prefix_output_dir name in ...
let set_mode m = if ! mode = ` Link then if ( m = ` Shared && ! kind <> ` ServerOpt ) || ( m = ` Infer && ! kind = ` Client ) || ( m = ` Interface && ! kind = ` Client ) then usage ( ) else mode := m else let args = let basic_args = [ " - pack " ; " - a " ...
let get_product_name ( ) = match ! output_name with | None -> Printf . eprintf " Please specify the name of the output file , using option - o \ n " ; %! exit 1 | Some name -> check_or_create_dir ( Filename . dirname name ) ; name
let build_library ( ) = create_process ! compiler ( [ " - a " ; " - o " ; get_product_name ( ) ] @ get_common_include ( ) @ ! args )
let build_pack ( ) = create_process ! compiler ( [ " - pack " ; " - o " ; get_product_name ( ) ] @ get_common_include ( ) @ ! args )
let build_obj ( ) = create_process ! compiler ( [ " - output - obj " ; " - o " ; get_product_name ( ) ] @ get_common_include ( ) @ ! args )
let build_shared ( ) = create_process ! compiler ( [ " - shared " ; " - o " ; get_product_name ( ) ] @ get_common_include ( ) @ ! args )
let get_thread_opt ( ) = match ! kind with ` Client -> [ ] | ` Server | ` ServerOpt -> [ " - thread " ]
let obj_ext ( ) = if ! kind = ` ServerOpt then " . cmx " else " . cmo "
let compile_ocaml ~ impl_intf file = let obj = let ext = match impl_intf with ` Impl -> obj_ext ( ) | ` Intf -> " . cmi " in output_prefix file ^ ext in create_process ! compiler ( [ " - c " ; " - o " ; obj ] @ ! args @ get_thread_opt ( ) @ get_common_include ( ) ...
let output_ocaml_interface file = create_process ! compiler ( [ " - i " ] @ ! args @ get_common_include ( ) @ get_common_ppx ( ) @ preprocess_opt ~ ocaml : true ! ppopt @ [ file ] )
let process_ocaml ~ impl_intf file = if do_compile ( ) then compile_ocaml ~ impl_intf file ; if ! mode = ` Interface then output_ocaml_interface file
let compile_obj file = if do_compile ( ) then ( create_process ! compiler ( ! args @ [ file ] ) ; args := ! args @ [ output_prefix file ^ ext_obj ] )
let run_command s = let v = Sys . command s in if v != 0 then failwith ( Printf . sprintf " Warning : command [ % s ] returned % d " s v )
let run_sed file = run_command ( " sed - i - e ' s [ $/ 1 - 9 ] [ 0 - 9 ] *$$ g ' " ^ file ) ; run_command ( " sed - i - e ' s / _ [ ( [ ] ) [ \\\\<>\\/\\ 1 / g ' " ^ file ) ; run_command ( Printf . sprintf " sed - i - e " \ s ' ( /\\ _...
let compile_server_type_eliom file = let obj = output_prefix ~ ty : true file ^ ! server_types_file_ext and ppopts = ! ppopt @ if ! pp_mode = ` Ppx then [ ] else [ " - impl " ] in if ! do_dump then ( let camlp4 , ppopt = get_pp_dump [ ] ( ( " - printer " :: " o " :: pp...
let output_eliom_interface ~ impl_intf file = if ! do_dump then ( Printf . eprintf " Dump ( - dump ) not supported for interface inference ( - i ) . " ; exit 1 ) ; let indent ch = let spaces = match ! pp_mode with ` Ppx -> " " | ` Camlp4 -> " " in try while true do let li...
let compile_eliom ~ impl_intf file = let obj = let ext = match ! kind with ` Client -> " . cmo " | ` Server | ` ServerOpt -> obj_ext ( ) in output_prefix file ^ ext in let ppopts = get_ppopts ~ impl_intf file in create_process ! compiler ( [ " - c " ; " - o " ; obj ] @ ...
let process_eliom ~ impl_intf file = match ! mode with | ` Infer when impl_intf = ` Impl -> compile_server_type_eliom file | ` Interface -> output_eliom_interface ~ impl_intf file | _ -> compile_eliom ~ impl_intf file
let build_server ( ? name = " a . out " ) ( ) = ignore name ; fail " Linking eliom server is not yet supported "
let build_client ( ) = let name = chop_extension_if_any ( get_product_name ( ) ) in let exe = prefix_output_dir ( Filename . basename name ) in check_or_create_dir ( Filename . dirname exe ) ; let js = name ^ " . js " in create_process ! compiler ( [ " - o " ; exe ] @...
let process_option ( ) = let i = ref 1 and ppx = ref false in while ! i < Array . length Sys . argv do match Sys . argv . ( ! i ) with | " - help " | " -- help " -> usage ( ) | " - no - autoload " -> autoload_predef := false ; incr i | " - dont - force - linkall ...
let main ( ) = let cmd = Filename . basename Sys . argv . ( 0 ) in let cmd = try let idx = String . index cmd ' . ' in String . sub cmd 0 idx with Not_found -> cmd in let k = match cmd with | " eliomopt " -> compiler := ocamlopt ; build_dir := default_server_dir ; ` ServerO...
let _ = main ( )
let usage ( ) = Printf . eprintf " Usage : % s - server < options > < files >\ n " ( Filename . basename Sys . argv . ( 0 ) ) ; Printf . eprintf " Usage : % s - client < options > < files >\ n " ( Filename . basename Sys . argv . ( 0 ) ) ; Printf . epri...
let inode_of_dir d = ( Unix . stat d ) . Unix . st_ino
let do_dump = ref false
let mode : [ ` Normal | ` Sort ] ref = ref ` Normal
let sort_files = ref [ ]
let eliom_inc_dirs = ref [ " . " ]
let eliom_inc_inodes = ref [ inode_of_dir " . " ]
let do_sort ( ) = ! mode = ` Sort
let in_an_eliom_inc_dir s = List . exists ( fun d_inode -> inode_of_dir ( Filename . dirname s ) = d_inode ) ! eliom_inc_inodes