From: Kim Nguyễn Date: Thu, 1 Mar 2012 13:28:45 +0000 (+0100) Subject: Add grammar related function to result sets (2/2). X-Git-Url: http://git.nguyen.vg/gitweb/?a=commitdiff_plain;h=013ac87b16485acbe56f07d99a810d6364242a9e;p=SXSI%2Fxpathcomp.git Add grammar related function to result sets (2/2). --- diff --git a/src/resJIT.ml b/src/resJIT.ml index 28f9281..df08d9c 100644 --- a/src/resJIT.ml +++ b/src/resJIT.ml @@ -209,10 +209,10 @@ DEFINE EXEC_CODE_TEMPLATE(ns) = fun slot slot1 slot2 t dst code -> | OP_NOP _ -> () | OP_LEFT1 src -> - SET(slot.(dst), slot1.(src)) + SET(slot.(dst), slot1.(src)) | OP_LEFT2 (src1, src2) -> - SET(slot.(dst) , ns.concat slot1.(src1) slot1.(src2)) + SET(slot.(dst) , ns.concat slot1.(src1) slot1.(src2)) | OP_RIGHT1 src -> SET(slot.(dst) , slot2.(src)) @@ -220,13 +220,12 @@ DEFINE EXEC_CODE_TEMPLATE(ns) = fun slot slot1 slot2 t dst code -> SET (slot.(dst) , ns.concat slot2.(src1) slot2.(src2) ) | OP_LEFT1_RIGHT1 (src1, src2) -> - SET (slot.(dst) , ns.concat slot1.(src1) slot2.(src2)) + SET (slot.(dst) , ns.concat slot1.(src1) slot2.(src2)) | OP_LEFT2_RIGHT1 (src1, src2, src3) -> - SET (slot.(dst) , ns.concat3 slot1.(src1) slot1.(src2) slot2.(src3)) + SET (slot.(dst) , ns.concat3 slot1.(src1) slot1.(src2) slot2.(src3)) | OP_LEFT1_RIGHT2 (src1, src2, src3) -> - TRACE("res-jit", 3, __ "slot==slot1: %b, slot==slot2:%b\n" (slot==slot1) (slot==slot2)); SET (slot.(dst) , ns.concat3 slot1.(src1) slot2.(src2) slot2.(src3)); | OP_LEFT2_RIGHT2 (src1, src2, src3, src4) -> @@ -271,6 +270,10 @@ module type S = module NS : NodeSet.S type t = NS.t array val exec : t -> t -> t -> Tree.node -> code -> unit + val print : Format.formatter -> t -> unit + val var : int -> t -> t + val close : ((int*State.t, NS.t) Hashtbl.t) -> t -> t + val is_open : t -> bool end @@ -279,7 +282,7 @@ module Count = struct module NS = NodeSet.Count type t = NodeSet.Count.t array - let pr_slot fmt s = + let print fmt s = let pr fmt (state, count) = fprintf fmt "%a: %i" State.print state (NS.length count) in @@ -314,13 +317,18 @@ module Count = exec slot slot1 slot2 t code; TRACE("res-jit", 3, __ " RES : %a\n\n%!" pr_slot slot) + + let var _ x = x + let close _ x = x + + let is_open _ = false end module Mat = struct module NS = NodeSet.Mat type t = NodeSet.Mat.t array - let pr_slot fmt s = + let print fmt s = let pr fmt (state, count) = fprintf fmt "%a: %i" State.print state (NS.length count) in @@ -341,7 +349,59 @@ module Mat = exec_code slot slot1 slot2 t dst' code'; exec slot slot1 slot2 t code1' end + + let var _ x = x + let close _ x = x + let is_open _ = false end +module Make(U : NodeSet.S) = + struct + module NS = U + type t = U.t array + let print fmt s = + let pr fmt (state, count) = + fprintf fmt "%a: %i" State.print state (NS.length count) + in + Pretty.print_array ~sep:", " pr fmt (Array.mapi (fun x y -> (x,y)) s) + + let exec_instr = EXEC_INSTR_TEMPLATE(U) + let exec_code = EXEC_CODE_TEMPLATE(U) + (* inline by hand for efficiency reason *) + let rec exec slot slot1 slot2 t code = + match code with + | Nil -> () + | Cons(dst, opcode, code1) -> + TRACE("res-jit", 3, __ " %a := %a\n%!" + State.print dst print_opcode opcode; + ); + exec_code slot slot1 slot2 t dst opcode; + begin + match code1 with + | Nil -> () + | Cons(dst, opcode, code1) -> + TRACE("res-jit", 3, __ " %a := %a\n%!" + State.print dst print_opcode opcode; + ); + exec_code slot slot1 slot2 t dst opcode; + exec slot slot1 slot2 t code1 + end + + let exec slot slot1 slot2 t code = + TRACE("res-jit", 3, __ "Node %i:\n" (Node.to_int t)); + TRACE("res-jit", 3, __ " LEFT : %a\n" pr_slot slot1); + TRACE("res-jit", 3, __ " RIGHT : %a\n" pr_slot slot2); + exec slot slot1 slot2 t code; + TRACE("res-jit", 3, __ " RES : %a\n\n%!" pr_slot slot) + + + let var i t = + Array.mapi (fun j _ -> NS.var (i,j)) t + let close h t = + Array.map (NS.close h) t + + let is_open t = + List.exists NS.is_open (Array.to_list t) + end diff --git a/src/resJIT.mli b/src/resJIT.mli index 9b7faff..fcf38b8 100644 --- a/src/resJIT.mli +++ b/src/resJIT.mli @@ -33,18 +33,12 @@ module type S = module NS : NodeSet.S type t = NS.t array val exec : t -> t -> t -> Tree.node -> code -> unit + val print : Format.formatter -> t -> unit + val var : int -> t -> t + val close : ((int*State.t, NS.t) Hashtbl.t) -> t -> t + val is_open : t -> bool end -module Count : - sig - module NS : NodeSet.S with type t = int - type t = NS.t array - val exec : t -> t -> t -> Tree.node -> code -> unit - end - -module Mat : - sig - module NS : NodeSet.S with type t = Tree.node NodeSet.mat - type t = NS.t array - val exec : t -> t -> t -> Tree.node -> code -> unit - end +module Count : S with type NS.t = int +module Mat : S with type NS.t = Tree.node NodeSet.mat +module Make(U : NodeSet.S) : S with type NS.t = U.t