text stringlengths 12 786k |
|---|
let array_set_unsafe ~ array ~ index ~ new_value ( array_kind : P . Array_kind . t ) : H . expr_primitive = match array_kind with | Immediates | Values -> Ternary ( Array_set ( array_kind , Assignment Heap ) , array , index , new_value ) | Naked_floats -> Ternary ( Array_set ( N... |
let checked_arith_op ~ dbg ( bi : Lambda . boxed_integer option ) op mode arg1 arg2 : H . expr_primitive = let primitive , kind , zero , arg_wrap = match bi , mode with | None , None -> ( H . Binary ( Int_arith ( I . Tagged_immediate , op ) , arg1 , arg2 ) , K . value , ... |
let bbswap bi si mode arg : H . expr_primitive = let mode = Alloc_mode . from_lambda mode in Unary ( Box_number ( bi , mode ) , Prim ( Unary ( Int_arith ( si , Swap_byte_endianness ) , Prim ( Unary ( Unbox_number bi , arg ) ) ) ) ) |
let convert_lprim ~ big_endian ( prim : L . primitive ) ( args : Simple . t list ) ( dbg : Debuginfo . t ) : H . expr_primitive = let args = List . map ( fun arg : H . simple_or_prim -> Simple arg ) args in let size_int = assert ( Targetint . size mod 8 = 0 ) ; Targetint... |
let convert_and_bind acc ~ big_endian exn_cont ~ register_const_string ( prim : L . primitive ) ( ~ args : Simple . t list ) ( dbg : Debuginfo . t ) ( cont : Acc . t -> Flambda . Named . t option -> Acc . t * Expr_with_acc . t ) : Acc . t * Expr_with_acc . t = let expr ... |
module VB = Bound_var let highest_index_allowed = Targetint_31_63 . Imm . sub string_length_in_bytes result_size_in_bytes in if Targetint_31_63 . Imm . compare index_in_bytes highest_index_allowed >= 0 then Out_of_range else In_range ) * |
type failure = | Division_by_zero | Index_out_of_bounds |
type expr_primitive = | Simple of Simple . t | Nullary of Flambda_primitive . nullary_primitive | Unary of P . unary_primitive * simple_or_prim | Binary of P . binary_primitive * simple_or_prim * simple_or_prim | Ternary of P . ternary_primitive * simple_or_prim * simple_or_prim * simple_or_prim ... |
let rec print_expr_primitive ppf expr_primitive = let module W = Flambda_primitive . Without_args in match expr_primitive with | Simple simple -> Simple . print ppf simple | Nullary prim -> W . print ppf ( Nullary prim ) | Unary ( prim , _ ) -> W . print ppf ( Unary prim ) | Binary ( p... |
let print_simple_or_prim ppf ( simple_or_prim : simple_or_prim ) = match simple_or_prim with | Simple simple -> Simple . print ppf simple | Prim _ -> Format . pp_print_string ppf " < prim " > |
let print_list_of_simple_or_prim ppf simple_or_prim_list = Format . fprintf ppf " [ ( @% a ) ] " @ ( Format . pp_print_list ~ pp_sep : Format . pp_print_space print_simple_or_prim ) simple_or_prim_list |
let raise_exn_for_failure acc ~ dbg exn_cont exn_bucket extra_let_binding = let exn_handler = Exn_continuation . exn_handler exn_cont in let trap_action = Trap_action . Pop { exn_handler ; raise_kind = Some Regular } in let args = let extra_args = List . map ( fun ( simple , _kind ) -> simp... |
let expression_for_failure acc exn_cont ~ register_const_string primitive dbg ( failure : failure ) = let exn_cont = match exn_cont with | Some exn_cont -> exn_cont | None -> Misc . fatal_errorf " Validity checks for primitive @ % a @ may raise , but no exception \ continuation was supplied with t... |
let rec bind_rec acc exn_cont ~ register_const_string ( prim : expr_primitive ) ( dbg : Debuginfo . t ) ( cont : Acc . t -> Named . t -> Acc . t * Expr_with_acc . t ) : Acc . t * Expr_with_acc . t = match prim with | Simple simple -> let named = Named . create_simple simple in c... |
type ' a t = ' a CamlinternalLazy . t |
let from_fun ( f : unit -> ' arg ) = let x = Obj . new_block Obj . lazy_tag 1 in Obj . set_field x 0 ( Obj . repr f ) ; ( Obj . obj x : ' arg t ) |
let from_val ( v : ' arg ) = let t = Obj . tag ( Obj . repr v ) in if t = Obj . forward_tag || t = Obj . lazy_tag || t = Obj . double_tag then begin make_forward v end else begin ( Obj . magic v : ' arg t ) end |
let is_val ( l : ' arg t ) = Obj . tag ( Obj . repr l ) <> Obj . lazy_tag |
type ident = string * Syntax . location |
type tag_info = { id : string ; start : bool ; action : int } |
type regexp = Empty | Chars of int * bool | Action of int | Tag of tag_info | Seq of regexp * regexp | Alt of regexp * regexp | Star of regexp |
type tag_base = Start | End | Mem of int |
type tag_addr = Sum of ( tag_base * int ) |
type ident_info = | Ident_string of bool * tag_addr * tag_addr | Ident_char of bool * tag_addr |
type t_env = ( ident * ident_info ) list |
type ( ' args , ' action ) lexer_entry = { lex_name : string ; lex_regexp : regexp ; lex_mem_tags : int ; lex_actions : ( int * t_env * ' action ) list } |
type automata = Perform of int * tag_action list | Shift of automata_trans * ( automata_move * memory_action list ) array No_remember | Remember of int * tag_action list Backtrack | Goto of int | Copy of int * int | Set of int |
type ( ' args , ' action ) automata_entry = { auto_name : string ; auto_args : ' args ; auto_mem_size : int ; auto_initial_state : int * memory_action list ; auto_actions : ( int * t_env * ' action ) list } |
module Ints = Set . Make ( struct type t = int let compare ( x : t ) y = compare x y end ) |
let id_compare ( id1 , _ ) ( id2 , _ ) = String . compare id1 id2 |
let tag_compare t1 t2 = Stdlib . compare t1 t2 |
module Tags = Set . Make ( struct type t = tag_info let compare = tag_compare end ) |
module TagMap = Map . Make ( struct type t = tag_info let compare = tag_compare end ) |
module IdSet = Set . Make ( struct type t = ident let compare = id_compare end ) |
let rec do_remove_nested to_remove = function | Bind ( e , x ) -> if IdSet . mem x to_remove then do_remove_nested to_remove e else Bind ( do_remove_nested ( IdSet . add x to_remove ) e , x ) | Epsilon | Eof | Characters _ as e -> e | Sequence ( e1 , e2 ) -> Sequence ( do_remove_ne... |
let remove_nested_as e = do_remove_nested IdSet . empty e |
let stringset_delta s1 s2 = IdSet . union ( IdSet . diff s1 s2 ) ( IdSet . diff s2 s1 ) |
let rec find_all_vars = function | Characters _ | Epsilon | Eof -> IdSet . empty | Bind ( e , x ) -> IdSet . add x ( find_all_vars e ) | Sequence ( e1 , e2 ) | Alternative ( e1 , e2 ) -> IdSet . union ( find_all_vars e1 ) ( find_all_vars e2 ) | Repetition e -> find_all_v... |
let rec do_find_opt = function | Characters _ | Epsilon | Eof -> IdSet . empty , IdSet . empty | Bind ( e , x ) -> let opt , all = do_find_opt e in opt , IdSet . add x all | Sequence ( e1 , e2 ) -> let opt1 , all1 = do_find_opt e1 and opt2 , all2 = do_find_opt e2 in IdSet . un... |
let find_optional e = let r , _ = do_find_opt e in r |
let rec do_find_double = function | Characters _ | Epsilon | Eof -> IdSet . empty , IdSet . empty | Bind ( e , x ) -> let dbl , all = do_find_double e in ( if IdSet . mem x all then IdSet . add x dbl else dbl ) , IdSet . add x all | Sequence ( e1 , e2 ) -> let dbl1 , all1 =... |
let find_double e = do_find_double e |
let add_some x = function | Some i -> Some ( x + i ) | None -> None |
let add_some_some x y = match x , y with |
let rec do_find_chars sz = function | Epsilon | Eof -> IdSet . empty , IdSet . empty , sz | Characters _ -> IdSet . empty , IdSet . empty , add_some 1 sz | Bind ( e , x ) -> let c , s , e_sz = do_find_chars ( Some 0 ) e in begin match e_sz with | Some 1 -> IdSet . add x c ... |
let find_chars e = let c , s , _ = do_find_chars ( Some 0 ) e in IdSet . diff c s |
let chars = ref ( [ ] : Cset . t list ) |
let chars_count = ref 0 |
let rec encode_regexp char_vars act = function Epsilon -> Empty | Characters cl -> let n = ! chars_count in chars := cl :: ! chars ; incr chars_count ; Chars ( n , false ) | Eof -> let n = ! chars_count in chars := Cset . eof :: ! chars ; incr chars_count ; Chars ( n , true ) | Se... |
let mk_seq r1 r2 = match r1 , r2 with |
let add_pos p i = match p with |
let mem_name name id_set = IdSet . exists ( fun ( id_name , _ ) -> name = id_name ) id_set |
let opt_regexp all_vars char_vars optional_vars double_vars r = let env = Hashtbl . create 17 in let rec size_forward pos = function | Empty | Chars ( _ , true ) | Tag _ -> Some pos | Chars ( _ , false ) -> Some ( pos + 1 ) | Seq ( r1 , r2 ) -> begin match size_forward pos r1 wi... |
let encode_casedef casedef = let r = List . fold_left ( fun ( reg , actions , count , ntags ) ( expr , act ) -> let expr = remove_nested_as expr in let char_vars = find_chars expr in let r = encode_regexp char_vars count expr and opt_vars = find_optional expr and double_vars , all_vars = f... |
let encode_lexdef def = chars := [ ] ; chars_count := 0 ; let entry_list = List . map ( fun { name = entry_name ; args = args ; shortest = shortest ; clauses = casedef } -> let ( re , actions , _ , ntags ) = encode_casedef casedef in { lex_name = entry_name ; lex_regexp ... |
type t_transition = OnChars of int | ToAction of int |
type transition = t_transition * Tags . t |
let trans_compare ( t1 , tags1 ) ( t2 , tags2 ) = match Stdlib . compare t1 t2 with | 0 -> Tags . compare tags1 tags2 | r -> r |
module TransSet = Set . Make ( struct type t = transition let compare = trans_compare end ) |
let rec nullable = function | Empty | Tag _ -> true | Chars ( _ , _ ) | Action _ -> false | Seq ( r1 , r2 ) -> nullable r1 && nullable r2 | Alt ( r1 , r2 ) -> nullable r1 || nullable r2 | Star _ -> true |
let rec emptymatch = function | Empty | Chars ( _ , _ ) | Action _ -> Tags . empty | Tag t -> Tags . add t Tags . empty | Seq ( r1 , r2 ) -> Tags . union ( emptymatch r1 ) ( emptymatch r2 ) | Alt ( r1 , r2 ) -> if nullable r1 then emptymatch r1 else emptymatch r2 | Star ... |
let addtags transs tags = TransSet . fold ( fun ( t , tags_t ) r -> TransSet . add ( t , Tags . union tags tags_t ) r ) transs TransSet . empty |
let rec firstpos = function Empty | Tag _ -> TransSet . empty | Chars ( pos , _ ) -> TransSet . add ( OnChars pos , Tags . empty ) TransSet . empty | Action act -> TransSet . add ( ToAction act , Tags . empty ) TransSet . empty | Seq ( r1 , r2 ) -> if nullable r1 then Tr... |
let followpos size entry_list = let v = Array . make size TransSet . empty in let rec fill s = function | Empty | Action _ | Tag _ -> ( ) | Chars ( n , _ ) -> v . ( n ) <- s | Alt ( r1 , r2 ) -> fill s r1 ; fill s r2 | Seq ( r1 , r2 ) -> fill ( if nullable r2 then Tr... |
module StateSet = Set . Make ( struct type t = t_transition let compare = Stdlib . compare end ) |
module MemMap = Map . Make ( struct type t = int let compare ( x : t ) y = Stdlib . compare x y end ) |
type ' a dfa_state = { final : int * ( ' a * int TagMap . t ) ; others : ( ' a * int TagMap . t ) MemMap . t } |
let dfa_state_empty = { final ( = no_action , ( max_int , TagMap . empty ) ) ; others = MemMap . empty } act = no_action && o = MemMap . empty |
module StateSetSet = Set . Make ( struct type t = StateSet . t let compare = StateSet . compare end ) |
type t_equiv = { tag : tag_info ; equiv : StateSetSet . t } |
module MemKey = Set . Make ( struct type t = t_equiv let compare e1 e2 = match Stdlib . compare e1 . tag e2 . tag with | 0 -> StateSetSet . compare e1 . equiv e2 . equiv | r -> r end ) |
type dfa_key = { kstate : StateSet . t ; kmem : MemKey . t } |
let env_to_class m = let env1 = MemMap . fold ( fun _ ( tag , s ) r -> TagMap . update tag ( function | None -> Some ( StateSetSet . singleton s ) | Some ss -> Some ( StateSetSet . add s ss ) ) r ) m TagMap . empty in TagMap . fold ( fun tag ss r -> MemKey . add { tag =... |
let inverse_mem_map trans m r = TagMap . fold ( fun tag addr r -> MemMap . update addr ( function | None -> Some ( tag , StateSet . singleton trans ) | Some ( otag , s ) -> assert ( tag = otag ) ; Some ( tag , StateSet . add trans s ) ) r ) m r |
let inverse_mem_map_other n ( _ , m ) r = inverse_mem_map ( OnChars n ) m r |
let get_key { final ( = act , ( _ , m_act ) ) ; others = o } = let env = MemMap . fold inverse_mem_map_other o ( if act = no_action then MemMap . empty else inverse_mem_map ( ToAction act ) m_act MemMap . empty ) in let state_key = MemMap . fold ( fun n _ r -> StateSet . a... |
let key_compare k1 k2 = match StateSet . compare k1 . kstate k2 . kstate with |
module StateMap = Map . Make ( struct type t = dfa_key let compare = key_compare end ) |
let state_map = ref ( StateMap . empty : int StateMap . t ) |
let next_state_num = ref 0 |
let next_mem_cell = ref 0 |
let temp_pending = ref false |
let tag_cells = Hashtbl . create 17 |
let state_table = Table . create dfa_state_empty |
let reset_state ( ) = Stack . clear todo ; next_state_num := 0 ; let _ = Table . trim state_table in ( ) |
let reset_state_partial ntags = next_mem_cell := ntags ; Hashtbl . clear tag_cells ; temp_pending := false ; state_map := StateMap . empty |
let do_alloc_temp ( ) = temp_pending := true ; let n = ! next_mem_cell in n |
let do_alloc_cell used t = let available = try Hashtbl . find tag_cells t with Not_found -> Ints . empty in try Ints . choose ( Ints . diff available used ) with | Not_found -> temp_pending := false ; let n = ! next_mem_cell in if n >= 255 then raise Memory_overflow ; Hashtbl . replace tag_c... |
let is_old_addr a = a >= 0 |
let old_in_map m r = TagMap . fold ( fun _ addr r -> if is_old_addr addr then Ints . add addr r else r ) m r |
let alloc_map used m mvs = TagMap . fold ( fun tag a ( r , mvs ) -> let a , mvs = if is_new_addr a then let a = do_alloc_cell used tag in a , Ints . add a mvs else a , mvs in TagMap . add tag a r , mvs ) m ( TagMap . empty , mvs ) |
let create_new_state { final ( = act , ( _ , m_act ) ) ; others = o } = let used = MemMap . fold ( fun _ ( _ , m ) r -> old_in_map m r ) o ( old_in_map m_act Ints . empty ) in let new_m_act , mvs = alloc_map used m_act Ints . empty in let new_o , mvs = MemMap . fold... |
type new_addr_gen = { mutable count : int ; mutable env : int TagMap . t } |
let create_new_addr_gen ( ) = { count = - 1 ; env = TagMap . empty } |
let alloc_new_addr tag r = try TagMap . find tag r . env with | Not_found -> let a = r . count in r . count <- a - 1 ; r . env <- TagMap . add tag a r . env ; a |
let create_mem_map tags gen = Tags . fold ( fun tag r -> TagMap . add tag ( alloc_new_addr tag gen ) r ) tags TagMap . empty |
let create_init_state pos = let gen = create_new_addr_gen ( ) in let st = TransSet . fold ( fun ( t , tags ) st -> match t with | ToAction n -> let on , _otags = st . final in if n < on then { st with final = ( n , ( 0 , create_mem_map tags gen ) ) } else st | OnChars n ->... |
let get_map t st = match t with let ( _ , m ) = MemMap . find n st . others in m |
let dest = function | Copy ( d , _ ) | Set d -> d |
let sort_mvs mvs = let rec do_rec r mvs = match mvs with | [ ] -> r | _ -> let dests = List . fold_left ( fun r mv -> Ints . add ( dest mv ) r ) Ints . empty mvs in let rem , here = List . partition ( fun mv -> Ints . mem ( orig mv ) dests ) mvs in match here with | [ ] ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.