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
Haley Sapphie Owsianko
ACC-project
Commits
5e1720d2
Commit
5e1720d2
authored
Apr 25, 2021
by
Luca Bataillard
Browse files
fix improved CC translation
parent
5b6c4476
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSValueRepresenter.scala
View file @
5e1720d2
...
@@ -59,12 +59,12 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
...
@@ -59,12 +59,12 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val
cntsFVs
=
cnts
.
flatMap
(
c
=>
fv
(
c
.
body
,
fvMap
)
--
c
.
args
)
val
cntsFVs
=
cnts
.
flatMap
(
c
=>
fv
(
c
.
body
,
fvMap
)
--
c
.
args
)
fv
(
body
,
fvMap
)
++
cntsFVs
fv
(
body
,
fvMap
)
++
cntsFVs
case
H
.
LetF
(
funs
,
body
)
=>
case
H
.
LetF
(
funs
,
body
)
=>
val
(
newFvMap
,
funFVs
)
=
f
vFunSeq
(
funs
,
fvMap
)
val
fun
s
FVs
=
f
uns
.
flatMap
(
f
=>
(
fv
(
f
.
body
,
fvMap
)
--
f
.
args
)
)
(
fv
(
body
,
newF
vMap
)
++
funFVs
)
--
funs
.
map
(
_
.
name
)
(
fv
(
body
,
f
vMap
)
++
fun
s
FVs
)
--
funs
.
map
(
_
.
name
)
case
H
.
AppC
(
cnt
,
args
)
=>
case
H
.
AppC
(
cnt
,
args
)
=>
fvAtomSeq
(
args
,
fvMap
)
fvAtomSeq
(
args
,
fvMap
)
case
H
.
AppF
(
fun
,
retC
,
args
)
=>
case
H
.
AppF
(
fun
,
retC
,
args
)
=>
fun
.
asName
.
toSet
++
fvAtomSeq
(
args
,
fvMap
)
fvAtomSeq
(
args
,
fvMap
)
++
fvMap
.
getOrElse
(
fun
.
asName
.
get
,
Set
(
fun
.
asName
.
get
))
case
H
.
If
(
_
,
args
,
_
,
_
)
=>
case
H
.
If
(
_
,
args
,
_
,
_
)
=>
fvAtomSeq
(
args
,
fvMap
)
fvAtomSeq
(
args
,
fvMap
)
case
H
.
Halt
(
arg
)
=>
case
H
.
Halt
(
arg
)
=>
...
@@ -73,26 +73,14 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
...
@@ -73,26 +73,14 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
def
fvAtomSeq
(
as
:
Seq
[
H.Atom
],
fvMap
:
FVMap
)
:
Set
[
Symbol
]
=
def
fvAtomSeq
(
as
:
Seq
[
H.Atom
],
fvMap
:
FVMap
)
:
Set
[
Symbol
]
=
as
.
map
(
_
.
asName
).
filter
(
_
.
isDefined
).
toSet
as
.
map
(
_
.
asName
).
filter
(
_
.
isDefined
).
toSet
.
flatMap
((
n
:
Option
[
Symbol
])
=>
fvMap
.
getOrElse
(
n
.
get
,
Set
())
+
n
.
get
)
.
map
((
n
:
Option
[
Symbol
])
=>
n
.
get
)
def
fvFunSeq
(
funs
:
Seq
[
H.Fun
],
fvMap
:
FVMap
)
:
(
FVMap
,
Set
[
Symbol
])
=
{
val
fNames
=
funs
map
(
_
.
name
)
val
defFvMap
=
fNames
.
map
((
_
,
Set
[
Symbol
]())).
toMap
val
funFVs
=
funs
map
{
f
=>
{
val
fNewFvMap
=
fvMap
++
(
defFvMap
-
f
.
name
)
fv
(
f
.
body
,
fNewFvMap
)
--
f
.
args
}}
(
fvMap
++
(
fNames
zip
funFVs
),
funFVs
reduce
(
_
++
_
))
}
def
iterate
(
fvMap
:
FVMap
)
:
FVMap
=
def
iterate
(
fvMap
:
FVMap
)
:
FVMap
=
definedFuns
.
m
ap
{
definedFuns
.
foldLeft
(
fvM
ap
)
{
case
(
acc
,
H
.
Fun
(
fName
,
_
,
fArgs
,
fBody
))
=>
case
H
.
Fun
(
fName
,
_
,
fArgs
,
fBody
)
=>
val
newFv
=
(
fv
(
fBody
,
acc
))
--
fArgs
val
new
Fv
=
(
fv
(
fBody
,
fvMap
-
fName
))
--
fArgs
val
new
Binding
=
(
fName
,
newFv
)
(
fName
,
newFv
)
acc
+
newBinding
}
.
toMap
}
val
definedFvMap
=
definedFuns
.
map
(
f
=>
(
f
.
name
,
Set
[
Symbol
]())).
toMap
val
definedFvMap
=
definedFuns
.
map
(
f
=>
(
f
.
name
,
Set
[
Symbol
]())).
toMap
val
initialFvMap
:
FVMap
=
definedFvMap
++
prevKnownFuns
.
map
{
case
(
fName
,
(
_
,
_
,
fvs
))
=>
(
fName
,
fvs
.
toSet
)}
val
initialFvMap
:
FVMap
=
definedFvMap
++
prevKnownFuns
.
map
{
case
(
fName
,
(
_
,
_
,
fvs
))
=>
(
fName
,
fvs
.
toSet
)}
...
@@ -154,7 +142,7 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
...
@@ -154,7 +142,7 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val
blockAtom
=
L
.
AtomN
(
fName
)
val
blockAtom
=
L
.
AtomN
(
fName
)
val
varInits
=
initFunHelper
(
fvs
,
1
,
blockAtom
,
rest
)
val
varInits
=
initFunHelper
(
fvs
,
1
,
blockAtom
,
rest
)
val
t1
=
Symbol
.
fresh
(
"blockset_unused"
)
val
t1
=
Symbol
.
fresh
(
"blockset_unused"
)
val
blockSetArgs
=
Seq
(
blockAtom
,
L
.
AtomL
(
0
),
L
.
AtomN
(
w
ork
er
))
val
blockSetArgs
=
Seq
(
blockAtom
,
L
.
AtomL
(
0
),
L
.
AtomN
(
w
rapp
er
))
L
.
LetP
(
t1
,
CPS
.
BlockSet
,
blockSetArgs
,
varInits
)
L
.
LetP
(
t1
,
CPS
.
BlockSet
,
blockSetArgs
,
varInits
)
}
}
}
}
...
...
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