text stringlengths 12 786k |
|---|
let write_signature och = chunk_write och png_signature |
let write_chunk ( och : chunk_writer ) chunk = let len = String . length chunk . chunk_data in chunk_write och ( int_to_str4 len |> Bytes . to_string ) ; chunk_write och chunk . chunk_type ; chunk_write och chunk . chunk_data ; let type_and_data = String . concat " " [ chunk . chu... |
let ihdr_to_string ihdr = let s = Bytes . create 13 in Bytes . blit ( int_to_str4 ( fst ihdr . image_size ) ) 0 s 0 4 ; Bytes . blit ( int_to_str4 ( snd ihdr . image_size ) ) 0 s 4 4 ; Bytes . set s 8 ( char_of_int ihdr . bit_depth ) ; Bytes . set s 9 ( char_of_int... |
let output_png img ( och : chunk_writer ) = write_signature och ; let maxv = img . max_val in let bd = let rec find_bd i = if ones i >= maxv then i else find_bd ( i + 1 ) in find_bd 1 in let ct = match img . pixels with | Grey _ -> 0 | GreyA _ -> 4 | RGB _ -> 2 | RGBA _ -> 6 in l... |
let write_png ( och : chunk_writer ) img = PngWriter . output_png img och |
let bytes_of_png img = let approx_size = img . width * img . height in let buf = Buffer . create approx_size in let och = chunk_writer_of_buffer buf in PngWriter . output_png img och ; close_chunk_writer och ; Bytes . unsafe_of_string ( Buffer . contents buf ) |
module ReadPPM : ReadImage = struct let extensions = [ " ppm " ; " pgm " ; " pbm " ; " pnm " ] let read_header ( content : chunk_reader ) = let magic = ref " " in let width = ref ( - 1 ) and height = ref ( - 1 ) in let max_val = ref 1 in let scanner = Scanf . S... |
type ppm_mode = Binary | ASCII |
let write_ppm ( och : ImageUtil . chunk_writer ) img mode = let w = img . width and h = img . height in ( match img . pixels , mode , img . max_val with | ( RGB _ | RGBA _ ) , Binary , mv -> chunk_printf och " P6 \ n % i % i % i \ n " w h mv ; for y = 0 to h - 1 do fo... |
let write cw img = write_ppm cw img Binary |
module FrameSelect = struct type t = ( int * int ) list let of_string frm : t = String . split_on_char ' , ' frm |> List . map ( fun selection -> begin match String . split_on_char ' ' - selection with | [ single ] -> single , single | [ first ; last ] -> first , last | ... |
type config = { input_file : string ; display_mode : [ ` IRC | ` VT100 ] option ; background : int ; character : string option ; crop_x : int ; crop_y : int ; gamma : float ; resize : [ ` Original | ` Percent of float | ` Dim of ( int * int ) ] ; output_file : strin... |
let arg_parser array : config = let rec erase leftover config = let set_display_mode mode tl = erase leftover { config with display_mode = Some mode } tl in function | [ ] -> config , Array . of_list leftover | " -- help " :: _ -> config , [ | " " ; " " ] | | " -- frame... |
let ( ) = let config = arg_parser Sys . argv in let extension filename = let ri = try 1 + String . rindex filename ' . ' with Not_found -> invalid_arg " filename without extension " in String . ( sub filename ri @@ ( length filename ) - ri ) in let foreach_pixel f img = for y = 0 ... |
let chop_extension ' fname = try Filename . chop_extension fname with _ -> fname |
let get_extension fname = let baselen = String . length ( chop_extension ' fname ) in let extlen = String . length fname - baselen - 1 in if extlen <= 0 then let err = Printf . sprintf " No extension in filename ' % s ' . " fname in raise ( Invalid_argument err ) else String . sub ... |
let get_extension ' fname = try get_extension fname with _ -> " " |
let lines_from_channel ich = let lines = ref [ ] in let rec intfun ( ) = try let l = input_line ich in lines := l :: ! lines ; intfun ( ) ; with | End_of_file -> close_in ich | e -> close_in ich ; raise e in intfun ( ) ; List . rev ! lines |
let lines_from_file fn = let ich = open_in_bin fn in let ls = lines_from_channel ich in close_in ich ; ls |
let chunk_reader_of_in_channel ich : chunk_reader = function | ` Bytes num_bytes -> begin try Ok ( really_input_string ich num_bytes ) with | End_of_file -> let offset = pos_in ich in close_in ich ; Error ( ` End_of_file offset ) | e -> close_in ich ; raise e end | ` Close -> close_in ich ;... |
let chunk_writer_of_out_channel och : chunk_writer = function | ` String x -> ( try Ok ( output_string och x ) with | _ -> close_out och ; Error ` Write_error ) | ` Close -> close_out och ; Ok ( ) |
let chunk_reader_of_path fn = chunk_reader_of_in_channel ( open_in_bin fn ) |
let chunk_writer_of_path fn = chunk_writer_of_out_channel ( open_out_bin fn ) |
let xcf_signature = " gimp xcf " |
type xcf_header_data = { version : int ; image_size : int * int ; colour_type : int } |
module ReadXCF : ReadImage = struct let extensions = [ " xcf " ] let version_num s = match s with | " file \ 000 " -> 0 | " v001 \ 000 " -> 1 | " v002 \ 000 " -> 2 | _ -> raise ( Corrupted_image " Unknown version number . . . " ) let read_header ich = let magic ... |
let gpu_to_gray = kern v -> let open Std in let tid = thread_idx_x + block_dim_x * block_idx_x in if tid <= ( 512 * 512 ) then ( let i = ( tid * 4 ) in let res = int_of_float ( ( 0 . 21 . * ( float ( v . [ < i ] ) ) ) > . + ( 0 . 71 . * ( float ( v . ... |
let append_text e s = Dom . appendChild e ( document ## createTextNode ( Js . string s ) ) |
let button action = let b = createInput ~ _type ( : Js . string " button " ) document in b ## value <- ( Js . string " Go " ) ; b ## onclick <- handler action ; b |
let measure_time s f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " Time % s : % Fs \ n " %! s ( t1 . - t0 ) ; a ; ; |
let compute devid devs data imageData c = let dev = devs . ( devid ) in Printf . printf " Will use device : % s " ! ( dev ) . Spoc . Devices . general_info . Spoc . Devices . name ; let gpu_vect = Spoc . Vector . create Vector . int32 ( 512 * 512 * 4 ) in Random . se... |
let f select_devices devs data imageData c = ( fun _ -> let select = select_devices ## selectedIndex + 0 in compute select devs data imageData c ; Js . _true ) ; ; |
let newLine _ = Dom_html . createBr document |
let nodeJsText t = let sp = Dom_html . createSpan document in Dom . appendChild sp ( document ## createTextNode ( t ) ) ; sp |
let nodeText t = nodeJsText ( Js . string t ) |
let go _ = let body = Js . Opt . get ( document ## getElementById ( Js . string " section1 " ) ) ( fun ( ) -> assert false ) in Dom . appendChild body ( newLine ( ) ) ; let select_devices = createSelect document in Dom . appendChild body ( nodeText " Choose a computing ... |
let _ = window ## onload <- handler go |
let expect_ok = function | Ok x -> x | Error ( ` Msg m ) -> failwith m |
let ( ) >>*= m f = let open Lwt in m >>= function | Error x -> Lwt . return ( Error x ) | Ok x -> f x |
let src = let src = Logs . Src . create " qcow " ~ doc " : qcow2 - formatted BLOCK device " in Logs . Src . set_level src ( Some Logs . Info ) ; src |
module Log = ( val Logs . src_log src : Logs . LOG ) |
module ReadWriteBlock = struct include Block let original_connect = connect let connect path = connect ~ lock : true path end |
module Time = struct type ' a io = ' a Lwt . t let sleep_ns ns = Lwt_unix . sleep ( Int64 . to_float ns . / 1e9 ) end |
module TracedBlock = struct include ReadWriteBlock let length_of bufs = List . fold_left ( ) + 0 ( List . map Cstruct . len bufs ) let read t sector bufs = Log . info ( fun f -> f " BLOCK . read % Ld len = % d " sector ( length_of bufs ) ) ; read t sector bufs let write t sector... |
module type BLOCK = sig include Qcow_s . RESIZABLE_BLOCK val connect : string -> t Lwt . t end |
module UnsafeBlock = struct include ReadWriteBlock let flush _ = Lwt . return ( Ok ( ) ) end |
module ReadOnlyBlock = struct include UnsafeBlock let connect path = original_connect ~ lock : false path let write _ _ _ = failwith " write to a read - only virtual device " let resize _ _ = failwith " attempt to resize a read - only virtual device " end |
let handle_common common_options_t = if common_options_t . Common . debug then begin List . iter ( fun src -> if Logs . Src . name src = " qcow " then Logs . Src . set_level src ( Some Logs . Debug ) ) ( Logs . Src . list ( ) ) end |
let spinner = [ | ' ' ; - ' ' ; \\ ' ' ; | ' ' / ] | |
let spinner_idx = ref 0 |
let last_percent = ref ( - 1 ) |
let last_spinner_time = ref ( Unix . gettimeofday ( ) ) |
let progress_cb ~ percent = let now = Unix . gettimeofday ( ) in if now . - ( ! last_spinner_time ) > 0 . 5 || ! last_percent <> percent then begin last_percent := percent ; last_spinner_time := now ; let line = Bytes . make ( progress_bar_width + 8 ) ' \ 000 ' in let len ... |
let progress_cb_json fd = let oc = Unix . out_channel_of_descr fd in let last_percent = ref ( - 1 ) in fun ~ percent -> if ! last_percent <> percent then begin last_percent := percent ; output_string oc ( Printf . sprintf " { " \ progress " \: % d } \ n " percent ) ; flush_all ... |
let mib = Int64 . mul 1024L 1024L |
let info filename filter = let t = let open Lwt in Lwt_unix . openfile filename [ Lwt_unix . O_RDONLY ] 0 >>= fun fd -> let buffer = Cstruct . create 1024 in Lwt_cstruct . complete ( Lwt_cstruct . read fd ) buffer >>= fun ( ) -> let h , _ = expect_ok ( Header . read buffer ) in ... |
let write filename sector data trace = let block = if trace then ( module TracedBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) in let t = let open Lwt in BLOCK . connect filename >>= fun... |
let read filename sector length trace = let block = if trace then ( module TracedBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) in let t = let open Lwt in BLOCK . connect filename >>= fu... |
let check filename = let module B = Qcow . Make ( ReadOnlyBlock ) ( Time ) in let open Lwt in let t = let rec retry = function | 0 -> Printf . fprintf stderr " Warning : file is being concurrently modified \ n " ; Printf . fprintf stderr " We found no concrete problems , but the file is... |
let is_zero buffer = try for i = 0 to Cstruct . len buffer - 1 do if Cstruct . get_uint8 buffer i <> 0 then raise Non_zero done ; true with Non_zero -> false |
let handle_error pp_error = function | Error e -> let msg = Format . asprintf " % a " pp_error e in Lwt . return ( ` Error ( false , msg ) ) | Ok x -> Lwt . return ( ` Ok x ) |
let discard unsafe_buffering filename = let block = if unsafe_buffering then ( module UnsafeBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) in let open Lwt in let t = BLOCK . connect filen... |
let compact common_options_t unsafe_buffering filename = handle_common common_options_t ; let block = if unsafe_buffering then ( module UnsafeBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) ... |
let repair unsafe_buffering filename = let block = if unsafe_buffering then ( module UnsafeBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) in let open Lwt in let t = BLOCK . connect filena... |
let sha _common_options_t filename = let module B = Qcow . Make ( ReadOnlyBlock ) ( Time ) in let open Lwt in let t = Block . connect filename >>= fun x -> let config = B . Config . create ~ read_only : true ( ) in B . connect ~ config x >>= fun x -> B . get_info x >>= fun info -> ... |
let decode filename output = let module B = Qcow . Make ( Block ) ( Time ) in let open Lwt in let t = Block . connect filename >>= fun x -> B . connect x >>= fun x -> B . get_info x >>= fun info -> let total_size = Int64 . ( mul info . Mirage_block . size_sectors ( of_int info . Mi... |
let encode filename output = let module B = Qcow . Make ( ReadWriteBlock ) ( Time ) in let open Lwt in let t = ReadWriteBlock . connect filename >>= fun raw_input -> ReadWriteBlock . get_info raw_input >>= fun raw_input_info -> let total_size = Int64 . ( mul raw_input_info . Mirage_block . ... |
let create size strict_refcounts trace filename = let block = if trace then ( module TracedBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) in let open Lwt in let t = Lwt_unix . openfile fi... |
let pattern common_options_t trace filename size number = let block = if trace then ( module TracedBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module Uncached = ( val block : BLOCK ) in let module BLOCK = Qcow_block_cache . Make ( Uncached ) in let module B = Qcow . Make ( ... |
let resize trace filename new_size ignore_data_loss = let block = if trace then ( module TracedBlock : BLOCK ) else ( module ReadWriteBlock : BLOCK ) in let module BLOCK = ( val block : BLOCK ) in let module B = Qcow . Make ( BLOCK ) ( Time ) in let open Lwt in let t = BLOCK . connect fi... |
type output = [ | ` Text | ` Json ] |
let is_zero buf = let rec loop ofs = ( ofs >= Cstruct . len buf ) || ( Cstruct . get_uint8 buf ofs = 0 && ( loop ( ofs + 1 ) ) ) in loop 0 |
let mapped filename _format ignore_zeroes = let module B = Qcow . Make ( Block ) ( Time ) in let open Lwt in let t = Block . connect filename >>= fun x -> B . connect x >>= fun x -> B . get_info x >>= fun info -> Printf . printf " # offset ( bytes ) , length ( bytes ) \ n " ;... |
let finally f g = try let r = f ( ) in g ( ) ; r with e -> g ( ) ; raise e |
type metadata = { blocks : Qcow . Int64 . IntervalSet . t ; total_size : int64 ; |
let dehydrate _common input_filename output_filename = let module B = Qcow . Make ( ReadOnlyBlock ) ( Time ) in let open Lwt . Infix in let t = Block . connect input_filename >>= fun x -> Block . get_info x >>= fun info -> let total_size = Int64 . ( mul info . Mirage_block . size_sector... |
let rehydrate _common input_filename output_filename = let open Lwt . Infix in let t = let sexp = Sexplib . Sexp . load_sexp ( input_filename ^ " . map " ) in let metadata = metadata_of_sexp sexp in let buffer = Cstruct . create 1048576 in Lwt_unix . openfile ( input_filename ^ " . me... |
let import_set_of_closures = let import_function_declarations ( clos : A . function_declarations ) : A . function_declarations = let sym_to_fun_var_map ( clos : A . function_declarations ) = Variable . Map . fold ( fun fun_var _ acc -> let closure_id = Closure_id . wrap fun_var in let sym... |
let rec import_ex ex = let import_value_set_of_closures ~ set_of_closures_id ~ bound_vars ~ free_vars ( ~ ex_info : Export_info . t ) ~ what : A . value_set_of_closures option = let bound_vars = Var_within_closure . Map . map import_approx bound_vars in match import_set_of_closures set_of_closures... |
let import_symbol sym = if Compilenv . is_predefined_exception sym then A . value_unknown Other else begin let compilation_unit = Symbol . compilation_unit sym in match Compilenv . approx_for_global compilation_unit with | None -> A . value_unresolved ( Symbol sym ) | Some export_info -> match Symbo... |
let rec really_import ( approx : A . descr ) = match approx with | Value_extern ex -> really_import_ex ex | Value_symbol sym -> really_import_symbol sym | r -> r really_import ( import_ex ex ) . descr really_import ( import_symbol sym ) . descr |
let really_import_approx ( approx : Simple_value_approx . t ) = A . replace_description approx ( really_import approx . descr ) |
let test ( ) = let var_ext = Variable . create " ext " in let var_ok = Variable . create " ok " in let var_bad = Variable . create " bad " in let variables = Variable . Map . add var_ok var_bad ( Variable . Map . singleton var_ext var_ok ) in let renaming = Renaming . create_im... |
let _ = let comp_unit = let id = Ident . create_persistent " Test " in let linkage_name = Linkage_name . create " camlTest " in Compilation_unit . create id linkage_name in Compilation_unit . set_current comp_unit ; test ( ) |
let class_types env cty1 cty2 = Ctype . match_class_types env cty1 cty2 |
let class_type_declarations env cty1 cty2 = Ctype . match_class_declarations env cty1 . clty_params cty1 . clty_type cty2 . clty_params cty2 . clty_type |
let class_declarations env cty1 cty2 = match cty1 . cty_new , cty2 . cty_new with None , Some _ -> [ Ctype . CM_Virtual_class ] | _ -> Ctype . match_class_declarations env cty1 . cty_params cty1 . cty_type cty2 . cty_params cty2 . cty_type |
let include_err ppf = function | CM_Virtual_class -> fprintf ppf " A class cannot be changed from virtual to concrete " | CM_Parameter_arity_mismatch ( ls , lp ) -> fprintf ppf " The classes do not have the same number of type parameters " | CM_Type_parameter_mismatch trace -> fprintf ppf " [ ... |
let report_error ppf = function | [ ] -> ( ) | err :: errs -> let print_errs ppf errs = List . iter ( fun err -> fprintf ppf " @ % a " include_err err ) errs in fprintf ppf " [ @< v >% a % a ] " @ include_err err print_errs errs |
let value_descriptions env vd1 vd2 = if Ctype . moregeneral env true vd1 . val_type vd2 . val_type then begin match ( vd1 . val_kind , vd2 . val_kind ) with ( Val_prim p1 , Val_prim p2 ) -> if p1 = p2 then Tcoerce_none else raise Dont_match | ( Val_prim p , _ ) -> Tcoerce_primitive p ... |
let private_flags decl1 decl2 = match decl1 . type_private , decl2 . type_private with | Private , Public -> decl2 . type_kind = Type_abstract && ( decl2 . type_manifest = None || decl1 . type_kind <> Type_abstract ) | _ , _ -> true |
let is_absrow env ty = match ty . desc with Tconstr ( Pident id , _ , _ ) -> begin match Ctype . expand_head env ty with { desc = Tobject _ | Tvariant _ } -> true | _ -> false end | _ -> false |
let type_manifest env ty1 params1 ty2 params2 priv2 = let ty1 ' = Ctype . expand_head env ty1 and ty2 ' = Ctype . expand_head env ty2 in match ty1 ' . desc , ty2 ' . desc with Tvariant row1 , Tvariant row2 when is_absrow env ( Btype . row_more row2 ) -> let row1 = Btype . row_repr row1 ... |
type type_mismatch = Arity | Privacy | Kind | Constraint | Manifest | Variance | Field_type of string | Field_mutable of string | Field_arity of string | Field_names of int * string * string | Field_missing of bool * string | Record_representation of bool |
let nth n = if n = 1 then " first " else if n = 2 then " 2nd " else if n = 3 then " 3rd " else string_of_int n ^ " th " |
let report_type_mismatch0 first second decl ppf err = let pr fmt = Format . fprintf ppf fmt in match err with Arity -> pr " They have different arities " | Privacy -> pr " A private type would be revealed " | Kind -> pr " Their kinds differ " | Constraint -> pr " Their constraints differ " |... |
let report_type_mismatch first second decl ppf = List . iter ( fun err -> if err = Manifest then ( ) else Format . fprintf ppf " @ % a . " ( report_type_mismatch0 first second decl ) err ) |
let rec compare_variants env decl1 decl2 n cstrs1 cstrs2 = match cstrs1 , cstrs2 with [ ] , [ ] -> [ ] | [ ] , ( cstr2 , _ ) :: _ -> [ Field_missing ( true , cstr2 ) ] | ( cstr1 , _ ) :: _ , [ ] -> [ Field_missing ( false , cstr1 ) ] | ( cstr1 ,... |
let rec compare_records env decl1 decl2 n labels1 labels2 = match labels1 , labels2 with [ ] , [ ] -> [ ] | [ ] , ( lab2 , _ , _ ) :: _ -> [ Field_missing ( true , lab2 ) ] | ( lab1 , _ , _ ) :: _ , [ ] -> [ Field_missing ( false , lab1 ) ] ... |
let type_declarations env id decl1 decl2 = if decl1 . type_arity <> decl2 . type_arity then [ Arity ] else if not ( private_flags decl1 decl2 ) then [ Privacy ] else let err = match ( decl1 . type_kind , decl2 . type_kind ) with ( _ , Type_abstract ) -> [ ] | ( Type_variant c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.