Class Ek9ClassWriter

java.lang.Object
org.objectweb.asm.ClassVisitor
org.objectweb.asm.ClassWriter
org.ek9lang.compiler.backend.jvm.Ek9ClassWriter

final class Ek9ClassWriter extends org.objectweb.asm.ClassWriter
Custom ClassWriter that doesn't require loading classes during frame computation.

Standard ClassWriter.COMPUTE_FRAMES uses ClassLoader to find common superclasses when computing stack map frames. This fails when generating multiple classes in the same compilation unit because referenced classes aren't on classpath yet.

This custom writer uses a type hierarchy map (built from ISymbol data) to find actual common superclasses. This is essential for function delegate polymorphism: when if/else branches assign different concrete functions (e.g., UpperProcessor, LowerProcessor) to a variable of abstract type (Processor), ASM needs to know the actual common superclass (Processor) rather than defaulting to Object.

For exception types, uses java/lang/Throwable as the common superclass. For types not in the hierarchy map, defaults to java/lang/Object.

  • Field Summary

    Fields inherited from class org.objectweb.asm.ClassWriter

    COMPUTE_FRAMES, COMPUTE_MAXS

    Fields inherited from class org.objectweb.asm.ClassVisitor

    api, cv
  • Constructor Summary

    Constructors
    Constructor
    Description
    Ek9ClassWriter(int flags, Map<String,String> typeHierarchy)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Override getCommonSuperClass to use EK9's type hierarchy from ISymbol data.

    Methods inherited from class org.objectweb.asm.ClassWriter

    getClassLoader, hasFlags, newClass, newConst, newConstantDynamic, newField, newHandle, newHandle, newInvokeDynamic, newMethod, newMethodType, newModule, newNameType, newPackage, newUTF8, setFlags, toByteArray, visit, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitMethod, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitSource, visitTypeAnnotation

    Methods inherited from class org.objectweb.asm.ClassVisitor

    getDelegate

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Ek9ClassWriter

      Ek9ClassWriter(int flags, Map<String,String> typeHierarchy)
  • Method Details

    • getCommonSuperClass

      protected String getCommonSuperClass(String type1, String type2)
      Override getCommonSuperClass to use EK9's type hierarchy from ISymbol data. Walks up both type hierarchies to find the first common ancestor.
      Overrides:
      getCommonSuperClass in class org.objectweb.asm.ClassWriter
      Parameters:
      type1 - First type (internal name, e.g., "module/UpperProcessor")
      type2 - Second type (internal name, e.g., "module/LowerProcessor")
      Returns:
      Common superclass internal name (e.g., "module/Processor")