text
stringlengths
12
786k
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 e...
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 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_in...
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_in...
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 ( struc...
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 ( he...
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 -> re...
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 ( "...
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 false...
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 " , [ CPro...
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 " , ...
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 . ...
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 : nu...
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 ( funct...
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_ve...
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 . ...
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 . break...
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_...
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 voi...
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 " byteLengt...
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 ' ; ...
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 " la...
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 = F...
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 -> O...
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 '...
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 , ...
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 gl...
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 = " Docu...
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...
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 " [ ...
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 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_to...
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...
module G = struct let console = Jv . get Jv . global " console " let document = El . global_document let navigator = Jv . get Jv . global " navigator " let performance = Jv . get Jv . global " performance " let window = Jv . get Jv . global " window " let is_secure_context = Jv ...
module Matrix4 = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let is_2d m = Jv . Bool . get m " is2D " let is_identity m = Jv . Bool . get m " isIdentity " let inverse m = Jv . call m " inverse " [ ] || let multiply m m ' = Jv . call m " mult...
module Vec4 = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v4 = Jv . get Jv . global " DOMPointReadOnly " let v ~ x ~ y ~ z ~ w = Jv . new ' v4 Jv . [ | of_float x ; of_float y ; of_float z ; of_float w ; ] | let tr m v = Jv . call v " ...
module Canvas = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let create ? d ? at ( ? w = 0 ) ( ? h = 0 ) cs = let c = El . to_jv @@ El . canvas ? d ? at cs in Jv . Int . set c " width " w ; Jv . Int . set c " height " h ; c let of_el ...
module C2d = struct module Fill_rule = struct type t = Jstr . t let nonzero = Jstr . v " nonzero " let evenodd = Jstr . v " evenodd " end module Image_smoothing_quality = struct type t = Jstr . t let low = Jstr . v " low " let medium = Jstr . v " medium " let high = Jstr . v " ...
module Gl = struct module Attrs = struct module Power_preference = struct type t = Jstr . t let default = Jstr . v " default " let high_performance = Jstr . v " high - performance " let low_power = Jstr . v " low - power " end type t = Jv . t include ( Jv . Id : Jv . CONV with typ...
module Clipboard = struct module Item = struct module Presentation_style = struct type t = Jstr . t let unspecified = Jstr . v " unspecified " let inline = Jstr . v " inline " let attachment = Jstr . v " attachement " end type opts = Jv . t let opts ? presentation_style ( ) = let o ...
module Form = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let of_el e = if El . has_tag_name El . Name . form e then El . to_jv e else let exp = Jstr . v " Expected form element but found : " in Jv . throw ( Jstr . append exp ( El . tag_name e ) ) ...
module Fetch = struct module Body = struct type init = Jv . t let of_jstr = Jv . of_jstr let of_uri_params = Uri . Params . to_jv let of_form_data = Form . Data . to_jv let of_blob = Blob . to_jv let of_array_buffer = Tarray . Buffer . to_jv type t = Jv . t include ( Jv . Id : Jv . C...
module Geolocation = struct module Error = struct type code = int let permission_denied = 1 let position_unavailable = 2 let timeout = 3 type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let code e = Jv . Int . get e " code " let message e = Jv . Jstr . get e " messa...
module Media = struct module Prop = struct module Bool = struct module Constraint = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? exact ? ideal ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " exact " exact ; Jv . Bool . set_if_...
module Message = struct type transfer = Jv . t let transfer = Jv . repr type opts = Jv . t let opts ? target_origin ? transfer ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " targetOrigin " target_origin ; Jv . set_if_some o " transfer " ( Option . map Jv . of...
module Notification = struct module Permission = struct type t = Jstr . t let default = Jstr . v " default " let denied = Jstr . v " denied " let granted = Jstr . v " granted " end let notification = Jv . get Jv . global " Notification " let permission ( ) = Jv . Jstr . get n...
module Storage = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let local w = Jv . get ( Window . to_jv w ) " localStorage " let session w = Jv . get ( Window . to_jv w ) " sessionStorage " let length s = Jv . Int . get s " length " let key s i ...
module Websocket = struct module Binary_type = struct type t = Jstr . t let blob = Jstr . v " blob " let arraybuffer = Jstr . v " arraybuffer " end module Ready_state = struct type t = int let connecting = 0 let open ' = 1 let closing = 2 let closed = 3 end type t = Jv . t include ( ...
module Futr = struct let to_event f = let e , send_e = E . create ( ) in let send_e v = ignore ( G . set_timeout ~ ms : 0 @@ fun ( ) -> send_e v ) in Fut . await f send_e ; e let of_event e = let fut , set_fut = Fut . create ( ) in let logr = ref None in let set_fut v = ignore...
module Consoler = struct let tick _ = Console . [ Jstr . v " tick " ] let log_value ( ? l = Console . debug ) ( ? v = fun v -> Console . [ v ] ) id x = l Console . ( Jstr . ( v id + v " " ) : :: ( v x ) ) ; x module E = struct let log ( ? obs = false ) ...
module Evr = struct let instruct ( ? propagate = true ) ( ? default = true ) e = ( if default then ( ) else Ev . prevent_default e ) ; if propagate then ( ) else Ev . stop_propagation e let endless_listen ( ? capture = false ) ? propagate ? default t type ' f = let opts = mat...
module Elr = struct let xxx_funs xxx e : ( unit -> unit ) list = Obj . magic @@ Jv . get e xxx let add_xxx_fun xxx f e = let fs = Jv . get e xxx in let fs = if Jv . is_undefined fs then [ f ] else ( f :: Obj . magic fs ) in Jv . set e xxx ( Jv . repr fs ) let add_add_fun = add_xx...
module Key = struct type code = int type t = [ ` Alt of [ ` Left | ` Right ] | ` Arrow of [ ` Up | ` Down | ` Left | ` Right ] | ` Ascii of Char . t | ` Backspace | ` Ctrl of [ ` Left | ` Right ] | ` End | ` Enter | ` Escape | ` Func of int | ` Home ...
module Mouse = struct let warn_but ( ) = Console . ( warn [ Jstr . v " unexpected e . which " ] ) let pt x y = ( x , y ) type ' a events = { t : Ev . target ; normalize : bool ; pt : float -> float -> ' a ; mutable last_pos : float * float ; mutable unlisten : ( ...
module Windowr = struct let in_fullscreen ( ) = Option . is_some ( Document . fullscreen_element G . document ) let is_fullscreen = let is_fullscreen , set_fullscreen = S . create ( in_fullscreen ( ) ) in let change _e = set_fullscreen ( in_fullscreen ( ) ) in Ev . listen Ev . ...
module Time = struct type span = float let tick_now ( ) = Performance . now_ms G . performance . / 1000 . let start = tick_now ( ) let elapsed ( ) = tick_now ( ) . - start type counter = span let counter ( ) = tick_now ( ) let counter_value c = tick_now ( ) . - c let ...
module Human = struct let noticed = 0 . 1 let interrupted = 1 . let left = 10 . let rec feel_action feel set_feel ( ) = let new_feel , delay = match S . value feel with | ` Interacting -> ` Interrupted , left . - interrupted | ` Interrupted -> ` Left , 0 . | ` Left -> a...
module Ui = struct let ui_active = Jstr . v " ui - active " let ui_button = Jstr . v " ui - button " let ui_button_selector = Jstr . v " ui - button - selector " let ui_dir_align_center = Jstr . v " ui - dir - align - center " let ui_dir_align_distribute = Jstr . v " ui - dir ...
let json = Jv . get Jv . global " JSON " = " caml_int64_create_lo_mi_hi "