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
324b72dc
Commit
324b72dc
authored
3 years ago
by
Luca Bataillard
Browse files
Options
Downloads
Patches
Plain Diff
fix array out of bounds issue
parent
cf388c4a
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/CPSValueRepresenter.scala
+19
-17
19 additions, 17 deletions
compiler/src/l3/CPSValueRepresenter.scala
with
19 additions
and
17 deletions
compiler/src/l3/CPSValueRepresenter.scala
+
19
−
17
View file @
324b72dc
...
...
@@ -56,11 +56,7 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
}
}
private
def
rewriteIndex
(
idx
:
H.Atom
)
:
L.Atom
=
idx
match
{
case
H
.
AtomN
(
n
)
=>
L
.
AtomN
(
n
)
case
H
.
AtomL
(
IntLit
(
i
))
=>
L
.
AtomL
(
i
.
toInt
)
case
_
=>
throw
new
Exception
(
f
"Cannot rewrite atom {idx} which is not Name or Int Literal"
)
}
private
def
getMaskR
(
numBits
:
Int
)
:
Either
[
H.Atom
,
L.Atom
]
=
Right
(
L
.
AtomL
((
1
<<
numBits
)
-
1
))
...
...
@@ -87,15 +83,6 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
}
prim
match
{
case
L3
.
BlockSet
=>
val
block
=
rewrite
(
x
)
val
idx
=
rewriteIndex
(
y
)
val
value
=
rewrite
(
z
)
L
.
LetP
(
n
,
CPS
.
BlockSet
,
Seq
(
block
,
idx
,
value
),
apply
(
body
))
case
L3
.
BlockGet
=>
val
block
=
rewrite
(
x
)
val
idx
=
rewriteIndex
(
y
)
L
.
LetP
(
n
,
CPS
.
BlockGet
,
Seq
(
block
,
idx
),
apply
(
body
))
case
L3
.
IntAdd
=>
tempLetP
(
CPS
.
Sub
,
Seq
(
Left
(
x
),
lAtomOne
))
{
x1
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
x1
,
rewrite
(
y
)),
apply
(
body
))
...
...
@@ -146,21 +133,29 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
case
L3
.
BlockAlloc
(
tag
)
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Right
(
rewrite
(
x
)
)
,
lAtomOne
))
{
t1
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Left
(
x
),
lAtomOne
))
{
t1
=>
L
.
LetP
(
n
,
CPS
.
BlockAlloc
(
tag
),
Seq
(
t1
),
apply
(
body
))
}
case
L3
.
BlockTag
=>
tempLetP
(
CPS
.
BlockTag
,
args
map
(
x
=>
Right
(
rewrite
(
x
)
)))
{
t1
=>
tempLetP
(
CPS
.
BlockTag
,
args
map
(
Left
(
_
)))
{
t1
=>
tempLetP
(
CPS
.
ShiftLeft
,
Seq
(
Right
(
t1
),
lAtomOne
))
{
t2
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
t2
,
L
.
AtomL
(
1
)),
apply
(
body
))
}
}
case
L3
.
BlockLength
=>
tempLetP
(
CPS
.
BlockLength
,
args
map
(
x
=>
Left
(
x
)))
{
t1
=>
tempLetP
(
CPS
.
BlockLength
,
args
map
(
Left
(
_
)))
{
t1
=>
tempLetP
(
CPS
.
ShiftLeft
,
Seq
(
Right
(
t1
),
Right
(
L
.
AtomL
(
1
))))
{
t2
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
t2
,
L
.
AtomL
(
1
)),
apply
(
body
))
}
}
case
L3
.
BlockSet
=>
val
block
=
rewrite
(
x
)
val
value
=
rewrite
(
z
)
rewriteIndex
(
y
)
{
idx
=>
L
.
LetP
(
n
,
CPS
.
BlockSet
,
Seq
(
block
,
idx
,
value
),
apply
(
body
))}
case
L3
.
BlockGet
=>
val
block
=
rewrite
(
x
)
rewriteIndex
(
y
){
idx
=>
L
.
LetP
(
n
,
CPS
.
BlockGet
,
Seq
(
block
,
idx
),
apply
(
body
))}
case
L3
.
ByteRead
=>
tempLetP
(
CPS
.
ByteRead
,
Seq
()){
t1
=>
...
...
@@ -211,4 +206,11 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
L
.
AtomL
(
0x0a
)
// 01010
case
H
.
AtomL
(
UnitLit
)
=>
L
.
AtomL
(
2
)
}
private
def
rewriteIndex
(
idx
:
H.Atom
)(
cont
:
L.Atom
=>
L
.
LetP
)
:
L.LetP
=
idx
match
{
case
H
.
AtomN
(
n
)
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Left
(
idx
),
Right
(
L
.
AtomL
(
1
))))(
cont
)
case
H
.
AtomL
(
IntLit
(
i
))
=>
cont
(
L
.
AtomL
(
i
.
toInt
))
case
_
=>
throw
new
Exception
(
f
"Cannot rewrite atom {idx} which is not Name or Int Literal"
)
}
}
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