Enum Class InstanceOfKind

java.lang.Object
java.lang.Enum<InstanceOfKind>
org.ek9lang.compiler.ir.instructions.InstanceOfKind
All Implemented Interfaces:
Serializable, Comparable<InstanceOfKind>, Constable

public enum InstanceOfKind extends Enum<InstanceOfKind>
Discriminator for the 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.

  • Enum Constant Details

    • EXACT

      public static final InstanceOfKind 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 (via INVOKEVIRTUAL Object.getClass / LDC / IF_ACMPEQ).
      • LLVM (future): null-check then icmp eq i32 on the ek9_ObjectHeader.type_hash field against the compile-time FNV-1a hash of targetType.
    • SUBTYPE

      public static final InstanceOfKind SUBTYPE
      source.type isA targetType — true for targetType and 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 TargetClass bytecode.
      • 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.
    • TRAIT

      public static final InstanceOfKind TRAIT
      source.type implements targetType, where targetType is a trait. Not currently emitted. Distinguished from SUBTYPE because 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 JVM INSTANCEOF bytecode 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.

  • Method Details

    • values

      public static InstanceOfKind[] 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

      public static InstanceOfKind valueOf(String name)
      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 name
      NullPointerException - if the argument is null