Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ACC-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Haley Sapphie Owsianko
ACC-project
Commits
04502edc
Commit
04502edc
authored
4 years ago
by
Luca Bataillard
Browse files
Options
Downloads
Patches
Plain Diff
fix if translation, all tests pass
parent
212fc8c1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compiler/src/l3/CL3ToCPSTranslator.scala
+27
-41
27 additions, 41 deletions
compiler/src/l3/CL3ToCPSTranslator.scala
with
27 additions
and
41 deletions
compiler/src/l3/CL3ToCPSTranslator.scala
+
27
−
41
View file @
04502edc
...
...
@@ -57,10 +57,10 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
}
// Builds a CPS If out of its arguments
def
transformTestPrim
(
p
:
L3TestPrimitive
,
primArgs
:
Seq
[
S.Tree
],
thenC
:
C.Name
,
elseC
:
C.Name
)
:
C.Tree
=
{
def
transformTestPrim
(
p
:
L3TestPrimitive
,
primArgs
:
Seq
[
S.Tree
],
thenC
:
C.Name
,
elseC
:
C.Name
)
:
C.Tree
=
{
def
transformArgs
(
args
:
Seq
[
S.Tree
])(
atoms
:
Seq
[
C.Atom
])
:
C.Tree
=
args
match
{
case
Nil
=>
C
.
If
(
p
,
atoms
,
thenC
,
elseC
)
case
x
::
xs
=>
...
...
@@ -77,44 +77,30 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
case
((
name
,
expr
),
tree
)
=>
transform
(
expr
)(
v
=>
C
.
LetP
(
name
,
L3
.
Id
,
Seq
(
v
),
tree
))
}
case
S
.
If
(
cnd
,
thn
,
els
)
=>
cnd
match
{
case
S
.
Prim
(
p
:
L3TestPrimitive
,
primArgs
)
=>
// Context continuation name
val
ctxCNme
=
Symbol
.
fresh
(
"c"
)
val
ctxCId
=
C
.
AtomN
(
ctxCNme
)
// Context continuation arg
val
ctxCArg
=
Symbol
.
fresh
(
"a"
)
// Context continuation body
// This is simply what we already had
val
ctxCBody
=
ctx
(
C
.
AtomN
(
ctxCArg
))
// Context continuation
val
ctxC
=
C
.
Cnt
(
ctxCNme
,
Seq
(
ctxCArg
),
ctxCBody
)
// 'Then' continuation name and body
val
thenCNme
=
Symbol
.
fresh
(
"ct"
)
val
thenCBody
=
transform
(
thn
)(
v2
=>
C
.
AppC
(
ctxCNme
,
Seq
(
v2
)))
val
thenC
=
C
.
Cnt
(
thenCNme
,
Seq
(),
thenCBody
)
// 'Else' continuation name and body
val
elseCNme
=
Symbol
.
fresh
(
"ce"
)
val
elseCBody
=
transform
(
thn
)(
v3
=>
C
.
AppC
(
ctxCNme
,
Seq
(
v3
)))
val
elseC
=
C
.
Cnt
(
elseCNme
,
Seq
(),
elseCBody
)
val
letBody
=
transformTestPrim
(
p
,
primArgs
,
thenCNme
,
elseCNme
)
C
.
LetC
(
Seq
(
ctxC
),
C
.
LetC
(
Seq
(
thenC
),
C
.
LetC
(
Seq
(
elseC
),
letBody
)
)
)
case
e1
=>
val
pArgs
=
S
.
Lit
(
BooleanLit
(
false
))(
cnd
.
pos
)
val
newCnd
=
S
.
Prim
(
L3
.
Eq
,
Seq
(
e1
,
pArgs
))(
cnd
.
pos
)
val
newIf
=
S
.
If
(
newCnd
,
els
,
thn
)(
cnd
.
pos
)
transform
(
newIf
)(
ctx
)
case
S
.
If
(
S
.
Prim
(
p
:
L3TestPrimitive
,
primArgs
),
thn
,
els
)
=>
{
val
retCntName
=
Symbol
.
fresh
(
"c"
)
val
retArgName
=
Symbol
.
fresh
(
"r"
)
val
retCnt
=
C
.
Cnt
(
retCntName
,
Seq
(
retArgName
),
ctx
(
C
.
AtomN
(
retArgName
)))
val
thnCntName
=
Symbol
.
fresh
(
"ct"
)
val
thnCntBody
=
transform
(
thn
)(
v
=>
C
.
AppC
(
retCntName
,
Seq
(
v
)))
val
thnCnt
=
C
.
Cnt
(
thnCntName
,
Seq
(),
thnCntBody
)
val
elsCntName
=
Symbol
.
fresh
(
"cf"
)
val
elsCntBody
=
transform
(
els
)(
v
=>
C
.
AppC
(
retCntName
,
Seq
(
v
)))
val
elsCnt
=
C
.
Cnt
(
elsCntName
,
Seq
(),
elsCntBody
)
val
ifBody
=
transformTestPrim
(
p
,
primArgs
,
thnCntName
,
elsCntName
)
C
.
LetC
(
Seq
(
retCnt
),
C
.
LetC
(
Seq
(
thnCnt
),
C
.
LetC
(
Seq
(
elsCnt
),
ifBody
)))
}
case
S
.
If
(
cond
,
thn
,
els
)
=>
{
implicit
val
pos
=
tree
.
pos
val
primCond
=
S
.
Prim
(
L3
.
Eq
,
Seq
(
cond
,
S
.
Lit
(
BooleanLit
(
false
))))
transform
(
S
.
If
(
primCond
,
els
,
thn
))(
ctx
)
}
case
S
.
App
(
fun
,
args
)
=>
transformApp
(
fun
,
args
)
case
S
.
LetRec
(
funs
,
body
)
=>
transformLetRec
(
funs
,
body
)
case
S
.
Prim
(
p
,
args
)
=>
p
match
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment