Class DispatchTableInstr
java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.DispatchTableInstr
- All Implemented Interfaces:
INode
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)
-
Method Summary
Modifier and TypeMethodDescriptionstatic DispatchTableInstrcreateDispatchTable(DispatchTableDetails details) Create a dispatch table instruction from details.booleanisVoid()toString()Methods inherited from class IRInstr
accept, addOperand, addOperands, equals, getDebugInfo, getEscapeMetaData, getOpcode, getOperands, getResult, hasEscapeMetaData, hashCode, hasResult, isControlFlow, isLabel, isMemoryManagement, isMethodCall, setEscapeMetaData
-
Method Details
-
createDispatchTable
Create a dispatch table instruction from details. -
getSelfTypeFqn
-
getMethodName
-
getReturnTypeFqn
-
getParamNames
-
getEntries
-
isVoid
public boolean isVoid() -
toString
-