text
stringlengths 0
601k
|
---|
type t = kind * Topkg_cmd . t * Topkg_fpath . t
|
let git = let git = Topkg_cmd . v ( Topkg_os . Env . opt_var " TOPKG_GIT " ~ absent " : git ) " in lazy ( Topkg_os . Cmd . exists git >>= fun exists -> Ok ( exists , git ) git ) git
|
let hg = let hg = Topkg_cmd . v ( Topkg_os . Env . opt_var " TOPKG_HG " ~ absent " : hg ) " in lazy ( Topkg_os . Cmd . exists hg >>= fun exists -> Ok ( exists , hg ) hg ) hg
|
let vcs_cmd kind cmd dir = match kind with
|
let v k cmd ~ dir = ( k , cmd , dir ) dir
|
let kind ( k , _ , _ ) _ = k
|
let dir ( _ , _ , dir ) dir = dir
|
let cmd ( kind , cmd , dir ) dir = vcs_cmd kind cmd dir
|
let git_work_tree ( _ , _ , dir ) dir = Topkg_cmd ( . v " -- work - tree " % Topkg_fpath . dirname dir ) dir
|
let find_git ( ) = Lazy . force git >>= function let git_dir = Topkg_cmd ( . git % " rev - parse " % " -- git - dir ) " in Topkg_os . Cmd ( . run_out ~ err : Topkg_os . File . null git_dir |> out_string ) out_string >>= function | ( dir , ( _ , ` Exited 0 ) 0 ) 0 -> Ok ( Some ( v ` Git git ~ dir ) dir ) dir | _ -> Ok None
|
let err_git cmd c = R . error_msgf " % a exited with % d " Topkg_cmd . dump cmd c
|
let run_git r args out = let git = Topkg_cmd ( . cmd r %% args ) args in Topkg_os . Cmd ( . run_out git |> out ) out >>= function | ( v , ( _ , ` Exited 0 ) 0 ) 0 -> Ok v | ( _ , ( _ , ` Exited c ) c ) c -> err_git git c
|
let git_is_dirty r = let status = Topkg_cmd ( . cmd r %% git_work_tree r % " status " % " -- porcelain ) " in Topkg_os . Cmd ( . run_out ~ err : Topkg_os . File . null status |> out_string ) out_string >>= function | ( " " , ( _ , ` Exited 0 ) 0 ) 0 -> Ok false | ( _ , ( _ , ` Exited 0 ) 0 ) 0 -> Ok true | ( _ , ( _ , ` Exited c ) c ) c -> err_git status c
|
let git_file_is_dirty r file = let diff = Topkg_cmd ( . cmd r %% git_work_tree r % " diff - index " % " -- quiet " % " HEAD " % p file ) file in Topkg_os . Cmd ( . run_status ~ err : Topkg_os . File . null diff ) diff >>= function | ` Exited 0 -> Ok false | ` Exited 1 -> Ok true | ` Exited c -> err_git diff c
|
let dirtify_if ~ dirty r id = match dirty with git_is_dirty r >>= fun is_dirty -> Ok ( if is_dirty then dirtify id else id ) id
|
let git_head ~ dirty r = run_git r Topkg_cmd ( . v " rev - parse " % " HEAD ) " Topkg_os . Cmd . out_string >>= fun id -> dirtify_if ~ dirty r id
|
let git_commit_id ~ dirty r commit_ish = let dirty = dirty && commit_ish = " HEAD " in let id = Topkg_cmd ( . v " rev - parse " % " -- verify " % ( commit_ish ^ { " ^ commit } commit ) ) " in run_git r id Topkg_os . Cmd . out_string >>= fun id -> dirtify_if ~ dirty r id
|
let git_commit_ptime_s r commit_ish = let time = Topkg_cmd ( . v " show " % " - s " % " -- format =% ct " % commit_ish ) commit_ish in run_git r time Topkg_os . Cmd . out_string >>= fun ptime -> try Ok ( int_of_string ptime ) ptime with | Failure _ -> R . error_msgf " Could not parse timestamp from % S " ptime
|
let git_describe ~ dirty r commit_ish = let dirty = dirty && commit_ish = " HEAD " in run_git r Topkg_cmd ( . git_work_tree r % " describe " % " -- always " %% on dirty ( v " -- dirty ) " %% on ( not dirty ) dirty ( v commit_ish ) commit_ish ) commit_ish Topkg_os . Cmd . out_string
|
let git_tags r = run_git r Topkg_cmd ( . v " tag " % " -- list ) " Topkg_os . Cmd . out_lines
|
let git_changes r ~ after ~ until = let range = if after = " " then until else Topkg_string . strf " % s . . % s " after until in let changes = Topkg_cmd ( . v " log " % " -- oneline " % " -- no - decorate " % range ) range in run_git r changes Topkg_os . Cmd . out_lines >>= fun commits -> parse_changes commits
|
let git_tracked_files r ~ tree_ish = let tracked = Topkg_cmd ( . git_work_tree r % " ls - tree " % " -- name - only " % " - r " % tree_ish ) tree_ish in run_git r tracked Topkg_os . Cmd . out_lines
|
let git_clone r ~ dir : d = let clone = Topkg_cmd ( . v " clone " % " -- local " % ( dir r ) r % d ) d in run_git r clone Topkg_os . Cmd . out_stdout >>= fun _ -> Ok ( )
|
let git_checkout r ~ branch ~ commit_ish = let branch = match branch with | None -> Topkg_cmd . empty | Some branch -> Topkg_cmd ( . v " - b " % branch ) branch in run_git r Topkg_cmd ( . v " checkout " % " -- quiet " %% branch % commit_ish ) commit_ish Topkg_os . Cmd . out_string >>= fun _ -> Ok ( )
|
let git_commit_files r ~ msg files = let msg = match msg with | None -> Topkg_cmd . empty | Some m -> Topkg_cmd ( . v " - m " % m ) m in let files = Topkg_cmd ( . of_list @@ List . map p files ) files in run_git r Topkg_cmd ( . v " commit " %% msg %% files ) files Topkg_os . Cmd . out_stdout
|
let git_tag r ~ force ~ sign ~ msg ~ commit_ish tag = let msg = match msg with | None -> Topkg_cmd . empty | Some m -> Topkg_cmd ( . v " - m " % m ) m in let flags = Topkg_cmd ( . on force ( v " - f ) " %% on sign ( v " - s ) ) " in run_git r Topkg_cmd ( . v " tag " % " - a " %% flags %% msg % tag % commit_ish ) commit_ish Topkg_os . Cmd . out_stdout
|
let git_delete_tag r tag = run_git r Topkg_cmd ( . v " tag " % " - d " % tag ) tag Topkg_os . Cmd . out_stdout
|
let hg_rev commit_ish = match commit_ish with " HEAD " -> " tip " | c -> c
|
let find_hg ( ) = Lazy . force hg >>= function let hg_root = Topkg_cmd ( . hg % " root ) " in Topkg_os . Cmd ( . run_out ~ err : Topkg_os . File . null hg_root |> out_string ) out_string >>= function | ( dir , ( _ , ` Exited 0 ) 0 ) 0 -> Ok ( Some ( v ` Hg hg ~ dir ) dir ) dir | _ -> Ok None
|
let err_hg cmd c = R . error_msgf " % a exited with % d " Topkg_cmd . dump cmd c
|
let run_hg r args out = let hg = Topkg_cmd ( . cmd r %% args ) args in Topkg_os . Cmd ( . run_out hg |> out ) out >>= function | ( v , ( _ , ` Exited 0 ) 0 ) 0 -> Ok v | ( _ , ( _ , ` Exited c ) c ) c -> err_hg hg c
|
let hg_id r ~ rev = run_hg r Topkg_cmd ( . v " id " % " - i " % " -- rev " % rev ) rev Topkg_os . Cmd . out_string >>= fun id -> let len = String . length id in let is_dirty = String . length id > 0 && id [ . len - 1 ] 1 = ' + ' in let id = if is_dirty then String . sub id 0 ( len - 1 ) 1 else id in Ok ( id , is_dirty ) is_dirty
|
let hg_is_dirty r = hg_id r ~ rev " : tip " >>= function ( id , is_dirty ) is_dirty -> Ok is_dirty
|
let hg_file_is_dirty r file = run_hg r Topkg_cmd ( . v " status " % p file ) file Topkg_os . Cmd . out_string >>= function | " " -> Ok false | _ -> Ok true
|
let hg_head ~ dirty r = hg_id r ~ rev " : tip " >>= function ( id , is_dirty ) is_dirty -> Ok ( if is_dirty && dirty then dirtify id else id ) id
|
let hg_commit_id ~ dirty r ~ rev = hg_id r ~ rev >>= fun ( id , is_dirty ) is_dirty -> Ok ( if is_dirty && dirty then dirtify id else id ) id
|
let hg_commit_ptime_s r ~ rev = let time = Topkg_cmd ( . v " log " % " -- template " % { " date ( datedate , " \% s ) } " " \ % " -- rev " % rev ) rev in run_hg r time Topkg_os . Cmd . out_string >>= fun ptime -> try Ok ( int_of_string ptime ) ptime with | Failure _ -> R . error_msgf " Could not parse timestamp from % S " ptime
|
let hg_describe ~ dirty r ~ rev = let get_distance s = try Ok ( int_of_string s ) s with | Failure _ -> R . error_msgf " % s : Could not parse hg tag distance . " ( dir r ) r in let parent t = run_hg r Topkg_cmd ( . v " parent " % " -- rev " % rev % " -- template " % t ) t Topkg_os . Cmd . out_string in parent { " latesttagdistance } latesttagdistance " >>= get_distance >>= begin function | 1 -> parent { " latesttag } latesttag " | n -> parent { " latesttag } latesttag { - latesttagdistance } latesttagdistance { - node | short } short " end >>= fun descr -> match dirty with | false -> Ok descr | true -> hg_id ~ rev " : tip " r >>= fun ( _ , is_dirty ) is_dirty -> Ok ( if is_dirty then dirtify descr else descr ) descr
|
let hg_tags r = run_hg r Topkg_cmd ( . v " tags " % " -- quiet " ) Topkg_os . Cmd . out_lines
|
let hg_changes r ~ after ~ until = let rev = Topkg_string . strf " % s ::% s " after until in let changes = Topkg_cmd ( . v " log " % " -- template " % { " node | short } short { desc | firstline } firstline \\ n " % " -- rev " % rev ) rev in run_hg r changes Topkg_os . Cmd . out_lines >>= fun commits -> parse_changes commits >>= function | [ ] -> Ok [ ] | after :: rest -> Ok ( List . rev rest ) rest
|
let hg_tracked_files r ~ rev = run_hg r Topkg_cmd ( . v " manifest " % " -- rev " % rev ) rev Topkg_os . Cmd . out_lines
|
let hg_clone r ~ dir : d = let clone = Topkg_cmd ( . v " clone " % ( dir r ) r % d ) d in run_hg r clone Topkg_os . Cmd . out_stdout
|
let hg_checkout r ~ branch ~ rev = run_hg r Topkg_cmd ( . v " update " % " -- rev " % rev ) rev Topkg_os . Cmd . out_string >>= fun _ -> match branch with | None -> Ok ( ) | Some branch -> run_hg r Topkg_cmd ( . v " branch " % branch ) branch Topkg_os . Cmd . out_string >>= fun _ -> Ok ( )
|
let hg_commit_files r ~ msg files = let msg = match msg with | None -> Topkg_cmd . empty | Some m -> Topkg_cmd ( . v " - m " % m ) m in let files = Topkg_cmd ( . of_list @@ List . map p files ) files in run_hg r Topkg_cmd ( . v " commit " %% msg %% files ) files Topkg_os . Cmd . out_stdout
|
let hg_tag r ~ force ~ sign ~ msg ~ rev tag = if sign then R . error_msgf " Tag signing is not supported by hg " else let msg = match msg with | None -> Topkg_cmd . empty | Some m -> Topkg_cmd ( . v " - m " % m ) m in run_hg r Topkg_cmd ( . v " tag " %% on force ( v " - f ) " %% msg % " -- rev " % rev % tag ) tag Topkg_os . Cmd . out_stdout
|
let hg_delete_tag r tag = run_hg r Topkg_cmd ( . v " tag " % " -- remove " % tag ) tag Topkg_os . Cmd . out_stdout
|
let find ? dir ( ) = match dir with begin find_git ( ) >>= function | Some _ as v -> Ok v | None -> find_hg ( ) end let git_dir = Topkg_fpath . append dir " . git " in Topkg_os . Dir . exists git_dir >>= function | true -> begin Lazy . force git >>= function | ( _ , cmd ) cmd -> Ok ( Some ( v ` Git cmd ~ dir : git_dir ) git_dir ) git_dir end | false -> let hg_dir = Topkg_fpath . append dir " . hg " in Topkg_os . Dir . exists hg_dir >>= function | false -> Ok None | true -> Lazy . force hg >>= function ( _ , cmd ) cmd -> Ok ( Some ( v ` Hg cmd ~ dir ) dir ) dir
|
let get ? dir ( ) = find ? dir ( ) >>= function let dir = match dir with | None -> Topkg_os . Dir . current ( ) | Some dir -> Ok dir in dir >>= function dir -> R . error_msgf " % s : No VCS repository found " dir
|
let pp ppf r = Format . fprintf ppf ( " % a , % s ) s " pp_kind ( kind r ) r ( dir r ) r
|
let not_dirty r = is_dirty r >>= function
|
let file_is_dirty r file = match r with
|
let head ( ? dirty = true ) true = function
|
let commit_id ( ? dirty = true ) true ( ? commit_ish = " HEAD ) " = function
|
let commit_ptime_s ( ? commit_ish = " HEAD ) " = function
|
let describe ( ? dirty = true ) true ( ? commit_ish = " HEAD ) " = function
|
let changes ( ? until = " HEAD ) " r ~ after = match r with
|
let tracked_files ( ? tree_ish = " HEAD ) " = function
|
let clone r ~ dir = match r with
|
let checkout ? branch r ~ commit_ish = match r with
|
let commit_files ? msg r files = match r with
|
let tag ( ? force = false ) false ( ? sign = false ) false ? msg ( ? commit_ish = " HEAD ) " r tag = match r with | ( ` Git , _ , _ as r ) r -> git_tag r ~ force ~ sign ~ msg ~ commit_ish tag | ( ` Hg , _ , _ as r ) r -> hg_tag r ~ force ~ sign ~ msg ~ rev ( : hg_rev commit_ish ) commit_ish tag
|
let delete_tag r tag = match r with
|
let init top = let module O = Options in top # init ~ nopervasives :! O . nopervasives ~ pkgs :! O . findlib_pkgs ~ use_threads ( : Std . Various . use_threads ( ) ) ~ cma_files :! O . cma_files ( )
|
let set_absname x = Clflags . absname := x # else Location . absname := x # endif
|
let serialize_location_error x = let main = x . Location . main in let b = Buffer . create 128 in let fmt = Format . formatter_of_buffer b in Format . fprintf fmt " [ @% t ] " @ main . Location . txt ; Format . pp_print_flush fmt ( ) ; ( main . Location . loc , Buffer . contents b ) # else x . Location . loc , x . Location . msg # endif # endif
|
let set_argv new_argv = caml_sys_modify_argv new_argv ; # else let orig_argv_length = Array . length Sys . argv in let new_argv_length = Array . length new_argv in assert ( new_argv_length <= orig_argv_length ) ; ArrayLabels . blit ~ src : new_argv ~ src_pos : 0 ~ dst : Sys . argv ~ dst_pos : 0 ~ len : new_argv_length ; if new_argv_length <> orig_argv_length then Obj . truncate ( Obj . repr Sys . argv ) new_argv_length ; # endif Arg . current := 0
|
let run_main in_channel ~ the_fpm ~ the_execution_engine = let anonymous_func_count = ref 0 in let supplier = Parser . MenhirInterpreter . lexer_lexbuf_to_supplier Lexer . read ( Lexing . from_channel in_channel ) in let rec run_loop the_fpm the_execution_engine supplier = let incremental = Parser . Incremental . toplevel Lexing . dummy_pos in printf " \ n " ; printf " ready > " ; Out_channel . flush stdout ; ( try match Parser . MenhirInterpreter . loop supplier incremental with | ` Expr ast -> printf " parsed a toplevel expression " ; let func = Ast . func_of_no_binop_func ast in Out_channel . flush stdout ; Llvm_executionengine . add_module Codegen . the_module the_execution_engine ; anonymous_func_count := ! anonymous_func_count + 1 ; let tmp_name = sprintf " __toplevel % d " ! anonymous_func_count in let tmp_func = Ast . set_func_name tmp_name func in let the_function = Codegen . codegen_func the_fpm tmp_func in Llvm . dump_value the_function ; let fp = Llvm_executionengine . get_function_address tmp_name ( Foreign . funptr Ctypes . ( void @-> returning double ) ) the_execution_engine in printf " Evaluated to % f " ( fp ( ) ) ; Llvm_executionengine . remove_module Codegen . the_module the_execution_engine | ` Extern ext -> printf " parsed an extern " ; Out_channel . flush stdout ; Llvm . dump_value ( Codegen . codegen_proto ext ) | ` Def def -> printf " parsed a definition " ; let func = Ast . func_of_no_binop_func def in Out_channel . flush stdout ; Llvm . dump_value ( Codegen . codegen_func the_fpm func ) | ` Eof -> printf " \ n \ n " ; printf " reached eof \ n " ; printf " module dump :\ n " ; Out_channel . flush Out_channel . stdout ; Llvm . dump_module Codegen . the_module ; exit 0 with e -> printf " !\ nencountered an error { % sexp : exn } " e ) ; Out_channel . flush Out_channel . stdout ; run_loop the_fpm the_execution_engine supplier in run_loop the_fpm the_execution_engine supplier
|
let main input = Hashtbl . add_exn Ast . binop_precedence ~ key ' ' := ~ data : 2 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ' :< ~ data : 10 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ' :+ ~ data : 20 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ' :- ~ data : 20 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ' :* ~ data : 40 ; let the_execution_engine = ( match Llvm_executionengine . initialize ( ) with | true -> ( ) | false -> raise_s [ % message " failed to initialize " ] ) ; Llvm_executionengine . create Codegen . the_module in let the_fpm = Llvm . PassManager . create_function Codegen . the_module in Llvm_scalar_opts . add_memory_to_register_promotion the_fpm ; Llvm_scalar_opts . add_instruction_combination the_fpm ; Llvm_scalar_opts . add_reassociation the_fpm ; Llvm_scalar_opts . add_gvn the_fpm ; Llvm_scalar_opts . add_cfg_simplification the_fpm ; Llvm . PassManager . initialize the_fpm |> ignore ; match input with | ` Stdin -> run_main ~ the_execution_engine ~ the_fpm In_channel . stdin | ` File file -> In_channel . with_file file ~ f ( : run_main ~ the_execution_engine ~ the_fpm )
|
module Make ( P : sig val np : int val mem : int end ) ( ) = struct open P let with_workflow w ~ f = let open Scheduler in let db = Db . init_exn " _bistro " in let loggers = [ Console_logger . create ( ) ] in let sched = create ~ np : np ~ mem ( ` : GB mem ) ~ loggers db in let thread = eval_exn sched w in start sched ; try Lwt_main . run thread |> f with | Failure msg as e -> ( print_endline msg ; raise e ) let eval w = with_workflow w ~ f ( : fun x -> x ) let with_pworkflow w ~ f = with_workflow ( Workflow . path w ) ~ f let path w = with_pworkflow w ~ f ( : fun x -> x ) let sh fmt = Printf . kprintf ( fun s -> ignore ( Sys . command s ) ) fmt let rm w = with_pworkflow w ~ f ( : sh " rm % s " ) let file w = with_pworkflow w ~ f ( : sh " file % s " ) let less w = with_pworkflow w ~ f ( : sh " less % s " ) let wc w = with_pworkflow w ~ f ( : sh " wc % s " ) let firefox w = with_pworkflow w ~ f ( : sh " firefox -- no - remote % s " ) let evince w = with_pworkflow w ~ f ( : sh " evince % s " ) let ls w = with_pworkflow w ~ f ( : sh " ls % s " ) end
|
type directive_fun = | Directive_none of ( unit -> unit ) | Directive_string of ( string -> unit ) | Directive_int of ( int -> unit ) | Directive_ident of ( Longident . t -> unit ) | Directive_bool of ( bool -> unit )
|
type directive_info = { section : string ; doc : string ; }
|
let phrase_buffer = Buffer . create 1024
|
let toplevel_value_bindings : Obj . t String . Map . t ref = ref String . Map . empty
|
let getvalue name = try String . Map . find name ! toplevel_value_bindings with Not_found -> fatal_error ( name ^ " unbound at toplevel " )
|
let setvalue name v = toplevel_value_bindings := String . Map . add name v ! toplevel_value_bindings
|
let rec eval_address = function | Env . Aident id -> if Ident . persistent id || Ident . global id then Symtable . get_global_value id else begin let name = Translmod . toplevel_name id in try String . Map . find name ! toplevel_value_bindings with Not_found -> raise ( Symtable . Error ( Symtable . Undefined_global name ) ) end | Env . Adot ( p , pos ) -> Obj . field ( eval_address p ) pos
|
let eval_path find env path = match find path env with | addr -> eval_address addr | exception Not_found -> fatal_error ( " Cannot find address for : " ^ ( Path . name path ) )
|
let eval_module_path env path = eval_path Env . find_module_address env path
|
let eval_value_path env path = eval_path Env . find_value_address env path
|
let eval_extension_path env path = eval_path Env . find_constructor_address env path
|
let eval_class_path env path = eval_path Env . find_class_address env path
|
module EvalPath = struct type valu = Obj . t exception Error let eval_address addr = try eval_address addr with Symtable . Error _ -> raise Error let same_value v1 v2 = ( v1 == v2 ) end
|
let max_printer_depth = ref 100
|
let max_printer_steps = ref 300
|
let print_untyped_exception ppf obj = ! print_out_value ppf ( Printer . outval_of_untyped_exception obj )
|
let outval_of_value env obj ty = Printer . outval_of_value ! max_printer_steps ! max_printer_depth ( fun _ _ _ -> None ) env obj ty
|
let print_value env obj ppf ty = ! print_out_value ppf ( outval_of_value env obj ty )
|
type ( ' a , ' b ) gen_printer = ( ' a , ' b ) Genprintval . gen_printer = | Zero of ' b | Succ of ( ' a -> ( ' a , ' b ) gen_printer )
|
let parse_toplevel_phrase = ref Parse . toplevel_phrase
|
let parse_use_file = ref Parse . use_file
|
let parse_mod_use_file name lb = let modname = String . capitalize_ascii ( Filename . remove_extension ( Filename . basename name ) ) in let items = List . concat ( List . map ( function Ptop_def s -> s | Ptop_dir _ -> [ ] ) ( ! parse_use_file lb ) ) in [ Ptop_def [ Str . module_ ( Mb . mk ( Location . mknoloc ( Some modname ) ) ( Mod . structure items ) ) ] ]
|
let toplevel_startup_hook = ref ( fun ( ) -> ( ) )
|
type event += | Startup | After_setup
|
let hooks = ref [ ]
|
let add_hook f = hooks := f :: ! hooks
|
let ( ) = add_hook ( function | Startup -> ! toplevel_startup_hook ( ) | _ -> ( ) )
|
let run_hooks hook = List . iter ( fun f -> f hook ) ! hooks
|
let may_trace = ref false
|
type evaluation_outcome = Result of Obj . t | Exception of exn
|
let backtrace = ref None
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.