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.