text stringlengths 12 786k |
|---|
let do_for_multiple_match ~ scopes value_kind loc paraml mode pat_act_list partial = let repr = None in let partial = check_partial pat_act_list partial in let raise_num , arg , pm1 = let raise_num , default = match partial with | Partial -> let raise_num = next_raise_count ( ) in ( raise_num , D... |
let param_to_var param = match param with | Lvar v -> ( v , None ) | _ -> ( Ident . create_local " * match " , * Some param ) |
let bind_opt ( v , eo ) k = match eo with | None -> k | Some e -> Lambda . bind Strict v e k |
let for_multiple_match ~ scopes value_kind loc paraml mode pat_act_list partial = let v_paraml = List . map param_to_var paraml in let paraml = List . map ( fun ( v , _ ) -> Lvar v ) v_paraml in List . fold_right bind_opt v_paraml ( do_for_multiple_match ~ scopes value_kind loc paraml mode pat_... |
type context = { buf : string ; mutable pos : int ; mutable a : int32 ; mutable b : int32 ; mutable c : int32 ; mutable d : int32 ; mutable bits : int64 } |
let step1 w x y z data s = let w = Int32 . add ( Int32 . add w data ) ( Int32 . logxor z ( Int32 . logand x ( Int32 . logxor y z ) ) ) in Int32 . add x ( Int32 . logor ( Int32 . shift_left w s ) ( Int32 . shift_right_logical w ( 32 - s ) ) ) |
let step2 w x y z data s = let w = Int32 . add ( Int32 . add w data ) ( Int32 . logxor y ( Int32 . logand z ( Int32 . logxor x y ) ) ) in Int32 . add x ( Int32 . logor ( Int32 . shift_left w s ) ( Int32 . shift_right_logical w ( 32 - s ) ) ) |
let step3 w x y z data s = let w = Int32 . add ( Int32 . add w data ) ( Int32 . logxor x ( Int32 . logxor y z ) ) in Int32 . add x ( Int32 . logor ( Int32 . shift_left w s ) ( Int32 . shift_right_logical w ( 32 - s ) ) ) |
let step4 w x y z data s = let w = Int32 . add ( Int32 . add w data ) ( Int32 . logxor y ( Int32 . logor x ( Int32 . logxor z ( - 1l ) ) ) ) in Int32 . add x ( Int32 . logor ( Int32 . shift_left w s ) ( Int32 . shift_right_logical w ( 32 - s ) ) ) |
let transform ctx data = let a = ctx . a and b = ctx . b and c = ctx . c and d = ctx . d in let a = step1 a b c d ( Int32 . add data . ( 0 ) 0xd76aa478l ) 7 in let d = step1 d a b c ( Int32 . add data . ( 1 ) 0xe8c7b756l ) 12 in let c = step1 c d a b ( Int32 . add data ... |
let string_to_data s = let data = Array . make 16 0l in for i = 0 to 15 do let j = i lsl 2 in data . ( i ) <- Int32 . logor ( Int32 . shift_left ( Int32 . of_int ( Char . code s . [ j + 3 ] ) ) 24 ) ( Int32 . logor ( Int32 . shift_left ( Int32 . of_int ( Char... |
let int32_to_string n s i = s . [ i + 3 ] <- Char . chr ( Int32 . to_int ( Int32 . shift_right n 24 ) land 0xFF ) ; s . [ i + 2 ] <- Char . chr ( Int32 . to_int ( Int32 . shift_right n 16 ) land 0xFF ) ; s . [ i + 1 ] <- Char . chr ( Int32 . to_int (... |
let init ( ) = { buf = String . create 64 ; pos = 0 ; a = 0x67452301l ; b = 0xefcdab89l ; c = 0x98badcfel ; d = 0x10325476l ; bits = 0L } |
let update ctx input ofs len = let rec upd ofs len = if len <= 0 then ( ) else if ctx . pos + len < 64 then begin String . blit input ofs ctx . buf ctx . pos len ; ctx . pos <- ctx . pos + len end else begin let len ' = 64 - ctx . pos in if len ' > 0 then String . blit input ofs ... |
let finish ctx = let padding = String . make 64 ' \ 000 ' in padding . [ 0 ] <- ' \ x80 ' ; let numbits = ctx . bits in if ctx . pos < 56 then begin update ctx padding 0 ( 56 - ctx . pos ) end else begin update ctx padding 0 ( 64 + 56 - ctx . pos ) end ; assert ( ... |
let test s = let ctx = init ( ) in update ctx s 0 ( String . length s ) ; let res = finish ctx in let exp = Digest . string s in let ok = ( res = exp ) in if not ok then Printf . printf " Failure for ' % s ' \ n " s ; ok |
let time msg iter fn = let start = Sys . time ( ) in for i = 1 to iter do fn ( ) done ; let stop = Sys . time ( ) in printf " % s : . % 2f s \ n " msg ( stop . - start ) |
let _ = if test " " && test " a " && test " abc " && test " message digest " && test " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " then printf " Test vectors passed . \ n " ; flush stdout ; if ( Array . length Sys . argv ) > 1 && ( Sys . argv . ... |
let add_equation ( simple : Simple . t ) ty_of_simple env_extension = match Simple . must_be_name simple with | Some ( name , coercion_from_name_to_simple ) -> let coercion_from_simple_to_name = Coercion . inverse coercion_from_name_to_simple in let ty_of_name = TG . apply_coercion ty_of_simple ... |
let all_aliases_of env simple_opt ~ in_env = match simple_opt with | None -> Aliases . Alias_set . empty | Some simple -> let simples = TE . aliases_of_simple_allowable_in_types env simple in Aliases . Alias_set . filter ~ f ( : fun simple -> TE . mem_simple in_env simple ) simples |
type meet_expanded_head_result = | Left_head_unchanged | Right_head_unchanged | New_head of ET . t * TEE . t |
let meet_alloc_mode ( alloc_mode1 : Alloc_mode . t Or_unknown . t ) ( alloc_mode2 : Alloc_mode . t Or_unknown . t ) : Alloc_mode . t Or_unknown . t Or_bottom . t = match alloc_mode1 , alloc_mode2 with | Unknown , Unknown -> Ok Unknown | Unknown , Known _ -> Ok alloc_mode2 | Known _... |
let join_alloc_mode ( alloc_mode1 : Alloc_mode . t Or_unknown . t ) ( alloc_mode2 : Alloc_mode . t Or_unknown . t ) : Alloc_mode . t Or_unknown . t = match alloc_mode1 , alloc_mode2 with | Unknown , _ | _ , Unknown -> Unknown | Known Heap , Known Heap -> Known Heap | Known Local ... |
let rec meet env ( t1 : TG . t ) ( t2 : TG . t ) : ( TG . t * TEE . t ) Or_bottom . t = let t , env_extension = meet0 env t1 t2 in if TG . is_obviously_bottom t then Bottom else Ok ( t , env_extension ) if not ( K . equal ( TG . kind t1 ) ( TG . kind t2 ) ) then M... |
let meet_shape env t ~ shape ~ result_var ~ result_kind : _ Or_bottom . t = let result = Bound_name . create_var result_var in let env = TE . add_definition env result result_kind in let <+ _meet_ty , env_extension = meet ( Meet_env . create env ) t shape in env_extension |
let create_env ( ) = let resolver _ = None in let get_imported_names ( ) = Name . Set . empty in TE . create ~ resolver ~ get_imported_names |
let test_meet_chains_two_vars ( ) = let env = create_env ( ) in let var1 = Variable . create " var1 " in let var1 ' = Bound_var . create var1 Name_mode . normal in let env = TE . add_definition env ( Bound_name . create_var var1 ' ) K . value in let env = TE . add_equation env ( ... |
let test_meet_chains_three_vars ( ) = let env = create_env ( ) in let var1 = Variable . create " var1 " in let var1 ' = Bound_var . create var1 Name_mode . normal in let env = TE . add_definition env ( Bound_name . create_var var1 ' ) K . value in let env = TE . add_equation env ... |
let meet_variants_don ' t_lose_aliases ( ) = let env = create_env ( ) in let define env v = let v ' = Bound_var . create v Name_mode . normal in TE . add_definition env ( Bound_name . create_var v ' ) K . value in let defines env l = List . fold_left define env l in let vx = Variable... |
let test_meet_two_blocks ( ) = let define env v = let v ' = Bound_var . create v Name_mode . normal in TE . add_definition env ( Bound_name . create_var v ' ) K . value in let defines env l = List . fold_left define env l in let env = create_env ( ) in let block1 = Variable . create ... |
let ( ) = let comp_unit = Compilation_unit . create ~ name " : Meet_test " ( Linkage_name . create " meet_test " ) in Compilation_unit . set_current comp_unit ; Format . eprintf " MEET CHAINS WITH TWO VARS @\ n . " ; @ test_meet_chains_two_vars ( ) ; Format . eprintf " ... |
let auto = ref true |
let unsafe = ref false |
let auto_transfers b = auto := b |
let unsafe_rw b = unsafe := b |
let unsafe_set vect idx value = Vector . unsafe_set vect idx value |
let unsafe_get vect idx = Vector . unsafe_get vect idx |
let rec flush_and_transfer_to_cpu d vect = Devices . flush d ( ) ; to_cpu vect ( ) ; Devices . flush d ( ) if ! unsafe then unsafe_set vect idx value else ( if ( idx < 0 ) || ( idx >= Vector . length vect ) then raise ( Invalid_argument " index out of bounds " ) ; if ! a... |
let sub_vector ( vect : ( ' a , ' b ) Vector . vector ) _start ? ok_rng ( : _ok_r = 0 ) ? ko_rng ( : _ko_r = 0 ) _len = if ( _ok_r > _len ) || ( ( _ok_r < 0 ) || ( _ko_r < 0 ) ) then failwith " Wrong value : sub_vector " else ( if ( _start + _l... |
let gpu_vector_copy vecA startA vecB startB size dev = ( match dev . Devices . specific_info with | Devices . CudaInfo _ -> ( match Vector . vector vecA with | Vector . CustomArray _ -> ( Cuda . cuda_custom_vector_copy vecA startA vecB startB size dev . Devices . general_info dev . Device... |
let cpu_vector_copy vecA startA vecB startB size = let sB = ref startB in for i = startA to startA + size - 1 do set vecB ! sB ( get vecA i ) ; incr sB ; done |
let rec vector_copy ( vecA : ( ' a , ' b ) Vector . vector ) startA ( vecB : ( ' a , ' b ) Vector . vector ) startB size = if ( startA + size ) > Vector . length vecA || ( startB + size ) > Vector . length vecB then raise ( Invalid_argument " index out of bounds "... |
let gpu_matrix_copy ( vecA : ( ' a , ' b ) Vector . vector ) ldA start_rowA start_colA ( vecB : ( ' a , ' b ) Vector . vector ) ldB start_rowB start_colB rows cols dev = ( match dev . Devices . specific_info with | Devices . CudaInfo _ -> ( match Vector . vector vecA wi... |
let cpu_matrix_copy ( _vecA : ( ' a , ' b ) Vector . vector ) _ldA _start_rowA _start_colA ( _vecB : ( ' a , ' b ) Vector . vector ) _ldB _start_rowB _start_colB _rows _cols = ( ) |
let rec matrix_copy ( vecA : ( ' a , ' b ) Vector . vector ) ldA start_rowA start_colA ( vecB : ( ' a , ' b ) Vector . vector ) ldB start_rowB start_colB rows cols = if ( start_rowA * ldA + start_colA ) + ( rows * cols ) - 1 > Vector . length vecA then raise ( Inval... |
type t = { mutable locked : bool ; mutable locked_ext : bool ; mutable failed : bool ; mutable stopped : bool ; report_exn : exn -> unit ; trace : Trace . Writer . t ; ext_sampler : Geometric_sampler . t ; } |
let curr_active_tracer : t option ref = ref None |
let active_tracer ( ) = ! curr_active_tracer |
let bytes_before_ext_sample = ref max_int |
let draw_sampler_bytes t = Geometric_sampler . draw t . ext_sampler * ( Sys . word_size / 8 ) if s . locked then if s . locked_ext then false else ( Thread . yield ( ) ; lock_tracer s ) else if s . failed then false else ( s . locked <- true ; true ) if s . locked then ( Thr... |
let default_report_exn e = let msg = Printf . sprintf " Memtrace failure : % s \ n " ( Printexc . to_string e ) in output_string stderr msg ; Printexc . print_backtrace stderr ; flush stderr |
let start ( ? report_exn = default_report_exn ) ~ sampling_rate trace = let ext_sampler = Geometric_sampler . make ~ sampling_rate ( ) in let s = { trace ; locked = false ; locked_ext = false ; stopped = false ; failed = false ; report_exn ; ext_sampler } in let tracker : ( _ , ... |
let stop s = if not s . stopped then begin s . stopped <- true ; Gc . Memprof . stop ( ) ; if lock_tracer s then Trace . Writer . close s . trace ; curr_active_tracer := None end match ! curr_active_tracer with | None -> bytes_before_ext_sample := max_int ; None | Some s -> if lock_tr... |
let ext_alloc ~ bytes = let n = ! bytes_before_ext_sample - bytes in bytes_before_ext_sample := n ; if n <= 0 then ext_alloc_slowpath ~ bytes else None |
let ext_free id = match ! curr_active_tracer with | None -> ( ) | Some s -> if lock_tracer_ext s then begin match Trace . Writer . put_collect s . trace ( Trace . Timestamp . now ( ) ) id with | ( ) -> unlock_tracer_ext s ; ( ) | exception e -> mark_failed s e ; ( ) end |
let getpid64 ( ) = Int64 . of_int ( Unix . getpid ( ) ) |
let start_tracing ~ context ~ sampling_rate ~ filename = if Memprof_tracer . active_tracer ( ) <> None then failwith " Only one Memtrace instance may be active at a time " ; let fd = Unix . openfile filename Unix . [ O_CREAT ; O_WRONLY ; O_TRUNC ] 0o600 in let info : Trace . Info . t... |
let stop_tracing t = Memprof_tracer . stop t |
let ( ) = at_exit ( fun ( ) -> Option . iter stop_tracing ( Memprof_tracer . active_tracer ( ) ) ) |
let trace_if_requested ? context ? sampling_rate ( ) = match Sys . getenv_opt " MEMTRACE " with | None | Some " " -> ( ) | Some filename -> Unix . putenv " MEMTRACE " " " ; let check_rate = function | Some rate when 0 . < rate && rate <= 1 . -> rate | _ -> raise ( ... |
module External = struct type token = Memprof_tracer . ext_token let alloc = Memprof_tracer . ext_alloc let free = Memprof_tracer . ext_free end |
let rec take n xs = match n , xs with | 0 , _ | _ , [ ] -> [ ] | _ , ( x :: xs as input ) -> let xs ' = take ( n - 1 ) xs in if xs == xs ' then input else x :: xs ' |
let rec drop n xs = match n , xs with | 0 , _ -> xs | _ , [ ] -> [ ] | _ , _ :: xs -> drop ( n - 1 ) xs |
let rec uniq1 cmp x ys = match ys with | [ ] -> [ ] | y :: ys -> if cmp x y = 0 then uniq1 cmp x ys else y :: uniq1 cmp y ys |
let uniq cmp xs = match xs with | [ ] -> [ ] | x :: xs -> x :: uniq1 cmp x xs |
let weed cmp xs = uniq cmp ( List . sort cmp xs ) |
type ' a stream = ' a head Lazy . t | Nil | Cons of ' a * ' a stream |
let rec length xs = match Lazy . force xs with | Nil -> 0 | Cons ( _ , xs ) -> 1 + length xs |
let rec foldr f xs accu = match Lazy . force xs with | Nil -> accu | Cons ( x , xs ) -> f x ( foldr f xs accu ) end |
type ( ' token , ' semantic_value ) traditional = ( Lexing . lexbuf -> ' token ) -> Lexing . lexbuf -> ' semantic_value |
type ( ' token , ' semantic_value ) revised = ( unit -> ' token ) -> ' semantic_value |
let traditional2revised ( get_raw_token : ' token -> ' raw_token ) ( get_startp : ' token -> Lexing . position ) ( get_endp : ' token -> Lexing . position ) ( parser : ( ' raw_token , ' semantic_value ) traditional ) fun ( lexer : unit -> ' token ) -> let lexbuf : ... |
let revised2traditional ( make_token : ' raw_token -> Lexing . position -> Lexing . position -> ' token ) ( parser : ( ' token , ' semantic_value ) revised ) fun ( lexer : Lexing . lexbuf -> ' raw_token ) ( lexbuf : Lexing . lexbuf ) -> let lexer ( ) : ' token = ... |
module Simplified = struct let traditional2revised parser = traditional2revised ( fun ( token , _ , _ ) -> token ) ( fun ( _ , startp , _ ) -> startp ) ( fun ( _ , _ , endp ) -> endp ) parser let revised2traditional parser = revised2traditional ( fun token startp endp ... |
module type INCREMENTAL_ENGINE = sig type token type production type ' a env type ' a checkpoint = private | InputNeeded of ' a env | Shifting of ' a env * ' a env * bool | AboutToReduce of ' a env * production | HandlingError of ' a env | Accepted of ' a | Rejected val offer : ' a checkpo... |
module type SYMBOLS = sig type ' a terminal type ' a nonterminal type ' a symbol = | T : ' a terminal -> ' a symbol | N : ' a nonterminal -> ' a symbol type xsymbol = | X : ' a symbol -> xsymbol end |
module type INSPECTION = sig include SYMBOLS type ' a lr1state type production type item = production * int val compare_terminals : _ terminal -> _ terminal -> int val compare_nonterminals : _ nonterminal -> _ nonterminal -> int val compare_symbols : xsymbol -> xsymbol -> int val compare_productions ... |
module type EVERYTHING = sig include INCREMENTAL_ENGINE include INSPECTION with type ' a lr1state := ' a lr1state with type production := production with type ' a env := ' a env end end |
type ( ' state , ' semantic_value ) stack = { state : ' state ; semv : ' semantic_value ; startp : Lexing . position ; endp : Lexing . position ; next : ( ' state , ' semantic_value ) stack ; } |
type ( ' state , ' semantic_value , ' token ) env = { error : bool ; triple : ' token * Lexing . position * Lexing . position ; stack : ( ' state , ' semantic_value ) stack ; current : ' state ; } |
module type TABLE = sig type state val number : state -> int type token type terminal type nonterminal type semantic_value val token2terminal : token -> terminal val token2value : token -> semantic_value val error_terminal : terminal val error_value : semantic_value val foreach_terminal : ( terminal -> ' ... |
module type MONOLITHIC_ENGINE = sig type state type token type semantic_value exception Error val entry : [ ` Legacy | ` Simplified ] -> state -> ( Lexing . lexbuf -> token ) -> Lexing . lexbuf -> semantic_value end |
module type INCREMENTAL_ENGINE_START = sig type state type semantic_value type ' a checkpoint val start : state -> Lexing . position -> semantic_value checkpoint end |
module type ENGINE = sig include MONOLITHIC_ENGINE include IncrementalEngine . INCREMENTAL_ENGINE with type token := token and type ' a lr1state = state include INCREMENTAL_ENGINE_START with type state := state and type semantic_value := semantic_value and type ' a checkpoint := ' a checkpoint end end |
module Make ( T : TABLE ) = struct include T type ' a env = ( state , semantic_value , token ) EngineTypes . env type ' a checkpoint = | InputNeeded of ' a env | Shifting of ' a env * ' a env * bool | AboutToReduce of ' a env * production | HandlingError of ' a env | Accepted of ... |
type ' a buffer = ' a content ref |
let update buffer x = buffer := match ! buffer , x with | Zero , _ -> One x | One x1 , x2 | Two ( _ , x1 ) , x2 -> Two ( x1 , x2 ) |
let show f buffer : string = match ! buffer with | Zero -> assert false | One invalid -> Printf . sprintf " before ' % s ' " ( f invalid ) | Two ( valid , invalid ) -> Printf . sprintf " after ' % s ' and before ' % s ' " ( f valid ) ( f invalid ) |
let last buffer = match ! buffer with | Zero -> assert false | One invalid | Two ( _ , invalid ) -> invalid |
let wrap lexer = let buffer = ref Zero in buffer , fun lexbuf -> let token = lexer lexbuf in update buffer ( lexbuf . lex_start_p , lexbuf . lex_curr_p ) ; token |
let wrap_supplier supplier = let buffer = ref Zero in buffer , fun ( ) -> let ( _token , pos1 , pos2 ) as triple = supplier ( ) in update buffer ( pos1 , pos2 ) ; triple |
let extract text ( pos1 , pos2 ) : string = let ofs1 = pos1 . pos_cnum and ofs2 = pos2 . pos_cnum in let len = ofs2 - ofs1 in try String . sub text ofs1 len with Invalid_argument _ -> " " ??? |
let sanitize text = String . map ( fun c -> if Char . code c < 32 then ' ' else c ) text |
let rec compress n b i j skipping = if j < n then let c , j = Bytes . get b j , j + 1 in match c with | ' ' | ' \ t ' | ' \ n ' | ' \ r ' -> let i = if not skipping then ( Bytes . set b i ' ' ; i + 1 ) else i in let skipping = true in compress n b i j skipping | _ -... |
let compress text = let b = Bytes . of_string text in let n = Bytes . length b in compress n b 0 0 false |
let shorten k text = let n = String . length text in if n <= 2 * k + 3 then text else String . sub text 0 k ^ " . . . " ^ String . sub text ( n - k ) k |
let is_digit c = let c = Char . code c in Char . code ' 0 ' <= c && c <= Char . code ' 9 ' |
let expand f text = let n = String . length text in let b = Buffer . create n in let rec loop i = if i < n then begin let c , i = text . [ i ] , i + 1 in loop ( try if c <> ' ' $ then raise Copy ; let j = ref i in while ! j < n && is_digit text . [ ! j ] do incr j done ; if ... |
let init filename lexbuf = lexbuf . lex_curr_p <- { pos_fname = filename ; pos_lnum = 1 ; pos_bol = 0 ; pos_cnum = 0 } ; lexbuf |
let read filename = let c = open_in filename in let text = really_input_string c ( in_channel_length c ) in close_in c ; let lexbuf = Lexing . from_string text in text , init filename lexbuf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.