deprecated unary '<'
This commit is contained in:
parent
c17f6c7837
commit
70ea45cdba
56 changed files with 259 additions and 258 deletions
|
|
@ -20,3 +20,5 @@
|
||||||
recursive types can be created across module boundaries. See
|
recursive types can be created across module boundaries. See
|
||||||
[package level objects](https://nim-lang.org/docs/manual.html#package-level-objects)
|
[package level objects](https://nim-lang.org/docs/manual.html#package-level-objects)
|
||||||
for more information.
|
for more information.
|
||||||
|
- The **unary** ``<`` is now deprecated, for ``.. <`` use ``..<`` for other usages
|
||||||
|
use the ``pred`` proc.
|
||||||
|
|
|
||||||
|
|
@ -1604,10 +1604,10 @@ proc hasPattern*(s: PSym): bool {.inline.} =
|
||||||
result = isRoutine(s) and s.ast.sons[patternPos].kind != nkEmpty
|
result = isRoutine(s) and s.ast.sons[patternPos].kind != nkEmpty
|
||||||
|
|
||||||
iterator items*(n: PNode): PNode =
|
iterator items*(n: PNode): PNode =
|
||||||
for i in 0.. <n.safeLen: yield n.sons[i]
|
for i in 0..<n.safeLen: yield n.sons[i]
|
||||||
|
|
||||||
iterator pairs*(n: PNode): tuple[i: int, n: PNode] =
|
iterator pairs*(n: PNode): tuple[i: int, n: PNode] =
|
||||||
for i in 0.. <n.len: yield (i, n.sons[i])
|
for i in 0..<n.len: yield (i, n.sons[i])
|
||||||
|
|
||||||
proc isAtom*(n: PNode): bool {.inline.} =
|
proc isAtom*(n: PNode): bool {.inline.} =
|
||||||
result = n.kind >= nkNone and n.kind <= nkNilLit
|
result = n.kind >= nkNone and n.kind <= nkNilLit
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ proc hashTree(c: var MD5Context, n: PNode) =
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
c &= n.strVal
|
c &= n.strVal
|
||||||
else:
|
else:
|
||||||
for i in 0.. <n.len: hashTree(c, n.sons[i])
|
for i in 0..<n.len: hashTree(c, n.sons[i])
|
||||||
|
|
||||||
proc hashType(c: var MD5Context, t: PType) =
|
proc hashType(c: var MD5Context, t: PType) =
|
||||||
# modelled after 'typeToString'
|
# modelled after 'typeToString'
|
||||||
|
|
@ -151,13 +151,13 @@ proc hashType(c: var MD5Context, t: PType) =
|
||||||
c.hashType(t.sons[0])
|
c.hashType(t.sons[0])
|
||||||
of tyProc:
|
of tyProc:
|
||||||
c &= (if tfIterator in t.flags: "iterator " else: "proc ")
|
c &= (if tfIterator in t.flags: "iterator " else: "proc ")
|
||||||
for i in 0.. <t.len: c.hashType(t.sons[i])
|
for i in 0..<t.len: c.hashType(t.sons[i])
|
||||||
md5Update(c, cast[cstring](addr(t.callConv)), 1)
|
md5Update(c, cast[cstring](addr(t.callConv)), 1)
|
||||||
|
|
||||||
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
|
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
|
||||||
if tfThread in t.flags: c &= ".thread"
|
if tfThread in t.flags: c &= ".thread"
|
||||||
else:
|
else:
|
||||||
for i in 0.. <t.len: c.hashType(t.sons[i])
|
for i in 0..<t.len: c.hashType(t.sons[i])
|
||||||
if tfNotNil in t.flags: c &= "not nil"
|
if tfNotNil in t.flags: c &= "not nil"
|
||||||
|
|
||||||
proc canonConst(n: PNode): TUid =
|
proc canonConst(n: PNode): TUid =
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
proc leftAppearsOnRightSide(le, ri: PNode): bool =
|
proc leftAppearsOnRightSide(le, ri: PNode): bool =
|
||||||
if le != nil:
|
if le != nil:
|
||||||
for i in 1 .. <ri.len:
|
for i in 1 ..< ri.len:
|
||||||
let r = ri[i]
|
let r = ri[i]
|
||||||
if isPartOf(le, r) != arNo: return true
|
if isPartOf(le, r) != arNo: return true
|
||||||
|
|
||||||
|
|
@ -364,7 +364,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
|
||||||
of '@':
|
of '@':
|
||||||
if j < ri.len:
|
if j < ri.len:
|
||||||
result.add genOtherArg(p, ri, j, typ)
|
result.add genOtherArg(p, ri, j, typ)
|
||||||
for k in j+1 .. < ri.len:
|
for k in j+1 ..< ri.len:
|
||||||
result.add(~", ")
|
result.add(~", ")
|
||||||
result.add genOtherArg(p, ri, k, typ)
|
result.add genOtherArg(p, ri, k, typ)
|
||||||
inc i
|
inc i
|
||||||
|
|
@ -377,7 +377,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
|
||||||
result.add(~"(")
|
result.add(~"(")
|
||||||
if 1 < ri.len:
|
if 1 < ri.len:
|
||||||
result.add genOtherArg(p, ri, 1, typ)
|
result.add genOtherArg(p, ri, 1, typ)
|
||||||
for k in j+1 .. < ri.len:
|
for k in j+1 ..< ri.len:
|
||||||
result.add(~", ")
|
result.add(~", ")
|
||||||
result.add genOtherArg(p, ri, k, typ)
|
result.add genOtherArg(p, ri, k, typ)
|
||||||
result.add(~")")
|
result.add(~")")
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
else:
|
else:
|
||||||
flags
|
flags
|
||||||
let t = skipTypes(dest.t, abstractInst).getUniqueType()
|
let t = skipTypes(dest.t, abstractInst).getUniqueType()
|
||||||
for i in 0 .. <t.len:
|
for i in 0 ..< t.len:
|
||||||
let t = t.sons[i]
|
let t = t.sons[i]
|
||||||
let field = "Field$1" % [i.rope]
|
let field = "Field$1" % [i.rope]
|
||||||
genAssignment(p, optAsgnLoc(dest, t, field),
|
genAssignment(p, optAsgnLoc(dest, t, field),
|
||||||
|
|
@ -1218,7 +1218,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
constructLoc(p, tmp)
|
constructLoc(p, tmp)
|
||||||
discard getTypeDesc(p.module, t)
|
discard getTypeDesc(p.module, t)
|
||||||
let ty = getUniqueType(t)
|
let ty = getUniqueType(t)
|
||||||
for i in 1 .. <e.len:
|
for i in 1 ..< e.len:
|
||||||
let it = e.sons[i]
|
let it = e.sons[i]
|
||||||
var tmp2: TLoc
|
var tmp2: TLoc
|
||||||
tmp2.r = r
|
tmp2.r = r
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ proc genSingleVar(p: BProc, a: PNode) =
|
||||||
var params: Rope
|
var params: Rope
|
||||||
let typ = skipTypes(value.sons[0].typ, abstractInst)
|
let typ = skipTypes(value.sons[0].typ, abstractInst)
|
||||||
assert(typ.kind == tyProc)
|
assert(typ.kind == tyProc)
|
||||||
for i in 1.. <value.len:
|
for i in 1..<value.len:
|
||||||
if params != nil: params.add(~", ")
|
if params != nil: params.add(~", ")
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
add(params, genOtherArg(p, value, i, typ))
|
add(params, genOtherArg(p, value, i, typ))
|
||||||
|
|
@ -386,7 +386,7 @@ proc genReturnStmt(p: BProc, t: PNode) =
|
||||||
lineF(p, cpsStmts, "goto BeforeRet_;$n", [])
|
lineF(p, cpsStmts, "goto BeforeRet_;$n", [])
|
||||||
|
|
||||||
proc genGotoForCase(p: BProc; caseStmt: PNode) =
|
proc genGotoForCase(p: BProc; caseStmt: PNode) =
|
||||||
for i in 1 .. <caseStmt.len:
|
for i in 1 ..< caseStmt.len:
|
||||||
startBlock(p)
|
startBlock(p)
|
||||||
let it = caseStmt.sons[i]
|
let it = caseStmt.sons[i]
|
||||||
for j in 0 .. it.len-2:
|
for j in 0 .. it.len-2:
|
||||||
|
|
@ -402,7 +402,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
|
||||||
# first pass: Generate array of computed labels:
|
# first pass: Generate array of computed labels:
|
||||||
var casePos = -1
|
var casePos = -1
|
||||||
var arraySize: int
|
var arraySize: int
|
||||||
for i in 0 .. <n.len:
|
for i in 0 ..< n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.kind == nkCaseStmt:
|
if it.kind == nkCaseStmt:
|
||||||
if lastSon(it).kind != nkOfBranch:
|
if lastSon(it).kind != nkOfBranch:
|
||||||
|
|
@ -432,7 +432,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
|
||||||
let oldBody = p.blocks[topBlock].sections[cpsStmts]
|
let oldBody = p.blocks[topBlock].sections[cpsStmts]
|
||||||
p.blocks[topBlock].sections[cpsStmts] = nil
|
p.blocks[topBlock].sections[cpsStmts] = nil
|
||||||
|
|
||||||
for j in casePos+1 .. <n.len: genStmts(p, n.sons[j])
|
for j in casePos+1 ..< n.len: genStmts(p, n.sons[j])
|
||||||
let tailB = p.blocks[topBlock].sections[cpsStmts]
|
let tailB = p.blocks[topBlock].sections[cpsStmts]
|
||||||
|
|
||||||
p.blocks[topBlock].sections[cpsStmts] = nil
|
p.blocks[topBlock].sections[cpsStmts] = nil
|
||||||
|
|
@ -447,7 +447,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
|
||||||
# first goto:
|
# first goto:
|
||||||
lineF(p, cpsStmts, "goto *$#[$#];$n", [tmp, a.rdLoc])
|
lineF(p, cpsStmts, "goto *$#[$#];$n", [tmp, a.rdLoc])
|
||||||
|
|
||||||
for i in 1 .. <caseStmt.len:
|
for i in 1 ..< caseStmt.len:
|
||||||
startBlock(p)
|
startBlock(p)
|
||||||
let it = caseStmt.sons[i]
|
let it = caseStmt.sons[i]
|
||||||
for j in 0 .. it.len-2:
|
for j in 0 .. it.len-2:
|
||||||
|
|
@ -457,7 +457,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
|
||||||
let val = getOrdValue(it.sons[j])
|
let val = getOrdValue(it.sons[j])
|
||||||
lineF(p, cpsStmts, "TMP$#_:$n", [intLiteral(val+id+1)])
|
lineF(p, cpsStmts, "TMP$#_:$n", [intLiteral(val+id+1)])
|
||||||
genStmts(p, it.lastSon)
|
genStmts(p, it.lastSon)
|
||||||
#for j in casePos+1 .. <n.len: genStmts(p, n.sons[j]) # tailB
|
#for j in casePos+1 ..< n.len: genStmts(p, n.sons[j]) # tailB
|
||||||
#for j in 0 .. casePos-1: genStmts(p, n.sons[j]) # tailA
|
#for j in 0 .. casePos-1: genStmts(p, n.sons[j]) # tailA
|
||||||
add(p.s(cpsStmts), tailB)
|
add(p.s(cpsStmts), tailB)
|
||||||
add(p.s(cpsStmts), tailA)
|
add(p.s(cpsStmts), tailA)
|
||||||
|
|
@ -744,7 +744,7 @@ proc genOrdinalCase(p: BProc, n: PNode, d: var TLoc) =
|
||||||
if splitPoint+1 < n.len:
|
if splitPoint+1 < n.len:
|
||||||
lineF(p, cpsStmts, "switch ($1) {$n", [rdCharLoc(a)])
|
lineF(p, cpsStmts, "switch ($1) {$n", [rdCharLoc(a)])
|
||||||
var hasDefault = false
|
var hasDefault = false
|
||||||
for i in splitPoint+1 .. < n.len:
|
for i in splitPoint+1 ..< n.len:
|
||||||
# bug #4230: avoid false sharing between branches:
|
# bug #4230: avoid false sharing between branches:
|
||||||
if d.k == locTemp and isEmptyType(n.typ): d.k = locNone
|
if d.k == locTemp and isEmptyType(n.typ): d.k = locNone
|
||||||
var branch = n[i]
|
var branch = n[i]
|
||||||
|
|
|
||||||
|
|
@ -809,7 +809,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||||
var chunkStart = 0
|
var chunkStart = 0
|
||||||
while i < cppName.data.len:
|
while i < cppName.data.len:
|
||||||
if cppName.data[i] == '\'':
|
if cppName.data[i] == '\'':
|
||||||
var chunkEnd = <i
|
var chunkEnd = i-1
|
||||||
var idx, stars: int
|
var idx, stars: int
|
||||||
if scanCppGenericSlot(cppName.data, i, idx, stars):
|
if scanCppGenericSlot(cppName.data, i, idx, stars):
|
||||||
result.add cppName.data.substr(chunkStart, chunkEnd)
|
result.add cppName.data.substr(chunkStart, chunkEnd)
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ import
|
||||||
proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
|
proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkStmtList:
|
of nkStmtList:
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
result = getPragmaStmt(n[i], w)
|
result = getPragmaStmt(n[i], w)
|
||||||
if result != nil: break
|
if result != nil: break
|
||||||
of nkPragma:
|
of nkPragma:
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
if whichPragma(n[i]) == w: return n[i]
|
if whichPragma(n[i]) == w: return n[i]
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -920,7 +920,7 @@ proc getFileHeader(cfile: Cfile): Rope =
|
||||||
proc genFilenames(m: BModule): Rope =
|
proc genFilenames(m: BModule): Rope =
|
||||||
discard cgsym(m, "dbgRegisterFilename")
|
discard cgsym(m, "dbgRegisterFilename")
|
||||||
result = nil
|
result = nil
|
||||||
for i in 0.. <fileInfos.len:
|
for i in 0..<fileInfos.len:
|
||||||
result.addf("dbgRegisterFilename($1);$N", [fileInfos[i].projPath.makeCString])
|
result.addf("dbgRegisterFilename($1);$N", [fileInfos[i].projPath.makeCString])
|
||||||
|
|
||||||
proc genMainProc(m: BModule) =
|
proc genMainProc(m: BModule) =
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ proc genCase(c: var Con; n: PNode) =
|
||||||
# Lend:
|
# Lend:
|
||||||
var endings: seq[TPosition] = @[]
|
var endings: seq[TPosition] = @[]
|
||||||
c.gen(n.sons[0])
|
c.gen(n.sons[0])
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.len == 1:
|
if it.len == 1:
|
||||||
c.gen(it.sons[0])
|
c.gen(it.sons[0])
|
||||||
|
|
@ -219,7 +219,7 @@ proc genTry(c: var Con; n: PNode) =
|
||||||
let elsePos = c.forkI(n)
|
let elsePos = c.forkI(n)
|
||||||
c.gen(n.sons[0])
|
c.gen(n.sons[0])
|
||||||
c.patch(elsePos)
|
c.patch(elsePos)
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.kind != nkFinally:
|
if it.kind != nkFinally:
|
||||||
var blen = len(it)
|
var blen = len(it)
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ proc getName(d: PDoc, n: PNode, splitAfter = -1): string =
|
||||||
of nkIdent: result = esc(d.target, n.ident.s, splitAfter)
|
of nkIdent: result = esc(d.target, n.ident.s, splitAfter)
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
result = esc(d.target, "`")
|
result = esc(d.target, "`")
|
||||||
for i in 0.. <n.len: result.add(getName(d, n[i], splitAfter))
|
for i in 0..<n.len: result.add(getName(d, n[i], splitAfter))
|
||||||
result.add esc(d.target, "`")
|
result.add esc(d.target, "`")
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
result = getName(d, n[0], splitAfter)
|
result = getName(d, n[0], splitAfter)
|
||||||
|
|
@ -268,7 +268,7 @@ proc getNameIdent(n: PNode): PIdent =
|
||||||
of nkIdent: result = n.ident
|
of nkIdent: result = n.ident
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
var r = ""
|
var r = ""
|
||||||
for i in 0.. <n.len: r.add(getNameIdent(n[i]).s)
|
for i in 0..<n.len: r.add(getNameIdent(n[i]).s)
|
||||||
result = getIdent(r)
|
result = getIdent(r)
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
result = getNameIdent(n[0])
|
result = getNameIdent(n[0])
|
||||||
|
|
@ -283,7 +283,7 @@ proc getRstName(n: PNode): PRstNode =
|
||||||
of nkIdent: result = newRstNode(rnLeaf, n.ident.s)
|
of nkIdent: result = newRstNode(rnLeaf, n.ident.s)
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
result = getRstName(n.sons[0])
|
result = getRstName(n.sons[0])
|
||||||
for i in 1 .. <n.len: result.text.add(getRstName(n[i]).text)
|
for i in 1 ..< n.len: result.text.add(getRstName(n[i]).text)
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
result = getRstName(n[0])
|
result = getRstName(n[0])
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
|
||||||
awr(pointer, res +! sizeof(pointer))
|
awr(pointer, res +! sizeof(pointer))
|
||||||
of tyArray:
|
of tyArray:
|
||||||
let baseSize = typ.sons[1].getSize
|
let baseSize = typ.sons[1].getSize
|
||||||
for i in 0 .. <v.len:
|
for i in 0 ..< v.len:
|
||||||
pack(v.sons[i], typ.sons[1], res +! i * baseSize)
|
pack(v.sons[i], typ.sons[1], res +! i * baseSize)
|
||||||
of tyObject, tyTuple:
|
of tyObject, tyTuple:
|
||||||
packObject(v, typ, res)
|
packObject(v, typ, res)
|
||||||
|
|
@ -291,7 +291,7 @@ proc unpackArray(x: pointer, typ: PType, n: PNode): PNode =
|
||||||
if result.kind != nkBracket:
|
if result.kind != nkBracket:
|
||||||
globalError(n.info, "cannot map value from FFI")
|
globalError(n.info, "cannot map value from FFI")
|
||||||
let baseSize = typ.sons[1].getSize
|
let baseSize = typ.sons[1].getSize
|
||||||
for i in 0 .. < result.len:
|
for i in 0 ..< result.len:
|
||||||
result.sons[i] = unpack(x +! i * baseSize, typ.sons[1], result.sons[i])
|
result.sons[i] = unpack(x +! i * baseSize, typ.sons[1], result.sons[i])
|
||||||
|
|
||||||
proc canonNodeKind(k: TNodeKind): TNodeKind =
|
proc canonNodeKind(k: TNodeKind): TNodeKind =
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
|
||||||
# now that we have working untyped parameters.
|
# now that we have working untyped parameters.
|
||||||
genericParams = if sfImmediate in s.flags or fromHlo: 0
|
genericParams = if sfImmediate in s.flags or fromHlo: 0
|
||||||
else: s.ast[genericParamsPos].len
|
else: s.ast[genericParamsPos].len
|
||||||
expectedRegularParams = <s.typ.len
|
expectedRegularParams = s.typ.len-1
|
||||||
givenRegularParams = totalParams - genericParams
|
givenRegularParams = totalParams - genericParams
|
||||||
if givenRegularParams < 0: givenRegularParams = 0
|
if givenRegularParams < 0: givenRegularParams = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,13 @@ proc counterInTree(n, loop: PNode; counter: PSym): bool =
|
||||||
for it in n:
|
for it in n:
|
||||||
if counterInTree(it.lastSon): return true
|
if counterInTree(it.lastSon): return true
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <safeLen(n):
|
for i in 0 ..< safeLen(n):
|
||||||
if counterInTree(n[i], loop, counter): return true
|
if counterInTree(n[i], loop, counter): return true
|
||||||
|
|
||||||
proc copyExcept(n: PNode, x, dest: PNode) =
|
proc copyExcept(n: PNode, x, dest: PNode) =
|
||||||
if x == n: return
|
if x == n: return
|
||||||
if n.kind in {nkStmtList, nkStmtListExpr}:
|
if n.kind in {nkStmtList, nkStmtListExpr}:
|
||||||
for i in 0 .. <n.len: copyExcept(n[i], x, dest)
|
for i in 0 ..< n.len: copyExcept(n[i], x, dest)
|
||||||
else:
|
else:
|
||||||
dest.add n
|
dest.add n
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ proc canon*(n: PNode): PNode =
|
||||||
# XXX for now only the new code in 'semparallel' uses this
|
# XXX for now only the new code in 'semparallel' uses this
|
||||||
if n.safeLen >= 1:
|
if n.safeLen >= 1:
|
||||||
result = shallowCopy(n)
|
result = shallowCopy(n)
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
result.sons[i] = canon(n.sons[i])
|
result.sons[i] = canon(n.sons[i])
|
||||||
elif n.kind == nkSym and n.sym.kind == skLet and
|
elif n.kind == nkSym and n.sym.kind == skLet and
|
||||||
n.sym.ast.getMagic in (someEq + someAdd + someMul + someMin +
|
n.sym.ast.getMagic in (someEq + someAdd + someMul + someMin +
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
|
||||||
# we apply the last pattern first, so that pattern overriding is possible;
|
# we apply the last pattern first, so that pattern overriding is possible;
|
||||||
# however the resulting AST would better not trigger the old rule then
|
# however the resulting AST would better not trigger the old rule then
|
||||||
# anymore ;-)
|
# anymore ;-)
|
||||||
for i in countdown(<c.patterns.len, 0):
|
for i in countdown(c.patterns.len-1, 0):
|
||||||
let pattern = c.patterns[i]
|
let pattern = c.patterns[i]
|
||||||
if not isNil(pattern):
|
if not isNil(pattern):
|
||||||
let x = applyRule(c, pattern, result)
|
let x = applyRule(c, pattern, result)
|
||||||
|
|
@ -75,7 +75,7 @@ proc hlo(c: PContext, n: PNode): PNode =
|
||||||
result = applyPatterns(c, n)
|
result = applyPatterns(c, n)
|
||||||
if result == n:
|
if result == n:
|
||||||
# no optimization applied, try subtrees:
|
# no optimization applied, try subtrees:
|
||||||
for i in 0 .. < safeLen(result):
|
for i in 0 ..< safeLen(result):
|
||||||
let a = result.sons[i]
|
let a = result.sons[i]
|
||||||
let h = hlo(c, a)
|
let h = hlo(c, a)
|
||||||
if h != a: result.sons[i] = h
|
if h != a: result.sons[i] = h
|
||||||
|
|
|
||||||
|
|
@ -1363,7 +1363,7 @@ proc genPatternCall(p: PProc; n: PNode; pat: string; typ: PType;
|
||||||
case pat[i]
|
case pat[i]
|
||||||
of '@':
|
of '@':
|
||||||
var generated = 0
|
var generated = 0
|
||||||
for k in j .. < n.len:
|
for k in j ..< n.len:
|
||||||
if generated > 0: add(r.res, ", ")
|
if generated > 0: add(r.res, ", ")
|
||||||
genOtherArg(p, n, k, typ, generated, r)
|
genOtherArg(p, n, k, typ, generated, r)
|
||||||
inc i
|
inc i
|
||||||
|
|
@ -1528,7 +1528,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
if p.target == targetJS:
|
if p.target == targetJS:
|
||||||
result = rope("{")
|
result = rope("{")
|
||||||
for i in 0.. <t.sonsLen:
|
for i in 0..<t.sonsLen:
|
||||||
if i > 0: add(result, ", ")
|
if i > 0: add(result, ", ")
|
||||||
addf(result, "Field$1: $2", [i.rope,
|
addf(result, "Field$1: $2", [i.rope,
|
||||||
createVar(p, t.sons[i], false)])
|
createVar(p, t.sons[i], false)])
|
||||||
|
|
@ -1536,7 +1536,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||||
if indirect: result = "[$1]" % [result]
|
if indirect: result = "[$1]" % [result]
|
||||||
else:
|
else:
|
||||||
result = rope("array(")
|
result = rope("array(")
|
||||||
for i in 0.. <t.sonsLen:
|
for i in 0..<t.sonsLen:
|
||||||
if i > 0: add(result, ", ")
|
if i > 0: add(result, ", ")
|
||||||
add(result, createVar(p, t.sons[i], false))
|
add(result, createVar(p, t.sons[i], false))
|
||||||
add(result, ")")
|
add(result, ")")
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ proc genObjectInfo(p: PProc, typ: PType, name: Rope) =
|
||||||
|
|
||||||
proc genTupleFields(p: PProc, typ: PType): Rope =
|
proc genTupleFields(p: PProc, typ: PType): Rope =
|
||||||
var s: Rope = nil
|
var s: Rope = nil
|
||||||
for i in 0 .. <typ.len:
|
for i in 0 ..< typ.len:
|
||||||
if i > 0: add(s, ", " & tnl)
|
if i > 0: add(s, ", " & tnl)
|
||||||
s.addf("{kind: 1, offset: \"Field$1\", len: 0, " &
|
s.addf("{kind: 1, offset: \"Field$1\", len: 0, " &
|
||||||
"typ: $2, name: \"Field$1\", sons: null}",
|
"typ: $2, name: \"Field$1\", sons: null}",
|
||||||
|
|
|
||||||
|
|
@ -693,7 +693,7 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) =
|
||||||
proc newString(s: cstring, len: int): string =
|
proc newString(s: cstring, len: int): string =
|
||||||
## XXX, how come there is no support for this?
|
## XXX, how come there is no support for this?
|
||||||
result = newString(len)
|
result = newString(len)
|
||||||
for i in 0 .. <len:
|
for i in 0 ..< len:
|
||||||
result[i] = s[i]
|
result[i] = s[i]
|
||||||
|
|
||||||
proc handleCRLF(L: var TLexer, pos: int): int =
|
proc handleCRLF(L: var TLexer, pos: int): int =
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ proc considerQuotedIdent*(n: PNode, origin: PNode = nil): PIdent =
|
||||||
of 1: result = considerQuotedIdent(n.sons[0], origin)
|
of 1: result = considerQuotedIdent(n.sons[0], origin)
|
||||||
else:
|
else:
|
||||||
var id = ""
|
var id = ""
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
let x = n.sons[i]
|
let x = n.sons[i]
|
||||||
case x.kind
|
case x.kind
|
||||||
of nkIdent: id.add(x.ident.s)
|
of nkIdent: id.add(x.ident.s)
|
||||||
|
|
|
||||||
|
|
@ -463,7 +463,7 @@ proc setupArgsForConcurrency(n: PNode; objType: PType; scratchObj: PSym,
|
||||||
varSection, varInit, result: PNode) =
|
varSection, varInit, result: PNode) =
|
||||||
let formals = n[0].typ.n
|
let formals = n[0].typ.n
|
||||||
let tmpName = getIdent(genPrefix)
|
let tmpName = getIdent(genPrefix)
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
# we pick n's type here, which hopefully is 'tyArray' and not
|
# we pick n's type here, which hopefully is 'tyArray' and not
|
||||||
# 'tyOpenArray':
|
# 'tyOpenArray':
|
||||||
var argType = n[i].typ.skipTypes(abstractInst)
|
var argType = n[i].typ.skipTypes(abstractInst)
|
||||||
|
|
@ -519,7 +519,7 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
|
||||||
let tmpName = getIdent(genPrefix)
|
let tmpName = getIdent(genPrefix)
|
||||||
# we need to copy the foreign scratch object fields into local variables
|
# we need to copy the foreign scratch object fields into local variables
|
||||||
# for correctness: These are called 'threadLocal' here.
|
# for correctness: These are called 'threadLocal' here.
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
let n = n[i]
|
let n = n[i]
|
||||||
let argType = skipTypes(if i < formals.len: formals[i].typ else: n.typ,
|
let argType = skipTypes(if i < formals.len: formals[i].typ else: n.typ,
|
||||||
abstractInst)
|
abstractInst)
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ proc semNodeKindConstraints*(p: PNode): PNode =
|
||||||
result.strVal = newStringOfCap(10)
|
result.strVal = newStringOfCap(10)
|
||||||
result.strVal.add(chr(aqNone.ord))
|
result.strVal.add(chr(aqNone.ord))
|
||||||
if p.len >= 2:
|
if p.len >= 2:
|
||||||
for i in 1.. <p.len:
|
for i in 1..<p.len:
|
||||||
compileConstraints(p.sons[i], result.strVal)
|
compileConstraints(p.sons[i], result.strVal)
|
||||||
if result.strVal.len > MaxStackSize-1:
|
if result.strVal.len > MaxStackSize-1:
|
||||||
internalError(p.info, "parameter pattern too complex")
|
internalError(p.info, "parameter pattern too complex")
|
||||||
|
|
@ -152,7 +152,7 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
|
||||||
# indirect call: assume side effect:
|
# indirect call: assume side effect:
|
||||||
return seSideEffect
|
return seSideEffect
|
||||||
# we need to check n[0] too: (FwithSideEffectButReturnsProcWithout)(args)
|
# we need to check n[0] too: (FwithSideEffectButReturnsProcWithout)(args)
|
||||||
for i in 0 .. <n.len:
|
for i in 0 ..< n.len:
|
||||||
let ret = checkForSideEffects(n.sons[i])
|
let ret = checkForSideEffects(n.sons[i])
|
||||||
if ret == seSideEffect: return ret
|
if ret == seSideEffect: return ret
|
||||||
elif ret == seUnknown and result == seNoSideEffect:
|
elif ret == seUnknown and result == seNoSideEffect:
|
||||||
|
|
@ -163,7 +163,7 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
|
||||||
else:
|
else:
|
||||||
# assume no side effect:
|
# assume no side effect:
|
||||||
result = seNoSideEffect
|
result = seNoSideEffect
|
||||||
for i in 0 .. <n.len:
|
for i in 0 ..< n.len:
|
||||||
let ret = checkForSideEffects(n.sons[i])
|
let ret = checkForSideEffects(n.sons[i])
|
||||||
if ret == seSideEffect: return ret
|
if ret == seSideEffect: return ret
|
||||||
elif ret == seUnknown and result == seNoSideEffect:
|
elif ret == seUnknown and result == seNoSideEffect:
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ proc sameTrees(a, b: PNode): bool =
|
||||||
|
|
||||||
proc inSymChoice(sc, x: PNode): bool =
|
proc inSymChoice(sc, x: PNode): bool =
|
||||||
if sc.kind == nkClosedSymChoice:
|
if sc.kind == nkClosedSymChoice:
|
||||||
for i in 0.. <sc.len:
|
for i in 0..<sc.len:
|
||||||
if sc.sons[i].sym == x.sym: return true
|
if sc.sons[i].sym == x.sym: return true
|
||||||
elif sc.kind == nkOpenSymChoice:
|
elif sc.kind == nkOpenSymChoice:
|
||||||
# same name suffices for open sym choices!
|
# same name suffices for open sym choices!
|
||||||
|
|
@ -83,7 +83,7 @@ proc isPatternParam(c: PPatternContext, p: PNode): bool {.inline.} =
|
||||||
result = p.kind == nkSym and p.sym.kind == skParam and p.sym.owner == c.owner
|
result = p.kind == nkSym and p.sym.kind == skParam and p.sym.owner == c.owner
|
||||||
|
|
||||||
proc matchChoice(c: PPatternContext, p, n: PNode): bool =
|
proc matchChoice(c: PPatternContext, p, n: PNode): bool =
|
||||||
for i in 1 .. <p.len:
|
for i in 1 ..< p.len:
|
||||||
if matches(c, p.sons[i], n): return true
|
if matches(c, p.sons[i], n): return true
|
||||||
|
|
||||||
proc bindOrCheck(c: PPatternContext, param: PSym, n: PNode): bool =
|
proc bindOrCheck(c: PPatternContext, param: PSym, n: PNode): bool =
|
||||||
|
|
@ -115,7 +115,7 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
|
||||||
if rpn: arglist.add(n.sons[0])
|
if rpn: arglist.add(n.sons[0])
|
||||||
elif n.kind == nkHiddenStdConv and n.sons[1].kind == nkBracket:
|
elif n.kind == nkHiddenStdConv and n.sons[1].kind == nkBracket:
|
||||||
let n = n.sons[1]
|
let n = n.sons[1]
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
if not matchStarAux(c, op, n[i], arglist, rpn): return false
|
if not matchStarAux(c, op, n[i], arglist, rpn): return false
|
||||||
elif checkTypes(c, p.sons[2].sym, n):
|
elif checkTypes(c, p.sons[2].sym, n):
|
||||||
add(arglist, n)
|
add(arglist, n)
|
||||||
|
|
@ -186,7 +186,7 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
|
||||||
# unpack varargs:
|
# unpack varargs:
|
||||||
let n = lastSon(n).sons[1]
|
let n = lastSon(n).sons[1]
|
||||||
arglist = newNodeI(nkArgList, n.info, n.len)
|
arglist = newNodeI(nkArgList, n.info, n.len)
|
||||||
for i in 0.. <n.len: arglist.sons[i] = n.sons[i]
|
for i in 0..<n.len: arglist.sons[i] = n.sons[i]
|
||||||
else:
|
else:
|
||||||
arglist = newNodeI(nkArgList, n.info, sonsLen(n) - plen + 1)
|
arglist = newNodeI(nkArgList, n.info, sonsLen(n) - plen + 1)
|
||||||
# f(1, 2, 3)
|
# f(1, 2, 3)
|
||||||
|
|
@ -206,7 +206,7 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
|
||||||
|
|
||||||
proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
|
proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
|
||||||
proc matchRange(c: PPatternContext, p, n: PNode, i: int): bool =
|
proc matchRange(c: PPatternContext, p, n: PNode, i: int): bool =
|
||||||
for j in 0 .. <p.len:
|
for j in 0 ..< p.len:
|
||||||
if not matches(c, p.sons[j], n.sons[i+j]):
|
if not matches(c, p.sons[j], n.sons[i+j]):
|
||||||
# we need to undo any bindings:
|
# we need to undo any bindings:
|
||||||
if not isNil(c.mapping): c.mapping = nil
|
if not isNil(c.mapping): c.mapping = nil
|
||||||
|
|
@ -229,7 +229,7 @@ proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
|
||||||
|
|
||||||
proc aliasAnalysisRequested(params: PNode): bool =
|
proc aliasAnalysisRequested(params: PNode): bool =
|
||||||
if params.len >= 2:
|
if params.len >= 2:
|
||||||
for i in 1 .. < params.len:
|
for i in 1 ..< params.len:
|
||||||
let param = params.sons[i].sym
|
let param = params.sons[i].sym
|
||||||
if whichAlias(param) != aqNone: return true
|
if whichAlias(param) != aqNone: return true
|
||||||
|
|
||||||
|
|
@ -237,7 +237,7 @@ proc addToArgList(result, n: PNode) =
|
||||||
if n.typ != nil and n.typ.kind != tyStmt:
|
if n.typ != nil and n.typ.kind != tyStmt:
|
||||||
if n.kind != nkArgList: result.add(n)
|
if n.kind != nkArgList: result.add(n)
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <n.len: result.add(n.sons[i])
|
for i in 0 ..< n.len: result.add(n.sons[i])
|
||||||
|
|
||||||
proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
|
proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
|
||||||
## returns a tree to semcheck if the rule triggered; nil otherwise
|
## returns a tree to semcheck if the rule triggered; nil otherwise
|
||||||
|
|
@ -256,7 +256,7 @@ proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
|
||||||
var args: PNode
|
var args: PNode
|
||||||
if requiresAA:
|
if requiresAA:
|
||||||
args = newNodeI(nkArgList, n.info)
|
args = newNodeI(nkArgList, n.info)
|
||||||
for i in 1 .. < params.len:
|
for i in 1 ..< params.len:
|
||||||
let param = params.sons[i].sym
|
let param = params.sons[i].sym
|
||||||
let x = getLazy(ctx, param)
|
let x = getLazy(ctx, param)
|
||||||
# couldn't bind parameter:
|
# couldn't bind parameter:
|
||||||
|
|
@ -265,7 +265,7 @@ proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
|
||||||
if requiresAA: addToArgList(args, x)
|
if requiresAA: addToArgList(args, x)
|
||||||
# perform alias analysis here:
|
# perform alias analysis here:
|
||||||
if requiresAA:
|
if requiresAA:
|
||||||
for i in 1 .. < params.len:
|
for i in 1 ..< params.len:
|
||||||
var rs = result.sons[i]
|
var rs = result.sons[i]
|
||||||
let param = params.sons[i].sym
|
let param = params.sons[i].sym
|
||||||
case whichAlias(param)
|
case whichAlias(param)
|
||||||
|
|
|
||||||
|
|
@ -575,7 +575,7 @@ proc pragmaLockStmt(c: PContext; it: PNode) =
|
||||||
if n.kind != nkBracket:
|
if n.kind != nkBracket:
|
||||||
localError(n.info, errGenerated, "locks pragma takes a list of expressions")
|
localError(n.info, errGenerated, "locks pragma takes a list of expressions")
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <n.len:
|
for i in 0 ..< n.len:
|
||||||
n.sons[i] = c.semExpr(c, n.sons[i])
|
n.sons[i] = c.semExpr(c, n.sons[i])
|
||||||
|
|
||||||
proc pragmaLocks(c: PContext, it: PNode): TLockLevel =
|
proc pragmaLocks(c: PContext, it: PNode): TLockLevel =
|
||||||
|
|
|
||||||
|
|
@ -1076,7 +1076,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
put(g, tkAccent, "`")
|
put(g, tkAccent, "`")
|
||||||
if n.len > 0: gsub(g, n.sons[0])
|
if n.len > 0: gsub(g, n.sons[0])
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
put(g, tkSpaces, Space)
|
put(g, tkSpaces, Space)
|
||||||
gsub(g, n.sons[i])
|
gsub(g, n.sons[i])
|
||||||
put(g, tkAccent, "`")
|
put(g, tkAccent, "`")
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ proc newDepN(id: int, pnode: PNode): DepN =
|
||||||
|
|
||||||
proc accQuoted(n: PNode): PIdent =
|
proc accQuoted(n: PNode): PIdent =
|
||||||
var id = ""
|
var id = ""
|
||||||
for i in 0 .. <n.len:
|
for i in 0 ..< n.len:
|
||||||
let x = n[i]
|
let x = n[i]
|
||||||
case x.kind
|
case x.kind
|
||||||
of nkIdent: id.add(x.ident.s)
|
of nkIdent: id.add(x.ident.s)
|
||||||
|
|
|
||||||
|
|
@ -795,7 +795,7 @@ proc getReader(moduleId: int): PRodReader =
|
||||||
# the module ID! We could introduce a mapping ID->PRodReader but I'll leave
|
# the module ID! We could introduce a mapping ID->PRodReader but I'll leave
|
||||||
# this for later versions if benchmarking shows the linear search causes
|
# this for later versions if benchmarking shows the linear search causes
|
||||||
# problems:
|
# problems:
|
||||||
for i in 0 .. <gMods.len:
|
for i in 0 ..< gMods.len:
|
||||||
result = gMods[i].rd
|
result = gMods[i].rd
|
||||||
if result != nil and result.moduleID == moduleId: return result
|
if result != nil and result.moduleID == moduleId: return result
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ proc commonType*(x, y: PType): PType =
|
||||||
if a.sons[idx].kind == tyEmpty: return y
|
if a.sons[idx].kind == tyEmpty: return y
|
||||||
elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len:
|
elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len:
|
||||||
var nt: PType
|
var nt: PType
|
||||||
for i in 0.. <a.len:
|
for i in 0..<a.len:
|
||||||
let aEmpty = isEmptyContainer(a.sons[i])
|
let aEmpty = isEmptyContainer(a.sons[i])
|
||||||
let bEmpty = isEmptyContainer(b.sons[i])
|
let bEmpty = isEmptyContainer(b.sons[i])
|
||||||
if aEmpty != bEmpty:
|
if aEmpty != bEmpty:
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ proc at(a, i: PNode, elemType: PType): PNode =
|
||||||
result.typ = elemType
|
result.typ = elemType
|
||||||
|
|
||||||
proc liftBodyTup(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
proc liftBodyTup(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
for i in 0 .. <t.len:
|
for i in 0 ..< t.len:
|
||||||
let lit = lowerings.newIntLit(i)
|
let lit = lowerings.newIntLit(i)
|
||||||
liftBodyAux(c, t.sons[i], body, x.at(lit, t.sons[i]), y.at(lit, t.sons[i]))
|
liftBodyAux(c, t.sons[i], body, x.at(lit, t.sons[i]), y.at(lit, t.sons[i]))
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ proc liftBodyObj(c: var TLiftCtx; n, body, x, y: PNode) =
|
||||||
var access = dotField(x, n[0].sym)
|
var access = dotField(x, n[0].sym)
|
||||||
caseStmt.add(access)
|
caseStmt.add(access)
|
||||||
# copy the branches over, but replace the fields with the for loop body:
|
# copy the branches over, but replace the fields with the for loop body:
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
var branch = copyTree(n[i])
|
var branch = copyTree(n[i])
|
||||||
let L = branch.len
|
let L = branch.len
|
||||||
branch.sons[L-1] = newNodeI(nkStmtList, c.info)
|
branch.sons[L-1] = newNodeI(nkStmtList, c.info)
|
||||||
|
|
@ -297,7 +297,7 @@ proc liftBody(c: PContext; typ: PType; kind: TTypeAttachedOp;
|
||||||
of attachedDestructor: typ.destructor = result
|
of attachedDestructor: typ.destructor = result
|
||||||
|
|
||||||
var n = newNodeI(nkProcDef, info, bodyPos+1)
|
var n = newNodeI(nkProcDef, info, bodyPos+1)
|
||||||
for i in 0 .. < n.len: n.sons[i] = emptyNode
|
for i in 0 ..< n.len: n.sons[i] = emptyNode
|
||||||
n.sons[namePos] = newSymNode(result)
|
n.sons[namePos] = newSymNode(result)
|
||||||
n.sons[paramsPos] = result.typ.n
|
n.sons[paramsPos] = result.typ.n
|
||||||
n.sons[bodyPos] = body
|
n.sons[bodyPos] = body
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) =
|
||||||
proc instGenericConvertersSons*(c: PContext, n: PNode, x: TCandidate) =
|
proc instGenericConvertersSons*(c: PContext, n: PNode, x: TCandidate) =
|
||||||
assert n.kind in nkCallKinds
|
assert n.kind in nkCallKinds
|
||||||
if x.genericConverter:
|
if x.genericConverter:
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
instGenericConvertersArg(c, n.sons[i], x)
|
instGenericConvertersArg(c, n.sons[i], x)
|
||||||
|
|
||||||
proc indexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode =
|
proc indexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode =
|
||||||
|
|
@ -494,7 +494,7 @@ proc searchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym =
|
||||||
var call = newNodeI(nkCall, fn.info)
|
var call = newNodeI(nkCall, fn.info)
|
||||||
var hasDistinct = false
|
var hasDistinct = false
|
||||||
call.add(newIdentNode(fn.name, fn.info))
|
call.add(newIdentNode(fn.name, fn.info))
|
||||||
for i in 1.. <fn.typ.n.len:
|
for i in 1..<fn.typ.n.len:
|
||||||
let param = fn.typ.n.sons[i]
|
let param = fn.typ.n.sons[i]
|
||||||
let t = skipTypes(param.typ, abstractVar-{tyTypeDesc, tyDistinct})
|
let t = skipTypes(param.typ, abstractVar-{tyTypeDesc, tyDistinct})
|
||||||
if t.kind == tyDistinct or param.typ.kind == tyDistinct: hasDistinct = true
|
if t.kind == tyDistinct or param.typ.kind == tyDistinct: hasDistinct = true
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ proc instantiateDestructor(c: PContext, typ: PType): PType
|
||||||
proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
|
proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
|
||||||
var t = s.typ.sons[1].skipTypes({tyVar})
|
var t = s.typ.sons[1].skipTypes({tyVar})
|
||||||
if t.kind == tyGenericInvocation:
|
if t.kind == tyGenericInvocation:
|
||||||
for i in 1 .. <t.sonsLen:
|
for i in 1 ..< t.sonsLen:
|
||||||
if t.sons[i].kind != tyGenericParam:
|
if t.sons[i].kind != tyGenericParam:
|
||||||
localError(n.info, errDestructorNotGenericEnough)
|
localError(n.info, errDestructorNotGenericEnough)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -436,12 +436,12 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
#addSon(result, fitNode(c, typ, n.sons[i]))
|
#addSon(result, fitNode(c, typ, n.sons[i]))
|
||||||
inc(lastIndex)
|
inc(lastIndex)
|
||||||
addSonSkipIntLit(result.typ, typ)
|
addSonSkipIntLit(result.typ, typ)
|
||||||
for i in 0 .. <result.len:
|
for i in 0 ..< result.len:
|
||||||
result.sons[i] = fitNode(c, typ, result.sons[i], result.sons[i].info)
|
result.sons[i] = fitNode(c, typ, result.sons[i], result.sons[i].info)
|
||||||
result.typ.sons[0] = makeRangeType(c, 0, sonsLen(result) - 1, n.info)
|
result.typ.sons[0] = makeRangeType(c, 0, sonsLen(result) - 1, n.info)
|
||||||
|
|
||||||
proc fixAbstractType(c: PContext, n: PNode) =
|
proc fixAbstractType(c: PContext, n: PNode) =
|
||||||
for i in 1 .. < n.len:
|
for i in 1 ..< n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
# do not get rid of nkHiddenSubConv for OpenArrays, the codegen needs it:
|
# do not get rid of nkHiddenSubConv for OpenArrays, the codegen needs it:
|
||||||
if it.kind == nkHiddenSubConv and
|
if it.kind == nkHiddenSubConv and
|
||||||
|
|
@ -539,7 +539,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
|
||||||
var call = newNodeIT(nkCall, n.info, n.typ)
|
var call = newNodeIT(nkCall, n.info, n.typ)
|
||||||
call.add(n.sons[0])
|
call.add(n.sons[0])
|
||||||
var allConst = true
|
var allConst = true
|
||||||
for i in 1 .. < n.len:
|
for i in 1 ..< n.len:
|
||||||
var a = getConstExpr(c.module, n.sons[i])
|
var a = getConstExpr(c.module, n.sons[i])
|
||||||
if a == nil:
|
if a == nil:
|
||||||
allConst = false
|
allConst = false
|
||||||
|
|
@ -558,7 +558,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
|
||||||
# done until we have a more robust infrastructure for
|
# done until we have a more robust infrastructure for
|
||||||
# implicit statics.
|
# implicit statics.
|
||||||
if n.len > 1:
|
if n.len > 1:
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
# see bug #2113, it's possible that n[i].typ for errornous code:
|
# see bug #2113, it's possible that n[i].typ for errornous code:
|
||||||
if n[i].typ.isNil or n[i].typ.kind != tyStatic or
|
if n[i].typ.isNil or n[i].typ.kind != tyStatic or
|
||||||
tfUnresolved notin n[i].typ.flags:
|
tfUnresolved notin n[i].typ.flags:
|
||||||
|
|
@ -580,7 +580,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
var call = newNodeIT(nkCall, n.info, n.typ)
|
var call = newNodeIT(nkCall, n.info, n.typ)
|
||||||
call.add(n.sons[0])
|
call.add(n.sons[0])
|
||||||
for i in 1 .. < n.len:
|
for i in 1 ..< n.len:
|
||||||
let a = getConstExpr(c.module, n.sons[i])
|
let a = getConstExpr(c.module, n.sons[i])
|
||||||
if a == nil: return n
|
if a == nil: return n
|
||||||
call.add(a)
|
call.add(a)
|
||||||
|
|
@ -654,7 +654,7 @@ proc bracketedMacro(n: PNode): PSym =
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
proc setGenericParams(c: PContext, n: PNode) =
|
proc setGenericParams(c: PContext, n: PNode) =
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
n[i].typ = semTypeNode(c, n[i], nil)
|
n[i].typ = semTypeNode(c, n[i], nil)
|
||||||
|
|
||||||
proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
|
proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
|
||||||
|
|
@ -1464,7 +1464,7 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
|
||||||
|
|
||||||
n.sons[0] = takeImplicitAddr(c, n.sons[0])
|
n.sons[0] = takeImplicitAddr(c, n.sons[0])
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
for i in 0.. <t.sonsLen:
|
for i in 0..<t.sonsLen:
|
||||||
var e = skipTypes(t.sons[i], {tyGenericInst, tyAlias})
|
var e = skipTypes(t.sons[i], {tyGenericInst, tyAlias})
|
||||||
if e.kind == tyVar:
|
if e.kind == tyVar:
|
||||||
if n.sons[0].kind == nkPar:
|
if n.sons[0].kind == nkPar:
|
||||||
|
|
@ -1657,7 +1657,7 @@ proc processQuotations(n: var PNode, op: string,
|
||||||
elif n.kind == nkAccQuoted and op == "``":
|
elif n.kind == nkAccQuoted and op == "``":
|
||||||
returnQuote n[0]
|
returnQuote n[0]
|
||||||
|
|
||||||
for i in 0 .. <n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
processQuotations(n.sons[i], op, quotes, ids)
|
processQuotations(n.sons[i], op, quotes, ids)
|
||||||
|
|
||||||
proc semQuoteAst(c: PContext, n: PNode): PNode =
|
proc semQuoteAst(c: PContext, n: PNode): PNode =
|
||||||
|
|
@ -1825,7 +1825,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
dec c.inParallelStmt
|
dec c.inParallelStmt
|
||||||
of mSpawn:
|
of mSpawn:
|
||||||
result = setMs(n, s)
|
result = setMs(n, s)
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
result.sons[i] = semExpr(c, n.sons[i])
|
result.sons[i] = semExpr(c, n.sons[i])
|
||||||
let typ = result[^1].typ
|
let typ = result[^1].typ
|
||||||
if not typ.isEmptyType:
|
if not typ.isEmptyType:
|
||||||
|
|
@ -2076,7 +2076,7 @@ proc semBlock(c: PContext, n: PNode): PNode =
|
||||||
proc semExport(c: PContext, n: PNode): PNode =
|
proc semExport(c: PContext, n: PNode): PNode =
|
||||||
var x = newNodeI(n.kind, n.info)
|
var x = newNodeI(n.kind, n.info)
|
||||||
#let L = if n.kind == nkExportExceptStmt: L = 1 else: n.len
|
#let L = if n.kind == nkExportExceptStmt: L = 1 else: n.len
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
let a = n.sons[i]
|
let a = n.sons[i]
|
||||||
var o: TOverloadIter
|
var o: TOverloadIter
|
||||||
var s = initOverloadIter(o, c, a)
|
var s = initOverloadIter(o, c, a)
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ proc semForObjectFields(c: TFieldsCtx, typ, forLoop, father: PNode) =
|
||||||
access.sons[1] = newSymNode(typ.sons[0].sym, forLoop.info)
|
access.sons[1] = newSymNode(typ.sons[0].sym, forLoop.info)
|
||||||
caseStmt.add(semExprWithType(c.c, access))
|
caseStmt.add(semExprWithType(c.c, access))
|
||||||
# copy the branches over, but replace the fields with the for loop body:
|
# copy the branches over, but replace the fields with the for loop body:
|
||||||
for i in 1 .. <typ.len:
|
for i in 1 ..< typ.len:
|
||||||
var branch = copyTree(typ[i])
|
var branch = copyTree(typ[i])
|
||||||
let L = branch.len
|
let L = branch.len
|
||||||
branch.sons[L-1] = newNodeI(nkStmtList, forLoop.info)
|
branch.sons[L-1] = newNodeI(nkStmtList, forLoop.info)
|
||||||
|
|
|
||||||
|
|
@ -121,14 +121,14 @@ proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
|
||||||
idTablePut(symMap, s, x)
|
idTablePut(symMap, s, x)
|
||||||
n.sym = x
|
n.sym = x
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <safeLen(n): freshGenSyms(n.sons[i], owner, orig, symMap)
|
for i in 0 ..< safeLen(n): freshGenSyms(n.sons[i], owner, orig, symMap)
|
||||||
|
|
||||||
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind)
|
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind)
|
||||||
|
|
||||||
proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) =
|
proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) =
|
||||||
if n.sons[bodyPos].kind != nkEmpty:
|
if n.sons[bodyPos].kind != nkEmpty:
|
||||||
let procParams = result.typ.n
|
let procParams = result.typ.n
|
||||||
for i in 1 .. <procParams.len:
|
for i in 1 ..< procParams.len:
|
||||||
addDecl(c, procParams[i].sym)
|
addDecl(c, procParams[i].sym)
|
||||||
maybeAddResult(c, result, result.ast)
|
maybeAddResult(c, result, result.ast)
|
||||||
|
|
||||||
|
|
@ -138,7 +138,7 @@ proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) =
|
||||||
var symMap: TIdTable
|
var symMap: TIdTable
|
||||||
initIdTable symMap
|
initIdTable symMap
|
||||||
if params != nil:
|
if params != nil:
|
||||||
for i in 1 .. <params.len:
|
for i in 1 ..< params.len:
|
||||||
let param = params[i].sym
|
let param = params[i].sym
|
||||||
if sfGenSym in param.flags:
|
if sfGenSym in param.flags:
|
||||||
idTablePut(symMap, params[i].sym, result.typ.n[param.position+1].sym)
|
idTablePut(symMap, params[i].sym, result.typ.n[param.position+1].sym)
|
||||||
|
|
@ -211,7 +211,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
let originalParams = result.n
|
let originalParams = result.n
|
||||||
result.n = originalParams.shallowCopy
|
result.n = originalParams.shallowCopy
|
||||||
|
|
||||||
for i in 1 .. <result.len:
|
for i in 1 ..< result.len:
|
||||||
# twrong_field_caching requires these 'resetIdTable' calls:
|
# twrong_field_caching requires these 'resetIdTable' calls:
|
||||||
if i > 1:
|
if i > 1:
|
||||||
resetIdTable(cl.symMap)
|
resetIdTable(cl.symMap)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ proc annotateType*(n: PNode, t: PType) =
|
||||||
of nkObjConstr:
|
of nkObjConstr:
|
||||||
let x = t.skipTypes(abstractPtrs)
|
let x = t.skipTypes(abstractPtrs)
|
||||||
n.typ = t
|
n.typ = t
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
var j = i-1
|
var j = i-1
|
||||||
let field = x.n.ithField(j)
|
let field = x.n.ithField(j)
|
||||||
if field.isNil:
|
if field.isNil:
|
||||||
|
|
@ -53,7 +53,7 @@ proc annotateType*(n: PNode, t: PType) =
|
||||||
of nkPar:
|
of nkPar:
|
||||||
if x.kind == tyTuple:
|
if x.kind == tyTuple:
|
||||||
n.typ = t
|
n.typ = t
|
||||||
for i in 0 .. <n.len:
|
for i in 0 ..< n.len:
|
||||||
if i >= x.len: globalError n.info, "invalid field at index " & $i
|
if i >= x.len: globalError n.info, "invalid field at index " & $i
|
||||||
else: annotateType(n.sons[i], x.sons[i])
|
else: annotateType(n.sons[i], x.sons[i])
|
||||||
elif x.kind == tyProc and x.callConv == ccClosure:
|
elif x.kind == tyProc and x.callConv == ccClosure:
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ proc mergeInitStatus(existing: var InitStatus, newStatus: InitStatus) =
|
||||||
proc locateFieldInInitExpr(field: PSym, initExpr: PNode): PNode =
|
proc locateFieldInInitExpr(field: PSym, initExpr: PNode): PNode =
|
||||||
# Returns the assignment nkExprColonExpr node or nil
|
# Returns the assignment nkExprColonExpr node or nil
|
||||||
let fieldId = field.name.id
|
let fieldId = field.name.id
|
||||||
for i in 1 .. <initExpr.len:
|
for i in 1 ..< initExpr.len:
|
||||||
let assignment = initExpr[i]
|
let assignment = initExpr[i]
|
||||||
if assignment.kind != nkExprColonExpr:
|
if assignment.kind != nkExprColonExpr:
|
||||||
localError(initExpr.info, "incorrect object construction syntax")
|
localError(initExpr.info, "incorrect object construction syntax")
|
||||||
|
|
@ -145,7 +145,7 @@ proc semConstructFields(c: PContext, recNode: PNode,
|
||||||
internalAssert discriminator.kind == nkSym
|
internalAssert discriminator.kind == nkSym
|
||||||
var selectedBranch = -1
|
var selectedBranch = -1
|
||||||
|
|
||||||
for i in 1 .. <recNode.len:
|
for i in 1 ..< recNode.len:
|
||||||
let innerRecords = recNode[i]{-1}
|
let innerRecords = recNode[i]{-1}
|
||||||
let status = semConstructFields(c, innerRecords, initExpr, flags)
|
let status = semConstructFields(c, innerRecords, initExpr, flags)
|
||||||
if status notin {initNone, initUnknown}:
|
if status notin {initNone, initUnknown}:
|
||||||
|
|
@ -220,7 +220,7 @@ proc semConstructFields(c: PContext, recNode: PNode,
|
||||||
else:
|
else:
|
||||||
# All bets are off. If any of the branches has a mandatory
|
# All bets are off. If any of the branches has a mandatory
|
||||||
# fields we must produce an error:
|
# fields we must produce an error:
|
||||||
for i in 1 .. <recNode.len: checkMissingFields recNode[i]
|
for i in 1 ..< recNode.len: checkMissingFields recNode[i]
|
||||||
|
|
||||||
of nkSym:
|
of nkSym:
|
||||||
let field = recNode.sym
|
let field = recNode.sym
|
||||||
|
|
@ -277,7 +277,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# Since we were traversing the object fields, it's possible that
|
# Since we were traversing the object fields, it's possible that
|
||||||
# not all of the fields specified in the constructor was visited.
|
# not all of the fields specified in the constructor was visited.
|
||||||
# We'll check for such fields here:
|
# We'll check for such fields here:
|
||||||
for i in 1.. <result.len:
|
for i in 1..<result.len:
|
||||||
let field = result[i]
|
let field = result[i]
|
||||||
if nfSem notin field.flags:
|
if nfSem notin field.flags:
|
||||||
if field.kind != nkExprColonExpr:
|
if field.kind != nkExprColonExpr:
|
||||||
|
|
@ -286,7 +286,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
let id = considerQuotedIdent(field[0])
|
let id = considerQuotedIdent(field[0])
|
||||||
# This node was not processed. There are two possible reasons:
|
# This node was not processed. There are two possible reasons:
|
||||||
# 1) It was shadowed by a field with the same name on the left
|
# 1) It was shadowed by a field with the same name on the left
|
||||||
for j in 1 .. <i:
|
for j in 1 ..< i:
|
||||||
let prevId = considerQuotedIdent(result[j][0])
|
let prevId = considerQuotedIdent(result[j][0])
|
||||||
if prevId.id == id.id:
|
if prevId.id == id.id:
|
||||||
localError(field.info, errFieldInitTwice, id.s)
|
localError(field.info, errFieldInitTwice, id.s)
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ proc initAnalysisCtx(): AnalysisCtx =
|
||||||
result.guards = @[]
|
result.guards = @[]
|
||||||
|
|
||||||
proc lookupSlot(c: AnalysisCtx; s: PSym): int =
|
proc lookupSlot(c: AnalysisCtx; s: PSym): int =
|
||||||
for i in 0.. <c.locals.len:
|
for i in 0..<c.locals.len:
|
||||||
if c.locals[i].v == s or c.locals[i].alias == s: return i
|
if c.locals[i].v == s or c.locals[i].alias == s: return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ proc getSlot(c: var AnalysisCtx; v: PSym): ptr MonotonicVar =
|
||||||
return addr(c.locals[L])
|
return addr(c.locals[L])
|
||||||
|
|
||||||
proc gatherArgs(c: var AnalysisCtx; n: PNode) =
|
proc gatherArgs(c: var AnalysisCtx; n: PNode) =
|
||||||
for i in 0.. <n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
let root = getRoot n[i]
|
let root = getRoot n[i]
|
||||||
if root != nil:
|
if root != nil:
|
||||||
block addRoot:
|
block addRoot:
|
||||||
|
|
@ -119,7 +119,7 @@ proc checkLocal(c: AnalysisCtx; n: PNode) =
|
||||||
if s >= 0 and c.locals[s].stride != nil:
|
if s >= 0 and c.locals[s].stride != nil:
|
||||||
localError(n.info, "invalid usage of counter after increment")
|
localError(n.info, "invalid usage of counter after increment")
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <n.safeLen: checkLocal(c, n.sons[i])
|
for i in 0 ..< n.safeLen: checkLocal(c, n.sons[i])
|
||||||
|
|
||||||
template `?`(x): untyped = x.renderTree
|
template `?`(x): untyped = x.renderTree
|
||||||
|
|
||||||
|
|
@ -180,7 +180,7 @@ proc stride(c: AnalysisCtx; n: PNode): BiggestInt =
|
||||||
if s >= 0 and c.locals[s].stride != nil:
|
if s >= 0 and c.locals[s].stride != nil:
|
||||||
result = c.locals[s].stride.intVal
|
result = c.locals[s].stride.intVal
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <n.safeLen: result += stride(c, n.sons[i])
|
for i in 0 ..< n.safeLen: result += stride(c, n.sons[i])
|
||||||
|
|
||||||
proc subStride(c: AnalysisCtx; n: PNode): PNode =
|
proc subStride(c: AnalysisCtx; n: PNode): PNode =
|
||||||
# substitute with stride:
|
# substitute with stride:
|
||||||
|
|
@ -192,7 +192,7 @@ proc subStride(c: AnalysisCtx; n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
elif n.safeLen > 0:
|
elif n.safeLen > 0:
|
||||||
result = shallowCopy(n)
|
result = shallowCopy(n)
|
||||||
for i in 0 .. <n.len: result.sons[i] = subStride(c, n.sons[i])
|
for i in 0 ..< n.len: result.sons[i] = subStride(c, n.sons[i])
|
||||||
else:
|
else:
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
|
|
@ -251,7 +251,7 @@ proc checkSlicesAreDisjoint(c: var AnalysisCtx) =
|
||||||
proc analyse(c: var AnalysisCtx; n: PNode)
|
proc analyse(c: var AnalysisCtx; n: PNode)
|
||||||
|
|
||||||
proc analyseSons(c: var AnalysisCtx; n: PNode) =
|
proc analyseSons(c: var AnalysisCtx; n: PNode) =
|
||||||
for i in 0 .. <safeLen(n): analyse(c, n[i])
|
for i in 0 ..< safeLen(n): analyse(c, n[i])
|
||||||
|
|
||||||
proc min(a, b: PNode): PNode =
|
proc min(a, b: PNode): PNode =
|
||||||
if a.isNil: result = b
|
if a.isNil: result = b
|
||||||
|
|
@ -293,11 +293,11 @@ proc analyseCall(c: var AnalysisCtx; n: PNode; op: PSym) =
|
||||||
proc analyseCase(c: var AnalysisCtx; n: PNode) =
|
proc analyseCase(c: var AnalysisCtx; n: PNode) =
|
||||||
analyse(c, n.sons[0])
|
analyse(c, n.sons[0])
|
||||||
let oldFacts = c.guards.len
|
let oldFacts = c.guards.len
|
||||||
for i in 1.. <n.len:
|
for i in 1..<n.len:
|
||||||
let branch = n.sons[i]
|
let branch = n.sons[i]
|
||||||
setLen(c.guards, oldFacts)
|
setLen(c.guards, oldFacts)
|
||||||
addCaseBranchFacts(c.guards, n, i)
|
addCaseBranchFacts(c.guards, n, i)
|
||||||
for i in 0 .. <branch.len:
|
for i in 0 ..< branch.len:
|
||||||
analyse(c, branch.sons[i])
|
analyse(c, branch.sons[i])
|
||||||
setLen(c.guards, oldFacts)
|
setLen(c.guards, oldFacts)
|
||||||
|
|
||||||
|
|
@ -307,14 +307,14 @@ proc analyseIf(c: var AnalysisCtx; n: PNode) =
|
||||||
addFact(c.guards, canon(n.sons[0].sons[0]))
|
addFact(c.guards, canon(n.sons[0].sons[0]))
|
||||||
|
|
||||||
analyse(c, n.sons[0].sons[1])
|
analyse(c, n.sons[0].sons[1])
|
||||||
for i in 1.. <n.len:
|
for i in 1..<n.len:
|
||||||
let branch = n.sons[i]
|
let branch = n.sons[i]
|
||||||
setLen(c.guards, oldFacts)
|
setLen(c.guards, oldFacts)
|
||||||
for j in 0..i-1:
|
for j in 0..i-1:
|
||||||
addFactNeg(c.guards, canon(n.sons[j].sons[0]))
|
addFactNeg(c.guards, canon(n.sons[j].sons[0]))
|
||||||
if branch.len > 1:
|
if branch.len > 1:
|
||||||
addFact(c.guards, canon(branch.sons[0]))
|
addFact(c.guards, canon(branch.sons[0]))
|
||||||
for i in 0 .. <branch.len:
|
for i in 0 ..< branch.len:
|
||||||
analyse(c, branch.sons[i])
|
analyse(c, branch.sons[i])
|
||||||
setLen(c.guards, oldFacts)
|
setLen(c.guards, oldFacts)
|
||||||
|
|
||||||
|
|
@ -407,7 +407,7 @@ proc transformSlices(n: PNode): PNode =
|
||||||
return result
|
return result
|
||||||
if n.safeLen > 0:
|
if n.safeLen > 0:
|
||||||
result = shallowCopy(n)
|
result = shallowCopy(n)
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
result.sons[i] = transformSlices(n.sons[i])
|
result.sons[i] = transformSlices(n.sons[i])
|
||||||
else:
|
else:
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -415,7 +415,7 @@ proc transformSlices(n: PNode): PNode =
|
||||||
proc transformSpawn(owner: PSym; n, barrier: PNode): PNode
|
proc transformSpawn(owner: PSym; n, barrier: PNode): PNode
|
||||||
proc transformSpawnSons(owner: PSym; n, barrier: PNode): PNode =
|
proc transformSpawnSons(owner: PSym; n, barrier: PNode): PNode =
|
||||||
result = shallowCopy(n)
|
result = shallowCopy(n)
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
result.sons[i] = transformSpawn(owner, n.sons[i], barrier)
|
result.sons[i] = transformSpawn(owner, n.sons[i], barrier)
|
||||||
|
|
||||||
proc transformSpawn(owner: PSym; n, barrier: PNode): PNode =
|
proc transformSpawn(owner: PSym; n, barrier: PNode): PNode =
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ type
|
||||||
TIntersection = seq[tuple[id, count: int]] # a simple count table
|
TIntersection = seq[tuple[id, count: int]] # a simple count table
|
||||||
|
|
||||||
proc addToIntersection(inter: var TIntersection, s: int) =
|
proc addToIntersection(inter: var TIntersection, s: int) =
|
||||||
for j in 0.. <inter.len:
|
for j in 0..<inter.len:
|
||||||
if s == inter[j].id:
|
if s == inter[j].id:
|
||||||
inc inter[j].count
|
inc inter[j].count
|
||||||
return
|
return
|
||||||
|
|
@ -282,7 +282,7 @@ proc createTag(n: PNode): PNode =
|
||||||
proc addEffect(a: PEffects, e: PNode, useLineInfo=true) =
|
proc addEffect(a: PEffects, e: PNode, useLineInfo=true) =
|
||||||
assert e.kind != nkRaiseStmt
|
assert e.kind != nkRaiseStmt
|
||||||
var aa = a.exc
|
var aa = a.exc
|
||||||
for i in a.bottom .. <aa.len:
|
for i in a.bottom ..< aa.len:
|
||||||
if sameType(aa[i].excType, e.excType):
|
if sameType(aa[i].excType, e.excType):
|
||||||
if not useLineInfo or gCmd == cmdDoc: return
|
if not useLineInfo or gCmd == cmdDoc: return
|
||||||
elif aa[i].info == e.info: return
|
elif aa[i].info == e.info: return
|
||||||
|
|
@ -290,7 +290,7 @@ proc addEffect(a: PEffects, e: PNode, useLineInfo=true) =
|
||||||
|
|
||||||
proc addTag(a: PEffects, e: PNode, useLineInfo=true) =
|
proc addTag(a: PEffects, e: PNode, useLineInfo=true) =
|
||||||
var aa = a.tags
|
var aa = a.tags
|
||||||
for i in 0 .. <aa.len:
|
for i in 0 ..< aa.len:
|
||||||
if sameType(aa[i].typ.skipTypes(skipPtrs), e.typ.skipTypes(skipPtrs)):
|
if sameType(aa[i].typ.skipTypes(skipPtrs), e.typ.skipTypes(skipPtrs)):
|
||||||
if not useLineInfo or gCmd == cmdDoc: return
|
if not useLineInfo or gCmd == cmdDoc: return
|
||||||
elif aa[i].info == e.info: return
|
elif aa[i].info == e.info: return
|
||||||
|
|
@ -345,12 +345,12 @@ proc trackTryStmt(tracked: PEffects, n: PNode) =
|
||||||
inc tracked.inTryStmt
|
inc tracked.inTryStmt
|
||||||
track(tracked, n.sons[0])
|
track(tracked, n.sons[0])
|
||||||
dec tracked.inTryStmt
|
dec tracked.inTryStmt
|
||||||
for i in oldState.. <tracked.init.len:
|
for i in oldState..<tracked.init.len:
|
||||||
addToIntersection(inter, tracked.init[i])
|
addToIntersection(inter, tracked.init[i])
|
||||||
|
|
||||||
var branches = 1
|
var branches = 1
|
||||||
var hasFinally = false
|
var hasFinally = false
|
||||||
for i in 1 .. < n.len:
|
for i in 1 ..< n.len:
|
||||||
let b = n.sons[i]
|
let b = n.sons[i]
|
||||||
let blen = sonsLen(b)
|
let blen = sonsLen(b)
|
||||||
if b.kind == nkExceptBranch:
|
if b.kind == nkExceptBranch:
|
||||||
|
|
@ -364,7 +364,7 @@ proc trackTryStmt(tracked: PEffects, n: PNode) =
|
||||||
|
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
track(tracked, b.sons[blen-1])
|
track(tracked, b.sons[blen-1])
|
||||||
for i in oldState.. <tracked.init.len:
|
for i in oldState..<tracked.init.len:
|
||||||
addToIntersection(inter, tracked.init[i])
|
addToIntersection(inter, tracked.init[i])
|
||||||
else:
|
else:
|
||||||
assert b.kind == nkFinally
|
assert b.kind == nkFinally
|
||||||
|
|
@ -420,7 +420,7 @@ proc documentEffect(n, x: PNode, effectType: TSpecialWord, idx: int): PNode =
|
||||||
|
|
||||||
# warning: hack ahead:
|
# warning: hack ahead:
|
||||||
var effects = newNodeI(nkBracket, n.info, real.len)
|
var effects = newNodeI(nkBracket, n.info, real.len)
|
||||||
for i in 0 .. <real.len:
|
for i in 0 ..< real.len:
|
||||||
var t = typeToString(real[i].typ)
|
var t = typeToString(real[i].typ)
|
||||||
if t.startsWith("ref "): t = substr(t, 4)
|
if t.startsWith("ref "): t = substr(t, 4)
|
||||||
effects.sons[i] = newIdentNode(getIdent(t), n.info)
|
effects.sons[i] = newIdentNode(getIdent(t), n.info)
|
||||||
|
|
@ -613,16 +613,16 @@ proc trackCase(tracked: PEffects, n: PNode) =
|
||||||
warnProveField in gNotes
|
warnProveField in gNotes
|
||||||
var inter: TIntersection = @[]
|
var inter: TIntersection = @[]
|
||||||
var toCover = 0
|
var toCover = 0
|
||||||
for i in 1.. <n.len:
|
for i in 1..<n.len:
|
||||||
let branch = n.sons[i]
|
let branch = n.sons[i]
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
if interesting:
|
if interesting:
|
||||||
setLen(tracked.guards, oldFacts)
|
setLen(tracked.guards, oldFacts)
|
||||||
addCaseBranchFacts(tracked.guards, n, i)
|
addCaseBranchFacts(tracked.guards, n, i)
|
||||||
for i in 0 .. <branch.len:
|
for i in 0 ..< branch.len:
|
||||||
track(tracked, branch.sons[i])
|
track(tracked, branch.sons[i])
|
||||||
if not breaksBlock(branch.lastSon): inc toCover
|
if not breaksBlock(branch.lastSon): inc toCover
|
||||||
for i in oldState.. <tracked.init.len:
|
for i in oldState..<tracked.init.len:
|
||||||
addToIntersection(inter, tracked.init[i])
|
addToIntersection(inter, tracked.init[i])
|
||||||
|
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
|
|
@ -642,10 +642,10 @@ proc trackIf(tracked: PEffects, n: PNode) =
|
||||||
var toCover = 0
|
var toCover = 0
|
||||||
track(tracked, n.sons[0].sons[1])
|
track(tracked, n.sons[0].sons[1])
|
||||||
if not breaksBlock(n.sons[0].sons[1]): inc toCover
|
if not breaksBlock(n.sons[0].sons[1]): inc toCover
|
||||||
for i in oldState.. <tracked.init.len:
|
for i in oldState..<tracked.init.len:
|
||||||
addToIntersection(inter, tracked.init[i])
|
addToIntersection(inter, tracked.init[i])
|
||||||
|
|
||||||
for i in 1.. <n.len:
|
for i in 1..<n.len:
|
||||||
let branch = n.sons[i]
|
let branch = n.sons[i]
|
||||||
setLen(tracked.guards, oldFacts)
|
setLen(tracked.guards, oldFacts)
|
||||||
for j in 0..i-1:
|
for j in 0..i-1:
|
||||||
|
|
@ -653,10 +653,10 @@ proc trackIf(tracked: PEffects, n: PNode) =
|
||||||
if branch.len > 1:
|
if branch.len > 1:
|
||||||
addFact(tracked.guards, branch.sons[0])
|
addFact(tracked.guards, branch.sons[0])
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
for i in 0 .. <branch.len:
|
for i in 0 ..< branch.len:
|
||||||
track(tracked, branch.sons[i])
|
track(tracked, branch.sons[i])
|
||||||
if not breaksBlock(branch.lastSon): inc toCover
|
if not breaksBlock(branch.lastSon): inc toCover
|
||||||
for i in oldState.. <tracked.init.len:
|
for i in oldState..<tracked.init.len:
|
||||||
addToIntersection(inter, tracked.init[i])
|
addToIntersection(inter, tracked.init[i])
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
if lastSon(n).len == 1:
|
if lastSon(n).len == 1:
|
||||||
|
|
@ -668,7 +668,7 @@ proc trackIf(tracked: PEffects, n: PNode) =
|
||||||
proc trackBlock(tracked: PEffects, n: PNode) =
|
proc trackBlock(tracked: PEffects, n: PNode) =
|
||||||
if n.kind in {nkStmtList, nkStmtListExpr}:
|
if n.kind in {nkStmtList, nkStmtListExpr}:
|
||||||
var oldState = -1
|
var oldState = -1
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
if hasSubnodeWith(n.sons[i], nkBreakStmt):
|
if hasSubnodeWith(n.sons[i], nkBreakStmt):
|
||||||
# block:
|
# block:
|
||||||
# x = def
|
# x = def
|
||||||
|
|
@ -701,7 +701,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
n.sons[0].info = n.info
|
n.sons[0].info = n.info
|
||||||
#throws(tracked.exc, n.sons[0])
|
#throws(tracked.exc, n.sons[0])
|
||||||
addEffect(tracked, n.sons[0], useLineInfo=false)
|
addEffect(tracked, n.sons[0], useLineInfo=false)
|
||||||
for i in 0 .. <safeLen(n):
|
for i in 0 ..< safeLen(n):
|
||||||
track(tracked, n.sons[i])
|
track(tracked, n.sons[i])
|
||||||
of nkCallKinds:
|
of nkCallKinds:
|
||||||
# p's effects are ours too:
|
# p's effects are ours too:
|
||||||
|
|
@ -752,11 +752,11 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
message(arg.info, warnProveInit, $arg)
|
message(arg.info, warnProveInit, $arg)
|
||||||
for i in 0 .. <safeLen(n):
|
for i in 0 ..< safeLen(n):
|
||||||
track(tracked, n.sons[i])
|
track(tracked, n.sons[i])
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
guardDotAccess(tracked, n)
|
guardDotAccess(tracked, n)
|
||||||
for i in 0 .. <len(n): track(tracked, n.sons[i])
|
for i in 0 ..< len(n): track(tracked, n.sons[i])
|
||||||
of nkCheckedFieldExpr:
|
of nkCheckedFieldExpr:
|
||||||
track(tracked, n.sons[0])
|
track(tracked, n.sons[0])
|
||||||
if warnProveField in gNotes: checkFieldAccess(tracked.guards, n)
|
if warnProveField in gNotes: checkFieldAccess(tracked.guards, n)
|
||||||
|
|
@ -804,13 +804,13 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
of nkForStmt, nkParForStmt:
|
of nkForStmt, nkParForStmt:
|
||||||
# we are very conservative here and assume the loop is never executed:
|
# we are very conservative here and assume the loop is never executed:
|
||||||
let oldState = tracked.init.len
|
let oldState = tracked.init.len
|
||||||
for i in 0 .. <len(n):
|
for i in 0 ..< len(n):
|
||||||
track(tracked, n.sons[i])
|
track(tracked, n.sons[i])
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
of nkObjConstr:
|
of nkObjConstr:
|
||||||
when false: track(tracked, n.sons[0])
|
when false: track(tracked, n.sons[0])
|
||||||
let oldFacts = tracked.guards.len
|
let oldFacts = tracked.guards.len
|
||||||
for i in 1 .. <len(n):
|
for i in 1 ..< len(n):
|
||||||
let x = n.sons[i]
|
let x = n.sons[i]
|
||||||
track(tracked, x)
|
track(tracked, x)
|
||||||
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
|
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
|
||||||
|
|
@ -821,7 +821,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
let oldLocked = tracked.locked.len
|
let oldLocked = tracked.locked.len
|
||||||
let oldLockLevel = tracked.currLockLevel
|
let oldLockLevel = tracked.currLockLevel
|
||||||
var enforcedGcSafety = false
|
var enforcedGcSafety = false
|
||||||
for i in 0 .. <pragmaList.len:
|
for i in 0 ..< pragmaList.len:
|
||||||
let pragma = whichPragma(pragmaList.sons[i])
|
let pragma = whichPragma(pragmaList.sons[i])
|
||||||
if pragma == wLocks:
|
if pragma == wLocks:
|
||||||
lockLocations(tracked, pragmaList.sons[i])
|
lockLocations(tracked, pragmaList.sons[i])
|
||||||
|
|
@ -840,7 +840,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
||||||
if n.len == 1: track(tracked, n.sons[0])
|
if n.len == 1: track(tracked, n.sons[0])
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <safeLen(n): track(tracked, n.sons[i])
|
for i in 0 ..< safeLen(n): track(tracked, n.sons[i])
|
||||||
|
|
||||||
proc subtypeRelation(spec, real: PNode): bool =
|
proc subtypeRelation(spec, real: PNode): bool =
|
||||||
result = safeInheritanceDiff(real.excType, spec.typ) <= 0
|
result = safeInheritanceDiff(real.excType, spec.typ) <= 0
|
||||||
|
|
@ -852,7 +852,7 @@ proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool;
|
||||||
var used = initIntSet()
|
var used = initIntSet()
|
||||||
for r in items(real):
|
for r in items(real):
|
||||||
block search:
|
block search:
|
||||||
for s in 0 .. <spec.len:
|
for s in 0 ..< spec.len:
|
||||||
if effectPredicate(spec[s], r):
|
if effectPredicate(spec[s], r):
|
||||||
used.incl(s)
|
used.incl(s)
|
||||||
break search
|
break search
|
||||||
|
|
@ -862,7 +862,7 @@ proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool;
|
||||||
popInfoContext()
|
popInfoContext()
|
||||||
# hint about unnecessarily listed exception types:
|
# hint about unnecessarily listed exception types:
|
||||||
if hints:
|
if hints:
|
||||||
for s in 0 .. <spec.len:
|
for s in 0 ..< spec.len:
|
||||||
if not used.contains(s):
|
if not used.contains(s):
|
||||||
message(spec[s].info, hintXDeclaredButNotUsed, renderTree(spec[s]))
|
message(spec[s].info, hintXDeclaredButNotUsed, renderTree(spec[s]))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -858,7 +858,7 @@ proc checkCovariantParamsUsages(genericType: PType) =
|
||||||
|
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
let targetBody = t[0]
|
let targetBody = t[0]
|
||||||
for i in 1 .. <t.len:
|
for i in 1 ..< t.len:
|
||||||
let param = t[i]
|
let param = t[i]
|
||||||
if param.kind == tyGenericParam:
|
if param.kind == tyGenericParam:
|
||||||
if tfCovariant in param.flags:
|
if tfCovariant in param.flags:
|
||||||
|
|
@ -1005,7 +1005,7 @@ proc checkForMetaFields(n: PNode) =
|
||||||
of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyPtr, tyRef,
|
of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyPtr, tyRef,
|
||||||
tyProc, tyGenericInvocation, tyGenericInst, tyAlias:
|
tyProc, tyGenericInvocation, tyGenericInst, tyAlias:
|
||||||
let start = ord(t.kind in {tyGenericInvocation, tyGenericInst})
|
let start = ord(t.kind in {tyGenericInvocation, tyGenericInst})
|
||||||
for i in start .. <t.sons.len:
|
for i in start ..< t.sons.len:
|
||||||
checkMeta(t.sons[i])
|
checkMeta(t.sons[i])
|
||||||
else:
|
else:
|
||||||
checkMeta(t)
|
checkMeta(t)
|
||||||
|
|
@ -1131,7 +1131,7 @@ proc addResultNode(c: PContext, n: PNode) =
|
||||||
|
|
||||||
proc copyExcept(n: PNode, i: int): PNode =
|
proc copyExcept(n: PNode, i: int): PNode =
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
for j in 0.. <n.len:
|
for j in 0..<n.len:
|
||||||
if j != i: result.add(n.sons[j])
|
if j != i: result.add(n.sons[j])
|
||||||
|
|
||||||
proc lookupMacro(c: PContext, n: PNode): PSym =
|
proc lookupMacro(c: PContext, n: PNode): PSym =
|
||||||
|
|
@ -1145,7 +1145,7 @@ proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
validPragmas: TSpecialWords): PNode =
|
validPragmas: TSpecialWords): PNode =
|
||||||
var n = prc.sons[pragmasPos]
|
var n = prc.sons[pragmasPos]
|
||||||
if n == nil or n.kind == nkEmpty: return
|
if n == nil or n.kind == nkEmpty: return
|
||||||
for i in countup(0, <n.len):
|
for i in countup(0, n.len-1):
|
||||||
var it = n.sons[i]
|
var it = n.sons[i]
|
||||||
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
|
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
|
||||||
let m = lookupMacro(c, key)
|
let m = lookupMacro(c, key)
|
||||||
|
|
@ -1296,7 +1296,7 @@ proc activate(c: PContext, n: PNode) =
|
||||||
of nkLambdaKinds:
|
of nkLambdaKinds:
|
||||||
discard semLambda(c, n, {})
|
discard semLambda(c, n, {})
|
||||||
of nkCallKinds:
|
of nkCallKinds:
|
||||||
for i in 1 .. <n.len: activate(c, n[i])
|
for i in 1 ..< n.len: activate(c, n[i])
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
@ -1719,7 +1719,7 @@ proc evalInclude(c: PContext, n: PNode): PNode =
|
||||||
excl(c.includedFiles, f)
|
excl(c.includedFiles, f)
|
||||||
|
|
||||||
proc setLine(n: PNode, info: TLineInfo) =
|
proc setLine(n: PNode, info: TLineInfo) =
|
||||||
for i in 0 .. <safeLen(n): setLine(n.sons[i], info)
|
for i in 0 ..< safeLen(n): setLine(n.sons[i], info)
|
||||||
n.info = info
|
n.info = info
|
||||||
|
|
||||||
proc semPragmaBlock(c: PContext, n: PNode): PNode =
|
proc semPragmaBlock(c: PContext, n: PNode): PNode =
|
||||||
|
|
@ -1727,7 +1727,7 @@ proc semPragmaBlock(c: PContext, n: PNode): PNode =
|
||||||
pragma(c, nil, pragmaList, exprPragmas)
|
pragma(c, nil, pragmaList, exprPragmas)
|
||||||
result = semExpr(c, n.sons[1])
|
result = semExpr(c, n.sons[1])
|
||||||
n.sons[1] = result
|
n.sons[1] = result
|
||||||
for i in 0 .. <pragmaList.len:
|
for i in 0 ..< pragmaList.len:
|
||||||
case whichPragma(pragmaList.sons[i])
|
case whichPragma(pragmaList.sons[i])
|
||||||
of wLine: setLine(result, pragmaList.sons[i].info)
|
of wLine: setLine(result, pragmaList.sons[i].info)
|
||||||
of wLocks, wGcSafe:
|
of wLocks, wGcSafe:
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode =
|
||||||
a = nextOverloadIter(o, c, n)
|
a = nextOverloadIter(o, c, n)
|
||||||
|
|
||||||
proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
# If 'a' is an overloaded symbol, we used to use the first symbol
|
# If 'a' is an overloaded symbol, we used to use the first symbol
|
||||||
# as a 'witness' and use the fact that subsequent lookups will yield
|
# as a 'witness' and use the fact that subsequent lookups will yield
|
||||||
|
|
@ -95,7 +95,7 @@ proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
||||||
result = newNodeI(nkEmpty, n.info)
|
result = newNodeI(nkEmpty, n.info)
|
||||||
|
|
||||||
proc semMixinStmt(c: PContext, n: PNode, toMixin: var IntSet): PNode =
|
proc semMixinStmt(c: PContext, n: PNode, toMixin: var IntSet): PNode =
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
toMixin.incl(considerQuotedIdent(n.sons[i]).id)
|
toMixin.incl(considerQuotedIdent(n.sons[i]).id)
|
||||||
result = newNodeI(nkEmpty, n.info)
|
result = newNodeI(nkEmpty, n.info)
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ proc onlyReplaceParams(c: var TemplCtx, n: PNode): PNode =
|
||||||
result = newSymNode(s, n.info)
|
result = newSymNode(s, n.info)
|
||||||
styleCheckUse(n.info, s)
|
styleCheckUse(n.info, s)
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
result.sons[i] = onlyReplaceParams(c, n.sons[i])
|
result.sons[i] = onlyReplaceParams(c, n.sons[i])
|
||||||
|
|
||||||
proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
|
proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
|
||||||
|
|
@ -301,7 +301,7 @@ proc semPattern(c: PContext, n: PNode): PNode
|
||||||
|
|
||||||
proc semTemplBodySons(c: var TemplCtx, n: PNode): PNode =
|
proc semTemplBodySons(c: var TemplCtx, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
for i in 0.. < n.len:
|
for i in 0 ..< n.len:
|
||||||
result.sons[i] = semTemplBody(c, n.sons[i])
|
result.sons[i] = semTemplBody(c, n.sons[i])
|
||||||
|
|
||||||
proc oprIsRoof(n: PNode): bool =
|
proc oprIsRoof(n: PNode): bool =
|
||||||
|
|
|
||||||
|
|
@ -515,7 +515,7 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
||||||
# first element is special and will overwrite: branch.sons[i]:
|
# first element is special and will overwrite: branch.sons[i]:
|
||||||
branch.sons[i] = semCaseBranchSetElem(c, t, r[0], covered)
|
branch.sons[i] = semCaseBranchSetElem(c, t, r[0], covered)
|
||||||
# other elements have to be added to ``branch``
|
# other elements have to be added to ``branch``
|
||||||
for j in 1 .. <r.len:
|
for j in 1 ..< r.len:
|
||||||
branch.add(semCaseBranchSetElem(c, t, r[j], covered))
|
branch.add(semCaseBranchSetElem(c, t, r[j], covered))
|
||||||
# caution! last son of branch must be the actions to execute:
|
# caution! last son of branch must be the actions to execute:
|
||||||
var L = branch.len
|
var L = branch.len
|
||||||
|
|
@ -846,7 +846,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
@[newTypeS(paramType.kind, c)])
|
@[newTypeS(paramType.kind, c)])
|
||||||
result = addImplicitGeneric(typ)
|
result = addImplicitGeneric(typ)
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <paramType.len:
|
for i in 0 ..< paramType.len:
|
||||||
if paramType.sons[i] == paramType:
|
if paramType.sons[i] == paramType:
|
||||||
globalError(info, errIllegalRecursionInTypeX, typeToString(paramType))
|
globalError(info, errIllegalRecursionInTypeX, typeToString(paramType))
|
||||||
var lifted = liftingWalk(paramType.sons[i])
|
var lifted = liftingWalk(paramType.sons[i])
|
||||||
|
|
@ -897,7 +897,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
result.shouldHaveMeta
|
result.shouldHaveMeta
|
||||||
|
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
for i in 1 .. <paramType.len:
|
for i in 1 ..< paramType.len:
|
||||||
let lifted = liftingWalk(paramType.sons[i])
|
let lifted = liftingWalk(paramType.sons[i])
|
||||||
if lifted != nil: paramType.sons[i] = lifted
|
if lifted != nil: paramType.sons[i] = lifted
|
||||||
|
|
||||||
|
|
@ -1146,7 +1146,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
|
|
||||||
var isConcrete = true
|
var isConcrete = true
|
||||||
|
|
||||||
for i in 1 .. <m.call.len:
|
for i in 1 ..< m.call.len:
|
||||||
var typ = m.call[i].typ
|
var typ = m.call[i].typ
|
||||||
if typ.kind == tyTypeDesc and typ.sons[0].kind == tyNone:
|
if typ.kind == tyTypeDesc and typ.sons[0].kind == tyNone:
|
||||||
isConcrete = false
|
isConcrete = false
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ proc prepareNode(cl: var TReplTypeVars, n: PNode): PNode =
|
||||||
result.typ = t
|
result.typ = t
|
||||||
if result.kind == nkSym: result.sym = replaceTypeVarsS(cl, n.sym)
|
if result.kind == nkSym: result.sym = replaceTypeVarsS(cl, n.sym)
|
||||||
let isCall = result.kind in nkCallKinds
|
let isCall = result.kind in nkCallKinds
|
||||||
for i in 0 .. <n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
# XXX HACK: ``f(a, b)``, avoid to instantiate `f`
|
# XXX HACK: ``f(a, b)``, avoid to instantiate `f`
|
||||||
if isCall and i == 0: result.add(n[i])
|
if isCall and i == 0: result.add(n[i])
|
||||||
else: result.add(prepareNode(cl, n[i]))
|
else: result.add(prepareNode(cl, n[i]))
|
||||||
|
|
@ -151,7 +151,7 @@ proc hasGenericArguments*(n: PNode): bool =
|
||||||
(n.sym.kind == skType and
|
(n.sym.kind == skType and
|
||||||
n.sym.typ.flags * {tfGenericTypeParam, tfImplicitTypeParam} != {})
|
n.sym.typ.flags * {tfGenericTypeParam, tfImplicitTypeParam} != {})
|
||||||
else:
|
else:
|
||||||
for i in 0.. <n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
if hasGenericArguments(n.sons[i]): return true
|
if hasGenericArguments(n.sons[i]): return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
@ -166,13 +166,13 @@ proc reResolveCallsWithTypedescParams(cl: var TReplTypeVars, n: PNode): PNode =
|
||||||
# overload resolution is executed again (which may trigger generateInstance).
|
# overload resolution is executed again (which may trigger generateInstance).
|
||||||
if n.kind in nkCallKinds and sfFromGeneric in n[0].sym.flags:
|
if n.kind in nkCallKinds and sfFromGeneric in n[0].sym.flags:
|
||||||
var needsFixing = false
|
var needsFixing = false
|
||||||
for i in 1 .. <n.safeLen:
|
for i in 1 ..< n.safeLen:
|
||||||
if isTypeParam(n[i]): needsFixing = true
|
if isTypeParam(n[i]): needsFixing = true
|
||||||
if needsFixing:
|
if needsFixing:
|
||||||
n.sons[0] = newSymNode(n.sons[0].sym.owner)
|
n.sons[0] = newSymNode(n.sons[0].sym.owner)
|
||||||
return cl.c.semOverloadedCall(cl.c, n, n, {skProc, skFunc}, {})
|
return cl.c.semOverloadedCall(cl.c, n, n, {skProc, skFunc}, {})
|
||||||
|
|
||||||
for i in 0 .. <n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
n.sons[i] = reResolveCallsWithTypedescParams(cl, n[i])
|
n.sons[i] = reResolveCallsWithTypedescParams(cl, n[i])
|
||||||
|
|
||||||
return n
|
return n
|
||||||
|
|
@ -385,11 +385,11 @@ proc eraseVoidParams*(t: PType) =
|
||||||
if t.sons[0] != nil and t.sons[0].kind == tyVoid:
|
if t.sons[0] != nil and t.sons[0].kind == tyVoid:
|
||||||
t.sons[0] = nil
|
t.sons[0] = nil
|
||||||
|
|
||||||
for i in 1 .. <t.sonsLen:
|
for i in 1 ..< t.sonsLen:
|
||||||
# don't touch any memory unless necessary
|
# don't touch any memory unless necessary
|
||||||
if t.sons[i].kind == tyVoid:
|
if t.sons[i].kind == tyVoid:
|
||||||
var pos = i
|
var pos = i
|
||||||
for j in i+1 .. <t.sonsLen:
|
for j in i+1 ..< t.sonsLen:
|
||||||
if t.sons[j].kind != tyVoid:
|
if t.sons[j].kind != tyVoid:
|
||||||
t.sons[pos] = t.sons[j]
|
t.sons[pos] = t.sons[j]
|
||||||
t.n.sons[pos] = t.n.sons[j]
|
t.n.sons[pos] = t.n.sons[j]
|
||||||
|
|
@ -399,7 +399,7 @@ proc eraseVoidParams*(t: PType) =
|
||||||
return
|
return
|
||||||
|
|
||||||
proc skipIntLiteralParams*(t: PType) =
|
proc skipIntLiteralParams*(t: PType) =
|
||||||
for i in 0 .. <t.sonsLen:
|
for i in 0 ..< t.sonsLen:
|
||||||
let p = t.sons[i]
|
let p = t.sons[i]
|
||||||
if p == nil: continue
|
if p == nil: continue
|
||||||
let skipped = p.skipIntLit
|
let skipped = p.skipIntLit
|
||||||
|
|
@ -500,7 +500,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
bailout()
|
bailout()
|
||||||
result = instCopyType(cl, t)
|
result = instCopyType(cl, t)
|
||||||
idTablePut(cl.localCache, t, result)
|
idTablePut(cl.localCache, t, result)
|
||||||
for i in 1 .. <result.sonsLen:
|
for i in 1 ..< result.sonsLen:
|
||||||
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
||||||
propagateToOwner(result, result.lastSon)
|
propagateToOwner(result, result.lastSon)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ proc hashTree(c: var MD5Context, n: PNode) =
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
c &= n.strVal
|
c &= n.strVal
|
||||||
else:
|
else:
|
||||||
for i in 0.. <n.len: hashTree(c, n.sons[i])
|
for i in 0..<n.len: hashTree(c, n.sons[i])
|
||||||
|
|
||||||
proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
if t == nil:
|
if t == nil:
|
||||||
|
|
@ -230,14 +230,14 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
c &= ','
|
c &= ','
|
||||||
c.hashType(t.sons[0], flags)
|
c.hashType(t.sons[0], flags)
|
||||||
else:
|
else:
|
||||||
for i in 0.. <t.len: c.hashType(t.sons[i], flags)
|
for i in 0..<t.len: c.hashType(t.sons[i], flags)
|
||||||
c &= char(t.callConv)
|
c &= char(t.callConv)
|
||||||
if CoType notin flags:
|
if CoType notin flags:
|
||||||
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
|
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
|
||||||
if tfThread in t.flags: c &= ".thread"
|
if tfThread in t.flags: c &= ".thread"
|
||||||
if tfVarargs in t.flags: c &= ".varargs"
|
if tfVarargs in t.flags: c &= ".varargs"
|
||||||
else:
|
else:
|
||||||
for i in 0.. <t.len: c.hashType(t.sons[i], flags)
|
for i in 0..<t.len: c.hashType(t.sons[i], flags)
|
||||||
if tfNotNil in t.flags and CoType notin flags: c &= "not nil"
|
if tfNotNil in t.flags and CoType notin flags: c &= "not nil"
|
||||||
|
|
||||||
when defined(debugSigHashes):
|
when defined(debugSigHashes):
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ proc sumGeneric(t: PType): int =
|
||||||
inc result
|
inc result
|
||||||
of tyGenericInvocation, tyTuple, tyProc, tyAnd:
|
of tyGenericInvocation, tyTuple, tyProc, tyAnd:
|
||||||
result += ord(t.kind in {tyGenericInvocation, tyAnd})
|
result += ord(t.kind in {tyGenericInvocation, tyAnd})
|
||||||
for i in 0 .. <t.len:
|
for i in 0 ..< t.len:
|
||||||
if t.sons[i] != nil:
|
if t.sons[i] != nil:
|
||||||
result += t.sons[i].sumGeneric
|
result += t.sons[i].sumGeneric
|
||||||
break
|
break
|
||||||
|
|
@ -220,7 +220,7 @@ proc sumGeneric(t: PType): int =
|
||||||
proc complexDisambiguation(a, b: PType): int =
|
proc complexDisambiguation(a, b: PType): int =
|
||||||
# 'a' matches better if *every* argument matches better or equal than 'b'.
|
# 'a' matches better if *every* argument matches better or equal than 'b'.
|
||||||
var winner = 0
|
var winner = 0
|
||||||
for i in 1 .. <min(a.len, b.len):
|
for i in 1 ..< min(a.len, b.len):
|
||||||
let x = a.sons[i].sumGeneric
|
let x = a.sons[i].sumGeneric
|
||||||
let y = b.sons[i].sumGeneric
|
let y = b.sons[i].sumGeneric
|
||||||
#if ggDebug:
|
#if ggDebug:
|
||||||
|
|
@ -240,8 +240,8 @@ proc complexDisambiguation(a, b: PType): int =
|
||||||
result = winner
|
result = winner
|
||||||
when false:
|
when false:
|
||||||
var x, y: int
|
var x, y: int
|
||||||
for i in 1 .. <a.len: x += a.sons[i].sumGeneric
|
for i in 1 ..< a.len: x += a.sons[i].sumGeneric
|
||||||
for i in 1 .. <b.len: y += b.sons[i].sumGeneric
|
for i in 1 ..< b.len: y += b.sons[i].sumGeneric
|
||||||
result = x - y
|
result = x - y
|
||||||
|
|
||||||
proc writeMatches*(c: TCandidate) =
|
proc writeMatches*(c: TCandidate) =
|
||||||
|
|
@ -276,7 +276,7 @@ proc cmpCandidates*(a, b: TCandidate): int =
|
||||||
proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string =
|
proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string =
|
||||||
if arg.kind in nkSymChoices:
|
if arg.kind in nkSymChoices:
|
||||||
result = typeToString(arg[0].typ, prefer)
|
result = typeToString(arg[0].typ, prefer)
|
||||||
for i in 1 .. <arg.len:
|
for i in 1 ..< arg.len:
|
||||||
result.add(" | ")
|
result.add(" | ")
|
||||||
result.add typeToString(arg[i].typ, prefer)
|
result.add typeToString(arg[i].typ, prefer)
|
||||||
elif arg.typ == nil:
|
elif arg.typ == nil:
|
||||||
|
|
@ -581,7 +581,7 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
|
|
||||||
# Note: We have to do unification for the parameters before the
|
# Note: We have to do unification for the parameters before the
|
||||||
# return type!
|
# return type!
|
||||||
for i in 1 .. <f.sonsLen:
|
for i in 1 ..< f.sonsLen:
|
||||||
checkParam(f.sons[i], a.sons[i])
|
checkParam(f.sons[i], a.sons[i])
|
||||||
|
|
||||||
if f.sons[0] != nil:
|
if f.sons[0] != nil:
|
||||||
|
|
@ -659,7 +659,7 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
||||||
var typeParams: seq[(PSym, PType)]
|
var typeParams: seq[(PSym, PType)]
|
||||||
|
|
||||||
if ff.kind == tyUserTypeClassInst:
|
if ff.kind == tyUserTypeClassInst:
|
||||||
for i in 1 .. <(ff.len - 1):
|
for i in 1 ..< (ff.len - 1):
|
||||||
var
|
var
|
||||||
typeParamName = ff.base.sons[i-1].sym.name
|
typeParamName = ff.base.sons[i-1].sym.name
|
||||||
typ = ff.sons[i]
|
typ = ff.sons[i]
|
||||||
|
|
@ -2233,7 +2233,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
proc semFinishOperands*(c: PContext, n: PNode) =
|
proc semFinishOperands*(c: PContext, n: PNode) =
|
||||||
# this needs to be called to ensure that after overloading resolution every
|
# this needs to be called to ensure that after overloading resolution every
|
||||||
# argument has been sem'checked:
|
# argument has been sem'checked:
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
n.sons[i] = prepareOperand(c, n.sons[i])
|
n.sons[i] = prepareOperand(c, n.sons[i])
|
||||||
|
|
||||||
proc partialMatch*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
proc partialMatch*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ proc freshLabels(c: PTransf, n: PNode; symMap: var TIdTable) =
|
||||||
let x = PSym(idTableGet(symMap, n.sym))
|
let x = PSym(idTableGet(symMap, n.sym))
|
||||||
if x != nil: n.sym = x
|
if x != nil: n.sym = x
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <safeLen(n): freshLabels(c, n.sons[i], symMap)
|
for i in 0 ..< safeLen(n): freshLabels(c, n.sons[i], symMap)
|
||||||
|
|
||||||
proc transformBlock(c: PTransf, n: PNode): PTransNode =
|
proc transformBlock(c: PTransf, n: PNode): PTransNode =
|
||||||
var labl: PSym
|
var labl: PSym
|
||||||
|
|
@ -275,7 +275,7 @@ proc transformWhile(c: PTransf; n: PNode): PTransNode =
|
||||||
var body = newTransNode(n)
|
var body = newTransNode(n)
|
||||||
for i in 0..n.len-2:
|
for i in 0..n.len-2:
|
||||||
body[i] = transform(c, n.sons[i])
|
body[i] = transform(c, n.sons[i])
|
||||||
body[<n.len] = transformLoopBody(c, n.sons[<n.len])
|
body[n.len-1] = transformLoopBody(c, n.sons[n.len-1])
|
||||||
result[1] = body
|
result[1] = body
|
||||||
discard c.breakSyms.pop
|
discard c.breakSyms.pop
|
||||||
|
|
||||||
|
|
@ -516,7 +516,7 @@ proc findWrongOwners(c: PTransf, n: PNode) =
|
||||||
internalError(x.info, "bah " & x.sym.name.s & " " &
|
internalError(x.info, "bah " & x.sym.name.s & " " &
|
||||||
x.sym.owner.name.s & " " & getCurrOwner(c).name.s)
|
x.sym.owner.name.s & " " & getCurrOwner(c).name.s)
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <safeLen(n): findWrongOwners(c, n.sons[i])
|
for i in 0 ..< safeLen(n): findWrongOwners(c, n.sons[i])
|
||||||
|
|
||||||
proc transformFor(c: PTransf, n: PNode): PTransNode =
|
proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||||
# generate access statements for the parameters (unless they are constant)
|
# generate access statements for the parameters (unless they are constant)
|
||||||
|
|
@ -646,7 +646,7 @@ proc transformArrayAccess(c: PTransf, n: PNode): PTransNode =
|
||||||
result = n.PTransNode
|
result = n.PTransNode
|
||||||
else:
|
else:
|
||||||
result = newTransNode(n)
|
result = newTransNode(n)
|
||||||
for i in 0 .. < n.len:
|
for i in 0 ..< n.len:
|
||||||
result[i] = transform(c, skipConv(n.sons[i]))
|
result[i] = transform(c, skipConv(n.sons[i]))
|
||||||
|
|
||||||
proc getMergeOp(n: PNode): PSym =
|
proc getMergeOp(n: PNode): PSym =
|
||||||
|
|
@ -750,7 +750,7 @@ proc dontInlineConstant(orig, cnst: PNode): bool {.inline.} =
|
||||||
|
|
||||||
proc commonOptimizations*(c: PSym, n: PNode): PNode =
|
proc commonOptimizations*(c: PSym, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
for i in 0 .. < n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
result.sons[i] = commonOptimizations(c, n.sons[i])
|
result.sons[i] = commonOptimizations(c, n.sons[i])
|
||||||
var op = getMergeOp(n)
|
var op = getMergeOp(n)
|
||||||
if (op != nil) and (op.magic != mNone) and (sonsLen(n) >= 3):
|
if (op != nil) and (op.magic != mNone) and (sonsLen(n) >= 3):
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ proc isDeepConstExpr*(n: PNode): bool =
|
||||||
of nkExprEqExpr, nkExprColonExpr, nkHiddenStdConv, nkHiddenSubConv:
|
of nkExprEqExpr, nkExprColonExpr, nkHiddenStdConv, nkHiddenSubConv:
|
||||||
result = isDeepConstExpr(n.sons[1])
|
result = isDeepConstExpr(n.sons[1])
|
||||||
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure, nkRange:
|
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure, nkRange:
|
||||||
for i in ord(n.kind == nkObjConstr) .. <n.len:
|
for i in ord(n.kind == nkObjConstr) ..< n.len:
|
||||||
if not isDeepConstExpr(n.sons[i]): return false
|
if not isDeepConstExpr(n.sons[i]): return false
|
||||||
if n.typ.isNil: result = true
|
if n.typ.isNil: result = true
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -742,7 +742,7 @@ proc equalParam(a, b: PSym): TParamsEquality =
|
||||||
proc sameConstraints(a, b: PNode): bool =
|
proc sameConstraints(a, b: PNode): bool =
|
||||||
if isNil(a) and isNil(b): return true
|
if isNil(a) and isNil(b): return true
|
||||||
internalAssert a.len == b.len
|
internalAssert a.len == b.len
|
||||||
for i in 1 .. <a.len:
|
for i in 1 ..< a.len:
|
||||||
if not exprStructuralEquivalent(a[i].sym.constraint,
|
if not exprStructuralEquivalent(a[i].sym.constraint,
|
||||||
b[i].sym.constraint):
|
b[i].sym.constraint):
|
||||||
return false
|
return false
|
||||||
|
|
@ -1509,7 +1509,7 @@ proc isCompileTimeOnly*(t: PType): bool {.inline.} =
|
||||||
proc containsCompileTimeOnly*(t: PType): bool =
|
proc containsCompileTimeOnly*(t: PType): bool =
|
||||||
if isCompileTimeOnly(t): return true
|
if isCompileTimeOnly(t): return true
|
||||||
if t.sons != nil:
|
if t.sons != nil:
|
||||||
for i in 0 .. <t.sonsLen:
|
for i in 0 ..< t.sonsLen:
|
||||||
if t.sons[i] != nil and isCompileTimeOnly(t.sons[i]):
|
if t.sons[i] != nil and isCompileTimeOnly(t.sons[i]):
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ proc renderPlainSymbolName*(n: PNode): string =
|
||||||
result = ""
|
result = ""
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkPostfix, nkAccQuoted:
|
of nkPostfix, nkAccQuoted:
|
||||||
result = renderPlainSymbolName(n[<n.len])
|
result = renderPlainSymbolName(n[n.len-1])
|
||||||
of nkIdent:
|
of nkIdent:
|
||||||
result = n.ident.s
|
result = n.ident.s
|
||||||
of nkSym:
|
of nkSym:
|
||||||
|
|
@ -58,8 +58,8 @@ proc renderType(n: PNode): string =
|
||||||
assert params.kind == nkFormalParams
|
assert params.kind == nkFormalParams
|
||||||
assert len(params) > 0
|
assert len(params) > 0
|
||||||
result = "proc("
|
result = "proc("
|
||||||
for i in 1 .. <len(params): result.add(renderType(params[i]) & ',')
|
for i in 1 ..< len(params): result.add(renderType(params[i]) & ',')
|
||||||
result[<len(result)] = ')'
|
result[len(result)-1] = ')'
|
||||||
else:
|
else:
|
||||||
result = "proc"
|
result = "proc"
|
||||||
of nkIdentDefs:
|
of nkIdentDefs:
|
||||||
|
|
@ -67,18 +67,18 @@ proc renderType(n: PNode): string =
|
||||||
let typePos = len(n) - 2
|
let typePos = len(n) - 2
|
||||||
let typeStr = renderType(n[typePos])
|
let typeStr = renderType(n[typePos])
|
||||||
result = typeStr
|
result = typeStr
|
||||||
for i in 1 .. <typePos:
|
for i in 1 ..< typePos:
|
||||||
assert n[i].kind == nkIdent
|
assert n[i].kind == nkIdent
|
||||||
result.add(',' & typeStr)
|
result.add(',' & typeStr)
|
||||||
of nkTupleTy:
|
of nkTupleTy:
|
||||||
result = "tuple["
|
result = "tuple["
|
||||||
for i in 0 .. <len(n): result.add(renderType(n[i]) & ',')
|
for i in 0 ..< len(n): result.add(renderType(n[i]) & ',')
|
||||||
result[<len(result)] = ']'
|
result[len(result)-1] = ']'
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
assert len(n) >= 2
|
assert len(n) >= 2
|
||||||
result = renderType(n[0]) & '['
|
result = renderType(n[0]) & '['
|
||||||
for i in 1 .. <len(n): result.add(renderType(n[i]) & ',')
|
for i in 1 ..< len(n): result.add(renderType(n[i]) & ',')
|
||||||
result[<len(result)] = ']'
|
result[len(result)-1] = ']'
|
||||||
else: result = ""
|
else: result = ""
|
||||||
assert(not result.isNil)
|
assert(not result.isNil)
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ proc renderParamTypes(found: var seq[string], n: PNode) =
|
||||||
## generator does include the information.
|
## generator does include the information.
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkFormalParams:
|
of nkFormalParams:
|
||||||
for i in 1 .. <len(n): renderParamTypes(found, n[i])
|
for i in 1 ..< len(n): renderParamTypes(found, n[i])
|
||||||
of nkIdentDefs:
|
of nkIdentDefs:
|
||||||
# These are parameter names + type + default value node.
|
# These are parameter names + type + default value node.
|
||||||
let typePos = len(n) - 2
|
let typePos = len(n) - 2
|
||||||
|
|
@ -102,7 +102,7 @@ proc renderParamTypes(found: var seq[string], n: PNode) =
|
||||||
let typ = n[typePos+1].typ
|
let typ = n[typePos+1].typ
|
||||||
if not typ.isNil: typeStr = typeToString(typ, preferExported)
|
if not typ.isNil: typeStr = typeToString(typ, preferExported)
|
||||||
if typeStr.len < 1: return
|
if typeStr.len < 1: return
|
||||||
for i in 0 .. <typePos:
|
for i in 0 ..< typePos:
|
||||||
found.add(typeStr)
|
found.add(typeStr)
|
||||||
else:
|
else:
|
||||||
internalError(n.info, "renderParamTypes(found,n) with " & $n.kind)
|
internalError(n.info, "renderParamTypes(found,n) with " & $n.kind)
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool =
|
||||||
if x <% n.len and (let f = n.sons[x].sym; f.position == x):
|
if x <% n.len and (let f = n.sons[x].sym; f.position == x):
|
||||||
dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal
|
dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal
|
||||||
else:
|
else:
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
if n.sons[i].kind != nkSym: internalError("opConv for enum")
|
if n.sons[i].kind != nkSym: internalError("opConv for enum")
|
||||||
let f = n.sons[i].sym
|
let f = n.sons[i].sym
|
||||||
if f.position == x:
|
if f.position == x:
|
||||||
|
|
@ -431,7 +431,7 @@ proc setLenSeq(c: PCtx; node: PNode; newLen: int; info: TLineInfo) =
|
||||||
setLen(node.sons, newLen)
|
setLen(node.sons, newLen)
|
||||||
if oldLen < newLen:
|
if oldLen < newLen:
|
||||||
# TODO: This is still not correct for tyPtr, tyRef default value
|
# TODO: This is still not correct for tyPtr, tyRef default value
|
||||||
for i in oldLen .. <newLen:
|
for i in oldLen ..< newLen:
|
||||||
node.sons[i] = newNodeI(typeKind, info)
|
node.sons[i] = newNodeI(typeKind, info)
|
||||||
|
|
||||||
proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
|
|
@ -1078,7 +1078,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
regs[ra].node = newNodeI(nkBracket, c.debug[pc])
|
regs[ra].node = newNodeI(nkBracket, c.debug[pc])
|
||||||
regs[ra].node.typ = typ
|
regs[ra].node.typ = typ
|
||||||
newSeq(regs[ra].node.sons, count)
|
newSeq(regs[ra].node.sons, count)
|
||||||
for i in 0 .. <count:
|
for i in 0 ..< count:
|
||||||
regs[ra].node.sons[i] = getNullValue(typ.sons[0], c.debug[pc])
|
regs[ra].node.sons[i] = getNullValue(typ.sons[0], c.debug[pc])
|
||||||
of opcNewStr:
|
of opcNewStr:
|
||||||
decodeB(rkNode)
|
decodeB(rkNode)
|
||||||
|
|
@ -1213,7 +1213,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
var u = regs[rb].node
|
var u = regs[rb].node
|
||||||
if u.kind notin {nkEmpty..nkNilLit}:
|
if u.kind notin {nkEmpty..nkNilLit}:
|
||||||
# XXX can be optimized:
|
# XXX can be optimized:
|
||||||
for i in 0.. <x.len: u.add(x.sons[i])
|
for i in 0..<x.len: u.add(x.sons[i])
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, errGenerated, "cannot add to node kind: " & $u.kind)
|
stackTrace(c, tos, pc, errGenerated, "cannot add to node kind: " & $u.kind)
|
||||||
regs[ra].node = u
|
regs[ra].node = u
|
||||||
|
|
@ -1555,7 +1555,7 @@ proc execProc*(c: PCtx; sym: PSym; args: openArray[PNode]): PNode =
|
||||||
if not isEmptyType(sym.typ.sons[0]) or sym.kind == skMacro:
|
if not isEmptyType(sym.typ.sons[0]) or sym.kind == skMacro:
|
||||||
putIntoReg(tos.slots[0], getNullValue(sym.typ.sons[0], sym.info))
|
putIntoReg(tos.slots[0], getNullValue(sym.typ.sons[0], sym.info))
|
||||||
# XXX We could perform some type checking here.
|
# XXX We could perform some type checking here.
|
||||||
for i in 1.. <sym.typ.len:
|
for i in 1..<sym.typ.len:
|
||||||
putIntoReg(tos.slots[i], args[i-1])
|
putIntoReg(tos.slots[i], args[i-1])
|
||||||
|
|
||||||
result = rawExecute(c, start, tos).regToNode
|
result = rawExecute(c, start, tos).regToNode
|
||||||
|
|
@ -1637,7 +1637,7 @@ proc evalConstExprAux(module: PSym; cache: IdentCache; prc: PSym, n: PNode,
|
||||||
when debugEchoCode: c.echoCode start
|
when debugEchoCode: c.echoCode start
|
||||||
var tos = PStackFrame(prc: prc, comesFrom: 0, next: nil)
|
var tos = PStackFrame(prc: prc, comesFrom: 0, next: nil)
|
||||||
newSeq(tos.slots, c.prc.maxSlots)
|
newSeq(tos.slots, c.prc.maxSlots)
|
||||||
#for i in 0 .. <c.prc.maxSlots: tos.slots[i] = newNode(nkEmpty)
|
#for i in 0 ..< c.prc.maxSlots: tos.slots[i] = newNode(nkEmpty)
|
||||||
result = rawExecute(c, start, tos).regToNode
|
result = rawExecute(c, start, tos).regToNode
|
||||||
if result.info.line < 0: result.info = n.info
|
if result.info.line < 0: result.info = n.info
|
||||||
|
|
||||||
|
|
@ -1670,7 +1670,7 @@ proc setupMacroParam(x: PNode, typ: PType): TFullReg =
|
||||||
|
|
||||||
iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
|
iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
|
||||||
let gp = macroSym.ast[genericParamsPos]
|
let gp = macroSym.ast[genericParamsPos]
|
||||||
for i in 0 .. <gp.len:
|
for i in 0 ..< gp.len:
|
||||||
let genericParam = gp[i].sym
|
let genericParam = gp[i].sym
|
||||||
let posInCall = macroSym.typ.len + i
|
let posInCall = macroSym.typ.len + i
|
||||||
yield (genericParam, call[posInCall])
|
yield (genericParam, call[posInCall])
|
||||||
|
|
@ -1688,8 +1688,7 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
|
||||||
# arity here too:
|
# arity here too:
|
||||||
if sym.typ.len > n.safeLen and sym.typ.len > 1:
|
if sym.typ.len > n.safeLen and sym.typ.len > 1:
|
||||||
globalError(n.info, "in call '$#' got $#, but expected $# argument(s)" % [
|
globalError(n.info, "in call '$#' got $#, but expected $# argument(s)" % [
|
||||||
n.renderTree,
|
n.renderTree, $(n.safeLen-1), $(sym.typ.len-1)])
|
||||||
$ <n.safeLen, $ <sym.typ.len])
|
|
||||||
|
|
||||||
setupGlobalCtx(module, cache)
|
setupGlobalCtx(module, cache)
|
||||||
var c = globalCtx
|
var c = globalCtx
|
||||||
|
|
@ -1713,11 +1712,11 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
|
||||||
tos.slots[0].node = newNodeI(nkEmpty, n.info)
|
tos.slots[0].node = newNodeI(nkEmpty, n.info)
|
||||||
|
|
||||||
# setup parameters:
|
# setup parameters:
|
||||||
for i in 1.. <sym.typ.len:
|
for i in 1..<sym.typ.len:
|
||||||
tos.slots[i] = setupMacroParam(n.sons[i], sym.typ.sons[i])
|
tos.slots[i] = setupMacroParam(n.sons[i], sym.typ.sons[i])
|
||||||
|
|
||||||
let gp = sym.ast[genericParamsPos]
|
let gp = sym.ast[genericParamsPos]
|
||||||
for i in 0 .. <gp.len:
|
for i in 0 ..< gp.len:
|
||||||
if sfImmediate notin sym.flags:
|
if sfImmediate notin sym.flags:
|
||||||
let idx = sym.typ.len + i
|
let idx = sym.typ.len + i
|
||||||
if idx < n.len:
|
if idx < n.len:
|
||||||
|
|
@ -1732,7 +1731,7 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
|
||||||
c.callsite = nil
|
c.callsite = nil
|
||||||
globalError(n.info, "static[T] or typedesc nor supported for .immediate macros")
|
globalError(n.info, "static[T] or typedesc nor supported for .immediate macros")
|
||||||
# temporary storage:
|
# temporary storage:
|
||||||
#for i in L .. <maxSlots: tos.slots[i] = newNode(nkEmpty)
|
#for i in L ..< maxSlots: tos.slots[i] = newNode(nkEmpty)
|
||||||
result = rawExecute(c, start, tos).regToNode
|
result = rawExecute(c, start, tos).regToNode
|
||||||
if result.info.line < 0: result.info = n.info
|
if result.info.line < 0: result.info = n.info
|
||||||
if cyclicTree(result): globalError(n.info, errCyclicTree)
|
if cyclicTree(result): globalError(n.info, errCyclicTree)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ proc mapTypeToBracketX(name: string; m: TMagic; t: PType; info: TLineInfo;
|
||||||
inst=false): PNode =
|
inst=false): PNode =
|
||||||
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
||||||
result.add atomicTypeX(name, m, t, info)
|
result.add atomicTypeX(name, m, t, info)
|
||||||
for i in 0 .. < t.len:
|
for i in 0 ..< t.len:
|
||||||
if t.sons[i] == nil:
|
if t.sons[i] == nil:
|
||||||
let void = atomicTypeX("void", mVoid, t, info)
|
let void = atomicTypeX("void", mVoid, t, info)
|
||||||
void.typ = newType(tyVoid, t.owner)
|
void.typ = newType(tyVoid, t.owner)
|
||||||
|
|
@ -119,7 +119,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
result = atomicType("typeDesc", mTypeDesc)
|
result = atomicType("typeDesc", mTypeDesc)
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
||||||
for i in 0 .. < t.len:
|
for i in 0 ..< t.len:
|
||||||
result.add mapTypeToAst(t.sons[i], info)
|
result.add mapTypeToAst(t.sons[i], info)
|
||||||
of tyGenericInst, tyAlias:
|
of tyGenericInst, tyAlias:
|
||||||
if inst:
|
if inst:
|
||||||
|
|
@ -128,7 +128,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
else:
|
else:
|
||||||
result = newNodeX(nkBracketExpr)
|
result = newNodeX(nkBracketExpr)
|
||||||
result.add mapTypeToAst(t.lastSon, info)
|
result.add mapTypeToAst(t.lastSon, info)
|
||||||
for i in 1 .. < t.len-1:
|
for i in 1 ..< t.len-1:
|
||||||
result.add mapTypeToAst(t.sons[i], info)
|
result.add mapTypeToAst(t.sons[i], info)
|
||||||
else:
|
else:
|
||||||
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
||||||
|
|
|
||||||
|
|
@ -401,7 +401,7 @@ proc sameConstant*(a, b: PNode): bool =
|
||||||
|
|
||||||
proc genLiteral(c: PCtx; n: PNode): int =
|
proc genLiteral(c: PCtx; n: PNode): int =
|
||||||
# types do not matter here:
|
# types do not matter here:
|
||||||
for i in 0 .. <c.constants.len:
|
for i in 0 ..< c.constants.len:
|
||||||
if sameConstant(c.constants[i], n): return i
|
if sameConstant(c.constants[i], n): return i
|
||||||
result = rawGenLiteral(c, n)
|
result = rawGenLiteral(c, n)
|
||||||
|
|
||||||
|
|
@ -430,7 +430,7 @@ proc genCase(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
c.gen(n.sons[0], tmp)
|
c.gen(n.sons[0], tmp)
|
||||||
# branch tmp, codeIdx
|
# branch tmp, codeIdx
|
||||||
# fjmp elseLabel
|
# fjmp elseLabel
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.len == 1:
|
if it.len == 1:
|
||||||
# else stmt:
|
# else stmt:
|
||||||
|
|
@ -460,7 +460,7 @@ proc genTry(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
c.gen(n.sons[0], dest)
|
c.gen(n.sons[0], dest)
|
||||||
c.clearDest(n, dest)
|
c.clearDest(n, dest)
|
||||||
c.patch(elsePos)
|
c.patch(elsePos)
|
||||||
for i in 1 .. <n.len:
|
for i in 1 ..< n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.kind != nkFinally:
|
if it.kind != nkFinally:
|
||||||
var blen = len(it)
|
var blen = len(it)
|
||||||
|
|
@ -518,7 +518,7 @@ proc genCall(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
let x = c.getTempRange(n.len, slotTempUnknown)
|
let x = c.getTempRange(n.len, slotTempUnknown)
|
||||||
# varargs need 'opcSetType' for the FFI support:
|
# varargs need 'opcSetType' for the FFI support:
|
||||||
let fntyp = skipTypes(n.sons[0].typ, abstractInst)
|
let fntyp = skipTypes(n.sons[0].typ, abstractInst)
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
#if i > 0 and i < sonsLen(fntyp):
|
#if i > 0 and i < sonsLen(fntyp):
|
||||||
# let paramType = fntyp.n.sons[i]
|
# let paramType = fntyp.n.sons[i]
|
||||||
# if paramType.typ.isCompileTimeOnly: continue
|
# if paramType.typ.isCompileTimeOnly: continue
|
||||||
|
|
@ -995,7 +995,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
let n = n[1].skipConv
|
let n = n[1].skipConv
|
||||||
let x = c.getTempRange(n.len, slotTempUnknown)
|
let x = c.getTempRange(n.len, slotTempUnknown)
|
||||||
internalAssert n.kind == nkBracket
|
internalAssert n.kind == nkBracket
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
var r: TRegister = x+i
|
var r: TRegister = x+i
|
||||||
c.gen(n.sons[i], r)
|
c.gen(n.sons[i], r)
|
||||||
c.gABC(n, opcEcho, x, n.len)
|
c.gABC(n, opcEcho, x, n.len)
|
||||||
|
|
@ -1645,7 +1645,7 @@ proc genObjConstr(c: PCtx, n: PNode, dest: var TDest) =
|
||||||
c.gABx(n, opcNew, dest, c.genType(t.sons[0]))
|
c.gABx(n, opcNew, dest, c.genType(t.sons[0]))
|
||||||
else:
|
else:
|
||||||
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
|
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
|
||||||
for i in 1.. <n.len:
|
for i in 1..<n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.kind == nkExprColonExpr and it.sons[0].kind == nkSym:
|
if it.kind == nkExprColonExpr and it.sons[0].kind == nkSym:
|
||||||
let idx = genField(it.sons[0])
|
let idx = genField(it.sons[0])
|
||||||
|
|
@ -1660,7 +1660,7 @@ proc genTupleConstr(c: PCtx, n: PNode, dest: var TDest) =
|
||||||
if dest < 0: dest = c.getTemp(n.typ)
|
if dest < 0: dest = c.getTemp(n.typ)
|
||||||
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
|
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
|
||||||
# XXX x = (x.old, 22) produces wrong code ... stupid self assignments
|
# XXX x = (x.old, 22) produces wrong code ... stupid self assignments
|
||||||
for i in 0.. <n.len:
|
for i in 0..<n.len:
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.kind == nkExprColonExpr:
|
if it.kind == nkExprColonExpr:
|
||||||
let idx = genField(it.sons[0])
|
let idx = genField(it.sons[0])
|
||||||
|
|
@ -1796,7 +1796,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
|
||||||
for x in n: gen(c, x)
|
for x in n: gen(c, x)
|
||||||
of nkStmtListExpr:
|
of nkStmtListExpr:
|
||||||
let L = n.len-1
|
let L = n.len-1
|
||||||
for i in 0 .. <L: gen(c, n.sons[i])
|
for i in 0 ..< L: gen(c, n.sons[i])
|
||||||
gen(c, n.sons[L], dest, flags)
|
gen(c, n.sons[L], dest, flags)
|
||||||
of nkPragmaBlock:
|
of nkPragmaBlock:
|
||||||
gen(c, n.lastSon, dest, flags)
|
gen(c, n.lastSon, dest, flags)
|
||||||
|
|
@ -1882,7 +1882,7 @@ proc genExpr*(c: PCtx; n: PNode, requiresValue = true): int =
|
||||||
proc genParams(c: PCtx; params: PNode) =
|
proc genParams(c: PCtx; params: PNode) =
|
||||||
# res.sym.position is already 0
|
# res.sym.position is already 0
|
||||||
c.prc.slots[0] = (inUse: true, kind: slotFixedVar)
|
c.prc.slots[0] = (inUse: true, kind: slotFixedVar)
|
||||||
for i in 1.. <params.len:
|
for i in 1..<params.len:
|
||||||
c.prc.slots[i] = (inUse: true, kind: slotFixedLet)
|
c.prc.slots[i] = (inUse: true, kind: slotFixedLet)
|
||||||
c.prc.maxSlots = max(params.len, 1)
|
c.prc.maxSlots = max(params.len, 1)
|
||||||
|
|
||||||
|
|
@ -1895,7 +1895,7 @@ proc finalJumpTarget(c: PCtx; pc, diff: int) =
|
||||||
|
|
||||||
proc genGenericParams(c: PCtx; gp: PNode) =
|
proc genGenericParams(c: PCtx; gp: PNode) =
|
||||||
var base = c.prc.maxSlots
|
var base = c.prc.maxSlots
|
||||||
for i in 0.. <gp.len:
|
for i in 0..<gp.len:
|
||||||
var param = gp.sons[i].sym
|
var param = gp.sons[i].sym
|
||||||
param.position = base + i # XXX: fix this earlier; make it consistent with templates
|
param.position = base + i # XXX: fix this earlier; make it consistent with templates
|
||||||
c.prc.slots[base + i] = (inUse: true, kind: slotFixedLet)
|
c.prc.slots[base + i] = (inUse: true, kind: slotFixedLet)
|
||||||
|
|
@ -1903,7 +1903,7 @@ proc genGenericParams(c: PCtx; gp: PNode) =
|
||||||
|
|
||||||
proc optimizeJumps(c: PCtx; start: int) =
|
proc optimizeJumps(c: PCtx; start: int) =
|
||||||
const maxIterations = 10
|
const maxIterations = 10
|
||||||
for i in start .. <c.code.len:
|
for i in start ..< c.code.len:
|
||||||
let opc = c.code[i].opcode
|
let opc = c.code[i].opcode
|
||||||
case opc
|
case opc
|
||||||
of opcTJmp, opcFJmp:
|
of opcTJmp, opcFJmp:
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet) =
|
||||||
s.add("]")
|
s.add("]")
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
s.add("{")
|
s.add("{")
|
||||||
for i in 0.. <t.len:
|
for i in 0..<t.len:
|
||||||
if i > 0: s.add(", ")
|
if i > 0: s.add(", ")
|
||||||
s.add("\"Field" & $i)
|
s.add("\"Field" & $i)
|
||||||
s.add("\": ")
|
s.add("\": ")
|
||||||
|
|
@ -90,7 +90,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet) =
|
||||||
s.add("}")
|
s.add("}")
|
||||||
of tySet:
|
of tySet:
|
||||||
s.add("[")
|
s.add("[")
|
||||||
for i in 0.. <a.len:
|
for i in 0..<a.len:
|
||||||
if i > 0: s.add(", ")
|
if i > 0: s.add(", ")
|
||||||
if a[i].kind == nkRange:
|
if a[i].kind == nkRange:
|
||||||
var x = copyNode(a[i][0])
|
var x = copyNode(a[i][0])
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ proc returnsNewExpr*(n: PNode): NewLocation =
|
||||||
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure,
|
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure,
|
||||||
nkIfExpr, nkIfStmt, nkWhenStmt, nkCaseStmt, nkTryStmt:
|
nkIfExpr, nkIfStmt, nkWhenStmt, nkCaseStmt, nkTryStmt:
|
||||||
result = newLit
|
result = newLit
|
||||||
for i in ord(n.kind == nkObjConstr) .. <n.len:
|
for i in ord(n.kind == nkObjConstr) ..< n.len:
|
||||||
let x = returnsNewExpr(n.sons[i])
|
let x = returnsNewExpr(n.sons[i])
|
||||||
case x
|
case x
|
||||||
of newNone: return newNone
|
of newNone: return newNone
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ proc cycle*[T](s: openArray[T], n: Natural): seq[T] =
|
||||||
## assert total == @[1, 2, 3, 1, 2, 3, 1, 2, 3]
|
## assert total == @[1, 2, 3, 1, 2, 3, 1, 2, 3]
|
||||||
result = newSeq[T](n * s.len)
|
result = newSeq[T](n * s.len)
|
||||||
var o = 0
|
var o = 0
|
||||||
for x in 0 .. <n:
|
for x in 0 ..< n:
|
||||||
for e in s:
|
for e in s:
|
||||||
result[o] = e
|
result[o] = e
|
||||||
inc o
|
inc o
|
||||||
|
|
@ -88,7 +88,7 @@ proc repeat*[T](x: T, n: Natural): seq[T] =
|
||||||
## total = repeat(5, 3)
|
## total = repeat(5, 3)
|
||||||
## assert total == @[5, 5, 5]
|
## assert total == @[5, 5, 5]
|
||||||
result = newSeq[T](n)
|
result = newSeq[T](n)
|
||||||
for i in 0 .. <n:
|
for i in 0 ..< n:
|
||||||
result[i] = x
|
result[i] = x
|
||||||
|
|
||||||
proc deduplicate*[T](s: openArray[T]): seq[T] =
|
proc deduplicate*[T](s: openArray[T]): seq[T] =
|
||||||
|
|
@ -132,7 +132,7 @@ proc zip*[S, T](s1: openArray[S], s2: openArray[T]): seq[tuple[a: S, b: T]] =
|
||||||
## assert zip2[2].b == "three"
|
## assert zip2[2].b == "three"
|
||||||
var m = min(s1.len, s2.len)
|
var m = min(s1.len, s2.len)
|
||||||
newSeq(result, m)
|
newSeq(result, m)
|
||||||
for i in 0 .. <m:
|
for i in 0 ..< m:
|
||||||
result[i] = (s1[i], s2[i])
|
result[i] = (s1[i], s2[i])
|
||||||
|
|
||||||
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
|
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
|
||||||
|
|
@ -180,22 +180,22 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
|
||||||
# Use an algorithm which overcounts the stride and minimizes reading limits.
|
# Use an algorithm which overcounts the stride and minimizes reading limits.
|
||||||
if extra > 0: inc(stride)
|
if extra > 0: inc(stride)
|
||||||
|
|
||||||
for i in 0 .. <num:
|
for i in 0 ..< num:
|
||||||
result[i] = newSeq[T]()
|
result[i] = newSeq[T]()
|
||||||
for g in first .. <min(s.len, first + stride):
|
for g in first ..< min(s.len, first + stride):
|
||||||
result[i].add(s[g])
|
result[i].add(s[g])
|
||||||
first += stride
|
first += stride
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Use an undercounting algorithm which *adds* the remainder each iteration.
|
# Use an undercounting algorithm which *adds* the remainder each iteration.
|
||||||
for i in 0 .. <num:
|
for i in 0 ..< num:
|
||||||
last = first + stride
|
last = first + stride
|
||||||
if extra > 0:
|
if extra > 0:
|
||||||
extra -= 1
|
extra -= 1
|
||||||
inc(last)
|
inc(last)
|
||||||
|
|
||||||
result[i] = newSeq[T]()
|
result[i] = newSeq[T]()
|
||||||
for g in first .. <last:
|
for g in first ..< last:
|
||||||
result[i].add(s[g])
|
result[i].add(s[g])
|
||||||
first = last
|
first = last
|
||||||
|
|
||||||
|
|
@ -215,7 +215,7 @@ proc map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
|
||||||
## b = map(a, proc(x: int): string = $x)
|
## b = map(a, proc(x: int): string = $x)
|
||||||
## assert b == @["1", "2", "3", "4"]
|
## assert b == @["1", "2", "3", "4"]
|
||||||
newSeq(result, s.len)
|
newSeq(result, s.len)
|
||||||
for i in 0 .. <s.len:
|
for i in 0 ..< s.len:
|
||||||
result[i] = op(s[i])
|
result[i] = op(s[i])
|
||||||
|
|
||||||
proc map*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
|
proc map*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
|
||||||
|
|
@ -235,7 +235,7 @@ proc map*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
|
||||||
## echo repr(a)
|
## echo repr(a)
|
||||||
## # --> ["142", "242", "342", "442"]
|
## # --> ["142", "242", "342", "442"]
|
||||||
## **Deprecated since version 0.12.0:** Use the ``apply`` proc instead.
|
## **Deprecated since version 0.12.0:** Use the ``apply`` proc instead.
|
||||||
for i in 0 .. <s.len: op(s[i])
|
for i in 0 ..< s.len: op(s[i])
|
||||||
|
|
||||||
proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
|
proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
|
||||||
{.inline.} =
|
{.inline.} =
|
||||||
|
|
@ -255,7 +255,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
|
||||||
## echo repr(a)
|
## echo repr(a)
|
||||||
## # --> ["142", "242", "342", "442"]
|
## # --> ["142", "242", "342", "442"]
|
||||||
##
|
##
|
||||||
for i in 0 .. <s.len: op(s[i])
|
for i in 0 ..< s.len: op(s[i])
|
||||||
|
|
||||||
proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
|
proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
|
||||||
{.inline.} =
|
{.inline.} =
|
||||||
|
|
@ -275,7 +275,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
|
||||||
## echo repr(a)
|
## echo repr(a)
|
||||||
## # --> ["142", "242", "342", "442"]
|
## # --> ["142", "242", "342", "442"]
|
||||||
##
|
##
|
||||||
for i in 0 .. <s.len: s[i] = op(s[i])
|
for i in 0 ..< s.len: s[i] = op(s[i])
|
||||||
|
|
||||||
iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
|
iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
|
||||||
## Iterates through a container and yields every item that fulfills the
|
## Iterates through a container and yields every item that fulfills the
|
||||||
|
|
@ -288,7 +288,7 @@ iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
|
||||||
## for n in filter(numbers, proc (x: int): bool = x mod 2 == 0):
|
## for n in filter(numbers, proc (x: int): bool = x mod 2 == 0):
|
||||||
## echo($n)
|
## echo($n)
|
||||||
## # echoes 4, 8, 4 in separate lines
|
## # echoes 4, 8, 4 in separate lines
|
||||||
for i in 0 .. <s.len:
|
for i in 0 ..< s.len:
|
||||||
if pred(s[i]):
|
if pred(s[i]):
|
||||||
yield s[i]
|
yield s[i]
|
||||||
|
|
||||||
|
|
@ -306,7 +306,7 @@ proc filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
|
||||||
## assert f1 == @["red", "black"]
|
## assert f1 == @["red", "black"]
|
||||||
## assert f2 == @["yellow"]
|
## assert f2 == @["yellow"]
|
||||||
result = newSeq[T]()
|
result = newSeq[T]()
|
||||||
for i in 0 .. <s.len:
|
for i in 0 ..< s.len:
|
||||||
if pred(s[i]):
|
if pred(s[i]):
|
||||||
result.add(s[i])
|
result.add(s[i])
|
||||||
|
|
||||||
|
|
@ -322,7 +322,7 @@ proc keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
|
||||||
## keepIf(floats, proc(x: float): bool = x > 10)
|
## keepIf(floats, proc(x: float): bool = x > 10)
|
||||||
## assert floats == @[13.0, 12.5, 10.1]
|
## assert floats == @[13.0, 12.5, 10.1]
|
||||||
var pos = 0
|
var pos = 0
|
||||||
for i in 0 .. <len(s):
|
for i in 0 ..< len(s):
|
||||||
if pred(s[i]):
|
if pred(s[i]):
|
||||||
if pos != i:
|
if pos != i:
|
||||||
shallowCopy(s[pos], s[i])
|
shallowCopy(s[pos], s[i])
|
||||||
|
|
@ -413,7 +413,7 @@ template keepItIf*(varSeq: seq, pred: untyped) =
|
||||||
## keepItIf(candidates, it.len == 3 and it[0] == 'b')
|
## keepItIf(candidates, it.len == 3 and it[0] == 'b')
|
||||||
## assert candidates == @["bar", "baz"]
|
## assert candidates == @["bar", "baz"]
|
||||||
var pos = 0
|
var pos = 0
|
||||||
for i in 0 .. <len(varSeq):
|
for i in 0 ..< len(varSeq):
|
||||||
let it {.inject.} = varSeq[i]
|
let it {.inject.} = varSeq[i]
|
||||||
if pred:
|
if pred:
|
||||||
if pos != i:
|
if pos != i:
|
||||||
|
|
@ -680,7 +680,7 @@ template applyIt*(varSeq, op: untyped) =
|
||||||
## var nums = @[1, 2, 3, 4]
|
## var nums = @[1, 2, 3, 4]
|
||||||
## nums.applyIt(it * 3)
|
## nums.applyIt(it * 3)
|
||||||
## assert nums[0] + nums[3] == 15
|
## assert nums[0] + nums[3] == 15
|
||||||
for i in 0 .. <varSeq.len:
|
for i in 0 ..< varSeq.len:
|
||||||
let it {.inject.} = varSeq[i]
|
let it {.inject.} = varSeq[i]
|
||||||
varSeq[i] = op
|
varSeq[i] = op
|
||||||
|
|
||||||
|
|
@ -700,7 +700,7 @@ template newSeqWith*(len: int, init: untyped): untyped =
|
||||||
## var seqRand = newSeqWith(20, random(10))
|
## var seqRand = newSeqWith(20, random(10))
|
||||||
## echo seqRand
|
## echo seqRand
|
||||||
var result = newSeq[type(init)](len)
|
var result = newSeq[type(init)](len)
|
||||||
for i in 0 .. <len:
|
for i in 0 ..< len:
|
||||||
result[i] = init
|
result[i] = init
|
||||||
result
|
result
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -652,13 +652,17 @@ proc sizeof*[T](x: T): int {.magic: "SizeOf", noSideEffect.}
|
||||||
when defined(nimtypedescfixed):
|
when defined(nimtypedescfixed):
|
||||||
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
|
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
|
||||||
|
|
||||||
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect.}
|
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect, deprecated.}
|
||||||
## unary ``<`` that can be used for nice looking excluding ranges:
|
## unary ``<`` that can be used for nice looking excluding ranges:
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## for i in 0 .. <10: echo i #=> 0 1 2 3 4 5 6 7 8 9
|
## for i in 0 .. <10: echo i #=> 0 1 2 3 4 5 6 7 8 9
|
||||||
##
|
##
|
||||||
## Semantically this is the same as ``pred``.
|
## Semantically this is the same as ``pred``.
|
||||||
|
##
|
||||||
|
## **Deprecated since version 0.18.0**. For the common excluding range
|
||||||
|
## write ``0 ..< 10`` instead of ``0 .. < 10`` (look at the spacing).
|
||||||
|
## For ``<x`` write ``pred(x)``.
|
||||||
|
|
||||||
proc succ*[T](x: Ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.}
|
proc succ*[T](x: Ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.}
|
||||||
## returns the ``y``-th successor of the value ``x``. ``T`` has to be
|
## returns the ``y``-th successor of the value ``x``. ``T`` has to be
|
||||||
|
|
@ -3410,6 +3414,30 @@ proc `/`*(x, y: int): float {.inline, noSideEffect.} =
|
||||||
## integer division that results in a float.
|
## integer division that results in a float.
|
||||||
result = toFloat(x) / toFloat(y)
|
result = toFloat(x) / toFloat(y)
|
||||||
|
|
||||||
|
proc `^`*[T](x: int; y: openArray[T]): int {.noSideEffect, magic: "Roof".}
|
||||||
|
proc `^`*(x: int): int {.noSideEffect, magic: "Roof".} =
|
||||||
|
## builtin `roof`:idx: operator that can be used for convenient array access.
|
||||||
|
## ``a[^x]`` is rewritten to ``a[a.len-x]``. However currently the ``a``
|
||||||
|
## expression must not have side effects for this to compile. Note that since
|
||||||
|
## this is a builtin, it automatically works for all kinds of
|
||||||
|
## overloaded ``[]`` or ``[]=`` accessors.
|
||||||
|
discard
|
||||||
|
|
||||||
|
template `..^`*(a, b: untyped): untyped =
|
||||||
|
## a shortcut for '.. ^' to avoid the common gotcha that a space between
|
||||||
|
## '..' and '^' is required.
|
||||||
|
a .. ^b
|
||||||
|
|
||||||
|
template `..<`*(a, b: untyped): untyped {.dirty.} =
|
||||||
|
## a shortcut for 'a..pred(b)'.
|
||||||
|
a .. pred(b)
|
||||||
|
|
||||||
|
iterator `..<`*[S,T](a: S, b: T): T =
|
||||||
|
var i = T(a)
|
||||||
|
while i < b:
|
||||||
|
yield i
|
||||||
|
inc i
|
||||||
|
|
||||||
template spliceImpl(s, a, L, b: untyped): untyped =
|
template spliceImpl(s, a, L, b: untyped): untyped =
|
||||||
# make room for additional elements or cut:
|
# make room for additional elements or cut:
|
||||||
var shift = b.len - max(0,L) # ignore negative slice size
|
var shift = b.len - max(0,L) # ignore negative slice size
|
||||||
|
|
@ -3423,7 +3451,7 @@ template spliceImpl(s, a, L, b: untyped): untyped =
|
||||||
# cut down:
|
# cut down:
|
||||||
setLen(s, newLen)
|
setLen(s, newLen)
|
||||||
# fill the hole:
|
# fill the hole:
|
||||||
for i in 0 .. <b.len: s[a+i] = b[i]
|
for i in 0 ..< b.len: s[a+i] = b[i]
|
||||||
|
|
||||||
when hasAlloc or defined(nimscript):
|
when hasAlloc or defined(nimscript):
|
||||||
proc `[]`*(s: string, x: Slice[int]): string {.inline.} =
|
proc `[]`*(s: string, x: Slice[int]): string {.inline.} =
|
||||||
|
|
@ -3447,7 +3475,7 @@ when hasAlloc or defined(nimscript):
|
||||||
var a = x.a
|
var a = x.a
|
||||||
var L = x.b - a + 1
|
var L = x.b - a + 1
|
||||||
if L == b.len:
|
if L == b.len:
|
||||||
for i in 0 .. <L: s[i+a] = b[i]
|
for i in 0..<L: s[i+a] = b[i]
|
||||||
else:
|
else:
|
||||||
spliceImpl(s, a, L, b)
|
spliceImpl(s, a, L, b)
|
||||||
|
|
||||||
|
|
@ -3462,7 +3490,7 @@ proc `[]`*[Idx, T](a: array[Idx, T], x: Slice[int]): seq[T] =
|
||||||
{.error: "Slicing for arrays with negative indices is unsupported.".}
|
{.error: "Slicing for arrays with negative indices is unsupported.".}
|
||||||
var L = x.b - x.a + 1
|
var L = x.b - x.a + 1
|
||||||
result = newSeq[T](L)
|
result = newSeq[T](L)
|
||||||
for i in 0.. <L: result[i] = a[i + x.a]
|
for i in 0..<L: result[i] = a[i + x.a]
|
||||||
|
|
||||||
proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[int], b: openArray[T]) =
|
proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[int], b: openArray[T]) =
|
||||||
## slice assignment for arrays.
|
## slice assignment for arrays.
|
||||||
|
|
@ -3470,7 +3498,7 @@ proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[int], b: openArray[T]) =
|
||||||
{.error: "Slicing for arrays with negative indices is unsupported.".}
|
{.error: "Slicing for arrays with negative indices is unsupported.".}
|
||||||
var L = x.b - x.a + 1
|
var L = x.b - x.a + 1
|
||||||
if L == b.len:
|
if L == b.len:
|
||||||
for i in 0 .. <L: a[i+x.a] = b[i]
|
for i in 0..<L: a[i+x.a] = b[i]
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeError, "different lengths for slice assignment")
|
sysFatal(RangeError, "different lengths for slice assignment")
|
||||||
|
|
||||||
|
|
@ -3478,14 +3506,14 @@ proc `[]`*[Idx, T](a: array[Idx, T], x: Slice[Idx]): seq[T] =
|
||||||
## slice operation for arrays.
|
## slice operation for arrays.
|
||||||
var L = ord(x.b) - ord(x.a) + 1
|
var L = ord(x.b) - ord(x.a) + 1
|
||||||
newSeq(result, L)
|
newSeq(result, L)
|
||||||
for i in 0.. <L:
|
for i in 0..<L:
|
||||||
result[i] = a[Idx(ord(x.a) + i)]
|
result[i] = a[Idx(ord(x.a) + i)]
|
||||||
|
|
||||||
proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[Idx], b: openArray[T]) =
|
proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[Idx], b: openArray[T]) =
|
||||||
## slice assignment for arrays.
|
## slice assignment for arrays.
|
||||||
var L = ord(x.b) - ord(x.a) + 1
|
var L = ord(x.b) - ord(x.a) + 1
|
||||||
if L == b.len:
|
if L == b.len:
|
||||||
for i in 0 .. <L:
|
for i in 0..<L:
|
||||||
a[Idx(ord(x.a) + i)] = b[i]
|
a[Idx(ord(x.a) + i)] = b[i]
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeError, "different lengths for slice assignment")
|
sysFatal(RangeError, "different lengths for slice assignment")
|
||||||
|
|
@ -3500,7 +3528,7 @@ proc `[]`*[T](s: seq[T], x: Slice[int]): seq[T] =
|
||||||
var a = x.a
|
var a = x.a
|
||||||
var L = x.b - a + 1
|
var L = x.b - a + 1
|
||||||
newSeq(result, L)
|
newSeq(result, L)
|
||||||
for i in 0.. <L: result[i] = s[i + a]
|
for i in 0 ..< L: result[i] = s[i + a]
|
||||||
|
|
||||||
proc `[]=`*[T](s: var seq[T], x: Slice[int], b: openArray[T]) =
|
proc `[]=`*[T](s: var seq[T], x: Slice[int], b: openArray[T]) =
|
||||||
## slice assignment for sequences. If
|
## slice assignment for sequences. If
|
||||||
|
|
@ -3509,7 +3537,7 @@ proc `[]=`*[T](s: var seq[T], x: Slice[int], b: openArray[T]) =
|
||||||
var a = x.a
|
var a = x.a
|
||||||
var L = x.b - a + 1
|
var L = x.b - a + 1
|
||||||
if L == b.len:
|
if L == b.len:
|
||||||
for i in 0 .. <L: s[i+a] = b[i]
|
for i in 0 ..< L: s[i+a] = b[i]
|
||||||
else:
|
else:
|
||||||
spliceImpl(s, a, L, b)
|
spliceImpl(s, a, L, b)
|
||||||
|
|
||||||
|
|
@ -3853,31 +3881,6 @@ proc procCall*(x: untyped) {.magic: "ProcCall", compileTime.} =
|
||||||
## procCall someMethod(a, b)
|
## procCall someMethod(a, b)
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc `^`*[T](x: int; y: openArray[T]): int {.noSideEffect, magic: "Roof".}
|
|
||||||
proc `^`*(x: int): int {.noSideEffect, magic: "Roof".} =
|
|
||||||
## builtin `roof`:idx: operator that can be used for convenient array access.
|
|
||||||
## ``a[^x]`` is rewritten to ``a[a.len-x]``. However currently the ``a``
|
|
||||||
## expression must not have side effects for this to compile. Note that since
|
|
||||||
## this is a builtin, it automatically works for all kinds of
|
|
||||||
## overloaded ``[]`` or ``[]=`` accessors.
|
|
||||||
discard
|
|
||||||
|
|
||||||
template `..^`*(a, b: untyped): untyped =
|
|
||||||
## a shortcut for '.. ^' to avoid the common gotcha that a space between
|
|
||||||
## '..' and '^' is required.
|
|
||||||
a .. ^b
|
|
||||||
|
|
||||||
template `..<`*(a, b: untyped): untyped {.dirty.} =
|
|
||||||
## a shortcut for '.. <' to avoid the common gotcha that a space between
|
|
||||||
## '..' and '<' is required.
|
|
||||||
a .. <b
|
|
||||||
|
|
||||||
iterator `..<`*[S,T](a: S, b: T): T =
|
|
||||||
var i = T(a)
|
|
||||||
while i < b:
|
|
||||||
yield i
|
|
||||||
inc i
|
|
||||||
|
|
||||||
proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard
|
proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard
|
||||||
proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} =
|
proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} =
|
||||||
## returns the length of a sequence or a string without testing for 'nil'.
|
## returns the length of a sequence or a string without testing for 'nil'.
|
||||||
|
|
|
||||||
3
todo.txt
3
todo.txt
|
|
@ -3,7 +3,6 @@ version 1.0 battle plan
|
||||||
|
|
||||||
- make nimresolve part of the Nim compiler and add support for
|
- make nimresolve part of the Nim compiler and add support for
|
||||||
'import staticExec()'
|
'import staticExec()'
|
||||||
- deprecate unary '<'
|
|
||||||
- remove 'mod x' type rule
|
- remove 'mod x' type rule
|
||||||
- implement x[^1] differently, no compiler magic
|
- implement x[^1] differently, no compiler magic
|
||||||
- fix "high priority" bugs
|
- fix "high priority" bugs
|
||||||
|
|
@ -24,8 +23,6 @@ Not critical for 1.0
|
||||||
'static[T]' mess in the compiler!
|
'static[T]' mess in the compiler!
|
||||||
- ``not`` or ``~`` for the effects system
|
- ``not`` or ``~`` for the effects system
|
||||||
- figure out why C++ bootstrapping is so much slower
|
- figure out why C++ bootstrapping is so much slower
|
||||||
- The bitwise 'not' operator cold be renamed to 'bnot' to
|
|
||||||
prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs!
|
|
||||||
- make 'nil' work for 'add':
|
- make 'nil' work for 'add':
|
||||||
- resizeString
|
- resizeString
|
||||||
- incrSeq
|
- incrSeq
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue