text
stringlengths
12
786k
let ocaml_name jname = let is_upper c = ' A ' <= c && c <= ' Z ' in let is_digit c = ' 0 ' <= c && c <= ' 9 ' in let buf = Buffer . create ( String . length jname ) in let last_up = ref true in for i = 0 to String . length jname - 1 do if is_upper jname . [ i ] && not (...
let parse_ret i l = match String . cut_left " " l with
let parse_name i l = match String . cut_left " ( " l with String . trim n , String . subrange ~ last ( : String . length args - 2 ) args
let parse_args i args = if args = " " then [ ] else let name n = match String . trim n with | " type " -> " type ' " | " end " -> " end ' " | s -> s in let parse_arg i arg = match String . cut_left " " ( String . trim arg ) with | None -> B00_lines . err i " % ...
let parse_func i l = match String . cut_left " ; " l with let version = if v = " 1 " then 1 else 2 in let ret , rest = parse_ret i rest in let name , args = parse_name i rest in let args = parse_args i args in { name ; args ; ret ; version }
let parse_funcs ~ file data = let add_line i line acc = match line with | " " -> acc | l -> let f = parse_func i line in String . Map . add_to_list f . name f acc in Result . map cleanup_funcs ( B00_lines . fold ~ file data add_line String . Map . empty )
let dump funcs = let opt_arg a = if a . optional then " option " else " " in let out_arg a = Printf . sprintf " ( % s : % s % s ) " a . n a . type ' ( opt_arg a ) in let out_args args = String . concat " " ( List . map out_arg args ) in let out_func f = Printf . prin...
let otype fname = function " int " " Shader_precision_format . t "
let func_link func = let base = match func . version = 1 with | true -> " https :// developer . mozilla . org / en - US / docs / Web / API / WebGLRenderingContext " / | false -> " https :// developer . mozilla . org / en - US / docs / Web / API / WebGL2RenderingContext " / in P...
let func_mli func = let fname = ocaml_name func . name in let arg_type { type ' ; _ } = otype func . name type ' in let args = List . filter ( fun a -> not a . optional ) func . args in let args_sig = match args with | [ ] -> " " | args -> " -> " ^ String . concat " ...
let type_of_jv fname = function
let type_to_jv fname = function " of_int "
let func_ml func = let fname = ocaml_name func . name in let args = List . filter ( fun a -> not a . optional ) func . args in let ret = let ret = type_of_jv func . name func . ret in if ret = " " then " " else ret ^ " @@ " in let args_names = String . concat " " ( List . ...
let out_funcs out_fmt funcs = let out_func fname funs ( ) = match funs with | [ f ] -> out_fmt f | funcs -> Printf . printf " \ n " %! in String . Map . fold out_func funcs ( )
let out funcs = function
let gen file outfmt = let * file = Fpath . of_string file in let * data = Os . File . read file in let * funcs = parse_funcs ~ file data in out funcs outfmt ; Ok 0
let main ( ) = let usage = " Usage : gen [ -- input FILE | -- mli | -- ml ] " in let file = ref " glfuns . spec " in let outfmt = ref ` Dump in let args = [ " -- input " , Arg . Set_string file , " The file to read " ; " -- dump " , Arg . Unit ( fun ( ) ...
let ( ) = if ! Sys . interactive then ( ) else main ( )
let string_of_token = function ; ;
let match_character_class cl c = Bool . eval begin function ( c1 , c2 ) -> c1 <= c && c <= c2 end cl ; ;
module NFA = struct type transition = | QCLASS of character_class | QEPSILON ; ; module IS = Set . Make ( struct type t = int let compare = compare let print = Format . pp_print_int end ) ; ; module ISM = Map . Make ( struct type t = IS . t let compare = IS . compare let print = IS ....
module Brute = struct exception Succeed ; ; exception Fail ; ; exception Too_hard ; ; let match_pattern counter p u = let m = String . length u in let rec loop ( i , n , p ) = assert ( 0 <= i && 0 <= n && i + n <= m ) ; incr counter ; if ! counter >= brute_limit then raise To...
type fast_pattern = fast_pattern_contents ref ; ;
type globber = fast_pattern atom Bool . boolean ; ;
let fast_pattern_of_pattern p = ref ( Brute ( ref 0 , p ) ) ; ;
let add_dir dir x = match dir with | None -> x | Some ( dir ) -> match x with | Constant ( s ) -> Constant ( My_std . filename_concat dir s ) | Pattern ( p ) -> Pattern ( Concat ( Word ( My_std . filename_concat dir " " ) , p ) ) ; ;
let add_ast_dir dir x = match dir with | None -> x | Some dir -> let slash = Class ( Atom ( ' ' , ' ' ) ) // in let any = Class True in let q = Union [ Epsilon ; Concat ( slash , Star any ) ] in And [ Atom ( Pattern ( ref ( Brute ( ref 0 , Concat ( Word dir , q ) ...
let parse ? dir u = let l = Lexing . from_string u in let tok = ref None in let f = fun ( ) -> match ! tok with | None -> token l | Some x -> tok := None ; x in let g t = match ! tok with | None -> tok := Some t | Some t ' -> raise ( Parse_error ( sf " Trying to unput token % s while...
let eval g u = Bool . eval begin function | Constant v -> u = v | Pattern kind -> match ! kind with | Brute ( count , p ) -> begin let do_nfa ( ) = let m = NFA . build p in kind := Machine m ; NFA . run m u in if ! count >= brute_limit then do_nfa ( ) else try Brute . match_pattern...
module type GLOBREF = sig type t val register : string -> t val get : t -> string val set : t -> string -> unit val remove : t -> unit end
module Classic : GLOBREF = struct type t external register : string -> t = " gb_classic_register " external get : t -> string = " gb_get " external set : t -> string -> unit = " gb_classic_set " external remove : t -> unit = " gb_classic_remove " end
module Generational : GLOBREF = struct type t external register : string -> t = " gb_generational_register " external get : t -> string = " gb_get " external set : t -> string -> unit = " gb_generational_set " external remove : t -> unit = " gb_generational_remove " end
module Test ( G : GLOBREF ) = struct let size = 1024 let vals = Array . init size string_of_int let a = Array . init size ( fun i -> G . register ( string_of_int i ) ) let check ( ) = for i = 0 to size - 1 do if G . get a . ( i ) <> vals . ( i ) then begin print_string "...
let _ = let n = if Array . length Sys . argv < 2 then 10000 else int_of_string Sys . argv . ( 1 ) in print_string " Non - generational API \ n " ; TestClassic . test n ; print_newline ( ) ; print_string " Generational API \ n " ; TestGenerational . test n ; print_newline ...
let _ = let test_closed_chan str = try ignore ( Test . run_str ~ print_exn : false str ) with | Lisp_error ( ClosedChan _ ) -> ( ) | Repl_exn ( Lisp_error ( ClosedChan _ ) :: _ ) -> ( ) in let test_time str time rst = let start_time = Unix . gettimeofday ( ) in Test . te...
let write_dot_rank chan circuit = Int64 . to_string ( uid signal ) in ] } ) * let outputs = List . fold ( Circuit . outputs circuit ) ~ init ( : Set . empty ( module Uid ) ) ~ f ( : fun set signal -> Set . add set ( uid signal ) ) in let fdeps s = match s with | Mem _ ...
let write_gdl ( ? names = false ) ( ? widths = false ) ( ? consts = true ) ( ? clocks = false ) chan circuit = let quote s = " " " \ ^ s ^ " " " \ in fprintf chan " graph : { \ n " ; let props = [ " title " , quote ( Circuit . name circuit ) ; " man...
let aisee3 ( ? args = " " ) ( ? names = false ) ( ? widths = false ) ( ? consts = true ) ( ? clocks = false ) circuit = let name , file = Filename . open_temp_file " aisee3 " " . gdl " in write_gdl ~ names ~ widths ~ consts ~ clocks file circuit ; Out_channel . ...
let _ = Callback . register_exception " Graphics . Graphic_failure " ( Graphic_failure " " )
let unix_open_graph arg = Sys . set_signal ( sigio_signal ( ) ) ( Sys . Signal_handle sigio_handler ) ; raw_open_graph arg
let unix_close_graph ( ) = Sys . set_signal ( sigio_signal ( ) ) Sys . Signal_ignore ; raw_close_graph ( )
let ( open_graph , close_graph ) = match Sys . os_type with | " Unix " | " Cygwin " -> ( unix_open_graph , unix_close_graph ) | " Win32 " -> ( raw_open_graph , raw_close_graph ) | " MacOS " -> ( raw_open_graph , raw_close_graph ) | _ -> invalid_arg ( " Graphics ...
let auto_synchronize = function | true -> display_mode true ; remember_mode true ; synchronize ( ) | false -> display_mode false ; remember_mode true ; ;
let rgb r g b = ( r lsl 16 ) + ( g lsl 8 ) + b
let plots points = for i = 0 to Array . length points - 1 do let ( x , y ) = points . ( i ) in plot x y ; done ; ;
let current_point ( ) = current_x ( ) , current_y ( )
let rlineto x y = lineto ( current_x ( ) + x ) ( current_y ( ) + y )
let rmoveto x y = moveto ( current_x ( ) + x ) ( current_y ( ) + y )
let draw_rect x y w h = if w < 0 || h < 0 then raise ( Invalid_argument " draw_rect " ) else raw_draw_rect x y w h ; ;
let draw_poly , draw_poly_line = let dodraw close_flag points = if Array . length points > 0 then begin let ( savex , savey ) = current_point ( ) in moveto ( fst points . ( 0 ) ) ( snd points . ( 0 ) ) ; for i = 1 to Array . length points - 1 do let ( x , y ) = po...
let draw_segments segs = let ( savex , savey ) = current_point ( ) in for i = 0 to Array . length segs - 1 do let ( x1 , y1 , x2 , y2 ) = segs . ( i ) in moveto x1 y1 ; lineto x2 y2 ; done ; moveto savex savey ; ; ; = " caml_gr_draw_arc " " caml_gr_draw_arc_nat "
let draw_arc x y rx ry a1 a2 = if rx < 0 || ry < 0 then raise ( Invalid_argument " draw_arc / ellipse / circle " ) else raw_draw_arc x y rx ry a1 a2 ; ;
let draw_ellipse x y rx ry = draw_arc x y rx ry 0 360
let draw_circle x y r = draw_arc x y r r 0 360
let set_line_width w = if w < 0 then raise ( Invalid_argument " set_line_width " ) else raw_set_line_width w ; ;
let fill_rect x y w h = if w < 0 || h < 0 then raise ( Invalid_argument " fill_rect " ) else raw_fill_rect x y w h ; ; = " caml_gr_fill_arc " " caml_gr_fill_arc_nat "
let fill_arc x y rx ry a1 a2 = if rx < 0 || ry < 0 then raise ( Invalid_argument " fill_arc / ellipse / circle " ) else raw_fill_arc x y rx ry a1 a2 ; ;
let fill_ellipse x y rx ry = fill_arc x y rx ry 0 360
let fill_circle x y r = fill_arc x y r r 0 360
let get_image x y w h = let image = create_image w h in blit_image image x y ; image
type status = { mouse_x : int ; mouse_y : int ; button : bool ; keypressed : bool ; key : char }
type event = Button_down | Button_up | Key_pressed | Mouse_motion | Poll
let mouse_pos ( ) = let e = wait_next_event [ Poll ] in ( e . mouse_x , e . mouse_y )
let button_down ( ) = let e = wait_next_event [ Poll ] in e . button
let read_key ( ) = let e = wait_next_event [ Key_pressed ] in e . key
let key_pressed ( ) = let e = wait_next_event [ Poll ] in e . keypressed
let add ( x1 , y1 ) ( x2 , y2 ) = ( x1 . + x2 , y1 . + y2 )
let test a b c d = let v = sub d a in let s = norm v in area v ( sub a b ) <= s && area v ( sub a c ) <= s ; ;
let spline a b c d = let rec spl accu a b c d = if test a b c d then d :: accu else let a ' = middle a b and o = middle b c in let b ' = middle a ' o and d ' = middle c d in let c ' = middle o d ' in let i = middle b ' c ' in spl ( spl accu a a ' b ' i ) i c ' d ' d in spl [ a ] ...
let curveto b c ( x , y as d ) = let float_point ( x , y ) = ( float_of_int x , float_of_int y ) in let round f = int_of_float ( f . + 0 . 5 ) in let int_point ( x , y ) = ( round x , round y ) in let points = spline ( float_point ( current_point ( ) ) ) ( flo...
let xr = size_x ( ) / 2 - 30 ; ;
let point x y = let dr = ( x - xr ) ( * x - xr ) + ( y - yr ) ( * y - yr ) and dg = ( x - xg ) ( * x - xg ) + ( y - yg ) ( * y - yg ) and db = ( x - xb ) ( * x - xb ) + ( y - yb ) ( * y - yb ) in if dr > dg && dr > db then set_color ( rgb 255...
let n = 0x000000 ; ;
let caml = make_image [ | [ | t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; n ; n ; n ; n ; n ; n ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; ] ; | [ | t ; t ; t ; t ; t ; t ; t ; t ; t ; t ; n ; n ; n...
let dashes y = for i = 1 to 100 do plot y ( 2 * i ) ; plot y ( 3 * i ) ; plot y ( 4 * i ) ; done ; ;
let carre c = rlineto 0 c ; rlineto c 0 ; rlineto 0 ( - c ) ; rlineto ( - c ) 0 ; ; moveto ( 10 * i ) ( 10 * i ) ; set_color ( rgb ( 155 + 10 * i ) 0 0 ) ; carre ( 10 * i ) done ; ; carre ( 10 * i ) done ; ;
let x , y = current_point ( ) in
let go_caption l = moveto 210 ( 130 - lw + l ) ; ;
let go_legend ( ) = go_caption ( - 3 * lw ) ; ;
let x , y = current_point ( ) in
let draw_green_string s = set_color green ; draw_string s ; ;
let draw_red_string s = set_color red ; draw_string s ; ;
let draw_poly v = let l = Array . length v in if l > 0 then begin let x0 , y0 = current_point ( ) in let p0 = v . ( 0 ) in let x , y = p0 in moveto x y ; for i = 1 to l - 1 do let x , y = v . ( i ) in lineto x y done ; lineto x y ; moveto x0 y0 end ; ;
let equi x y l = [ | ( x - l / 2 , y ) ; ( x , y + int_of_float ( float_of_int l . * ( sqrt 3 . 0 . / 2 . 0 ) ) ) ; ( x + l / 2 , y ) ] ; ; |
let x , y = current_point ( ) in
let x , y = current_point ( ) in
let x , y = current_point ( ) in
let x , y = current_point ( ) in
let draw_arc_ellipse x y r1 r2 = set_color green ; draw_arc x y r1 r2 60 120 ; set_color black ; draw_arc x y r1 r2 120 420 ; ;
let draw_arc_ellipses x y r1 r2 = let step = 5 in for i = 0 to ( r1 - step ) / ( 2 * step ) do for j = 0 to ( r2 - step ) / ( 2 * step ) do draw_arc_ellipse x y ( 3 * i * step ) ( 3 * j * step ) done done ; ;
let fill_arc_ellipse x y r1 r2 c1 c2 = set_color c1 ; fill_arc x y r1 r2 60 120 ; set_color c2 ; fill_arc x y r1 r2 120 420 ; ;
let fill_arc_ellipses x y r1 r2 = let step = 3 in let c1 = ref black and c2 = ref yellow in let exchange r1 r2 = let tmp = ! r1 in r1 := ! r2 ; r2 := tmp in for i = r1 / ( 2 * step ) downto 10 do for j = r2 / ( 2 * step ) downto 30 do exchange c1 c2 ; fill_arc_ellipse x y ( 3 * i ) ...
module Controls = struct type t = [ ` NEW | ` OPEN | ` SAVE | ` SAVE_AS | ` EXECUTE | ` EXECUTE_ALL | ` STOP | ` RESTART | ` CLEAR | ` SELECT_COLOR | ` ZOOM_IN | ` ZOOM_OUT | ` FULLSCREEN | ` QUIT ] let stock = function | ` RESTART -> ` REFRESH | ` EXECUTE_ALL -...
let main_view = GBin . scrolled_window ~ hpolicy ` : NEVER ( )
let toplevel_view = GBin . scrolled_window ~ hpolicy ` : AUTOMATIC ( )
let status_bar , top_msg , index_msg = let bar = GMisc . statusbar ( ) in let ctx_top = bar # new_context ~ name " : top " in let ctx_index = bar # new_context ~ name " : index " in bar , ( fun msg -> ctx_top # pop ( ) ; if msg <> " " then ignore @@ ctx_top # push msg ) ...
type shortcut_mods = [ ` CONTROL | ` SHIFT | ` META | ` SUPER | ` HYPER ]
let shortcuts = [ ( [ ` CONTROL ] , GdkKeysyms . _n ) , ` NEW ; ( [ ` CONTROL ] , GdkKeysyms . _o ) , ` OPEN ; ( [ ` CONTROL ] , GdkKeysyms . _s ) , ` SAVE ; ( [ ` CONTROL ] , GdkKeysyms . _e ) , ` EXECUTE ; ( [ ] , GdkKeysym...
let add objs container = List . iter ( fun o -> container # add ( o :> GObj . widget ) ) objs ; container
let pack objs ( container : GPack . box ) = List . iter ( fun o -> container # pack o ) objs ; container