text stringlengths 0 601k |
|---|
let removeEventListener typ listener options = window ## removeEventListener typ listener options |
let requestAnimationFrame_polyfill : unit -> unit = fun ( ) -> [ % bs . raw { | // requestAnimationFrame polyfill ( function ( ) { var lastTime = 0 ; var vendors = [ ' ms ' , ' moz ' , ' webkit ' , ' o ' ] ; for ( var x = 0 ; x < vendors . length && ! window . requestAnimationFrame ; ++ x ) { window . requestAnimationF... |
let decode_callback ( err : unit -> string ) ( cb : Value . t ) : Value . t -> unit = match Decode . _function cb with | None -> Main . raise_js ( err ( ) ) | Some cb -> fun v -> cb [ | v ] | |> ignore |
let send_message ( err : unit -> string ) ( msg : Value . t ) ( dec : ' msg Decode . t ) ( cb : ' msg -> unit ) : unit = match dec msg with | None -> let open Main in log_string ( err ( ) ) ; log_value msg | Some msg -> cb msg |
let do_async ( f : unit -> unit ) : unit = Timer . set f 0 |> ignore object method postMessage : ' msg -> unit Js . meth method terminate : unit Js . meth end |
type t = worker Js . t |
let start ( url : string ) ( dec : ' msg Decode . t ) ( cb : ' msg -> unit ) : t = let open Main in let w = new_global " Worker " [ | Value . string url ] | and cb event = send_message ( fun _ -> " cannot decode message from " ^ url ^ " " " ) \ ( Event . value event ) dec cb in Event_target . add " message " cb ( Obj .... |
let post_message ( msg : Value . t ) ( w : t ) : unit = w ## postMessage msg |
let terminate ( w : t ) : unit = w ## terminate |
type ' msg worker_function = ( Value . t -> unit ) -> ' msg -> unit |
let make ( decode : ' msg Decode . t ) ( f : ' msg worker_function ) : unit = let open Main in let post = match get_global " postMessage " with | None -> raise_js " webworker : < postMessage > function not available " | Some post -> post in let post = decode_callback ( fun _ -> " webworker : < postMessage > is not a fu... |
module Simulate = struct type t = ( Value . t -> unit ) option ref let start ( dec : ' rcv Decode . t ) ( cb : ' rcv -> unit ) ( worker_decode : ' msg Decode . t ) ( worker : ' msg worker_function ) : t = let post_to_creator v = send_message ( fun _ -> " main : cannot decode message from worker " ) v dec cb in let post... |
let simulate_js ( name : string ) ( decode : ' msg Decode . t ) ( wfun : ' msg worker_function ) : unit = let open Main in ( fun post -> let post_to_creator = decode_callback ( fun _ -> " webworker : < postMessage > is not a funtion " ) post in let w = Simulate . start ( fun v -> Decode . return v v ) post_to_creator d... |
let kasa_worker = Worker . create " KaSaWorker . js " in let kasa_mailbox = Kasa_client . new_mailbox ( ) in let kamoha_worker = Worker . create " KaMoHaWorker . js " in let kamoha_mailbox = Kamoha_client . new_mailbox ( ) in let kastor_worker = Worker . create " KaStorWorker . js " in let stor_state , update_stor_stat... |
type event_loadend = Web_json . t method abort : unit -> unit method getAllResponseHeaders : unit -> string Js . null method getResponseHeader : string -> string Js . null method _open : string -> string -> bool -> string -> string -> unit method overrideMimeType : string -> unit method send : unit -> unit method send_... |
type t = _xmlhttprequest Js . t |
type errors = | IncompleteResponse | NetworkError |
type body = | EmptyBody | EmptyStringBody | StringBody of string | FormDataBody of Web_formdata . t | FormListBody of ( string * string ) list | DocumentBody of Web_document . t |
let abort x = x ## abort ( ) |
let getAllResponseHeaders x = let open ! Tea_result in match Js . Null . toOption ( x ## getAllResponseHeaders ( ) ) with | None -> Error IncompleteResponse | Some " " -> Error NetworkError | Some s -> Ok s |
let getAllResponseHeadersAsList x = let open ! Tea_result in match getAllResponseHeaders x with | Error _ as err -> err | Ok s -> Ok ( s |> Js . String . split " \ r \ n " |> Array . map ( Js . String . splitAtMost " : " ~ limit : 2 ) |> Array . to_list |> List . filter ( fun a -> Array . length a == 2 ) |> List . map ... |
let getAllResponseHeadersAsDict x = let module StringMap = Map . Make ( String ) in match getAllResponseHeadersAsList x with | Tea_result . Error _ as err -> err | Tea_result . Ok l -> let insert d ( k , v ) = StringMap . add k v d in Tea_result . Ok ( List . fold_left insert StringMap . empty l ) |
let getResponseHeader key x = Js . Null . toOption ( x ## getResponse key ) |
let open_ method ' url ( ? async = true ) ( ? user " " ) = ( ? password " " ) = x = x ## _open method ' url async user password |
let overrideMimeType mimetype x = x ## overrideMimeType mimetype |
let send body x = match body with | EmptyBody -> x ## send ( ) | EmptyStringBody -> x ## send__string Js . Null . empty | StringBody s -> x ## send__string ( Js . Null . return s ) | FormDataBody f -> x ## send__formdata f | FormListBody l -> let form = List . fold_left ( fun f ( key , value ) -> let ( ) = Web_formdata... |
let setRequestHeader header value x = x ## setRequestHeader header value |
type state = | Unsent | Opened | HeadersReceived | Loading | Done |
type responseType = | StringResponseType | ArrayBufferResponseType | BlobResponseType | DocumentResponseType | JsonResponseType | TextResponseType | RawResponseType of string |
type responseBody = | NoResponse | StringResponse of string | ArrayBufferResponse of unit | BlobResponse of unit | DocumentResponse of Web_document . t | JsonResponse of Web_json . t | TextResponse of string | RawResponse of string * unit |
let set_onreadystatechange cb x = x ## onreadystatechange #= cb |
let get_onreadystatechange x = x ## onreadystatechange |
let readyState x = match x ## readystate with | 0 -> Unsent | 1 -> Opened | 2 -> HeadersReceived | 3 -> Loading | 4 -> Done | i -> failwith ( " Invalid return from ' readystate ' of : " ^ string_of_int i ) |
let set_responseType typ x = match typ with | StringResponseType -> x ## responseType #= " " | ArrayBufferResponseType -> x ## responseType #= " arraybuffer " | BlobResponseType -> x ## responseType #= " blob " | DocumentResponseType -> x ## responseType #= " document " | JsonResponseType -> x ## responseType #= " json... |
let get_responseType x = match x ## responseType with | " " -> StringResponseType | " arraybuffer " -> ArrayBufferResponseType | " blob " -> BlobResponseType | " document " -> DocumentResponseType | " json " -> JsonResponseType | " text " -> TextResponseType | s -> RawResponseType s |
let get_response x = match Js . Null . toOption x ## response with | None -> NoResponse | Some resp -> match get_responseType x with | StringResponseType -> StringResponse ( Obj . magic resp ) | ArrayBufferResponseType -> ArrayBufferResponse ( Obj . magic resp ) | BlobResponseType -> BlobResponse ( Obj . magic resp ) |... |
let get_responseText x = x ## responseText |
let get_responseURL x = x ## responseURL |
let get_responseXML x = Js . Null . toOption x ## responseXML |
let get_status x = x ## status |
let get_statusText x = x ## statusText |
let set_timeout t x = x ## timeout #= t |
let get_timeout x = x ## timeout |
let set_withCredentials b x = x ## withCredentials #= b |
let get_withCredentials x = x ## withCredentials |
let set_onabort cb x = x ## onabort #= cb |
let get_onabort x = x ## onabort |
let set_onerror cb x = x ## onerror #= cb |
let get_onerror x = x ## onerror |
let set_onload cb x = x ## onload #= cb |
let get_onload x = x ## onload |
let set_onloadstart cb x = x ## onloadstart #= cb |
let get_onloadstart x = x ## onloadstart |
let set_onprogress cb x = x ## onprogress #= cb |
let get_onprogress x = x ## onprogress |
let set_ontimeout cb x = x ## ontimeout #= cb |
let get_ontimeout x = x ## ontimeout |
let set_onloadend cb x = x ## onloadend #= cb |
let get_onloadend x = x ## onloadend |
let rec check_break_expr in_loop ( expr , _ ) = match expr with | VarExpr _ -> true | NilExpr -> true | IntExpr _ -> true | StringExpr _ -> true | CallExpr { call_args ; _ } -> List . for_all ( check_break_expr in_loop ) call_args | OpExpr { op_left ; op_right ; _ } -> check_break_expr in_loop op_left && check_break_ex... |
let assert_break expr = if not ( check_break_expr false expr ) then failwith " break outside of a loop " |
let compare_date ( i1 : Rss2 . item ) ( i2 : Rss2 . item ) = let open Rss2 in match i1 . pubDate , i2 . pubDate with | Some d1 , Some d2 -> Syndic . Date . compare d2 d1 | None , Some _ -> 1 | Some _ , None -> - 1 | None , None -> 0 |
let post = lazy ( let xml = ` String ( 0 , Http . get ( cwn_base_url ^ " cwn . rss " ) ) in let feed = Syndic . Rss2 . parse ( Xmlm . make_input xml ) in let posts = List . sort compare_date feed . Rss2 . items in match posts with p :: _ -> p | [ ] -> failwith " weekly_news : empty feed " ! ) |
let cwn_date = lazy ( match ( Lazy . force post ) . Rss2 . pubDate with | Some d -> d | None -> failwith " cwn_date " ) |
let cwn_html_date ( ) = let d = Lazy . force cwn_date in [ Nethtml . Data ( sprintf " % s % d , % d " ( Utils . en_string_of_month ( Date . month d ) ) ( Date . day d ) ( Date . year d ) ) ] |
let rec get_elements tag = function | [ ] -> [ ] | Nethtml . Data _ :: tl -> get_elements tag tl | Nethtml . Element ( t , _ , c ) :: tl -> let e = if t = tag then c else get_elements tag c in e @ get_elements tag tl |
let rec drop_until n tag = function | [ ] -> [ ] | Nethtml . Data _ :: tl -> drop_until n tag tl | ( Nethtml . Element ( t , _ , _ ) :: tl ) as l -> if t = tag then if n <= 1 then l else drop_until ( n - 1 ) tag tl else drop_until n tag tl |
let rec rm_tags tag = function | [ ] -> [ ] | ( Nethtml . Data _ as e ) :: tl -> e :: rm_tags tag tl | Nethtml . Element ( t , args , sub ) :: tl -> if t = tag then rm_tags tag tl else Nethtml . Element ( t , args , rm_tags tag sub ) :: rm_tags tag tl |
let cwn_html_page ( ) = let d = Lazy . force cwn_date in let url = cwn_base_url ^ sprintf " % d . % 02d . % 02d . html " ( Date . year d ) ( Utils . int_of_month ( Date . month d ) ) ( Date . day d ) in let content = Http . get url in let html = Nethtml . parse ( new Netchannels . input_string content ) ~ dtd : Utils .... |
let cwn_html_summary ( ) = match ( Lazy . force post ) . Rss2 . story with | Rss2 . All ( _ , _ , content ) -> let open Nethtml in Nethtml . parse ( new Netchannels . input_string content ) ~ dtd : Utils . relaxed_html40_dtd | Rss2 . Title _ | Rss2 . Description _ -> failwith " cwn_page " |
let ( ) = let contents = ref false in let date = ref false in let specs = [ ( " -- contents " , Arg . Set contents , " output the contents of the latest CWN " ) ; ( " -- date " , Arg . Set date , " output the date of the lastest CWN " ) ; ] in let usage = " weekly_news < option " > in Arg . parse ( Arg . align specs ) ... |
module Where = Dune_rpc_private . Where . Make ( struct type ' a t = ' a let return a = a module O = struct let ( let + ) x f = f x let ( let * ) x f = f x end end ) ( struct let read_file f = Ok ( Io . String_path . read_file f ) let analyze_path s = match ( Unix . stat s ) . st_kind with | Unix . S_SOCK -> Ok ` Unix_... |
let build_dir = lazy ( let build_dir = Path . Build . to_string Path . Build . root in match String . drop_prefix build_dir ~ prefix ( : Sys . getcwd ( ) ^ " " ) / with | None -> build_dir | Some s -> Filename . concat " . " s ) |
let get ( ) = let env = Env . get Env . initial in match Where . get ~ env ~ build_dir ( : Lazy . force build_dir ) with | Ok s -> s | Error exn -> User_error . raise [ Pp . text " Unable to find dune rpc address " ; Exn . pp exn ] |
let default ( ) = Where . default ~ build_dir ( : Lazy . force build_dir ) ( ) |
let to_socket = function | ` Unix p -> Unix . ADDR_UNIX p | ` Ip ( ` Host host , ` Port port ) -> Unix . ADDR_INET ( Unix . inet_addr_of_string host , port ) |
module Response = struct module Device_info = struct module Session_info = struct module Connection_info = struct type t = { ip : string option ; last_seen : int option ; user_agent : string option ; } [ @@ deriving accessor ] let encoding = let to_tuple t = t . ip , t . last_seen , t . user_agent in let of_tuple v = l... |
let shared_constants_class_name = " pack . ocamljavaConstants " |> UTF8 . of_string |> Name . make_for_class_from_external |> ref |
module ClassNameMap = Map . Make ( struct type t = Name . for_class let compare x y = Name . compare_for_class x y end ) end |
let constants_name_to_main_name : Name . for_class ClassNameMap . t ref = ref ClassNameMap . empty |
let constant_fields : ( Field . t list ) list ClassNameMap . t ref = ref ClassNameMap . empty |
let is_constants_class cn = ClassNameMap . mem cn ! constants_name_to_main_name |
let main_class_of_constants_class cn = ClassNameMap . find cn ! constants_name_to_main_name |
let additional_fields cn = try ClassNameMap . find cn ! constant_fields with Not_found -> [ ] inherit ClassTraversal . default_class_definition_iterator method ! class_definition ( _ : AccessFlag . for_class list ) list ( cn : Name . for_class ) for_class ( _ : Name . for_class option ) option ( _ : Name . for_class li... |
module IntSet = Set . Make ( struct type t = int let compare ( x : int ) int ( y : int ) int = Pervasives . compare x y end ) end |
let extract_ints l = List . fold_left ( fun acc elem -> match elem with | Annotation . Int_value x -> IntSet . add ( Int32 . to_int x ) x acc | _ -> assert false ) false IntSet . empty l |
let linked_classes : UTF8 . t list option ref = ref None |
type indices = { read_indices : IntSet . t ; written_indices : IntSet . t ; } |
let indices : ( UTF8 . t * indices ) indices list ClassNameMap . t ref = ref ClassNameMap . empty |
let merge_maps ( dst : indices ClassNameMap . t ) t ( name , uses ) uses = let class_name = Name . make_for_class_from_external name in let value = try let old = ClassNameMap . find class_name dst in { read_indices = IntSet . union old . read_indices uses . read_indices ; written_indices = IntSet . union old . written_... |
let get_used_indices ( ) = ClassNameMap . fold ( fun user used acc -> let merge = match ! linked_classes with | Some l -> List . exists ( fun x -> UTF8 . equal x ( Name . external_utf8_for_class user ) user ) user l | None -> false in if merge then begin List . fold_left merge_maps acc used end else acc ) acc ! indices... |
let make_remove_indices_function ( ) = let used_indices = get_used_indices ( ) in if ! Args . verbose then begin used_indices |> ClassNameMap . iter ( fun cn { read_indices ; written_indices } -> cn |> Name . external_utf8_for_class |> UTF8 . to_string |> Printf . printf " indices for % S :\ n " ; IntSet . iter ( Print... |
let iter_archive filename = let make_iterator x = new iterator x in ArchiveTraversal . iter_file make_iterator filename |
let shared_constants : UTF8 . Set . t ref = ref UTF8 . Set . empty |
let add_shared_constant name = shared_constants := UTF8 . Set . add ( Name . utf8_for_field name ) name ! shared_constants |
let empty_cstr = let code = Attribute ( { . max_stack = u2 1 ; max_locals = u2 1 ; code = [ Instruction . ALOAD_0 ; Instruction . INVOKESPECIAL ( Names . object_ , Misc . make_method_name " < init " , > ( [ ] , ` Void ) Void ) Void ; Instruction . RETURN ] ; exception_table = [ ] ; attributes = [ ] ; } ) in Method ( . ... |
let push_int32 = function | ( - 1l ) 1l -> Instruction . ICONST_M1 | 0l -> Instruction . ICONST_0 | 1l -> Instruction . ICONST_1 | 2l -> Instruction . ICONST_2 | 3l -> Instruction . ICONST_3 | 4l -> Instruction . ICONST_4 | 5l -> Instruction . ICONST_5 | n when n >= ( - 128l ) 128l && n <= 127l -> Instruction . BIPUSH ... |
let push_int64 = function | 0L -> [ Instruction . LCONST_0 ] | 1L -> [ Instruction . LCONST_1 ] | 2L -> [ Instruction . ICONST_2 ; Instruction . I2L ] | 3L -> [ Instruction . ICONST_3 ; Instruction . I2L ] | 4L -> [ Instruction . ICONST_4 ; Instruction . I2L ] | 5L -> [ Instruction . ICONST_5 ; Instruction . I2L ] | n ... |
let push_double x = if x = 0 . 0 then Instruction . DCONST_0 else if x = 1 . 0 then Instruction . DCONST_1 else Instruction . LDC2_W ( ` Double x ) x |
let compile_shared_constant_class ( ) = let fields_and_inits = List . map ( fun name -> let underscore = UTF8 . index_from name 0 ( UChar . of_char ' _ ' ) ' _ ' in let typ = UTF8 . substring name 0 ( pred underscore ) underscore in let hexa = UTF8 . substring name ( succ underscore ) underscore ( pred ( UTF8 . length ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.