Merge pull request #4592 from arnetheduck/compiler-cleanup
Compiler cleanup
This commit is contained in:
commit
10f445da89
27 changed files with 12 additions and 464 deletions
|
|
@ -726,9 +726,6 @@ type
|
||||||
flags*: TLocFlags # location's flags
|
flags*: TLocFlags # location's flags
|
||||||
t*: PType # type of location
|
t*: PType # type of location
|
||||||
r*: Rope # rope value of location (code generators)
|
r*: Rope # rope value of location (code generators)
|
||||||
heapRoot*: Rope # keeps track of the enclosing heap object that
|
|
||||||
# owns this location (required by GC algorithms
|
|
||||||
# employing heap snapshots or sliding views)
|
|
||||||
|
|
||||||
# ---------------- end of backend information ------------------------------
|
# ---------------- end of backend information ------------------------------
|
||||||
|
|
||||||
|
|
@ -862,9 +859,6 @@ type
|
||||||
key*, val*: RootRef
|
key*, val*: RootRef
|
||||||
|
|
||||||
TPairSeq* = seq[TPair]
|
TPairSeq* = seq[TPair]
|
||||||
TTable* = object # the same as table[PObject] of PObject
|
|
||||||
counter*: int
|
|
||||||
data*: TPairSeq
|
|
||||||
|
|
||||||
TIdPair* = object
|
TIdPair* = object
|
||||||
key*: PIdObj
|
key*: PIdObj
|
||||||
|
|
@ -1108,12 +1102,6 @@ proc copyIdTable*(dest: var TIdTable, src: TIdTable) =
|
||||||
newSeq(dest.data, len(src.data))
|
newSeq(dest.data, len(src.data))
|
||||||
for i in countup(0, high(src.data)): dest.data[i] = src.data[i]
|
for i in countup(0, high(src.data)): dest.data[i] = src.data[i]
|
||||||
|
|
||||||
proc copyTable*(dest: var TTable, src: TTable) =
|
|
||||||
dest.counter = src.counter
|
|
||||||
if isNil(src.data): return
|
|
||||||
setLen(dest.data, len(src.data))
|
|
||||||
for i in countup(0, high(src.data)): dest.data[i] = src.data[i]
|
|
||||||
|
|
||||||
proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) =
|
proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) =
|
||||||
dest.counter = src.counter
|
dest.counter = src.counter
|
||||||
if isNil(src.data): return
|
if isNil(src.data): return
|
||||||
|
|
@ -1327,10 +1315,6 @@ proc initStrTable*(x: var TStrTable) =
|
||||||
proc newStrTable*: TStrTable =
|
proc newStrTable*: TStrTable =
|
||||||
initStrTable(result)
|
initStrTable(result)
|
||||||
|
|
||||||
proc initTable(x: var TTable) =
|
|
||||||
x.counter = 0
|
|
||||||
newSeq(x.data, StartSize)
|
|
||||||
|
|
||||||
proc initIdTable*(x: var TIdTable) =
|
proc initIdTable*(x: var TIdTable) =
|
||||||
x.counter = 0
|
x.counter = 0
|
||||||
newSeq(x.data, StartSize)
|
newSeq(x.data, StartSize)
|
||||||
|
|
@ -1511,16 +1495,6 @@ proc hasSubnodeWith*(n: PNode, kind: TNodeKind): bool =
|
||||||
return true
|
return true
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc replaceSons(n: PNode, oldKind, newKind: TNodeKind) =
|
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
|
||||||
if n.sons[i].kind == oldKind: n.sons[i].kind = newKind
|
|
||||||
|
|
||||||
proc sonsNotNil(n: PNode): bool =
|
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
|
||||||
if n.sons[i] == nil:
|
|
||||||
return false
|
|
||||||
result = true
|
|
||||||
|
|
||||||
proc getInt*(a: PNode): BiggestInt =
|
proc getInt*(a: PNode): BiggestInt =
|
||||||
case a.kind
|
case a.kind
|
||||||
of nkIntLit..nkUInt64Lit: result = a.intVal
|
of nkIntLit..nkUInt64Lit: result = a.intVal
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,6 @@ proc objectSetIncl*(t: var TObjectSet, obj: RootRef)
|
||||||
proc objectSetContainsOrIncl*(t: var TObjectSet, obj: RootRef): bool
|
proc objectSetContainsOrIncl*(t: var TObjectSet, obj: RootRef): bool
|
||||||
# more are not needed ...
|
# more are not needed ...
|
||||||
|
|
||||||
# ----------------------- (key, val)-Hashtables ----------------------------
|
|
||||||
proc tablePut*(t: var TTable, key, val: RootRef)
|
|
||||||
proc tableGet*(t: TTable, key: RootRef): RootRef
|
|
||||||
type
|
|
||||||
TCmpProc* = proc (key, closure: RootRef): bool {.nimcall.} # true if found
|
|
||||||
|
|
||||||
proc tableSearch*(t: TTable, key, closure: RootRef,
|
|
||||||
comparator: TCmpProc): RootRef
|
|
||||||
# return val as soon as comparator returns true; if this never happens,
|
|
||||||
# nil is returned
|
|
||||||
|
|
||||||
# ----------------------- str table -----------------------------------------
|
# ----------------------- str table -----------------------------------------
|
||||||
proc strTableContains*(t: TStrTable, n: PSym): bool
|
proc strTableContains*(t: TStrTable, n: PSym): bool
|
||||||
proc strTableAdd*(t: var TStrTable, n: PSym)
|
proc strTableAdd*(t: var TStrTable, n: PSym)
|
||||||
|
|
@ -251,20 +240,6 @@ proc symToYamlAux(n: PSym, marker: var IntSet,
|
||||||
indent, maxRecDepth: int): Rope
|
indent, maxRecDepth: int): Rope
|
||||||
proc typeToYamlAux(n: PType, marker: var IntSet,
|
proc typeToYamlAux(n: PType, marker: var IntSet,
|
||||||
indent, maxRecDepth: int): Rope
|
indent, maxRecDepth: int): Rope
|
||||||
proc strTableToYaml(n: TStrTable, marker: var IntSet, indent: int,
|
|
||||||
maxRecDepth: int): Rope =
|
|
||||||
var istr = rspaces(indent + 2)
|
|
||||||
result = rope("[")
|
|
||||||
var mycount = 0
|
|
||||||
for i in countup(0, high(n.data)):
|
|
||||||
if n.data[i] != nil:
|
|
||||||
if mycount > 0: add(result, ",")
|
|
||||||
addf(result, "$N$1$2",
|
|
||||||
[istr, symToYamlAux(n.data[i], marker, indent + 2, maxRecDepth - 1)])
|
|
||||||
inc(mycount)
|
|
||||||
if mycount > 0: addf(result, "$N$1", [rspaces(indent)])
|
|
||||||
add(result, "]")
|
|
||||||
assert(mycount == n.counter)
|
|
||||||
|
|
||||||
proc ropeConstr(indent: int, c: openArray[Rope]): Rope =
|
proc ropeConstr(indent: int, c: openArray[Rope]): Rope =
|
||||||
# array of (name, value) pairs
|
# array of (name, value) pairs
|
||||||
|
|
@ -463,9 +438,6 @@ proc debug(n: PType) =
|
||||||
proc debug(n: PNode) =
|
proc debug(n: PNode) =
|
||||||
echo($debugTree(n, 0, 100))
|
echo($debugTree(n, 0, 100))
|
||||||
|
|
||||||
const
|
|
||||||
EmptySeq = @[]
|
|
||||||
|
|
||||||
proc nextTry(h, maxHash: Hash): Hash =
|
proc nextTry(h, maxHash: Hash): Hash =
|
||||||
result = ((5 * h) + 1) and maxHash
|
result = ((5 * h) + 1) and maxHash
|
||||||
# For any initial h in range(maxHash), repeating that maxHash times
|
# For any initial h in range(maxHash), repeating that maxHash times
|
||||||
|
|
@ -519,55 +491,6 @@ proc objectSetContainsOrIncl(t: var TObjectSet, obj: RootRef): bool =
|
||||||
inc(t.counter)
|
inc(t.counter)
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc tableRawGet(t: TTable, key: RootRef): int =
|
|
||||||
var h: Hash = hashNode(key) and high(t.data) # start with real hash value
|
|
||||||
while t.data[h].key != nil:
|
|
||||||
if t.data[h].key == key:
|
|
||||||
return h
|
|
||||||
h = nextTry(h, high(t.data))
|
|
||||||
result = -1
|
|
||||||
|
|
||||||
proc tableSearch(t: TTable, key, closure: RootRef,
|
|
||||||
comparator: TCmpProc): RootRef =
|
|
||||||
var h: Hash = hashNode(key) and high(t.data) # start with real hash value
|
|
||||||
while t.data[h].key != nil:
|
|
||||||
if t.data[h].key == key:
|
|
||||||
if comparator(t.data[h].val, closure):
|
|
||||||
# BUGFIX 1
|
|
||||||
return t.data[h].val
|
|
||||||
h = nextTry(h, high(t.data))
|
|
||||||
result = nil
|
|
||||||
|
|
||||||
proc tableGet(t: TTable, key: RootRef): RootRef =
|
|
||||||
var index = tableRawGet(t, key)
|
|
||||||
if index >= 0: result = t.data[index].val
|
|
||||||
else: result = nil
|
|
||||||
|
|
||||||
proc tableRawInsert(data: var TPairSeq, key, val: RootRef) =
|
|
||||||
var h: Hash = hashNode(key) and high(data)
|
|
||||||
while data[h].key != nil:
|
|
||||||
assert(data[h].key != key)
|
|
||||||
h = nextTry(h, high(data))
|
|
||||||
assert(data[h].key == nil)
|
|
||||||
data[h].key = key
|
|
||||||
data[h].val = val
|
|
||||||
|
|
||||||
proc tableEnlarge(t: var TTable) =
|
|
||||||
var n: TPairSeq
|
|
||||||
newSeq(n, len(t.data) * GrowthFactor)
|
|
||||||
for i in countup(0, high(t.data)):
|
|
||||||
if t.data[i].key != nil: tableRawInsert(n, t.data[i].key, t.data[i].val)
|
|
||||||
swap(t.data, n)
|
|
||||||
|
|
||||||
proc tablePut(t: var TTable, key, val: RootRef) =
|
|
||||||
var index = tableRawGet(t, key)
|
|
||||||
if index >= 0:
|
|
||||||
t.data[index].val = val
|
|
||||||
else:
|
|
||||||
if mustRehash(len(t.data), t.counter): tableEnlarge(t)
|
|
||||||
tableRawInsert(t.data, key, val)
|
|
||||||
inc(t.counter)
|
|
||||||
|
|
||||||
proc strTableContains(t: TStrTable, n: PSym): bool =
|
proc strTableContains(t: TStrTable, n: PSym): bool =
|
||||||
var h: Hash = n.name.h and high(t.data) # start with real hash value
|
var h: Hash = n.name.h and high(t.data) # start with real hash value
|
||||||
while t.data[h] != nil:
|
while t.data[h] != nil:
|
||||||
|
|
|
||||||
|
|
@ -411,7 +411,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
|
||||||
add(result, substr(pat, start, i - 1))
|
add(result, substr(pat, start, i - 1))
|
||||||
|
|
||||||
proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
var op, a: TLoc
|
var op: TLoc
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
# getUniqueType() is too expensive here:
|
# getUniqueType() is too expensive here:
|
||||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
||||||
|
|
@ -458,7 +458,7 @@ proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
|
|
||||||
proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
# generates a crappy ObjC call
|
# generates a crappy ObjC call
|
||||||
var op, a: TLoc
|
var op: TLoc
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
var pl = ~"["
|
var pl = ~"["
|
||||||
# getUniqueType() is too expensive here:
|
# getUniqueType() is too expensive here:
|
||||||
|
|
@ -536,8 +536,6 @@ proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||||
else:
|
else:
|
||||||
genPrefixCall(p, nil, e, d)
|
genPrefixCall(p, nil, e, d)
|
||||||
postStmtActions(p)
|
postStmtActions(p)
|
||||||
when false:
|
|
||||||
if d.s == onStack and containsGarbageCollectedRef(d.t): keepAlive(p, d)
|
|
||||||
|
|
||||||
proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
if ri.sons[0].typ.skipTypes({tyGenericInst}).callConv == ccClosure:
|
if ri.sons[0].typ.skipTypes({tyGenericInst}).callConv == ccClosure:
|
||||||
|
|
@ -549,6 +547,3 @@ proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
else:
|
else:
|
||||||
genPrefixCall(p, le, ri, d)
|
genPrefixCall(p, le, ri, d)
|
||||||
postStmtActions(p)
|
postStmtActions(p)
|
||||||
when false:
|
|
||||||
if d.s == onStack and containsGarbageCollectedRef(d.t): keepAlive(p, d)
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,19 +30,6 @@ proc intLiteral(i: BiggestInt): Rope =
|
||||||
else:
|
else:
|
||||||
result = ~"(IL64(-9223372036854775807) - IL64(1))"
|
result = ~"(IL64(-9223372036854775807) - IL64(1))"
|
||||||
|
|
||||||
proc int32Literal(i: int): Rope =
|
|
||||||
if i == int(low(int32)):
|
|
||||||
result = ~"(-2147483647 -1)"
|
|
||||||
else:
|
|
||||||
result = rope(i)
|
|
||||||
|
|
||||||
proc genHexLiteral(v: PNode): Rope =
|
|
||||||
# hex literals are unsigned in C
|
|
||||||
# so we don't generate hex literals any longer.
|
|
||||||
if v.kind notin {nkIntLit..nkUInt64Lit}:
|
|
||||||
internalError(v.info, "genHexLiteral")
|
|
||||||
result = intLiteral(v.intVal)
|
|
||||||
|
|
||||||
proc getStrLit(m: BModule, s: string): Rope =
|
proc getStrLit(m: BModule, s: string): Rope =
|
||||||
discard cgsym(m, "TGenericSeq")
|
discard cgsym(m, "TGenericSeq")
|
||||||
result = getTempName(m)
|
result = getTempName(m)
|
||||||
|
|
@ -171,7 +158,6 @@ proc getStorageLoc(n: PNode): TStorageLoc =
|
||||||
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if dest.s == OnStack or not usesNativeGC():
|
if dest.s == OnStack or not usesNativeGC():
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
|
||||||
elif dest.s == OnHeap:
|
elif dest.s == OnHeap:
|
||||||
# location is on heap
|
# location is on heap
|
||||||
# now the writer barrier is inlined for performance:
|
# now the writer barrier is inlined for performance:
|
||||||
|
|
@ -198,7 +184,6 @@ proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
else:
|
else:
|
||||||
linefmt(p, cpsStmts, "#unsureAsgnRef((void**) $1, $2);$n",
|
linefmt(p, cpsStmts, "#unsureAsgnRef((void**) $1, $2);$n",
|
||||||
addrLoc(dest), rdLoc(src))
|
addrLoc(dest), rdLoc(src))
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
|
||||||
|
|
||||||
proc asgnComplexity(n: PNode): int =
|
proc asgnComplexity(n: PNode): int =
|
||||||
if n != nil:
|
if n != nil:
|
||||||
|
|
@ -218,7 +203,6 @@ proc optAsgnLoc(a: TLoc, t: PType, field: Rope): TLoc =
|
||||||
result.s = a.s
|
result.s = a.s
|
||||||
result.t = t
|
result.t = t
|
||||||
result.r = rdLoc(a) & "." & field
|
result.r = rdLoc(a) & "." & field
|
||||||
result.heapRoot = a.heapRoot
|
|
||||||
|
|
||||||
proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
let newflags =
|
let newflags =
|
||||||
|
|
@ -268,7 +252,6 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
||||||
addrLoc(dest), addrLoc(src), rdLoc(dest))
|
addrLoc(dest), addrLoc(src), rdLoc(dest))
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
|
||||||
else:
|
else:
|
||||||
linefmt(p, cpsStmts, "#genericShallowAssign((void*)$1, (void*)$2, $3);$n",
|
linefmt(p, cpsStmts, "#genericShallowAssign((void*)$1, (void*)$2, $3);$n",
|
||||||
addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t))
|
addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t))
|
||||||
|
|
@ -299,7 +282,6 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
else:
|
else:
|
||||||
if dest.s == OnStack or not usesNativeGC():
|
if dest.s == OnStack or not usesNativeGC():
|
||||||
linefmt(p, cpsStmts, "$1 = #copyString($2);$n", dest.rdLoc, src.rdLoc)
|
linefmt(p, cpsStmts, "$1 = #copyString($2);$n", dest.rdLoc, src.rdLoc)
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
|
||||||
elif dest.s == OnHeap:
|
elif dest.s == OnHeap:
|
||||||
# we use a temporary to care for the dreaded self assignment:
|
# we use a temporary to care for the dreaded self assignment:
|
||||||
var tmp: TLoc
|
var tmp: TLoc
|
||||||
|
|
@ -310,7 +292,6 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
else:
|
else:
|
||||||
linefmt(p, cpsStmts, "#unsureAsgnRef((void**) $1, #copyString($2));$n",
|
linefmt(p, cpsStmts, "#unsureAsgnRef((void**) $1, #copyString($2));$n",
|
||||||
addrLoc(dest), rdLoc(src))
|
addrLoc(dest), rdLoc(src))
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
|
||||||
of tyProc:
|
of tyProc:
|
||||||
if needsComplexAssignment(dest.t):
|
if needsComplexAssignment(dest.t):
|
||||||
# optimize closure assignment:
|
# optimize closure assignment:
|
||||||
|
|
@ -400,9 +381,6 @@ proc genDeepCopy(p: BProc; dest, src: TLoc) =
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||||
else: internalError("genDeepCopy: " & $ty.kind)
|
else: internalError("genDeepCopy: " & $ty.kind)
|
||||||
|
|
||||||
proc getDestLoc(p: BProc, d: var TLoc, typ: PType) =
|
|
||||||
if d.k == locNone: getTemp(p, typ, d)
|
|
||||||
|
|
||||||
proc putLocIntoDest(p: BProc, d: var TLoc, s: TLoc) =
|
proc putLocIntoDest(p: BProc, d: var TLoc, s: TLoc) =
|
||||||
if d.k != locNone:
|
if d.k != locNone:
|
||||||
if lfNoDeepCopy in d.flags: genAssignment(p, d, s, {})
|
if lfNoDeepCopy in d.flags: genAssignment(p, d, s, {})
|
||||||
|
|
@ -453,13 +431,6 @@ proc unaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
lineCg(p, cpsStmts, frmt, [rdLoc(a)])
|
lineCg(p, cpsStmts, frmt, [rdLoc(a)])
|
||||||
|
|
||||||
proc binaryStmtChar(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
|
||||||
var a, b: TLoc
|
|
||||||
if (d.k != locNone): internalError(e.info, "binaryStmtChar")
|
|
||||||
initLocExpr(p, e.sons[1], a)
|
|
||||||
initLocExpr(p, e.sons[2], b)
|
|
||||||
lineCg(p, cpsStmts, frmt, [rdCharLoc(a), rdCharLoc(b)])
|
|
||||||
|
|
||||||
proc binaryExpr(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
proc binaryExpr(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
var a, b: TLoc
|
var a, b: TLoc
|
||||||
assert(e.sons[1].typ != nil)
|
assert(e.sons[1].typ != nil)
|
||||||
|
|
@ -728,8 +699,6 @@ proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
|
|
||||||
template inheritLocation(d: var TLoc, a: TLoc) =
|
template inheritLocation(d: var TLoc, a: TLoc) =
|
||||||
if d.k == locNone: d.s = a.s
|
if d.k == locNone: d.s = a.s
|
||||||
if d.heapRoot == nil:
|
|
||||||
d.heapRoot = if a.heapRoot != nil: a.heapRoot else: a.r
|
|
||||||
|
|
||||||
proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc): PType =
|
proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc): PType =
|
||||||
initLocExpr(p, e.sons[0], a)
|
initLocExpr(p, e.sons[0], a)
|
||||||
|
|
@ -893,7 +862,6 @@ proc genSeqElem(p: BProc, x, y: PNode, d: var TLoc) =
|
||||||
"if ((NU)($1) >= (NU)($2->$3)) #raiseIndexError();$n",
|
"if ((NU)($1) >= (NU)($2->$3)) #raiseIndexError();$n",
|
||||||
rdLoc(b), rdLoc(a), lenField(p))
|
rdLoc(b), rdLoc(a), lenField(p))
|
||||||
if d.k == locNone: d.s = OnHeap
|
if d.k == locNone: d.s = OnHeap
|
||||||
d.heapRoot = a.r
|
|
||||||
if skipTypes(a.t, abstractVar).kind in {tyRef, tyPtr}:
|
if skipTypes(a.t, abstractVar).kind in {tyRef, tyPtr}:
|
||||||
a.r = rfmt(nil, "(*$1)", a.r)
|
a.r = rfmt(nil, "(*$1)", a.r)
|
||||||
putIntoDest(p, d, elemType(skipTypes(a.t, abstractVar)),
|
putIntoDest(p, d, elemType(skipTypes(a.t, abstractVar)),
|
||||||
|
|
@ -1008,9 +976,8 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
|
||||||
add(p.s(cpsStmts), appends)
|
add(p.s(cpsStmts), appends)
|
||||||
if d.k == locNone:
|
if d.k == locNone:
|
||||||
d = tmp
|
d = tmp
|
||||||
keepAlive(p, tmp)
|
|
||||||
else:
|
else:
|
||||||
genAssignment(p, d, tmp, {needToKeepAlive}) # no need for deep copying
|
genAssignment(p, d, tmp, {}) # no need for deep copying
|
||||||
gcUsage(e)
|
gcUsage(e)
|
||||||
|
|
||||||
proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
|
|
@ -1047,7 +1014,6 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
rdLoc(dest), rdLoc(a)))
|
rdLoc(dest), rdLoc(a)))
|
||||||
linefmt(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n",
|
linefmt(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n",
|
||||||
rdLoc(dest), lens, rope(L))
|
rdLoc(dest), lens, rope(L))
|
||||||
keepAlive(p, dest)
|
|
||||||
add(p.s(cpsStmts), appends)
|
add(p.s(cpsStmts), appends)
|
||||||
gcUsage(e)
|
gcUsage(e)
|
||||||
|
|
||||||
|
|
@ -1067,7 +1033,6 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
rdLoc(a),
|
rdLoc(a),
|
||||||
getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)),
|
getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)),
|
||||||
getTypeDesc(p.module, bt)])
|
getTypeDesc(p.module, bt)])
|
||||||
keepAlive(p, a)
|
|
||||||
#if bt != b.t:
|
#if bt != b.t:
|
||||||
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
|
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
|
||||||
initLoc(dest, locExpr, bt, OnHeap)
|
initLoc(dest, locExpr, bt, OnHeap)
|
||||||
|
|
@ -1094,7 +1059,7 @@ proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) =
|
||||||
genTypeInfo(p.module, refType),
|
genTypeInfo(p.module, refType),
|
||||||
sizeExpr]
|
sizeExpr]
|
||||||
if a.s == OnHeap and usesNativeGC():
|
if a.s == OnHeap and usesNativeGC():
|
||||||
# use newObjRC1 as an optimization; and we don't need 'keepAlive' either
|
# use newObjRC1 as an optimization
|
||||||
if canFormAcycle(a.t):
|
if canFormAcycle(a.t):
|
||||||
linefmt(p, cpsStmts, "if ($1) #nimGCunref($1);$n", a.rdLoc)
|
linefmt(p, cpsStmts, "if ($1) #nimGCunref($1);$n", a.rdLoc)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1103,7 +1068,7 @@ proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) =
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", a.rdLoc, b.rdLoc)
|
linefmt(p, cpsStmts, "$1 = $2;$n", a.rdLoc, b.rdLoc)
|
||||||
else:
|
else:
|
||||||
b.r = ropecg(p.module, "($1) #newObj($2, $3)", args)
|
b.r = ropecg(p.module, "($1) #newObj($2, $3)", args)
|
||||||
genAssignment(p, a, b, {needToKeepAlive}) # set the object type:
|
genAssignment(p, a, b, {}) # set the object type:
|
||||||
let bt = skipTypes(refType.sons[0], abstractRange)
|
let bt = skipTypes(refType.sons[0], abstractRange)
|
||||||
genObjectInit(p, cpsStmts, bt, a, false)
|
genObjectInit(p, cpsStmts, bt, a, false)
|
||||||
|
|
||||||
|
|
@ -1134,7 +1099,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) =
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", dest.rdLoc, call.rdLoc)
|
linefmt(p, cpsStmts, "$1 = $2;$n", dest.rdLoc, call.rdLoc)
|
||||||
else:
|
else:
|
||||||
call.r = ropecg(p.module, "($1) #newSeq($2, $3)", args)
|
call.r = ropecg(p.module, "($1) #newSeq($2, $3)", args)
|
||||||
genAssignment(p, dest, call, {needToKeepAlive})
|
genAssignment(p, dest, call, {})
|
||||||
|
|
||||||
proc genNewSeq(p: BProc, e: PNode) =
|
proc genNewSeq(p: BProc, e: PNode) =
|
||||||
var a, b: TLoc
|
var a, b: TLoc
|
||||||
|
|
@ -1199,7 +1164,6 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
tmp2.k = locTemp
|
tmp2.k = locTemp
|
||||||
tmp2.t = field.loc.t
|
tmp2.t = field.loc.t
|
||||||
tmp2.s = if isRef: OnHeap else: OnStack
|
tmp2.s = if isRef: OnHeap else: OnStack
|
||||||
tmp2.heapRoot = tmp.r
|
|
||||||
expr(p, it.sons[1], tmp2)
|
expr(p, it.sons[1], tmp2)
|
||||||
|
|
||||||
if d.k == locNone:
|
if d.k == locNone:
|
||||||
|
|
@ -1246,7 +1210,6 @@ proc genNewFinalize(p: BProc, e: PNode) =
|
||||||
a, b, f: TLoc
|
a, b, f: TLoc
|
||||||
refType, bt: PType
|
refType, bt: PType
|
||||||
ti: Rope
|
ti: Rope
|
||||||
oldModule: BModule
|
|
||||||
refType = skipTypes(e.sons[1].typ, abstractVarRange)
|
refType = skipTypes(e.sons[1].typ, abstractVarRange)
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
initLocExpr(p, e.sons[2], f)
|
initLocExpr(p, e.sons[2], f)
|
||||||
|
|
@ -1256,7 +1219,7 @@ proc genNewFinalize(p: BProc, e: PNode) =
|
||||||
b.r = ropecg(p.module, "($1) #newObj($2, sizeof($3))", [
|
b.r = ropecg(p.module, "($1) #newObj($2, sizeof($3))", [
|
||||||
getTypeDesc(p.module, refType),
|
getTypeDesc(p.module, refType),
|
||||||
ti, getTypeDesc(p.module, skipTypes(refType.lastSon, abstractRange))])
|
ti, getTypeDesc(p.module, skipTypes(refType.lastSon, abstractRange))])
|
||||||
genAssignment(p, a, b, {needToKeepAlive}) # set the object type:
|
genAssignment(p, a, b, {}) # set the object type:
|
||||||
bt = skipTypes(refType.lastSon, abstractRange)
|
bt = skipTypes(refType.lastSon, abstractRange)
|
||||||
genObjectInit(p, cpsStmts, bt, a, false)
|
genObjectInit(p, cpsStmts, bt, a, false)
|
||||||
gcUsage(e)
|
gcUsage(e)
|
||||||
|
|
@ -1366,7 +1329,7 @@ proc genDollar(p: BProc, n: PNode, d: var TLoc, frmt: string) =
|
||||||
initLocExpr(p, n.sons[1], a)
|
initLocExpr(p, n.sons[1], a)
|
||||||
a.r = ropecg(p.module, frmt, [rdLoc(a)])
|
a.r = ropecg(p.module, frmt, [rdLoc(a)])
|
||||||
if d.k == locNone: getTemp(p, n.typ, d)
|
if d.k == locNone: getTemp(p, n.typ, d)
|
||||||
genAssignment(p, d, a, {needToKeepAlive})
|
genAssignment(p, d, a, {})
|
||||||
gcUsage(n)
|
gcUsage(n)
|
||||||
|
|
||||||
proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
|
|
@ -1408,12 +1371,10 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
||||||
lineCg(p, cpsStmts, setLenPattern, [
|
lineCg(p, cpsStmts, setLenPattern, [
|
||||||
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
||||||
getTypeDesc(p.module, t.sons[0])])
|
getTypeDesc(p.module, t.sons[0])])
|
||||||
keepAlive(p, a)
|
|
||||||
gcUsage(e)
|
gcUsage(e)
|
||||||
|
|
||||||
proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) =
|
proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
binaryStmt(p, e, d, "$1 = #setLengthStr($1, $2);$n")
|
binaryStmt(p, e, d, "$1 = #setLengthStr($1, $2);$n")
|
||||||
keepAlive(p, d)
|
|
||||||
gcUsage(e)
|
gcUsage(e)
|
||||||
|
|
||||||
proc genSwap(p: BProc, e: PNode, d: var TLoc) =
|
proc genSwap(p: BProc, e: PNode, d: var TLoc) =
|
||||||
|
|
@ -1683,7 +1644,6 @@ proc binaryFloatArith(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
binaryArith(p, e, d, m)
|
binaryArith(p, e, d, m)
|
||||||
|
|
||||||
proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
var line, filen: Rope
|
|
||||||
case op
|
case op
|
||||||
of mOr, mAnd: genAndOr(p, e, d, op)
|
of mOr, mAnd: genAndOr(p, e, d, op)
|
||||||
of mNot..mToBiggestInt: unaryArith(p, e, d, op)
|
of mNot..mToBiggestInt: unaryArith(p, e, d, op)
|
||||||
|
|
@ -1721,10 +1681,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
getTypeDesc(p.module, ranged), res])
|
getTypeDesc(p.module, ranged), res])
|
||||||
|
|
||||||
of mConStrStr: genStrConcat(p, e, d)
|
of mConStrStr: genStrConcat(p, e, d)
|
||||||
of mAppendStrCh:
|
of mAppendStrCh: binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n")
|
||||||
binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n")
|
|
||||||
# strictly speaking we need to generate "keepAlive" here too, but this
|
|
||||||
# very likely not needed and would slow down the code too much I fear
|
|
||||||
of mAppendStrStr: genStrAppend(p, e, d)
|
of mAppendStrStr: genStrAppend(p, e, d)
|
||||||
of mAppendSeqElem: genSeqElemAppend(p, e, d)
|
of mAppendSeqElem: genSeqElemAppend(p, e, d)
|
||||||
of mEqStr: genStrEquals(p, e, d)
|
of mEqStr: genStrEquals(p, e, d)
|
||||||
|
|
|
||||||
|
|
@ -459,7 +459,6 @@ proc genWhileStmt(p: BProc, t: PNode) =
|
||||||
# significantly worse code
|
# significantly worse code
|
||||||
var
|
var
|
||||||
a: TLoc
|
a: TLoc
|
||||||
labl: TLabel
|
|
||||||
assert(sonsLen(t) == 2)
|
assert(sonsLen(t) == 2)
|
||||||
inc(p.withinLoop)
|
inc(p.withinLoop)
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
|
|
@ -757,16 +756,6 @@ proc genCase(p: BProc, t: PNode, d: var TLoc) =
|
||||||
else:
|
else:
|
||||||
genOrdinalCase(p, t, d)
|
genOrdinalCase(p, t, d)
|
||||||
|
|
||||||
proc hasGeneralExceptSection(t: PNode): bool =
|
|
||||||
var length = sonsLen(t)
|
|
||||||
var i = 1
|
|
||||||
while (i < length) and (t.sons[i].kind == nkExceptBranch):
|
|
||||||
var blen = sonsLen(t.sons[i])
|
|
||||||
if blen == 1:
|
|
||||||
return true
|
|
||||||
inc(i)
|
|
||||||
result = false
|
|
||||||
|
|
||||||
proc genTryCpp(p: BProc, t: PNode, d: var TLoc) =
|
proc genTryCpp(p: BProc, t: PNode, d: var TLoc) =
|
||||||
# code to generate:
|
# code to generate:
|
||||||
#
|
#
|
||||||
|
|
@ -1089,7 +1078,6 @@ proc genDiscriminantCheck(p: BProc, a, tmp: TLoc, objtype: PType,
|
||||||
proc asgnFieldDiscriminant(p: BProc, e: PNode) =
|
proc asgnFieldDiscriminant(p: BProc, e: PNode) =
|
||||||
var a, tmp: TLoc
|
var a, tmp: TLoc
|
||||||
var dotExpr = e.sons[0]
|
var dotExpr = e.sons[0]
|
||||||
var d: PSym
|
|
||||||
if dotExpr.kind == nkCheckedFieldExpr: dotExpr = dotExpr.sons[0]
|
if dotExpr.kind == nkCheckedFieldExpr: dotExpr = dotExpr.sons[0]
|
||||||
initLocExpr(p, e.sons[0], a)
|
initLocExpr(p, e.sons[0], a)
|
||||||
getTemp(p, a.t, tmp)
|
getTemp(p, a.t, tmp)
|
||||||
|
|
|
||||||
|
|
@ -744,14 +744,6 @@ proc getClosureType(m: BModule, t: PType, kind: TClosureTypeKind): Rope =
|
||||||
"void* ClEnv;$n} $1;$n",
|
"void* ClEnv;$n} $1;$n",
|
||||||
[result, rettype, desc])
|
[result, rettype, desc])
|
||||||
|
|
||||||
proc getTypeDesc(m: BModule, magic: string): Rope =
|
|
||||||
var sym = magicsys.getCompilerProc(magic)
|
|
||||||
if sym != nil:
|
|
||||||
result = getTypeDesc(m, sym.typ)
|
|
||||||
else:
|
|
||||||
rawMessage(errSystemNeeds, magic)
|
|
||||||
result = nil
|
|
||||||
|
|
||||||
proc finishTypeDescriptions(m: BModule) =
|
proc finishTypeDescriptions(m: BModule) =
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(m.typeStack):
|
while i < len(m.typeStack):
|
||||||
|
|
@ -1000,9 +992,6 @@ proc fakeClosureType(owner: PSym): PType =
|
||||||
type
|
type
|
||||||
TTypeInfoReason = enum ## for what do we need the type info?
|
TTypeInfoReason = enum ## for what do we need the type info?
|
||||||
tiNew, ## for 'new'
|
tiNew, ## for 'new'
|
||||||
tiNewSeq, ## for 'newSeq'
|
|
||||||
tiNonVariantAsgn, ## for generic assignment without variants
|
|
||||||
tiVariantAsgn ## for generic assignment with variants
|
|
||||||
|
|
||||||
include ccgtrav
|
include ccgtrav
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,10 +167,6 @@ proc linefmt(p: BProc, s: TCProcSection, frmt: FormatStr,
|
||||||
args: varargs[Rope]) =
|
args: varargs[Rope]) =
|
||||||
add(p.s(s), indentLine(p, ropecg(p.module, frmt, args)))
|
add(p.s(s), indentLine(p, ropecg(p.module, frmt, args)))
|
||||||
|
|
||||||
proc appLineCg(p: BProc, r: var Rope, frmt: FormatStr,
|
|
||||||
args: varargs[Rope]) =
|
|
||||||
add(r, indentLine(p, ropecg(p.module, frmt, args)))
|
|
||||||
|
|
||||||
proc safeLineNm(info: TLineInfo): int =
|
proc safeLineNm(info: TLineInfo): int =
|
||||||
result = toLinenumber(info)
|
result = toLinenumber(info)
|
||||||
if result < 0: result = 0 # negative numbers are not allowed in #line
|
if result < 0: result = 0 # negative numbers are not allowed in #line
|
||||||
|
|
@ -259,8 +255,7 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc,
|
||||||
|
|
||||||
type
|
type
|
||||||
TAssignmentFlag = enum
|
TAssignmentFlag = enum
|
||||||
needToCopy, needForSubtypeCheck, afDestIsNil, afDestIsNotNil, afSrcIsNil,
|
needToCopy, afDestIsNil, afDestIsNotNil, afSrcIsNil, afSrcIsNotNil
|
||||||
afSrcIsNotNil, needToKeepAlive
|
|
||||||
TAssignmentFlags = set[TAssignmentFlag]
|
TAssignmentFlags = set[TAssignmentFlag]
|
||||||
|
|
||||||
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags)
|
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags)
|
||||||
|
|
@ -338,31 +333,6 @@ proc getTemp(p: BProc, t: PType, result: var TLoc; needsInit=false) =
|
||||||
result.flags = {}
|
result.flags = {}
|
||||||
constructLoc(p, result, not needsInit)
|
constructLoc(p, result, not needsInit)
|
||||||
|
|
||||||
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
|
||||||
when false:
|
|
||||||
# deactivated because of the huge slowdown this causes; GC will take care
|
|
||||||
# of interior pointers instead
|
|
||||||
if optRefcGC notin gGlobalOptions: return
|
|
||||||
var result: TLoc
|
|
||||||
var fid = rope(p.gcFrameId)
|
|
||||||
result.r = "GCFRAME.F" & fid
|
|
||||||
addf(p.gcFrameType, " $1 F$2;$n",
|
|
||||||
[getTypeDesc(p.module, toKeepAlive.t), fid])
|
|
||||||
inc(p.gcFrameId)
|
|
||||||
result.k = locTemp
|
|
||||||
#result.a = -1
|
|
||||||
result.t = toKeepAlive.t
|
|
||||||
result.s = OnStack
|
|
||||||
result.flags = {}
|
|
||||||
|
|
||||||
if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)):
|
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(result), rdLoc(toKeepAlive))
|
|
||||||
else:
|
|
||||||
useStringh(p.module)
|
|
||||||
linefmt(p, cpsStmts,
|
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
|
||||||
addrLoc(result), addrLoc(toKeepAlive), rdLoc(result))
|
|
||||||
|
|
||||||
proc initGCFrame(p: BProc): Rope =
|
proc initGCFrame(p: BProc): Rope =
|
||||||
if p.gcFrameId > 0: result = "struct {$1} GCFRAME;$n" % [p.gcFrameType]
|
if p.gcFrameId > 0: result = "struct {$1} GCFRAME;$n" % [p.gcFrameType]
|
||||||
|
|
||||||
|
|
@ -620,9 +590,6 @@ proc generateHeaders(m: BModule) =
|
||||||
addf(m.s[cfsHeaders], "#include $1$N", [rope(it.data)])
|
addf(m.s[cfsHeaders], "#include $1$N", [rope(it.data)])
|
||||||
it = PStrEntry(it.next)
|
it = PStrEntry(it.next)
|
||||||
|
|
||||||
proc retIsNotVoid(s: PSym): bool =
|
|
||||||
result = (s.typ.sons[0] != nil) and not isInvalidReturnType(s.typ.sons[0])
|
|
||||||
|
|
||||||
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
||||||
discard cgsym(p.module, "nimFrame")
|
discard cgsym(p.module, "nimFrame")
|
||||||
if p.maxFrameLen > 0:
|
if p.maxFrameLen > 0:
|
||||||
|
|
|
||||||
|
|
@ -505,10 +505,6 @@ proc noAbsolutePaths: bool {.inline.} =
|
||||||
# `optGenMapping` is included here for niminst.
|
# `optGenMapping` is included here for niminst.
|
||||||
result = gGlobalOptions * {optGenScript, optGenMapping} != {}
|
result = gGlobalOptions * {optGenScript, optGenMapping} != {}
|
||||||
|
|
||||||
const
|
|
||||||
specialFileA = 42
|
|
||||||
specialFileB = 42
|
|
||||||
|
|
||||||
var fileCounter: int
|
var fileCounter: int
|
||||||
|
|
||||||
proc add(s: var string, many: openArray[string]) =
|
proc add(s: var string, many: openArray[string]) =
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,6 @@ proc loadMaxIds*(project: string) =
|
||||||
if f.readLine(line):
|
if f.readLine(line):
|
||||||
var frontEndId = parseInt(line)
|
var frontEndId = parseInt(line)
|
||||||
if f.readLine(line):
|
if f.readLine(line):
|
||||||
var backEndId = parseInt(line)
|
# var backEndId = parseInt(line)
|
||||||
gFrontEndId = max(gFrontEndId, frontEndId)
|
gFrontEndId = max(gFrontEndId, frontEndId)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
||||||
|
|
@ -211,9 +211,6 @@ proc closeLexer*(lex: var TLexer) =
|
||||||
inc(gLinesCompiled, lex.lineNumber)
|
inc(gLinesCompiled, lex.lineNumber)
|
||||||
closeBaseLexer(lex)
|
closeBaseLexer(lex)
|
||||||
|
|
||||||
proc getColumn(L: TLexer): int =
|
|
||||||
result = getColNumber(L, L.bufpos)
|
|
||||||
|
|
||||||
proc getLineInfo(L: TLexer): TLineInfo =
|
proc getLineInfo(L: TLexer): TLineInfo =
|
||||||
result = newLineInfo(L.fileIdx, L.lineNumber, getColNumber(L, L.bufpos))
|
result = newLineInfo(L.fileIdx, L.lineNumber, getColNumber(L, L.bufpos))
|
||||||
|
|
||||||
|
|
@ -237,12 +234,6 @@ proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
|
||||||
proc matchTwoChars(L: TLexer, first: char, second: set[char]): bool =
|
proc matchTwoChars(L: TLexer, first: char, second: set[char]): bool =
|
||||||
result = (L.buf[L.bufpos] == first) and (L.buf[L.bufpos + 1] in second)
|
result = (L.buf[L.bufpos] == first) and (L.buf[L.bufpos + 1] in second)
|
||||||
|
|
||||||
proc isFloatLiteral(s: string): bool =
|
|
||||||
for i in countup(0, len(s) - 1):
|
|
||||||
if s[i] in {'.', 'e', 'E'}:
|
|
||||||
return true
|
|
||||||
result = false
|
|
||||||
|
|
||||||
{.push overflowChecks: off.}
|
{.push overflowChecks: off.}
|
||||||
# We need to parse the largest uint literal without overflow checks
|
# We need to parse the largest uint literal without overflow checks
|
||||||
proc unsafeParseUInt(s: string, b: var BiggestInt, start = 0): int =
|
proc unsafeParseUInt(s: string, b: var BiggestInt, start = 0): int =
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,6 @@ proc getModule*(fileIdx: int32): PSym =
|
||||||
if fileIdx >= 0 and fileIdx < gCompiledModules.len:
|
if fileIdx >= 0 and fileIdx < gCompiledModules.len:
|
||||||
result = gCompiledModules[fileIdx]
|
result = gCompiledModules[fileIdx]
|
||||||
|
|
||||||
template hash(x: PSym): untyped =
|
|
||||||
gMemCacheData[x.position].hash
|
|
||||||
|
|
||||||
proc hashChanged(fileIdx: int32): bool =
|
proc hashChanged(fileIdx: int32): bool =
|
||||||
internalAssert fileIdx >= 0 and fileIdx < gMemCacheData.len
|
internalAssert fileIdx >= 0 and fileIdx < gMemCacheData.len
|
||||||
|
|
||||||
|
|
@ -220,12 +217,6 @@ proc includeModule*(s: PSym, fileIdx: int32): PNode {.procvar.} =
|
||||||
addDep(s, fileIdx)
|
addDep(s, fileIdx)
|
||||||
doHash(fileIdx)
|
doHash(fileIdx)
|
||||||
|
|
||||||
proc `==^`(a, b: string): bool =
|
|
||||||
try:
|
|
||||||
result = sameFile(a, b)
|
|
||||||
except OSError:
|
|
||||||
result = false
|
|
||||||
|
|
||||||
proc compileSystemModule* =
|
proc compileSystemModule* =
|
||||||
if magicsys.systemModule == nil:
|
if magicsys.systemModule == nil:
|
||||||
systemFileIdx = fileInfoIdx(options.libpath/"system.nim")
|
systemFileIdx = fileInfoIdx(options.libpath/"system.nim")
|
||||||
|
|
|
||||||
|
|
@ -660,8 +660,6 @@ const
|
||||||
WarningColor = fgYellow
|
WarningColor = fgYellow
|
||||||
HintTitle = "Hint: "
|
HintTitle = "Hint: "
|
||||||
HintColor = fgGreen
|
HintColor = fgGreen
|
||||||
InfoTitle = "Info: "
|
|
||||||
InfoColor = fgCyan
|
|
||||||
|
|
||||||
proc getInfoContextLen*(): int = return msgContext.len
|
proc getInfoContextLen*(): int = return msgContext.len
|
||||||
proc setInfoContextLen*(L: int) = setLen(msgContext, L)
|
proc setInfoContextLen*(L: int) = setLen(msgContext, L)
|
||||||
|
|
|
||||||
|
|
@ -63,18 +63,6 @@ proc addNimblePath(p: string, info: TLineInfo) =
|
||||||
message(info, hintPath, p)
|
message(info, hintPath, p)
|
||||||
lists.prependStr(options.lazyPaths, p)
|
lists.prependStr(options.lazyPaths, p)
|
||||||
|
|
||||||
proc addPathWithNimFiles(p: string, info: TLineInfo) =
|
|
||||||
proc hasNimFile(dir: string): bool =
|
|
||||||
for kind, path in walkDir(dir):
|
|
||||||
if kind == pcFile and path.endsWith(".nim"):
|
|
||||||
result = true
|
|
||||||
break
|
|
||||||
if hasNimFile(p):
|
|
||||||
addNimblePath(p, info)
|
|
||||||
else:
|
|
||||||
for kind, p2 in walkDir(p):
|
|
||||||
if hasNimFile(p2): addNimblePath(p2, info)
|
|
||||||
|
|
||||||
proc addPathRec(dir: string, info: TLineInfo) =
|
proc addPathRec(dir: string, info: TLineInfo) =
|
||||||
var packages = newStringTable(modeStyleInsensitive)
|
var packages = newStringTable(modeStyleInsensitive)
|
||||||
var pos = dir.len-1
|
var pos = dir.len-1
|
||||||
|
|
|
||||||
|
|
@ -340,26 +340,6 @@ proc parseSymbol(p: var TParser, allowNil = false): PNode =
|
||||||
if not isKeyword(p.tok.tokType): getTok(p)
|
if not isKeyword(p.tok.tokType): getTok(p)
|
||||||
result = ast.emptyNode
|
result = ast.emptyNode
|
||||||
|
|
||||||
proc indexExpr(p: var TParser): PNode =
|
|
||||||
#| indexExpr = expr
|
|
||||||
result = parseExpr(p)
|
|
||||||
|
|
||||||
proc indexExprList(p: var TParser, first: PNode, k: TNodeKind,
|
|
||||||
endToken: TTokType): PNode =
|
|
||||||
#| indexExprList = indexExpr ^+ comma
|
|
||||||
result = newNodeP(k, p)
|
|
||||||
addSon(result, first)
|
|
||||||
getTok(p)
|
|
||||||
optInd(p, result)
|
|
||||||
while p.tok.tokType notin {endToken, tkEof}:
|
|
||||||
var a = indexExpr(p)
|
|
||||||
addSon(result, a)
|
|
||||||
if p.tok.tokType != tkComma: break
|
|
||||||
getTok(p)
|
|
||||||
skipComment(p, a)
|
|
||||||
optPar(p)
|
|
||||||
eat(p, endToken)
|
|
||||||
|
|
||||||
proc colonOrEquals(p: var TParser, a: PNode): PNode =
|
proc colonOrEquals(p: var TParser, a: PNode): PNode =
|
||||||
if p.tok.tokType == tkColon:
|
if p.tok.tokType == tkColon:
|
||||||
result = newNodeP(nkExprColonExpr, p)
|
result = newNodeP(nkExprColonExpr, p)
|
||||||
|
|
|
||||||
|
|
@ -146,12 +146,6 @@ proc put(g: var TSrcGen, kind: TTokType, s: string) =
|
||||||
else:
|
else:
|
||||||
g.pendingWhitespace = s.len
|
g.pendingWhitespace = s.len
|
||||||
|
|
||||||
proc putLong(g: var TSrcGen, kind: TTokType, s: string, lineLen: int) =
|
|
||||||
# use this for tokens over multiple lines.
|
|
||||||
addPendingNL(g)
|
|
||||||
addTok(g, kind, s)
|
|
||||||
g.lineLen = lineLen
|
|
||||||
|
|
||||||
proc toNimChar(c: char): string =
|
proc toNimChar(c: char): string =
|
||||||
case c
|
case c
|
||||||
of '\0': result = "\\0"
|
of '\0': result = "\\0"
|
||||||
|
|
@ -264,9 +258,6 @@ proc pushCom(g: var TSrcGen, n: PNode) =
|
||||||
proc popAllComs(g: var TSrcGen) =
|
proc popAllComs(g: var TSrcGen) =
|
||||||
setLen(g.comStack, 0)
|
setLen(g.comStack, 0)
|
||||||
|
|
||||||
proc popCom(g: var TSrcGen) =
|
|
||||||
setLen(g.comStack, len(g.comStack) - 1)
|
|
||||||
|
|
||||||
const
|
const
|
||||||
Space = " "
|
Space = " "
|
||||||
|
|
||||||
|
|
@ -492,7 +483,7 @@ proc fits(g: TSrcGen, x: int): bool =
|
||||||
|
|
||||||
type
|
type
|
||||||
TSubFlag = enum
|
TSubFlag = enum
|
||||||
rfLongMode, rfNoIndent, rfInConstExpr
|
rfLongMode, rfInConstExpr
|
||||||
TSubFlags = set[TSubFlag]
|
TSubFlags = set[TSubFlag]
|
||||||
TContext = tuple[spacing: int, flags: TSubFlags]
|
TContext = tuple[spacing: int, flags: TSubFlags]
|
||||||
|
|
||||||
|
|
@ -675,16 +666,6 @@ proc gfor(g: var TSrcGen, n: PNode) =
|
||||||
gcoms(g)
|
gcoms(g)
|
||||||
gstmts(g, n.sons[length - 1], c)
|
gstmts(g, n.sons[length - 1], c)
|
||||||
|
|
||||||
proc gmacro(g: var TSrcGen, n: PNode) =
|
|
||||||
var c: TContext
|
|
||||||
initContext(c)
|
|
||||||
gsub(g, n.sons[0])
|
|
||||||
putWithSpace(g, tkColon, ":")
|
|
||||||
if longMode(n) or (lsub(n.sons[1]) + g.lineLen > MaxLineLen):
|
|
||||||
incl(c.flags, rfLongMode)
|
|
||||||
gcoms(g)
|
|
||||||
gsons(g, n, c, 1)
|
|
||||||
|
|
||||||
proc gcase(g: var TSrcGen, n: PNode) =
|
proc gcase(g: var TSrcGen, n: PNode) =
|
||||||
var c: TContext
|
var c: TContext
|
||||||
initContext(c)
|
initContext(c)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ proc semStmt(c: PContext, n: PNode): PNode
|
||||||
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
||||||
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
||||||
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
||||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
|
||||||
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
|
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
|
||||||
proc activate(c: PContext, n: PNode)
|
proc activate(c: PContext, n: PNode)
|
||||||
proc semQuoteAst(c: PContext, n: PNode): PNode
|
proc semQuoteAst(c: PContext, n: PNode): PNode
|
||||||
|
|
@ -187,7 +186,6 @@ proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
|
||||||
# identifier with visibility
|
# identifier with visibility
|
||||||
proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
|
proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
|
||||||
allowed: TSymFlags): PSym
|
allowed: TSymFlags): PSym
|
||||||
proc semStmtScope(c: PContext, n: PNode): PNode
|
|
||||||
|
|
||||||
proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) =
|
proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) =
|
||||||
let t = typeAllowed(typ, kind)
|
let t = typeAllowed(typ, kind)
|
||||||
|
|
|
||||||
|
|
@ -414,8 +414,6 @@ proc arrayConstrType(c: PContext, n: PNode): PType =
|
||||||
if sonsLen(n) == 0:
|
if sonsLen(n) == 0:
|
||||||
rawAddSon(typ, newTypeS(tyEmpty, c)) # needs an empty basetype!
|
rawAddSon(typ, newTypeS(tyEmpty, c)) # needs an empty basetype!
|
||||||
else:
|
else:
|
||||||
var x = n.sons[0]
|
|
||||||
var lastIndex: BiggestInt = sonsLen(n) - 1
|
|
||||||
var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyOrdinal})
|
var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyOrdinal})
|
||||||
addSonSkipIntLit(typ, t)
|
addSonSkipIntLit(typ, t)
|
||||||
typ.sons[0] = makeRangeType(c, 0, sonsLen(n) - 1, n.info)
|
typ.sons[0] = makeRangeType(c, 0, sonsLen(n) - 1, n.info)
|
||||||
|
|
@ -512,16 +510,6 @@ proc fixAbstractType(c: PContext, n: PNode) =
|
||||||
#if (it.typ == nil):
|
#if (it.typ == nil):
|
||||||
# InternalError(it.info, "fixAbstractType: " & renderTree(it))
|
# InternalError(it.info, "fixAbstractType: " & renderTree(it))
|
||||||
|
|
||||||
proc skipObjConv(n: PNode): PNode =
|
|
||||||
case n.kind
|
|
||||||
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
|
||||||
if skipTypes(n.sons[1].typ, abstractPtrs).kind in {tyTuple, tyObject}:
|
|
||||||
result = n.sons[1]
|
|
||||||
else:
|
|
||||||
result = n
|
|
||||||
of nkObjUpConv, nkObjDownConv: result = n.sons[0]
|
|
||||||
else: result = n
|
|
||||||
|
|
||||||
proc isAssignable(c: PContext, n: PNode; isUnsafeAddr=false): TAssignableResult =
|
proc isAssignable(c: PContext, n: PNode; isUnsafeAddr=false): TAssignableResult =
|
||||||
result = parampatterns.isAssignable(c.p.owner, n, isUnsafeAddr)
|
result = parampatterns.isAssignable(c.p.owner, n, isUnsafeAddr)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -458,32 +458,6 @@ proc getConstIfExpr(c: PSym, n: PNode): PNode =
|
||||||
if result == nil: result = getConstExpr(c, it.sons[0])
|
if result == nil: result = getConstExpr(c, it.sons[0])
|
||||||
else: internalError(it.info, "getConstIfExpr()")
|
else: internalError(it.info, "getConstIfExpr()")
|
||||||
|
|
||||||
proc partialAndExpr(c: PSym, n: PNode): PNode =
|
|
||||||
# partial evaluation
|
|
||||||
result = n
|
|
||||||
var a = getConstExpr(c, n.sons[1])
|
|
||||||
var b = getConstExpr(c, n.sons[2])
|
|
||||||
if a != nil:
|
|
||||||
if getInt(a) == 0: result = a
|
|
||||||
elif b != nil: result = b
|
|
||||||
else: result = n.sons[2]
|
|
||||||
elif b != nil:
|
|
||||||
if getInt(b) == 0: result = b
|
|
||||||
else: result = n.sons[1]
|
|
||||||
|
|
||||||
proc partialOrExpr(c: PSym, n: PNode): PNode =
|
|
||||||
# partial evaluation
|
|
||||||
result = n
|
|
||||||
var a = getConstExpr(c, n.sons[1])
|
|
||||||
var b = getConstExpr(c, n.sons[2])
|
|
||||||
if a != nil:
|
|
||||||
if getInt(a) != 0: result = a
|
|
||||||
elif b != nil: result = b
|
|
||||||
else: result = n.sons[2]
|
|
||||||
elif b != nil:
|
|
||||||
if getInt(b) != 0: result = b
|
|
||||||
else: result = n.sons[1]
|
|
||||||
|
|
||||||
proc leValueConv(a, b: PNode): bool =
|
proc leValueConv(a, b: PNode): bool =
|
||||||
result = false
|
result = false
|
||||||
case a.kind
|
case a.kind
|
||||||
|
|
|
||||||
|
|
@ -97,22 +97,6 @@ proc genericCacheGet(genericSym: PSym, entry: TInstantiation;
|
||||||
if inst.compilesId == id and sameInstantiation(entry, inst[]):
|
if inst.compilesId == id and sameInstantiation(entry, inst[]):
|
||||||
return inst.sym
|
return inst.sym
|
||||||
|
|
||||||
proc removeDefaultParamValues(n: PNode) =
|
|
||||||
# we remove default params, because they cannot be instantiated properly
|
|
||||||
# and they are not needed anyway for instantiation (each param is already
|
|
||||||
# provided).
|
|
||||||
when false:
|
|
||||||
for i in countup(1, sonsLen(n)-1):
|
|
||||||
var a = n.sons[i]
|
|
||||||
if a.kind != nkIdentDefs: IllFormedAst(a)
|
|
||||||
var L = a.len
|
|
||||||
if a.sons[L-1].kind != nkEmpty and a.sons[L-2].kind != nkEmpty:
|
|
||||||
# ``param: typ = defaultVal``.
|
|
||||||
# We don't need defaultVal for semantic checking and it's wrong for
|
|
||||||
# ``cmp: proc (a, b: T): int = cmp``. Hm, for ``cmp = cmp`` that is
|
|
||||||
# not possible... XXX We don't solve this issue here.
|
|
||||||
a.sons[L-1] = ast.emptyNode
|
|
||||||
|
|
||||||
proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
|
proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
|
||||||
# we need to create a fresh set of gensym'ed symbols:
|
# we need to create a fresh set of gensym'ed symbols:
|
||||||
if n.kind == nkSym and sfGenSym in n.sym.flags and n.sym.owner == orig:
|
if n.kind == nkSym and sfGenSym in n.sym.flags and n.sym.owner == orig:
|
||||||
|
|
@ -128,17 +112,6 @@ proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
|
||||||
|
|
||||||
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind)
|
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind)
|
||||||
|
|
||||||
proc addProcDecls(c: PContext, fn: PSym) =
|
|
||||||
# get the proc itself in scope (e.g. for recursion)
|
|
||||||
addDecl(c, fn)
|
|
||||||
|
|
||||||
for i in 1 .. <fn.typ.n.len:
|
|
||||||
var param = fn.typ.n.sons[i].sym
|
|
||||||
param.owner = fn
|
|
||||||
addParamOrResult(c, param, fn.kind)
|
|
||||||
|
|
||||||
maybeAddResult(c, fn, fn.ast)
|
|
||||||
|
|
||||||
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:
|
||||||
inc c.inGenericInst
|
inc c.inGenericInst
|
||||||
|
|
@ -188,9 +161,6 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType,
|
||||||
cl.allowMetaTypes = allowMetaTypes
|
cl.allowMetaTypes = allowMetaTypes
|
||||||
result = replaceTypeVarsT(cl, header)
|
result = replaceTypeVarsT(cl, header)
|
||||||
|
|
||||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType =
|
|
||||||
result = instGenericContainer(c, n.info, header)
|
|
||||||
|
|
||||||
proc instantiateProcType(c: PContext, pt: TIdTable,
|
proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
prc: PSym, info: TLineInfo) =
|
prc: PSym, info: TLineInfo) =
|
||||||
# XXX: Instantiates a generic proc signature, while at the same
|
# XXX: Instantiates a generic proc signature, while at the same
|
||||||
|
|
|
||||||
|
|
@ -151,13 +151,6 @@ proc isStrangeArray(t: PType): bool =
|
||||||
let t = t.skipTypes(abstractInst)
|
let t = t.skipTypes(abstractInst)
|
||||||
result = t.kind == tyArray and t.firstOrd != 0
|
result = t.kind == tyArray and t.firstOrd != 0
|
||||||
|
|
||||||
proc isNegative(n: PNode): bool =
|
|
||||||
let n = n.skipConv
|
|
||||||
if n.kind in {nkCharLit..nkUInt64Lit}:
|
|
||||||
result = n.intVal < 0
|
|
||||||
elif n.kind in nkCallKinds and n.sons[0].kind == nkSym:
|
|
||||||
result = n.sons[0].sym.magic in {mUnaryMinusI, mUnaryMinusI64}
|
|
||||||
|
|
||||||
proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
||||||
flags: TExprFlags): PNode =
|
flags: TExprFlags): PNode =
|
||||||
case n[0].sym.magic
|
case n[0].sym.magic
|
||||||
|
|
|
||||||
|
|
@ -280,10 +280,6 @@ proc createTag(n: PNode): PNode =
|
||||||
result.typ = sysTypeFromName"TEffect"
|
result.typ = sysTypeFromName"TEffect"
|
||||||
if not n.isNil: result.info = n.info
|
if not n.isNil: result.info = n.info
|
||||||
|
|
||||||
proc createAnyGlobal(n: PNode): PNode =
|
|
||||||
result = newSymNode(anyGlobal)
|
|
||||||
result.info = n.info
|
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -816,9 +812,6 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
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
|
||||||
|
|
||||||
proc symbolPredicate(spec, real: PNode): bool =
|
|
||||||
result = real.sym.id == spec.sym.id
|
|
||||||
|
|
||||||
proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool;
|
proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool;
|
||||||
effectPredicate: proc (a, b: PNode): bool {.nimcall.}) =
|
effectPredicate: proc (a, b: PNode): bool {.nimcall.}) =
|
||||||
# check that any real exception is listed in 'spec'; mark those as used;
|
# check that any real exception is listed in 'spec'; mark those as used;
|
||||||
|
|
|
||||||
|
|
@ -1141,11 +1141,6 @@ type
|
||||||
TProcCompilationSteps = enum
|
TProcCompilationSteps = enum
|
||||||
stepRegisterSymbol,
|
stepRegisterSymbol,
|
||||||
stepDetermineType,
|
stepDetermineType,
|
||||||
stepCompileBody
|
|
||||||
|
|
||||||
proc isForwardDecl(s: PSym): bool =
|
|
||||||
internalAssert s.kind == skProc
|
|
||||||
result = s.ast[bodyPos].kind != nkEmpty
|
|
||||||
|
|
||||||
proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
validPragmas: TSpecialWords,
|
validPragmas: TSpecialWords,
|
||||||
|
|
@ -1183,8 +1178,6 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
s.ast = n
|
s.ast = n
|
||||||
#s.scope = c.currentScope
|
#s.scope = c.currentScope
|
||||||
|
|
||||||
# if typeIsDetermined: assert phase == stepCompileBody
|
|
||||||
# else: assert phase == stepDetermineType
|
|
||||||
# before compiling the proc body, set as current the scope
|
# before compiling the proc body, set as current the scope
|
||||||
# where the proc was declared
|
# where the proc was declared
|
||||||
let oldScope = c.currentScope
|
let oldScope = c.currentScope
|
||||||
|
|
@ -1566,8 +1559,3 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
proc semStmt(c: PContext, n: PNode): PNode =
|
proc semStmt(c: PContext, n: PNode): PNode =
|
||||||
# now: simply an alias:
|
# now: simply an alias:
|
||||||
result = semExprNoType(c, n)
|
result = semExprNoType(c, n)
|
||||||
|
|
||||||
proc semStmtScope(c: PContext, n: PNode): PNode =
|
|
||||||
openScope(c)
|
|
||||||
result = semStmt(c, n)
|
|
||||||
closeScope(c)
|
|
||||||
|
|
|
||||||
|
|
@ -287,35 +287,6 @@ proc semTemplBodySons(c: var TemplCtx, n: PNode): PNode =
|
||||||
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 wrapInBind(c: var TemplCtx; n: PNode; opr: string): PNode =
|
|
||||||
let ident = getIdent(opr)
|
|
||||||
if ident.id in c.toInject: return n
|
|
||||||
|
|
||||||
let s = searchInScopes(c.c, ident)
|
|
||||||
if s != nil:
|
|
||||||
var callee: PNode
|
|
||||||
if contains(c.toBind, s.id):
|
|
||||||
callee = symChoice(c.c, n, s, scClosed)
|
|
||||||
elif contains(c.toMixin, s.name.id):
|
|
||||||
callee = symChoice(c.c, n, s, scForceOpen)
|
|
||||||
elif s.owner == c.owner and sfGenSym in s.flags:
|
|
||||||
# template tmp[T](x: var seq[T]) =
|
|
||||||
# var yz: T
|
|
||||||
incl(s.flags, sfUsed)
|
|
||||||
callee = newSymNode(s, n.info)
|
|
||||||
styleCheckUse(n.info, s)
|
|
||||||
else:
|
|
||||||
callee = semTemplSymbol(c.c, n, s)
|
|
||||||
|
|
||||||
let call = newNodeI(nkCall, n.info)
|
|
||||||
call.add(callee)
|
|
||||||
for i in 0 .. n.len-1: call.add(n[i])
|
|
||||||
result = newNodeI(nkBind, n.info, 2)
|
|
||||||
result.sons[0] = n
|
|
||||||
result.sons[1] = call
|
|
||||||
else:
|
|
||||||
result = n
|
|
||||||
|
|
||||||
proc oprIsRoof(n: PNode): bool =
|
proc oprIsRoof(n: PNode): bool =
|
||||||
const roof = "^"
|
const roof = "^"
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
|
||||||
|
|
@ -594,13 +594,6 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||||
popTransCon(c)
|
popTransCon(c)
|
||||||
# echo "transformed: ", stmtList.PNode.renderTree
|
# echo "transformed: ", stmtList.PNode.renderTree
|
||||||
|
|
||||||
proc getMagicOp(call: PNode): TMagic =
|
|
||||||
if call.sons[0].kind == nkSym and
|
|
||||||
call.sons[0].sym.kind in {skProc, skMethod, skConverter}:
|
|
||||||
result = call.sons[0].sym.magic
|
|
||||||
else:
|
|
||||||
result = mNone
|
|
||||||
|
|
||||||
proc transformCase(c: PTransf, n: PNode): PTransNode =
|
proc transformCase(c: PTransf, n: PNode): PTransNode =
|
||||||
# removes `elif` branches of a case stmt
|
# removes `elif` branches of a case stmt
|
||||||
# adds ``else: nil`` if needed for the code generator
|
# adds ``else: nil`` if needed for the code generator
|
||||||
|
|
|
||||||
|
|
@ -145,10 +145,6 @@ proc elemType*(t: PType): PType =
|
||||||
else: result = t.lastSon
|
else: result = t.lastSon
|
||||||
assert(result != nil)
|
assert(result != nil)
|
||||||
|
|
||||||
proc skipGeneric(t: PType): PType =
|
|
||||||
result = t
|
|
||||||
while result.kind == tyGenericInst: result = lastSon(result)
|
|
||||||
|
|
||||||
proc isOrdinalType(t: PType): bool =
|
proc isOrdinalType(t: PType): bool =
|
||||||
assert(t != nil)
|
assert(t != nil)
|
||||||
const
|
const
|
||||||
|
|
@ -578,10 +574,6 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
result = typeToStr[t.kind]
|
result = typeToStr[t.kind]
|
||||||
result.addTypeFlags(t)
|
result.addTypeFlags(t)
|
||||||
|
|
||||||
proc resultType(t: PType): PType =
|
|
||||||
assert(t.kind == tyProc)
|
|
||||||
result = t.sons[0] # nil is allowed
|
|
||||||
|
|
||||||
proc base(t: PType): PType =
|
proc base(t: PType): PType =
|
||||||
result = t.sons[0]
|
result = t.sons[0]
|
||||||
|
|
||||||
|
|
@ -772,18 +764,6 @@ proc equalParams(a, b: PNode): TParamsEquality =
|
||||||
result = paramsIncompatible # overloading by different
|
result = paramsIncompatible # overloading by different
|
||||||
# result types does not work
|
# result types does not work
|
||||||
|
|
||||||
proc sameLiteral(x, y: PNode): bool =
|
|
||||||
if x.kind == y.kind:
|
|
||||||
case x.kind
|
|
||||||
of nkCharLit..nkInt64Lit: result = x.intVal == y.intVal
|
|
||||||
of nkFloatLit..nkFloat64Lit: result = x.floatVal == y.floatVal
|
|
||||||
of nkNilLit: result = true
|
|
||||||
else: assert(false)
|
|
||||||
|
|
||||||
proc sameRanges(a, b: PNode): bool =
|
|
||||||
result = sameLiteral(a.sons[0], b.sons[0]) and
|
|
||||||
sameLiteral(a.sons[1], b.sons[1])
|
|
||||||
|
|
||||||
proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
|
proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
|
||||||
# two tuples are equivalent iff the names, types and positions are the same;
|
# two tuples are equivalent iff the names, types and positions are the same;
|
||||||
# however, both types may not have any field names (t.n may be nil) which
|
# however, both types may not have any field names (t.n may be nil) which
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,6 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
mapTypeToBracketX(name, m, t, info, inst)
|
mapTypeToBracketX(name, m, t, info, inst)
|
||||||
template newNodeX(kind): untyped =
|
template newNodeX(kind): untyped =
|
||||||
newNodeIT(kind, if t.n.isNil: info else: t.n.info, t)
|
newNodeIT(kind, if t.n.isNil: info else: t.n.info, t)
|
||||||
template newIdent(s): untyped =
|
|
||||||
var r = newNodeX(nkIdent)
|
|
||||||
r.add !s
|
|
||||||
r
|
|
||||||
template newIdentDefs(n,t): untyped =
|
template newIdentDefs(n,t): untyped =
|
||||||
var id = newNodeX(nkIdentDefs)
|
var id = newNodeX(nkIdentDefs)
|
||||||
id.add n # name
|
id.add n # name
|
||||||
|
|
|
||||||
|
|
@ -1127,14 +1127,6 @@ proc fitsRegister*(t: PType): bool =
|
||||||
t.skipTypes(abstractInst-{tyTypeDesc}).kind in {
|
t.skipTypes(abstractInst-{tyTypeDesc}).kind in {
|
||||||
tyRange, tyEnum, tyBool, tyInt..tyUInt64, tyChar}
|
tyRange, tyEnum, tyBool, tyInt..tyUInt64, tyChar}
|
||||||
|
|
||||||
proc requiresCopy(n: PNode): bool =
|
|
||||||
if n.typ.skipTypes(abstractInst-{tyTypeDesc}).kind in atomicTypes:
|
|
||||||
result = false
|
|
||||||
elif n.kind in ({nkCurly, nkBracket, nkPar, nkObjConstr}+nkCallKinds):
|
|
||||||
result = false
|
|
||||||
else:
|
|
||||||
result = true
|
|
||||||
|
|
||||||
proc unneededIndirection(n: PNode): bool =
|
proc unneededIndirection(n: PNode): bool =
|
||||||
n.typ.skipTypes(abstractInst-{tyTypeDesc}).kind == tyRef
|
n.typ.skipTypes(abstractInst-{tyTypeDesc}).kind == tyRef
|
||||||
|
|
||||||
|
|
@ -1215,8 +1207,6 @@ proc whichAsgnOpc(n: PNode): TOpcode =
|
||||||
else:
|
else:
|
||||||
opcAsgnComplex
|
opcAsgnComplex
|
||||||
|
|
||||||
proc isRef(t: PType): bool = t.skipTypes(abstractRange-{tyTypeDesc}).kind == tyRef
|
|
||||||
|
|
||||||
proc whichAsgnOpc(n: PNode; opc: TOpcode): TOpcode = opc
|
proc whichAsgnOpc(n: PNode; opc: TOpcode): TOpcode = opc
|
||||||
|
|
||||||
proc genAsgn(c: PCtx; dest: TDest; ri: PNode; requiresCopy: bool) =
|
proc genAsgn(c: PCtx; dest: TDest; ri: PNode; requiresCopy: bool) =
|
||||||
|
|
@ -1268,9 +1258,6 @@ proc isTemp(c: PCtx; dest: TDest): bool =
|
||||||
template needsAdditionalCopy(n): untyped =
|
template needsAdditionalCopy(n): untyped =
|
||||||
not c.isTemp(dest) and not fitsRegister(n.typ)
|
not c.isTemp(dest) and not fitsRegister(n.typ)
|
||||||
|
|
||||||
proc skipDeref(n: PNode): PNode =
|
|
||||||
result = if n.kind in {nkDerefExpr, nkHiddenDeref}: n.sons[0] else: n
|
|
||||||
|
|
||||||
proc preventFalseAlias(c: PCtx; n: PNode; opc: TOpcode;
|
proc preventFalseAlias(c: PCtx; n: PNode; opc: TOpcode;
|
||||||
dest, idx, value: TRegister) =
|
dest, idx, value: TRegister) =
|
||||||
# opcLdObj et al really means "load address". We sometimes have to create a
|
# opcLdObj et al really means "load address". We sometimes have to create a
|
||||||
|
|
@ -1848,7 +1835,6 @@ 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:
|
||||||
let param = params.sons[i].sym
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue