Skip to content

Commit 719b0b8

Browse files
committed
progress
1 parent ec607ec commit 719b0b8

File tree

2 files changed

+66
-26
lines changed

2 files changed

+66
-26
lines changed

compiler/ast.nim

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,19 @@ proc add*(father, son: PType) =
549549
proc addAllowNil*(father, son: PType) {.inline.} =
550550
father.sonsImpl.add son
551551

552-
template `[]`*(n: PType, i: int): PType = n.sonsImpl[i]
552+
template `[]`*(n: PType, i: int): PType =
553+
if n.state == Partial: loadType(n)
554+
n.sonsImpl[i]
553555
template `[]=`*(n: PType, i: int; x: PType) =
556+
if n.state == Partial: loadType(n)
554557
n.sonsImpl[i] = x
555558

556-
template `[]`*(n: PType, i: BackwardsIndex): PType = n[n.len - i.int]
557-
template `[]=`*(n: PType, i: BackwardsIndex; x: PType) = n[n.len - i.int] = x
559+
template `[]`*(n: PType, i: BackwardsIndex): PType =
560+
if n.state == Partial: loadType(n)
561+
n[n.len - i.int]
562+
template `[]=`*(n: PType, i: BackwardsIndex; x: PType) =
563+
if n.state == Partial: loadType(n)
564+
n[n.len - i.int] = x
558565

559566
proc getDeclPragma*(n: PNode): PNode =
560567
## return the `nkPragma` node for declaration `n`, or `nil` if no pragma was found.
@@ -791,29 +798,57 @@ proc replaceFirstSon*(n, newson: PNode) {.inline.} =
791798
proc replaceSon*(n: PNode; i: int; newson: PNode) {.inline.} =
792799
n.sons[i] = newson
793800

794-
proc last*(n: PType): PType {.inline.} = n.sonsImpl[^1]
801+
proc last*(n: PType): PType {.inline.} =
802+
if n.state == Partial: loadType(n)
803+
n.sonsImpl[^1]
795804

796-
proc elementType*(n: PType): PType {.inline.} = n.sonsImpl[^1]
797-
proc skipModifier*(n: PType): PType {.inline.} = n.sonsImpl[^1]
805+
proc elementType*(n: PType): PType {.inline.} =
806+
if n.state == Partial: loadType(n)
807+
n.sonsImpl[^1]
798808

799-
proc indexType*(n: PType): PType {.inline.} = n.sonsImpl[0]
800-
proc baseClass*(n: PType): PType {.inline.} = n.sonsImpl[0]
809+
proc skipModifier*(n: PType): PType {.inline.} =
810+
if n.state == Partial: loadType(n)
811+
n.sonsImpl[^1]
812+
813+
proc indexType*(n: PType): PType {.inline.} =
814+
if n.state == Partial: loadType(n)
815+
n.sonsImpl[0]
816+
817+
proc baseClass*(n: PType): PType {.inline.} =
818+
if n.state == Partial: loadType(n)
819+
n.sonsImpl[0]
801820

802821
proc base*(t: PType): PType {.inline.} =
822+
if t.state == Partial: loadType(t)
803823
result = t.sonsImpl[0]
804824

805-
proc returnType*(n: PType): PType {.inline.} = n.sonsImpl[0]
825+
proc returnType*(n: PType): PType {.inline.} =
826+
if n.state == Partial: loadType(n)
827+
n.sonsImpl[0]
828+
806829
proc setReturnType*(n, r: PType) {.inline.} =
830+
if n.state == Partial: loadType(n)
807831
n.sonsImpl[0] = r
832+
808833
proc setIndexType*(n, idx: PType) {.inline.} =
834+
if n.state == Partial: loadType(n)
809835
n.sonsImpl[0] = idx
810836

811-
proc firstParamType*(n: PType): PType {.inline.} = n.sonsImpl[1]
812-
proc firstGenericParam*(n: PType): PType {.inline.} = n.sonsImpl[1]
837+
proc firstParamType*(n: PType): PType {.inline.} =
838+
if n.state == Partial: loadType(n)
839+
n.sonsImpl[1]
840+
841+
proc firstGenericParam*(n: PType): PType {.inline.} =
842+
if n.state == Partial: loadType(n)
843+
n.sonsImpl[1]
813844

814-
proc typeBodyImpl*(n: PType): PType {.inline.} = n.sonsImpl[^1]
845+
proc typeBodyImpl*(n: PType): PType {.inline.} =
846+
if n.state == Partial: loadType(n)
847+
n.sonsImpl[^1]
815848

816-
proc genericHead*(n: PType): PType {.inline.} = n.sonsImpl[0]
849+
proc genericHead*(n: PType): PType {.inline.} =
850+
if n.state == Partial: loadType(n)
851+
n.sonsImpl[0]
817852

818853
proc skipTypes*(t: PType, kinds: TTypeKinds): PType =
819854
## Used throughout the compiler code to test whether a type tree contains or

compiler/ast2nif.nim

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,6 @@ proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) =
268268
dest.addIdent "x"
269269
else:
270270
dest.addDotToken
271-
if sym.magicImpl == mNone:
272-
dest.addDotToken
273-
else:
274-
dest.addIdent toNifTag(sym.magicImpl)
275-
writeFlags(dest, sym.flagsImpl)
276-
writeFlags(dest, sym.optionsImpl)
277-
dest.addIntLit sym.offsetImpl
278271
# field `disamb` made part of the name, so do not store it here
279272
dest.buildTree sym.kindImpl.toNifTag:
280273
case sym.kindImpl
@@ -284,6 +277,15 @@ proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) =
284277
dest.addIntLit sym.alignmentImpl
285278
else:
286279
discard
280+
281+
if sym.magicImpl == mNone:
282+
dest.addDotToken
283+
else:
284+
dest.addIdent toNifTag(sym.magicImpl)
285+
writeFlags(dest, sym.flagsImpl)
286+
writeFlags(dest, sym.optionsImpl)
287+
dest.addIntLit sym.offsetImpl
288+
287289
if sym.kindImpl == skModule:
288290
dest.addDotToken() # position will be set by the loader!
289291
else:
@@ -786,13 +788,9 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule:
786788
else:
787789
raiseAssert "expected `x` or '.' but got " & $n.kind
788790

789-
loadField s.magicImpl
790-
loadField s.flagsImpl
791-
loadField s.optionsImpl
792-
loadField s.offsetImpl
793-
794791
expect n, ParLe
795-
s.kindImpl = parse(TSymKind, pool.tags[n.tagId])
792+
{.cast(uncheckedAssign).}:
793+
s.kindImpl = parse(TSymKind, pool.tags[n.tagId])
796794
inc n
797795

798796
case s.kindImpl
@@ -804,6 +802,11 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule:
804802
discard
805803
skipParRi n
806804

805+
loadField s.magicImpl
806+
loadField s.flagsImpl
807+
loadField s.optionsImpl
808+
loadField s.offsetImpl
809+
807810
if s.kindImpl == skModule:
808811
expect n, DotToken
809812
inc n
@@ -829,6 +832,8 @@ proc loadSym*(c: var DecodeContext; s: PSym) =
829832
expect n, ParLe
830833
if n.tagId != sdefTag:
831834
raiseAssert "(sd) expected"
835+
# Extract line info from the sdef tag before moving past it
836+
s.infoImpl = c.infos.oldLineInfo(n.info)
832837
inc n
833838
loadSymFromCursor(c, s, n, c.moduleToNifSuffix[symsModule])
834839

0 commit comments

Comments
 (0)