Class DerivedComparisonGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.DerivedComparisonGenerator
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
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSyntheticGenerator
AbstractSyntheticGenerator.ScopeSetup -
Field Summary
Fields inherited from class AbstractSyntheticGenerator
stackContext -
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, createDebugInfo, createSynthesisScope, generateAnyFieldSetGuard, generateBinaryOperatorGuards, generateBooleanBranch, generateBooleanReturnBlock, generateConstructorCall, generateConstructorCall, generateConstructorCall, generateConstructorCallWithArgs, generateFieldLoad, generateFieldLoad, generateFieldSetStatusCheck, generateIsSetGuard, generateIsSetGuard, generateLabelName, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateResultReturnBlock, generateResultReturnBlock, generateStringLiteralLoad, generateTempName, generateThisIsSetGuard, generateThisIsSetGuard, generateUnsetReturnBlock, generateUnsetReturnBlockWithLabel, generateUnsetReturnBlockWithLabel, getBitsTypeName, getBooleanTypeName, getIntegerTypeName, getReturnBlockHelper, getStringTypeName, getSuperTypeName, getSyntheticFields, getTypeName, getVoidTypeName, initializeScope, isAnyType, 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
-