text stringlengths 0 601k |
|---|
type t = Pattern . t list |
let check_pattern_list_invariant pattern_list = let everything_being_defined = List . map Pattern . everything_being_defined_as_list pattern_list |> List . concat in let everything_being_defined_as_set = Code_id_or_symbol . Set . of_list everything_being_defined in if List . compare_length_with everything_being_defined... |
let create pattern_list = if Flambda_features . check_invariants ( ) then check_pattern_list_invariant pattern_list ; pattern_list |
let singleton pattern = [ pattern ] |
let to_list t = t |
let [ @ ocamlformat " disable " ] print ppf t = Format . fprintf ppf " [ @< hov 1 ( >% a ) ] " @ ( Format . pp_print_list ~ pp_sep : Format . pp_print_space Pattern . print ) t |
let symbols_being_defined t = List . map Pattern . symbols_being_defined t |> Symbol . Set . union_list |
let code_being_defined t = List . fold_left ( fun code_ids pattern -> Code_id . Set . union code_ids ( Pattern . code_being_defined pattern ) ) Code_id . Set . empty t |
let binds_code t = List . exists Pattern . binds_code t |
let binds_symbols t = List . exists Pattern . binds_symbols t |
let everything_being_defined t = List . map Pattern . everything_being_defined t |> Code_id_or_symbol . Set . union_list |
let apply_renaming t perm = List . map ( fun pattern -> Pattern . apply_renaming pattern perm ) t |
let free_names t = List . map Pattern . free_names t |> Name_occurrences . union_list |
let all_ids_for_export t = List . map Pattern . all_ids_for_export t |> Ids_for_export . union_list |
let concat t1 t2 = t1 @ t2 |
let gc_roots t = List . map Pattern . gc_roots t |> List . concat |
type t = { var : Variable . t ; name_mode : Name_mode . t } |
let [ @ ocamlformat " disable " ] print ppf { var ; name_mode ; } = match name_mode with | Normal -> Variable . print ppf var | In_types -> assert false | Phantom -> Variable . print ppf var |
let create var name_mode = { var ; name_mode } |
let var t = t . var |
let name_mode t = t . name_mode |
let with_var t var = { t with var } |
let with_name_mode t name_mode = { t with name_mode } |
let rename t = with_var t ( Variable . rename t . var ) |
let apply_renaming t perm = with_var t ( Renaming . apply_variable perm t . var ) |
let free_names t = Name_occurrences . singleton_variable t . var t . name_mode |
let all_ids_for_export { var ; name_mode = _ } = Ids_for_export . add_variable Ids_for_export . empty var |
let renaming { var ; name_mode = _ } ~ guaranteed_fresh = let { var = guaranteed_fresh ; name_mode = _ } = guaranteed_fresh in Renaming . add_fresh_variable Renaming . empty var ~ guaranteed_fresh |
let error_occurred = ref false |
let function_tested = ref " " |
let testing_function s = function_tested := s ; print_newline ( ) ; print_string s ; print_newline ( ) |
let test test_number answer correct_answer = flush stdout ; flush stderr ; if answer <> correct_answer then begin eprintf " *** Bad result ( % s , test % d ) \ n " ! function_tested test_number ; flush stderr ; error_occurred := true end else begin printf " % d . . . " test_number end |
module type TESTSIG = sig type t module Ops : sig val neg : t -> t val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val unsigned_div : t -> t -> t val rem : t -> t -> t val logand : t -> t -> t val logor : t -> t -> t val logxor : t -> t -> t val shift_left : t -> int -> t val shi... |
module Test32 ( M : TESTSIG ) = struct open M open Ops let _ = testing_function " of_int , to_int " ; test 1 ( to_int ( of_int 0 ) ) 0 ; test 2 ( to_int ( of_int 123 ) ) 123 ; test 3 ( to_int ( of_int ( - 456 ) ) ) ( - 456 ) ; test 4 ( to_int ( of_int 0x3FFFFFFF ) ) 0x3FFFFFFF ; test 5 ( to_int ( of_int ( - 0x40000000 ... |
module Test64 ( M : TESTSIG ) = struct open M open Ops let _ = testing_function " of_int , to_int " ; test 1 ( to_int ( of_int 0 ) ) 0 ; test 2 ( to_int ( of_int 123 ) ) 123 ; test 3 ( to_int ( of_int ( - 456 ) ) ) ( - 456 ) ; test 4 ( to_int ( of_int 0x3FFFFFFF ) ) 0x3FFFFFFF ; test 5 ( to_int ( of_int ( - 0x40000000 ... |
let testcomp_int32 ( a : int32 ) ( b : int32 ) = ( a = b , a <> b , a < b , a > b , a <= b , a >= b , compare a b , Int32 . unsigned_compare a b ) |
let testcomp_int64 ( a : int64 ) ( b : int64 ) = ( a = b , a <> b , a < b , a > b , a <= b , a >= b , compare a b , Int64 . unsigned_compare a b ) |
let testcomp_nativeint ( a : nativeint ) ( b : nativeint ) = ( a = b , a <> b , a < b , a > b , a <= b , a >= b , compare a b , Nativeint . unsigned_compare a b ) |
let _ = testing_function " -------- Int32 " ; -------- let module A = Test32 ( struct type t = int32 module Ops = Int32 let testcomp = testcomp_int32 let skip_float_tests = false end ) in print_newline ( ) ; testing_function " -------- Int64 " ; -------- let module B = Test64 ( struct type t = int64 module Ops = Int64 ... |
let _ = print_newline ( ) ; if ! error_occurred then begin prerr_endline " ************* TEST FAILED " ; **************** exit 2 end else exit 0 |
type term = Var of int | Prop of head * term list { name : string ; mutable props : ( term * term ) list } |
let rec print_term = function Var v -> print_string " v " ; print_int v | Prop ( head , argl ) -> print_string " ( " ; print_string head . name ; List . iter ( fun t -> print_string " " ; print_term t ) argl ; print_string " ) " |
let lemmas = ref ( [ ] : head list ) |
let get name = let rec get_rec = function hd1 :: hdl -> if hd1 . name = name then hd1 else get_rec hdl | [ ] -> let entry = { name = name ; props = [ ] } in lemmas := entry :: ! lemmas ; entry in get_rec ! lemmas |
let add_lemma = function | Prop ( _ , [ ( Prop ( headl , _ ) as left ) ; right ] ) -> headl . props <- ( left , right ) :: headl . props | _ -> assert false |
type subst = Bind of int * term |
let get_binding v list = let rec get_rec = function [ ] -> failwith " unbound " | Bind ( w , t ) :: rest -> if v = w then t else get_rec rest in get_rec list |
let apply_subst alist term = let rec as_rec = function Var v -> begin try get_binding v alist with Failure _ -> term end | Prop ( head , argl ) -> Prop ( head , List . map as_rec argl ) in as_rec term |
let rec unify term1 term2 = unify1 term1 term2 [ ] match term2 with Var v -> begin try if get_binding v unify_subst = term1 then unify_subst else raise Unify with Failure _ -> Bind ( v , term1 ) :: unify_subst end | Prop ( head2 , argl2 ) -> match term1 with Var _ -> raise Unify | Prop ( head1 , argl1 ) -> if head1 == ... |
let rec rewrite = function Var _ as term -> term | Prop ( head , argl ) -> rewrite_with_lemmas ( Prop ( head , List . map rewrite argl ) ) head . props match lemmas with [ ] -> term | ( t1 , t2 ) :: rest -> try rewrite ( apply_subst ( unify term t1 ) t2 ) with Unify -> rewrite_with_lemmas term rest |
type cterm = CVar of int | CProp of string * cterm list |
let rec cterm_to_term = function CVar v -> Var v | CProp ( p , l ) -> Prop ( get p , List . map cterm_to_term l ) |
let add t = add_lemma ( cterm_to_term t ) |
let _ = ( " equal " , [ CProp ( " compile " , [ CVar 5 ] ) ; CProp ( " reverse " , [ CProp ( " codegen " , [ CProp ( " optimize " , [ CVar 5 ] ) ; CProp ( " nil " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " eqp " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " equal " , [ CProp ( " fix " , [ CVar 23 ] ) ; CProp ( " fix " ,... |
let truep x lst = match x with Prop ( head , _ ) -> head . name = " true " || List . mem x lst | _ -> List . mem x lst match x with Prop ( head , _ ) -> head . name = " false " || List . mem x lst | _ -> List . mem x lst |
let rec tautologyp x true_lst false_lst = if truep x true_lst then true else if falsep x false_lst then false else begin match x with Var _ -> false | Prop ( head , [ test ; yes ; no ] ) -> if head . name = " if " then if truep test true_lst then tautologyp yes true_lst false_lst else if falsep test false_lst then taut... |
let tautp x = let y = rewrite x in tautologyp y [ ] [ ] |
let subst = CProp ( " f " , [ CProp ( " plus " , [ CProp ( " plus " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 2 ; CProp ( " zero " , [ ] ) ] ) ] ) ] ) ) ) ; Bind ( 24 , cterm_to_term ( CProp ( " f " , [ CProp ( " times " , [ CProp ( " times " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 2 ; CVar 3 ] ) ... |
let term = cterm_to_term ( CProp ( " implies " , [ CProp ( " and " , [ CProp ( " implies " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " and " , [ CProp ( " implies " , [ CVar 24 ; CVar 25 ] ) ; CProp ( " and " , [ CProp ( " implies " , [ CVar 25 ; CVar 20 ] ) ; CProp ( " implies " , [ CVar 20 ; CVar 22 ] ) ] ) ] ) ] ) ; CProp... |
let _ = let ok = ref true in for i = 1 to 50 do if not ( tautp ( apply_subst subst term ) ) then ok := false done ; if ! ok then print_string " Proved !\ n " else print_string " Cannot prove !\ n " ; exit 0 |
module Make ( T : Branch_relaxation_intf . S ) = struct let label_map code = let map = Hashtbl . create 37 in let rec fill_map pc instr = match instr . desc with | Lend -> ( pc , map ) | Llabel lbl -> Hashtbl . add map lbl pc ; fill_map pc instr . next | op -> fill_map ( pc + T . instr_size op ) instr . next in fill_ma... |
module type S = sig type distance = int module Cond_branch : sig type t val all : t list val max_displacement : t -> distance val classify_instr : Linear . instruction_desc -> t option end val offset_pc_at_branch : distance val instr_size : Linear . instruction_desc -> distance val relax_allocation : num_bytes : int ->... |
let debug_breakpoints = ref false |
let breakpoint_number = ref 0 |
let breakpoints = ref ( [ ] : ( breakpoint_id * code_event ) list ) |
let positions = ref ( [ ] : ( pc * int ref ) list ) |
let current_version = ref 0 |
let max_version = ref 0 |
let copy_breakpoints ( ) = ! current_checkpoint . c_breakpoints <- ! positions ; ! current_checkpoint . c_breakpoint_version <- ! current_version |
let new_version ( ) = incr max_version ; current_version := ! max_version |
let breakpoints_count ( ) = List . length ! breakpoints |
let rec breakpoints_at_pc pc = begin match Symbols . event_at_pc pc with | { ev_frag = frag ; ev_ev = { ev_repr = Event_child { contents = pos } } } -> breakpoints_at_pc { frag ; pos } | _ -> [ ] | exception Not_found -> [ ] end @ List . map fst ( List . filter ( function ( _ , { ev_frag = frag ; ev_ev = { ev_pos = pos... |
let breakpoint_at_pc pc = breakpoints_at_pc pc <> [ ] |
let print_pc out { frag ; pos } = fprintf out " % d :% d " frag pos |
let remove_breakpoints pcs = if ! debug_breakpoints then printf " Removing breakpoints . . . \ n " ; %! List . iter ( function ( pc , _ ) -> if ! debug_breakpoints then printf " % a \ n " %! print_pc pc ; reset_instr pc ; Symbols . set_event_at_pc pc ) pcs |
let set_breakpoints pcs = if ! debug_breakpoints then printf " Setting breakpoints . . . \ n " ; %! List . iter ( function ( pc , _ ) -> if ! debug_breakpoints then printf " % a \ n " %! print_pc pc ; set_breakpoint pc ) pcs |
let update_breakpoints ( ) = if ! debug_breakpoints then begin prerr_string " Updating breakpoints . . . " ; prerr_int ! current_checkpoint . c_breakpoint_version ; prerr_string " " ; prerr_int ! current_version ; prerr_endline " " end ; if ! current_checkpoint . c_breakpoint_version <> ! current_version then Exec . pr... |
let execute_without_breakpoints f = Misc . protect_refs [ Misc . R ( Debugger_config . break_on_load , false ) ; Misc . R ( current_version , 0 ) ; Misc . R ( positions , [ ] ) ; Misc . R ( breakpoints , [ ] ) ; Misc . R ( breakpoint_number , 0 ) ] f |
let insert_position pos = try incr ( List . assoc pos ! positions ) with Not_found -> positions := ( pos , ref 1 ) :: ! positions ; new_version ( ) |
let remove_position pos = let count = List . assoc pos ! positions in decr count ; if ! count = 0 then begin positions := List . remove_assoc pos ! positions ; new_version ( ) end |
let rec new_breakpoint event = match event with { ev_frag = frag ; ev_ev { = ev_repr = Event_child pos } } -> new_breakpoint ( Symbols . any_event_at_pc { frag ; pos ( =! pos ) } ) | { ev_frag = frag ; ev_ev { = ev_pos = pos } } -> let pc = { frag ; pos } in Exec . protect ( function ( ) -> incr breakpoint_number ; ins... |
let remove_breakpoint number = try let ev = List . assoc number ! breakpoints in let pc = { frag = ev . ev_frag ; pos = ev . ev_ev . ev_pos } in Exec . protect ( function ( ) -> breakpoints := List . remove_assoc number ! breakpoints ; remove_position pc ; if ! Parameters . breakpoint then printf " Removed breakpoint %... |
let remove_all_breakpoints ( ) = List . iter ( function ( number , _ ) -> remove_breakpoint number ) ! breakpoints |
let temporary_breakpoint_position = ref ( None : pc option ) |
let exec_with_temporary_breakpoint pc funct = let previous_version = ! current_version in let remove ( ) = temporary_breakpoint_position := None ; current_version := previous_version ; let count = List . assoc pc ! positions in decr count ; if ! count = 0 then begin positions := List . remove_assoc pc ! positions ; res... |
module Ev = struct type ' a type ' = Jstr . t module Type = struct type void type ' a t = ' a type ' external create : Jstr . t -> ' a t = " % identity " external name : ' a t -> Jstr . t = " % identity " external void : Jstr . t -> ' a t = " % identity " end type void = Type . void type ' type init = Jv . t let init ?... |
module Tarray = struct module Buffer = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let array_buffer = Jv . get Jv . global " ArrayBuffer " let create n = Jv . new ' array_buffer Jv . [ | of_int n ] | let byte_length a = Jv . Int . get a " byteLength " let slice ( ? start = 0 ) ? stop a = let... |
module Blob = struct module Ending_type = struct type t = Jstr . t let transparent = Jstr . v " transparent " let native = Jstr . v " native " end type init = Jv . t let init ? type ' ? endings ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " type " type ' ; Jv . Jstr . set_if_some o " endings " endings ; o... |
module File = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) type init = Jv . t let init ? blob_init ? last_modified_ms ( ) = let o = match blob_init with None -> Jv . obj [ ] || | Some b -> Jv . repr b in Jv . Int . set_if_some o " lastModified " last_modified_ms ; o let file = Jv . get Jv . g... |
module Base64 = struct type data = Jstr . t let data_utf_8_of_jstr s = Tarray . to_binary_jstr ( Tarray . of_jstr s ) let data_utf_8_to_jstr d = match Tarray . of_binary_jstr d with | Error _ as e -> e | Ok t -> Tarray . to_jstr t let data_of_binary_jstr = Fun . id let data_to_binary_jstr = Fun . id let encode bs = mat... |
module Json = struct type t = Jv . t let json = Jv . get Jv . global " JSON " let encode v = Jv . to_jstr ( Jv . call json " stringify " [ | v ] ) | let decode s = match Jv . call json " parse " [ | Jv . of_jstr s ] | with | exception Jv . Error e -> Error e | v -> Ok v end |
module Uri = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let encode = Jv . get Jv . global " encodeURI " let decode = Jv . get Jv . global " decodeURI " let url = Jv . get Jv . global " URL " let v ? base s = match base with | None -> Jv . new ' url [ | Jv . of_jstr s ] | | Some b -> Jv . ne... |
module At = struct type name = Jstr . t type t = name * Jstr . t let v n v = ( n , v ) let true ' n = ( n , Jstr . empty ) let int n i = ( n , Jstr . of_int i ) let add_if b at l = if b then at :: l else l let add_if_some name o l = match o with None -> l | Some a -> ( name , a ) :: l let to_pair = Fun . id module Name... |
module El = struct type document = Jv . t type window = Jv . t type tag_name = Jstr . t type el = Jv . t type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let global_document = Jv . get Jv . global " document " let document e = Jv . get e " ownerDocument " let global_root = Jv . get global_document " doc... |
module Document = struct type t = El . document include ( Jv . Id : Jv . CONV with type t := t ) let as_target d = d let root d = El . of_jv ( Jv . get d " documentElement " ) let body d = let b = Jv . get d " body " in if Jv . is_some b then El . of_jv b else let err = " Document body is null . Try to defer your scrip... |
module Abort = struct module Signal = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let aborted s = Jv . Bool . get s " aborted " let abort = Ev . Type . void ( Jstr . v " abort " ) end type t = Jv . t include ( Jv . Id : Jv . CONV with ty... |
module Console = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let call c meth args = ignore ( Jv . call c meth args ) let c = ref ( Jv . get Jv . global " console " ) let get ( ) = ! c let set n = c := n let clear ( ) = call ! c " clear " [ ] || type msg = [ ] : msg | ( :: ) : ' a * msg -> ms... |
module Window = struct type t = El . window include ( Jv . Id : Jv . CONV with type t := t ) let as_target w = Ev . target_of_jv w let closed w = Jv . Bool . get w " closed " let scroll_x w = Jv . Float . get w " scrollX " let scroll_y w = Jv . Float . get w " scrollY " let device_pixel_ratio w = Jv . Float . get w " d... |
module Navigator = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let languages n = match Jv . find n " languages " with | Some a -> Jv . to_jstr_list a | None -> match Jv . Jstr . find n " language " with | Some v -> [ v ] | None -> [ ] let max_touch_points n = let t = Jv . get n " maxTouchPoi... |
module Performance = struct module Entry = struct module Type = struct type t = Jstr . t let frame = Jstr . v " frame " let navigation = Jstr . v " navigation " let resource = Jstr . v " resource " let mark = Jstr . v " mark " let measure = Jstr . v " measure " let paint = Jstr . v " paint " let longtask = Jstr . v " l... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.