text
stringlengths
0
601k
let test_concurrent_workload ( ) = let n = ref 100000 in let attempts = 100000 in let thieves = 16 in let q = create ( ) in let c = ref 0 in let fresh ( ) = let x = ! c in c := x + 1 ; x in let pushed = ref [ ] and popped = ref [ ] and stolen = Array . make thieves [ ] in let owner = Domain . spawn begin fun ( ) -> let...
let _ = test_empty ( ) ; test_push_and_pop ( ) ; test_push_and_steal ( ) ; test_concurrent_workload ( ) ;
module Vertex = struct type t = string let compare = Stdlib . compare let hash = Hashtbl . hash let equal = ( = ) end
module G = Persistent . Digraph . Concrete ( Vertex )
module Wto = WeakTopological . Make ( G )
let rec print_element = function | WeakTopological . Vertex v -> print_string v | WeakTopological . Component ( head , components ) -> print_string " ( " ; print_string head ; print_string " " ; print_components components ; print_string " ) " WeakTopological . fold_left ( fun ( ) elem -> print_element elem ; print_str...
let edges = [ " 1 " , " 4 " ; " 1 " , " 2 " ; " 2 " , " 3 " ; " 3 " , " 6 " ; " 4 " , " 1 ' " ; " 5 " , " 6 " ; " 6 " , " 5 ' " ; " 1 ' " , " 2 ' " ; " 1 ' " , " 4 ' " ; " 2 ' " , " 3 ' " ; " 3 ' " , " 6 ' " ; " 4 ' " , " 1 " ; " 5 ' " , " 6 ' " ; " 6 ' " , " 5 " ; ]
let g = List . fold_left ( fun acc ( v , w ) -> G . add_edge acc v w ) G . empty edges
let result = Wto . recursive_scc g " 1 "
let ( ) = print_components result
let start_element name = ` Start_element ( ( " " , name ) , [ ] )
let no_custom_entities = fun _ -> None
let no_top_level_namespaces = fun _ -> None
let expect ? context ( ? namespace = no_top_level_namespaces ) text signals = let report , iterate , ended = expect_signals signal_to_string text signals in text |> Markup__Stream_io . string |> Markup__Encoding . utf_8 |> Markup__Input . preprocess is_valid_xml_char Error . ignore_errors |> Markup__Xml_tokenizer . tok...
let tests = [ ( " xml . parser . empty " >:: fun _ -> expect " " [ ] ) ; ( " xml . parser . document " >:: fun _ -> expect " < root > foo </ root " > [ 1 , 1 , S ( start_element " root " ) ; 1 , 7 , S ( ` Text [ " foo " ] ) ; 1 , 10 , S ` End_element ] ; expect " < root > foo </ root > " [ 1 , 3 , S ( start_element " r...
let xml_decl version encoding standalone = ` Xml { version ; encoding ; standalone }
let raw_doctype s = ` Doctype { doctype_name = None ; public_identifier = None ; system_identifier = None ; raw_text = Some s ; force_quirks = false }
let tag ( ? self_closing = false ) name attributes = { Token_tag . name ; attributes ; self_closing }
let no_custom_entities = fun _ -> None
let expect ( ? entity = no_custom_entities ) text signals = let report , iterate , ended = expect_signals token_to_string text signals in text |> Markup__Stream_io . string |> Markup__Encoding . utf_8 |> Markup__Input . preprocess is_valid_xml_char Error . ignore_errors |> Markup__Xml_tokenizer . tokenize report entity...
let xml = " xml declaration "
let pi = " processing instruction "
let tests = [ ( " xml . tokenizer . empty " >:: fun _ -> expect " " [ 1 , 1 , S ` EOF ] ) ; ( " xml . tokenizer . whitespace " >:: fun _ -> expect " \ t \ n \ x09 \ x0d \ x0d \ x0a " [ 1 , 1 , S ( ` Chars [ " \ t \ n \ x09 \ x0a \ x0a " ] ) ; 4 , 2 , S ` EOF ] ) ; ( " xml . tokenizer . text " >:: fun _ -> expect " foo ...
let no_prefixes = fun _ -> None
let expect ( ? prefix = no_prefixes ) id signals strings = let report , iterate , ended = expect_strings id strings in signals |> Markup__Kstream . of_list |> Markup__Xml_writer . write report prefix |> iter iterate ; ended ( )
let tests = [ ( " xml . writer . empty " >:: fun _ -> expect " empty " [ ] [ ] ) ; ( " xml . writer . text " >:: fun _ -> expect " text " [ ` Text [ " foo " ] ] [ S " foo " ] ; expect " adjacent text " [ ` Text [ " foo " ] ; ` Text [ " bar " ] ] [ S " foo " ; S " bar " ] ; expect " empty text " [ ` Text [ " " ] ] [ ] )...
let with_connection f = let h = Hidapi . open_id_exn ~ vendor_id ~ product_id in try match f h with | Result . Ok ( ) -> Hidapi . close h | Result . Error e -> failwith ( Format . asprintf " Ledger error : % a " Ledgerwallet . Transport . pp_error e ) with exn -> Hidapi . close h ; raise exn
let test_open_close ( ) = with_connection ( fun _ -> R . ok ( ) )
let test_ping ( ) = with_connection Ledgerwallet . Transport . ping
let hard x = Int32 . logor x 0x8000_0000l
let test_getversion ( ) = with_connection begin fun h -> get_version h >>| fun ( ma , mi , pa ) -> Printf . printf " % d . % d . % d " ma mi pa end
let test_getpk ~ display_addr ( ) = with_connection begin fun h -> get_pk ~ display_addr h 0l >>| fun ( pk , addr ) -> match Bech32 . Segwit . encode addr with | Error msg -> fail msg | Ok v -> Format . printf " % a % s " Hex . pp ( Hex . of_cstruct pk ) v end
let basic = [ " version " , ` Quick , test_getversion ; " getaddr " , ` Quick , ( test_getpk ~ display_addr : true ) ; ]
let ( ) = Alcotest . run " ledgerwallet . zil " [ " basic " , basic ; ]
module type Input_intf = sig val snapp_update : Party . Update . t val test_description : string val failure_expected : Mina_base . Transaction_status . Failure . t end
module Make ( Input : Input_intf ) Input_intf = struct open Input let ` VK vk , ` Prover snapp_prover = Lazy . force U . trivial_zkapp let memo = Signed_command_memo . create_from_string_exn test_description let % test_unit " update a snapp account with signature " = Quickcheck . test ~ trials : 1 U . gen_snapp_ledger ...
let ctx = Zmq . Context . create ( )
let create_zmq_client data = if Unix . fork ( ) = 0 then begin try let socket = Zmq . Socket . create ctx Zmq . Socket . req in Zmq . Socket . connect socket " tcp :// 127 . 0 . 0 . 1 : 5555 " ; Zmq . Socket . send_all socket data ; let _ = Zmq . Socket . recv socket in Zmq . Socket . close socket ; exit 0 with exn -> ...
let test_recv_send ctxt = let expected = [ " This " ; " is " ; " ZeroMQ " ] in create_zmq_client expected ; Lwt_main . run begin let socket = Zmq_channel . create ~ ctx ~ kind : Zmq . Socket . rep " tcp :// 0 . 0 . 0 . 0 : 5555 " in Zmq_channel . recv socket >>= fun actual -> Zmq_channel . send socket [ " shutdown " ] ...
let suite = " Zmq_channel " >:: test_recv_send
let test ? cr zone = require_does_not_raise [ % here ] ? cr ( fun ( ) -> print_s [ % sexp ( Time . utc_offset Time . epoch ~ zone : Time . Span . t ) ] ) in test Time . Zone . utc ; [ % expect { | 0s } ] ; | let zone = Time . Zone . utc |> Binable . to_string ( module Time . Stable . Zone . Full_data . V1 ) |> Binable ...
type falling_block = { mutable pattern : int array list ; mutable bcolor : int ; mutable x : int ; mutable y : int ; mutable d : int ; mutable alive : bool }
let colors = [ | ` Color " red " ; ` Color " yellow " ; ` Color " blue " ; ` Color " orange " ; ` Color " magenta " ; ` Color " green " ; ` Color " cyan " ] |
let backgrounds = [ " Lambda2 . back . gif " ]
let blocks = [ [ [ " | 0000 " ; " 0000 " ; " 1111 " ; " 0000 " ] ; | [ " | 0010 " ; " 0010 " ; " 0010 " ; " 0010 " ] ; | [ " | 0000 " ; " 0000 " ; " 1111 " ; " 0000 " ] ; | [ " | 0010 " ; " 0010 " ; " 0010 " ; " 0010 " ] | ] ; [ [ " | 0000 " ; " 0110 " ; " 0110 " ; " 0000 " ] ; | [ " | 0000 " ; " 0110 " ; " 0110 " ; " ...
let line_empty = int_of_string " 0b1110000000000111 "
let line_full = int_of_string " 0b1111111111111111 "
let decode_block dvec = let btoi d = int_of_string ( " 0b " ^ d ) in Array . map ~ f : btoi dvec val mutable color = 0 method get = color method set ~ color : col = if color = col then ( ) else if color <> 0 && col = 0 then begin Canvas . move canvas t1 ~ x ( :- block_size * ( x + 1 ) - 10 - cell_border * 2 ) ~ y ( :- ...
let cell_get ( c , cf ) x y = cf . ( y ) . ( x ) # get
let cell_set ( c , cf ) ~ x ~ y ~ color = if x >= 0 && y >= 0 && Array . length cf > y && Array . length cf . ( y ) > x then let cur = cf . ( y ) . ( x ) in if cur # get = color then ( ) else cur # set ~ color
let create_base_matrix ~ cols ~ rows = let m = Array . create_matrix ~ dimx : rows ~ dimy : cols ( 0 , 0 ) in for x = 0 to cols - 1 do for y = 0 to rows - 1 do m . ( y ) . ( x ) <- ( x , y ) done done ; m
let init fw = let scorev = Textvariable . create ( ) and linev = Textvariable . create ( ) and levv = Textvariable . create ( ) and namev = Textvariable . create ( ) in let f = Frame . create fw ~ borderwidth : 2 in let c = Canvas . create f ~ width : ( block_size * 10 ) ~ height : ( block_size * 20 ) ~ borderwidth : c...
let draw_block field ~ color ~ block ~ x ~ y = for iy = 0 to 3 do let base = ref 1 in let xd = block . ( iy ) in for ix = 0 to 3 do if xd land ! base <> 0 then cell_set field ~ x ( : ix + x ) ~ y ( : iy + y ) ~ color ; base := ! base lsl 1 done done
let timer_ref = ( ref None : Timer . t option ref )
let remove_timer ( ) = match ! timer_ref with None -> ( ) | Some t -> Timer . remove t
let do_after ~ ms ~ callback = timer_ref := Some ( Timer . add ~ ms ~ callback )
let copy_block c = { pattern = ! c . pattern ; bcolor = ! c . bcolor ; x = ! c . x ; y = ! c . y ; d = ! c . d ; alive = ! c . alive }
let _ = let top = openTk ( ) in let lb = Label . create top and fw = Frame . create top in let set_message s = Label . configure lb ~ text : s in pack [ coe lb ; coe fw ] ~ side : ` Top ; let score = ref 0 in let line = ref 0 in let level = ref 0 in let time = ref 1000 in let blocks = List . map ~ f ( : List . map ~ f ...
let _ = Printexc . print mainLoop ( )
let brand_points = ba2_glefloat_of_array [ | [ | 0 . 0 ; 0 . 0 ; 0 . 1 ] ; | [ | 0 . 0 ; 0 . 0 ; 0 . 0 ] ; | [ | 0 . 0 ; 0 . 0 ; - 5 . 0 ] ; | [ | 0 . 0 ; 0 . 0 ; - 5 . 1 ] ; | ] |
let brand_colors = ba2_float32_of_array [ | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | [ | 1 . 0 ; 0 . 3 ; 0 . 0 ] ; | ] |
let tnum , tspine = let tcoords = [ | ( - 1 . 5 , 2 . 0 ) ; ( - 0 . 75 , 2 . 0 ) ; ( - 0 . 75 , 1 . 38 ) ; ( - 0 . 5 , 1 . 25 ) ; ( 0 . 88 , 1 . 12 ) ; ( 1 . 0 , 0 . 62 ) ; ( 1 . 12 , 0 . 1 ) ; ( 0 . 5 , - 0 . 5 ) ; ( 0 . 2 , - 1 . 12 ) ; ( 0 . 3 , - 1 . 5 ) ; ( - 0 . 25 , - 1 . 45 ) ; ( - 1 . 06 , - 0 . 3 ) ; ( - 1 . ...
let tcolors = ( ba2_float32_create tnum 3 )
let ( += ) a b = ( a := ! a + b )
let ( %= ) a b = ( a := ! a mod b )
let init_spine ( ) = let ir = ref 0 and ig = ref 0 and ib = ref 0 in for i = 0 to pred tnum do ir += 33 ; ig += 47 ; ib += 89 ; ir %= 255 ; ig %= 255 ; ib %= 255 ; let r = ( float ! ir ) . / 255 . 0 and g = ( float ! ig ) . / 255 . 0 and b = ( float ! ib ) . / 255 . 0 in tcolors . { i , 0 } <- ( r ) ; tcolors . { i , 1...
let coords = [ ( - 0 . 75 , 2 . 0 ) ; ( - 0 . 75 , 1 . 38 ) ; ( - 0 . 5 , 1 . 25 ) ; ( 0 . 88 , 1 . 12 ) ; ( 1 . 0 , 0 . 62 ) ; ( 1 . 12 , 0 . 1 ) ; ( 0 . 5 , - 0 . 5 ) ; ( 0 . 2 , - 1 . 12 ) ; ( 0 . 3 , - 1 . 5 ) ; ( - 0 . 25 , - 1 . 45 ) ; ( - 1 . 06 , - 0 . 3 ) ; ( - 1 . 38 , - 0 . 3 ) ; ( - 1 . 65 , - 0 . 6 ) ; ( -...
let ncoords = List . length coords
let texas_xsection = ( ba2_glefloat_create ncoords 2 )
let texas_normal = ( ba2_glefloat_create ncoords 2 )
let border i ( x , y ) = texas_xsection . { i , 0 } <- scale . * ( x ) ; texas_xsection . { i , 1 } <- scale . * ( y ) ; if i <> 0 then begin let ax = texas_xsection . { i , 0 } . - texas_xsection . { i - 1 , 0 } and ay = texas_xsection . { i , 1 } . - texas_xsection . { i - 1 , 1 } in let alen = 1 . 0 . / sqrt ( ax . ...
let init_xsection ( ) = ignore ( List . fold_left border 0 coords ) ; ; ;
let init_stuff ( ) = init_spine ( ) ; init_xsection ( ) ; gleSetJoinStyle [ TUBE_JN_CAP ; TUBE_CONTOUR_CLOSED ; TUBE_NORM_FACET ; TUBE_JN_ANGLE ] ; ; ;
let draw_stuff ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glPushMatrix ( ) ; glTranslatev ( 0 . 0 , 0 . 0 , - 80 . 0 ) ; glRotate ( float ! lastx ) 0 . 0 1 . 0 0 . 0 ; glRotate ( float ! lasty ) 1 . 0 0 . 0 0 . 0 ; gleExtrusion texas_xsection texas_normal None tspine tcolors ; gleExtrusion texas_xsec...
let makeStripeImage ( ) = let stripeImage = Bigarray . Array1 . create Bigarray . int8_unsigned Bigarray . c_layout ( 4 * stripeImageWidth ) in for j = 0 to pred stripeImageWidth do stripeImage . { 4 * j } <- ( if j <= 4 then 255 else 0 ) ; stripeImage . { 4 * j + 1 } <- ( if j > 4 then 255 else 0 ) ; stripeImage . { 4...
let xequalzero = ( 1 . 0 , 0 . 0 , 0 . 0 , 0 . 0 )
let slanted = ( 1 . 0 , 1 . 0 , 1 . 0 , 0 . 0 )
let currentCoeff = ref xequalzero
let currentPlane = ref GL_OBJECT_PLANE
let currentGenMode = ref GL_OBJECT_LINEAR
let init ( ) = glClearColor 0 . 0 0 . 0 0 . 0 0 . 0 ; glEnable GL_DEPTH_TEST ; glShadeModel GL_SMOOTH ; let stripeImage = makeStripeImage ( ) in glPixelStorei GL_UNPACK_ALIGNMENT 1 ; let texName = glGenTexture ( ) in glBindTexture BindTex . GL_TEXTURE_1D texName ; glTexParameter TexParam . GL_TEXTURE_1D ( TexParam . GL...
let display texName ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glPushMatrix ( ) ; glRotate 45 . 0 0 . 0 0 . 0 1 . 0 ; glBindTexture BindTex . GL_TEXTURE_1D texName ; glutSolidTeapot 2 . 0 ; glPopMatrix ( ) ; glFlush ( ) ; ; ;
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; let w = float w and h = float h in if w <= h then glOrtho ( - 3 . 5 ) ( 3 . 5 ) ( - 3 . 5 . * h . / w ) ( 3 . 5 . * h . / w ) ( - 3 . 5 ) ( 3 . 5 ) else glOrtho ( - 3 . 5 . * w . / h ) ( 3 . 5 . * w . / h ) ( -...
let keyboard ~ key ~ x ~ y = match key with | ' e ' | ' E ' -> currentGenMode := GL_EYE_LINEAR ; currentPlane := GL_EYE_PLANE ; glTexGen GL_S GL_TEXTURE_GEN_MODE ! currentGenMode ; glTexGenv GL_S ! currentPlane ! currentCoeff ; glutPostRedisplay ( ) ; | ' o ' | ' O ' -> currentGenMode := GL_OBJECT_LINEAR ; currentPlane...
let ( ) = let _ = glutInit Sys . argv in glutInitDisplayMode [ GLUT_SINGLE ; GLUT_RGB ; GLUT_DEPTH ] ; glutInitWindowSize 256 256 ; glutInitWindowPosition 100 100 ; let _ = glutCreateWindow Sys . argv . ( 0 ) in let texName = init ( ) in glutDisplayFunc ~ display ( : display texName ) ; glutReshapeFunc ~ reshape ; glut...
unsigned short imagic ; unsigned short type ; unsigned short dim ; unsigned short xsize , ysize , zsize ; unsigned int min , max ; unsigned int wasteBytes ; char name [ 80 ] ; unsigned long colorMap ; FILE * file ; unsigned char * tmp ; unsigned long rleEnd ; unsigned int * rowStart ; int * rowSize ; void while ( n ) -...
type environment = | Normal | Caml | Verbatim of string * string | Verbatim_like
let in_quotes = ref false
let is_alpha c = ( ' A ' <= c && c <= ' Z ' ) || ( ' a ' <= c && c <= ' z ' )
let is_prefix prefix str = let length_prefix = String . length prefix in let length_str = String . length str in if length_prefix > length_str then false else ( String . sub str 0 length_prefix ) = prefix
let escape = function | ' ' | ' \ n ' -> " \\ " | ' { ' -> " { \\ char123 } " | ' } ' -> " { \\ char125 } " | ' ' ^ -> " { \\ char94 } " | ' _ ' -> " { \\ char95 } " | ' ' \\ -> " { \\ char92 } " | ' ' ~ -> " { \\ char126 } " | ' ' $ -> " " \\$ | ' ' & -> " { \\ char38 } " | ' ' # -> " " \\# | ' ' % -> " " \\% | ' ' ' ...
let process_normal_line line = let ( verb_mark : char option ref ) = ref None in let l = String . length line in let i = ref 0 in while ! i < l do match ! verb_mark with | None -> ( match line . [ ! i ] with | ' " ' -> let r = if ! in_quotes then " } } " else " { \\ machine { " in print_string r ; in_quotes := not ! in...
let process_line line = function | Normal -> if is_prefix " \\ begin { caml_ " line || is_prefix " \\ begin { rawhtml } " line then ( print_string line ; Verbatim_like ) else if is_prefix " \\ begin { camlexample } " line then ( print_endline line ; Caml ) else if is_prefix " \\ begin { verbatim } " line then begin pri...
let rec process_input env = match input_line stdin with | exception End_of_file -> ( ) | line -> let env = process_line line env in process_input env
let main ( ) = print_endline " % THIS FILE IS GENERATED . " ; print_newline ( ) ; process_input Normal
let top = opentk ( )
let scroll_link sb tx = Text . configure tx [ YScrollCommand ( Scrollbar . set sb ) ] ; Scrollbar . configure sb [ ScrollCommand ( Text . yview tx ) ]
let f = Frame . create top [ ]
let text = Text . create f [ ]
let scrollbar = Scrollbar . create f [ ]