text stringlengths 0 601k |
|---|
let string_of_constructor_arg = function Pcstr_tuple coretypes -> string_of_coretype { ptyp_desc = Ptyp_tuple coretypes ; ptyp_loc = Location . none ; ptyp_attributes = [ ] ; ptyp_loc_stack = [ ] } |
let rec dots_between = function [ ] -> " " |
let string_of_longident l = dots_between ( Longident . flatten l ) |
let rec to_string = function Unit -> " Unit " Printf . sprintf " Op ( % s , % s , % s ) " ( to_string_op op ) ( to_string l ) ( to_string r ) Printf . sprintf " And ( % s , % s ) " ( to_string a ) ( to_string b ) Printf . sprintf " Or ( % s , % s ) " ( to_string a ) ( to_string b ) Printf . sprintf " Cmp ( % s , % s , ... |
let rec bound_in_pattern = function PatAny -> [ ] |
let bound_in_bindings bindings = List . flatten ( List . map bound_in_pattern ( List . map fst bindings ) ) |
let begins_with n s = String . length n <= String . length s && n = String . sub s 0 ( String . length n ) |
let rec pattern_begins_with n = function PatVar s when begins_with n s -> true |
let binding_begins_with n ( p , e ) = pattern_begins_with n p |
let string_loc_begins_with n ( { txt } : string loc ) = begins_with n txt |
let bindings_beginning_with n env = option_map ( function envitem -> match envitem with EnvFunctor ( func_name , input_module_name , modtype , e , env ) -> if begins_with n func_name then Some envitem else None | EnvBinding ( recflag , bindings ) -> if List . for_all ( binding_begins_with n ) ! bindings then Some envit... |
let cut n s = String . sub s ( String . length n + 1 ) ( String . length s - String . length n - 1 ) |
let rec strip_pattern n = function PatVar s -> PatVar ( cut n s ) |
let strip_binding n ( p , e ) = ( strip_pattern n p , e ) |
let strip_constructor n c = match c with { pcd_name = ( { txt } as loc ) } -> { c with pcd_name = { loc with txt = cut n txt } } |
let strip_ptype_kind n = function Ptype_abstract -> Ptype_abstract |
let strip_typedecl n t = { t with ptype_name = { t . ptype_name with txt = cut n t . ptype_name . txt } ; ptype_kind = strip_ptype_kind n t . ptype_kind } |
let strip_bindings n = function EnvFunctor ( s , input_module_name , modtype , e , env ) -> EnvFunctor ( cut n s , input_module_name , modtype , e , env ) EnvBinding ( recflag , ref ( List . map ( strip_binding n ) ! bs ) ) EnvType ( recflag , List . map ( strip_typedecl n ) typedecls ) |
let open_module n ( env : env ) = List . map ( strip_bindings n ) ( bindings_beginning_with n env ) @ env |
let rec prefix_pattern prefix = function PatVar s -> PatVar ( prefix ^ " . " ^ s ) |
let prefix_binding prefix ( p , e ) = ( prefix_pattern prefix p , e ) |
let prefix_bindings p = function EnvBinding ( recflag , bs ) -> EnvBinding ( recflag , ref ( List . map ( prefix_binding p ) ! bs ) ) EnvFunctor ( p ^ n , input_module_name , modtype , e , env ) |
let alias_module current alias ( env : env ) = let replaced = List . map ( prefix_bindings alias ) ( List . map ( strip_bindings current ) ( bindings_beginning_with current env ) ) in replaced @ env |
let bindings_of_struct_item p = function | LetDef ( b , ld ) -> Some ( prefix_bindings p ( EnvBinding ( b , ref ld ) ) ) | _ -> None |
let open_struct_as_module name items ( env : env ) = let bindings = option_map ( bindings_of_struct_item name ) items in let top_level_binding = EnvBinding ( false , ref [ ( PatVar name , Struct ( false , items ) ) ] ) in top_level_binding :: bindings @ env |
let realops = ref false |
let rec tag_of_constructor_name_constdecls valnum blocknum str = function [ ] -> valnum , blocknum , None if args = [ ] then valnum , blocknum , Some valnum else valnum , blocknum , Some blocknum if args = [ ] then tag_of_constructor_name_constdecls ( valnum + 1 ) blocknum str t else tag_of_constructor_name_constdecls ... |
let rec tag_of_constructor_name_envtype valnum blocknum str ( recflag , typedecls ) = match typedecls with [ ] -> None | { ptype_kind = Ptype_variant constdecls } :: more -> begin match tag_of_constructor_name_constdecls valnum blocknum str constdecls with _ , _ , Some tag -> Some tag | valnum ' , blocknum ' , None -> ... |
let rec tag_of_constructor_name env str = match env with [ ] -> begin match str with " Invalid_argument " | " Failure " | " None " | " Some " | " Stream . Error " | " Stream . Failure " | " GenHashTable . EDead " | " GenHashTable . EFalse " | " GenHashTable . ETrue " -> 0 | _ -> 42 end | EnvType t :: more -> begin matc... |
let tag_of_constructor_name env str = try tag_of_constructor_name env str with e -> Printf . printf " TAG_OF_CONSTRUCTOR failed . . . . . " ; ! print_endline ( to_string_env env ) ; raise e |
let rec of_real_ocaml_expression_desc env = function Pexp_constant ( Pconst_integer ( s , None ) ) -> Int ( int_of_string s ) Cons ( of_real_ocaml env e , of_real_ocaml env e ' ) let str = string_of_longident txt in Constr ( tag_of_constructor_name env str , str , None ) let str = string_of_longident txt in Constr ( ta... |
let of_real_ocaml env x = let env ' , str = of_real_ocaml_structure env [ ] x in ( env ' , Struct ( false , str ) ) |
let _ = Ocamliprim . of_real_ocaml := of_real_ocaml |
let rec to_real_ocaml_expression_desc = function | Control ( _ , x ) -> to_real_ocaml_expression_desc x | Unit -> Pexp_construct ( { txt = Longident . Lident " ( ) " ; loc = Location . none } , None ) | Int i -> Pexp_constant ( Pconst_integer ( string_of_int i , None ) ) | String s -> Pexp_constant ( Pconst_string ( By... |
let to_real_ocaml = function | Struct ( _ , xs ) -> List . map ( function LetDef ( recflag , bindings ) -> { pstr_desc = Pstr_value ( ( if recflag then Recursive else Nonrecursive ) , List . map to_real_ocaml_binding bindings ) ; pstr_loc = Location . none } | x -> { pstr_desc = Pstr_eval ( to_real_ocaml x , [ ] ) ; ps... |
let extract_from_let = function LetDef ( _ , [ ( _ , e ) ] ) -> e |
let of_string s = match of_real_ocaml [ ] ( ast s ) with env , Struct ( _ , ( _ :: _ as l ) ) -> ( env , extract_from_let ( List . hd ( List . rev l ) ) ) | _ -> failwith " Tinyocaml . of_string " |
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 -> true is_value e && is_value e ' -> true Li... |
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 ) | Op ( op , a , b ) -> Op ( op , underline_redex a , b ) | And ( Bool fa... |
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 -> return acc s ) with Failed -> (... |
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 ^ if height r = 0 then " " \\ else " " in print prefixl... |
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 ) <- leaf_size + 1 ; fib_tbl . ( 1 ) <- 3 * leaf... |
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_fast ! sum rope ; let sum_len = ref ( length ! sum ) i... |
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 ) else make_concat l r | Concat ( ll , cll , ... |
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 Concat ( Leaf ( str_append ls rls ) , slen , rr... |
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 concat ( set i v l ) r else concat l ( set ... |
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 ) else r in loop Empty s ( STRING . length s ) 0 |
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 ( make ( len - length rope ) c ) |
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 else Empty | Concat ( l , cl , r ... |
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_bounds | Concat ( l , cl , r ... |
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 . append Config . common_widg... |
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_string delay } | _ -> raise ( Inva... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.