Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export astdef
when not defined(nimKochBootstrap):
import ast2nif

template typ*(n: PNode): PType =
n.typField

when not defined(nimKochBootstrap):
var program* {.threadvar.}: DecodeContext

Expand Down Expand Up @@ -366,26 +363,23 @@ proc size*(t: PType): BiggestInt {.inline.} =
result = t.sizeImpl

proc `size=`*(t: PType, val: BiggestInt) {.inline.} =
assert t.state != Sealed
if t.state == Partial: loadType(t)
backendEnsureMutable t
t.sizeImpl = val

proc align*(t: PType): int16 {.inline.} =
if t.state == Partial: loadType(t)
result = t.alignImpl

proc `align=`*(t: PType, val: int16) {.inline.} =
assert t.state != Sealed
if t.state == Partial: loadType(t)
backendEnsureMutable t
t.alignImpl = val

proc paddingAtEnd*(t: PType): int16 {.inline.} =
if t.state == Partial: loadType(t)
result = t.paddingAtEndImpl

proc `paddingAtEnd=`*(t: PType, val: int16) {.inline.} =
assert t.state != Sealed
if t.state == Partial: loadType(t)
backendEnsureMutable t
t.paddingAtEndImpl = val

proc loc*(t: PType): TLoc {.inline.} =
Expand Down Expand Up @@ -426,6 +420,14 @@ proc excl*(t: PType; flags: set[TTypeFlag]) {.inline.} =
if t.state == Partial: loadType(t)
t.flagsImpl.excl(flags)

proc typ*(n: PNode): PType {.inline.} =
result = n.typField
if result == nil and nfLazyType in n.flags:
result = n.sym.typ

proc `typ=`*(n: PNode, val: sink PType) {.inline.} =
n.typField = val

template nodeId(n: PNode): int = cast[int](n)

type Gconfig = object
Expand Down Expand Up @@ -769,7 +771,7 @@ proc withInfo*(n: PNode, info: TLineInfo): PNode =
proc newSymNode*(sym: PSym): PNode =
result = newNode(nkSym)
result.sym = sym
result.typ() = sym.typ
result.typField = sym.typ
result.info = sym.info

proc newOpenSym*(n: PNode): PNode {.inline.} =
Expand Down Expand Up @@ -879,7 +881,7 @@ proc newIntTypeNode*(intVal: BiggestInt, typ: PType): PNode =
result = newNode(nkIntLit)
else: raiseAssert $kind
result.intVal = intVal
result.typ() = typ
result.typField = typ

proc newIntTypeNode*(intVal: Int128, typ: PType): PNode =
# XXX: introduce range check
Expand Down Expand Up @@ -1180,7 +1182,7 @@ proc copyNode*(src: PNode): PNode =
return nil
result = newNode(src.kind)
result.info = src.info
result.typ() = src.typ
result.typ = src.typ
result.flags = src.flags * PersistentNodeFlags
result.comment = src.comment
when defined(useNodeIds):
Expand Down Expand Up @@ -1249,7 +1251,7 @@ template copyNodeImpl(dst, src, processSonsStmt) =
dst.info = src.info
when defined(nimsuggest):
result.endInfo = src.endInfo
dst.typ() = src.typ
dst.typ = src.typ
dst.flags = src.flags * PersistentNodeFlags
dst.comment = src.comment
when defined(useNodeIds):
Expand Down
Loading