Class CompareGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.CompareGenerator
Generates synthetic IR for the _cmp (<=>) operator.
The generated code follows this pattern:
Integer _cmp(T other):
// Guard: check this is set
if !this._isSet() -> return unset
// Guard: check other is set
if !other._isSet() -> return unset
// Super check (if super is not Any)
if super != Any:
result = super._cmp(other)
if !result._isSet() -> return unset
if result != 0 -> return result
// Field-by-field comparison (in declaration order)
for each field in properties:
result = this.field._cmp(other.field)
if !result._isSet() -> return unset
if result != 0 -> return result
return 0 // All fields equal
Key semantic requirements:
- If this or other is unset, return unset
- If any field comparison returns unset, return unset
- If any field comparison returns non-zero, return that value (short-circuit)
- Only if all comparisons return zero, return zero
- Super's _cmp is called first if super is not Any
- Fields are compared in declaration order
-
Field Summary
Fields inherited from class AbstractSyntheticGenerator
stackContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate the _cmp operator IR for the given aggregate.Methods inherited from class AbstractSyntheticGenerator
createDebugInfo, generateBooleanReturnBlock, generateConstructorCall, generateFieldLoad, generateIsSetGuard, generateLabelName, generateMethodCall, generateTempName, generateThisIsSetGuard, generateUnsetReturnBlock, getBooleanTypeName, getIntegerTypeName, getStringTypeName, getSuperTypeName, getSyntheticFields, getTypeName, getVoidTypeName, isAnyType, superHasOperator
-
Constructor Details
-
CompareGenerator
CompareGenerator(IRGenerationContext stackContext)
-
-
Method Details
-
generate
Generate the _cmp operator IR for the given aggregate.- Parameters:
operatorSymbol- The _cmp operator method symbolaggregateSymbol- The aggregate containing the operator- Returns:
- List of IR instructions implementing the operator
-