Class DerivedComparisonGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.DerivedComparisonGenerator
Generates synthetic IR for every comparison operator a type's <=> answers: <,
<=, >, >= - and == and <> whenever the type has its own
<=> (Steve, 2026-09-29: a defaulted comparison can never disagree with the type's ordering, so
a == b exactly when (a <=> b) == 0). A type with no <=> of its own (an unorderable
field) keeps the field-by-field == (EqualsGenerator) and <> as its negation
(NotEqualsGenerator). This also removed the defaulted <> that called an == the type
did not have - a compiler crash (front-end audit FE74).
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
- == - 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
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSyntheticGenerator
AbstractSyntheticGenerator.CycleGuardEntry, AbstractSyntheticGenerator.ScopeSetup -
Field Summary
Fields inherited from class AbstractSyntheticGenerator
stackContext, synthesisedCallMetaData -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(String operatorName, MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate IR for a derived comparison operator.Methods inherited from class AbstractSyntheticGenerator
aggregateHasOperator, constructorCall, createDebugInfo, createSynthesisScope, fieldTypeHasRealOperator, generateBinaryOperatorGuards, generateBooleanBranch, generateCycleGuardedRegion, generateCycleGuardEnter, generateFieldLoad, generateFieldLoad, generateFieldSetStatusCheck, generateIsSetGuard, generateIsSetGuard, generateLabelName, generatePoisonableCycleGuardedRegion, generateResultReturnBlock, generateResultReturnBlock, generateStringLiteralLoad, generateTempName, generateThisIsSetGuard, generateThisIsSetGuard, generateUnsetReturnBlockWithLabel, generateUnsetReturnBlockWithLabel, getAnyType, getAnyTypeName, getBitsType, getBitsTypeName, getBooleanType, getBooleanTypeName, getIntegerType, getIntegerTypeName, getReturnBlockHelper, getStringType, getStringTypeName, getSuperTypeName, getSyntheticFields, getType, getTypeName, getVoidTypeName, initializeScope, initializeScopeNoReturn, isAnyType, isTraitType, methodCall, nearestSuperOperator, needsCycleGuard, rendersNothing, servingOperatorParameterTypeName, superCallOwner, superContributesRepresentation, superHasOperator
-
Constructor Details
-
DerivedComparisonGenerator
DerivedComparisonGenerator(IRGenerationContext stackContext)
-
-
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 symbolaggregateSymbol- The aggregate containing the operator- Returns:
- List of IR instructions implementing the operator
-