Support for throwing exceptions from Eval

This commit is contained in:
Andrey Breslav
2013-10-06 13:35:46 +04:00
parent 7559c3bd94
commit 3bae3e25b5
+8 -6
View File
@@ -24,6 +24,8 @@ trait InterpretationEventHandler {
fun exceptionCaught(currentState: Frame<Value>, currentInsn: AbstractInsnNode, exception: Value): InterpreterResult? fun exceptionCaught(currentState: Frame<Value>, currentInsn: AbstractInsnNode, exception: Value): InterpreterResult?
} }
class ThrownFromEvalException(val exception: Value): RuntimeException()
fun interpreterLoop( fun interpreterLoop(
ownerClassInternalName: String, ownerClassInternalName: String,
m: MethodNode, m: MethodNode,
@@ -41,12 +43,10 @@ fun interpreterLoop(
} }
val interpreter = SingleInstructionInterpreter(eval) val interpreter = SingleInstructionInterpreter(eval)
try {
var frame = initFrame(ownerClassInternalName, m, interpreter) var frame = initFrame(ownerClassInternalName, m, interpreter)
while (true) { while (true) {
// TODO try-catch-finally support // TODO try-catch-finally support
// TODO support exceptions thrown by eval
val insnOpcode = currentInsn.getOpcode() val insnOpcode = currentInsn.getOpcode()
val insnType = currentInsn.getType() val insnType = currentInsn.getType()
@@ -95,17 +95,19 @@ fun interpreterLoop(
} }
} }
try {
frame.execute(currentInsn, interpreter) frame.execute(currentInsn, interpreter)
}
catch (e: ThrownFromEvalException) {
// TODO: try/catch.finaly
return ExceptionThrown(e.exception)
}
val handled = instructionHandler(currentInsn) val handled = instructionHandler(currentInsn)
if (handled != null) return handled if (handled != null) return handled
goto(currentInsn.getNext()) goto(currentInsn.getNext())
} }
}
catch (e: Throwable) {
throw e
}
} }
// Copied from org.objectweb.asm.tree.analysis.Analyzer.analyze() // Copied from org.objectweb.asm.tree.analysis.Analyzer.analyze()