text stringlengths 12 786k |
|---|
let calc = function Add -> ( ) + | Sub -> ( ) - | Mul -> ( * ) | Div -> ( ) / |
let comp = function LT -> ( ) < | EQ -> ( ) = | GT -> ( ) > | EQLT -> ( ) <= | EQGT -> ( ) >= | NEQ -> ( ) <> |
let rec is_value e = match e with Unit | Int _ | Bool _ | Fun _ | Function _ List . for_all is_value ( List . map ( fun ( _ , { contents = e } ) -> e ) items ) -> true List . for_all is_value items -> true List . for_all is_value items -> true Array . for_all is_value items -... |
let bold , ul , code_end = ( " \ x1b [ 1m " , " \ x1b [ 4m " , " \ x1b [ 0m " ) |
let underline x = Control ( Underline , x ) |
let fastcurry = ref false |
let rec underline_redex e = try match e with Control ( c , x ) -> Control ( c , underline_redex x ) | Op ( _ , ( Int _ | Var _ ) , ( Int _ | Var _ ) ) -> underline e | Op ( op , ( ( Int _ | Var _ ) as a ) , b ) -> Op ( op , a , underline_redex b ) | O... |
let underline_redex e = if is_value e then e else underline_redex e |
let rec strip_control = function Control ( _ , e ) -> strip_control e |
let rec remove_named_recursive_functions all fns = function Let ( true , [ ( PatVar n , v ) ] , e ) -> let r = Tinyocaml . recurse ( remove_named_recursive_functions all fns ) e in if all || List . mem n fns then r else Let ( true , [ ( PatVar n , v ) ] , r ) |
type state = { tokens : token array ; pos : int } |
let choice xs s = let rec loop xs = match xs with [ ] -> fail ( ) | x :: xs -> try x s with Failed -> loop xs in loop xs |
let skip x s = try let _ , s = x s in ( ) , s with Failed -> ( ) , s |
let skip_many x s = let s = ref s in try while true do s := snd ( x ! s ) ; done ; ( ) , ! s with Failed -> ( ) , ! s |
let token t s = if current s = t then ( ) , next s else fail ( ) |
let token_map f s = f ( current s ) , next s |
let sep sep x = let return acc s = List . rev acc , s in let rec loop acc s = try let x , s = x s in let acc = x :: acc in ( try let _ , s = sep s in loop acc s with Failed -> return acc s ) with Failed -> return acc s in loop [ ] |
let sep_empty sep x empty = let return acc s = List . rev acc , s in let rec empties acc s = try let _ , s = sep s in empties ( empty :: acc ) s with Failed -> loop acc s and loop acc s = try let x , s = x s in let acc = x :: acc in ( try let _ , s = sep s in empties acc s with Failed -> r... |
let sep_token t x = let return acc s = List . rev acc , s in let rec loop acc s = try let x , s = x s in let acc = x :: acc in ( try if current s = t then loop acc ( next s ) else return acc s with Failed -> return acc s ) with Failed -> return acc s in loop [ ] |
let sep_token1 t x s = match sep_token t x s with [ ] , _ -> fail ( ) | ok -> ok |
let seq x = let rec loop acc s = try let x , s = x s in loop ( x :: acc ) s with Failed -> List . rev acc , s in loop [ ] |
let seq1 x s = match seq x s with [ ] , _ -> fail ( ) | ok -> ok |
let seq_fold x ~ f ~ init = let rec loop acc s = try let x , s = x s in loop ( f acc x ) s with Failed -> acc , s in loop init |
let seq_fold_token ~ f ~ init = let rec loop acc s = try loop ( f acc ( current s ) ) ( next s ) with Failed -> acc , s in loop init |
type t = Empty | Concat of t * int * t * int * int | Leaf of string |
let height = function Empty | Leaf _ -> 0 | Concat ( _ , _ , _ , _ , h ) -> h |
let print = let rec print prefix = function | Empty -> print_string " \ n " | Leaf s -> print_string prefix ; print_string s ; print_string " \ n " | Concat ( l , _ , r , _ , _ ) -> let prefixl = prefix ^ if height l = 0 then " " / else " " in let prefixr = prefix ^ i... |
type forest_element = { mutable c : t ; mutable len : int } |
let string_of_string_list l = String . concat " " l |
let is_empty = function Empty -> true | _ -> false |
let length = function Empty -> 0 | Leaf s -> STRING . length s | Concat ( _ , cl , _ , cr , _ ) -> cl + cr |
let make_concat l r = let hl = height l and hr = height r in let cl = length l and cr = length r in Concat ( l , cl , r , cr , if hl >= hr then hl + 1 else hr + 1 ) |
let min_len = let fib_tbl = Array . make max_height 0 in let rec fib n = match fib_tbl . ( n ) with 0 -> let last = fib ( n - 1 ) and prev = fib ( n - 2 ) in let r = last + prev in let r = if r > last then r else last in fib_tbl . ( n ) <- r ; r | n -> n in fib_tbl . ( 0 ... |
let max_length = min_len . ( Array . length min_len - 1 ) |
let concat_fast l r = match l with Empty -> r | Leaf _ | Concat ( _ , _ , _ , _ , _ ) -> match r with Empty -> l | Leaf _ | Concat ( _ , _ , _ , _ , _ ) -> make_concat l r |
let add_forest forest rope len = let i = ref 0 in let sum = ref empty in while len > min_len . ( ! i + 1 ) do if forest . ( ! i ) . c <> Empty then begin sum := concat_fast forest . ( ! i ) . c ! sum ; forest . ( ! i ) . c <- Empty end ; incr i done ; sum := concat_fa... |
let concat_forest forest = Array . fold_left ( fun s x -> concat_fast x . c s ) Empty forest |
let rec balance_insert rope len forest = match rope with Empty -> ( ) | Leaf _ -> add_forest forest rope len | Concat ( l , cl , r , cr , h ) when h >= max_height || len < min_len . ( h ) -> balance_insert l cl forest ; balance_insert r cr forest | x -> add_forest forest x len |
let balance r = match r with Empty -> Empty | Leaf _ -> r | _ -> let forest = Array . init max_height ( fun _ -> { c = Empty ; len = 0 } ) in balance_insert r ( length r ) forest ; concat_forest forest |
let bal_if_needed l r = let r = make_concat l r in if height r < max_height then r else balance r |
let concat_str l = function Empty | Concat ( _ , _ , _ , _ , _ ) -> invalid_arg " concat_str " | Leaf rs as r -> let lenr = STRING . length rs in match l with | Empty -> r | Leaf ls -> let slen = lenr + STRING . length ls in if slen <= leaf_size then Leaf ( str_append ls rs ) e... |
let append_char c r = concat_str r ( Leaf ( STRING . make 1 c ) ) |
let concat l = function Empty -> l | Leaf _ as r -> concat_str l r | Concat ( Leaf rls , rlc , rr , rc , h ) as r -> ( match l with Empty -> r | Concat ( _ , _ , _ , _ , _ ) -> bal_if_needed l r | Leaf ls -> let slen = rlc + STRING . length ls in if slen <= leaf_size then... |
let prepend_char c r = concat ( Leaf ( STRING . make 1 c ) ) r |
let rec get i = function Empty -> raise Out_of_bounds | Leaf s -> if i >= 0 && i < STRING . length s then STRING . unsafe_get s i else raise Out_of_bounds | Concat ( l , cl , r , _ , _ ) -> if i < cl then get i l else get ( i - cl ) r |
let rec getn i = function Empty -> raise Out_of_bounds | Leaf _ -> 0 | Concat ( l , cl , r , _ , _ ) -> if i < cl then 1 + getn i l else 1 + getn ( i - cl ) r |
let rec set i v = function Empty -> raise Out_of_bounds | Leaf s -> if i >= 0 && i < STRING . length s then let s = Bytes . of_string s in Bytes . unsafe_set s i v ; Leaf ( Bytes . unsafe_to_string s ) else raise Out_of_bounds | Concat ( l , cl , r , _ , _ ) -> if i < cl then con... |
let of_string = function s when STRING . length s = 0 -> Empty | s -> let min ( x : int ) ( y : int ) = if x <= y then x else y in let rec loop r s len i = if i < len then loop ( concat r ( Leaf ( STRING . sub s i ( min ( len - i ) leaf_size ) ) ) ) s len ( i + leaf_size ... |
let rec make len c = let rec concatloop len i r = if i <= len then concatloop len ( i * 2 ) ( concat r r ) else r in if len = 0 then Empty else if len <= leaf_size then Leaf ( STRING . make len c ) else let rope = concatloop len 2 ( of_string ( STRING . make 1 c ) ) in concat rope ( ... |
let rec sub start len = function Empty -> if start <> 0 || len <> 0 then raise Out_of_bounds else Empty | Leaf s -> if len > 0 then ( try Leaf ( STRING . sub s start len ) with _ -> raise Out_of_bounds ) else if len < 0 || start < 0 || start > STRING . length s then raise Out_of_bounds e... |
let insert start rope r = concat ( concat ( sub 0 start r ) rope ) ( sub start ( length r - start ) r ) |
let remove start len r = concat ( sub 0 start r ) ( sub ( start + len ) ( length r - start - len ) r ) |
let to_string r = let rec strings l = function Empty -> l | Leaf s -> s :: l | Concat ( left , _ , right , _ , _ ) -> strings ( strings l right ) left in string_of_string_list ( strings [ ] r ) |
let rec iter f = function Empty -> ( ) | Leaf s -> STRING . iter f s | Concat ( l , _ , r , _ , _ ) -> iter f l ; iter f r |
let iteri f r = let rec aux f i = function Empty -> ( ) | Leaf s -> for j = 0 to STRING . length s - 1 do f ( i + j ) ( STRING . unsafe_get s j ) done | Concat ( l , cl , r , _ , _ ) -> aux f i l ; aux f ( i + cl ) r in aux f 0 r |
let rec rangeiter f start len = function Empty -> if start <> 0 || len <> 0 then raise Out_of_bounds | Leaf s -> let n = start + len in let lens = STRING . length s in if start >= 0 && len >= 0 && n <= lens then for i = start to n - 1 do f ( STRING . unsafe_get s i ) done else raise Out_of... |
let rec fold f a = function Empty -> a | Leaf s -> let acc = ref a in for i = 0 to STRING . length s - 1 do acc := f ! acc ( STRING . unsafe_get s i ) done ; ! acc | Concat ( l , _ , r , _ , _ ) -> fold f ( fold f a l ) r |
let set_title _ config soup = let make_title_string default prepend append title_opt = match title_opt with | None -> default | Some title -> let title = Printf . sprintf " % s % s " prepend title in let title = Printf . sprintf " % s % s " title append in title in let valid_options = List . ... |
type gifFrame = { imagephoto : imagePhoto ; frameWidth : int ; frameHeight : int ; left : int ; top : int ; delay : int } |
type animatedGif = { frames : gifFrame list ; animWidth : int ; animHeight : int ; loop : int } |
type imageType = | Still of Tk . options | Animated of animatedGif |
let debug = ref false |
let cTKtoCAMLgifFrame s = match splitlist s with | [ photo ; width ; height ; left ; top ; delay ] -> { imagephoto = cTKtoCAMLimagePhoto photo ; frameWidth = int_of_string width ; frameHeight = int_of_string height ; left = int_of_string left ; top = int_of_string top ; delay = int_of... |
let cTKtoCAMLanimatedGif s = match splitlist s with | [ width ; height ; frames ; loop ] -> { frames = List . map cTKtoCAMLgifFrame ( splitlist frames ) ; animWidth = int_of_string width ; animHeight = int_of_string height ; loop = int_of_string loop } | _ -> raise ( Invalid_argume... |
let available ( ) = let packages = splitlist ( Protocol . tkEval [ | TkToken " package " ; TkToken " names " ] ) | in List . mem " Tkanim " packages |
let create file = let s = Protocol . tkEval [ | TkToken " animation " ; TkToken " create " ; TkToken file ] | in let anmgif = cTKtoCAMLanimatedGif s in match anmgif . frames with | [ ] -> raise ( TkError " Null frame in a gif " ) ? | [ x ] -> Still ( ImagePhoto x . imag... |
let delete anim = List . iter ( fun { imagephoto = i } -> Imagephoto . delete i ) anim . frames |
let width anm = anm . animWidth |
let height anm = anm . animHeight |
let images anm = List . map ( fun x -> x . imagephoto ) anm . frames |
let image_existence_check img = try ignore ( Imagephoto . height img ) with TkError s -> prerr_endline ( " tkanim : " ^ s ) ; raise ( TkError s ) |
let imagephoto_copy dst src opts = image_existence_check src ; Imagephoto . copy dst src opts |
let animate_gen w i anim = let length = List . length anim . frames in let frames = Array . of_list anim . frames in let current = ref 0 in let loop = ref anim . loop in let f = frames . ( ! current ) in imagephoto_copy i f . imagephoto [ ImgTo ( f . left , f . top , f . left + ... |
let animate label anim = let i = Imagephoto . create [ Width ( Pixels anim . animWidth ) ; Height ( Pixels anim . animHeight ) ] in bind label [ [ ] , Destroy ] ( BindExtend ( [ ] , ( fun _ -> Imagephoto . delete i ) ) ) ; Label . configure label [ ImagePhoto ... |
let animate_canvas_item canvas tag anim = let i = Imagephoto . create [ Width ( Pixels anim . animWidth ) ; Height ( Pixels anim . animHeight ) ] in bind canvas [ [ ] , Destroy ] ( BindExtend ( [ ] , ( fun _ -> Imagephoto . delete i ) ) ) ; Canvas . configure_im... |
let gifdata s = let tmp_dir = ref Filename . temp_dir_name in let mktemp = let cnter = ref 0 and pid = Unix . getpid ( ) in ( function prefx -> incr cnter ; ( Filename . concat ! tmp_dir ( prefx ^ string_of_int pid ^ " . " ^ string_of_int ! cnter ) ) ) in let fname = mktemp " ... |
let rec find_loc_expression char_start char_stop expr = if char_start = expr . Typedtree . exp_loc . Location . loc_start && char_stop = expr . Typedtree . exp_loc . Location . loc_end then raise ( Found expr ) ; if char_start >= expr . Typedtree . exp_loc . Location . loc_start && c... |
let line_column_to_char_number lines_mappping line char = ( lines_mappping . ( line ) ) + char ; ; |
let char_number_to_line_column lines_mappping char_number = let max_l = Array . length lines_mappping in let rec find l = if l > max_l then assert false ; if char_number < lines_mappping . ( l ) then begin let line = l - 1 in let char = char_number - lines_mappping . ( l - 1 ) in ( line , ... |
let create_mark_radical = let cpt = ref 0 in function ( ) -> let name = " MARK " ^ ( string_of_int ! cpt ) in incr cpt ; name ; ; |
let create_popup parent_w expression = let new_window = Toplevel . create parent_w [ ] in Wm . title_set new_window " Zoom " ; let label0_w = Label . create new_window [ Text " Type of expression " ] in let text0_w = Text . create new_window [ Background ( NamedColor " LightSteelBlue... |
let make_callback widget lines_mappping syntax_tree _ = try begin let ( line , char ) = ( match Text . index widget ( TextIndex ( TagFirst " sel " , [ ] ) ) with LineChar ( l , c ) -> ( l - 1 , c ) | _ -> assert false ) in let char_start = line_column_to_char_number l... |
let load_source widget filename syntax_tree = let in_channel = Stdlibpath . open_in_with_path filename in let char_of_begin_line = ref 0 in let current_mapping = ref [ ] in try while true do current_mapping := ! char_of_begin_line :: ! current_mapping ; let l = ( input_line in_channel ) " ^\ n ... |
let scan_string pcontext s pos num = let text_w = pcontext . Printcontext . widget in let tag_buffer = pcontext . Printcontext . tag_buffer in let tag_scan_flag = pcontext . Printcontext . tag_scan_flag in let start = ref pos in for i = pos to pos + num - 1 do match s . [ i ] with | ' \ 0... |
let scan_string_at pcontext index s pos num = let text_w = pcontext . Printcontext . widget in let tag_buffer = pcontext . Printcontext . tag_buffer in let tag_scan_flag = pcontext . Printcontext . tag_scan_flag in let left_indent = pcontext . Printcontext . left_indent in let start = ref pos in f... |
let create_mark_radical = let cpt = ref 0 in function ( ) -> let name = " MARK " ^ ( string_of_int ! cpt ) in incr cpt ; name ; ; |
let pp_label_description pcontext ppf lbl_desc = fprintf ppf " % a :@ % a " Printbasic . pp_mutable_flag lbl_desc . Typedtree . fld_mut ( Tkprinttypes . pp_ml_type_scheme pcontext ) lbl_desc . Typedtree . fld_scheme ; ; |
let rec pp_signature pcontext ppf signature = let iter_pp_signature_item = Printbasic . iter_pp " " ( pp_signature_item pcontext ) in fprintf ppf " % a " iter_pp_signature_item signature | Typedtree . Tsig_value ( ident , scheme ) -> let mark_r = create_mark_radical ( ) in let pcontext '... |
let jobs : ( unit -> unit ) Queue . t = Queue . create ( ) |
let m = Mutex . create ( ) |
let with_jobs f = Mutex . lock m ; let y = f jobs in Mutex . unlock m ; y |
let loop_id = ref None |
let gui_safe ( ) = ! loop_id = Some ( Thread . id ( Thread . self ( ) ) ) |
let running ( ) = ! loop_id <> None |
let has_jobs ( ) = not ( with_jobs Queue . is_empty ) |
let n_jobs ( ) = with_jobs Queue . length |
let do_next_job ( ) = with_jobs Queue . take ( ) |
let async j x = with_jobs ( Queue . add ( fun ( ) -> j x ) ) |
let sync f x = if ! loop_id = None then failwith " Tkthread . sync " ; if gui_safe ( ) then f x else let m = Mutex . create ( ) in let res = ref None in Mutex . lock m ; let c = Condition . create ( ) in let j x = let y = f x in Mutex . lock m ; res := Some y ; Mutex . unloc... |
let rec job_timer ( ) = Timer . set ~ ms : 10 ~ callback : ( fun ( ) -> for i = 1 to n_jobs ( ) do do_next_job ( ) done ; job_timer ( ) ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.