Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
9287f623
Commit
9287f623
authored
May 21, 2014
by
Julien Lopez
Browse files
Cleaner way to add a fresh variable for patterns, but can't keep it until the
execution yet
parent
e98b1638
Changes
2
Hide whitespace changes
Inline
Side-by-side
compile/compile.ml
View file @
9287f623
...
...
@@ -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
new
fv
=
fv
@
[
!
Patterns
.
counter
,
freshname
]
in
new
fv
,
Patterns
.
Cap
((
Types
.
any
,
new
fv
,
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
...
...
types/patterns.ml
View file @
9287f623
...
...
@@ -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
=
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment