# compiler/ic/packed_ast

Dark Mode

- Index

Search:
Group by:
Source Edit

Packed AST representation, mostly based on a seq of nodes. For IC support. Far future: Rewrite the compiler passes to use this representation directly in all the transformations, it is superior.

# Imports

bitabs, ../ast, ../options

# Types

    ModuleId = distinct int32

  Source Edit

    NodeId = distinct int32

  Source Edit

    NodePos = distinct int

  Source Edit

    PackedInstantiation = object
      key*, sym*: PackedItemId
      concreteTypes*: seq[PackedItemId]

  Source Edit

    PackedItemId = object
      module*: LitId
      item*: int32

  Source Edit

    PackedLib = object
      kind*: TLibKind
      generated*: bool
      isOverriden*: bool
      name*: LitId
      path*: NodeId

  Source Edit

    PackedLineInfo = object
      line*: uint16
      col*: int16
      file*: LitId

  Source Edit

    PackedNode = object
      kind*: TNodeKind
      flags*: TNodeFlags
      operand*: int32
      typeId*: PackedItemId
      info*: PackedLineInfo

  Source Edit

    PackedSym = object
      kind*: TSymKind
      name*: LitId
      typ*: PackedItemId
      flags*: TSymFlags
      magic*: TMagic
      info*: PackedLineInfo
      ast*: NodeId
      owner*: PackedItemId
      guard*: PackedItemId
      bitsize*: int
      alignment*: int
      options*: TOptions
      position*: int
      offset*: int
      externalName*: LitId
      locFlags*: TLocFlags
      annex*: PackedLib
      when hasFFI:
          cname*: LitId

      constraint*: NodeId

  Source Edit

    PackedTree = object
      nodes*: seq[PackedNode]

  usually represents a full Nim module Source Edit

    PackedType = object
      kind*: TTypeKind
      callConv*: TCallingConvention
      flags*: TTypeFlags
      types*: seq[PackedItemId]
      n*: NodeId
      sym*: PackedItemId
      owner*: PackedItemId
      size*: BiggestInt
      align*: int16
      paddingAtEnd*: int16
      lockLevel*: TLockLevel
      typeInst*: PackedItemId
      nonUniqueId*: int32

  Source Edit

    SymId = distinct int32

  Source Edit

# Consts

    directIntLit = nkInt32Lit

  Source Edit

    emptyNodeId = -1'i32

  Source Edit

    externIntLit = {nkCharLit, nkIntLit, nkInt8Lit, nkInt16Lit, nkInt64Lit,
                    nkUIntLit, nkUInt8Lit, nkUInt16Lit, nkUInt32Lit, nkUInt64Lit}

  Source Edit

    externSIntLit = {nkIntLit, nkInt8Lit, nkInt16Lit, nkInt64Lit}

  Source Edit

    externUIntLit = {nkUIntLit, nkUInt8Lit, nkUInt16Lit, nkUInt32Lit, nkUInt64Lit}

  Source Edit

    nilItemId = (module: 0'u, item: -1)

  Source Edit

# Procs

    proc `==`(a, b: NodeId): bool {.borrow, ...raises: [], tags: [].}

  Source Edit

    proc `==`(a, b: NodePos): bool {.borrow, ...raises: [], tags: [].}

  Source Edit

    proc `==`(a, b: SymId): bool {.borrow, ...raises: [], tags: [].}

  Source Edit

    proc `[]`(tree: PackedTree; i: int): lent PackedNode {.inline, ...raises: [],
        tags: [].}

  Source Edit

    proc addIdent(tree: var PackedTree; s: LitId; info: PackedLineInfo) {.
        ...raises: [], tags: [].}

  Source Edit

    proc addModuleId(tree: var PackedTree; s: ModuleId; info: PackedLineInfo) {.
        ...raises: [], tags: [].}

  Source Edit

    proc addSym(tree: var PackedTree; s: int32; info: PackedLineInfo) {....raises: [],
        tags: [].}

  Source Edit

    proc addSymDef(tree: var PackedTree; s: SymId; info: PackedLineInfo) {.
        ...raises: [], tags: [].}

  Source Edit

    proc copyTree(dest: var PackedTree; tree: PackedTree; n: NodePos) {....raises: [],
        tags: [].}

  Source Edit

    proc firstSon(n: NodePos): NodePos {.inline, ...raises: [], tags: [].}

  Source Edit

    proc firstSon(tree: PackedTree; n: NodePos): NodePos {.inline, ...raises: [],
        tags: [].}

  Source Edit

    proc getNodeId(tree: PackedTree): NodeId {.inline, ...raises: [], tags: [].}

  Source Edit

    proc hasAtLeastXsons(tree: PackedTree; n: NodePos; x: int): bool {....raises: [],
        tags: [].}

  Source Edit

    proc hash(a: SymId): Hash {.borrow, ...raises: [], tags: [].}

  Source Edit

    proc hasXsons(tree: PackedTree; n: NodePos; x: int): bool {....raises: [], tags: [].}

  Source Edit

    proc info(tree: PackedTree; n: NodePos): PackedLineInfo {.inline, ...raises: [],
        tags: [].}

  Source Edit

    proc isAtom(tree: PackedTree; pos: int): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc ithSon(tree: PackedTree; n: NodePos; i: int): NodePos {....raises: [],
        tags: [].}

  Source Edit

    proc kind(tree: PackedTree; n: NodePos): TNodeKind {.inline, ...raises: [],
        tags: [].}

  Source Edit

    proc len(tree: PackedTree): int {.inline, ...raises: [], tags: [].}

  Source Edit

    proc litId(tree: PackedTree; n: NodePos): LitId {.inline, ...raises: [], tags: [].}

  Source Edit

    proc newTreeFrom(old: PackedTree): PackedTree {....raises: [], tags: [].}

  Source Edit

    proc patch(tree: var PackedTree; pos: PatchPos) {....raises: [], tags: [].}

  Source Edit

    proc prepare(dest: var PackedTree; source: PackedTree; sourcePos: NodePos): PatchPos {.
        ...raises: [], tags: [].}

  Source Edit

    proc prepare(tree: var PackedTree; kind: TNodeKind; flags: TNodeFlags;
                 typeId: PackedItemId; info: PackedLineInfo): PatchPos {....raises: [],
        tags: [].}

  Source Edit

    proc sons2(tree: PackedTree; n: NodePos): (NodePos, NodePos) {....raises: [],
        tags: [].}

  Source Edit

    proc sons3(tree: PackedTree; n: NodePos): (NodePos, NodePos, NodePos) {.
        ...raises: [], tags: [].}

  Source Edit

    proc span(tree: PackedTree; pos: int): int {.inline, ...raises: [], tags: [].}

  Source Edit

    proc throwAwayLastNode(tree: var PackedTree) {....raises: [], tags: [].}

  Source Edit

    proc toPackedItemId(item: int32): PackedItemId {.inline, ...raises: [], tags: [].}

  Source Edit

# Iterators

    iterator allNodes(tree: PackedTree): NodePos {....raises: [], tags: [].}

  Source Edit

    iterator isons(dest: var PackedTree; tree: PackedTree; n: NodePos): (int,
        NodePos) {....raises: [], tags: [].}

  Source Edit

    iterator sons(dest: var PackedTree; tree: PackedTree; n: NodePos): NodePos {.
        ...raises: [], tags: [].}

  Source Edit

    iterator sonsFrom1(tree: PackedTree; n: NodePos): NodePos {....raises: [], tags: [].}

  Source Edit

    iterator sonsReadonly(tree: PackedTree; n: NodePos): NodePos {....raises: [],
        tags: [].}

  Source Edit

    iterator sonsWithoutLast2(tree: PackedTree; n: NodePos): NodePos {....raises: [],
        tags: [].}

  Source Edit

# Templates

    template copyInto(dest, n, body)

  Source Edit

    template copyIntoKind(dest, kind, info, body)

  Source Edit

    template flags(n: NodePos): TNodeFlags

  Source Edit

    template info(n: NodePos): PackedLineInfo

  Source Edit

    template kind(n: NodePos): TNodeKind

  Source Edit

    template litId(n: NodePos): LitId

  Source Edit

    template operand(n: NodePos): int32

  Source Edit

    template parent(n: NodePos): NodePos

  Source Edit

    template symId(n: NodePos): SymId

  Source Edit

    template typ(n: NodePos): PackedItemId

  Source Edit