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
9871602d
Commit
9871602d
authored
3 years ago
by
Sapphie
Browse files
Options
Downloads
Patches
Plain Diff
Fix bug
parent
32c98d65
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compiler/src/l3/CPSValueRepresenter.scala
+13
-11
13 additions, 11 deletions
compiler/src/l3/CPSValueRepresenter.scala
compiler/src/l3/Main.scala
+1
-0
1 addition, 0 deletions
compiler/src/l3/Main.scala
tests/stmt-defrec.l3
+11
-9
11 additions, 9 deletions
tests/stmt-defrec.l3
with
25 additions
and
20 deletions
compiler/src/l3/CPSValueRepresenter.scala
+
13
−
11
View file @
9871602d
...
...
@@ -32,11 +32,11 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
private
def
transformLetF
(
initialFuns
:
Seq
[
H.Fun
],
body
:
H.Tree
)
:
L.LetF
=
{
// for each function, closes it and returns all the variables that used be free in it
// as well as the associated
w
or
ker
function
// as well as the associated or
iginal
function
name
def
transformFunAbs
(
funs
:
Seq
[
H.Fun
])
:
Seq
[(
L.Fun
,
Seq
[
Symbol
]
,
Symbol
)]
=
funs
match
{
case
Nil
=>
Nil
case
f
::
fs
=>
val
workerFun
=
Symbol
.
fresh
(
"w"
)
val
workerFun
=
Symbol
.
fresh
(
"w
orker_function
"
)
val
envName
=
Symbol
.
fresh
(
"env"
)
val
newArgs
=
envName
+:
f
.
args
val
funBody
=
apply
(
f
.
body
)
...
...
@@ -49,14 +49,14 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
substitute
(
funBody
)(
accSubst
)
case
freeVar
::
vs
=>
// Bind the fresh variable v to a block get
val
v
=
Symbol
.
fresh
(
"
v
"
)
val
v
=
Symbol
.
fresh
(
"
block_variable
"
)
L
.
LetP
(
v
,
CPS
.
BlockGet
,
Seq
(
L
.
AtomN
(
envName
),
L
.
AtomL
(
counter
)),
argsBindings
(
vs
,
counter
+
1
,
accSubst
+
(
freeVar
->
v
)))
}
val
newFunBody
=
argsBindings
(
fv
,
1
,
Map
())
val
newFun
=
L
.
Fun
(
workerFun
,
f
.
retC
,
newArgs
,
newFunBody
)
(
newFun
,
fv
,
workerFun
)
+:
transformFunAbs
(
fs
)
(
newFun
,
fv
,
f
.
name
)
+:
transformFunAbs
(
fs
)
}
def
allocInitFun
(
funsAndVars
:
Seq
[(
L.Fun
,
Seq
[
Symbol
]
,
Symbol
)],
lastBody
:
L.Tree
)
:
L.Tree
=
{
...
...
@@ -70,13 +70,13 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
funsAndVars
match
{
case
Nil
=>
lastBody
case
(
f
un
,
vars
,
w
or
kerFun
)
::
rest
=>
val
blockAtom
=
L
.
AtomN
(
fun
.
n
ame
)
case
(
workerF
un
,
vars
,
or
iginalFunName
)
::
rest
=>
val
blockAtom
=
L
.
AtomN
(
originalFunN
ame
)
val
varInits
=
initFun
(
vars
,
1
,
blockAtom
,
rest
)
val
t1
=
Symbol
.
fresh
(
"
t1
"
)
val
prim
Args
=
Seq
(
blockAtom
,
L
.
AtomL
(
0
),
L
.
AtomN
(
workerFun
))
val
nextBody
=
L
.
LetP
(
t1
,
CPS
.
BlockSet
,
prim
Args
,
varInits
)
L
.
LetP
(
fun
.
n
ame
,
CPS
.
BlockAlloc
(
202
),
Seq
(
L
.
AtomL
(
vars
.
length
+
1
)),
nextBody
)
val
t1
=
Symbol
.
fresh
(
"
blockset_unused
"
)
val
blockSet
Args
=
Seq
(
blockAtom
,
L
.
AtomL
(
0
),
L
.
AtomN
(
workerFun
.
name
))
val
nextBody
=
L
.
LetP
(
t1
,
CPS
.
BlockSet
,
blockSet
Args
,
varInits
)
L
.
LetP
(
originalFunN
ame
,
CPS
.
BlockAlloc
(
202
),
Seq
(
L
.
AtomL
(
vars
.
length
+
1
)),
nextBody
)
}
}
...
...
@@ -85,7 +85,9 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val
lastBody
=
apply
(
body
)
val
closureAllocInit
=
allocInitFun
(
funsAndVars
,
lastBody
)
L
.
LetF
(
funsAndVars
.
unzip3
.
_1
,
closureAllocInit
)
val
res
=
L
.
LetF
(
funsAndVars
.
unzip3
.
_1
,
closureAllocInit
)
println
(
res
)
res
}
// Substitutes _free_ variables in `tree`
...
...
This diff is collapsed.
Click to expand it.
compiler/src/l3/Main.scala
+
1
−
0
View file @
9871602d
...
...
@@ -13,6 +13,7 @@ object Main {
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
val
backEnd
:
Tree
=>
TerminalPhaseResult
=
(
CL3ToCPSTranslator
andThen
treePrinter
(
"---------- After CPS translation"
)
andThen
CPSValueRepresenter
andThen
treePrinter
(
"---------- After value representation"
)
andThen
treeChecker
...
...
This diff is collapsed.
Click to expand it.
tests/stmt-defrec.l3
+
11
−
9
View file @
9871602d
...
...
@@ -2,13 +2,15 @@
;; Test the "defrec" statement
(@byte-write 67)
;;
(@byte-write 67)
(defrec succ (fun (x) (@+ x 1)))
(@byte-write (succ 64))
(defrec fact (fun (x) (if (@= x 0) 1 (@* x (fact (@- x 1))))))
(@byte-write (@- (fact 5) 54))
(defrec fact (fun (x) (@+ x 2)))
(@byte-write (fact 65))
(defrec id (fun (x) (x)))
(id 1)
;;(defrec succ (fun (x) (@+ x 1)))
;;(@byte-write (succ 64))
;;
;;(defrec fact (fun (x) (if (@= x 0) 1 (@* x (fact (@- x 1))))))
;;(@byte-write (@- (fact 5) 54))
;;
;;(defrec fact (fun (x) (@+ x 2)))
;;(@byte-write (fact 65))
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