Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
77081479
Commit
77081479
authored
Apr 01, 2021
by
Sapphie
Browse files
Tentative implementation of hoister
parent
3691e68f
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSHoister.scala
View file @
77081479
...
...
@@ -3,6 +3,33 @@ package l3
import
SymbolicCPSTreeModuleLow._
object
CPSHoister
extends
(
Tree
=>
LetF
)
{
def
apply
(
tree
:
Tree
)
:
LetF
=
???
def
apply
(
tree
:
Tree
)
:
LetF
=
tree
match
{
case
LetP
(
name
,
prim
,
args
,
body
)
=>
val
LetF
(
funs
,
hoistedBody
)
=
apply
(
body
)
LetF
(
funs
,
LetP
(
name
,
prim
,
args
,
hoistedBody
))
case
LetC
(
cnts
,
body
)
=>
val
(
newCnts
,
funsHoistedCnts
)
=
cnts
.
map
(
cnt
=>
(
cnt
,
apply
(
cnt
.
body
)))
.
map
{
case
(
cnt
,
LetF
(
funs
,
body
))
=>
(
Cnt
(
cnt
.
name
,
cnt
.
args
,
body
),
funs
)}
.
unzip
val
LetF
(
funsHoistedBody
,
hoistedBody
)
=
apply
(
body
)
val
funsHoistedFlat
=
(
funsHoistedCnts
:+
funsHoistedBody
).
flatten
LetF
(
funsHoistedFlat
,
LetC
(
newCnts
,
hoistedBody
))
case
LetF
(
funs
,
body
)
=>
val
(
newFuns
,
funsHoistedFuns
)
=
funs
.
map
(
fun
=>
(
fun
,
apply
(
fun
.
body
)))
.
map
{
case
(
fun
,
LetF
(
funsHoisted
,
body
))
=>
(
Fun
(
fun
.
name
,
fun
.
retC
,
fun
.
args
,
body
),
funsHoisted
)
}.
unzip
val
LetF
(
funsHoistedBody
,
hoistedBody
)
=
apply
(
body
)
val
funsHoistedFlat
=
(
funsHoistedFuns
:+
funsHoistedBody
).
flatten
LetF
(
funsHoistedFlat
,
hoistedBody
)
case
e
=>
LetF
(
Seq
(),
e
)
}
}
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