text
stringlengths
0
601k
let not16 x = mod16 ( lnot x )
let s = Array . init 4 ( function 0 -> 1 | 1 -> 2 | 2 -> 3 | 3 -> 5 | _ -> assert false )
let pmod a = let b = 4 in let r = a mod b in if r < 0 then ( r + b ) mod b else r
let r_mix r i k j = r . ( i ) <- ror16 r . ( i ) s . ( i ) ; r . ( i ) <- mod16 ( r . ( i ) - k . ( j ) - ( r . ( pmod ( i - 1 ) ) land r . ( pmod ( i - 2 ) ) ) - ( not16 r . ( pmod ( i - 1 ) ) land ( r . ( pmod ( i - 3 ) ) ) ) ) ; pred j
let r_mix_round r k j = let j ' = r_mix r 3 k j in let j ' ' = r_mix r 2 k j ' in let j ' ' ' = r_mix r 1 k j ' ' in let j ' ' ' ' = r_mix r 0 k j ' ' ' in j ' ' ' '
let r_mash r i k = r . ( i ) <- mod16 ( r . ( i ) - k . ( r . ( pmod ( i - 1 ) ) land 63 ) )
let r_mash_round r k = r_mash r 3 k ; r_mash r 2 k ; r_mash r 1 k ; r_mash r 0 k
let decrypt_one ~ key ~ data ( ? off = 0 ) dst = let r = Array . init 4 ( fun idx -> Cstruct . LE . get_uint16 data ( off + idx * 2 ) ) in let j = 63 in let j = r_mix_round r key j in let j = r_mix_round r key j in let j = r_mix_round r key j in let j = r_mix_round r key j in let j = r_mix_round r key j in r_mash_round...
let decrypt_cbc ( ? effective = 128 ) ~ key ~ iv data = let block = 8 in let key = key_expansion effective key in let l = Cstruct . length data in let dst = Cstruct . create l in for i = 0 to pred ( ( l + pred block ) / block ) do decrypt_one ~ key ~ data ~ off ( : i * block ) dst done ; Mirage_crypto . Uncommon . Cs ....
let selection_changed = new selection_changed ( ) in let vbox = GPack . vbox ~ spacing : 5 ? packing ( ) in let cols = new GTree . column_list in let col_data = cols # add Gobject . Data . caml in let col_name = cols # add Gobject . Data . string in let col_default = cols # add Gobject . Data . boolean in let model = G...
let create_entry ? label ~ packing ( ) = let vbox = GPack . vbox ~ packing ( ) in Gaux . may label ~ f ( : fun markup -> GMisc . label ~ markup ~ xalign : 0 . 0 ~ packing : vbox # pack ( ) ) ; GEdit . entry ~ packing : vbox # pack ( ) let vbox = GPack . vbox ~ spacing : 8 ? packing ( ) in let title = GMisc . label ~ ma...
let unquote = let re = Str . regexp " " ( . ) " " ^\\\*\\\$ in fun x -> if Str . string_match re x 0 then Str . matched_group 1 x else x
let get_command_output command = let ch = Unix . open_process_in command in set_binary_mode_in ch false ; let output = ref [ ] in try while true do output := ( input_line ch ) :: ! output done ; assert false with End_of_file -> begin ignore ( Unix . close_process_in ch ) ; List . rev ! output end | e -> begin ignore ( ...
let is_mingw = List . exists ( ( ) = " system : mingw " ) ( get_command_output " ocamlc - config " )
let _ = if not Sys . win32 || is_mingw then exit 0 ; ;
let resources = [ " launcher " , ( " . \\ ocamleditorw . resource . rc " , " \ " ocamleditor - msvc " , ( " . \\ ocamleditor . opt . resource . rc " , " \ ]
let _ = let exit_code = Sys . command " where rc 1 > NUL " in if exit_code <> 0 then failwith " Cannot find ' rc ' command . " ; let exit_code = Sys . command " where cvtres 1 > NUL " in if exit_code <> 0 then failwith " Cannot find ' cvtres ' command . " ; let rcname , rc = try List . assoc Sys . argv . ( 1 ) resource...
module type Data_intf = sig type key type t val to_key : t -> key val copy : t -> t end
module type S = sig type key type data type t val create : ? growth_allowed : bool -> ? size : int -> unit -> t val save : t -> data -> unit val free : t -> key -> unit val find : t -> key -> data option end
module Make ( Key : Hashable . S ) S ( Data : Data_intf with type key := Key . t ) t : S with type key := Key . t and type data := Data . t = struct type t = ( Data . t * int ) int Key . Table . t let create = Key . Table . create let save t data = let key = Data . to_key data in Key . Table . change t key ~ f ( : func...
type ' body t = { version : Code . version ; meth : Code . meth ; uri : Uri . t ; req_headers : Header . t ; req_body : ' body ; resp_headers : Header . t ; resp_body : ' body ; resp_redirect : bool ; dispatch_path : string ; path_info : ( string * string ) list } constraint ' body = [ > ` Empty ]
let make ( ? dispatch_path " " ) = ( ? path_info [ ] ) = ( ? resp_headers = Header . init ( ) ) ( ? resp_body ` = Empty ) ( ? resp_redirect = false ) ( ? req_body ` = Empty ) ~ request ( ) = { uri = Uri . of_string request . Request . resource ; version = request . Request . version ; meth = request . Request . meth ; ...
let with_req_headers f t = { t with req_headers = f t . req_headers }
let with_resp_headers f t = { t with resp_headers = f t . resp_headers }
let lookup_path_info_exn key t = List . assoc key t . path_info
let lookup_path_info key t = try Some ( lookup_path_info_exn key t ) with Not_found -> None
let redirect location t = with_resp_headers ( fun header -> Header . add header " location " location ) { t with resp_redirect = true }
let f x = match x with | _ -> ( ) | exception _ -> . ; ; [ %% expect { | ^ Here is an example of a value that would reach it : _ } ] | ; ;
let f x = match x with | _ -> ( ) | None | exception _ -> . ; ; [ %% expect { | ^ Here is an example of a value that would reach it : _ } ] | ; ;
let f x = match x with | _ -> ( ) | exception Not_found | None -> . ; ; [ %% expect { | ^^^^^^^^^ Here is an example of a value that would reach it : Not_found } ] | ; ;
let f x = match x with | _ | exception _ -> ( ) | exception Not_found -> . ; ; [ %% expect { | } ] | ; ;
module type S = sig type t type ' a offer val empty : t val with_CAS : t -> PostCommitCas . t -> t val with_offer : t -> ' a offer -> t val try_commit : t -> bool val cas_count : t -> int val has_offer : t -> ' a offer -> bool val union : t -> t -> t val with_post_commit : t -> ( unit -> unit ) -> t end
module Make ( Sched : Scheduler . S ) : S with type ' a offer = ' a Offer . Make ( Sched ) . t = struct module Offer = Offer . Make ( Sched ) type ' a offer = ' a Offer . t module IntSet = Set . Make ( struct type t = int let compare = compare end ) type t = { cases : PostCommitCas . t list ; offers : IntSet . t ; post...
type ' a javascript_object = ' a Js . t
type ' a component_api = ( < isMounted : bool Js . t Js . meth ; . . > as ' a ) Js . t
module Infix = struct let ( !@ ) = Js . wrap_meth_callback let ( !^ ) = Js . Unsafe . inject let ( <!> ) ( obj : ' a Js . t ) field = Js . Unsafe . get obj ( Js . string field ) let ( <?> ) ( obj : ' a Js . t ) field = Js . Opt . ( obj <!> field |> return |> to_option ) let ( <@> ) ( obj : ' a Js . t ) field = Js . Opt...
module Helpers = struct let set_interval ~ f ~ every = Dom_html . window ## setInterval ( Js . wrap_callback f ) every let get_elem ~ id = Dom_html . getElementById id let debug thing field = Firebug . console ## log ( Js . Unsafe . ( meth_call ( get thing field ) " toString " [ ] ) ) || let real_type_name ( o : ' a Js...
module Low_level_bindings = struct class type react_dom_server = object method renderToString : react_element Js . t -> Js . js_string Js . t Js . meth method renderToStaticMarkup : react_element Js . t -> Js . js_string Js . t Js . meth end and react_dom = object method render : react_element Js . t -> # Dom_html . el...
type element_spec = { class_name : string option ; } [ @@ deriving make ]
type react_node = | Text of string | Elem of Low_level_bindings . react_element Js . t
type tree = react_node list
type ( ' this , ' initial_state , ' default_props , ' prop_types , ' static_functions , ' next_props , ' next_state , ' prev_props , ' prev_state , ' props , ' mixin ) class_spec = { render : this ' : this component_api -> Low_level_bindings . react_element Js . t ; [ @ main ] initial_state : ( this ' : this component_...
let create_element : ? element_opts : element_spec -> string -> tree -> Low_level_bindings . react_element Js . t = fun ? element_opts elem_name children -> Js . Unsafe . ( let g = children |> List . map ~ f ( : function | Elem e -> inject e | Text s -> Js . string s |> inject ) in [ [ | inject ( Js . string elem_name ...
let create_element_from_class class_ = Low_level_bindings . react ## createElement_WithReactClass class_ Js . null
let create_factory : Low_level_bindings . react_class Js . t -> ( props ' : a Js . t -> Low_level_bindings . react_element Js . t ) = fun c -> let call_me = Low_level_bindings . react ## createFactory c in fun ~ props -> Js . Unsafe . fun_call call_me [ | Js . Unsafe . inject props ] |
let create_class class_opts = let open Js . Optdef in let comp = ( object % js val render = Js . wrap_meth_callback ( fun this -> class_opts . render ~ this ) val getInitialState = ( fun f -> Js . wrap_meth_callback ( fun this -> f ~ this ) ) |> map ( option class_opts . initial_state ) val getDefaultProps = ( fun f ->...
let elem_from_spec spec = create_element_from_class ( create_class spec )
let render ~ react_elem dom_elem = Low_level_bindings . react_dom ## render react_elem dom_elem
let ( react , react_dom , react_dom_server ) = Low_level_bindings . react , Low_level_bindings . react_dom , Low_level_bindings . react_dom_server
module DOM = struct type tag = [ ` a | ` abbr | ` address | ` area | ` article | ` aside | ` audio | ` b | ` base | ` bdi | ` bdo | ` big | ` blockquote | ` body | ` br | ` button | ` canvas | ` caption | ` cite | ` code | ` col | ` colgroup | ` data | ` datalist | ` dd | ` del | ` details | ` dfn | ` dialog | ` div | ...
module Common_components = struct let stylesheet ? custom_opts ~ href ( ) = Infix . ( let attrs = object % js val ref = " !* stylesheet " val href = !* href end in match custom_opts with None -> Elem ( DOM . make ~ elem_spec : attrs ~ tag ` : link [ ] ) | Some custom -> Elem ( DOM . make ~ elem_spec ( : attrs <+> custo...
let labelled str = Ast_404 . Asttypes . Labelled str
let argIsKeyRef = function | ( Asttypes . Labelled ( " key " | " ref ) " , _ ) _ | ( Asttypes . Optional ( " key " | " ref ) " , _ ) _ -> true | _ -> false
let constantString ~ loc str = Ast_helper . Exp . constant ~ loc ( Parsetree . Pconst_string ( str , None ) None ) None # else
let labelled str = str
let argIsKeyRef = function | ( ( " key " | " ref ) " , _ ) _ | ( ( " ? key " | " ? ref ) " , _ ) _ -> true | _ -> false
let constantString ~ loc str = Ast_helper . Exp . constant ~ loc ( Asttypes . Const_string ( str , None ) None ) None # end
let transformChildren ~ loc ~ mapper theList = let rec transformChildren ' theList accum = match theList with | { pexp_desc = Pexp_construct ( { txt = Lident [ ] } " " , None ) None } None -> List . rev accum |> Exp . array ~ loc | { pexp_desc = Pexp_construct ( { txt = Lident } " " , :: Some { pexp_desc = Pexp_tuple (...
let extractChildrenForDOMElements ( ? removeLastPositionUnit = false ) false ~ loc propsAndChildren = let rec allButLast_ lst acc = match lst with | [ ] -> [ ] | ( Nolabel , { pexp_desc = Pexp_construct ( { txt = Lident ( ) } " " , None ) None } None ) None [ ] :: -> acc | ( Nolabel , _ ) _ :: rest -> raise ( Invalid_a...
let jsxMapper ( ) = let jsxTransformV3 modulePath mapper loc attrs callExpression callArguments = let ( children , argsWithLabels ) argsWithLabels = extractChildrenForDOMElements ~ loc ~ removeLastPositionUnit : true callArguments in let ( argsKeyRef , argsForMake ) argsForMake = List . partition argIsKeyRef argsWithLa...
module Js = struct module Unsafe = struct type any external inject : ' a -> any = " % identity " external get : ' a -> ' b -> ' c = " caml_js_get " external set : ' a -> ' b -> ' c -> unit = " caml_js_set " external pure_js_expr : string -> ' a = " caml_pure_js_expr " let global = pure_js_expr " joo_global_object " ext...
let rewrite code = let mapper = jsxMapper ( ) in Location . input_name := " // toplevel " ; // try let lexer = Lexing . from_string code in let pstr = Parse . implementation lexer in let pstr = mapper . structure mapper pstr in let buffer = Buffer . create 1000 in Pprintast . structure Format . str_formatter pstr ; let...
let export ( field : string ) string v = Js . Unsafe . set ( Js . Unsafe . global ) global field v
let make_ppx name = export name ( Js . Unsafe ( . obj [ " | rewrite " , inject @@ Js . wrap_meth_callback ( fun _ code -> rewrite ( Js . to_string code ) code ) code ; ] ) ) |
let ( ) = make_ppx " jsxv2 "
let ( ) = Compiler_libs . Ast_mapper . register " JSX " ( fun _argv -> jsxMapper ( ) ) # else
let ( ) = Ast_mapper . register " JSX " ( fun _argv -> jsxMapper ( ) ) # end
let labelled str = Ast_411 . Asttypes . Labelled str
let argIsKeyRef = function | ( Asttypes . Labelled ( " key " | " ref " ) , _ ) | ( Asttypes . Optional ( " key " | " ref " ) , _ ) -> true | _ -> false
let constantString ~ loc str = Ast_helper . Exp . constant ~ loc ( Parsetree . Pconst_string ( str , loc , None ) )
let transformChildrenIfList ~ loc ~ mapper theList = let rec transformChildren_ theList accum = match theList with | { pexp_desc = Pexp_construct ( { txt = Lident " [ ] " } , None ) } -> List . rev accum |> Exp . array ~ loc | { pexp_desc = Pexp_construct ( { txt = Lident " " } , :: Some { pexp_desc = Pexp_tuple ( v ::...
let extractChildren ( ? removeLastPositionUnit = false ) ~ loc propsAndChildren = let rec allButLast_ lst acc = match lst with | [ ] -> [ ] | ( Nolabel , { pexp_desc = Pexp_construct ( { txt = Lident " ( ) " } , None ) } ) [ ] :: -> acc | ( Nolabel , _ ) :: _ -> raise ( Invalid_argument " JSX : found non - labelled arg...
let jsxMapper ( ) = let jsxVersion = ref None in let transformUppercaseCall modulePath mapper loc attrs _ callArguments = let ( children , argsWithLabels ) = extractChildren ~ loc ~ removeLastPositionUnit : true callArguments in let ( argsKeyRef , argsForMake ) = List . partition argIsKeyRef argsWithLabels in let child...
let rewrite code = let mapper = jsxMapper ( ) in Location . input_name := " // toplevel " ; // try let lexer = Lexing . from_string code in let pstr = Parse . implementation lexer in let pstr = mapper . structure mapper pstr in let buffer = Buffer . create 1000 in Pprintast . structure Format . str_formatter pstr ; let...
let export ( field : string ) v = Js . Unsafe . set ( Js . Unsafe . global ) field v
let make_ppx name = export name ( Js . Unsafe . ( obj [ " | rewrite " , inject @@ Js . wrap_meth_callback ( fun _ code -> rewrite ( Js . to_string code ) ) ; ] ) ) |
let ( ) = make_ppx " jsxv2 " ) *
let ( ) = Compiler_libs . Ast_mapper . register " JSX " ( fun _argv -> jsxMapper ( ) )
let rec find_opt p = function [ ] -> None | x :: l -> if p x then Some x else find_opt p l
let labelled str = Labelled str
let optional str = Optional str
let isOptional str = match str with Optional _ -> true | _ -> false
let isLabelled str = match str with Labelled _ -> true | _ -> false
let getLabel str = match str with Optional str | Labelled str -> str | Nolabel -> " "
let optionIdent = Lident " option "
let constantString ~ loc str = Ast_helper . Exp . constant ~ loc ( Pconst_string ( str , Location . none , None ) )
let safeTypeFromValue valueStr = let valueStr = getLabel valueStr in match String . sub valueStr 0 1 with " _ " -> " T " ^ valueStr | _ -> valueStr [ @@ raises Invalid_argument ]
let keyType loc = Typ . constr ~ loc { loc ; txt = optionIdent } [ Typ . constr ~ loc { loc ; txt = Lident " string " } [ ] ]
type ' a children = ListLiteral of ' a | Exact of ' a
type componentConfig = { propsName : string }
let transformChildrenIfListUpper ~ loc ~ mapper theList = let rec transformChildren_ theList accum = match theList with | { pexp_desc = Pexp_construct ( { txt = Lident " [ ] " } , None ) } -> ( match accum with | [ singleElement ] -> Exact singleElement | accum -> ListLiteral ( Exp . array ~ loc ( List . rev accum ) ) ...
let transformChildrenIfList ~ loc ~ mapper theList = let rec transformChildren_ theList accum = match theList with | { pexp_desc = Pexp_construct ( { txt = Lident " [ ] " } , None ) } -> Exp . array ~ loc ( List . rev accum ) | { pexp_desc = Pexp_construct ( { txt = Lident " " :: } , Some { pexp_desc = Pexp_tuple [ v ;...
let extractChildren ( ? removeLastPositionUnit = false ) ~ loc propsAndChildren = let rec allButLast_ lst acc = match lst with | [ ] -> [ ] | [ ( Nolabel , { pexp_desc = Pexp_construct ( { txt = Lident " ( ) " } , None ) } ) ] -> acc | ( Nolabel , _ ) :: _rest -> raise ( Invalid_argument " JSX : found non - labelled ar...
let unerasableIgnore loc = { attr_name = { loc ; txt = " warning " } ; attr_payload = PStr [ Str . eval ( Exp . constant ( Pconst_string ( " - 16 " , Location . none , None ) ) ) ] ; attr_loc = loc ; }
let merlinFocus = { attr_name = { loc = Location . none ; txt = " merlin . focus " } ; attr_payload = PStr [ ] ; attr_loc = Location . none ; }
let hasAttr { attr_name = loc ; _ } = loc . txt = " react . component "
let otherAttrsPure { attr_name = loc ; _ } = loc . txt <> " react . component "
let hasAttrOnBinding { pvb_attributes } = find_opt hasAttr pvb_attributes <> None
let getFnName binding = match binding with | { pvb_pat = { ppat_desc = Ppat_var { txt } } } -> txt | _ -> raise ( Invalid_argument " react . component calls cannot be destructured . " ) [ @@ raises Invalid_argument ]
let makeNewBinding binding expression newName = match binding with | { pvb_pat = { ppat_desc = Ppat_var ppat_var } as pvb_pat } -> { binding with pvb_pat = { pvb_pat with ppat_desc = Ppat_var { ppat_var with txt = newName } } ; pvb_expr = expression ; pvb_attributes = [ merlinFocus ] ; } | _ -> raise ( Invalid_argument...