- Timestamp:
- Oct 11, 2011, 5:42:20 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Deliverables/D2.2/8051-indexed-labels-branch/src/common/costLabel.ml
r1328 r1357 20 20 type indexing = sexpr list 21 21 22 type const_indexing = int array22 type const_indexing = int ExtArray.t 23 23 24 (** [enter_loop n indexing] is used to update indexing when one is entering a 25 loop indexed by [n]. 26 The function recycles the same constant indexing *) 27 let rec enter_loop n indexing = match n with 28 | None -> () 29 | Some x -> try indexing.(x) <- 0 with | _ -> assert false 24 let const_ind_iter = ExtArray.iter 30 25 31 (** [enter_loop n indexing] is used to update indexing when one is continuing a 32 loop indexed by [n]. *) 33 let rec continue_loop n indexing = match n with 34 | None -> () 35 | Some x -> try indexing.(x) <- indexing.(x) + 1 with | _ -> assert false 26 let curr_const_ind = function 27 | hd :: _ -> hd 28 | _ -> invalid_arg "curr_const_ind applied to non-empty list" 29 30 let init_const_indexing () = ExtArray.make ~buff:1 0 0 31 32 let enter_loop_single indexing n = ExtArray.set indexing n 0 33 34 let continue_loop_single indexing n = 35 try 36 ExtArray.set indexing n (ExtArray.get indexing n + 1) 37 with | _ -> 38 invalid_arg "uninitialized loop index" 39 40 let curr_ind = function 41 | hd :: _ -> hd 42 | _ -> invalid_arg "non-empty indexing stack" 43 44 let enter_loop inds = enter_loop_single (curr_ind inds) 45 46 let continue_loop inds = continue_loop_single (curr_ind inds) 47 48 let enter_loop_opt indexing = Option.iter (enter_loop indexing) 49 50 let continue_loop_opt indexing = Option.iter (continue_loop indexing) 51 52 let new_const_ind inds = init_const_indexing () :: inds 53 54 let forget_const_ind = function 55 | _ :: inds -> inds 56 | _ -> invalid_arg "non-empty indexing stack" 36 57 37 58 let sexpr_of i l = … … 69 90 | s :: l -> 70 91 try 71 const_sexpr (ev_sexpr c.(i) s) :: compose_const_indexing_i (i+1) c l 92 const_sexpr (ev_sexpr (ExtArray.get c i) s) :: 93 compose_const_indexing_i (i+1) c l 72 94 with 73 | Invalid_argument _ -> assert false 95 | Invalid_argument _ -> 96 invalid_arg "constant indexing not enough to be applied" 74 97 75 98 module IndexingSet = Set.Make(struct … … 83 106 } 84 107 85 let apply_const_indexing c lbl =108 let ev_indexing c lbl = 86 109 {lbl with i = compose_const_indexing_i 0 c lbl.i} 87 110
Note: See TracChangeset
for help on using the changeset viewer.