text
stringlengths
0
601k
let test55 ( ) = let ob = Buffer . create 42 in let ib = create_tscanf_data ob tscanf_data_file_lines ; let s = Buffer . contents ob in Buffer . clear ob ; Scanning . from_string s in let tscanf_data_file_lines_digest = add_digest_ib ob ib ; Buffer . contents ob in digest_file tscanf_data_file = tscanf_data_file_lines_...
let regexp alpha = [ ' a ' - ' z ' ] ' z '
let regexp digit = [ ' 0 ' - ' 9 ' ] ' 9 '
let regexp hexa = [ ' 0 ' - ' 9 ' ' a ' - ' f ' ] ' f '
let regexp space = [ ' ' ' \ t ' ' \ n ' ] n '
let regexp ident = [ ' a ' - ' z ' ' - ' ] ' [ ' A ' - ' Z ' ' a ' - ' z ' ' 0 ' - ' 9 ' ' - ' ' _ ' ] ' _ ' *
let regexp variable = [ ' A ' - ' Z ' ] ' Z ' [ ' A ' - ' Z ' ' a ' - ' z ' ' 0 ' - ' 9 ' ' - ' ' _ ' ] ' _ ' *
let regexp hashed = ' # ' [ ' A ' - ' Z ' ' a ' - ' z ' ' 0 ' - ' 9 ' ' - ' ' _ ' ] ' _ ' +
let regexp number = ( ' - ' | ' + ' ) ' ? digit + ( ' . ' digit ) +?
let regexp units = alpha + | ' % '
let regexp slc = " " // [ ^ ' \ n ' ] n ' +
let regexp nth = ( ' - ' | ' + ' ) ' ? digit + ' n ' ( ' - ' | ' + ' ) ' digit +
let add_lines nlines lexbuf =
let trim_lexbuf ( ? left = 0 ) 0 ( ? right = 0 ) 0 lexbuf =
let rec main_scanner nlines = lexer
type token = | TokSemicolumn | TokId of string | TokAssign | TokPrint | TokLParen | TokRParen | TokComma | TokNum of float | TokPlus | TokMinus | TokTimes | TokDiv | TokEOF
let string_of_token tok = match tok with | TokSemicolumn -> " TokSemicolumn " | TokId x -> " TokId [ " ^ x ^ " ] " | TokAssign -> " TokAssign " | TokPrint -> " TokAssign " | TokLParen -> " TokLParen " | TokRParen -> " TokRParen " | TokComma -> " TokComma " | TokNum x -> " TokNum [ " ^ string_of_float x ^ " ] " | TokPlu...
type scanner_buffer = { mutable buffer : char list ; channel : in_channel }
let get_char sbuffer = match sbuffer . buffer with | c :: cs -> sbuffer . buffer <- cs ; Some c | [ ] -> try Some ( input_char sbuffer . channel ) with End_of_file -> None
let unget_char sbuffer c = sbuffer . buffer <- c :: sbuffer . buffer
let scanner_buffer_from_channel channel = { buffer = [ ] ; channel = channel }
let is_digit c = ' 0 ' <= c && c <= ' 9 '
let is_letter c = ' a ' <= c && c <= ' z ' || ' A ' <= c && c <= ' Z '
let rec get_token f = match get_char f with | None -> TokEOF | Some x -> match x with | ' ' | ' \ n ' | ' \ t ' -> get_token f | ' ' # -> let rec loop ( ) = match get_char f with | Some y when y <> ' \ n ' -> loop ( ) | _ -> get_token f in loop ( ) | ' ( ' -> TokLParen | ' ) ' -> TokRParen | ' ; ' -> TokSemicolumn | ' ...
let main ( ) = let channel = if Array . length Sys . argv = 2 then open_in Sys . argv . ( 1 ) else stdin in let rec go f = let t = get_token f in print_endline ( string_of_token t ) ; if t <> TokEOF then go f in go ( scanner_buffer_from_channel channel )
let _ = main ( )
let regexp alpha = [ ' a ' - ' z ' ] ' z '
let regexp digit = [ ' 0 ' - ' 9 ' ] ' 9 '
let regexp hexa = [ ' 0 ' - ' 9 ' ' a ' - ' f ' ] ' f '
let regexp space = [ ' ' ' \ t ' ' \ n ' ] n '
let regexp ident = [ ' a ' - ' z ' ' - ' ] ' [ ' A ' - ' Z ' ' a ' - ' z ' ' 0 ' - ' 9 ' ' - ' ' _ ' ] ' _ ' *
let regexp variable = [ ' A ' - ' Z ' ] ' Z ' [ ' A ' - ' Z ' ' a ' - ' z ' ' 0 ' - ' 9 ' ' - ' ' _ ' ] ' _ ' *
let regexp hashed = ' # ' [ ' A ' - ' Z ' ' a ' - ' z ' ' 0 ' - ' 9 ' ' - ' ' _ ' ] ' _ ' +
let regexp number = ( ' - ' | ' + ' ) ' ? digit + ( ' . ' digit ) +?
let regexp units = alpha + | ' % '
let regexp slc = " " // [ ^ ' \ n ' ] n ' +
let regexp nth = ( ' - ' | ' + ' ) ' ? digit + ' n ' ( ' - ' | ' + ' ) ' digit +
type t = charset_t option * statement_t list ] ] ] ] ] ] ] ] ] ]
module Lexer ( U : sig type token = EOF | S | CHARSET | IMPORT | MEDIA | PAGE | FONTFACE | OPEN_CURLY | CLOSE_CURLY | OPEN_ROUND | CLOSE_ROUND | OPEN_SQUARE | CLOSE_SQUARE | SEMICOLON | COLON | DOUBLE_COLON | COMMA | PERIOD | SLASH | ASTERISK | QUOTIENT | PLUS | MINUS | TILDE | GT | IMPORTANT | ATTR_EQUALS | ATTR_INCLU...
let brace_depth = ref 0
let comment_depth = ref 0
let initial_string_buffer = String . create 256
let string_buff = ref initial_string_buffer
let string_index = ref 0
let reset_string_buffer ( ) = string_buff := initial_string_buffer ; string_index := 0
let store_string_char c = begin if ! string_index >= String . length ! string_buff then begin let new_buff = String . create ( String . length ! string_buff * 2 ) in String . blit new_buff 0 ! string_buff 0 ( String . length ! string_buff ) ; string_buff := new_buff end end ; String . unsafe_set ! string_buff ! string_...
let get_stored_string ( ) = let s = String . sub ! string_buff 0 ! string_index in string_buff := initial_string_buffer ; s
let char_for_backslash = function ' n ' -> ' \ 010 ' | ' t ' -> ' \ 009 ' | ' b ' -> ' \ 008 ' | ' r ' -> ' \ 013 ' | c -> c
let char_for_decimal_code lexbuf i = Char . chr ( 100 * ( Char . code ( Lexing . lexeme_char lexbuf i ) - 48 ) + 10 * ( Char . code ( Lexing . lexeme_char lexbuf ( i + 1 ) ) - 48 ) + ( Char . code ( Lexing . lexeme_char lexbuf ( i + 2 ) ) - 48 ) )
let strong_assert x = if not x then assert false
let check = ref false
module Simple : sig type ' a t type ' a label val create : unit -> ' a t val count : ' a t -> int val label : ' a -> ' a label val get : ' a label -> ' a val set : ' a label -> ' a -> unit val insert : ' a t -> ' a label -> unit val order : ' a t -> set ' : a label -> before ' : a label -> unit val forget : ' a t -> ' ...
module Make_simple ( ) : sig type label val count : unit -> int val label : unit -> label val order : set : label -> before : label -> unit val forget : label -> unit val compare : label -> label -> int type label = unit Simple . label let t = Simple . create ( ) let count ( ) = Simple . count t let label = Simple . la...
module Indirect : sig type t type label val create : unit -> t val count : t -> int val label : unit -> label val insert : t -> label -> unit val order : t -> set : label -> before : label -> unit val forget : t -> label -> unit val compare : label -> label -> int val from_array : label array -> t module Label : sig ty...
module Make ( ) : sig type label val count : unit -> int val label : unit -> label val order : set : label -> before : label -> unit val forget : label -> unit val compare : label -> label -> int type label = Indirect . label let t = Indirect . create ( ) let count ( ) = Indirect . count t let label = Indirect . label ...
let centering_ger n = let i = Mat . identity n in let o = Vec . make n 1 . in ger ~ alpha ( :- 1 . . / ( float n ) n ) n o o i
let scatter_2gemm a = let n = Mat . dim1 a in let c = centering_ger n in gemm ( gemm ~ transa ` : T a c ) c a
let col_mean n c = Vec . sum c . / n
let column_means a = let n = Mat . dim1 a in gemv ~ alpha ( : 1 . . / ( float n ) n ) n ~ trans ` : T a ( Vec . make n 1 ) .
let scatter_fold_ger a = let n = Mat . dim1 a in let u = column_means a in ger ~ alpha ( :- 1 . . * float n ) n u u ( gemm ~ transa ` : T a a ) a
let ( ) = let hun = Mat . random 100 100 in let tho = Mat . random 1000 1000 in let ten = Mat . random 10000 10000 in Core . Command . run ( Bench . make_command [ Bench . Test . create ~ name " : using 2gemm 100 " ( fun ( ) -> ignore ( scatter_2gemm hun ) hun ) hun ; Bench . Test . create ~ name " : using fold_ger 100...
let myinit ( ) = let light_ambient = 0 . 0 , 0 . 0 , 0 . 0 , 1 . 0 and light_diffuse = 1 . 0 , 1 . 0 , 1 . 0 , 1 . 0 and light_specular = 1 . 0 , 1 . 0 , 1 . 0 , 1 . 0 and light_position = 1 . 0 , 1 . 0 , 1 . 0 , 0 . 0 in GlLight . light ~ num : 0 ( ` ambient light_ambient ) ; GlLight . light ~ num : 0 ( ` diffuse ligh...
let pi = acos ( - 1 . )
let solid_torus ~ inner ~ outer = let slices = 32 and faces = 16 in let slice_angle = 2 . 0 . * pi . / float slices and face_angle = 2 . 0 . * pi . / float faces in let vertex ~ i ~ j = let angle1 = slice_angle . * float i and angle2 = face_angle . * float j in GlDraw . normal3 ( cos angle1 . * cos angle2 , GlDraw . ve...
let solid_cone ~ radius ~ height = GluQuadric . cylinder ~ base : radius ~ top : 0 . ~ height ~ slices : 15 ~ stacks : 10 ( )
let solid_sphere ~ radius = GluQuadric . sphere ~ radius ~ slices : 32 ~ stacks : 32 ( )
let display ( ) = GlClear . clear [ ` color ; ` depth ] ; GlMat . push ( ) ; GlMat . rotate ~ angle : 20 . 0 ~ x : 1 . 0 ( ) ; GlMat . push ( ) ; GlMat . translate ~ x ( :- 0 . 75 ) ~ y : 0 . 5 ( ) ; GlMat . rotate ~ angle : 90 . 0 ~ x : 1 . 0 ( ) ; solid_torus ~ inner : 0 . 275 ~ outer : 0 . 85 ; GlMat . pop ( ) ; GlM...
let my_reshape ~ w ~ h = GlDraw . viewport ~ x : 0 ~ y : 0 ~ w ~ h ; GlMat . mode ` projection ; GlMat . load_identity ( ) ; if w <= h then GlMat . ortho ~ x ( :- 2 . 5 , 2 . 5 ) ~ z ( :- 10 . 0 , 10 . 0 ) ~ y ( :- 2 . 5 . * float h . / float w , 2 . 5 . * float h . / float w ) else GlMat . ortho ~ y ( :- 2 . 5 , 2 . 5...
let main ( ) = let top = openTk ( ) in let togl = Togl . create top ~ rgba : true ~ depth : true ~ width : 500 ~ height : 500 in Wm . title_set top " Scene " ; myinit ( ) ; Togl . reshape_func togl ~ cb ( : fun ( ) -> my_reshape ~ w ( : Togl . width togl ) ~ h ( : Togl . height togl ) ) ; Togl . display_func togl ~ cb ...
let _ = Printexc . print main ( )
let pi = 4 . . * atan 1 .
let path_extent ctx fill stroke = if stroke <> None then Cairo . stroke_extents ctx else Cairo . fill_extents ctx
let compute_extent ctx e = Cairo . new_path ctx ; match e with | Path ( cmd , fill , stroke ) -> Array . iter ( fun c -> match c with | Move_to ( x , y ) -> Cairo . move_to ctx x y | Curve_to ( x1 , y1 , x2 , y2 , x3 , y3 ) -> Cairo . curve_to ctx x1 y1 x2 y2 x3 y3 ) cmd ; path_extent ctx fill stroke | Ellipse ( cx , c...
let compute ctx l = Array . map ( fun e -> compute_extent ctx e ) l
let array_stringify f ch l = Format . fprintf ch " [ @< 1 [ > 0 " ; Array . iter ( fun e -> Format . fprintf ch " , , @% a " f e ) l ; Format . fprintf ch " ] ] " @
let string_stringify ch s = Format . fprintf ch " " \% s " " \ s
let color_stringify ch c = match c with | None -> Format . fprintf ch " 0 " | Some ( r , g , b ) -> let h v = truncate ( v . * 255 . 99 ) in Format . fprintf ch " [ @< 1 [ > 0 , , @% a ] ] " @ string_stringify ( Format . sprintf " #% 02x % 02x % 02x " ( h r ) ( h g ) ( h b ) )
let font_stringify ch ( font , size ) = Format . fprintf ch " % a " string_stringify ( Format . sprintf " % gpx % s " size font )
let command_stringify ch c = match c with | Move_to ( x , y ) -> Format . fprintf ch " [ @< 1 [ > 0 , , @% g , , @% g ] ] " @ x y | Curve_to ( x1 , y1 , x2 , y2 , x3 , y3 ) -> Format . fprintf ch " [ @< 1 [ > 1 , , @% g , , @% g , , @% g , , @% g , , @% g , , @% g ] ] " @ x1 y1 x2 y2 x3 y3
let commands_stringify = array_stringify command_stringify
let point_stringify ch ( x , y ) = Format . fprintf ch " [ @< 1 [ > 0 , , @% g , , @% g ] ] " @ x y
let points_stringify = array_stringify point_stringify
let rect_stringify ch ( x1 , y1 , x2 , y2 ) = Format . fprintf ch " [ @< 1 [ > 0 , , @% g , , @% g , , @% g , , @% g ] ] " @ x1 y1 x2 y2
let rect_array_stringify = array_stringify rect_stringify
let element_stringify ch e = match e with | Path ( cmds , fill , stroke ) -> Format . fprintf ch " [ @< 1 [ > 0 , , @% a , , @% a , , @% a ] ] " @ commands_stringify cmds color_stringify fill color_stringify stroke | Polygon ( l , fill , stroke ) -> Format . fprintf ch " [ @< 1 [ > 1 , , @% a , , @% a , , @% a ] ] " @ ...
let stringify = array_stringify element_stringify
" simplest " >:: ( fun [ _ -> assert_equal { ~ msg " = not equal " } { ~ printer ( = fun x -> x ) } { foo | do { 1 ; 2 } ; 3 ; | foo } ( pr ( pa1 { foo ( | begin 1 2 ) 3 ( define x 1 ) | foo } ) ) ] ) ; " simple module " >:: ( fun [ _ -> assert_equal { ~ msg " = not equal " } { ~ printer ( = fun [ x -> x ] ) } { foo | ...
type _ eff += Yield : unit eff | Fork : ( unit -> string ) -> unit eff | Ping : unit eff
let run main = let run_q = Queue . create ( ) in let enqueue k = Queue . push k run_q in let rec dequeue ( ) = if Queue . is_empty run_q then ` Finished else continue ( Queue . pop run_q ) ( ) in let rec spawn f = match_with f ( ) { retc = ( function | " ok " -> say " . " ; dequeue ( ) | s -> failwith ( " Unexpected re...
let test ( ) = say " A " ; perform ( Fork ( fun ( ) -> perform Yield ; say " C " ; perform Yield ; begin match_with ( fun ( ) -> perform Ping ; failwith " no pong " ) ? ( ) { retc = ( fun x -> x ) ; exnc = ( function | Pong -> say " ] " | e -> raise e ) ; effc = fun ( type a ) ( e : a eff ) -> match e with | Yield -> S...
let ( ) = let ` Finished = run test in say " \ n "
type code_dag_node = { instr : instruction ; delay : int ; mutable sons : ( code_dag_node * int ) list ; mutable date : int ; mutable length : int ; mutable ancestors : int ; mutable emitted_ancestors : int }
let dummy_node = { instr = end_instr ; delay = 0 ; sons = [ ] ; date = 0 ; length = - 1 ; ancestors = 0 ; emitted_ancestors = 0 }
let code_results = ( Hashtbl . create 31 : ( location , code_dag_node ) Hashtbl . t )
let code_uses = ( Hashtbl . create 31 : ( location , code_dag_node ) Hashtbl . t )
let code_stores = ref ( [ ] : code_dag_node list )
let code_loads = ref ( [ ] : code_dag_node list )
let code_checkbounds = ref ( [ ] : code_dag_node list )
let clear_code_dag ( ) = Hashtbl . clear code_results ; Hashtbl . clear code_uses ; code_stores := [ ] ; code_loads := [ ] ; code_checkbounds := [ ]
let add_edge ancestor son delay = ancestor . sons <- ( son , delay ) :: ancestor . sons ; son . ancestors <- son . ancestors + 1