Skip to content

Commit 7fd02fc

Browse files
committed
progress
1 parent 447bf7e commit 7fd02fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+421
-409
lines changed

compiler/ast.nim

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ export astdef
2929
when not defined(nimKochBootstrap):
3030
import ast2nif
3131

32-
template typ*(n: PNode): PType =
33-
n.typField
34-
3532
when not defined(nimKochBootstrap):
3633
var program* {.threadvar.}: DecodeContext
3734

@@ -426,6 +423,14 @@ proc excl*(t: PType; flags: set[TTypeFlag]) {.inline.} =
426423
if t.state == Partial: loadType(t)
427424
t.flagsImpl.excl(flags)
428425

426+
proc typ*(n: PNode): PType {.inline.} =
427+
result = n.typField
428+
if result == nil and nfLazyType in n.flags:
429+
result = n.sym.typ
430+
431+
proc `typ=`*(n: PNode, val: sink PType) {.inline.} =
432+
n.typField = val
433+
429434
template nodeId(n: PNode): int = cast[int](n)
430435

431436
type Gconfig = object
@@ -769,7 +774,7 @@ proc withInfo*(n: PNode, info: TLineInfo): PNode =
769774
proc newSymNode*(sym: PSym): PNode =
770775
result = newNode(nkSym)
771776
result.sym = sym
772-
result.typ() = sym.typ
777+
result.typField = sym.typ
773778
result.info = sym.info
774779

775780
proc newOpenSym*(n: PNode): PNode {.inline.} =
@@ -879,7 +884,7 @@ proc newIntTypeNode*(intVal: BiggestInt, typ: PType): PNode =
879884
result = newNode(nkIntLit)
880885
else: raiseAssert $kind
881886
result.intVal = intVal
882-
result.typ() = typ
887+
result.typField = typ
883888

884889
proc newIntTypeNode*(intVal: Int128, typ: PType): PNode =
885890
# XXX: introduce range check
@@ -1180,7 +1185,7 @@ proc copyNode*(src: PNode): PNode =
11801185
return nil
11811186
result = newNode(src.kind)
11821187
result.info = src.info
1183-
result.typ() = src.typ
1188+
result.typ = src.typ
11841189
result.flags = src.flags * PersistentNodeFlags
11851190
result.comment = src.comment
11861191
when defined(useNodeIds):
@@ -1249,7 +1254,7 @@ template copyNodeImpl(dst, src, processSonsStmt) =
12491254
dst.info = src.info
12501255
when defined(nimsuggest):
12511256
result.endInfo = src.endInfo
1252-
dst.typ() = src.typ
1257+
dst.typ = src.typ
12531258
dst.flags = src.flags * PersistentNodeFlags
12541259
dst.comment = src.comment
12551260
when defined(useNodeIds):

compiler/ast2nif.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string;
11661166
inc n
11671167
else:
11681168
result = newSymNode(c.loadSymStub(n, thisModule, localSyms), info)
1169+
if result.typField == nil:
1170+
result.flags.incl nfLazyType
11691171
of DotToken:
11701172
result = nil
11711173
inc n

compiler/astdef.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ type
323323
nfDisabledOpenSym # temporary: node should be nkOpenSym but cannot
324324
# because openSym experimental switch is disabled
325325
# gives warning instead
326+
nfLazyType # node has a lazy type
326327

327328
TNodeFlags* = set[TNodeFlag]
328329
TTypeFlag* = enum # keep below 32 for efficiency reasons (now: 47)
@@ -866,7 +867,7 @@ const
866867
nfFromTemplate, nfDefaultRefsParam,
867868
nfExecuteOnReload, nfLastRead,
868869
nfFirstWrite, nfSkipFieldChecking,
869-
nfDisabledOpenSym}
870+
nfDisabledOpenSym, nfLazyType}
870871
namePos* = 0
871872
patternPos* = 1 # empty except for term rewriting macros
872873
genericParamsPos* = 2

compiler/ccgcalls.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Builder; n
368368
# variable. Thus, we create a temporary pointer variable instead.
369369
let needsIndirect = mapType(p.config, n[0].typ, mapTypeChooser(n[0]) == skParam) != ctArray
370370
if needsIndirect:
371-
n.typ() = n.typ.exactReplica
371+
n.typ = n.typ.exactReplica
372372
n.typ.incl tfVarIsPtr
373373
a = initLocExprSingleUse(p, n)
374374
a = withTmpIfNeeded(p, a, needsTmp)
@@ -498,7 +498,7 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
498498
else:
499499
cCall(p, params, e)
500500
cIfExpr(e,
501-
eCall,
501+
eCall,
502502
cCall(cCast(pTyp, p), params))
503503

504504
template callIter(rp, params: Snippet): Snippet =

compiler/ccgexprs.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ proc genSeqConstr(p: BProc, n: PNode, d: var TLoc) =
19161916
proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) =
19171917
var elem, arr: TLoc
19181918
if n[1].kind == nkBracket:
1919-
n[1].typ() = n.typ
1919+
n[1].typ = n.typ
19201920
genSeqConstr(p, n[1], d)
19211921
return
19221922
if d.k == locNone:

compiler/cgen.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ proc t(a: TLoc): PType {.inline.} =
9797

9898
proc lodeTyp(t: PType): PNode =
9999
result = newNode(nkEmpty)
100-
result.typ() = t
100+
result.typ = t
101101

102102
proc isSimpleConst(typ: PType): bool =
103103
let t = skipTypes(typ, abstractVar)

compiler/cgmeth.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ proc methodCall*(n: PNode; conf: ConfigRef): PNode =
5555
# replace ordinary method by dispatcher method:
5656
let disp = getDispatcher(result[0].sym)
5757
if disp != nil:
58-
result[0].typ() = disp.typ
58+
result[0].typ = disp.typ
5959
result[0].sym = disp
6060
# change the arguments to up/downcasts to fit the dispatcher's parameters:
6161
for i in 1..<result.len:

compiler/closureiters.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ proc newNotCall(g: ModuleGraph; e: PNode): PNode =
458458

459459
proc boolLit(g: ModuleGraph; info: TLineInfo; value: bool): PNode =
460460
result = newIntLit(g, info, ord value)
461-
result.typ() = getSysType(g, info, tyBool)
461+
result.typ = getSysType(g, info, tyBool)
462462

463463
proc captureVar(c: var Ctx, s: PSym) =
464464
if c.varStates.getOrDefault(s.itemId) != localRequiresLifting:
@@ -819,7 +819,7 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
819819
result = newNodeIT(nkStmtListExpr, n.info, n.typ)
820820
let (st, ex) = exprToStmtList(n[1])
821821
n.transitionSonsKind(nkBlockStmt)
822-
n.typ() = nil
822+
n.typ = nil
823823
n[1] = st
824824
result.add(n)
825825
result.add(ex)

compiler/docgen.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ proc documentEffect(cache: IdentCache; n, x: PNode, effectType: TSpecialWord, id
13201320
if t.startsWith("ref "): t = substr(t, 4)
13211321
effects[i] = newIdentNode(getIdent(cache, t), n.info)
13221322
# set the type so that the following analysis doesn't screw up:
1323-
effects[i].typ() = real[i].typ
1323+
effects[i].typ = real[i].typ
13241324

13251325
result = newTreeI(nkExprColonExpr, n.info,
13261326
newIdentNode(getIdent(cache, $effectType), n.info), effects)

compiler/evalffi.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ proc unpackObject(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
275275
# the nkPar node:
276276
if n.isNil:
277277
result = newNode(nkTupleConstr)
278-
result.typ() = typ
278+
result.typ = typ
279279
if typ.n.isNil:
280280
internalError(conf, "cannot unpack unnamed tuple")
281281
unpackObjectAdd(conf, x, typ.n, result)
@@ -298,7 +298,7 @@ proc unpackObject(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
298298
proc unpackArray(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
299299
if n.isNil:
300300
result = newNode(nkBracket)
301-
result.typ() = typ
301+
result.typ = typ
302302
newSeq(result.sons, lengthOrd(conf, typ).toInt)
303303
else:
304304
result = n
@@ -319,7 +319,7 @@ proc unpack(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
319319
template aw(k, v, field: untyped): untyped =
320320
if n.isNil:
321321
result = newNode(k)
322-
result.typ() = typ
322+
result.typ = typ
323323
else:
324324
# check we have the right field:
325325
result = n
@@ -333,12 +333,12 @@ proc unpack(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
333333
template setNil() =
334334
if n.isNil:
335335
result = newNode(nkNilLit)
336-
result.typ() = typ
336+
result.typ = typ
337337
else:
338338
reset n[]
339339
result = n
340340
result[] = TNode(kind: nkNilLit)
341-
result.typ() = typ
341+
result.typ = typ
342342

343343
template awi(kind, v: untyped): untyped = aw(kind, v, intVal)
344344
template awf(kind, v: untyped): untyped = aw(kind, v, floatVal)
@@ -427,7 +427,7 @@ proc fficast*(conf: ConfigRef, x: PNode, destTyp: PType): PNode =
427427
# cast through a pointer needs a new inner object:
428428
let y = if x.kind == nkRefTy: newNodeI(nkRefTy, x.info, 1)
429429
else: x.copyTree
430-
y.typ() = x.typ
430+
y.typ = x.typ
431431
result = unpack(conf, a, destTyp, y)
432432
dealloc a
433433

@@ -481,7 +481,7 @@ proc callForeignFunction*(conf: ConfigRef, fn: PNode, fntyp: PType,
481481
if aTyp.isNil:
482482
internalAssert conf, i+1 < fntyp.len
483483
aTyp = fntyp[i+1]
484-
args[i+start].typ() = aTyp
484+
args[i+start].typ = aTyp
485485
sig[i] = mapType(conf, aTyp)
486486
if sig[i].isNil: globalError(conf, info, "cannot map FFI type")
487487

0 commit comments

Comments
 (0)