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
3c096064
Commit
3c096064
authored
Apr 24, 2021
by
Sapphie
Browse files
Implement LetF shrinking and start AppF shrinking
parent
f868bab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSOptimizer.scala
View file @
3c096064
...
...
@@ -55,7 +55,32 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
private
def
shrink
(
tree
:
Tree
)
:
Tree
=
shrink
(
tree
,
State
(
census
(
tree
)))
private
def
shrink
(
tree
:
Tree
,
s
:
State
)
:
Tree
=
???
private
def
shrink
(
tree
:
Tree
,
s
:
State
)
:
Tree
=
tree
match
{
case
LetF
(
funs
,
body
)
=>
val
undeadFuns
=
funs
.
filter
(
fun
=>
!
s
.
dead
(
fun
.
name
))
val
undeadShrunkFuns
=
undeadFuns
.
map
{
fun
=>
Fun
(
fun
.
name
,
fun
.
retC
,
fun
.
args
,
shrink
(
fun
.
body
,
s
))}
val
(
funsAppliedOnce
,
restFuns
)
=
undeadShrunkFuns
.
partition
(
fun
=>
s
.
appliedOnce
(
fun
.
name
))
val
newState
=
s
.
withFuns
(
undeadShrunkFuns
)
val
newBody
=
shrink
(
body
,
newState
)
if
(
restFuns
.
isEmpty
)
{
newBody
}
else
{
LetF
(
restFuns
,
newBody
)
}
case
AppF
(
fun
,
retC
,
args
)
=>
fun
match
{
case
AtomN
(
n
)
if
s
.
fEnv
.
contains
(
n
)
&&
s
.
appliedOnce
(
n
)
=>
// Inline
val
fun
=
s
.
fEnv
.
get
(
n
)
???
case
_
=>
tree
}
}
// (Non-shrinking) inlining
...
...
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