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
ccaeb11f
Commit
ccaeb11f
authored
May 06, 2021
by
Luca Bataillard
Browse files
fix general inlining
parent
4399af88
Changes
2
Show whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSOptimizer.scala
View file @
ccaeb11f
...
...
@@ -269,9 +269,9 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val
args
=
replaceArgs
(
oldArgs
,
s
)
if
(
s
.
cEnv
.
contains
(
cntName
))
{
val
cnt
=
copyC
(
s
.
cEnv
(
cntName
)
,
s
.
aSubst
,
s
.
cSubst
)
val
newState
=
s
.
withASubst
(
c
nt
.
args
,
args
)
inlineT
(
cnt
.
body
)(
newState
)
val
savedCnt
=
s
.
cEnv
(
cntName
)
val
newState
=
s
.
withASubst
(
savedC
nt
.
args
,
args
)
copyT
(
savedCnt
.
body
,
newState
.
aSubst
,
newState
.
cSubst
)
}
else
{
AppC
(
cntName
,
args
)
}
...
...
@@ -284,14 +284,11 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
funName
match
{
case
AtomN
(
n
)
if
s
.
fEnv
.
contains
(
n
)
=>
{
val
oldFun
=
s
.
fEnv
(
n
)
val
notUsedAsValue
=
s
.
census
.
get
(
oldFun
.
name
).
fold
(
false
)(
count
=>
count
.
asValue
==
0
)
val
nonRecursive
=
notUsedAsValue
&&
!
census
(
oldFun
.
body
).
contains
(
oldFun
.
name
)
if
(
nonRecursive
&&
sameLen
(
oldFun
.
args
,
args
))
{
val
fun
=
copyF
(
oldFun
,
s
.
aSubst
,
s
.
cSubst
)
val
newState
=
s
.
withASubst
(
fun
.
args
,
args
).
withCSubst
(
fun
.
retC
,
retC
)
inlineT
(
fun
.
body
)(
newState
)
val
savedFun
=
s
.
fEnv
(
n
)
if
(
sameLen
(
savedFun
.
args
,
args
))
{
val
newState
=
s
.
withASubst
(
savedFun
.
args
,
args
).
withCSubst
(
savedFun
.
retC
,
retC
)
copyT
(
savedFun
.
body
,
newState
.
aSubst
,
newState
.
cSubst
)
}
else
{
AppF
(
funName
,
retC
,
args
)
}
...
...
examples/fact.l3
0 → 100644
View file @
ccaeb11f
(defrec fact
(fun (x) (if (@= x 0) 1 (@* x (fact (@- x 1))))))
(@byte-write (fact 5))
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