Class EnumIteratorImplAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.EnumIteratorImplAsmGenerator
- All Implemented Interfaces:
Consumer<EnumIteratorImplInstr>
final class EnumIteratorImplAsmGenerator
extends AbstractAsmGenerator
implements Consumer<EnumIteratorImplInstr>
Specialized ASM generator for ENUM_ITERATOR_IMPL instruction.
Generates JVM bytecode for enum iterator implementation. The generated code:
- Generates an anonymous iterator class (EnumType$EnumIterator) that extends the parameterized Iterator wrapper (_Iterator_HASH...)
- Creates a java.util.ArrayList containing all enum values
- Gets a java.util.Iterator from the ArrayList
- Creates an instance of the anonymous class with the Java iterator
- Stores result in the designated result variable
Enum fields use Java primitives:
- _ordinal: int (primitive)
- _name: java.lang.String
- _isEnumSet: boolean (primitive)
This approach maintains the EK9 type hierarchy (Iterator of EnumType) while providing efficient iteration over enum values using native Java collections.
-
Field Summary
Fields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple, outputVisitor -
Constructor Summary
ConstructorsConstructorDescriptionEnumIteratorImplAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(EnumIteratorImplInstr instr) Generate JVM bytecode for ENUM_ITERATOR_IMPL instruction.Methods inherited from class AbstractAsmGenerator
convertToJvmDescriptor, convertToJvmName, extractFieldName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStringLiteral, getCurrentMethodVisitor, getFieldDescriptor, getMethodContext, getOrCreateLabel, getOwnerClassName, getVariableIndex, isFieldAccess, isVariableAllocated, isVariableFieldAccess, setCurrentMethodVisitor, setSharedMethodContext, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
EnumIteratorImplAsmGenerator
EnumIteratorImplAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
-
-
Method Details
-
accept
Generate JVM bytecode for ENUM_ITERATOR_IMPL instruction.Generated bytecode pattern:
// Generate anonymous iterator class (done once per enum) // EnumType$EnumIterator extends _Iterator_HASH... // Create ArrayList and populate with enum values NEW java.util.ArrayList DUP INVOKESPECIAL ArrayList.<init>() ASTORE listVar // For each enum value (e.g., Red, Green, Blue): ALOAD listVar NEW EnumType DUP INVOKESPECIAL EnumType.<init>() DUP [create Integer for ordinal] PUTFIELD EnumType._ordinal DUP [create String for name] PUTFIELD EnumType._name INVOKEINTERFACE List.add(Object) POP // discard boolean return // Get java.util.Iterator from ArrayList ALOAD listVar INVOKEINTERFACE List.iterator() ASTORE iterVar // Create anonymous iterator instance NEW EnumType$EnumIterator DUP ALOAD iterVar INVOKESPECIAL EnumType$EnumIterator.<init>(Iterator) ASTORE resultVar
- Specified by:
acceptin interfaceConsumer<EnumIteratorImplInstr>
-