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 . add x let table = if is_useful then mark_useful r table else table in S . fold add w table |
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 . singleton n ) r table | EQmatch ( _ , e , m_h_list ) -> let r = fve S . empty e in let u = Unsafe . exp e in let table = add u S . empty r table in let table_b = List . fold_left merge table ( extend table_b r ) | EQreset ( res_eq_list , e ) -> let r = fve S . empty e in let u = Unsafe . exp e in let table = add u S . empty r table in let table_res = build_equation_list Env . empty res_eq_list in merge table ( extend table_res r ) | EQforall { for_index = i_list ; for_init = init_list ; for_body = b_eq_list } -> let index table { desc = desc } = match desc with | Einput ( i , e ) -> | Eoutput ( i , j ) -> | Eindex ( i , e1 , e2 ) -> let init table { desc = desc } = match desc with | Einit_last ( i , e ) -> let table = List . fold_left index table i_list in let table = List . fold_left init table init_list in build_block table b_eq_list | EQand ( eq_list ) | EQbefore ( eq_list ) -> build_equation_list table eq_list | EQblock _ | EQder _ | EQnext _ | EQautomaton _ | EQpresent _ | EQemit _ -> assert false List . fold_left build_equation table eq_list |
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 x table in visit x entry with Not_found -> ( ) and visit_table x ( { c_useful = u ; c_visited = v } as entry ) = if not v && u then visit x entry in S . iter visit_fathers read ; Env . iter visit_table table ; ! useful |
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 ) } | Evarpat ( x ) -> if S . mem x useful then p else { p with p_desc = Ewildpat } | Ealiaspat ( p_alias , x ) -> let p_alias = pattern useful p_alias in if S . mem x useful then { p with p_desc = Ealiaspat ( p_alias , x ) } else p_alias | Eorpat ( p1 , p2 ) -> { p with p_desc = Eorpat ( pattern useful p1 , pattern useful p2 ) } | Erecordpat ( ln_pat_list ) -> { p with p_desc = Erecordpat ( List . map ( fun ( ln , p ) -> ( ln , pattern useful p ) ) ln_pat_list ) } | Etypeconstraintpat ( p , ty_exp ) -> let p = pattern useful p in { p with p_desc = Etypeconstraintpat ( p , ty_exp ) } |
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 ) -> if Unsafe . exp e || S . mem n useful then eq :: eq_list else eq_list | EQmatch ( total , e , m_h_list ) -> let m_h_list = List . map if not ( Unsafe . exp e ) then eq_list else { eq with eq_desc = EQmatch ( total , e , m_h_list ) ; | EQreset ( res_eq_list , e ) -> let res_eq_list = remove_equation_list useful res_eq_list in if not ( Unsafe . exp e ) && res_eq_list = [ ] then eq_list else { eq with eq_desc = EQreset ( res_eq_list , e ) ; | EQforall ( { for_index = i_list ; for_init = init_list ; for_body = b_eq_list ; let index acc ( { desc = desc } as ind ) = match desc with | Einput ( i , e ) -> | Eoutput ( xo , o ) -> | Eindex _ -> let init acc ( { desc = desc } as ini ) = match desc with | Einit_last ( i , e ) -> let i_list = List . fold_left index [ ] i_list in let init_list = List . fold_left init [ ] init_list in let b_eq_list = remove_block useful b_eq_list in let in_env = Env . filter ( fun x entry -> S . mem x useful ) in_env in let out_env = Env . filter ( fun x entry -> S . mem x useful ) out_env in if is_empty_block b_eq_list then eq_list else { eq with eq_desc = EQforall { f_body with for_index = i_list ; | EQbefore ( before_eq_list ) -> let before_eq_list = remove_equation_list useful before_eq_list in if before_eq_list = [ ] then eq_list else ( Zaux . before before_eq_list ) :: eq_list | EQand ( and_eq_list ) -> let and_eq_list = remove_equation_list useful and_eq_list in if and_eq_list = [ ] then eq_list else ( Zaux . par and_eq_list ) :: eq_list | EQnext _ | EQder _ | EQautomaton _ | EQblock _ | EQpresent _ | EQemit _ -> assert false List . fold_right ( remove_equation useful ) eq_list [ ] ( { b_vars = n_list ; b_locals = l_list ; b_body = eq_list ; b_write = ( { dv = w } as defnames ) ; b_env = n_env } as b ) = let l_list = List . map ( remove_local useful ) l_list in let eq_list = remove_equation_list useful eq_list in let n_list = List . filter ( fun { vardec_name = x } -> S . mem x useful ) n_list in let n_env = Env . filter ( fun x entry -> S . mem x useful ) n_env in let w = S . filter ( fun x -> S . mem x useful ) w in { b with b_vars = n_list ; b_locals = l_list ; b_body = eq_list ; b_write = { defnames with dv = w } ; b_env = n_env } let eq_list = remove_equation_list useful eq_list in let l_env = Env . filter ( fun x entry -> S . mem x useful ) l_env in { l with l_eq = eq_list ; l_env = l_env } |
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 = Elet ( l , e_let ) } | _ -> e |
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 ty1 ; add_type_expr bv ty2 |
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_expr bv te | Evariant_type _ -> ( ) | Erecord_type l -> List . iter ( fun ( _ , te ) -> add_type_expr bv te ) l match i . desc with | Eopen s -> if not ( StringSet . mem s ! bv ) then bv := StringSet . add s ! bv ; | Etypedecl ( _ , _ , td ) -> add_type_decl bv td | Econstdecl ( _ , _ , e ) -> add_exp bv e | Efundecl ( _ , { f_args ; f_body ; _ } ) -> List . iter ( add_pattern bv ) f_args ; add_exp bv f_body match exp . desc with | Evar l -> add bv l | Econst _ -> ( ) | Econstr0 c -> add bv c | Econstr1 ( c , el ) -> add bv c ; List . iter ( add_exp bv ) el | Elast _ -> ( ) | Eapp ( _ , e , el ) -> add_exp bv e ; List . iter ( add_exp bv ) el | Eop ( op , el ) -> add_op bv op ; List . iter ( add_exp bv ) el | Etuple el -> List . iter ( add_exp bv ) el | Erecord_access ( e , id ) -> add_exp bv e ; add bv id | Erecord fields -> List . iter ( add_field bv ) fields | Erecord_with ( e , fields ) -> add_exp bv e ; List . iter ( add_field bv ) fields | Etypeconstraint ( e , ty ) -> add_exp bv e ; add_type_expr bv ty | Elet ( _ , pel , e ) -> List . iter ( add_eq bv ) pel ; add_exp bv e | Eseq ( e1 , e2 ) -> add_exp bv e1 ; add_exp bv e2 | Eperiod _ -> ( ) | Ematch ( e , mhl ) -> add_exp bv e ; List . iter ( add_match_handler add_exp bv ) mhl | Epresent ( phl , edo ) -> List . iter ( add_present_handler add_exp bv ) phl ; add_opt ( add_default add_exp ) bv edo | Eautomaton ( shl , seo ) -> List . iter ( add_state_handler add_exp bv ) shl ; add_opt add_state_exp bv seo | Ereset ( e1 , e2 ) -> add_exp bv e1 ; add_exp bv e2 | Eblock ( eqsb , body ) -> add_block add_eq_list bv eqsb ; add_exp bv body match op with | Efby | Eunarypre | Eifthenelse | Eminusgreater | Eup | Einitial | Edisc | Etest | Eaccess | Eupdate | Econcat | Eatomic -> ( ) | Eslice ( s1 , s2 ) -> add_size bv s1 ; add_size bv s2 match pat . desc with | Etuplepat pl -> List . iter ( add_pattern bv ) pl | Evarpat _ -> ( ) | Ewildpat -> ( ) | Econstpat _ -> ( ) | Econstr0pat c -> add bv c | Econstr1pat ( c , pl ) -> add bv c ; List . iter ( add_pattern bv ) pl | Ealiaspat ( p , _ ) -> add_pattern bv p | Eorpat ( p1 , p2 ) -> add_pattern bv p1 ; add_pattern bv p2 | Erecordpat pl -> List . iter ( fun ( lbl , p ) -> add bv lbl ; add_pattern bv p ) pl | Etypeconstraintpat ( p , ty ) -> add_pattern bv p ; add_type_expr bv ty match eq . desc with | EQeq ( p , e ) -> add_pattern bv p ; add_exp bv e | EQder ( _ , e , eo , phl ) -> add_exp bv e ; add_opt add_exp bv eo ; List . iter ( add_present_handler add_exp bv ) phl | EQinit ( _ , e ) | EQpluseq ( _ , e ) -> add_exp bv e | EQnext ( _ , e , eo ) -> add_exp bv e ; add_opt add_exp bv eo | EQemit ( _ , eo ) -> add_opt add_exp bv eo | EQautomaton ( shl , seo ) -> List . iter ( add_state_handler add_eq_list bv ) shl ; add_opt add_state_exp bv seo | EQpresent ( phl , bo ) -> List . iter ( add_present_handler ( add_block add_eq_list ) bv ) phl ; add_opt ( add_block add_eq_list ) bv bo | EQmatch ( e , mhl ) -> add_exp bv e ; List . iter ( add_match_handler ( add_block add_eq_list ) bv ) mhl | EQifthenelse ( e , bl , elsebl ) -> add_exp bv e ; add_block add_eq_list bv bl ; add_opt ( add_block add_eq_list ) bv elsebl | EQand eqs | EQbefore eqs -> add_eq_list bv eqs | EQreset ( eql , e ) -> List . iter ( add_eq bv ) eql ; add_exp bv e | EQblock block -> add_block add_eq_list bv block | EQforall handler -> add_forall_handler bv handler List . iter ( add_eq bv ) le fun a bv b -> let bb = b . desc in List . iter ( add_local bv ) bb . b_locals ; a bv bb . b_body let ( _ , eql ) = l . desc in List . iter ( add_eq bv ) eql match sp . desc with | Estate0pat _ -> ( ) | Estate1pat _ -> ( ) match se . desc with | Estate0 _ -> ( ) | Estate1 ( _ , el ) -> List . iter ( add_exp bv ) el add_scondpat bv e . e_cond ; add_opt ( add_block add_eq_list ) bv e . e_block ; add_state_exp bv e . e_next_state match scp . desc with | Econdand ( s1 , s2 ) -> add_scondpat bv s1 ; add_scondpat bv s2 | Econdor ( s1 , s2 ) -> add_scondpat bv s1 ; add_scondpat bv s2 | Econdexp e -> add_exp bv e | Econdon ( s , e ) -> add_scondpat bv s ; add_exp bv e | Econdpat ( e , p ) -> add_exp bv e ; add_pattern bv p fun a bv h -> add_pattern bv h . m_pat ; a bv h . m_body fun a bv h -> add_scondpat bv h . p_cond ; a bv h . p_body fun a bv { desc = h ; _ } -> add_statepat bv h . s_state ; add_block a bv h . s_block ; List . iter ( add_escape bv ) h . s_until ; List . iter ( add_escape bv ) h . s_unless List . iter ( add_index bv ) for_indexes ; List . iter ( add_init bv ) for_init ; add_block add_eq_list bv for_body match index . desc with | Einput ( _ , e ) -> add_exp bv e | Eoutput ( _ , _ ) -> ( ) | Eindex ( _ , e1 , e2 ) -> add_exp bv e1 ; add_exp bv e2 match init . desc with | Einit_last ( _ , e ) -> add_exp bv e |
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 , uChar ) uChar , tl in match uChars with | [ ] -> None , [ ] | uChar :: _ -> if not trim && is_combining_mark uChar then None , uChars else aux uChars |
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 combined , tl = subsequent tl in Some ( Zed_utf8 . implode ( uChar :: combined ) combined ) combined , tl | Some ( Null , uChar ) uChar , tl -> Some ( Zed_utf8 . singleton uChar ) uChar , tl | Some ( Other , uChar ) uChar , tl -> Some ( Zed_utf8 . singleton 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 in of_uChars uChars let to_t_exn us = match to_t us with | Some t , _ -> t | _ -> failwith " to_t_exn " end |
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 : int signal ; set_wanted_column : int -> unit ; } |
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 = changes . added - changes . removed in length := ! length + delta ; if ! length < 0 then raise Out_of_bounds ; if position > changes . position then begin if delta >= 0 then position + delta else if position < changes . position - delta then changes . position else position + delta end else position in let text_modifications = E . map ( fun x -> Text_modification x ) x changes in let position = S . fold update_position position ( E . select [ user_moves ; text_modifications ] text_modifications ) text_modifications in let compute_coordinates_and_display position = let lines = get_lines ( ) in let index = Zed_lines . line_index lines position in let bol = Zed_lines . line_start lines index in let column = position - bol in let width = Zed_lines . force_width lines bol column in ( index , column , bol , width ) width in let coordinates_and_display = S . map compute_coordinates_and_display position in let coordinates = S . map ( fun ( row , column , _ , _ ) _ -> ( row , column ) column ) column coordinates_and_display in let coordinates_display = S . map ( fun ( row , _ , _ , width ) width -> ( row , width ) width ) width coordinates_and_display in let line = S . map fst coordinates in let column = S . map snd coordinates in let column_display = S . map snd coordinates_display in let wanted_column , set_wanted_column = S . create wanted_column in { position ; send ; length ; changes ; get_lines ; coordinates ; coordinates_display ; line ; column ; column_display ; wanted_column ; set_wanted_column ; } |
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_wanted_column ( S . value cursor . column_display ) column_display end |
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 : Zed_cursor . t ; selection : bool signal ; set_selection : bool -> unit ; match_word : Zed_rope . t -> int -> int option ; locale : string option signal ; undo : ( Zed_rope . t * Zed_lines . t * int * int * int * int * int * int ) int array ; undo_size : int ; mutable undo_start : int ; mutable undo_index : int ; mutable undo_count : int ; } |
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 , None ) None ) None |
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 , None ) None ) None |
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_mode = S . create false in let selection , set_selection = S . create false in let clipboard = match clipboard with | Some clipboard -> clipboard | None -> new_clipboard ( ) in let edit = { data = None ; text = Zed_rope . empty ( ) ; lines = Zed_lines . empty ; changes ; send_changes ; erase_mode ; set_erase_mode ; editable ; clipboard ; mark = dummy_cursor ; selection ; set_selection ; match_word ; locale ; undo = Array . make undo_size ( Zed_rope . empty ( ) , Zed_lines . empty , 0 , 0 , 0 , 0 , 0 , 0 ) 0 ; undo_size ; undo_start = 0 ; undo_index = 0 ; undo_count = 0 ; } in edit . mark <- Zed_cursor . create 0 changes ( fun ( ) -> edit . lines ) lines 0 0 ; edit |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.