compiler/vm/vmtypegen

  Source   Edit

This module implements the PType to VmType translation. No duplicate types are allowed, making type comparison via ID (currently PVmType) possible.

The distinct modifier is ignored (distinct int maps to the same type as just int) and named tuples are treated as unnamed tuples.

Types

GenClosure = object
  queue: seq[(PVmType, PType)]
  tmpFields: seq[PVmType]
  sizeQueue: seq[PVmType]    ## newly created types that need to have their size
                             ## computed
  conf: ConfigRef
  Source   Edit

Procs

proc getOrCreate(c: var TCtx; typ: PType; noClosure = false): PVmType {.inline,
    ...raises: [KeyError, Exception], tags: [RootEffect].}
  Source   Edit
proc getOrCreate(c: var TypeInfoCache; conf: ConfigRef; typ: PType;
                 noClosure: bool; cl: var GenClosure): PVmType {.inline,
    ...raises: [KeyError, Exception], tags: [RootEffect].}
Lookup or create the VmType corresponding to typ. If a new type is created, the PType -> PVmType mapping is cached   Source   Edit
proc initRootRef(c: var TypeInfoCache; config: ConfigRef; root: PType) {.
    ...raises: [KeyError, Exception], tags: [RootEffect].}
Sets up the rootRef field for c. root must be the PType for the RootObj type.   Source   Edit
func lookup(c: TypeInfoCache; conf: ConfigRef; typ: PType): Option[PVmType] {.
    ...raises: [KeyError], tags: [].}
Searches the cache for a VmType matching the given typ. If one exists, it's returned, otherwise, none is returned   Source   Edit
func makeSignatureId(c: var TypeInfoCache; typ: PType): RoutineSigId {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
Generates a unique ID for the routine signature typ. The exact meaning of "unique" here is given by the == function. Two types that are equal (using the aforementioned comparison) map to the same ID   Source   Edit