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
f89f9e4e
Commit
f89f9e4e
authored
Apr 24, 2021
by
Sapphie
Browse files
Implement AppC
parent
761e22ae
Changes
1
Show whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSOptimizer.scala
View file @
f89f9e4e
...
@@ -55,18 +55,32 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
...
@@ -55,18 +55,32 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
private
def
shrink
(
tree
:
Tree
)
:
Tree
=
private
def
shrink
(
tree
:
Tree
)
:
Tree
=
shrink
(
tree
,
State
(
census
(
tree
)))
shrink
(
tree
,
State
(
census
(
tree
)))
private
def
replaceArgs
(
args
:
Seq
[
Atom
],
s
:
State
)
:
Seq
[
Atom
]
=
args
map
{
a
=>
s
.
aSubst
.
getOrElse
(
a
,
a
)
}
private
def
shrink
(
tree
:
Tree
,
s
:
State
)
:
Tree
=
tree
match
{
private
def
shrink
(
tree
:
Tree
,
s
:
State
)
:
Tree
=
tree
match
{
case
AppC
(
cntName
,
args
)
=>
val
replacedArgs
=
replaceArgs
(
args
,
s
)
if
(
s
.
appliedOnce
(
cntName
))
{
// Inline
val
cnt
=
s
.
cEnv
(
cntName
)
val
newState
=
s
.
withASubst
(
cnt
.
args
,
replacedArgs
)
shrink
(
cnt
.
body
,
newState
)
}
else
{
AppC
(
cntName
,
replacedArgs
)
}
case
AppF
(
funAtom
,
retC
,
args
)
=>
case
AppF
(
funAtom
,
retC
,
args
)
=>
val
replacedArgs
=
replaceArgs
(
args
,
s
)
funAtom
match
{
funAtom
match
{
case
AtomN
(
n
)
if
s
.
fEnv
.
contains
(
n
)
&&
s
.
appliedOnce
(
n
)
=>
case
AtomN
(
n
)
if
s
.
fEnv
.
contains
(
n
)
&&
s
.
appliedOnce
(
n
)
=>
// Inline
// Inline
val
fun
=
s
.
fEnv
(
n
)
val
fun
=
s
.
fEnv
(
n
)
val
newState
=
s
.
withASubst
(
fun
.
args
,
a
rgs
)
val
newState
=
s
.
withASubst
(
fun
.
args
,
replacedA
rgs
)
.
withCSubst
(
fun
.
retC
,
retC
)
.
withCSubst
(
fun
.
retC
,
retC
)
val
newBody
=
shrink
(
fun
.
body
,
newState
)
val
newBody
=
shrink
(
fun
.
body
,
newState
)
newBody
newBody
case
_
=>
tree
case
_
=>
AppF
(
funAtom
,
retC
,
replacedArgs
)
}
}
case
LetF
(
funs
,
body
)
=>
case
LetF
(
funs
,
body
)
=>
...
@@ -88,7 +102,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
...
@@ -88,7 +102,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
if
(
s
.
dead
(
name
)
&&
!
impure
(
prim
))
{
if
(
s
.
dead
(
name
)
&&
!
impure
(
prim
))
{
shrink
(
body
,
s
)
shrink
(
body
,
s
)
}
else
{
}
else
{
val
replacedArgs
=
args
map
{
a
=>
s
.
aSubst
.
getOrElse
(
a
,
a
)}
val
replacedArgs
=
replaceArgs
(
args
,
s
)
val
primArgPair
=
(
prim
,
replacedArgs
)
val
primArgPair
=
(
prim
,
replacedArgs
)
if
(!
unstable
(
prim
)
&&
!
impure
(
prim
)
&&
s
.
eInvEnv
.
contains
(
primArgPair
))
{
if
(!
unstable
(
prim
)
&&
!
impure
(
prim
)
&&
s
.
eInvEnv
.
contains
(
primArgPair
))
{
val
newS
=
s
.
withASubst
(
name
,
s
.
eInvEnv
(
primArgPair
))
val
newS
=
s
.
withASubst
(
name
,
s
.
eInvEnv
(
primArgPair
))
...
...
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