text
stringlengths
0
601k
let extend_block env eq_list ( { b_vars = b_vars ; b_env = b_env ; b_body = body_eq_list } as b ) = let b_vars = Env . fold ( fun i entry acc -> vardec_from_entry i entry :: acc ) env b_vars in { b with b_vars = b_vars ; b_body = eq_list @ body_eq_list ; b_env = Env . append env b_env }
let make_block env eq_list = extend_block env eq_list { b_vars = [ ] ; b_env = Env . empty ; b_locals = [ ] ; b_body = [ ] ; b_loc = Zlocation . no_location ; b_write = Deftypes . empty }
let eq_make n e = eqmake ( EQeq ( varpat n e . e_typ , e ) )
let eq_next n e = eqmake ( EQnext ( n , e , None ) )
let eq_init n e = eqmake ( EQinit ( n , e ) )
let pluseq_make n e = eqmake ( EQpluseq ( n , e ) )
let eq_reset eq_list e = eqmake ( EQreset ( eq_list , e ) )
let eq_match e l = eqmake ( EQmatch ( ref true , e , l ) )
let eq_block b = eqmake ( EQblock ( b ) )
let eq_der x e = eqmake ( EQder ( x , e , None , [ ] ) )
let handler p b = { m_pat = p ; m_body = b ; m_env = Env . empty ; m_reset = false ; m_zero = false }
let eq_ifthenelse e b1 b2 = eq_match e [ handler truepat b1 ; handler falsepat b2 ]
let eq_ifthen e b = eqmake ( EQmatch ( ref false , e , [ handler truepat b ] ) )
let before eq_list = match eq_list with | [ ] -> assert false | [ eq ] -> eq | _ -> eqmake ( EQbefore ( eq_list ) )
let par eq_list = match eq_list with | [ ] -> assert false | [ eq ] -> eq | _ -> eqmake ( EQand ( eq_list ) )
let init i eq_list = ( eq_init i etrue ) :: ( eq_make i efalse ) :: eq_list
let new_major env = let m = Zident . fresh " major " in let env = Env . add m { t_sort = Deftypes . major ( ) ; t_typ = Initial . typ_bool } env in let major = var m Initial . typ_bool in env , major
let major env = let exception Return of Zelus . exp in let find x t = match t with | { t_sort = Smem { m_kind = Some ( Major ) } ; t_typ = typ } -> raise ( Return ( var x typ ) ) | _ -> ( ) in try Env . iter find env ; new_major env with | Return ( x ) -> env , x
type table = cont Env . t and cont = { mutable c_vars : S . t ; mutable c_useful : bool ; mutable c_visited : bool ; }
let print ff table = let names ff l = Pp_tools . print_list_r Printer . name " { " " , " " } " ff ( S . elements l ) in let entry x { c_vars = l ; c_useful = u } = Format . fprintf ff " [ @% a -> { c_vars = % a ; c_useful = % s } ] @@ " Env . iter entry table
let add is_useful w r table = let mark_useful set table = let mark x table = try table with | Not_found -> S . fold mark set table in let add x table = try let { c_vars = l ; c_useful = u } as cont = Env . find x table in cont . c_vars <- S . union r l ; cont . c_useful <- u || is_useful ; table with | Not_found -> Env...
let extend table names = Env . map ( fun ( { c_vars = l } as cont ) -> { cont with c_vars = S . union l names } ) table
let merge table1 table2 = let add x ( { c_vars = l1 ; c_useful = u1 } as cont1 ) table = try let ( { c_vars = l2 ; c_useful = u2 } as cont2 ) = Env . find x table in cont2 . c_vars <- S . union l1 l2 ; cont2 . c_useful <- u1 || u2 ; table with | Not_found -> Env . add x cont1 table in Env . fold add table2 table1
let rec build_equation table { eq_desc = desc } = match desc with | EQeq ( p , e ) -> let w = fv_pat S . empty S . empty p in let r = fve S . empty e in add ( Unsafe . exp e ) w r table | EQpluseq ( n , e ) | EQinit ( n , e ) | EQder ( n , e , None , [ ] ) -> let r = fve S . empty e in add ( Unsafe . exp e ) ( S . sing...
let visit read table = let useful = ref S . empty in let rec visit x ( { c_vars = l ; c_useful = u ; c_visited = v } as entry ) = if not v then begin entry . c_visited <- true ; entry . c_useful <- true ; useful := S . add x ! useful ; end and visit_fathers x = useful := S . add x ! useful ; try let entry = Env . find ...
let is_empty_block { b_locals = l ; b_body = eq_list } = ( l = [ ] ) && ( eq_list = [ ] )
let writes useful { dv = dv ; di = di ; der = der ; nv = nv ; mv = mv } = let filter set = S . filter ( fun x -> S . mem x useful ) set in { dv = filter dv ; di = filter di ; der = filter der ; nv = filter nv ; mv = filter mv }
let rec pattern useful ( { p_desc = desc } as p ) = match desc with | Ewildpat | Econstpat _ | Econstr0pat _ -> p | Etuplepat ( p_list ) -> { p with p_desc = Etuplepat ( List . map ( pattern useful ) p_list ) } | Econstr1pat ( c , p_list ) -> { p with p_desc = Econstr1pat ( c , List . map ( pattern useful ) p_list ) } ...
let rec remove_equation useful match desc with | EQeq ( p , e ) -> let w = fv_pat S . empty S . empty p in if Unsafe . exp e || S . exists ( fun x -> S . mem x useful ) w then { eq with eq_desc = EQeq ( pattern useful p , e ) } :: eq_list else eq_list | EQpluseq ( n , e ) | EQder ( n , e , None , [ ] ) | EQinit ( n , e...
let horizon read { l_env = l_env } = let take h { t_sort = sort } acc = match sort with | Smem { m_kind = Some ( Horizon ) } -> S . add h acc | _ -> acc in Env . fold take l_env read
let exp ( { e_desc = desc } as e ) = match desc with | Elet ( l , e_let ) -> let read = fve S . empty e_let in let read = horizon read l in let table = build_local Env . empty l in let useful = visit read table in let { l_eq = eq_list } as l = remove_local useful l in if eq_list = [ ] then e_let else { e with e_desc = ...
let implementation impl = match impl . desc with | Eopen _ | Etypedecl _ | Econstdecl _ -> impl | Efundecl ( n , ( { f_body = e } as body ) ) -> { impl with desc = Efundecl ( n , { body with f_body = exp e } ) }
let implementation_list impl_list = Zmisc . iter implementation impl_list
module StringSet = Set . Make ( struct type t = string let compare = compare end )
let add bv ln = match ln with | Modname { qual = s ; id = _ } -> if not ( StringSet . mem s ! bv ) then bv := StringSet . add s ! bv | Name _ -> ( )
let add_opt add_fn bv = function | None -> ( ) | Some x -> add_fn bv x
let add_default add_fn bv = function | Init v | Default v -> add_fn bv v
let rec add_size bv s = match s . desc with | Sconst _ -> ( ) | Sname id -> add bv id | Sop ( _ , s1 , s2 ) -> add_size bv s1 ; add_size bv s2
let rec add_type_expr bv ty = match ty . desc with | Etypevar _ -> ( ) | Etypeconstr ( id , tel ) -> add bv id ; List . iter ( add_type_expr bv ) tel | Etypetuple tl -> List . iter ( add_type_expr bv ) tl | Etypevec ( ty , s ) -> add_type_expr bv ty ; add_size bv s | Etypefun ( _ , _ , ty1 , ty2 ) -> add_type_expr bv t...
let rec add_interface bv i = match i . desc with | Einter_open s -> if not ( StringSet . mem s ! bv ) then bv := StringSet . add s ! bv | Einter_typedecl ( _ , _ , tdl ) -> add_type_decl bv tdl | Einter_constdecl ( _ , te ) -> add_type_expr bv te match td . desc with | Eabstract_type -> ( ) | Eabbrev te -> add_type_exp...
let file traverse initial_structures file = let bv = ref initial_structures in List . iter ( traverse bv ) file ; ! bv
let source_file ( ? initial_structures = StringSet . empty ) source = file add_implem initial_structures source
let interface_file ( ? initial_structures = StringSet . empty ) interface = file add_interface initial_structures interface
type char_prop = | Printable of int | Other | Null
let to_array t = Array . of_list ( Zed_utf8 . explode t ) t
let zero = String . make 1 ( Char . chr 0 ) 0
let core t = Zed_utf8 . unsafe_extract t 0
let combined t = List . tl ( Zed_utf8 . explode t ) t
let prop_uChar uChar = match CharInfo_width . width uChar with | - 1 -> Other | 0 -> if UChar . code uChar = 0 then Null else Printable 0 | w -> Printable w
let prop t = prop_uChar ( Zed_utf8 . unsafe_extract t 0 ) 0
let is_printable uChar = match prop_uChar uChar with | Printable _ -> true | _ -> false
let is_printable_core uChar = match prop_uChar uChar with | Printable w when w > 0 -> true | _ -> false
let is_combining_mark uChar = match prop_uChar uChar with | Printable w when w = 0 -> true | _ -> false
let width t = CharInfo_width . width ( Zed_utf8 . unsafe_extract t 0 ) 0
let out_of_range t i = i < 0 || i >= size t
let get_opt t i = try Some ( get t i ) i with _ -> None
let append ch mark = match prop_uChar mark with | Printable 0 -> ch ^ ( Zed_utf8 . singleton mark ) mark | _ -> failwith " combining mark expected "
let compare_core t1 t2 = let core1 = Zed_utf8 . unsafe_extract t1 0 and core2 = Zed_utf8 . unsafe_extract t2 0 in UChar . compare core1 core2
let mix_uChar zChar uChar = match prop_uChar uChar with | Printable 0 -> Ok ( zChar ^ ( Zed_utf8 . singleton uChar ) uChar ) uChar | _ -> Error ( Zed_utf8 . singleton uChar ) uChar
let first_core ( ? trim = false ) false uChars = let rec aux uChars = match uChars with | [ ] -> None , [ ] | uChar :: tl -> let prop = prop_uChar uChar in match prop with | Printable w -> if w > 0 then Some ( prop , uChar ) uChar , tl else aux tl | Other -> Some ( prop , uChar ) uChar , tl | Null -> Some ( prop , uCha...
let rec subsequent uChars = match uChars with | [ ] -> [ ] , [ ] | uChar :: tl -> let prop = prop_uChar uChar in match prop with | Printable w -> if w > 0 then [ ] , uChars else let seq , remain = subsequent tl in uChar :: seq , remain | _ -> [ ] , uChars
let of_uChars ( ? trim = false ) false ( ? indv_combining = true ) true uChars = match uChars with | [ ] -> None , [ ] | uChar :: tl -> match first_core ~ trim uChars with | None , _ -> if indv_combining then Some ( Zed_utf8 . singleton uChar ) uChar , tl else None , uChars | Some ( Printable _w , uChar ) uChar , tl ->...
let zChars_of_uChars ( ? trim = false ) false ( ? indv_combining = true ) true uChars = let rec aux zChars uChars = match of_uChars ~ trim ~ indv_combining uChars with | None , tl -> List . rev zChars , tl | Some zChar , tl -> aux ( zChar :: zChars ) zChars tl in aux [ ] uChars
let unsafe_of_utf8 : string -> t = fun str -> if String . length str > 0 then str else failwith " malformed Zed_char sequence "
let of_utf8 ( ? indv_combining = true ) true str = match of_uChars ~ indv_combining ( Zed_utf8 . explode str ) str with | Some zChar , [ ] -> zChar | _ -> failwith " malformed Zed_char sequence "
let to_utf8 : t -> string = id
let unsafe_of_char c = Zed_utf8 . singleton ( UChar . of_char c ) c
let unsafe_of_uChar uChar = Zed_utf8 . singleton uChar
module US ( USUS : UnicodeString . Type ) Type = struct module Convert = Zed_utils . Convert ( ConvertUS ) ConvertUS let of_t t = Zed_utf8 . explode t |> Convert . of_list let to_t us = let len = US . length us in let rec create i = if i < len then US . get us i :: create ( i + 1 ) 1 else [ ] in let uChars = create 0 i...
type changes = { position : int ; added : int ; removed : int ; added_width : int ; removed_width : int ; }
type action = | User_move of int | Text_modification of changes
type t = { position : int signal ; send : action -> unit ; length : int ref ; changes : changes event ; get_lines : unit -> Zed_lines . t ; coordinates : ( int * int ) int signal ; coordinates_display : ( int * int ) int signal ; line : int signal ; column : int signal ; column_display : int signal ; wanted_column : in...
let create length changes get_lines position wanted_column = if position < 0 || position > length then raise Out_of_bounds ; let length = ref length in let user_moves , send = E . create ( ) in let update_position position action = match action with | User_move pos -> pos | Text_modification changes -> let delta = chan...
let copy cursor = create ( ! cursor . length ) length cursor . changes cursor . get_lines ( S . value cursor . position ) position ( S . value cursor . wanted_column ) wanted_column
let position cursor = cursor . position
let get_position cursor = S . value cursor . position
let line cursor = cursor . line
let get_line cursor = S . value cursor . line
let column cursor = cursor . column
let column_display cursor = cursor . column_display
let get_column cursor = S . value cursor . column
let get_column_display cursor = S . value cursor . column_display
let coordinates cursor = cursor . coordinates
let coordinates_display cursor = cursor . coordinates
let get_coordinates cursor = S . value cursor . coordinates
let get_coordinates_display cursor = S . value cursor . coordinates_display
let wanted_column cursor = cursor . wanted_column
let get_wanted_column cursor = S . value cursor . wanted_column
let set_wanted_column cursor column = cursor . set_wanted_column column
let move cursor ( ? set_wanted_column = true ) true delta = let new_position = S . value cursor . position + delta in if new_position < 0 || new_position > ( ! cursor . length ) length then raise Out_of_bounds else begin cursor . send ( User_move new_position ) new_position ; if set_wanted_column then cursor . set_want...
let goto cursor ( ? set_wanted_column = true ) true position = if position < 0 || position > ( ! cursor . length ) length then raise Out_of_bounds else begin cursor . send ( User_move position ) position ; if set_wanted_column then cursor . set_wanted_column ( S . value cursor . column_display ) column_display end
type clipboard = { clipboard_get : unit -> Zed_rope . t ; clipboard_set : Zed_rope . t -> unit ; }
type ' a t = { mutable data : ' a option ; mutable text : Zed_rope . t ; mutable lines : Zed_lines . t ; changes : Zed_cursor . changes event ; send_changes : Zed_cursor . changes -> unit ; erase_mode : bool signal ; set_erase_mode : bool -> unit ; editable : int -> int -> bool ; clipboard : clipboard ; mutable mark : ...
let dummy_cursor = Zed_cursor . create 0 E . never ( fun ( ) -> Zed_lines . empty ) empty 0 0
let match_by_regexp_core re rope idx = match Zed_re . Core . regexp_match ~ sem ` : Longest re rope idx with | None -> None | Some arr -> match arr ( . 0 ) 0 with | Some ( Some_zip1 , zip2 ) zip2 -> Some ( SomeZed_rope . Zip . offset zip2 ) zip2 | None -> None
let match_by_regexp_raw re rope idx = match Zed_re . Raw . regexp_match ~ sem ` : Longest re rope idx with | None -> None | Some arr -> match arr ( . 0 ) 0 with | Some ( Some_zip1 , zip2 ) zip2 -> Some ( SomeZed_rope . Zip_raw . offset zip2 ) zip2 | None -> None
let regexp_word_core = let set = UCharInfo . load_property_set ` Alphabetic in let set = List . fold_left ( fun set ch -> USet . add ( UChar . of_char ch ) ch set ) set set [ ' 0 ' ; ' 1 ' ; ' 2 ' ; ' 3 ' ; ' 4 ' ; ' 5 ' ; ' 6 ' ; ' 7 ' ; ' 8 ' ; ' 9 ' ] ' 9 ' in Zed_re . Core . compile ( ` Repn ( Repn ` Set set , 1 , ...
let regexp_word_raw = let set = UCharInfo . load_property_set ` Alphabetic in let set = List . fold_left ( fun set ch -> USet . add ( UChar . of_char ch ) ch set ) set set [ ' 0 ' ; ' 1 ' ; ' 2 ' ; ' 3 ' ; ' 4 ' ; ' 5 ' ; ' 6 ' ; ' 7 ' ; ' 8 ' ; ' 9 ' ] ' 9 ' in Zed_re . Raw . compile ( ` Repn ( Repn ` Set set , 1 , No...
let new_clipboard ( ) = let r = ref ( Zed_rope . empty ( ) ) in { clipboard_get = ( fun ( ) -> ! r ) r ; clipboard_set = ( fun x -> r := x ) x }
let create ( ? editable = fun _pos _len -> true ) true ( ? move = ( ) ) + ? clipboard ( ? match_word = match_by_regexp_core regexp_word_core ) regexp_word_core ( ? locale = S . const None ) None ( ? undo_size = 1000 ) 1000 ( ) = let _ = move in let changes , send_changes = E . create ( ) in let erase_mode , set_erase_m...