text
stringlengths
12
786k
let is_bit_set ' bit x = is_bit_set x bit
let set_bit x bit = x lor ( one lsl ( Char . unsafe_chr bit ) )
let set_bit ' bit x = x lor ( one lsl ( Char . unsafe_chr bit ) )
let unset_bit x bit = x land ( lnot ( one lsl ( Char . unsafe_chr bit ) ) )
let unset_bit ' bit x = x land ( lnot ( one lsl ( Char . unsafe_chr bit ) ) )
let toggle_bit x bit = x lxor ( one lsl ( Char . unsafe_chr bit ) )
let show_hex x = Printf . sprintf " 0x % 02X " ( code x )
let show_hex ' x = Printf . sprintf " % 02X " ( code x )
let show_bin d = if d = zero then " 0 " else let rec aux acc d = if d = zero then acc else aux ( string_of_int ( code ( d land one ) ) :: acc ) ( d lsr one ) in String . concat " " ( aux [ ] d )
let get_n_bits x n = ( x lsl n ) lsr n
module MakeInfix ( B : Uints_intf . Basics ) : Uints_intf . Infix with type t := B . t = struct open B let ( + ) = add let ( - ) = sub let ( * ) = mul let ( / ) = div let ( = ) = equal let ( <> ) = ( fun a b -> not ( equal a b ) ) let ( <= ) = le let ( ...
module Uint8 = struct module B = struct type t = int let max_int = 0xFF let zero = 0 let one = 1 let compare = Int . compare let equal x y = compare x y = 0 let le x y = ( x <= y ) let add x y = ( x + y ) land max_int let sub x y = ( x - y ) land max_int let mul x y = ( x * y ) la...
module Uint16 = struct module B = struct type t = int let max_int = 0xFFFF let zero = 0 let one = 1 let compare = Int . compare let equal x y = compare x y = 0 let le x y = ( x <= y ) let add x y = ( x + y ) land max_int let sub x y = ( x - y ) land max_int let mul x y = ( x * y ) ...
module Int8 = struct type t = int let of_byte b = b let of_int x = if x < 0 then ( x land 0xFF ) lor 0b10000000 else ( x land 0xFF ) let is_neg t = t land ( 1 lsl 7 ) <> 0 let abs t = if is_neg t then ( t - 1 ) lxor 0b11111111 else t let to_int t = if is_neg t then ( - abs t ) el...
module type Basics = sig type t val show : t -> string val max_int : t val zero : t val one : t val compare : t -> t -> int val equal : t -> t -> bool val le : t -> t -> bool val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val rem : t -> t -> t val s...
module type Infix = sig type t val ( + ) : t -> t -> t val ( - ) : t -> t -> t val ( * ) : t -> t -> t val ( / ) : t -> t -> t val ( = ) : t -> t -> bool val ( <> ) : t -> t -> bool val ( <= ) : t -> t -> bool val ( mod ) : t -> t -> t val ( land ) : ...
module type S = sig type t include Basics with type t := t module Infix : Infix with type t := t include Infix with type t := t end
let toggle_element ( projection : Api_types_j . simulation_info option -> bool ) ( content : [ < Html_types . div_content_fun ] Html . elt Html . list_wrap ) = Html . div ~ a [ : Tyxml_js . R . Html . a_class ( React . S . bind State_simulation . model ( fun model -> Reac...
let option_label label = if String . length label > 10 then ( String . sub label 0 7 ) " . . . " ^ else label
let export_controls ( ~ export_select_id : string ) ( ~ export_filename_id : string ) ( ~ export_button_id : string ) ( ~ export_data_label : string ) = let export_formats : string list = [ export_data_label ] in let export_filename = Html . input ~ a [ : Html . a_id export_filen...
let label_news tab_is_active counter = let count = React . S . map ( fun model -> let simulation_info = State_simulation . t_simulation_info model in counter simulation_info ) State_simulation . model in let bip = ref React . E . never in let labels , set_labels = ReactiveData . RList . crea...
let badge ( counter : Api_types_j . simulation_info option -> int ) = let badge , badge_handle = ReactiveData . RList . create [ ] in let _ = React . S . map ( fun model -> let simulation_info = State_simulation . t_simulation_info model in let count = counter simulation_info in if coun...
let arguments ( key : string ) : string list = List . map snd ( List . filter ( fun ( k , _ ) -> key = k ) Url . Current . arguments )
let version ( ? test ' : a option = None ) ( ~ prod ' : a ) ( ~ dev ' : a ) ' : a = let version : string list = arguments " version " in match ( test , version ) with | ( Some test , [ " test " ] ) -> test | ( _ , [ " dev " ] ) -> dev | _ -> p...
let navli label force_class decorations = let default_attributes = [ Html . a_id ( " nav " ^ label ) ; Html . a_role [ " presentation " ] ] in let attributes = match force_class with | None -> default_attributes | Some l -> ( Tyxml_js . R . Html5 . a_class l ) :: default_att...
let navtabs nav_tab_id = function | [ ] | ( _ , Some _ , _ ) :: _ -> Common . toss " ui_common . navtabs : missing tabs " | ( ti , None , l ) :: t -> Html . ul ~ a [ : Html . a_id nav_tab_id ; Html . a_class [ " nav " ; " nav - tabs " ] ; Html . Un...
let onenavcontent label active classes content = Html . div ~ a [ : Html . a_id label ; Html . a_class ( if active then " flex - content " :: " tab - pane " :: " active " :: classes else " flex - content " :: " tab - pane " :: classes ) ; Html . Unsafe . string_attrib...
let navcontent ? id classes = function | [ ] -> Common . toss " ui_common . navcontent : missing content " | ( t , cl , c ) :: l -> let id : [ > ` Id ] Html . attrib list = match id with | None -> [ ] | Some id -> [ Html . a_id id ] in Html . div ~ a ( [ : Ht...
let level ? debug ? info ? notice ? warning ? error ? fatal ( ) : ' a list = let level : string list = arguments " level " in let extract key value = match value with | None -> [ ] | Some value -> if List . mem key level then [ value ] else [ ] in ( extract " debug " debug )...
let features ( ? default [ ] ) = ( options ( : string * ' a ) list ) : ' a list = let features : string list = arguments " feature " in let matches : ' a list = List . map snd ( List . filter ( fun ( feature , _ ) -> List . mem feature features ) options ) in ma...
let input_change input_dom signal_handler = input_dom . ## onchange := Dom_html . handler ( fun _ -> let ( ) = signal_handler ( Js . to_string ( input_dom . ## value ) ) in Js . _true )
module type Menu = sig val content : unit -> [ > ` Button | ` Div | ` Ul | ` A of [ > ` PCDATA | ` Span ] ] Tyxml_js . Html5 . elt list val onload : unit -> unit end ; ;
module type Div = sig val id : string val content : unit -> Html_types . div_content_fun Tyxml_js . Html . elt list val onload : unit -> unit end ; ;
module type Tab = sig val navli : unit -> Html_types . flow5_without_interactive Tyxml_js . Html5 . elt ReactiveData . RList . t val content : unit -> Html_types . div_content_fun Tyxml_js . Html5 . elt list val onload : unit -> unit val onresize : unit -> unit end ; ;
module type SubTab = sig include Tab val parent_hide : unit -> unit val parent_shown : unit -> unit end
module type Panel = sig val content : unit -> Html_types . div Tyxml_js . Html5 . elt val onload : unit -> unit val onresize : unit -> unit end ; ;
let id_dom ( id : string ) : ' a Js . t = Js . Unsafe . coerce ( ( Js . Opt . get ( document ## getElementById ( Js . string id ) ) ( fun ( ) -> Common . toss ( Format . sprintf " ui_common . id_dom : could not find id % s " id ) ) ) : Dom_html . element J...
let create_modal ( ~ id : string ) ( ~ title_label : string ) ( ~ body : [ < Html_types . div_content_fun ] Html . elt Html . list_wrap ) ( ~ submit_label : string ) ( ~ submit : ( ' self Js . t , _ Js . t ) Dom . event_listener ) : [ > Html_types . div ] ...
type token = | DEF | EXTERN | PLUS | MINUS | MUL | DIV | LPAREN | RPAREN | SEMI | COMMA | EOF | NUMBER of float | KWD of char | IDENT of string
let regexp newline = ( ' \ 010 ' | ' \ 013 ' | " \ 013 \ 010 ) "
let regexp blank = [ ' ' ' \ 009 ' ' \ 012 ' ] 012 '
let regexp blanks = blank +
let regexp lowercase = [ ' a ' - ' z ' ' \ 223 ' - ' \ 246 ' ' \ 248 ' - ' \ 255 ' ' _ ' ] ' _ '
let regexp uppercase = [ ' A ' - ' Z ' ' \ 192 ' - ' \ 214 ' ' \ 216 ' - ' \ 222 ' ] 222 '
let regexp whitespace = ( blank | newline ) newline
let regexp underscore = " _ "
let regexp tilde = " " ~
let regexp identchar = [ ' A ' - ' Z ' ' a ' - ' z ' ' _ ' ' \ 192 ' - ' \ 214 ' ' \ 216 ' - ' \ 246 ' ' \ 248 ' - ' \ 255 ' ' \ ' ' ' 0 ' - ' 9 ' ] ' 9 '
let regexp symbolchar = [ ' ! ' ' $ ' ' % ' ' & ' ' * ' ' + ' ' - ' ' . ' ' / ' ' : ' ' < ' ' = ' ' > ' ' ? ' ' @ ' ' ^ ' ' | ' ' ~ ' ] '
let regexp lident = lowercase identchar *
let regexp uidnet = uppercase identchar *
let regexp decimal_literal = [ ' 0 ' - ' 9 ' ] ' 9 ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' *
let regexp hex_literal = ' 0 ' [ ' x ' ' X ' ] ' X ' [ ' 0 ' - ' 9 ' ' A ' - ' F ' ' a ' - ' f ' ] ' f ' [ ' f ' ' 0 ' - ' 9 ' ' A ' - ' F ' ' a ' - ' f ' ' _ ' ] ' _ ' *
let regexp oct_literal = ' 0 ' [ ' o ' ' O ' ] ' O ' [ ' 0 ' - ' 7 ' ] ' 7 ' [ ' 0 ' - ' 7 ' ' _ ' ] ' _ ' *
let regexp bin_literal = ' 0 ' [ ' b ' ' B ' ] ' B ' [ ' 0 ' - ' 1 ' ] ' 1 ' [ ' 0 ' - ' 1 ' ' _ ' ] ' _ ' *
let regexp int_literal = decimal_literal | hex_literal | oct_literal | bin_literal
let regexp float_literal = [ ' 0 ' - ' 9 ' ] ' 9 ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' * ( ' . ' [ ' 0 ' - ' 9 ' ' _ ' ] ' _ ' * ) ? ( [ ' e ' ' E ' ] ' E ' [ ' + ' ' - ' ] ' ? [ ' 0 ' - ' 9 ' ] ' 9 ' [ ' 0 ' - ' 9 ' ' _ ' ] ...
let first = ref true
let rec alex pos = lexer | " ; " -> SEMI | ( " " -> LPAREN | ) " " -> RPAREN | " " + -> PLUS | " " - -> MINUS | " " * -> MUL | " " / -> DIV | " extern " -> EXTERN | " def " -> DEF | " , " -> COMMA | " \ n " -> new_line lexbuf pos ; alex pos lexbuf | float_literal ->...
let test filename = Legacy ( . let revised_parser = menhir_with_ulex alex main in let chan = open_in filename in let lexbuf = Ulexing . from_utf8_channel chan in handle_ulexing_error revised_parser lexbuf ; close_in chan )
let test_lexer filename = Legacy ( . let chan = open_in filename in let lexbuf = Ulexing . from_utf8_channel chan in let tokens = tokens_of_buf alex lexbuf in Stream . iter ( dump |- print_string |- print_newline ) print_newline tokens )
let _ = test " sample . py "
type separator = [ ` CR | ` LF | ` CRLF | ` NEL | ` LS | ` PS ] let sp = match op with ` CR -> [ UChar . chr_of_uint 0x000d ] 0x000d | ` LF -> [ UChar . chr_of_uint 0x000a ] 0x000a | ` CRLF -> [ UChar . chr_of_uint 0x000d ; UChar . chr_of_uint 0x000a ] 0x000a...
module type Type = sig type text class input_line : UChar . t # obj_input_channel -> [ text ] text obj_input_channel class output_line : ? sp [ ` : CR | ` CRLF | ` LF | ` LS | ` NEL | ` PS ] PS -> UChar . t # obj_output_channel -> [ text ] text obj_output_channel end
module Make ( Text : UnicodeString . Type ) Type = struct type text = Text . t class input_line inchan = object val b = Text . Buf . create 0 val mutable wait = false method get ( get ) get = Text . Buf . clear b ; let rec loop ( ) = let x = wait in wait <- false ; match UChar . uint_cod...
let umap_of_imap m = m
let imap_of_umap m = m
let add ? eq u v m = IMap . add ? eq ( UChar . uint_code u ) u v m
let add_range ? eq u1 u2 v m = IMap . add_range ? eq ( UChar . uint_code u1 ) u1 ( UChar . uint_code u2 ) u2 v m
let find u m = IMap . find ( UChar . uint_code u ) u m
let remove u m = IMap . remove ( UChar . uint_code u ) u m
let remove_range u1 u2 m = IMap . remove_range ( UChar . uint_code u1 ) u1 ( UChar . uint_code u2 ) u2 m
let from u m = IMap . from ( UChar . uint_code u ) u m
let after u m = IMap . after ( UChar . uint_code u ) u m
let until u m = IMap . until ( UChar . uint_code u ) u m
let before u m = IMap . before ( UChar . uint_code u ) u m
let mem u m = IMap . mem ( UChar . uint_code u ) u m
let iter f m = let f ' n = f ( UChar . chr_of_uint n ) n in IMap . iter f ' m
let iter_range f m = let f ' n1 n2 = f ( UChar . chr_of_uint n1 ) n1 ( UChar . chr_of_uint n2 ) n2 in IMap . iter_range f ' m
let fold f m a = let f ' n v a = f ( UChar . chr_of_uint n ) n v a in IMap . fold f ' m a
let fold_range f m a = let f ' n1 n2 v a = f ( UChar . chr_of_uint n1 ) n1 ( UChar . chr_of_uint n2 ) n2 v a in IMap . fold_range f ' m a
let mapi ? eq f m = let f ' n v = f ( UChar . chr_of_uint n ) n v in IMap . mapi ? eq f ' m
let set_to_map s = IMap . set_to_map ( USet . iset_of_uset s ) s
let domain m = USet . uset_of_iset ( IMap . domain m ) m
let map_to_set p m = USet . uset_of_iset ( IMap . map_to_set p m ) m
module UnannotatedDefine = struct type t = { define : Define . Signature . t ; location : Location . WithModule . t ; } [ @@ deriving sexp , compare ] end
module ImportEntry = struct type t = | Module of { target : Reference . t ; implicit_alias : bool ; } | Name of { from : Reference . t ; target : Identifier . t ; implicit_alias : bool ; } [ @@ deriving sexp , compare ] let deprecated_original_name = function | Module { targe...
type t = | SimpleAssign of { explicit_annotation : Expression . t option ; value : Expression . t ; target_location : Location . WithModule . t ; } | TupleAssign of { value : Expression . t ; target_location : Location . WithModule . t ; index : int ; total_length : int ; } ...
module Collector = struct module Result = struct type unannotated_global = t [ @@ deriving sexp , compare ] type t = { name : Identifier . t ; unannotated_global : unannotated_global ; } [ @@ deriving sexp , compare ] end let from_source { Source . statements ; source_path = { Mod...
module ResolvedReference = struct type export = | FromModuleGetattr | Exported of Module . Export . Name . t [ @@ deriving sexp , compare , hash ] type t = | Module of Reference . t | ModuleAttribute of { from : Reference . t ; name : Identifier . t ; export : export ; remaining ...
let missing_builtin_globals = let assign name annotation = { UnannotatedGlobal . Collector . Result . name ; unannotated_global = UnannotatedGlobal . SimpleAssign { explicit_annotation = Some ( Type . expression annotation ) ; target_location = Location . WithModule . any ; value = Nod...
let missing_builtin_classes , missing_typing_classes , missing_typing_extensions_classes = let make ( ? bases = [ ] ) ( ? metaclasses = [ ] ) ( ? body = [ ] ) name = let create_base annotation = { Call . Argument . name = None ; value = Type . expression annotation } i...
module KeyTracker = struct module ClassKeyValue = struct type t = Identifier . t list [ @@ deriving compare ] let prefix = Prefix . make ( ) let description = " Class keys " end module DefineKeyValue = struct type t = Reference . t list [ @@ deriving compare ] let prefix = Prefix . mak...
module ModuleValue = struct type t = Module . t let prefix = Prefix . make ( ) let description = " Module " let compare = Module . compare end
module Modules = struct include DependencyTrackedMemory . DependencyTrackedTableWithCache ( SharedMemoryKeys . ReferenceKey ) ( DependencyKey ) ( ModuleValue ) let is_qualifier = true let key_to_reference = Fn . id end
module ClassSummaryValue = struct type t = ClassSummary . t Node . t let prefix = Prefix . make ( ) let description = " ClassSummary " let compare = Node . compare ClassSummary . compare end
module ClassSummaries = struct include DependencyTrackedMemory . DependencyTrackedTableWithCache ( SharedMemoryKeys . StringKey ) ( DependencyKey ) ( ClassSummaryValue ) let is_qualifier = false let key_to_reference name = Reference . create name end
module FunctionDefinitionValue = struct type t = FunctionDefinition . t let description = " FunctionDefinition " let prefix = Prefix . make ( ) let compare = FunctionDefinition . compare end
module FunctionDefinitions = struct include DependencyTrackedMemory . DependencyTrackedTableWithCache ( SharedMemoryKeys . ReferenceKey ) ( DependencyKey ) ( FunctionDefinitionValue ) let is_qualifier = false let key_to_reference = Fn . id end
module UnannotatedGlobalValue = struct type t = UnannotatedGlobal . t let prefix = Prefix . make ( ) let description = " UnannotatedGlobal " let compare = UnannotatedGlobal . compare end