text
stringlengths
12
786k
module PP = Camlp4 . Printers . OCamlr . Make Syntax ; let o = object inherit Ast . fold as super ; value accu = FV . S . empty ; method accu = accu ; method expr = fun [ << $ lid : s $ >> -> { < accu = FV . S . add s accu } > | e -> super # expr e ] ; end in ( o # ...
type tbl = { sb_var : Variable . t Variable . Map . t ; sb_mutable_var : Mutable_variable . t Mutable_variable . Map . t ; sb_exn : Static_exception . t Static_exception . Map . t ; back_var : Variable . t list Variable . Map . t ; back_mutable_var : Mutable_variable . t list M...
type t = | Inactive | Active of tbl
let empty_tbl = { sb_var = Variable . Map . empty ; sb_mutable_var = Mutable_variable . Map . empty ; sb_exn = Static_exception . Map . empty ; back_var = Variable . Map . empty ; back_mutable_var = Mutable_variable . Map . empty ; }
let print ppf = function | Inactive -> Format . fprintf ppf " Inactive " | Active tbl -> Format . fprintf ppf " Active :@ " ; Variable . Map . iter ( fun var1 var2 -> Format . fprintf ppf " % a -> % a @ " Variable . print var1 Variable . print var2 ) tbl . sb_var ; Mutable...
let is_empty = function | Inactive -> true | Active _ -> false
let empty_preserving_activation_state = function | Inactive -> Inactive | Active _ -> Active empty_tbl
let activate = function | Inactive -> Active empty_tbl | Active _ as t -> t
let rec add_sb_var sb id id ' = let sb = { sb with sb_var = Variable . Map . add id id ' sb . sb_var } in let sb = try let pre_vars = Variable . Map . find id sb . back_var in List . fold_left ( fun sb pre_id -> add_sb_var sb pre_id id ' ) sb pre_vars with Not_found -> sb in let back_...
let rec add_sb_mutable_var sb id id ' = let sb = { sb with sb_mutable_var = Mutable_variable . Map . add id id ' sb . sb_mutable_var ; } in let sb = try let pre_vars = Mutable_variable . Map . find id sb . back_mutable_var in List . fold_left ( fun sb pre_id -> add_sb_mutable_var sb pre_...
let apply_static_exception t i = match t with | Inactive -> i | Active t -> try Static_exception . Map . find i t . sb_exn with Not_found -> i
let add_static_exception t i = match t with | Inactive -> i , t | Active t -> let i ' = Static_exception . create ( ) in let sb_exn = Static_exception . Map . add i i ' t . sb_exn in i ' , Active { t with sb_exn ; }
let active_add_variable t id = let id ' = Variable . rename id in let t = add_sb_var t id id ' in id ' , t
let active_add_parameter t param = let param ' = Parameter . rename param in let t = add_sb_var t ( Parameter . var param ) ( Parameter . var param ' ) in param ' , t
let add_variable t id = match t with | Inactive -> id , t | Active t -> let id ' , t = active_add_variable t id in id ' , Active t
let active_add_parameters ' t ( params : Parameter . t list ) = List . fold_right ( fun param ( params , t ) -> let param ' , t = active_add_parameter t param in param ' :: params , t ) params ( [ ] , t )
let add_variables t defs = List . fold_right ( fun ( id , data ) ( defs , t ) -> let id ' , t = add_variable t id in ( id ' , data ) :: defs , t ) defs ( [ ] , t )
let add_variables ' t ids = List . fold_right ( fun id ( ids , t ) -> let id ' , t = add_variable t id in id ' :: ids , t ) ids ( [ ] , t )
let active_add_mutable_variable t id = let id ' = Mutable_variable . rename id in let t = add_sb_mutable_var t id id ' in id ' , t
let add_mutable_variable t id = match t with | Inactive -> id , t | Active t -> let id ' , t = active_add_mutable_variable t id in id ' , Active t
let active_find_var_exn t id = try Variable . Map . find id t . sb_var with | Not_found -> Misc . fatal_error ( Format . asprintf " find_var : can ' t find % a . " @ Variable . print id )
let apply_variable t var = match t with | Inactive -> var | Active t -> try Variable . Map . find var t . sb_var with | Not_found -> var
let apply_mutable_variable t mut_var = match t with | Inactive -> mut_var | Active t -> try Mutable_variable . Map . find mut_var t . sb_mutable_var with | Not_found -> mut_var
let rewrite_recursive_calls_with_symbols t ( function_declarations : Flambda . function_declarations ) ~ make_closure_symbol = match t with | Inactive -> function_declarations | Active _ -> let all_free_symbols = Variable . Map . fold ( fun _ ( function_decl : Flambda . function_declaration )...
module Project_var = struct type t = { vars_within_closure : Var_within_closure . t Var_within_closure . Map . t ; closure_id : Closure_id . t Closure_id . Map . t } let empty = { vars_within_closure = Var_within_closure . Map . empty ; closure_id = Closure_id . Map . empty ; } ...
let apply_function_decls_and_free_vars t fv func_decls ~ only_freshen_parameters = let module I = Project_var in let fv , t , of_closures = I . subst_free_vars fv t ~ only_freshen_parameters in let func_decls , t , of_closures = I . func_decls_subst of_closures t func_decls ~ only_freshen_parameters ...
let does_not_freshen t vars = match t with | Inactive -> true | Active subst -> not ( List . exists ( fun var -> Variable . Map . mem var subst . sb_var ) vars )
let freshen_projection ( projection : Projection . t ) ~ freshening ~ closure_freshening : Projection . t = match projection with | Project_var { closure ; closure_id ; var ; } -> Project_var { closure = apply_variable freshening closure ; closure_id = Project_var . apply_closure_id clo...
let freshen_projection_relation relation ~ freshening ~ closure_freshening = Variable . Map . map ( fun ( spec_to : Flambda . specialised_to ) -> let projection = match spec_to . projection with | None -> None | Some projection -> Some ( freshen_projection projection ~ freshening ~ closure_f...
let freshen_projection_relation ' relation ~ freshening ~ closure_freshening = Variable . Map . map ( fun ( ( spec_to : Flambda . specialised_to ) , data ) -> let projection = match spec_to . projection with | None -> None | Some projection -> Some ( freshen_projection projection ~ fr...
let create top opts navigation = let f = Frame . create top [ BorderWidth ( Pixels 2 ) ; Relief Raised ] in let lf = Frame . create f [ ] in let rf = Frame . create f [ ] in let c = Canvas . create lf [ BorderWidth ( Pixels 0 ) ] and xscroll = Scrollbar . create lf [ Orient...
let rec mapi f n l = match l with [ ] -> [ ] | x :: l -> let v = f n x in v ( :: mapi f ( succ n ) l )
let f w name title mesg bitmap def buttons = let t = Toplevel . create_named w name [ Class " Dialog " ] in Wm . title_set t title ; Wm . iconname_set t " Dialog " ; Wm . protocol_set t " WM_DELETE_WINDOW " ( function ( ) -> ( ) ) ; let ftop = Frame . create_named t " t...
let okcolor = NamedColor " # 3cb371 "
let new_vertical parent w h = let c = Canvas . create_named parent " fillbox " [ Width ( Pixels w ) ; Height ( Pixels h ) ; BorderWidth ( Pixels 1 ) ; Relief Sunken ] in let i = Canvas . create_rectangle c ( Pixels 0 ) ( Pixels 0 ) ( Pixels w ) ( Pixels 0 ) [ FillC...
let new_horizontal parent w h = let c = Canvas . create_named parent " fillbox " [ Width ( Pixels w ) ; Height ( Pixels h ) ; BorderWidth ( Pixels 1 ) ; Relief Sunken ] in let i = Canvas . create_rectangle c ( Pixels 0 ) ( Pixels 0 ) ( Pixels 0 ) ( Pixels h ) [ Fil...
let debug = ref false
let vert wid = let newsize = ref 0 and pending_resize = ref false and last_last = ref 0 . 0 in let rec resize ( ) = pending_resize := false ; if ! debug then ( Printf . eprintf " % s Resize % d \ n " ( Widget . name wid ) ! newsize ; flush stderr ) ; Text . configure wid [ ...
module StringSet = Set . Make ( struct type t = string let compare = compare end )
let available_fonts = ref ( StringSet . empty )
let get_canvas = Frx_misc . autodef ( fun ( ) -> Canvas . create Widget . default_toplevel [ ] )
let find fmly wght slant pxlsz = let fontspec = " " -*-^ fmly " " ^-^ wght " " ^-^ slant " ^- normal " -*-^ string_of_int pxlsz " ^-*-*-*-*-*- iso8859 - 1 " in if StringSet . mem fontspec ! available_fonts then fontspec else let c = get_canvas ( ) in try let tag = Canvas . creat...
let rec sort_options but lab com = function [ ] -> but , lab , com ( | Command f as o ) :: l -> sort_options ( o :: but ) lab com l ( | Bitmap b as o ) :: l -> sort_options ( o :: but ) lab com l ( | Text t as o ) :: l -> sort_options but ( o :: lab ) com l | o :: l -> s...
let create parent options = let but , lab , com = sort_options [ ] [ ] [ ] options in let f = Frame . create parent com in let b = Button . create f ( but @ com ) and l = Label . create f ( lab @ com ) in pack [ b ; l ] [ ] ; bind l [ [ ] , ButtonPressDetail 1 ]...
let configure f options = let but , lab , com = sort_options [ ] [ ] [ ] options in match Pack . slaves f with [ b ; l ] -> Frame . configure f com ; Button . configure b ( but @ com ) ; Label . configure l ( lab @ com ) | _ -> raise ( Invalid_argument " lbutton con...
let scroll_link sb lb = Listbox . configure lb [ YScrollCommand ( Scrollbar . set sb ) ] ; Scrollbar . configure sb [ ScrollCommand ( Listbox . yview lb ) ]
let add_completion lb action = let prefx = ref " " and maxi = Listbox . size lb - 1 and current = ref 0 and lastevent = ref 0 in let rec move_forward ( ) = if Listbox . get lb ( Number ! current ) < ! prefx then if ! current < maxi then begin incr current ; move_forward ( ) end and ...
let new_scrollable_listbox top options = let f = Frame . create top [ ] in let lb = Listbox . create f options and sb = Scrollbar . create f [ ] in scroll_link sb lb ; pack [ lb ] [ Side Side_Left ; Fill Fill_Both ; Expand true ] ; pack [ sb ] [ Side Side_Left ; Fill Fill_Y ] ...
let inited = ref None
let w = ref 300
let delay = ref 5
let wordsize = if 1 lsl 31 = 0 then 4 else 8
let init ( ) = let top = Toplevel . create Widget . default_toplevel [ Class " CamlGC " ] in let name = Camltk . appname_get ( ) in Wm . title_set top ( name ^ " Memory Gauge " ) ; Wm . withdraw top ; inited := Some top ; bind top [ [ ] , Destroy ] ( BindSet ( ...
let rec f ( ) = match ! inited with Some w -> Wm . deiconify w | None -> init ( ) ; f ( )
let autodef f = let v = ref None in ( function ( ) -> match ! v with None -> let x = f ( ) in v := Some x ; x | Some x -> x )
let create_photo options = let hasopt = ref None in List . iter ( function Data s -> begin match ! hasopt with None -> hasopt := Some ( Data s ) | Some _ -> raise ( Protocol . TkError " two data sources in options " ) end | File f -> begin match ! hasopt with None -> hasopt := Some ( F...
let open_simple title action notaction memory = let t = Toplevel . create Widget . default_toplevel [ Class " Dialog " ] in Focus . set t ; Wm . title_set t title ; let tit = Label . create t [ Text title ] in let len = max 40 ( String . length ( Textvariable . get memory ) ) ...
let open_simple_synchronous title memory = let t = Toplevel . create Widget . default_toplevel [ Class " Dialog " ] in Focus . set t ; Wm . title_set t title ; let tit = Label . create t [ Text title ] in let len = max 40 ( String . length ( Textvariable . get memory ) ) in le...
let open_list title elements action notaction = let t = Toplevel . create Widget . default_toplevel [ Class " Dialog " ] in Wm . title_set t title ; let tit = Label . create t [ Text title ] in let fls = Frame . create t [ Relief Sunken ; BorderWidth ( Pixels 2 ) ] in let lb = Li...
let open_passwd title = let username = ref " " and password = ref " " and cancelled = ref false in let t = Toplevel . create Widget . default_toplevel [ Class " Dialog " ] in Focus . set t ; Wm . title_set t title ; let tit = Label . create t [ Text title ] and fu , eu = Frx_e...
let register name f = let id = new_function_id ( ) in Hashtbl . add callback_naming_table id f ; Textvariable . set ( Textvariable . coerce ( " camltkrpc ( " ^ name " ) " ) ) ^ ( string_of_cbid id ) ; tkCommand [ | TkToken " proc " ; TkToken name ; TkToken " args "...
let invoke interp f args = tkEval [ | TkToken " send " ; TkToken interp ; TkToken f ; TkTokenList ( List . map ( fun s -> TkToken s ) args ) ] |
let async_invoke interp f args = tkCommand [ | TkToken " send " ; TkToken " - async " ; TkToken interp ; TkToken f ; TkTokenList ( List . map ( fun s -> TkToken s ) args ) ] |
let rpc_info interp = tkEval [ | TkToken " send " ; TkToken interp ; TkToken " array " ; TkToken " names " ; TkToken " camltkrpc " ] |
let events = Hashtbl . create 37
let get_event name = try Hashtbl . find events name with Not_found -> let h = Hashtbl . create 37 in Hashtbl . add events name h ; let var = " camltk_events ( " ^ name " ) " ^ in let tkvar = Textvariable . coerce var in let rec set ( ) = Textvariable . handle tkvar ( fun ( ) ...
let remove w name = Hashtbl . remove ( get_event name ) ( Widget . name w )
let bind w name f = remove w name ; Hashtbl . add ( get_event name ) ( Widget . name w ) f
let broadcast name = Textvariable . set ( Textvariable . coerce ( " camltk_events ( " ^ name " ) " ) ) ^ " all "
let send name w = Textvariable . set ( Textvariable . coerce ( " camltk_events ( " ^ name " ) " ) ) ^ ( Widget . name w )
let remove_callbacks w = Hashtbl . iter ( fun _ h -> Hashtbl . remove h ( Widget . name w ) ) events
let _ = add_destroy_hook remove_callbacks
let abs_index n = TextIndex ( LineChar ( 0 , 0 ) , [ CharOffset n ] )
let insertMark = TextIndex ( Mark " insert " , [ ] )
let currentMark = TextIndex ( Mark " current " , [ ] )
let textEnd = TextIndex ( End , [ ] )
let textBegin = TextIndex ( LineChar ( 0 , 0 ) , [ ] )
let scroll_link sb tx = Text . configure tx [ YScrollCommand ( Scrollbar . set sb ) ] ; Scrollbar . configure sb [ ScrollCommand ( Text . yview tx ) ]
let page_up tx = Text . yview tx ( ScrollPage ( - 1 ) )
let navigation_keys tx = let tags = bindtags_get tx in match tags with ( WidgetBindings t ) :: l when t = tx -> bindtags tx ( ( WidgetBindings tx ) :: ( TagBindings " TEXT_RO " ) :: l ) | _ -> ( )
let new_scrollable_text top options navigation = let f = Frame . create top [ ] in let tx = Text . create f options and sb = Scrollbar . create f [ ] in scroll_link sb tx ; pack [ sb ] [ Side Side_Right ; Fill Fill_Y ] ; pack [ tx ] [ Side Side_Left ; Fill Fill_Both ; Expand tr...
let patternv = Frx_misc . autodef Textvariable . create
let topsearch t = let top = Toplevel . create t [ Class " TextSearch " ] in Wm . title_set top " Text search " ; let f = Frame . create_named top " fpattern " [ ] in let m = Label . create_named f " search " [ Text " Search pattern " ] and e = Entry . create_named f " ...
let addsearch tx = let tags = bindtags_get tx in match tags with ( WidgetBindings t ) :: l when t = tx -> bindtags tx ( ( WidgetBindings tx ) :: ( TagBindings " SEARCH " ) :: l ) | _ -> ( )
let init ( ) = List . iter ( function ev -> tag_bind " TEXT_RO " ev ( BindSetBreakable ( [ Ev_Widget ] , ( fun ei -> page_up ei . ev_Widget ; break ( ) ) ) ) ) [ [ [ ] , KeyPressDetail " BackSpace " ] ; [ [ ] , KeyPressDetail " Delete " ] ; [ ...
let sort ( type s ) set l = let module Set = ( val set : Set . S with type elt = s ) in Set . elements ( List . fold_right Set . add l Set . empty )
let make_set ( type s ) cmp = let module S = Set . Make ( struct type t = s let compare = cmp end ) in ( module S : Set . S with type elt = s )
let both l = List . map ( fun set -> sort set l ) [ make_set compare ; make_set ( fun x y -> compare y x ) ]
let ( ) = print_endline ( String . concat " " ( List . map ( String . concat " " ) / ( both [ " abc " ; " xyz " ; " def " ] ) ) )
module type S = sig type t val to_string : t -> string val apply : t -> t val x : t end
let create ( type s ) to_string apply x = let module M = struct type t = s let to_string = to_string let apply = apply let x = x end in ( module M : S with type t = s )
let forget ( type s ) x = let module M = ( val x : S with type t = s ) in ( module M : S )
let print x = let module M = ( val x : S ) in print_endline ( M . to_string M . x )
let apply x = let module M = ( val x : S ) in let module N = struct include M let x = apply x end in ( module N : S )
let ( ) = let int = forget ( create string_of_int succ 0 ) in let str = forget ( create ( fun s -> s ) ( fun s -> s ^ s ) " X " ) in List . iter print ( List . map apply [ int ; apply int ; apply ( apply str ) ] )
module TypEq : sig type ( ' a , ' b ) t val apply : ( ' a , ' b ) t -> ' a -> ' b val refl : ( ' a , ' a ) t val sym : ( ' a , ' b ) t -> ( ' b , ' a ) t type ( ' a , ' b ) t = unit let apply _ = Obj . magic let refl = ( ) let sym ( ) ...
module rec Typ : sig module type PAIR = sig type t type t1 type t2 val eq : ( t , t1 * t2 ) TypEq . t val t1 : t1 Typ . typ val t2 : t2 Typ . typ end type ' a typ = | Int of ( ' a , int ) TypEq . t | String of ( ' a , string ) TypEq . t | Pair of ( module PAIR with type t ...
let int = Int TypEq . refl
let str = String TypEq . refl
let pair ( type s1 ) ( type s2 ) t1 t2 = let module P = struct type t = s1 * s2 type t1 = s1 type t2 = s2 let eq = TypEq . refl let t1 = t1 let t2 = t2 end in let pair = ( module P : PAIR with type t = s1 * s2 ) in Pair pair