All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.scalanative.codegen.FieldLayout.scala Maven / Gradle / Ivy

There is a newer version: 0.5.5
Show newest version
package scala.scalanative
package codegen

import scalanative.nir._
import scalanative.linker.{Class, Field}

class FieldLayout(meta: Metadata, cls: Class) {
  def index(fld: Field) =
    entries.indexOf(fld) + 1
  val entries: Seq[Field] = {
    val base = cls.parent.fold {
      Seq.empty[Field]
    } { parent => meta.layout(parent).entries }
    base ++ cls.members.collect { case f: Field => f }
  }
  val struct: Type.StructValue = {
    val data = entries.map(_.ty)
    val body = Type.Ptr +: data
    Type.StructValue(body)
  }
  val layout = MemoryLayout(struct.tys)
  val size = layout.size
  val referenceOffsetsTy =
    Type.StructValue(Seq(Type.Ptr))
  val referenceOffsetsValue =
    Val.StructValue(
      Seq(Val.Const(Val.ArrayValue(Type.Long, layout.offsetArray)))
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy