Class TryCatchAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.AbstractControlFlowAsmGenerator
org.ek9lang.compiler.backend.jvm.TryCatchAsmGenerator
Specialized generator for EK9 try/catch/finally statements.
Handles CONTROL_FLOW_CHAIN with chain_type: "TRY_CATCH_FINALLY".
JVM Bytecode Pattern for try/catch:
try_start: [try block instructions] goto after_handlers ; Normal exit try_end: catch_start_1: [catch block 1 instructions] goto after_handlers catch_end_1: after_handlers: [continue execution]
JVM Bytecode Pattern for try/finally (unified finally block):
try_start: [try block instructions] try_end: goto finally_block ; Normal path catch_start: [catch block instructions] goto finally_block ; Catch path finally_exception: astore temp_exception ; Store exception goto finally_block ; Exception path finally_block: [finally block - executes once for all paths] aload temp_exception (if set) ifnull after_finally athrow ; Rethrow if exception present after_finally: [continue execution] Exception Table: from to target type try_start try_end finally_exception null (catch-all)
Stack Frame Invariant: Stack is empty before try, after each handler, and after the entire statement.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractAsmGenerator
AbstractAsmGenerator.LocalVariableInfo, AbstractAsmGenerator.MethodContext, AbstractAsmGenerator.ScopeInfo, AbstractAsmGenerator.TempVariableSource -
Field Summary
Fields inherited from class AbstractControlFlowAsmGenerator
contextFields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple, outputVisitor -
Constructor Summary
ConstructorsConstructorDescriptionTryCatchAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ControlFlowChainInstr instr) Generate bytecode for try/catch/finally.Methods inherited from class AbstractControlFlowAsmGenerator
branchIfFalse, branchIfTrue, copyResultVariable, createControlFlowLabel, jumpTo, placeLabel, processBodyEvaluation, processConditionCase, processConditionCaseWithoutLabelPlacement, processConditionEvaluation, processInstructionsMethods inherited from class AbstractAsmGenerator
convertToJvmDescriptor, convertToJvmName, extractFieldName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStringLiteral, getCurrentMethodVisitor, getFieldDescriptor, getMethodContext, getOrCreateLabel, getOwnerClassName, getVariableIndex, isFieldAccess, isVariableAllocated, setCurrentMethodVisitor, setSharedMethodContext, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
TryCatchAsmGenerator
TryCatchAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter, BytecodeGenerationContext context)
-
-
Method Details
-
generate
Generate bytecode for try/catch/finally.Control Flow:
- Create labels for exception handlers and finally blocks
- Register exception handlers with JVM (visitTryCatchBlock)
- Execute try block
- Execute finally block (normal path) if present
- Jump to after handlers
- Execute each catch handler
- Execute finally block (exception path) if present
Stack Frame Invariant: Pre-condition: stack is empty Post-condition: stack is empty
- Parameters:
instr- CONTROL_FLOW_CHAIN instruction with TRY_CATCH_FINALLY type
-