Commit 9287f623 authored by Julien Lopez's avatar Julien Lopez

Cleaner way to add a fresh variable for patterns, but can't keep it until the

	execution yet
parent e98b1638
......@@ -182,11 +182,11 @@ and compile_branches env (brs : Typed.branches) =
* p_i / t_i is used here to add elements to env.gamma *)
and compile_branch env br =
(* We add a fresh variable "pat<nb>:x" for each pattern *)
let t, _, d = br.Typed.br_pat.Patterns.descr in
let t, fv, d = br.Typed.br_pat.Patterns.descr in
let fv, d = incr Patterns.counter;
let freshname = "pat" ^ (string_of_int !Patterns.counter) ^ ":x" in
let fv = (Patterns.fv br.Typed.br_pat) @ [!Patterns.counter, freshname] in
fv, Patterns.Cap((Types.any, fv, Patterns.Capture(!Patterns.counter, freshname)), (t, [], d))
let newfv = fv @ [!Patterns.counter, freshname] in
newfv, Patterns.Cap((Types.any, newfv, Patterns.Capture(!Patterns.counter, freshname)), (t, fv, d))
in
let pat = { br.Typed.br_pat with Patterns.descr=(t,fv,d); Patterns.fv=fv } in
let env = List.fold_left enter_local env fv in
......
......@@ -336,7 +336,7 @@ and filter_node t p : Types.Positive.v id_map =
let res = IdMap.map_from_slist (fun _ -> Types.Positive.forward ()) fv in
memo_filter := MemoFilter.add (t,p) res !memo_filter;
let r = filter_descr t (descr p) in
IdMap.collide Types.Positive.define res r; (* Had to comment this to add fresh variables for patterns *)
IdMap.collide Types.Positive.define res r;
r
let filter t p =
......@@ -370,10 +370,14 @@ x=(1,2)
| Cup ((a1,_,_) as p1,p2) ->
approx_var seen p2 (Types.diff t a1)
(approx_var seen p1 (Types.cap t a1) xs)
| Cap ((_,fv1,_) as p1,((_,fv2,_) as p2)) ->
IdSet.cup
| Cap ((_,fv1,d1) as p1,((_,fv2,d2) as p2)) ->
(* TODO: In case we have a fresh variable, we must keep it somewhere *)
(match d1 with
| Capture(_, name) when Str.string_match (Str.regexp "pat[0-9]+:") name 0 ->
(match d2 with | Constr _ -> xs | _ -> approx_var seen p2 t xs)
| _ -> IdSet.cup
(approx_var seen p1 t (IdSet.cap fv1 xs))
(approx_var seen p2 t (IdSet.cap fv2 xs))
(approx_var seen p2 t (IdSet.cap fv2 xs)))
| Capture _ ->
xs
| Constant (_,c) ->
......@@ -389,7 +393,6 @@ x=(1,2)
(approx_var_node seen q1 (pi1 ~kind:`XML t) xs)
(approx_var_node seen q2 (pi2 ~kind:`XML t) xs)
| Record _ -> IdSet.empty
(* | Constr _ -> xs (* Needed to add fresh variables to patterns *)*)
| _ -> assert false
and approx_var_node seen q t xs =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment