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
324b72dc
Commit
324b72dc
authored
Mar 26, 2021
by
Luca Bataillard
Browse files
fix array out of bounds issue
parent
cf388c4a
Changes
1
Show whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSValueRepresenter.scala
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"
)
}
}
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