compiler/mir/mirtypes

  Source   Edit

Implements the type IR for the MIR phase (not yet), plus the TypeEnv, which stores the data for all types.

All types are addressed via TypeId, with the built-in types using static IDs.

Types

TypeEnv {.requiresInit.} = object
  map: TypeTable[TypeId] ## maps the hash of a type. Since the hash is not guaranteed to be
                         ## unique, hash collisions are possible!
  types: Store[TypeId, PType]
  sizeType: TypeId           ## the target-dependent integer type to use for size values
  usizeType: TypeId          ## the target-dependent unsigned integer type to use for size values
  
Stores the data associated with types. Has no valid default value, and must be explicitly initialized first.   Source   Edit

Consts

BoolType = 1'u32
  Source   Edit
CharType = 2'u32
  Source   Edit
CstringType = 14'u32
  Source   Edit
Float32Type = 11'u32
  Source   Edit
Float64Type = 12'u32
  Source   Edit
Int8Type = 3'u32
  Source   Edit
Int16Type = 4'u32
  Source   Edit
Int32Type = 5'u32
  Source   Edit
Int64Type = 6'u32
  Source   Edit
PointerType = 15'u32
  Source   Edit
StringType = 13'u32
  Source   Edit
UInt8Type = 7'u32
  Source   Edit
UInt16Type = 8'u32
  Source   Edit
UInt32Type = 9'u32
  Source   Edit
UInt64Type = 10'u32
  Source   Edit
VoidType = 0'u32
  Source   Edit

Procs

func `[]`(env: TypeEnv; id: TypeId): lent PType {.inline, ...raises: [], tags: [].}
  Source   Edit
proc add(env: var TypeEnv; t: PType): TypeId {....raises: [Exception],
    tags: [RootEffect].}
If not registered yet, adds t to env and returns the ID to later look it up with. Basic structural type unification is performed.   Source   Edit
proc initTypeEnv(graph: ModuleGraph): TypeEnv {.
    ...raises: [KeyError, Exception, ERecoverableError],
    tags: [ReadDirEffect, RootEffect].}
Returns a fully initialized type environment instance.   Source   Edit
func sizeType(env: TypeEnv): TypeId {.inline, ...raises: [], tags: [].}
Returns the type to use for values representing some size. This is a signed integer type of target-dependent bit-width.   Source   Edit
func usizeType(env: TypeEnv): TypeId {.inline, ...raises: [], tags: [].}
Returns the type to use for values representing some size. This is an unsigned integer type of target-dependent bit-width.   Source   Edit