Enum Class InstanceOfKind
- All Implemented Interfaces:
Serializable, Comparable<InstanceOfKind>, Constable
CastInstr.instanceOf(String, String, String, InstanceOfKind, DebugInfo) IR instruction.
The single INSTANCEOF opcode is kind-discriminated so that backends
lower it with the correct runtime semantics. Without the kind, JVM and LLVM
lowerings can silently diverge — the JVM's native INSTANCEOF bytecode is
subtype-aware, while a type_hash compare on the EK9 object header is
exact-identity only.
The producer always knows which semantics it wants; it must say so explicitly. The IR opcode pretending to be backend-agnostic while encoding only what the JVM happens to do is a bug magnet.
A null source deterministically yields false for all three
kinds, matching JVM convention.
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic InstanceOfKindReturns the enum constant of this class with the specified name.static InstanceOfKind[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
EXACT
source.type == targetType— true exact type identity. Subclasses do NOT match. All current EK9 IR producers want this: every existing call site tests against a closed parameterised wrapper type whose value-set is exactly that wrapper class, never a subclass.Backend lowerings:
- JVM:
source.getClass() == TargetClass.class(viaINVOKEVIRTUAL Object.getClass / LDC / IF_ACMPEQ). - LLVM (future): null-check then
icmp eq i32on theek9_ObjectHeader.type_hashfield against the compile-time FNV-1a hash oftargetType.
- JVM:
-
SUBTYPE
source.type isA targetType— true fortargetTypeand any subclass. Not currently emitted by any EK9 IR producer; reserved for when subtype-aware checks against open classes become needed (e.g. flow-sensitive narrowing, Any-typed parameters).Backend lowerings:
- JVM: native
INSTANCEOF TargetClassbytecode. - LLVM (future): parent-hash-chain walk, Cohen-style type-range encoding,
or a C-runtime helper such as
__ek9_is_subtype(child_hash, parent_hash). Implementation choice deferred to when first emitter lands.
- JVM: native
-
TRAIT
source.type implements targetType, wheretargetTypeis a trait. Not currently emitted. Distinguished fromSUBTYPEbecause the LLVM mechanism differs from a parent-chain walk: a trait dispatch table or a trait-bitmap per vtable is likely. The producer already knows whether the target is a trait, so marking it explicitly saves the backend from having to inspect the target.Backend lowerings:
- JVM: identical to
SUBTYPE— the JVMINSTANCEOFbytecode handles interfaces uniformly with classes. - LLVM (future): trait-specific dispatch lookup, mechanism TBD.
If runtime work later decides traits and subtype share a mechanism, this kind can collapse into
SUBTYPE; the IR shape stays stable. - JVM: identical to
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-