text
stringlengths
12
786k
let pp ppf v = Fmt . pf ppf { | { title = % a ; slug = % a ; location = % a ; date = % a ; important_dates = % a ; presentations = % a ; program_committee = % a ; organising_committee = % a ; body_md = % a ; toc_html = % a ; body_html = % a } } | Pp . string v . title Pp . string v . slug Pp ( . string ) string v . location Pp . string v . date Pp ( . list pp_important_date ) pp_important_date v . important_dates Pp ( . list pp_presentation ) pp_presentation v . presentations Pp ( . list pp_committee_member ) pp_committee_member v . program_committee Pp ( . list pp_committee_member ) pp_committee_member v . organising_committee Pp . string v . body_md Pp . string v . toc_html Pp . string v . body_html
let pp_list = Pp . list pp
let template ( ) = Format . asprintf { |
type role = [ ` Chair | ` Co_chair ]
type important_date = { date : string ; info : string }
type committee_member = { name : string ; role : role option ; affiliation : string option ; picture : string option ; }
type presentation = { title : string ; authors : string list ; link : string option ; video : string option ; slides : string option ; poster : bool option ; additional_links : string list option ; }
type t = { title : string ; slug : string ; location : string ; date : string ; important_dates : important_date list ; presentations : presentation list ; program_committee : committee_member list ; organising_committee : committee_member list ; toc_html : string ; body_md : string ; body_html : string ; }
let all = % a } | pp_list ( all ( ) )
let env_field , env_field_lazy = let make f g = field " env " ~ default ( : f Dune_env . Stanza . empty ) ( g ( Dune_lang . Syntax . since syntax ( 1 , 1 ) >>> Dune_env . Stanza . decode ) ) in ( make Fun . id Fun . id , make Lazy . from_val lazy_ )
module Context = struct module Target = struct type t = | Native | Named of Context_name . t let equal x y = match ( x , y ) with | Native , Native -> true | Native , _ | _ , Native -> false | Named x , Named y -> Context_name . equal x y let t = let + context_name = Context_name . decode in match Context_name . to_string context_name with | " native " -> Native | _ -> Named context_name let add ts x = match x with | None -> ts | Some t -> if List . mem ts t ~ equal then ts else ts @ [ t ] end module Common = struct type t = { loc : Loc . t ; profile : Profile . t ; targets : Target . t list ; env : Dune_env . Stanza . t ; toolchain : Context_name . t option ; name : Context_name . t ; host_context : Context_name . t option ; paths : ( string * Ordered_set_lang . t ) list ; fdo_target_exe : Path . t option ; dynamically_linked_foreign_archives : bool ; instrument_with : Lib_name . t list ; merlin : bool } let to_dyn = Dyn . opaque let equal { loc = _ ; profile ; targets ; env ; toolchain ; name ; host_context ; paths ; fdo_target_exe ; dynamically_linked_foreign_archives ; instrument_with ; merlin } t = Profile . equal profile t . profile && List . equal Target . equal targets t . targets && Dune_env . Stanza . equal env t . env && Option . equal Context_name . equal toolchain t . toolchain && Context_name . equal name t . name && Option . equal Context_name . equal host_context t . host_context && List . equal ( Tuple . T2 . equal String . equal Ordered_set_lang . equal ) paths t . paths && Option . equal Path . equal fdo_target_exe t . fdo_target_exe && Bool . equal dynamically_linked_foreign_archives t . dynamically_linked_foreign_archives && List . equal Lib_name . equal instrument_with t . instrument_with && Bool . equal merlin t . merlin let fdo_suffix t = match t . fdo_target_exe with | None -> " " | Some file -> let name , _ = Path . split_extension file in " - fdo " - ^ Path . basename name let t = let + env = env_field and + targets = field " targets " ( repeat Target . t ) ~ default [ : Target . Native ] and + profile = field_o " profile " Profile . decode and + host_context = field_o " host " ( Dune_lang . Syntax . since syntax ( 1 , 10 ) >>> Context_name . decode ) and + toolchain = field_o " toolchain " ( Dune_lang . Syntax . since syntax ( 1 , 5 ) >>> Context_name . decode ) and + dynamically_linked_foreign_archives = let + disable = field ~ default : false " disable_dynamically_linked_foreign_archives " ( Dune_lang . Syntax . since syntax ( 2 , 0 ) >>> bool ) in not disable and + fdo_target_exe = let f file = let ext = Filename . extension file in if ext = " . exe " then Path . ( relative root file ) else User_error . raise [ Pp . textf " ` fdo % s ` expects executable filename ending with . exe \ extension , not % s . \ n \ Please specify the name of the executable to optimize , \ including path from < root . " > file ext ] in field_o " fdo " ( Dune_lang . Syntax . since syntax ( 2 , 0 ) >>> map string ~ f ) and + paths = let f l = match Env . Map . of_list ( List . map ~ f ( : fun ( ( loc , s ) , _ ) -> ( s , loc ) ) l ) with | Ok _ -> List . map ~ f ( : fun ( ( _ , s ) , x ) -> ( s , x ) ) l | Error ( var , _ , loc ) -> User_error . raise ~ loc [ Pp . textf " the variable % S can appear at most once in this stanza . " var ] in field " paths " ~ default [ ] : ( Dune_lang . Syntax . since Stanza . syntax ( 1 , 12 ) >>> map ~ f ( repeat ( pair ( located string ) Ordered_set_lang . decode ) ) ) and + instrument_with = field_o " instrument_with " ( Dune_lang . Syntax . since syntax ( 2 , 7 ) >>> repeat Lib_name . decode ) and + loc = loc and + merlin = field_b " merlin " in fun ~ profile_default ~ instrument_with_default -> let profile = Option . value profile ~ default : profile_default in let instrument_with = Option . value instrument_with ~ default : instrument_with_default in Option . iter host_context ~ f ( : fun _ -> match targets with | [ Target . Native ] -> ( ) | _ -> User_error . raise ~ loc [ Pp . text " ` targets ` and ` host ` options cannot be used in the same \ context . " ] ) ; { targets ; profile ; loc ; env ; name = Context_name . default ; host_context ; toolchain ; paths ; fdo_target_exe ; dynamically_linked_foreign_archives ; instrument_with ; merlin } end module Opam = struct type t = { base : Common . t ; switch : string ; root : string option } let to_dyn { base ; switch ; root } = let open Dyn in record [ ( " base " , Common . to_dyn base ) ; ( " switch " , string switch ) ; ( " root " , option string root ) ] let equal { base ; switch ; root } t = Common . equal base t . base && String . equal switch t . switch && Option . equal String . equal root t . root let t = let + loc_switch , switch = field " switch " ( located string ) and + name = field_o " name " Context_name . decode and + root = field_o " root " string and + base = Common . t in fun ~ profile_default ~ instrument_with_default ~ x -> let base = base ~ profile_default ~ instrument_with_default in let name = match name with | Some s -> s | None -> ( let name = switch ^ Common . fdo_suffix base in match Context_name . of_string_opt name with | Some s -> s | None -> User_error . raise ~ loc : loc_switch [ Pp . textf " Generated context name % S is invalid " name ; Pp . text " Please specify a context name manually with the ( name . . ) \ field " ] ) in let base = { base with targets = Target . add base . targets x ; name } in { base ; switch ; root } end module Default = struct type t = Common . t let to_dyn = Common . to_dyn let t = let + common = Common . t and + name = field_o " name " ( Dune_lang . Syntax . since syntax ( 1 , 10 ) >>= fun ( ) -> Context_name . decode ) in fun ~ profile_default ~ instrument_with_default ~ x -> let common = common ~ profile_default ~ instrument_with_default in let default = let name = Context_name . to_string common . name ^ Common . fdo_suffix common in Context_name . parse_string_exn ( Loc . none , name ) in let name = Option . value ~ default name in { common with targets = Target . add common . targets x ; name } let equal = Common . equal end type t = | Default of Default . t | Opam of Opam . t let hash = Hashtbl . hash let to_dyn = let open Dyn in function | Default d -> variant " Default " [ Default . to_dyn d ] | Opam o -> variant " Opam " [ Opam . to_dyn o ] let equal x y = match ( x , y ) with | Default x , Default y -> Default . equal x y | Opam x , Opam y -> Opam . equal x y | _ , _ -> false let loc = function | Default x -> x . loc | Opam x -> x . base . loc let host_context = function | Default { host_context ; _ } | Opam { base = { host_context ; _ } ; _ } -> host_context let t = sum [ ( " default " , let + f = fields Default . t in fun ~ profile_default ~ instrument_with_default ~ x -> Default ( f ~ profile_default ~ instrument_with_default ~ x ) ) ; ( " opam " , let + f = fields Opam . t in fun ~ profile_default ~ instrument_with_default ~ x -> Opam ( f ~ profile_default ~ instrument_with_default ~ x ) ) ] let env = function | Default d -> d . env | Opam o -> o . base . env let name = function | Default d -> d . name | Opam o -> o . base . name let targets = function | Default x -> x . targets | Opam x -> x . base . targets let all_names t = let n = name t in n :: List . filter_map ( targets t ) ~ f ( : function | Native -> None | Named s -> Some ( Context_name . target n ~ toolchain : s ) ) let default ~ x ~ profile ~ instrument_with = Default { loc = Loc . of_pos __POS__ ; targets = [ Option . value x ~ default : Target . Native ] ; profile = Option . value profile ~ default : Profile . default ; name = Context_name . default ; host_context = None ; env = Dune_env . Stanza . empty ; toolchain = None ; paths = [ ] ; fdo_target_exe = None ; dynamically_linked_foreign_archives = true ; instrument_with = Option . value instrument_with ~ default [ ] : ; merlin = false } let build_contexts t = let name = name t in let native = Build_context . create ~ name ~ host ( : host_context t ) in native :: List . filter_map ( targets t ) ~ f ( : function | Native -> None | Named toolchain -> let name = Context_name . target name ~ toolchain in Some ( Build_context . create ~ name ~ host ( : Some native . name ) ) ) end
type t = { merlin_context : Context_name . t option ; contexts : Context . t list ; env : Dune_env . Stanza . t ; config : Dune_config . t }
let to_dyn { merlin_context ; contexts ; env ; config } = let open Dyn in record [ ( " merlin_context " , option Context_name . to_dyn merlin_context ) ; ( " contexts " , list Context . to_dyn contexts ) ; ( " env " , Dune_env . Stanza . to_dyn env ) ; ( " config " , Dune_config . to_dyn config ) ]
let equal { merlin_context ; contexts ; env ; config } w = Option . equal Context_name . equal merlin_context w . merlin_context && List . equal Context . equal contexts w . contexts && Dune_env . Stanza . equal env w . env && Dune_config . equal config w . config
let hash { merlin_context ; contexts ; env ; config } = Hashtbl . hash ( Option . hash Context_name . hash merlin_context , List . hash Context . hash contexts , Dune_env . Stanza . hash env , Dune_config . hash config ) type t = unit end )
let ( ) = Lang . register syntax ( )
module Clflags = struct type t = { x : Context_name . t option ; profile : Profile . t option ; instrument_with : Lib_name . t list option ; workspace_file : Path . t option ; config_from_command_line : Dune_config . Partial . t ; config_from_config_file : Dune_config . Partial . t } let to_dyn { x ; profile ; instrument_with ; workspace_file ; config_from_command_line ; config_from_config_file } = let open Dyn in record [ ( " x " , option Context_name . to_dyn x ) ; ( " profile " , option Profile . to_dyn profile ) ; ( " instrument_with " , option ( list Lib_name . to_dyn ) instrument_with ) ; ( " workspace_file " , option Path . to_dyn workspace_file ) ; ( " config_from_command_line " , Dune_config . Partial . to_dyn config_from_command_line ) ; ( " config_from_config_file " , Dune_config . Partial . to_dyn config_from_config_file ) ] let t = Fdecl . create to_dyn let set v = Fdecl . set t v let t ( ) = Fdecl . get t end
let bad_configuration_check map = let find_exn loc name host = match Context_name . Map . find map host with | Some host_ctx -> host_ctx | None -> User_error . raise ~ loc [ Pp . textf " Undefined host context ' % s ' for ' % s ' . " ( Context_name . to_string host ) ( Context_name . to_string name ) ] in let check elt = Context . host_context elt |> Option . iter ~ f ( : fun host -> let name = Context . name elt in let loc = Context . loc elt in let host_elt = find_exn loc name host in Context . host_context host_elt |> Option . iter ~ f ( : fun host_of_host -> User_error . raise ~ loc ( : Context . loc host_elt ) [ Pp . textf " Context ' % s ' is both a host ( for ' % s ' ) and a target \ ( for ' % s ' ) . " ( Context_name . to_string host ) ( Context_name . to_string name ) ( Context_name . to_string host_of_host ) ] ) ) in Context_name . Map . iter map ~ f : check
let top_sort contexts = let key = Context . name in let map = Context_name . Map . of_list_map_exn contexts ~ f ( : fun x -> ( key x , x ) ) in let deps def = match Context . host_context def with | None -> [ ] | Some ctx -> [ Context_name . Map . find_exn map ctx ] in bad_configuration_check map ; match Context_name . Top_closure . top_closure ~ key ~ deps contexts with | Ok topo_contexts -> topo_contexts | Error _ -> assert false
let create_final_config ~ config_from_config_file ~ config_from_command_line ~ config_from_workspace_file = let ( ++ ) = Dune_config . superpose in Dune_config . default ++ config_from_config_file ++ config_from_workspace_file ++ config_from_command_line
module Step1 = struct type nonrec t = { t : t Lazy . t ; config : Dune_config . t } end
let step1 clflags = let { Clflags . x ; profile = cl_profile ; instrument_with = cl_instrument_with ; workspace_file = _ ; config_from_command_line ; config_from_config_file } = clflags in let x = Option . map x ~ f ( : fun s -> Context . Target . Named s ) in let superpose_with_command_line cl field = let + x = field in lazy ( Option . value cl ~ default ( : Lazy . force x ) ) in let * ( ) = Dune_lang . Versioned_file . no_more_lang and + env = env_field_lazy and + profile = superpose_with_command_line cl_profile ( field " profile " ( lazy_ Profile . decode ) ~ default ( : lazy Profile . default ) ) and + instrument_with = superpose_with_command_line cl_instrument_with ( field " instrument_with " ( lazy_ ( Dune_lang . Syntax . since Stanza . syntax ( 2 , 7 ) >>> repeat Lib_name . decode ) ) ~ default ( : lazy [ ] ) ) and + config_from_workspace_file = Dune_config . decode_fields_of_workspace_file in let + contexts = multi_field " context " ( lazy_ Context . t ) in let config = create_final_config ~ config_from_workspace_file ~ config_from_config_file ~ config_from_command_line in let t = lazy ( let profile = Lazy . force profile in let instrument_with = Lazy . force instrument_with in let contexts = List . map contexts ~ f ( : fun f -> Lazy . force f ~ profile_default : profile ~ instrument_with_default : instrument_with ~ x ) in let env = Lazy . force env in let defined_names = ref Context_name . Set . empty in let merlin_context = List . fold_left contexts ~ init : None ~ f ( : fun acc ctx -> let name = Context . name ctx in if Context_name . Set . mem ! defined_names name then User_error . raise ~ loc ( : Context . loc ctx ) [ Pp . textf " second definition of build context % S " ( Context_name . to_string name ) ] ; defined_names := Context_name . Set . union ! defined_names ( Context_name . Set . of_list ( Context . all_names ctx ) ) ; match ( ctx , acc ) with | Opam { base = { merlin = true ; _ } ; _ } , Some _ | Default { merlin = true ; _ } , Some _ -> User_error . raise ~ loc ( : Context . loc ctx ) [ Pp . text " you can only have one context for merlin " ] | Opam { base = { merlin = true ; _ } ; _ } , None | Default { merlin = true ; _ } , None -> Some name | _ -> acc ) in let contexts = match contexts with | [ ] -> [ Context . default ~ x ~ profile ( : Some profile ) ~ instrument_with ( : Some instrument_with ) ] | _ -> contexts in let merlin_context = match merlin_context with | Some _ -> merlin_context | None -> if List . exists contexts ~ f ( : function | Context . Default _ -> true | _ -> false ) then Some Context_name . default else None in { merlin_context ; contexts = top_sort ( List . rev contexts ) ; env ; config } ) in { Step1 . t ; config }
let step1 clflags = fields ( step1 clflags )
let default clflags = let { Clflags . x ; profile ; instrument_with ; workspace_file = _ ; config_from_command_line ; config_from_config_file } = clflags in let x = Option . map x ~ f ( : fun s -> Context . Target . Named s ) in let config = create_final_config ~ config_from_config_file ~ config_from_command_line ~ config_from_workspace_file : Dune_config . Partial . empty in { merlin_context = Some Context_name . default ; contexts = [ Context . default ~ x ~ profile ~ instrument_with ] ; env = Dune_env . Stanza . empty ; config }
let default_step1 clflags = let t = default clflags in { Step1 . t = lazy t ; config = t . config }
let load_step1 clflags p = Io . with_lexbuf_from_file p ~ f ( : fun lb -> if Dune_lexer . eof_reached lb then default_step1 clflags else parse_contents lb ~ f ( : fun lang -> String_with_vars . set_decoding_env ( Pform . Env . initial lang . version ) ( step1 clflags ) ) )
let workspace_step1 = let open Memo . O in let f ( ) = let clflags = Clflags . t ( ) in let + workspace_file = match clflags . workspace_file with | None -> let p = Path . of_string filename in let + exists = Fs_memo . file_exists p in Option . some_if exists p | Some p -> ( Fs_memo . file_exists p >>| function | true -> Some p | false -> User_error . raise [ Pp . textf " Workspace file % s does not exist " ( Path . to_string_maybe_quoted p ) ] ) in let clflags = { clflags with workspace_file } in match workspace_file with | None -> default_step1 clflags | Some p -> load_step1 clflags p in let memo = Memo . create " workspaces - internal " ~ input ( : module Unit ) f in Memo . exec memo
let workspace_config ( ) = let open Memo . O in let + step1 = workspace_step1 ( ) in step1 . config
let workspace = let open Memo . O in let f ( ) = let + step1 = workspace_step1 ( ) in Lazy . force step1 . t in let memo = Memo . create " workspace " ~ input ( : module Unit ) ~ cutoff : equal f in Memo . exec memo
let update_execution_parameters t ep = ep |> Execution_parameters . set_action_stdout_on_success t . config . action_stdout_on_success |> Execution_parameters . set_action_stderr_on_success t . config . action_stderr_on_success
let build_contexts t = List . concat_map t . contexts ~ f : Context . build_contexts
module Uri_map = Map . Make ( struct include Uri let compare x y = Ordering . of_int ( compare x y ) end )
type t = { workspace_folders : WorkspaceFolder . t Uri_map . t option ; root_uri : Uri . t option ; root_path : string option }
let create ( ip : InitializeParams . t ) = let workspace_folders = match ip . workspaceFolders with | None | Some None -> None | Some ( Some workspace_folders ) -> Uri_map . of_list_map_exn workspace_folders ~ f ( : fun ( ws : WorkspaceFolder . t ) -> ( ws . uri , ws ) ) |> Option . some in let root_uri = ip . rootUri in let root_path = match ip . rootPath with | None -> None | Some s -> s in { workspace_folders ; root_uri ; root_path }
let on_change t { DidChangeWorkspaceFoldersParams . event = { added ; removed } } = assert ( t . workspace_folders <> None ) ; let workspace_folders = let init = Option . value t . workspace_folders ~ default : Uri_map . empty in let init = List . fold_left removed ~ init ~ f ( : fun acc ( a : WorkspaceFolder . t ) -> Uri_map . remove acc a . uri ) in List . fold_left added ~ init ~ f ( : fun acc ( a : WorkspaceFolder . t ) -> Uri_map . set acc a . uri a ) |> Option . some in { t with workspace_folders }
let workspace_folders { root_uri ; root_path ; workspace_folders } = match workspace_folders with | Some s -> Uri_map . values s | None -> ( match ( workspace_folders , root_uri , root_path ) with | Some workspace_folders , _ , _ -> Uri_map . values workspace_folders | _ , Some root_uri , _ -> [ WorkspaceFolder . create ~ uri : root_uri ~ name ( : Filename . basename ( Uri . to_path root_uri ) ) ] | _ , _ , Some root_path -> [ WorkspaceFolder . create ~ uri ( : Uri . of_path root_path ) ~ name ( : Filename . basename root_path ) ] | _ -> let cwd = Sys . getcwd ( ) in [ WorkspaceFolder . create ~ uri ( : Uri . of_path cwd ) ~ name ( : Filename . basename cwd ) ] )
module Kind = struct type t = | Explicit | Dune_workspace | Dune_project | Cwd let priority = function | Explicit -> 0 | Dune_workspace -> 1 | Dune_project -> 2 | Cwd -> 3 let lowest_priority = max_int let of_dir_contents files = if String . Set . mem files Workspace . filename then Some Dune_workspace else if String . Set . mem files Dune_project . filename then Some Dune_project else None end
type t = { dir : string ; to_cwd : string list ; reach_from_root_prefix : string ; kind : Kind . t }
module Candidate = struct type t = { dir : string ; to_cwd : string list ; kind : Kind . t } end
let find ( ) = let cwd = Sys . getcwd ( ) in let rec loop counter ( ~ candidate : Candidate . t option ) ~ to_cwd dir : Candidate . t option = match Sys . readdir dir with | exception Sys_error msg -> User_warning . emit [ Pp . textf " Unable to read directory % s . Will not look for root in parent \ directories . " dir ; Pp . textf " Reason : % s " msg ; Pp . text " To remove this warning , set your root explicitly using -- root . " ] ; candidate | files -> let files = String . Set . of_list ( Array . to_list files ) in let candidate = let candidate_priority = match candidate with | Some c -> Kind . priority c . kind | None -> Kind . lowest_priority in match Kind . of_dir_contents files with | Some kind when Kind . priority kind <= candidate_priority -> Some { Candidate . kind ; dir ; to_cwd } | _ -> candidate in cont counter ~ candidate dir ~ to_cwd and cont counter ~ candidate ~ to_cwd dir = if counter > String . length cwd then candidate else let parent = Filename . dirname dir in if parent = dir then candidate else let base = Filename . basename dir in loop ( counter + 1 ) parent ~ candidate ~ to_cwd ( : base :: to_cwd ) in loop 0 ~ to_cwd [ ] : cwd ~ candidate : None
let create ~ default_is_cwd ~ specified_by_user = match match specified_by_user with | Some dn -> Some { Candidate . kind = Explicit ; dir = dn ; to_cwd = [ ] } | None -> ( let cwd = { Candidate . kind = Cwd ; dir = " . " ; to_cwd = [ ] } in if Dune_util . Config . inside_dune then Some cwd else match find ( ) with | Some s -> Some s | None -> if default_is_cwd then Some cwd else None ) with | Some { Candidate . dir ; to_cwd ; kind } -> { kind ; dir ; to_cwd ; reach_from_root_prefix = String . concat ~ sep " " : ( List . map to_cwd ~ f ( : sprintf " % s " ) ) / } | None -> User_error . raise [ Pp . text " I cannot find the root of the current workspace / project . " ; Pp . text " If you would like to create a new dune project , you can type " : ; Pp . nop ; Pp . verbatim " dune init project NAME " ; Pp . nop ; Pp . text " Otherwise , please make sure to run dune inside an existing project \ or workspace . For more information about how dune identifies the \ root of the current workspace / project , please refer to \ https :// dune . readthedocs . io / en / stable / usage . html # finding - the - root " ]
let browse_of_cmt ( cmt_infos : Cmt_format . cmt_infos ) : Browse_raw . node option = match cmt_infos . cmt_annots with | Implementation str -> Some ( Structure str ) | Interface sig_ -> Some ( Signature sig_ ) | Packed _ | Partial_implementation _ | Partial_interface _ -> None
let is_directory dir = try Sys . is_directory dir with Sys_error _ -> false
type error = Build_dir_not_found of string
let find_build_dir ( { name ; uri } : WorkspaceFolder . t ) = let build_dir = Filename . concat ( Uri . to_path uri ) " _build / default " in if is_directory build_dir then Ok build_dir else Error ( Build_dir_not_found name )
type cm_file = | Cmt of string | Cmti of string
let string_of_cm cm = match cm with | Cmt f | Cmti f -> f
module Outline : sig val get : Merlin_analysis . Browse_tree . t list -> Query_protocol . item list module Location = Loc open Merlin_utils open Merlin_analysis open Std open Option . Infix open Typedtree open Browse_raw open Browse_tree let id_of_patt = function | { pat_desc = Tpat_var ( id , _ ) ; _ } -> Some id | _ -> None let mk ( ? children = [ ] ) ~ location ~ deprecated outline_kind id = { Query_protocol . outline_kind ; outline_type = None ; location ; children ; outline_name = Ident . name id ; deprecated } let get_class_field_desc_infos = function | Typedtree . Tcf_val ( str_loc , _ , _ , _ , _ ) -> Some ( str_loc , ` Value ) | Typedtree . Tcf_method ( str_loc , _ , _ ) -> Some ( str_loc , ` Method ) | _ -> None let rec summarize node = let location = node . t_loc in match node . t_node with | Value_binding vb -> ( let deprecated = Type_utils . is_deprecated vb . vb_attributes in match id_of_patt vb . vb_pat with | None -> None | Some ident -> Some ( mk ~ location ~ deprecated ` Value ident ) ) | Value_description vd -> let deprecated = Type_utils . is_deprecated vd . val_attributes in Some ( mk ~ location ~ deprecated ` Value vd . val_id ) | Module_declaration md -> ( let children = get_mod_children node in match md . md_id with | None -> None | Some id -> let deprecated = Type_utils . is_deprecated md . md_attributes in Some ( mk ~ children ~ location ~ deprecated ` Module id ) ) | Module_binding mb -> ( let children = get_mod_children node in match mb . mb_id with | None -> None | Some id -> let deprecated = Type_utils . is_deprecated mb . mb_attributes in Some ( mk ~ children ~ location ~ deprecated ` Module id ) ) | Module_type_declaration mtd -> let children = get_mod_children node in let deprecated = Type_utils . is_deprecated mtd . mtd_attributes in Some ( mk ~ deprecated ~ children ~ location ` Modtype mtd . mtd_id ) | Type_declaration td -> let children = List . concat_map ( Lazy . force node . t_children ) ~ f ( : fun child -> match child . t_node with | Type_kind _ -> List . map ( Lazy . force child . t_children ) ~ f ( : fun x -> match x . t_node with | Constructor_declaration c -> let deprecated = Type_utils . is_deprecated c . cd_attributes in mk ` Constructor c . cd_id ~ deprecated ~ location : c . cd_loc | Label_declaration ld -> let deprecated = Type_utils . is_deprecated ld . ld_attributes in mk ` Label ld . ld_id ~ deprecated ~ location : ld . ld_loc | _ -> assert false ) | _ -> [ ] ) in let deprecated = Type_utils . is_deprecated td . typ_attributes in Some ( mk ~ children ~ location ~ deprecated ` Type td . typ_id ) | Type_extension te -> let name = Path . name te . tyext_path in let children = List . filter_map ( Lazy . force node . t_children ) ~ f ( : fun x -> summarize x >>| fun x -> { x with Query_protocol . outline_kind = ` Constructor } ) in let deprecated = Type_utils . is_deprecated te . tyext_attributes in Some { Query_protocol . outline_name = name ; outline_kind = ` Type ; outline_type = None ; location ; children ; deprecated } | Extension_constructor ec -> let deprecated = Type_utils . is_deprecated ec . ext_attributes in Some ( mk ~ location ` Exn ec . ext_id ~ deprecated ) | Class_declaration cd -> let children = List . concat_map ( Lazy . force node . t_children ) ~ f : get_class_elements in let deprecated = Type_utils . is_deprecated cd . ci_attributes in Some ( mk ~ children ~ location ` Class cd . ci_id_class_type ~ deprecated ) | _ -> None and get_class_elements node = match node . t_node with | Class_expr _ -> List . concat_map ( Lazy . force node . t_children ) ~ f : get_class_elements | Class_structure _ -> List . filter_map ( Lazy . force node . t_children ) ~ f ( : fun child -> match child . t_node with | Class_field cf -> ( match get_class_field_desc_infos cf . cf_desc with | Some ( str_loc , outline_kind ) -> let deprecated = Type_utils . is_deprecated cf . cf_attributes in Some { Query_protocol . outline_name = str_loc . Location . txt ; outline_kind ; outline_type = None ; location = str_loc . Location . loc ; children = [ ] ; deprecated } | None -> None ) | _ -> None ) | _ -> [ ] and get_mod_children node = List . concat_map ( Lazy . force node . t_children ) ~ f : remove_mod_indir and remove_mod_indir node = match node . t_node with | Module_expr _ | Module_type _ -> List . concat_map ( Lazy . force node . t_children ) ~ f : remove_mod_indir | _ -> remove_top_indir node and remove_top_indir t = match t . t_node with | Structure _ | Signature _ -> List . concat_map ~ f : remove_top_indir ( Lazy . force t . t_children ) | Signature_item _ | Structure_item _ -> List . filter_map ( Lazy . force t . t_children ) ~ f : summarize | _ -> [ ] let get browses = List . concat @@ List . rev_map ~ f : remove_top_indir browses end
let symbols_from_cm_file ~ filter root_uri cm_file = let cmt = let filename = string_of_cm cm_file in Cmt_format . read_cmt filename in match cmt . cmt_sourcefile with | None -> [ ] | Some sourcefile -> ( match Filename . extension sourcefile with | " . ml " | " . mli " -> ( match browse_of_cmt cmt with | None -> [ ] | Some browse -> let outline = let browse_tree = Merlin_analysis . Browse_tree . of_node browse in Outline . get [ browse_tree ] in let loc = Mbrowse . node_loc browse in let fname = loc . loc_start . pos_fname in let uri = Uri . of_path ( Filename . concat root_uri fname ) in filter ( Document_symbol . symbols_of_outline uri outline ) ) | _ -> [ ] )
let find_cm_files dir = let choose_file f1 f2 = match ( f1 , f2 ) with | ( Cmt _ as f ) , _ | _ , ( Cmt _ as f ) -> f | ( Cmti _ as f ) , Cmti _ -> f in let rec loop acc dir = let contents = Sys . readdir dir in Array . fold_left contents ~ init : acc ~ f ( : fun acc fname -> let path = Filename . concat dir fname in if is_directory path then loop acc path else match String . rsplit2 ~ on ' . ' : path with | Some ( path_without_ext , " cmt " ) -> String . Map . set acc path_without_ext ( Cmt path ) | Some ( path_without_ext , " cmti " ) -> ( let current_file = String . Map . find acc path_without_ext in let cmi_file = Cmti path in match current_file with | None -> String . Map . set acc path_without_ext cmi_file | Some current_file -> String . Map . set acc path_without_ext ( choose_file current_file cmi_file ) ) | _ -> acc ) in loop String . Map . empty dir |> String . Map . values
let run ( { query ; _ } : WorkspaceSymbolParams . t ) ( workspace_folders : WorkspaceFolder . t list ) = let filter = match query with | " " -> fun x -> x | query -> let re = Re . str query |> Re . compile in List . filter ~ f ( : fun ( symbol : SymbolInformation . t ) -> Re . execp re symbol . name ) in List . map workspace_folders ~ f ( : fun ( workspace_folder : WorkspaceFolder . t ) -> let open Result . O in let * build_dir = find_build_dir workspace_folder in Ok ( let cm_files = find_cm_files build_dir in let path = let uri = workspace_folder . uri in Uri . to_path uri in List . concat_map ~ f ( : symbols_from_cm_file ~ filter path ) cm_files ) )
module Make ( Inputs : Intf . Inputs_intf ) Inputs_intf = struct module Work_spec = Snark_work_lib . Work . Single . Spec module Job_status = struct type t = Assigned of Time . t let is_old ( Assigned at_time ) at_time ~ now ~ reassignment_wait = let max_age = Time . Span . of_ms ( Float . of_int reassignment_wait ) reassignment_wait in let delta = Time . diff now at_time in Time . Span ( . > ) delta max_age end module State = struct module Seen_key = struct module T = struct type t = Transaction_snark . Statement . t One_or_two . t [ @@ deriving compare , sexp , to_yojson , hash ] hash end include T include Comparable . Make ( T ) T end type t = { mutable available_jobs : ( Inputs . Transaction_witness . t , Inputs . Ledger_proof . t ) t Work_spec . t One_or_two . t list ; jobs_seen : ( Seen_key . t , Job_status . t ) t Hashtbl . t ; reassignment_wait : int } let init : reassignment_wait : int -> frontier_broadcast_pipe : Inputs . Transition_frontier . t option Pipe_lib . Broadcast_pipe . Reader . t -> logger : Logger . t -> t = fun ~ reassignment_wait ~ frontier_broadcast_pipe ~ logger -> let t = { available_jobs = [ ] ; jobs_seen = Hashtbl . create ( module Seen_key ) Seen_key ; reassignment_wait } in Pipe_lib . Broadcast_pipe . Reader . iter frontier_broadcast_pipe ~ f ( : fun frontier_opt -> ( match frontier_opt with | None -> [ % log debug ] debug " No frontier , setting available work to be empty " ; t . available_jobs <- [ ] | Some frontier -> Pipe_lib . Broadcast_pipe . Reader . iter ( Inputs . Transition_frontier . best_tip_pipe frontier ) frontier ~ f ( : fun _ -> let best_tip_staged_ledger = Inputs . Transition_frontier . best_tip_staged_ledger frontier in let start_time = Time . now ( ) in ( match Inputs . Staged_ledger . all_work_pairs best_tip_staged_ledger ~ get_state : ( Inputs . Transition_frontier . get_protocol_state frontier ) with | Error e -> [ % log fatal ] fatal " Error occured when updating available work : $ error " ~ metadata [ : ( " error " , Error_json . error_to_yojson e ) e ] | Ok new_available_jobs -> let end_time = Time . now ( ) in [ % log info ] info " Updating new available work took $ time ms " ~ metadata : [ ( " time " , ` Float ( Time . diff end_time start_time |> Time . Span . to_ms ) ) ] ; t . available_jobs <- new_available_jobs ) ; Deferred . unit ) |> Deferred . don ' t_wait_for ) ; Deferred . unit ) |> Deferred . don ' t_wait_for ; t let all_unseen_works t = List . filter t . available_jobs ~ f ( : fun js -> not @@ Hashtbl . mem t . jobs_seen ( One_or_two . map ~ f : Work_spec . statement js ) js ) let remove_old_assignments t ~ logger = let now = Time . now ( ) in Hashtbl . filteri_inplace t . jobs_seen ~ f ( : fun ~ key : work ~ data : status -> if Job_status . is_old status ~ now ~ reassignment_wait : t . reassignment_wait then ( [ % log info ] info ~ metadata [ : ( " work " , Seen_key . to_yojson work ) work ] " Waited too long to get work for $ work . Ready to be reassigned " ; Mina_metrics ( . Counter . inc_one Snark_work . snark_work_timed_out_rpc ) snark_work_timed_out_rpc ; false ) else true ) let remove t x = Hashtbl . remove t . jobs_seen ( One_or_two . map ~ f : Work_spec . statement x ) x let set t x = Hashtbl . set t . jobs_seen ~ key ( : One_or_two . map ~ f : Work_spec . statement x ) x ~ data ( : Job_status . Assigned ( Time . now ( ) ) ) end let does_not_have_better_fee ~ snark_pool ~ fee ( statements : Inputs . Transaction_snark_work . Statement . t ) t : bool = Option . value_map ~ default : true ( Inputs . Snark_pool . get_completed_work snark_pool statements ) statements ~ f ( : fun priced_proof -> let competing_fee = Inputs . Transaction_snark_work . fee priced_proof in Fee . compare fee competing_fee < 0 ) module For_tests = struct let does_not_have_better_fee = does_not_have_better_fee end let get_expensive_work ~ snark_pool ~ fee ( jobs : ( ' a , ' b ) ' b Work_spec . t One_or_two . t list ) list : ( ' a , ' b ) ' b Work_spec . t One_or_two . t list = List . filter jobs ~ f ( : fun job -> does_not_have_better_fee ~ snark_pool ~ fee ( One_or_two . map job ~ f : Work_spec . statement ) statement ) let all_pending_work ~ snark_pool statements = List . filter statements ~ f ( : fun st -> Option . is_none ( Inputs . Snark_pool . get_completed_work snark_pool st ) st ) let pending_work_statements ~ snark_pool ~ fee_opt ( state : State . t ) t = let all_todo_statements = List . map state . available_jobs ~ f ( : One_or_two . map ~ f : Work_spec . statement ) statement in let expensive_work statements ~ fee = List . filter statements ~ f ( : does_not_have_better_fee ~ snark_pool ~ fee ) fee in match fee_opt with | None -> all_pending_work ~ snark_pool all_todo_statements | Some fee -> expensive_work all_todo_statements ~ fee end
let anglex = ref 0 . 0
let angley = ref 30 . 0
let anglez = ref 0 . 0
let ball_radius = wall_size . / 3 . 0
let resting_space = spring_thickness . * spring_ncoils . + ( 2 . 0 . * ball_radius )
let left_offset = . - distance . / 4 . 0
let w1 = 0 . 0 . - ( wall_width . / 2 . 0 ) . - resting_space
let w2 = distance . + ( wall_width . / 2 . 0 ) . + resting_space
let lightOnePosition = ( 280 . 0 , 100 . 0 , 50 . 0 , 0 . 0 )
let lightAmbient = ( 0 . 5 , 0 . 5 , 0 . 5 , 1 . 0 )
let lightDiffuse = ( 0 . 2 , 0 . 2 , 0 . 2 , 1 . 0 )
let read_state fin = try let s = input_line fin in let i = String . index s ' , ' in let p1 = float_of_string ( String . sub s 0 i ) in let p2 = float_of_string ( String . sub s ( i + 1 ) ( String . length s - i - 1 ) ) in Some ( p1 , p2 ) with _ -> None
let draw_wall xpos = glPushMatrix ( ) ; glTranslate xpos 0 . 0 0 . 0 ; glScale wall_width wall_size wall_size ; glutSolidCube 1 . 0 ; glPopMatrix ( )
let draw_floor ( ) = glPushMatrix ( ) ; glTranslate ( distance . / 2 . 0 ) ( . - wall_size . / 2 . 0 ) 0 . 0 ; glScale ( w2 . - w1 . + wall_width ) wall_width wall_size ; glutSolidCube 1 . 0 ; glPopMatrix ( )
let draw_spring x1 x2 = let step_size = ( x2 . - x1 ) . / spring_ncoils in let length_degrees = spring_ncoils . * 360 . 0 in glPushMatrix ( ) ; glTranslate x1 0 . 0 0 . 0 ; glRotate 90 . 0 0 . 0 1 . 0 0 . 0 ; glScale 1 . 0 1 . 0 1 . 0 ; gleHelicoid spring_thickness spring_radius 0 . 0 0 . 0 step_size None None 0 . 0 length_degrees ; glPopMatrix ( )
let draw_ball x = glPushMatrix ( ) ; glTranslate x 0 . 0 0 . 0 ; glScale 1 . 0 1 . 0 1 . 0 ; glutSolidSphere ball_radius 24 24 ; glPopMatrix ( )
let display p1 p2 ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glLoadIdentity ( ) ; glTranslate 0 . 0 0 . 0 ( . - 2 . 5 ) ; glRotate ( ! angley ) 1 . 0 0 . 0 0 . 0 ; glRotate ( ! anglex ) 0 . 0 1 . 0 0 . 0 ; glRotate ( ! anglez ) 0 . 0 0 . 0 1 . 0 ; glPushMatrix ( ) ; glTranslate left_offset 0 . 0 0 . 0 ; glLight ( GL_LIGHT 0 ) ( Light . GL_POSITION lightOnePosition ) ; glScale 0 . 5 0 . 5 0 . 5 ; glColor3 0 . 0 0 . 5 0 . 0 ; glMaterial GL_FRONT ( Material . GL_AMBIENT ( 1 . 0 , 1 . 0 , 1 . 0 , 1 . 0 ) ) ; draw_wall w1 ; draw_wall w2 ; draw_floor ( ) ; glMaterial GL_FRONT_AND_BACK ( Material . GL_SHININESS 1 . 0 ) ; glColor3 0 . 8 0 . 8 0 . 8 ; draw_spring w1 ( ! p1 . - ball_radius . * 1 . 5 ) ; draw_spring w2 ( ! p2 . + ball_radius . * 1 . 5 ) ; glMaterial GL_FRONT ( Material . GL_SPECULAR ( 0 . 0 , 0 . 0 , 0 . 0 , 0 . 0 ) ) ; glColor3 1 . 0 0 . 0 0 . 0 ; draw_ball ( ! p1 . - ball_radius ) ; glColor3 0 . 0 0 . 0 1 . 0 ; draw_ball ( ! p2 . + ball_radius ) ; glPopMatrix ( ) ; glutSwapBuffers ( )
let make_model_functions p1i p2i fin = let p1 = ref p1i in let p2 = ref p2i in let rec update ~ value ( ) : = match read_state fin with | None -> schedule_update ( ) | Some ( p1 ' , p2 ' ) -> begin p1 := p1 ' ; p2 := p2 ' ; schedule_update ( ) ; glutPostRedisplay ( ) end and schedule_update ( ) = glutTimerFunc ~ msecs : update_period ~ timer : update ~ value ( ) : in ( display p1 p2 , update , schedule_update )
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; let aspect = ( ( float w ) . / ( float ( max 1 h ) ) ) in gluPerspective ~ fovy : 60 . 0 ~ aspect ~ zNear : 0 . 5 ~ zFar : 100 . 0 ; glMatrixMode GL_MODELVIEW ; glutPostRedisplay ( )
let keyboard ~ key ~ x ~ y = match key with | ' q ' | ' \ 027 ' -> exit 0 | _ -> ( )
let special ~ key ~ x ~ y = match key with | GLUT_KEY_LEFT -> ( anglex := ! anglex . - 5 . 00 ; glutPostRedisplay ( ) ) | GLUT_KEY_RIGHT -> ( anglex := ! anglex . + 5 . 00 ; glutPostRedisplay ( ) ) | GLUT_KEY_UP -> ( angley := ! angley . - 5 . 00 ; glutPostRedisplay ( ) ) | GLUT_KEY_DOWN -> ( angley := ! angley . + 5 . 00 ; glutPostRedisplay ( ) ) | _ -> ( )
let drag_last = ref ( None : ( int * int ) option )
let mouse ~ button ~ state ~ x ~ y = match button , state with | GLUT_LEFT_BUTTON , GLUT_DOWN -> drag_last := Some ( x , y ) | GLUT_LEFT_BUTTON , GLUT_UP -> drag_last := None | _ -> ( )
let motion ~ x ~ y = match ! drag_last with | None -> ( ) | Some ( xo , yo ) -> anglex := ! anglex . + ( float ( xo - x ) . * drag_scale ) ; angley := ! angley . + ( float ( yo - y ) . * drag_scale ) ; drag_last := Some ( x , y ) ; glutPostRedisplay ( )
let gl_init ( ) = glShadeModel GL_SMOOTH ; glClearColor 0 . 0 0 . 0 0 . 3 0 . 0 ; glClearDepth 1 . 0 ; glEnable GL_DEPTH_TEST ; gleSetJoinStyle [ TUBE_NORM_EDGE ; TUBE_JN_ANGLE ; TUBE_JN_CAP ] ; glLight ( GL_LIGHT 0 ) ( Light . GL_POSITION lightOnePosition ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_DIFFUSE lightDiffuse ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_AMBIENT lightAmbient ) ; glEnable GL_LIGHT0 ; glEnable GL_LIGHTING ; glColorMaterial GL_FRONT_AND_BACK GL_AMBIENT_AND_DIFFUSE ; glEnable GL_COLOR_MATERIAL
let run_glut_loop p1i p2i fin = Random . self_init ( ) ; ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DOUBLE ; GLUT_DEPTH ] ; ignore ( glutCreateWindow " Sticky Springs Visualisation " ) ; glutReshapeWindow ~ width : 800 ~ height : 600 ; glutSetCursor GLUT_CURSOR_CROSSHAIR ; gl_init ( ) ; let ( display , timer , start_timer ) = make_model_functions p1i p2i fin in glutDisplayFunc ~ display ; glutKeyboardFunc ~ keyboard ; glutSpecialFunc ~ special ; glutReshapeFunc ~ reshape ; glutMouseFunc ~ mouse ; glutMotionFunc ~ motion ; start_timer ( ) ; glutMainLoop ( )
let standalone ( ) = Unix . set_nonblock Unix . stdin ; run_glut_loop 0 . 0 distance stdin
let create p1i p2i = let input , output = Unix . pipe ( ) in let outch = Unix . out_channel_of_descr output in match Unix . fork ( ) with | 0 -> ( Unix . close input ; outch ) | _ -> begin Unix . close output ; Unix . set_nonblock input ; run_glut_loop p1i p2i ( Unix . in_channel_of_descr input ) ; outch end
let update fout p1 p2 = Printf . fprintf fout " % e , % e \ n " p1 p2 ; flush fout
let makeCheckImage ( ) = let checkImage = Bigarray . Array3 . create Bigarray . int8_unsigned Bigarray . c_layout checkImageHeight checkImageWidth 4 in for i = 0 to pred checkImageHeight do for j = 0 to pred checkImageWidth do let ( = ) a b = if a = b then 1 else 0 in let c = ( ( ( i land 0x8 ) = 0 ) lxor ( ( j land 0x8 ) = 0 ) ) * 255 in checkImage . { i , j , 0 } <- c ; checkImage . { i , j , 1 } <- c ; checkImage . { i , j , 2 } <- c ; checkImage . { i , j , 3 } <- 255 ; done ; done ; ( Bigarray . genarray_of_array3 checkImage ) ; ;
let init ( ) = glClearColor 0 . 0 0 . 0 0 . 0 0 . 0 ; glShadeModel GL_FLAT ; glEnable GL_DEPTH_TEST ; let checkImage = makeCheckImage ( ) in glPixelStorei GL_UNPACK_ALIGNMENT 1 ; let texName = glGenTexture ( ) in glBindTexture BindTex . GL_TEXTURE_2D texName ; glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_WRAP_S GL_REPEAT ) ; glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_WRAP_T GL_REPEAT ) ; glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_MAG_FILTER Mag . GL_NEAREST ) ; glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_MIN_FILTER Min . GL_NEAREST ) ; glTexImage2D TexTarget . GL_TEXTURE_2D 0 InternalFormat . GL_RGBA checkImageWidth checkImageHeight GL_RGBA GL_UNSIGNED_BYTE checkImage ; ( texName ) ; ;
let display texName ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glEnable GL_TEXTURE_2D ; glTexEnv TexEnv . GL_TEXTURE_ENV TexEnv . GL_TEXTURE_ENV_MODE TexEnv . GL_DECAL ; glBindTexture BindTex . GL_TEXTURE_2D texName ; glBegin GL_QUADS ; glTexCoord2 0 . 0 0 . 0 ; glVertex3 ( - 2 . 0 ) ( - 1 . 0 ) ( 0 . 0 ) ; glTexCoord2 0 . 0 3 . 0 ; glVertex3 ( - 2 . 0 ) ( 1 . 0 ) ( 0 . 0 ) ; glTexCoord2 3 . 0 3 . 0 ; glVertex3 ( 0 . 0 ) ( 1 . 0 ) ( 0 . 0 ) ; glTexCoord2 3 . 0 0 . 0 ; glVertex3 ( 0 . 0 ) ( - 1 . 0 ) ( 0 . 0 ) ; glTexCoord2 0 . 0 0 . 0 ; glVertex3 ( 1 . 0 ) ( - 1 . 0 ) ( 0 . 0 ) ; glTexCoord2 0 . 0 3 . 0 ; glVertex3 ( 1 . 0 ) ( 1 . 0 ) ( 0 . 0 ) ; glTexCoord2 3 . 0 3 . 0 ; glVertex3 ( 2 . 41421 ) ( 1 . 0 ) ( - 1 . 41421 ) ; glTexCoord2 3 . 0 0 . 0 ; glVertex3 ( 2 . 41421 ) ( - 1 . 0 ) ( - 1 . 41421 ) ; glEnd ( ) ; glFlush ( ) ; glDisable GL_TEXTURE_2D ; ; ;
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluPerspective 60 . 0 ( float w . / float h ) 1 . 0 30 . 0 ; glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; glTranslate 0 . 0 0 . 0 ( - 3 . 6 ) ; ; ;
let keyboard ~ key ~ x ~ y = match key with | ' s ' -> glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_WRAP_S GL_CLAMP ) ; glutPostRedisplay ( ) ; | ' S ' -> glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_WRAP_S GL_REPEAT ) ; glutPostRedisplay ( ) ; | ' t ' -> glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_WRAP_T GL_CLAMP ) ; glutPostRedisplay ( ) ; | ' T ' -> glTexParameter TexParam . GL_TEXTURE_2D ( TexParam . GL_TEXTURE_WRAP_T GL_REPEAT ) ; glutPostRedisplay ( ) ; | ' \ 027 ' -> exit ( 0 ) ; | _ -> ( ) ; ;
let ( ) = let _ = glutInit Sys . argv in glutInitDisplayMode [ GLUT_SINGLE ; GLUT_RGB ; GLUT_DEPTH ] ; glutInitWindowSize 250 250 ; glutInitWindowPosition 100 100 ; let _ = glutCreateWindow Sys . argv . ( 0 ) in let texName = init ( ) in glutDisplayFunc ~ display ( : display texName ) ; glutReshapeFunc ~ reshape ; glutKeyboardFunc ~ keyboard ; glutMainLoop ( ) ; ; ;
type t = { width : int ; initial_indent : string ; subsequent_indent : string ; expand_tabs : bool ; replace_whitespace : bool ; fix_sentence_endings : bool ; break_long_words : bool ; break_on_hyphens : bool ; drop_whitespace : bool }
let wordsep_simple_re = Str . regexp " [ \ r \ n \ t ] " +
let munge_whitespace { expand_tabs ; replace_whitespace ; _ } text = let text = if expand_tabs then Str . global_replace ( Str . regexp " \ t " ) ( String . make 8 ' ' ) text else text in if replace_whitespace then Str . global_replace whitespace_re " " text else text let res = Str . full_split wordsep_simple_re s in List . map ( function | Str . Delim _ -> " " | Str . Text t -> t ) res let chunks = Array . of_list chunks in let patsearch s = try Str . search_forward sentence_end_re s 0 >= 0 with Not_found -> false in let rec inner i chunks = if i >= Array . length chunks - 1 then chunks else if chunks . ( i + 1 ) = " " && patsearch chunks . ( i ) then ( chunks . ( i + 1 ) <- " " ; inner ( i + 2 ) chunks ) else inner ( i + 1 ) chunks in Array . to_list ( inner 0 chunks ) let space_left = if width < 1 then 1 else width - cur_len in match chunks with | ( chunk :: chunks ) when w . break_long_words -> ( String . sub chunk 0 space_left :: cur_line , String . sub chunk space_left ( String . length chunk - space_left ) :: chunks ) | ( chunk :: chunks ) when cur_line = [ ] -> ( chunk :: cur_line , chunks ) | chunks -> ( cur_line , chunks )
let wrap_chunks w = let is_whitespace = function | " " -> true | s -> Str . string_match wordsep_simple_re s 0 in let pre_drop_whitespace lines = function | ( chunk :: chunks ) when w . drop_whitespace && lines <> [ ] && is_whitespace chunk -> chunks | chunks -> chunks in let post_drop_whitespace = function | ( chunk :: line ) when w . drop_whitespace && is_whitespace chunk -> line | line -> line in let rec current line len width = function | chunk :: chunks when String . length chunk + len <= width -> current ( chunk :: line ) ( len + String . length chunk ) width chunks | chunks -> ( line , len , chunks ) in let rec inner lines = function | [ ] -> List . rev lines | chunks -> let indent = match lines with | [ ] -> w . initial_indent | _ -> w . subsequent_indent in let width = w . width - String . length indent in let chunks = pre_drop_whitespace lines chunks in let ( cur_line , cur_len , chunks ) = current [ ] 0 width chunks in let ( cur_line , chunks ) = if chunks <> [ ] && String . length ( List . hd chunks ) > width then handle_long_word w chunks cur_line cur_len width else ( cur_line , chunks ) in match post_drop_whitespace cur_line with | [ ] -> inner lines chunks | cur_line -> inner ( ( indent ^ String . concat " " ( List . rev cur_line ) ) :: lines ) chunks in inner [ ]
let make ( ? initial_indent " " ) = ( ? subsequent_indent " " ) = ( ? expand_tabs = true ) ( ? replace_whitespace = true ) ( ? fix_sentence_endings = false ) ( ? break_long_words = true ) ( ? break_on_hyphens = true ) ( ? drop_whitespace = true ) width = if width <= 0 then raise ( Invalid_argument " width <= 0 " ) ; { width ; initial_indent ; subsequent_indent ; expand_tabs ; replace_whitespace ; fix_sentence_endings ; break_long_words ; break_on_hyphens ; drop_whitespace }
let wrap w text = let chunks = split w ( munge_whitespace w text ) in let chunks = if w . fix_sentence_endings then fix_sentence_endings w chunks else chunks in wrap_chunks w chunks
let fill w text = String . concat " \ n " ( wrap w text )
module C = Torch_bindings . C ( Torch_generated )
let to_tensor_list ptr = let rec loop ptr acc = let tensor = !@ ptr in if is_null tensor then acc else ( Gc . finalise C . Tensor . free tensor ; loop ( ptr +@ 1 ) ( tensor :: acc ) ) in let result = loop ptr [ ] in C . free ( to_voidp ptr ) ; List . rev result
let __and__ self other = let out__ = CArray . make t 1 in stubs___and__ ( CArray . start out__ ) self other ; let t0 = CArray . get out__ 0 in Gc . finalise C . Tensor . free t0 ; t0
let __and__tensor_ self other = let out__ = CArray . make t 1 in stubs___and__tensor_ ( CArray . start out__ ) self other ; let t0 = CArray . get out__ 0 in Gc . finalise C . Tensor . free t0 ; t0
let __iand__ self other = let out__ = CArray . make t 1 in stubs___iand__ ( CArray . start out__ ) self other ; let t0 = CArray . get out__ 0 in Gc . finalise C . Tensor . free t0 ; t0
let __iand__tensor_ self other = let out__ = CArray . make t 1 in stubs___iand__tensor_ ( CArray . start out__ ) self other ; let t0 = CArray . get out__ 0 in Gc . finalise C . Tensor . free t0 ; t0