Class DispatchTableAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.DispatchTableAsmGenerator
- All Implemented Interfaces:
Consumer<DispatchTableInstr>
final class DispatchTableAsmGenerator
extends AbstractAsmGenerator
implements Consumer<DispatchTableInstr>
Specialized ASM generator for DISPATCH_TABLE instruction.
Generates a chain of exact runtime type identity checks (getClass() comparisons) at the start of a dispatcher method. Each entry in the precomputed dispatch table becomes:
ALOAD param INVOKEVIRTUAL java/lang/Object.getClass() LDC ConcreteType.class IF_ACMPNE L_next ALOAD_0 // load 'this' ALOAD param CHECKCAST HandlerParamType // cast to handler's declared param type INVOKEVIRTUAL/INVOKEINTERFACE // virtual call to handler ARETURN / RETURN // return handler result L_next:
After all entries, execution falls through to the original method body (the dispatcher entry point's fallback code).
Uses getClass() (not instanceof) for exact type identity — a Square object matches only the Square entry, never Rectangle. The dispatch table contains only concrete types that can actually be instantiated.
-
Field Summary
Fields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple, outputVisitor -
Constructor Summary
ConstructorsConstructorDescriptionDispatchTableAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter) -
Method Summary
Methods inherited from class AbstractAsmGenerator
convertToJvmDescriptor, convertToJvmName, extractFieldName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStoreVariableAsInt, generateStringLiteral, getCurrentMethodVisitor, getFieldDescriptor, getMethodContext, getOrCreateLabel, getOwnerClassName, getVariableIndex, isFieldAccess, isVariableAllocated, isVariableFieldAccess, setCurrentMethodVisitor, setSharedMethodContext, toJvmFieldName, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
DispatchTableAsmGenerator
DispatchTableAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<DispatchTableInstr>
-