- let null_result() = (pempty,Array.make slot_size RS.empty) in
-
- let rec loop t slist ctx =
- if t == Tree.nil then null_result() else get_trans t slist (Tree.tag tree t) ctx
- and loop_tag tag t slist ctx =
- if t == Tree.nil then null_result() else get_trans t slist tag ctx
- and loop_no_right t slist ctx =
- if t == Tree.nil then null_result() else get_trans ~noright:true t slist (Tree.tag tree t) ctx
- and get_trans ?(noright=false) t slist tag ctx =
- let cont =
- try
- CachedTransTable.find td_trans (tag,slist)
- with
- | Not_found ->
- let fl_list,llist,rlist,ca,da,sa,fa =
- SList.fold
- (fun set (fll_acc,lllacc,rllacc,ca,da,sa,fa) -> (* For each set *)
- let fl,ll,rr,ca,da,sa,fa =
- StateSet.fold
- (fun q acc ->
- List.fold_left
- (fun ((fl_acc,ll_acc,rl_acc,c_acc,d_acc,s_acc,f_acc) as acc)
- (ts,t) ->
- if (TagSet.mem tag ts)
- then
- let _,_,f,_ = Transition.node t in
- let (child,desc,below),(sibl,foll,after) = Formula.st f in
- (Formlist.cons t fl_acc,
- StateSet.union ll_acc below,
- StateSet.union rl_acc after,
- StateSet.union child c_acc,
- StateSet.union desc d_acc,
- StateSet.union sibl s_acc,
- StateSet.union foll f_acc)
- else acc ) acc (
- try Hashtbl.find a.trans q
- with
- Not_found -> Printf.eprintf "Looking for state %i, doesn't exist!!!\n%!"
- q;[]
- )
-
- ) set (Formlist.nil,StateSet.empty,StateSet.empty,ca,da,sa,fa)
- in fl::fll_acc, (SList.cons ll lllacc), (SList.cons rr rllacc),ca,da,sa,fa)
- slist ([],SList.nil,SList.nil,StateSet.empty,StateSet.empty,StateSet.empty,StateSet.empty)
- in
- (* Logic to chose the first and next function *)
- let _,tags_below,_,tags_after = Tree.tags tree tag in
-(* let _ = Printf.eprintf "Tags below %s are : \n" (Tag.to_string tag) in
- let _ = Ptset.Int.iter (fun i -> Printf.eprintf "%s " (Tag.to_string i)) tags_below in
- let _ = Printf.eprintf "\n%!" in *)
- let f_kind,first = choose_jump_down tree tags_below ca da a
- and n_kind,next = if noright then (`NIL, fun _ _ -> Tree.nil )
- else choose_jump_next tree tags_after sa fa a in
- let empty_res = null_result() in
- let cont =
- match f_kind,n_kind with
- | `NIL,`NIL ->
- (fun _ _ -> eval_fold2_slist fl_list t empty_res empty_res )
- | _,`NIL -> (
- match f_kind with
- |`TAG(tag) ->
- (fun t _ -> eval_fold2_slist fl_list t empty_res
- (loop_tag tag (first t) llist t))
- | `ANY ->
- (fun t _ -> eval_fold2_slist fl_list t empty_res
- (loop (first t) llist t))
- | _ -> assert false)
-
- | `NIL,_ -> (
- match n_kind with
- |`TAG(tag) ->
- (fun t ctx -> eval_fold2_slist fl_list t
- (loop_tag tag (next t ctx) rlist ctx) empty_res)
-
- | `ANY ->
- (fun t ctx -> eval_fold2_slist fl_list t
- (loop (next t ctx) rlist ctx) empty_res)
-
- | _ -> assert false)
-
- | `TAG(tag1),`TAG(tag2) ->
- (fun t ctx -> eval_fold2_slist fl_list t
- (loop (next t ctx) rlist ctx)
- (loop (first t) llist t))
-
- | `TAG(tag),`ANY ->
- (fun t ctx ->
- eval_fold2_slist fl_list t
- (loop (next t ctx) rlist ctx)
- (loop_tag tag (first t) llist t))
- | `ANY,`TAG(tag) ->
- (fun t ctx ->
- eval_fold2_slist fl_list t
- (loop_tag tag (next t ctx) rlist ctx)
- (loop (first t) llist t) )
- | `ANY,`ANY ->
- (fun t ctx ->
- eval_fold2_slist fl_list t
- (loop (next t ctx) rlist ctx)
- (loop (first t) llist t) )
- | _ -> assert false
- in
- let cont = D_IF_( (fun t ctx ->
- let a,b = cont t ctx in
- register_trace tree t (slist,a,fl_list,first,next,ctx);
- (a,b)
- ) ,cont)
- in
- (CachedTransTable.add td_trans (tag,slist) cont;cont)
- in cont t ctx
-
- in
- (if noright then loop_no_right else loop) t slist ctx
-
+
+ let null_result = (pempty,Array.copy rempty) in
+ let empty_res = null_result in
+
+ let rec loop t ctx slist _ =
+ if t == Tree.nil then null_result else
+ let tag = Tree.tag tree t in
+ (CodeCache.get_fun td_trans slist tag) t ctx slist tag false
+ (* get_trans t ctx slist tag false
+ (CodeCache.get_opcode td_trans slist tag)
+ *)
+ and loop_tag t ctx slist tag =
+ if t == Tree.nil then null_result else
+ (CodeCache.get_fun td_trans slist tag) t ctx slist tag false
+ (* get_trans t ctx slist tag false
+ (CodeCache.get_opcode td_trans slist tag) *)
+
+ and loop_no_right t ctx slist _ =
+ if t == Tree.nil then null_result else
+ let tag = Tree.tag tree t in
+ (CodeCache.get_fun td_trans slist tag) t ctx slist tag true
+ (* get_trans t ctx slist tag true
+ (CodeCache.get_opcode td_trans slist tag) *)
+ (*
+ and get_trans t ctx slist tag noright opcode =
+ match opcode with
+ | OpCode.K0 fll ->
+ eval_fold2_slist fll t tag empty_res empty_res
+
+ | OpCode.K1 (fll,first,llist,tag1) ->
+ eval_fold2_slist fll t tag empty_res
+ (loop_tag (first t) t llist tag1)
+
+ | OpCode.K2 (fll,first,llist) ->
+ eval_fold2_slist fll t tag empty_res
+ (loop (first t) t llist)
+
+ | OpCode.K3 (fll,next,rlist,tag2) ->
+ eval_fold2_slist fll t tag
+ (loop_tag (next t ctx) ctx rlist tag2)
+ empty_res
+ | OpCode.K4 (fll,next,rlist) ->
+ eval_fold2_slist fll t tag
+ (loop (next t ctx) ctx rlist)
+ empty_res
+
+ | OpCode.K5 (fll,next,rlist,tag2,first,llist,tag1) ->
+ eval_fold2_slist fll t tag
+ (loop_tag (next t ctx) ctx rlist tag2)
+ (loop_tag (first t) t llist tag1)
+
+ | OpCode.K6 (fll,next,rlist,first,llist,tag1) ->
+ eval_fold2_slist fll t tag
+ (loop (next t ctx) ctx rlist)
+ (loop_tag (first t) t llist tag1)
+
+ | OpCode.K7 (fll,next,rlist,tag2,first,llist) ->
+ eval_fold2_slist fll t tag
+ (loop_tag (next t ctx) ctx rlist tag2)
+ (loop (first t) t llist)
+
+ | OpCode.K8 (fll,next,rlist,first,llist) ->
+ eval_fold2_slist fll t tag
+ (loop (next t ctx) ctx rlist)
+ (loop (first t) t llist)
+
+ | OpCode.KDefault _ ->
+ mk_trans t ctx tag slist noright
+ *)
+ and mk_trans t ctx slist tag noright =
+ let fl_list,llist,rlist,ca,da,sa,fa =
+ SList.fold
+ (fun set (fll_acc,lllacc,rllacc,ca,da,sa,fa) -> (* For each set *)
+ let fl,ll,rr,ca,da,sa,fa =
+ StateSet.fold
+ (fun q acc ->
+ List.fold_left
+ (fun ((fl_acc,ll_acc,rl_acc,c_acc,d_acc,s_acc,f_acc) as acc)
+ (ts,t) ->
+ if (TagSet.mem tag ts)
+ then
+ let _,_,_,f,_ = t.Transition.node in
+ let (child,desc,below),(sibl,foll,after) = Formula.st f in
+ (Formlist.cons t fl_acc,
+ StateSet.union ll_acc below,
+ StateSet.union rl_acc after,
+ StateSet.union child c_acc,
+ StateSet.union desc d_acc,
+ StateSet.union sibl s_acc,
+ StateSet.union foll f_acc)
+ else acc ) acc (
+ try Hashtbl.find a.trans q
+ with
+ Not_found -> Printf.eprintf "Looking for state %i, doesn't exist!!!\n%!"
+ q;[]
+ )
+
+ ) set (Formlist.nil,StateSet.empty,StateSet.empty,ca,da,sa,fa)
+ in (Formlistlist.cons fl fll_acc), (SList.cons ll lllacc), (SList.cons rr rllacc),ca,da,sa,fa)
+ slist (Formlistlist.nil,SList.nil,SList.nil,StateSet.empty,StateSet.empty,StateSet.empty,StateSet.empty)
+ in
+ (* Logic to chose the first and next function *)
+ let tags_child,tags_below,tags_siblings,tags_after = Tree.tags tree tag in
+ let d_f = Algebra.decide a tags_child tags_below (StateSet.union ca da) true in
+ let d_n = Algebra.decide a tags_siblings tags_after (StateSet.union sa fa) false in
+ let f_kind,first = choose_jump_down tree d_f
+ and n_kind,next = if noright then (`NIL, fun _ _ -> Tree.nil )
+ else choose_jump_next tree d_n in
+ let empty_res = null_result in
+ let fll = fl_list in
+ let cont =
+ match f_kind,n_kind with
+ | `NIL,`NIL -> (*OpCode.K0(fl_list) *)
+ fun t _ _ tag _ -> eval_fold2_slist fll t tag empty_res empty_res
+
+ | _,`NIL -> (
+ match f_kind with
+ |`TAG(tag1) -> (*OpCode.K1(fl_list,first,llist,tag1) *)
+ fun t _ _ tag _ -> eval_fold2_slist fll t tag empty_res
+ (loop_tag (first t) t llist tag1)
+ | _ -> (* OpCode.K2(fl_list,first,llist) *)
+ fun t _ _ tag _ -> eval_fold2_slist fll t tag empty_res
+ (loop (first t) t llist tag)
+ )
+ | `NIL,_ -> (
+ match n_kind with
+ |`TAG(tag2) -> (*OpCode.K3(fl_list,next,rlist,tag2) *)
+ fun t ctx _ tag _ ->
+ eval_fold2_slist fll t tag
+ (loop_tag (next t ctx) ctx rlist tag2)
+ empty_res
+
+ | _ -> (*OpCode.K4(fl_list,next,rlist) *)
+ fun t ctx _ tag _ ->
+ eval_fold2_slist fll t tag
+ (loop (next t ctx) ctx rlist tag)
+ empty_res
+
+ )
+
+ | `TAG(tag1),`TAG(tag2) -> (*OpCode.K5(fl_list,next,rlist,tag2,first,llist,tag1) *)
+ fun t ctx _ tag _ ->
+ eval_fold2_slist fll t tag
+ (loop_tag (next t ctx) ctx rlist tag2)
+ (loop_tag (first t) t llist tag1)
+
+ | `TAG(tag1),`ANY -> (* OpCode.K6(fl_list,next,rlist,first,llist,tag1) *)
+ fun t ctx _ tag _ ->
+ eval_fold2_slist fll t tag
+ (loop (next t ctx) ctx rlist tag)
+ (loop_tag (first t) t llist tag1)
+
+ | `ANY,`TAG(tag2) -> (* OpCode.K7(fl_list,next,rlist,tag2,first,llist) *)
+ fun t ctx _ tag _ ->
+ eval_fold2_slist fll t tag
+ (loop_tag (next t ctx) ctx rlist tag2)
+ (loop (first t) t llist tag)
+
+
+ | _,_ -> (*OpCode.K8(fl_list,next,rlist,first,llist) *)
+ (*if SList.equal slist rlist && SList.equal slist llist
+ then
+ let rec loop t ctx =
+ if t == Tree.nil then empty_res else
+ let r1 = loop (first t) t
+ and r2 = loop (next t ctx) ctx
+ in
+ eval_fold2_slist fl_list t (Tree.tag tree t) r2 r1
+ in loop
+ else *)
+ fun t ctx _ tag _ ->
+ eval_fold2_slist fll t tag
+ (loop (next t ctx) ctx rlist tag)
+ (loop (first t) t llist tag)
+