Package org.ek9lang.compiler.phase7.synthesis
package org.ek9lang.compiler.phase7.synthesis
Synthetic operator and method generation for EK9.
This package contains the infrastructure for generating IR instructions for synthetic operators and methods. These are operators/methods declared with the 'default' keyword in EK9 source code, where the compiler generates the implementation automatically based on the aggregate's fields.
Architecture
Synthetic generation happens at IR level (Phase 7), not at the backend level. This ensures:
- Single implementation serves both JVM and LLVM backends
- Testable via @IR directives
- IR optimization (Phase 12) benefits both backends
- Backends remain "pretty dumb" - just translate IR instructions
Key Classes
SyntheticOperatorGenerator- Main coordinator that dispatches to specific generatorsAbstractSyntheticGenerator- Base class with common patterns (isSet guards, return blocks)
Supported Operators
For records and classes with 'default operator':
- _eq (==) - Field-by-field equality
- _neq (<>) - Negation of _eq
- _hashcode (#?) - Combined hash of all fields
- _string ($) - String representation
- _copy (:=:) - Copy all fields
For enumerations (implicitly generated):
- _lt, _lte, _gt, _gte - Ordinal comparisons
- _cmp (<=>) - Three-way comparison
- _inc, _dec (++, --) - Navigation through enum values
-
ClassesClassDescriptionBase class for synthetic operator generators.Generates synthetic IR for the _cmp (<=>) operator.Generates synthetic IR for the _copy (:=:) operator.Generates synthetic IR for derived comparison operators: <, <=, >, >=.Generates synthetic IR for the _eq (==) operator.Generates synthetic IR for the _fieldSetStatus() method.Generates synthetic IR for the _hashcode (#?) operator.Generates synthetic IR for the _isSet (?) operator.Generates synthetic IR for the _neq (<>) operator.Main coordinator for synthetic operator generation.Generates synthetic IR for the _string ($) operator.