Class DispatchTableInstr

java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.DispatchTableInstr
All Implemented Interfaces:
INode

public final class DispatchTableInstr extends IRInstr
High-level IR instruction for a precomputed dispatch table.

This instruction is prepended to a dispatcher method's body. When the backend encounters it, it generates runtime type testing code (e.g., getClass() comparisons on JVM) that routes to the correct handler. If no entry matches, execution falls through to the rest of the method body (the fallback/entry point code).

The dispatch table is fully resolved at compile time using the same cost model from Phase 5 ambiguity validation. Each entry maps exact concrete type FQN(s) to the winning handler method. No hierarchy walking or cost computation at runtime.

The backend is responsible for:

  • Emitting type identity checks per entry (JVM: getClass() + if_acmpne, LLVM: type tag cmp)
  • Casting arguments to handler parameter types (JVM: CHECKCAST)
  • Virtual dispatch to handler method (JVM: INVOKEVIRTUAL/INVOKEINTERFACE)
  • Returning handler result (or falling through to method body if no match)