Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
14 changes: 12 additions & 2 deletions src/main/scala/cafebabe/CodeHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ class CodeHandler private[cafebabe](c: CodeAttributeInfo, cp: ConstantPool, val
} else {
frozen = true

val abcList = abcBuffer.toList
val abcBufferList = abcBuffer.toList

//Add NOP at the end if the last instruction's size is 0 to avoid IndexOutofBounds
val abcList = abcBufferList.last match{
case abc if abc.size == 0 => abcBufferList :+ NOP
case _ => abcBufferList
}
code.maxLocals = locals

val labels : MutableMap[String,Int] = MutableMap.empty
Expand All @@ -108,7 +114,9 @@ class CodeHandler private[cafebabe](c: CodeAttributeInfo, cp: ConstantPool, val
lastLineNumber = ln
lineInfo(pc) = ln
}
case Label(name) => labels(name) = pc
case Label(name) => {
labels(name) = pc
}
case _ => ;
}
pc = pc + abc.size
Expand Down Expand Up @@ -153,6 +161,8 @@ class CodeHandler private[cafebabe](c: CodeAttributeInfo, cp: ConstantPool, val
locally {
var pc = 0
for(abc <- abcList) {
if(pc >= actualSize)
throw CodeFreezingException("Program counter at "+ pc +" exceeds actual size of codeArray " + actualSize, abcList)
codeArray(pc) = abc
pc += abc.size
}
Expand Down