Class DerivedComparisonGenerator

java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.DerivedComparisonGenerator

final class DerivedComparisonGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for derived comparison operators: <, <=, >, >=.

These operators delegate to <=> (_cmp) and interpret the Integer result:

  • < - returns true if _cmp result < 0
  • <= - returns true if _cmp result <= 0
  • > - returns true if _cmp result > 0
  • >= - returns true if _cmp result >= 0

Generated code pattern:

Boolean operator(T other):
  cmpResult = this._cmp(other)
  if !cmpResult._isSet() -> return unset
  return cmpResult.{_lt|_lte|_gt|_gte}(0)

This approach leverages the existing _cmp implementation which already handles:

  • This/other isSet guards
  • Super class comparison
  • Field-by-field tri-state semantics
  • Constructor Details

  • Method Details

    • generate

      List<IRInstr> generate(String operatorName, MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol)
      Generate IR for a derived comparison operator.
      Parameters:
      operatorName - The operator symbol (<, <=, >, >=)
      operatorSymbol - The operator method symbol
      aggregateSymbol - The aggregate containing the operator
      Returns:
      List of IR instructions implementing the operator