C code generator compiles again

This commit is contained in:
Andreas Rumpf 2018-05-12 23:45:51 +02:00
commit 1284827df2
11 changed files with 208 additions and 202 deletions

View file

@ -116,7 +116,7 @@ proc openArrayLoc(p: BProc, n: PNode): Rope =
else: else:
result = "$1->data+($2), ($3)-($2)+1" % [rdLoc(a), rdLoc(b), rdLoc(c)] result = "$1->data+($2), ($3)-($2)+1" % [rdLoc(a), rdLoc(b), rdLoc(c)]
else: else:
internalError("openArrayLoc: " & typeToString(a.t)) internalError(p.config, "openArrayLoc: " & typeToString(a.t))
else: else:
initLocExpr(p, n, a) initLocExpr(p, n, a)
case skipTypes(a.t, abstractVar).kind case skipTypes(a.t, abstractVar).kind
@ -137,8 +137,8 @@ proc openArrayLoc(p: BProc, n: PNode): Rope =
of tyArray: of tyArray:
result = "$1, $2" % [rdLoc(a), rope(lengthOrd(lastSon(a.t)))] result = "$1, $2" % [rdLoc(a), rope(lengthOrd(lastSon(a.t)))]
else: else:
internalError("openArrayLoc: " & typeToString(a.t)) internalError(p.config, "openArrayLoc: " & typeToString(a.t))
else: internalError("openArrayLoc: " & typeToString(a.t)) else: internalError(p.config, "openArrayLoc: " & typeToString(a.t))
proc genArgStringToCString(p: BProc, n: PNode): Rope {.inline.} = proc genArgStringToCString(p: BProc, n: PNode): Rope {.inline.} =
var a: TLoc var a: TLoc
@ -273,7 +273,7 @@ proc genOtherArg(p: BProc; ri: PNode; i: int; typ: PType): Rope =
result = genArgNoParam(p, ri.sons[i]) #, typ.n.sons[i].sym) result = genArgNoParam(p, ri.sons[i]) #, typ.n.sons[i].sym)
else: else:
if tfVarargs notin typ.flags: if tfVarargs notin typ.flags:
localError(ri.info, "wrong argument count") localError(p.config, ri.info, "wrong argument count")
result = nil result = nil
else: else:
result = genArgNoParam(p, ri.sons[i]) result = genArgNoParam(p, ri.sons[i])
@ -337,7 +337,7 @@ proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): Rope =
# for better or worse c2nim translates the 'this' argument to a 'var T'. # for better or worse c2nim translates the 'this' argument to a 'var T'.
# However manual wrappers may also use 'ptr T'. In any case we support both # However manual wrappers may also use 'ptr T'. In any case we support both
# for convenience. # for convenience.
internalAssert i < sonsLen(typ) internalAssert p.config, i < sonsLen(typ)
assert(typ.n.sons[i].kind == nkSym) assert(typ.n.sons[i].kind == nkSym)
# if the parameter is lying (tyVar) and thus we required an additional deref, # if the parameter is lying (tyVar) and thus we required an additional deref,
# skip the deref: # skip the deref:
@ -394,7 +394,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
result.add genOtherArg(p, ri, k, typ) result.add genOtherArg(p, ri, k, typ)
result.add(~")") result.add(~")")
else: else:
localError(ri.info, "call expression expected for C++ pattern") localError(p.config, ri.info, "call expression expected for C++ pattern")
inc i inc i
elif pat[i+1] == '.': elif pat[i+1] == '.':
result.add genThisArg(p, ri, j, typ) result.add genThisArg(p, ri, j, typ)
@ -432,7 +432,7 @@ proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
assert(sonsLen(typ) == sonsLen(typ.n)) assert(sonsLen(typ) == sonsLen(typ.n))
# don't call '$' here for efficiency: # don't call '$' here for efficiency:
let pat = ri.sons[0].sym.loc.r.data let pat = ri.sons[0].sym.loc.r.data
internalAssert pat != nil internalAssert p.config, pat != nil
if pat.contains({'#', '(', '@', '\''}): if pat.contains({'#', '(', '@', '\''}):
var pl = genPatternCall(p, ri, pat, typ) var pl = genPatternCall(p, ri, pat, typ)
# simpler version of 'fixupCall' that works with the pl+params combination: # simpler version of 'fixupCall' that works with the pl+params combination:
@ -481,7 +481,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
# don't call '$' here for efficiency: # don't call '$' here for efficiency:
let pat = ri.sons[0].sym.loc.r.data let pat = ri.sons[0].sym.loc.r.data
internalAssert pat != nil internalAssert p.config, pat != nil
var start = 3 var start = 3
if ' ' in pat: if ' ' in pat:
start = 1 start = 1
@ -501,7 +501,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
for i in countup(start, length-1): for i in countup(start, length-1):
assert(sonsLen(typ) == sonsLen(typ.n)) assert(sonsLen(typ) == sonsLen(typ.n))
if i >= sonsLen(typ): if i >= sonsLen(typ):
internalError(ri.info, "varargs for objective C method?") internalError(p.config, ri.info, "varargs for objective C method?")
assert(typ.n.sons[i].kind == nkSym) assert(typ.n.sons[i].kind == nkSym)
var param = typ.n.sons[i].sym var param = typ.n.sons[i].sym
add(pl, ~" ") add(pl, ~" ")

View file

@ -31,7 +31,7 @@ proc intLiteral(i: BiggestInt): Rope =
result = ~"(IL64(-9223372036854775807) - IL64(1))" result = ~"(IL64(-9223372036854775807) - IL64(1))"
proc genLiteral(p: BProc, n: PNode, ty: PType): Rope = proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
if ty == nil: internalError(n.info, "genLiteral: ty is nil") if ty == nil: internalError(p.config, n.info, "genLiteral: ty is nil")
case n.kind case n.kind
of nkCharLit..nkUInt64Lit: of nkCharLit..nkUInt64Lit:
case skipTypes(ty, abstractVarRange).kind case skipTypes(ty, abstractVarRange).kind
@ -76,7 +76,7 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
of nkFloat32Lit: of nkFloat32Lit:
result = rope(n.floatVal.toStrMaxPrecision("f")) result = rope(n.floatVal.toStrMaxPrecision("f"))
else: else:
internalError(n.info, "genLiteral(" & $n.kind & ')') internalError(p.config, n.info, "genLiteral(" & $n.kind & ')')
result = nil result = nil
proc genLiteral(p: BProc, n: PNode): Rope = proc genLiteral(p: BProc, n: PNode): Rope =
@ -145,7 +145,7 @@ proc getStorageLoc(n: PNode): TStorageLoc =
of tyVar, tyLent: result = OnUnknown of tyVar, tyLent: result = OnUnknown
of tyPtr: result = OnStack of tyPtr: result = OnStack
of tyRef: result = OnHeap of tyRef: result = OnHeap
else: internalError(n.info, "getStorageLoc") else: doAssert(false, "getStorageLoc")
of nkBracketExpr, nkDotExpr, nkObjDownConv, nkObjUpConv: of nkBracketExpr, nkDotExpr, nkObjDownConv, nkObjUpConv:
result = getStorageLoc(n.sons[0]) result = getStorageLoc(n.sons[0])
else: result = OnUnknown else: result = OnUnknown
@ -164,7 +164,7 @@ proc canMove(n: PNode): bool =
# result = false # result = false
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
if dest.storage == OnStack or not usesNativeGC(): if dest.storage == OnStack or not usesNativeGC(p.config):
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src)) linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
elif dest.storage == OnHeap: elif dest.storage == OnHeap:
# location is on heap # location is on heap
@ -256,7 +256,7 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
# (for objects, etc.): # (for objects, etc.):
if needToCopy notin flags or if needToCopy notin flags or
tfShallow in skipTypes(dest.t, abstractVarRange).flags: tfShallow in skipTypes(dest.t, abstractVarRange).flags:
if dest.storage == OnStack or not usesNativeGC(): if dest.storage == OnStack or not usesNativeGC(p.config):
useStringh(p.module) useStringh(p.module)
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",
@ -290,7 +290,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
if (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode): if (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode):
genRefAssign(p, dest, src, flags) genRefAssign(p, dest, src, flags)
else: else:
if dest.storage == OnStack or not usesNativeGC(): if dest.storage == OnStack or not usesNativeGC(p.config):
linefmt(p, cpsStmts, "$1 = #copyString($2);$n", dest.rdLoc, src.rdLoc) linefmt(p, cpsStmts, "$1 = #copyString($2);$n", dest.rdLoc, src.rdLoc)
elif dest.storage == OnHeap: elif dest.storage == OnHeap:
# we use a temporary to care for the dreaded self assignment: # we use a temporary to care for the dreaded self assignment:
@ -326,7 +326,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
elif needsComplexAssignment(ty): elif needsComplexAssignment(ty):
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4: if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
discard getTypeDesc(p.module, ty) discard getTypeDesc(p.module, ty)
internalAssert ty.n != nil internalAssert p.config, ty.n != nil
genOptAsgnObject(p, dest, src, flags, ty.n, ty) genOptAsgnObject(p, dest, src, flags, ty.n, ty)
else: else:
genGenericAsgn(p, dest, src, flags) genGenericAsgn(p, dest, src, flags)
@ -363,7 +363,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString, of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString,
tyInt..tyUInt64, tyRange, tyVar, tyLent: tyInt..tyUInt64, tyRange, tyVar, tyLent:
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src)) linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
else: internalError("genAssignment: " & $ty.kind) else: internalError(p.config, "genAssignment: " & $ty.kind)
if optMemTracker in p.options and dest.storage in {OnHeap, OnUnknown}: if optMemTracker in p.options and dest.storage in {OnHeap, OnUnknown}:
#writeStackTrace() #writeStackTrace()
@ -409,7 +409,7 @@ proc genDeepCopy(p: BProc; dest, src: TLoc) =
of tyPointer, tyChar, tyBool, tyEnum, tyCString, of tyPointer, tyChar, tyBool, tyEnum, tyCString,
tyInt..tyUInt64, tyRange, tyVar, tyLent: tyInt..tyUInt64, tyRange, tyVar, tyLent:
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(p.config, "genDeepCopy: " & $ty.kind)
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:
@ -450,14 +450,14 @@ proc putIntoDest(p: BProc, d: var TLoc, n: PNode, r: Rope; s=OnUnknown) =
proc binaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) = proc binaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
var a, b: TLoc var a, b: TLoc
if d.k != locNone: internalError(e.info, "binaryStmt") if d.k != locNone: internalError(p.config, e.info, "binaryStmt")
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b) initLocExpr(p, e.sons[2], b)
lineCg(p, cpsStmts, frmt, rdLoc(a), rdLoc(b)) lineCg(p, cpsStmts, frmt, rdLoc(a), rdLoc(b))
proc unaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) = proc unaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
var a: TLoc var a: TLoc
if d.k != locNone: internalError(e.info, "unaryStmt") if d.k != locNone: internalError(p.config, e.info, "unaryStmt")
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
lineCg(p, cpsStmts, frmt, [rdLoc(a)]) lineCg(p, cpsStmts, frmt, [rdLoc(a)])
@ -701,7 +701,7 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
of tyPtr: of tyPtr:
d.storage = OnUnknown # BUGFIX! d.storage = OnUnknown # BUGFIX!
else: else:
internalError(e.info, "genDeref " & $typ.kind) internalError(p.config, e.info, "genDeref " & $typ.kind)
elif p.module.compileToCpp: elif p.module.compileToCpp:
if typ.kind == tyVar and tfVarIsPtr notin typ.flags and if typ.kind == tyVar and tfVarIsPtr notin typ.flags and
e.kind == nkHiddenDeref: e.kind == nkHiddenDeref:
@ -736,7 +736,7 @@ template inheritLocation(d: var TLoc, a: TLoc) =
proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc) = proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc) =
initLocExpr(p, e.sons[0], a) initLocExpr(p, e.sons[0], a)
if e.sons[1].kind != nkSym: internalError(e.info, "genRecordFieldAux") if e.sons[1].kind != nkSym: internalError(p.config, e.info, "genRecordFieldAux")
d.inheritLocation(a) d.inheritLocation(a)
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
@ -752,7 +752,7 @@ proc genTupleElem(p: BProc, e: PNode, d: var TLoc) =
var r = rdLoc(a) var r = rdLoc(a)
case e.sons[1].kind case e.sons[1].kind
of nkIntLit..nkUInt64Lit: i = int(e.sons[1].intVal) of nkIntLit..nkUInt64Lit: i = int(e.sons[1].intVal)
else: internalError(e.info, "genTupleElem") else: internalError(p.config, e.info, "genTupleElem")
addf(r, ".Field$1", [rope(i)]) addf(r, ".Field$1", [rope(i)])
putIntoDest(p, d, e, r, a.storage) putIntoDest(p, d, e, r, a.storage)
@ -769,7 +769,7 @@ proc lookupFieldAgain(p: BProc, ty: PType; field: PSym; r: var Rope;
break break
if not p.module.compileToCpp: add(r, ".Sup") if not p.module.compileToCpp: add(r, ".Sup")
ty = ty.sons[0] ty = ty.sons[0]
if result == nil: internalError(field.info, "genCheckedRecordField") if result == nil: internalError(p.config, field.info, "genCheckedRecordField")
proc genRecordField(p: BProc, e: PNode, d: var TLoc) = proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
var a: TLoc var a: TLoc
@ -786,7 +786,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
var rtyp: PType var rtyp: PType
let field = lookupFieldAgain(p, ty, f, r, addr rtyp) let field = lookupFieldAgain(p, ty, f, r, addr rtyp)
if field.loc.r == nil and rtyp != nil: fillObjectFields(p.module, rtyp) if field.loc.r == nil and rtyp != nil: fillObjectFields(p.module, rtyp)
if field.loc.r == nil: internalError(e.info, "genRecordField 3 " & typeToString(ty)) if field.loc.r == nil: internalError(p.config, e.info, "genRecordField 3 " & typeToString(ty))
addf(r, ".$1", [field.loc.r]) addf(r, ".$1", [field.loc.r])
putIntoDest(p, d, e, r, a.storage) putIntoDest(p, d, e, r, a.storage)
@ -832,7 +832,7 @@ proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
let field = lookupFieldAgain(p, ty, f, r) let field = lookupFieldAgain(p, ty, f, r)
if field.loc.r == nil: fillObjectFields(p.module, ty) if field.loc.r == nil: fillObjectFields(p.module, ty)
if field.loc.r == nil: if field.loc.r == nil:
internalError(e.info, "genCheckedRecordField") # generate the checks: internalError(p.config, e.info, "genCheckedRecordField") # generate the checks:
genFieldCheck(p, e, r, field) genFieldCheck(p, e, r, field)
add(r, rfmt(nil, ".$1", field.loc.r)) add(r, rfmt(nil, ".$1", field.loc.r))
putIntoDest(p, d, e.sons[0], r, a.storage) putIntoDest(p, d, e.sons[0], r, a.storage)
@ -859,7 +859,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) =
else: else:
let idx = getOrdValue(y) let idx = getOrdValue(y)
if idx < firstOrd(ty) or idx > lastOrd(ty): if idx < firstOrd(ty) or idx > lastOrd(ty):
localError(x.info, errIndexOutOfBounds) localError(p.config, x.info, "index out of bounds")
d.inheritLocation(a) d.inheritLocation(a)
putIntoDest(p, d, n, putIntoDest(p, d, n,
rfmt(nil, "$1[($2)- $3]", rdLoc(a), rdCharLoc(b), first), a.storage) rfmt(nil, "$1[($2)- $3]", rdLoc(a), rdCharLoc(b), first), a.storage)
@ -932,7 +932,7 @@ proc genBracketExpr(p: BProc; n: PNode; d: var TLoc) =
of tySequence, tyString: genSeqElem(p, n, n.sons[0], n.sons[1], d) of tySequence, tyString: genSeqElem(p, n, n.sons[0], n.sons[1], d)
of tyCString: genCStringElem(p, n, n.sons[0], n.sons[1], d) of tyCString: genCStringElem(p, n, n.sons[0], n.sons[1], d)
of tyTuple: genTupleElem(p, n, d) of tyTuple: genTupleElem(p, n, d)
else: internalError(n.info, "expr(nkBracketExpr, " & $ty.kind & ')') else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
proc genAndOr(p: BProc, e: PNode, d: var TLoc, m: TMagic) = proc genAndOr(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
# how to generate code? # how to generate code?
@ -977,7 +977,7 @@ proc genAndOr(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
proc genEcho(p: BProc, n: PNode) = proc genEcho(p: BProc, n: PNode) =
# this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)`` # this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)``
# is threadsafe. # is threadsafe.
internalAssert n.kind == nkBracket internalAssert p.config, n.kind == nkBracket
if platform.targetOS == osGenode: if platform.targetOS == osGenode:
# bypass libc and print directly to the Genode LOG session # bypass libc and print directly to the Genode LOG session
var args: Rope = nil var args: Rope = nil
@ -1003,8 +1003,8 @@ proc genEcho(p: BProc, n: PNode) =
makeCString(repeat("%s", n.len) & tnl), args) makeCString(repeat("%s", n.len) & tnl), args)
linefmt(p, cpsStmts, "fflush(stdout);$n") linefmt(p, cpsStmts, "fflush(stdout);$n")
proc gcUsage(n: PNode) = proc gcUsage(conf: ConfigRef; n: PNode) =
if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree) if gSelectedGC == gcNone: message(conf, n.info, warnGcMem, n.renderTree)
proc genStrConcat(p: BProc, e: PNode, d: var TLoc) = proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
# <Nim code> # <Nim code>
@ -1046,7 +1046,7 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
d = tmp d = tmp
else: else:
genAssignment(p, d, tmp, {}) # no need for deep copying genAssignment(p, d, tmp, {}) # no need for deep copying
gcUsage(e) gcUsage(p.config, e)
proc genStrAppend(p: BProc, e: PNode, d: var TLoc) = proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
# <Nim code> # <Nim code>
@ -1083,7 +1083,7 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
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))
add(p.s(cpsStmts), appends) add(p.s(cpsStmts), appends)
gcUsage(e) gcUsage(p.config, e)
proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) = proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
# seq &= x --> # seq &= x -->
@ -1108,7 +1108,7 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
lineCg(p, cpsStmts, "$1 = $2->$3++;$n", tmpL.r, rdLoc(a), lenField(p)) lineCg(p, cpsStmts, "$1 = $2->$3++;$n", tmpL.r, rdLoc(a), lenField(p))
dest.r = rfmt(nil, "$1->data[$2]", rdLoc(a), tmpL.r) dest.r = rfmt(nil, "$1->data[$2]", rdLoc(a), tmpL.r)
genAssignment(p, dest, b, {needToCopy, afDestIsNil}) genAssignment(p, dest, b, {needToCopy, afDestIsNil})
gcUsage(e) gcUsage(p.config, e)
proc genReset(p: BProc, n: PNode) = proc genReset(p: BProc, n: PNode) =
var a: TLoc var a: TLoc
@ -1131,7 +1131,7 @@ proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) =
let args = [getTypeDesc(p.module, typ), let args = [getTypeDesc(p.module, typ),
genTypeInfo(p.module, typ, a.lode.info), genTypeInfo(p.module, typ, a.lode.info),
sizeExpr] sizeExpr]
if a.storage == OnHeap and usesNativeGC(): if a.storage == OnHeap and usesNativeGC(p.config):
# use newObjRC1 as an optimization # use newObjRC1 as an optimization
if canFormAcycle(a.t): if canFormAcycle(a.t):
linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", a.rdLoc) linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", a.rdLoc)
@ -1154,7 +1154,7 @@ proc genNew(p: BProc, e: PNode) =
rawGenNew(p, a, se.rdLoc) rawGenNew(p, a, se.rdLoc)
else: else:
rawGenNew(p, a, nil) rawGenNew(p, a, nil)
gcUsage(e) gcUsage(p.config, e)
proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) = proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) =
let seqtype = skipTypes(dest.t, abstractVarRange) let seqtype = skipTypes(dest.t, abstractVarRange)
@ -1162,7 +1162,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) =
genTypeInfo(p.module, seqtype, dest.lode.info), length] genTypeInfo(p.module, seqtype, dest.lode.info), length]
var call: TLoc var call: TLoc
initLoc(call, locExpr, dest.lode, OnHeap) initLoc(call, locExpr, dest.lode, OnHeap)
if dest.storage == OnHeap and usesNativeGC(): if dest.storage == OnHeap and usesNativeGC(p.config):
if canFormAcycle(dest.t): if canFormAcycle(dest.t):
linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", dest.rdLoc) linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", dest.rdLoc)
else: else:
@ -1178,7 +1178,7 @@ proc genNewSeq(p: BProc, e: PNode) =
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b) initLocExpr(p, e.sons[2], b)
genNewSeqAux(p, a, b.rdLoc) genNewSeqAux(p, a, b.rdLoc)
gcUsage(e) gcUsage(p.config, e)
proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
let seqtype = skipTypes(e.typ, abstractVarRange) let seqtype = skipTypes(e.typ, abstractVarRange)
@ -1188,7 +1188,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
"($1)#nimNewSeqOfCap($2, $3)", [ "($1)#nimNewSeqOfCap($2, $3)", [
getTypeDesc(p.module, seqtype), getTypeDesc(p.module, seqtype),
genTypeInfo(p.module, seqtype, e.info), a.rdLoc])) genTypeInfo(p.module, seqtype, e.info), a.rdLoc]))
gcUsage(e) gcUsage(p.config, e)
proc genConstExpr(p: BProc, n: PNode): Rope proc genConstExpr(p: BProc, n: PNode): Rope
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
@ -1230,7 +1230,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
rawGenNew(p, tmp, nil) rawGenNew(p, tmp, nil)
t = t.lastSon.skipTypes(abstractInst) t = t.lastSon.skipTypes(abstractInst)
r = "(*$1)" % [r] r = "(*$1)" % [r]
gcUsage(e) gcUsage(p.config, e)
else: else:
constructLoc(p, tmp) constructLoc(p, tmp)
else: else:
@ -1244,7 +1244,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
tmp2.r = r tmp2.r = r
let field = lookupFieldAgain(p, ty, it.sons[0].sym, tmp2.r) let field = lookupFieldAgain(p, ty, it.sons[0].sym, tmp2.r)
if field.loc.r == nil: fillObjectFields(p.module, ty) if field.loc.r == nil: fillObjectFields(p.module, ty)
if field.loc.r == nil: internalError(e.info, "genObjConstr") if field.loc.r == nil: internalError(p.config, e.info, "genObjConstr")
if it.len == 3 and optFieldCheck in p.options: if it.len == 3 and optFieldCheck in p.options:
genFieldCheck(p, it.sons[2], r, field) genFieldCheck(p, it.sons[2], r, field)
add(tmp2.r, ".") add(tmp2.r, ".")
@ -1283,7 +1283,7 @@ proc genSeqConstr(p: BProc, n: PNode, d: var TLoc) =
arr.r = rfmt(nil, "$1->data[$2]", rdLoc(dest[]), intLiteral(i)) arr.r = rfmt(nil, "$1->data[$2]", rdLoc(dest[]), intLiteral(i))
arr.storage = OnHeap # we know that sequences are on the heap arr.storage = OnHeap # we know that sequences are on the heap
expr(p, n[i], arr) expr(p, n[i], arr)
gcUsage(n) gcUsage(p.config, n)
if doesAlias: if doesAlias:
if d.k == locNone: if d.k == locNone:
d = tmp d = tmp
@ -1313,7 +1313,7 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) =
genAssignment(p, elem, arr, {afDestIsNil, needToCopy}) genAssignment(p, elem, arr, {afDestIsNil, needToCopy})
else: else:
var i: TLoc var i: TLoc
getTemp(p, getSysType(tyInt), i) getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), i)
let oldCode = p.s(cpsStmts) let oldCode = p.s(cpsStmts)
linefmt(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n", i.r, L.rope) linefmt(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n", i.r, L.rope)
initLoc(elem, locExpr, lodeTyp elemType(skipTypes(n.typ, abstractInst)), OnHeap) initLoc(elem, locExpr, lodeTyp elemType(skipTypes(n.typ, abstractInst)), OnHeap)
@ -1342,7 +1342,7 @@ proc genNewFinalize(p: BProc, e: PNode) =
genAssignment(p, a, b, {}) # 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(p.config, e)
proc genOfHelper(p: BProc; dest: PType; a: Rope; info: TLineInfo): Rope = proc genOfHelper(p: BProc; dest: PType; a: Rope; info: TLineInfo): Rope =
# unfortunately 'genTypeInfo' sets tfObjHasKids as a side effect, so we # unfortunately 'genTypeInfo' sets tfObjHasKids as a side effect, so we
@ -1380,7 +1380,7 @@ proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
add(r, ~".Sup") add(r, ~".Sup")
t = skipTypes(t.sons[0], skipPtrs) t = skipTypes(t.sons[0], skipPtrs)
if isObjLackingTypeField(t): if isObjLackingTypeField(t):
globalError(x.info, errGenerated, globalError(p.config, x.info,
"no 'of' operator available for pure objects") "no 'of' operator available for pure objects")
if nilCheck != nil: if nilCheck != nil:
r = rfmt(p.module, "(($1) && ($2))", nilCheck, genOfHelper(p, dest, r, x.info)) r = rfmt(p.module, "(($1) && ($2))", nilCheck, genOfHelper(p, dest, r, x.info))
@ -1425,7 +1425,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) =
of tyArray: of tyArray:
putIntoDest(p, b, e, putIntoDest(p, b, e,
"$1, $2" % [rdLoc(a), rope(lengthOrd(a.t))], a.storage) "$1, $2" % [rdLoc(a), rope(lengthOrd(a.t))], a.storage)
else: internalError(e.sons[0].info, "genRepr()") else: internalError(p.config, e.sons[0].info, "genRepr()")
putIntoDest(p, d, e, putIntoDest(p, d, e,
ropecg(p.module, "#reprOpenArray($1, $2)", [rdLoc(b), ropecg(p.module, "#reprOpenArray($1, $2)", [rdLoc(b),
genTypeInfo(p.module, elemType(t), e.info)]), a.storage) genTypeInfo(p.module, elemType(t), e.info)]), a.storage)
@ -1434,12 +1434,12 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) =
ropecg(p.module, "#reprAny($1, $2)", [ ropecg(p.module, "#reprAny($1, $2)", [
rdLoc(a), genTypeInfo(p.module, t, e.info)]), a.storage) rdLoc(a), genTypeInfo(p.module, t, e.info)]), a.storage)
of tyEmpty, tyVoid: of tyEmpty, tyVoid:
localError(e.info, "'repr' doesn't support 'void' type") localError(p.config, e.info, "'repr' doesn't support 'void' type")
else: else:
putIntoDest(p, d, e, ropecg(p.module, "#reprAny($1, $2)", putIntoDest(p, d, e, ropecg(p.module, "#reprAny($1, $2)",
[addrLoc(a), genTypeInfo(p.module, t, e.info)]), [addrLoc(a), genTypeInfo(p.module, t, e.info)]),
a.storage) a.storage)
gcUsage(e) gcUsage(p.config, e)
proc genGetTypeInfo(p: BProc, e: PNode, d: var TLoc) = proc genGetTypeInfo(p: BProc, e: PNode, d: var TLoc) =
let t = e.sons[1].typ let t = e.sons[1].typ
@ -1451,7 +1451,7 @@ proc genDollar(p: BProc, n: PNode, d: var TLoc, frmt: string) =
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, {}) genAssignment(p, d, a, {})
gcUsage(n) gcUsage(p.config, n)
proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
var a = e.sons[1] var a = e.sons[1]
@ -1493,7 +1493,7 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
# YYY: length(sideeffect) is optimized away incorrectly? # YYY: length(sideeffect) is optimized away incorrectly?
if op == mHigh: putIntoDest(p, d, e, rope(lastOrd(typ))) if op == mHigh: putIntoDest(p, d, e, rope(lastOrd(typ)))
else: putIntoDest(p, d, e, rope(lengthOrd(typ))) else: putIntoDest(p, d, e, rope(lengthOrd(typ)))
else: internalError(e.info, "genArrayLen()") else: internalError(p.config, e.info, "genArrayLen()")
proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) = proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
var a, b: TLoc var a, b: TLoc
@ -1511,11 +1511,11 @@ 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),
genTypeInfo(p.module, t.skipTypes(abstractInst), e.info)]) genTypeInfo(p.module, t.skipTypes(abstractInst), e.info)])
gcUsage(e) gcUsage(p.config, 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")
gcUsage(e) gcUsage(p.config, e)
proc genSwap(p: BProc, e: PNode, d: var TLoc) = proc genSwap(p: BProc, e: PNode, d: var TLoc) =
# swap(a, b) --> # swap(a, b) -->
@ -1541,7 +1541,7 @@ proc rdSetElemLoc(a: TLoc, setType: PType): Rope =
proc fewCmps(s: PNode): bool = proc fewCmps(s: PNode): bool =
# this function estimates whether it is better to emit code # this function estimates whether it is better to emit code
# for constructing the set or generating a bunch of comparisons directly # for constructing the set or generating a bunch of comparisons directly
if s.kind != nkCurly: internalError(s.info, "fewCmps") if s.kind != nkCurly: return false
if (getSize(s.typ) <= platform.intSize) and (nfAllConst in s.flags): if (getSize(s.typ) <= platform.intSize) and (nfAllConst in s.flags):
result = false # it is better to emit the set generation code result = false # it is better to emit the set generation code
elif elemType(s.typ).kind in {tyInt, tyInt16..tyInt64}: elif elemType(s.typ).kind in {tyInt, tyInt16..tyInt64}:
@ -1637,17 +1637,17 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mSymDiffSet: binaryExpr(p, e, d, "($1 ^ $2)") of mSymDiffSet: binaryExpr(p, e, d, "($1 ^ $2)")
of mInSet: of mInSet:
genInOp(p, e, d) genInOp(p, e, d)
else: internalError(e.info, "genSetOp()") else: internalError(p.config, e.info, "genSetOp()")
else: else:
case op case op
of mIncl: binaryStmtInExcl(p, e, d, "$1[(NU)($2)>>3] |=(1U<<($2&7U));$n") of mIncl: binaryStmtInExcl(p, e, d, "$1[(NU)($2)>>3] |=(1U<<($2&7U));$n")
of mExcl: binaryStmtInExcl(p, e, d, "$1[(NU)($2)>>3] &= ~(1U<<($2&7U));$n") of mExcl: binaryStmtInExcl(p, e, d, "$1[(NU)($2)>>3] &= ~(1U<<($2&7U));$n")
of mCard: unaryExprChar(p, e, d, "#cardSet($1, " & $size & ')') of mCard: unaryExprChar(p, e, d, "#cardSet($1, " & $size & ')')
of mLtSet, mLeSet: of mLtSet, mLeSet:
getTemp(p, getSysType(tyInt), i) # our counter getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), i) # our counter
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b) initLocExpr(p, e.sons[2], b)
if d.k == locNone: getTemp(p, getSysType(tyBool), d) if d.k == locNone: getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyBool), d)
lineF(p, cpsStmts, lookupOpr[op], lineF(p, cpsStmts, lookupOpr[op],
[rdLoc(i), rope(size), rdLoc(d), rdLoc(a), rdLoc(b)]) [rdLoc(i), rope(size), rdLoc(d), rdLoc(a), rdLoc(b)])
of mEqSet: of mEqSet:
@ -1655,7 +1655,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)") binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)")
of mMulSet, mPlusSet, mMinusSet, mSymDiffSet: of mMulSet, mPlusSet, mMinusSet, mSymDiffSet:
# we inline the simple for loop for better code generation: # we inline the simple for loop for better code generation:
getTemp(p, getSysType(tyInt), i) # our counter getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), i) # our counter
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b) initLocExpr(p, e.sons[2], b)
if d.k == locNone: getTemp(p, a.t, d) if d.k == locNone: getTemp(p, a.t, d)
@ -1665,7 +1665,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
rdLoc(i), rope(size), rdLoc(d), rdLoc(a), rdLoc(b), rdLoc(i), rope(size), rdLoc(d), rdLoc(a), rdLoc(b),
rope(lookupOpr[op])]) rope(lookupOpr[op])])
of mInSet: genInOp(p, e, d) of mInSet: genInOp(p, e, d)
else: internalError(e.info, "genSetOp") else: internalError(p.config, e.info, "genSetOp")
proc genOrd(p: BProc, e: PNode, d: var TLoc) = proc genOrd(p: BProc, e: PNode, d: var TLoc) =
unaryExprChar(p, e, d, "$1") unaryExprChar(p, e, d, "$1")
@ -1753,7 +1753,7 @@ proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) =
putIntoDest(p, d, n, putIntoDest(p, d, n,
ropecg(p.module, "#cstrToNimstr($1)", [rdLoc(a)]), ropecg(p.module, "#cstrToNimstr($1)", [rdLoc(a)]),
a.storage) a.storage)
gcUsage(n) gcUsage(p.config, n)
proc genStrEquals(p: BProc, e: PNode, d: var TLoc) = proc genStrEquals(p: BProc, e: PNode, d: var TLoc) =
var x: TLoc var x: TLoc
@ -1887,12 +1887,12 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mEcho: genEcho(p, e[1].skipConv) of mEcho: genEcho(p, e[1].skipConv)
of mArrToSeq: genArrToSeq(p, e, d) of mArrToSeq: genArrToSeq(p, e, d)
of mNLen..mNError, mSlurp..mQuoteAst: of mNLen..mNError, mSlurp..mQuoteAst:
localError(e.info, errXMustBeCompileTime, e.sons[0].sym.name.s) localError(p.config, e.info, strutils.`%`(errXMustBeCompileTime, e.sons[0].sym.name.s))
of mSpawn: of mSpawn:
let n = lowerings.wrapProcForSpawn(p.module.module, e, e.typ, nil, nil) let n = lowerings.wrapProcForSpawn(p.module.g.graph, p.module.module, e, e.typ, nil, nil)
expr(p, n, d) expr(p, n, d)
of mParallel: of mParallel:
let n = semparallel.liftParallel(p.module.module, e) let n = semparallel.liftParallel(p.module.g.graph, p.module.module, e)
expr(p, n, d) expr(p, n, d)
of mDeepCopy: of mDeepCopy:
var a, b: TLoc var a, b: TLoc
@ -1904,7 +1904,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
else: else:
when defined(debugMagics): when defined(debugMagics):
echo p.prc.name.s, " ", p.prc.id, " ", p.prc.flags, " ", p.prc.ast[genericParamsPos].kind echo p.prc.name.s, " ", p.prc.id, " ", p.prc.flags, " ", p.prc.ast[genericParamsPos].kind
internalError(e.info, "genMagicExpr: " & $op) internalError(p.config, e.info, "genMagicExpr: " & $op)
proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = proc genSetConstr(p: BProc, e: PNode, d: var TLoc) =
# example: { a..b, c, d, e, f..g } # example: { a..b, c, d, e, f..g }
@ -1924,7 +1924,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) =
[rdLoc(d), getTypeDesc(p.module, e.typ)]) [rdLoc(d), getTypeDesc(p.module, e.typ)])
for it in e.sons: for it in e.sons:
if it.kind == nkRange: if it.kind == nkRange:
getTemp(p, getSysType(tyInt), idx) # our counter getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), idx) # our counter
initLocExpr(p, it.sons[0], a) initLocExpr(p, it.sons[0], a)
initLocExpr(p, it.sons[1], b) initLocExpr(p, it.sons[1], b)
lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" & lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" &
@ -1940,7 +1940,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) =
lineF(p, cpsStmts, "$1 = 0;$n", [rdLoc(d)]) lineF(p, cpsStmts, "$1 = 0;$n", [rdLoc(d)])
for it in e.sons: for it in e.sons:
if it.kind == nkRange: if it.kind == nkRange:
getTemp(p, getSysType(tyInt), idx) # our counter getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), idx) # our counter
initLocExpr(p, it.sons[0], a) initLocExpr(p, it.sons[0], a)
initLocExpr(p, it.sons[1], b) initLocExpr(p, it.sons[1], b)
lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" & lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" &
@ -1984,7 +1984,7 @@ proc genClosure(p: BProc, n: PNode, d: var TLoc) =
initLocExpr(p, n.sons[0], a) initLocExpr(p, n.sons[0], a)
initLocExpr(p, n.sons[1], b) initLocExpr(p, n.sons[1], b)
if n.sons[0].skipConv.kind == nkClosure: if n.sons[0].skipConv.kind == nkClosure:
internalError(n.info, "closure to closure created") internalError(p.config, n.info, "closure to closure created")
# tasyncawait.nim breaks with this optimization: # tasyncawait.nim breaks with this optimization:
when false: when false:
if d.k != locNone: if d.k != locNone:
@ -2146,11 +2146,11 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
#if sym.kind == skIterator: #if sym.kind == skIterator:
# echo renderTree(sym.getBody, {renderIds}) # echo renderTree(sym.getBody, {renderIds})
if sfCompileTime in sym.flags: if sfCompileTime in sym.flags:
localError(n.info, "request to generate code for .compileTime proc: " & localError(p.config, n.info, "request to generate code for .compileTime proc: " &
sym.name.s) sym.name.s)
genProc(p.module, sym) genProc(p.module, sym)
if sym.loc.r == nil or sym.loc.lode == nil: if sym.loc.r == nil or sym.loc.lode == nil:
internalError(n.info, "expr: proc not init " & sym.name.s) internalError(p.config, n.info, "expr: proc not init " & sym.name.s)
putLocIntoDest(p, d, sym.loc) putLocIntoDest(p, d, sym.loc)
of skConst: of skConst:
if isSimpleConst(sym.typ): if isSimpleConst(sym.typ):
@ -2168,10 +2168,10 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
if sym.loc.r == nil or sym.loc.t == nil: if sym.loc.r == nil or sym.loc.t == nil:
#echo "FAILED FOR PRCO ", p.prc.name.s #echo "FAILED FOR PRCO ", p.prc.name.s
#echo renderTree(p.prc.ast, {renderIds}) #echo renderTree(p.prc.ast, {renderIds})
internalError n.info, "expr: var not init " & sym.name.s & "_" & $sym.id internalError p.config, n.info, "expr: var not init " & sym.name.s & "_" & $sym.id
if sfThread in sym.flags: if sfThread in sym.flags:
accessThreadLocalVar(p, sym) accessThreadLocalVar(p, sym)
if emulatedThreadVars(): if emulatedThreadVars(p.config):
putIntoDest(p, d, sym.loc.lode, "NimTV_->" & sym.loc.r) putIntoDest(p, d, sym.loc.lode, "NimTV_->" & sym.loc.r)
else: else:
putLocIntoDest(p, d, sym.loc) putLocIntoDest(p, d, sym.loc)
@ -2181,16 +2181,16 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
if sym.loc.r == nil or sym.loc.t == nil: if sym.loc.r == nil or sym.loc.t == nil:
#echo "FAILED FOR PRCO ", p.prc.name.s #echo "FAILED FOR PRCO ", p.prc.name.s
#echo renderTree(p.prc.ast, {renderIds}) #echo renderTree(p.prc.ast, {renderIds})
internalError(n.info, "expr: temp not init " & sym.name.s & "_" & $sym.id) internalError(p.config, n.info, "expr: temp not init " & sym.name.s & "_" & $sym.id)
putLocIntoDest(p, d, sym.loc) putLocIntoDest(p, d, sym.loc)
of skParam: of skParam:
if sym.loc.r == nil or sym.loc.t == nil: if sym.loc.r == nil or sym.loc.t == nil:
# echo "FAILED FOR PRCO ", p.prc.name.s # echo "FAILED FOR PRCO ", p.prc.name.s
# debug p.prc.typ.n # debug p.prc.typ.n
# echo renderTree(p.prc.ast, {renderIds}) # echo renderTree(p.prc.ast, {renderIds})
internalError(n.info, "expr: param not init " & sym.name.s & "_" & $sym.id) internalError(p.config, n.info, "expr: param not init " & sym.name.s & "_" & $sym.id)
putLocIntoDest(p, d, sym.loc) putLocIntoDest(p, d, sym.loc)
else: internalError(n.info, "expr(" & $sym.kind & "); unknown symbol") else: internalError(p.config, n.info, "expr(" & $sym.kind & "); unknown symbol")
of nkNilLit: of nkNilLit:
if not isEmptyType(n.typ): if not isEmptyType(n.typ):
putIntoDest(p, d, n, genLiteral(p, n)) putIntoDest(p, d, n, genLiteral(p, n))
@ -2259,7 +2259,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
var sym = n.sons[namePos].sym var sym = n.sons[namePos].sym
genProc(p.module, sym) genProc(p.module, sym)
if sym.loc.r == nil or sym.loc.lode == nil: if sym.loc.r == nil or sym.loc.lode == nil:
internalError(n.info, "expr: proc not init " & sym.name.s) internalError(p.config, n.info, "expr: proc not init " & sym.name.s)
putLocIntoDest(p, d, sym.loc) putLocIntoDest(p, d, sym.loc)
of nkClosure: genClosure(p, n, d) of nkClosure: genClosure(p, n, d)
@ -2267,7 +2267,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
of nkWhileStmt: genWhileStmt(p, n) of nkWhileStmt: genWhileStmt(p, n)
of nkVarSection, nkLetSection: genVarStmt(p, n) of nkVarSection, nkLetSection: genVarStmt(p, n)
of nkConstSection: discard # consts generated lazily on use of nkConstSection: discard # consts generated lazily on use
of nkForStmt: internalError(n.info, "for statement not eliminated") of nkForStmt: internalError(p.config, n.info, "for statement not eliminated")
of nkCaseStmt: genCase(p, n, d) of nkCaseStmt: genCase(p, n, d)
of nkReturnStmt: genReturnStmt(p, n) of nkReturnStmt: genReturnStmt(p, n)
of nkBreakStmt: genBreakStmt(p, n) of nkBreakStmt: genBreakStmt(p, n)
@ -2327,7 +2327,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
of nkState: genState(p, n) of nkState: genState(p, n)
of nkGotoState: genGotoState(p, n) of nkGotoState: genGotoState(p, n)
of nkBreakState: genBreakState(p, n) of nkBreakState: genBreakState(p, n)
else: internalError(n.info, "expr(" & $n.kind & "); unknown node kind") else: internalError(p.config, n.info, "expr(" & $n.kind & "); unknown node kind")
proc genNamedConstExpr(p: BProc, n: PNode): Rope = proc genNamedConstExpr(p: BProc, n: PNode): Rope =
if n.kind == nkExprColonExpr: result = genConstExpr(p, n.sons[1]) if n.kind == nkExprColonExpr: result = genConstExpr(p, n.sons[1])
@ -2363,7 +2363,7 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
if mapType(t) == ctArray: result = rope"{}" if mapType(t) == ctArray: result = rope"{}"
else: result = rope"0" else: result = rope"0"
else: else:
globalError(info, "cannot create null element for: " & $t.kind) globalError(p.config, info, "cannot create null element for: " & $t.kind)
proc getNullValueAux(p: BProc; t: PType; obj, cons: PNode, result: var Rope; count: var int) = proc getNullValueAux(p: BProc; t: PType; obj, cons: PNode, result: var Rope; count: var int) =
case obj.kind case obj.kind
@ -2389,7 +2389,7 @@ proc getNullValueAux(p: BProc; t: PType; obj, cons: PNode, result: var Rope; cou
# not found, produce default value: # not found, produce default value:
result.add getDefaultValue(p, field.typ, cons.info) result.add getDefaultValue(p, field.typ, cons.info)
else: else:
localError(cons.info, "cannot create null element for: " & $obj) localError(p.config, cons.info, "cannot create null element for: " & $obj)
proc getNullValueAuxT(p: BProc; orig, t: PType; obj, cons: PNode, result: var Rope; count: var int) = proc getNullValueAuxT(p: BProc; orig, t: PType; obj, cons: PNode, result: var Rope; count: var int) =
var base = t.sons[0] var base = t.sons[0]

View file

@ -15,7 +15,7 @@
template detectVersion(field, corename) = template detectVersion(field, corename) =
if m.g.field == 0: if m.g.field == 0:
let core = getCompilerProc(m.g. corename) let core = getCompilerProc(m.g.graph, corename)
if core == nil or core.kind != skConst: if core == nil or core.kind != skConst:
m.g.field = 1 m.g.field = 1
else: else:
@ -74,7 +74,7 @@ proc genStringLiteralDataOnly(m: BModule; s: string; info: TLineInfo): Rope =
of 0, 1: result = genStringLiteralDataOnlyV1(m, s) of 0, 1: result = genStringLiteralDataOnlyV1(m, s)
of 2: result = genStringLiteralDataOnlyV2(m, s) of 2: result = genStringLiteralDataOnlyV2(m, s)
else: else:
localError(info, "cannot determine how to produce code for string literal") localError(m.config, info, "cannot determine how to produce code for string literal")
proc genStringLiteralFromData(m: BModule; data: Rope; info: TLineInfo): Rope = proc genStringLiteralFromData(m: BModule; data: Rope; info: TLineInfo): Rope =
result = ropecg(m, "((#NimStringDesc*) &$1)", result = ropecg(m, "((#NimStringDesc*) &$1)",
@ -88,4 +88,4 @@ proc genStringLiteral(m: BModule; n: PNode): Rope =
of 0, 1: result = genStringLiteralV1(m, n) of 0, 1: result = genStringLiteralV1(m, n)
of 2: result = genStringLiteralV2(m, n) of 2: result = genStringLiteralV2(m, n)
else: else:
localError(n.info, "cannot determine how to produce code for string literal") localError(m.config, n.info, "cannot determine how to produce code for string literal")

View file

@ -43,13 +43,13 @@ proc inExceptBlockLen(p: BProc): int =
proc genVarTuple(p: BProc, n: PNode) = proc genVarTuple(p: BProc, n: PNode) =
var tup, field: TLoc var tup, field: TLoc
if n.kind != nkVarTuple: internalError(n.info, "genVarTuple") if n.kind != nkVarTuple: internalError(p.config, n.info, "genVarTuple")
var L = sonsLen(n) var L = sonsLen(n)
# if we have a something that's been captured, use the lowering instead: # if we have a something that's been captured, use the lowering instead:
for i in countup(0, L-3): for i in countup(0, L-3):
if n[i].kind != nkSym: if n[i].kind != nkSym:
genStmts(p, lowerTupleUnpacking(n, p.prc)) genStmts(p, lowerTupleUnpacking(p.module.g.graph, n, p.prc))
return return
genLineDir(p, n) genLineDir(p, n)
@ -70,7 +70,7 @@ proc genVarTuple(p: BProc, n: PNode) =
if t.kind == tyTuple: if t.kind == tyTuple:
field.r = "$1.Field$2" % [rdLoc(tup), rope(i)] field.r = "$1.Field$2" % [rdLoc(tup), rope(i)]
else: else:
if t.n.sons[i].kind != nkSym: internalError(n.info, "genVarTuple") if t.n.sons[i].kind != nkSym: internalError(p.config, n.info, "genVarTuple")
field.r = "$1.$2" % [rdLoc(tup), mangleRecFieldName(p.module, t.n.sons[i].sym, t)] field.r = "$1.$2" % [rdLoc(tup), mangleRecFieldName(p.module, t.n.sons[i].sym, t)]
putLocIntoDest(p, v.loc, field) putLocIntoDest(p, v.loc, field)
@ -149,7 +149,7 @@ template preserveBreakIdx(body: untyped): untyped =
p.breakIdx = oldBreakIdx p.breakIdx = oldBreakIdx
proc genState(p: BProc, n: PNode) = proc genState(p: BProc, n: PNode) =
internalAssert n.len == 1 internalAssert p.config, n.len == 1
let n0 = n[0] let n0 = n[0]
if n0.kind == nkIntLit: if n0.kind == nkIntLit:
let idx = n.sons[0].intVal let idx = n.sons[0].intVal
@ -191,7 +191,7 @@ proc genBreakState(p: BProc, n: PNode) =
proc genGotoVar(p: BProc; value: PNode) = proc genGotoVar(p: BProc; value: PNode) =
if value.kind notin {nkCharLit..nkUInt64Lit}: if value.kind notin {nkCharLit..nkUInt64Lit}:
localError(value.info, "'goto' target must be a literal value") localError(p.config, value.info, "'goto' target must be a literal value")
else: else:
lineF(p, cpsStmts, "goto NIMSTATE_$#;$n", [value.intVal.rope]) lineF(p, cpsStmts, "goto NIMSTATE_$#;$n", [value.intVal.rope])
@ -325,7 +325,7 @@ proc genIf(p: BProc, n: PNode, d: var TLoc) =
startBlock(p) startBlock(p)
expr(p, it.sons[0], d) expr(p, it.sons[0], d)
endBlock(p) endBlock(p)
else: internalError(n.info, "genIf()") else: internalError(p.config, n.info, "genIf()")
if sonsLen(n) > 1: fixLabel(p, lend) if sonsLen(n) > 1: fixLabel(p, lend)
@ -383,7 +383,7 @@ proc genGotoForCase(p: BProc; caseStmt: PNode) =
let it = caseStmt.sons[i] let it = caseStmt.sons[i]
for j in 0 .. it.len-2: for j in 0 .. it.len-2:
if it.sons[j].kind == nkRange: if it.sons[j].kind == nkRange:
localError(it.info, "range notation not available for computed goto") localError(p.config, it.info, "range notation not available for computed goto")
return return
let val = getOrdValue(it.sons[j]) let val = getOrdValue(it.sons[j])
lineF(p, cpsStmts, "NIMSTATE_$#:$n", [val.rope]) lineF(p, cpsStmts, "NIMSTATE_$#:$n", [val.rope])
@ -398,19 +398,19 @@ proc genComputedGoto(p: BProc; n: PNode) =
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:
localError(it.info, localError(p.config, it.info,
"case statement must be exhaustive for computed goto"); return "case statement must be exhaustive for computed goto"); return
casePos = i casePos = i
let aSize = lengthOrd(it.sons[0].typ) let aSize = lengthOrd(it.sons[0].typ)
if aSize > 10_000: if aSize > 10_000:
localError(it.info, localError(p.config, it.info,
"case statement has too many cases for computed goto"); return "case statement has too many cases for computed goto"); return
arraySize = aSize.int arraySize = aSize.int
if firstOrd(it.sons[0].typ) != 0: if firstOrd(it.sons[0].typ) != 0:
localError(it.info, localError(p.config, it.info,
"case statement has to start at 0 for computed goto"); return "case statement has to start at 0 for computed goto"); return
if casePos < 0: if casePos < 0:
localError(n.info, "no case statement found for computed goto"); return localError(p.config, n.info, "no case statement found for computed goto"); return
var id = p.labels+1 var id = p.labels+1
inc p.labels, arraySize+1 inc p.labels, arraySize+1
let tmp = "TMP$1_" % [id.rope] let tmp = "TMP$1_" % [id.rope]
@ -444,7 +444,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
let it = caseStmt.sons[i] let it = caseStmt.sons[i]
for j in 0 .. it.len-2: for j in 0 .. it.len-2:
if it.sons[j].kind == nkRange: if it.sons[j].kind == nkRange:
localError(it.info, "range notation not available for computed goto") localError(p.config, it.info, "range notation not available for computed goto")
return return
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)])
@ -548,7 +548,7 @@ proc genBreakStmt(p: BProc, t: PNode) =
# an unnamed 'break' can only break a loop after 'transf' pass: # an unnamed 'break' can only break a loop after 'transf' pass:
while idx >= 0 and not p.blocks[idx].isLoop: dec idx while idx >= 0 and not p.blocks[idx].isLoop: dec idx
if idx < 0 or not p.blocks[idx].isLoop: if idx < 0 or not p.blocks[idx].isLoop:
internalError(t.info, "no loop to break") internalError(p.config, t.info, "no loop to break")
let label = assignLabel(p.blocks[idx]) let label = assignLabel(p.blocks[idx])
blockLeaveActions(p, blockLeaveActions(p,
p.nestedTryStmts.len - p.blocks[idx].nestedTryStmts, p.nestedTryStmts.len - p.blocks[idx].nestedTryStmts,
@ -876,17 +876,14 @@ proc genTry(p: BProc, t: PNode, d: var TLoc) =
p.module.includeHeader("<setjmp.h>") p.module.includeHeader("<setjmp.h>")
genLineDir(p, t) genLineDir(p, t)
var safePoint = getTempName(p.module) var safePoint = getTempName(p.module)
if getCompilerProc("Exception") != nil:
discard cgsym(p.module, "Exception") discard cgsym(p.module, "Exception")
else:
discard cgsym(p.module, "E_Base")
linefmt(p, cpsLocals, "#TSafePoint $1;$n", safePoint) linefmt(p, cpsLocals, "#TSafePoint $1;$n", safePoint)
linefmt(p, cpsStmts, "#pushSafePoint(&$1);$n", safePoint) linefmt(p, cpsStmts, "#pushSafePoint(&$1);$n", safePoint)
if isDefined("nimStdSetjmp"): if isDefined(p.config, "nimStdSetjmp"):
linefmt(p, cpsStmts, "$1.status = setjmp($1.context);$n", safePoint) linefmt(p, cpsStmts, "$1.status = setjmp($1.context);$n", safePoint)
elif isDefined("nimSigSetjmp"): elif isDefined(p.config, "nimSigSetjmp"):
linefmt(p, cpsStmts, "$1.status = sigsetjmp($1.context, 0);$n", safePoint) linefmt(p, cpsStmts, "$1.status = sigsetjmp($1.context, 0);$n", safePoint)
elif isDefined("nimRawSetjmp"): elif isDefined(p.config, "nimRawSetjmp"):
linefmt(p, cpsStmts, "$1.status = _setjmp($1.context);$n", safePoint) linefmt(p, cpsStmts, "$1.status = _setjmp($1.context);$n", safePoint)
else: else:
linefmt(p, cpsStmts, "$1.status = setjmp($1.context);$n", safePoint) linefmt(p, cpsStmts, "$1.status = setjmp($1.context);$n", safePoint)
@ -1139,4 +1136,4 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
proc genStmts(p: BProc, t: PNode) = proc genStmts(p: BProc, t: PNode) =
var a: TLoc var a: TLoc
expr(p, t, a) expr(p, t, a)
internalAssert a.k in {locNone, locTemp, locLocalVar} internalAssert p.config, a.k in {locNone, locTemp, locLocalVar}

View file

@ -12,11 +12,11 @@
# included from cgen.nim # included from cgen.nim
proc emulatedThreadVars(): bool = proc emulatedThreadVars(conf: ConfigRef): bool =
result = {optThreads, optTlsEmulation} <= gGlobalOptions result = {optThreads, optTlsEmulation} <= gGlobalOptions
proc accessThreadLocalVar(p: BProc, s: PSym) = proc accessThreadLocalVar(p: BProc, s: PSym) =
if emulatedThreadVars() and not p.threadVarAccessed: if emulatedThreadVars(p.config) and not p.threadVarAccessed:
p.threadVarAccessed = true p.threadVarAccessed = true
incl p.module.flags, usesThreadVars incl p.module.flags, usesThreadVars
addf(p.procSec(cpsLocals), "\tNimThreadVars* NimTV_;$n", []) addf(p.procSec(cpsLocals), "\tNimThreadVars* NimTV_;$n", [])
@ -37,7 +37,7 @@ var
# made to be one. # made to be one.
proc declareThreadVar(m: BModule, s: PSym, isExtern: bool) = proc declareThreadVar(m: BModule, s: PSym, isExtern: bool) =
if emulatedThreadVars(): if emulatedThreadVars(m.config):
# we gather all thread locals var into a struct; we need to allocate # we gather all thread locals var into a struct; we need to allocate
# storage for that somehow, can't use the thread local storage # storage for that somehow, can't use the thread local storage
# allocator for it :-( # allocator for it :-(

View file

@ -29,12 +29,12 @@ proc genTraverseProc(c: TTraversalClosure, accessor: Rope, n: PNode;
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
genTraverseProc(c, accessor, n.sons[i], typ) genTraverseProc(c, accessor, n.sons[i], typ)
of nkRecCase: of nkRecCase:
if (n.sons[0].kind != nkSym): internalError(n.info, "genTraverseProc") if (n.sons[0].kind != nkSym): internalError(c.p.config, n.info, "genTraverseProc")
var p = c.p var p = c.p
let disc = n.sons[0].sym let disc = n.sons[0].sym
if disc.loc.r == nil: fillObjectFields(c.p.module, typ) if disc.loc.r == nil: fillObjectFields(c.p.module, typ)
if disc.loc.t == nil: if disc.loc.t == nil:
internalError(n.info, "genTraverseProc()") internalError(c.p.config, n.info, "genTraverseProc()")
lineF(p, cpsStmts, "switch ($1.$2) {$n", [accessor, disc.loc.r]) lineF(p, cpsStmts, "switch ($1.$2) {$n", [accessor, disc.loc.r])
for i in countup(1, sonsLen(n) - 1): for i in countup(1, sonsLen(n) - 1):
let branch = n.sons[i] let branch = n.sons[i]
@ -51,9 +51,9 @@ proc genTraverseProc(c: TTraversalClosure, accessor: Rope, n: PNode;
if field.typ.kind == tyVoid: return if field.typ.kind == tyVoid: return
if field.loc.r == nil: fillObjectFields(c.p.module, typ) if field.loc.r == nil: fillObjectFields(c.p.module, typ)
if field.loc.t == nil: if field.loc.t == nil:
internalError(n.info, "genTraverseProc()") internalError(c.p.config, n.info, "genTraverseProc()")
genTraverseProc(c, "$1.$2" % [accessor, field.loc.r], field.loc.t) genTraverseProc(c, "$1.$2" % [accessor, field.loc.r], field.loc.t)
else: internalError(n.info, "genTraverseProc()") else: internalError(c.p.config, n.info, "genTraverseProc()")
proc parentObj(accessor: Rope; m: BModule): Rope {.inline.} = proc parentObj(accessor: Rope; m: BModule): Rope {.inline.} =
if not m.compileToCpp: if not m.compileToCpp:
@ -72,7 +72,7 @@ proc genTraverseProc(c: TTraversalClosure, accessor: Rope, typ: PType) =
of tyArray: of tyArray:
let arraySize = lengthOrd(typ.sons[0]) let arraySize = lengthOrd(typ.sons[0])
var i: TLoc var i: TLoc
getTemp(p, getSysType(tyInt), i) getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo(), tyInt), i)
let oldCode = p.s(cpsStmts) let oldCode = p.s(cpsStmts)
linefmt(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n", linefmt(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n",
i.r, arraySize.rope) i.r, arraySize.rope)
@ -105,7 +105,7 @@ proc genTraverseProcSeq(c: TTraversalClosure, accessor: Rope, typ: PType) =
var p = c.p var p = c.p
assert typ.kind == tySequence assert typ.kind == tySequence
var i: TLoc var i: TLoc
getTemp(p, getSysType(tyInt), i) getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo(), tyInt), i)
let oldCode = p.s(cpsStmts) let oldCode = p.s(cpsStmts)
lineF(p, cpsStmts, "for ($1 = 0; $1 < $2->$3; $1++) {$n", lineF(p, cpsStmts, "for ($1 = 0; $1 < $2->$3; $1++) {$n",
[i.r, accessor, rope(if c.p.module.compileToCpp: "len" else: "Sup.len")]) [i.r, accessor, rope(if c.p.module.compileToCpp: "len" else: "Sup.len")])
@ -157,7 +157,7 @@ proc genTraverseProcForGlobal(m: BModule, s: PSym; info: TLineInfo): Rope =
var sLoc = s.loc.r var sLoc = s.loc.r
result = getTempName(m) result = getTempName(m)
if sfThread in s.flags and emulatedThreadVars(): if sfThread in s.flags and emulatedThreadVars(m.config):
accessThreadLocalVar(p, s) accessThreadLocalVar(p, s)
sLoc = "NimTV_->" & sLoc sLoc = "NimTV_->" & sLoc

View file

@ -122,7 +122,7 @@ proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope =
# check consistency: # check consistency:
assert($typ.loc.r == $(typ.typeName & $sig)) assert($typ.loc.r == $(typ.typeName & $sig))
result = typ.loc.r result = typ.loc.r
if result == nil: internalError("getTypeName: " & $typ.kind) if result == nil: internalError(m.config, "getTypeName: " & $typ.kind)
proc mapSetType(typ: PType): TCTypeKind = proc mapSetType(typ: PType): TCTypeKind =
case int(getSize(typ)) case int(getSize(typ))
@ -142,7 +142,7 @@ proc mapType(typ: PType): TCTypeKind =
of tyOpenArray, tyArray, tyVarargs: result = ctArray of tyOpenArray, tyArray, tyVarargs: result = ctArray
of tyObject, tyTuple: result = ctStruct of tyObject, tyTuple: result = ctStruct
of tyUserTypeClasses: of tyUserTypeClasses:
internalAssert typ.isResolvedUserTypeClass doAssert typ.isResolvedUserTypeClass
return mapType(typ.lastSon) return mapType(typ.lastSon)
of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal, of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal,
tyTypeDesc, tyAlias, tySink, tyInferred: tyTypeDesc, tyAlias, tySink, tyInferred:
@ -156,7 +156,7 @@ proc mapType(typ: PType): TCTypeKind =
of 2: result = ctUInt16 of 2: result = ctUInt16
of 4: result = ctInt32 of 4: result = ctInt32
of 8: result = ctInt64 of 8: result = ctInt64
else: internalError("mapType") else: result = ctInt32
of tyRange: result = mapType(typ.sons[0]) of tyRange: result = mapType(typ.sons[0])
of tyPtr, tyVar, tyLent, tyRef, tyOptAsRef: of tyPtr, tyVar, tyLent, tyRef, tyOptAsRef:
var base = skipTypes(typ.lastSon, typedescInst) var base = skipTypes(typ.lastSon, typedescInst)
@ -183,8 +183,8 @@ proc mapType(typ: PType): TCTypeKind =
result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt)) result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt))
of tyStatic: of tyStatic:
if typ.n != nil: result = mapType(lastSon typ) if typ.n != nil: result = mapType(lastSon typ)
else: internalError("mapType") else: doAssert(false, "mapType")
else: internalError("mapType") else: doAssert(false, "mapType")
proc mapReturnType(typ: PType): TCTypeKind = proc mapReturnType(typ: PType): TCTypeKind =
#if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr #if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr
@ -239,7 +239,7 @@ proc cacheGetType(tab: TypeCache; sig: SigHash): Rope =
result = tab.getOrDefault(sig) result = tab.getOrDefault(sig)
proc addAbiCheck(m: BModule, t: PType, name: Rope) = proc addAbiCheck(m: BModule, t: PType, name: Rope) =
if isDefined("checkabi"): if isDefined(m.config, "checkabi"):
addf(m.s[cfsTypeInfo], "NIM_CHECK_SIZE($1, $2);$n", [name, rope(getSize(t))]) addf(m.s[cfsTypeInfo], "NIM_CHECK_SIZE($1, $2);$n", [name, rope(getSize(t))])
proc ccgIntroducedPtr(s: PSym): bool = proc ccgIntroducedPtr(s: PSym): bool =
@ -303,7 +303,7 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope =
of tyDistinct, tyRange, tyOrdinal: result = getSimpleTypeDesc(m, typ.sons[0]) of tyDistinct, tyRange, tyOrdinal: result = getSimpleTypeDesc(m, typ.sons[0])
of tyStatic: of tyStatic:
if typ.n != nil: result = getSimpleTypeDesc(m, lastSon typ) if typ.n != nil: result = getSimpleTypeDesc(m, lastSon typ)
else: internalError("tyStatic for getSimpleTypeDesc") else: internalError(m.config, "tyStatic for getSimpleTypeDesc")
of tyGenericInst, tyAlias, tySink: of tyGenericInst, tyAlias, tySink:
result = getSimpleTypeDesc(m, lastSon typ) result = getSimpleTypeDesc(m, lastSon typ)
else: result = nil else: result = nil
@ -347,7 +347,7 @@ proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope =
else: else:
pushType(m, concrete) pushType(m, concrete)
doAssert m.forwTypeCache[sig] == result doAssert m.forwTypeCache[sig] == result
else: internalError("getTypeForward(" & $typ.kind & ')') else: internalError(m.config, "getTypeForward(" & $typ.kind & ')')
proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope = proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope =
## like getTypeDescAux but creates only a *weak* dependency. In other words ## like getTypeDescAux but creates only a *weak* dependency. In other words
@ -389,7 +389,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
else: else:
rettype = getTypeDescAux(m, t.sons[0], check) rettype = getTypeDescAux(m, t.sons[0], check)
for i in countup(1, sonsLen(t.n) - 1): for i in countup(1, sonsLen(t.n) - 1):
if t.n.sons[i].kind != nkSym: internalError(t.n.info, "genProcParams") if t.n.sons[i].kind != nkSym: internalError(m.config, t.n.info, "genProcParams")
var param = t.n.sons[i].sym var param = t.n.sons[i].sym
if isCompileTimeOnly(param.typ): continue if isCompileTimeOnly(param.typ): continue
if params != nil: add(params, ~", ") if params != nil: add(params, ~", ")
@ -442,7 +442,7 @@ proc mangleRecFieldName(m: BModule; field: PSym, rectype: PType): Rope =
result = field.loc.r result = field.loc.r
else: else:
result = rope(mangleField(m, field.name)) result = rope(mangleField(m, field.name))
if result == nil: internalError(field.info, "mangleRecFieldName") if result == nil: internalError(m.config, field.info, "mangleRecFieldName")
proc genRecordFieldsAux(m: BModule, n: PNode, proc genRecordFieldsAux(m: BModule, n: PNode,
accessExpr: Rope, rectype: PType, accessExpr: Rope, rectype: PType,
@ -453,7 +453,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
add(result, genRecordFieldsAux(m, n.sons[i], accessExpr, rectype, check)) add(result, genRecordFieldsAux(m, n.sons[i], accessExpr, rectype, check))
of nkRecCase: of nkRecCase:
if n.sons[0].kind != nkSym: internalError(n.info, "genRecordFieldsAux") if n.sons[0].kind != nkSym: internalError(m.config, n.info, "genRecordFieldsAux")
add(result, genRecordFieldsAux(m, n.sons[0], accessExpr, rectype, check)) add(result, genRecordFieldsAux(m, n.sons[0], accessExpr, rectype, check))
let uname = rope(mangle(n.sons[0].sym.name.s) & 'U') let uname = rope(mangle(n.sons[0].sym.name.s) & 'U')
let ae = if accessExpr != nil: "$1.$2" % [accessExpr, uname] let ae = if accessExpr != nil: "$1.$2" % [accessExpr, uname]
@ -481,7 +481,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
addf(unionBody, "#pragma pack(pop)$n", []) addf(unionBody, "#pragma pack(pop)$n", [])
else: else:
add(unionBody, genRecordFieldsAux(m, k, ae, rectype, check)) add(unionBody, genRecordFieldsAux(m, k, ae, rectype, check))
else: internalError("genRecordFieldsAux(record case branch)") else: internalError(m.config, "genRecordFieldsAux(record case branch)")
if unionBody != nil: if unionBody != nil:
addf(result, "union{$n$1} $2;$n", [unionBody, uname]) addf(result, "union{$n$1} $2;$n", [unionBody, uname])
of nkSym: of nkSym:
@ -509,7 +509,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
# don't use fieldType here because we need the # don't use fieldType here because we need the
# tyGenericInst for C++ template support # tyGenericInst for C++ template support
addf(result, "$1 $2;$n", [getTypeDescAux(m, field.loc.t, check), sname]) addf(result, "$1 $2;$n", [getTypeDescAux(m, field.loc.t, check), sname])
else: internalError(n.info, "genRecordFieldsAux()") else: internalError(m.config, n.info, "genRecordFieldsAux()")
proc getRecordFields(m: BModule, typ: PType, check: var IntSet): Rope = proc getRecordFields(m: BModule, typ: PType, check: var IntSet): Rope =
result = genRecordFieldsAux(m, typ.n, nil, typ, check) result = genRecordFieldsAux(m, typ.n, nil, typ, check)
@ -556,7 +556,7 @@ proc getRecordDesc(m: BModule, typ: PType, name: Rope,
# proper request to generate popCurrentExceptionEx not possible for 2 reasons: # proper request to generate popCurrentExceptionEx not possible for 2 reasons:
# generated function will be below declared Exception type and circular dependency # generated function will be below declared Exception type and circular dependency
# between Exception and popCurrentExceptionEx function # between Exception and popCurrentExceptionEx function
result = genProcHeader(m, magicsys.getCompilerProc("popCurrentExceptionEx")) & ";" & rnl & result result = genProcHeader(m, magicsys.getCompilerProc(m.g.graph, "popCurrentExceptionEx")) & ";" & rnl & result
hasField = true hasField = true
else: else:
appcg(m, result, " {$n $1 Sup;$n", appcg(m, result, " {$n $1 Sup;$n",
@ -606,7 +606,7 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType =
# Make sure the index refers to one of the generic params of the type. # Make sure the index refers to one of the generic params of the type.
# XXX: we should catch this earlier and report it as a semantic error. # XXX: we should catch this earlier and report it as a semantic error.
if idx >= typ.len: if idx >= typ.len:
internalError "invalid apostrophe type parameter index" doAssert false, "invalid apostrophe type parameter index"
result = typ.sons[idx] result = typ.sons[idx]
for i in 1..stars: for i in 1..stars:
@ -619,7 +619,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
var t = origTyp.skipTypes(irrelevantForBackend) var t = origTyp.skipTypes(irrelevantForBackend)
if containsOrIncl(check, t.id): if containsOrIncl(check, t.id):
if not (isImportedCppType(origTyp) or isImportedCppType(t)): if not (isImportedCppType(origTyp) or isImportedCppType(t)):
internalError("cannot generate C type for: " & typeToString(origTyp)) internalError(m.config, "cannot generate C type for: " & typeToString(origTyp))
# XXX: this BUG is hard to fix -> we need to introduce helper structs, # XXX: this BUG is hard to fix -> we need to introduce helper structs,
# but determining when this needs to be done is hard. We should split # but determining when this needs to be done is hard. We should split
# C type generation into an analysis and a code generation phase somehow. # C type generation into an analysis and a code generation phase somehow.
@ -697,7 +697,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
of 2: addf(m.s[cfsTypes], "typedef NU16 $1;$n", [result]) of 2: addf(m.s[cfsTypes], "typedef NU16 $1;$n", [result])
of 4: addf(m.s[cfsTypes], "typedef NI32 $1;$n", [result]) of 4: addf(m.s[cfsTypes], "typedef NI32 $1;$n", [result])
of 8: addf(m.s[cfsTypes], "typedef NI64 $1;$n", [result]) of 8: addf(m.s[cfsTypes], "typedef NI64 $1;$n", [result])
else: internalError(t.sym.info, "getTypeDescAux: enum") else: internalError(m.config, t.sym.info, "getTypeDescAux: enum")
when false: when false:
let owner = hashOwner(t.sym) let owner = hashOwner(t.sym)
if not gDebugInfo.hasEnum(t.sym.name.s, t.sym.info.line, owner): if not gDebugInfo.hasEnum(t.sym.name.s, t.sym.info.line, owner):
@ -808,7 +808,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
if typeInSlot == nil or typeInSlot.kind == tyVoid: if typeInSlot == nil or typeInSlot.kind == tyVoid:
result.add(~"void") result.add(~"void")
elif typeInSlot.kind == tyStatic: elif typeInSlot.kind == tyStatic:
internalAssert typeInSlot.n != nil internalAssert m.config, typeInSlot.n != nil
result.add typeInSlot.n.renderTree result.add typeInSlot.n.renderTree
else: else:
result.add getTypeDescAux(m, typeInSlot, check) result.add getTypeDescAux(m, typeInSlot, check)
@ -875,7 +875,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
tyUserTypeClass, tyUserTypeClassInst, tyInferred: tyUserTypeClass, tyUserTypeClassInst, tyInferred:
result = getTypeDescAux(m, lastSon(t), check) result = getTypeDescAux(m, lastSon(t), check)
else: else:
internalError("getTypeDescAux(" & $t.kind & ')') internalError(m.config, "getTypeDescAux(" & $t.kind & ')')
result = nil result = nil
# fixes bug #145: # fixes bug #145:
excl(check, t.id) excl(check, t.id)
@ -968,7 +968,7 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType;
if flags != 0: if flags != 0:
addf(m.s[cfsTypeInit3], "$1.flags = $2;$n", [name, rope(flags)]) addf(m.s[cfsTypeInit3], "$1.flags = $2;$n", [name, rope(flags)])
discard cgsym(m, "TNimType") discard cgsym(m, "TNimType")
if isDefined("nimTypeNames"): if isDefined(m.config, "nimTypeNames"):
var typename = typeToString(if origType.typeInst != nil: origType.typeInst var typename = typeToString(if origType.typeInst != nil: origType.typeInst
else: origType, preferName) else: origType, preferName)
if typename == "ref object" and origType.skipTypes(skipPtrs).sym != nil: if typename == "ref object" and origType.skipTypes(skipPtrs).sym != nil:
@ -1000,7 +1000,7 @@ proc discriminatorTableName(m: BModule, objtype: PType, d: PSym): Rope =
while lookupInRecord(objtype.n, d.name) == nil: while lookupInRecord(objtype.n, d.name) == nil:
objtype = objtype.sons[0] objtype = objtype.sons[0]
if objtype.sym == nil: if objtype.sym == nil:
internalError(d.info, "anonymous obj with discriminator") internalError(m.config, d.info, "anonymous obj with discriminator")
result = "NimDT_$1_$2" % [rope($hashType(objtype)), rope(d.name.s.mangle)] result = "NimDT_$1_$2" % [rope($hashType(objtype)), rope(d.name.s.mangle)]
proc discriminatorTableDecl(m: BModule, objtype: PType, d: PSym): Rope = proc discriminatorTableDecl(m: BModule, objtype: PType, d: PSym): Rope =
@ -1034,7 +1034,7 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope;
assert L > 0 assert L > 0
if field.loc.r == nil: fillObjectFields(m, typ) if field.loc.r == nil: fillObjectFields(m, typ)
if field.loc.t == nil: if field.loc.t == nil:
internalError(n.info, "genObjectFields") internalError(m.config, n.info, "genObjectFields")
addf(m.s[cfsTypeInit3], "$1.kind = 3;$n" & addf(m.s[cfsTypeInit3], "$1.kind = 3;$n" &
"$1.offset = offsetof($2, $3);$n" & "$1.typ = $4;$n" & "$1.offset = offsetof($2, $3);$n" & "$1.typ = $4;$n" &
"$1.name = $5;$n" & "$1.sons = &$6[0];$n" & "$1.name = $5;$n" & "$1.sons = &$6[0];$n" &
@ -1050,7 +1050,7 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope;
case b.kind case b.kind
of nkOfBranch: of nkOfBranch:
if sonsLen(b) < 2: if sonsLen(b) < 2:
internalError(b.info, "genObjectFields; nkOfBranch broken") internalError(m.config, b.info, "genObjectFields; nkOfBranch broken")
for j in countup(0, sonsLen(b) - 2): for j in countup(0, sonsLen(b) - 2):
if b.sons[j].kind == nkRange: if b.sons[j].kind == nkRange:
var x = int(getOrdValue(b.sons[j].sons[0])) var x = int(getOrdValue(b.sons[j].sons[0]))
@ -1064,23 +1064,23 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope;
of nkElse: of nkElse:
addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n", addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n",
[tmp, rope(L), tmp2]) [tmp, rope(L), tmp2])
else: internalError(n.info, "genObjectFields(nkRecCase)") else: internalError(m.config, n.info, "genObjectFields(nkRecCase)")
of nkSym: of nkSym:
var field = n.sym var field = n.sym
if field.bitsize == 0: if field.bitsize == 0:
if field.loc.r == nil: fillObjectFields(m, typ) if field.loc.r == nil: fillObjectFields(m, typ)
if field.loc.t == nil: if field.loc.t == nil:
internalError(n.info, "genObjectFields") internalError(m.config, n.info, "genObjectFields")
addf(m.s[cfsTypeInit3], "$1.kind = 1;$n" & addf(m.s[cfsTypeInit3], "$1.kind = 1;$n" &
"$1.offset = offsetof($2, $3);$n" & "$1.typ = $4;$n" & "$1.offset = offsetof($2, $3);$n" & "$1.typ = $4;$n" &
"$1.name = $5;$n", [expr, getTypeDesc(m, origType), "$1.name = $5;$n", [expr, getTypeDesc(m, origType),
field.loc.r, genTypeInfo(m, field.typ, info), makeCString(field.name.s)]) field.loc.r, genTypeInfo(m, field.typ, info), makeCString(field.name.s)])
else: internalError(n.info, "genObjectFields") else: internalError(m.config, n.info, "genObjectFields")
proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo) = proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo) =
if typ.kind == tyObject: if typ.kind == tyObject:
if incompleteType(typ): if incompleteType(typ):
localError(info, "request for RTTI generation for incomplete object: " & localError(m.config, info, "request for RTTI generation for incomplete object: " &
typeToString(typ)) typeToString(typ))
genTypeInfoAux(m, typ, origType, name, info) genTypeInfoAux(m, typ, origType, name, info)
else: else:
@ -1171,12 +1171,12 @@ proc genSetInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) =
proc genArrayInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) = proc genArrayInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) =
genTypeInfoAuxBase(m, typ, typ, name, genTypeInfo(m, typ.sons[1], info), info) genTypeInfoAuxBase(m, typ, typ, name, genTypeInfo(m, typ.sons[1], info), info)
proc fakeClosureType(owner: PSym): PType = proc fakeClosureType(m: BModule; owner: PSym): PType =
# we generate the same RTTI as for a tuple[pointer, ref tuple[]] # we generate the same RTTI as for a tuple[pointer, ref tuple[]]
result = newType(tyTuple, owner) result = newType(tyTuple, owner)
result.rawAddSon(newType(tyPointer, owner)) result.rawAddSon(newType(tyPointer, owner))
var r = newType(tyRef, owner) var r = newType(tyRef, owner)
let obj = createObj(owner, owner.info, final=false) let obj = createObj(m.g.graph, owner, owner.info, final=false)
r.rawAddSon(obj) r.rawAddSon(obj)
result.rawAddSon(r) result.rawAddSon(r)
@ -1227,15 +1227,15 @@ proc genTypeInfo(m: BModule, t: PType; info: TLineInfo): Rope =
genTypeInfoAuxBase(m, t, t, result, rope"0", info) genTypeInfoAuxBase(m, t, t, result, rope"0", info)
of tyStatic: of tyStatic:
if t.n != nil: result = genTypeInfo(m, lastSon t, info) if t.n != nil: result = genTypeInfo(m, lastSon t, info)
else: internalError("genTypeInfo(" & $t.kind & ')') else: internalError(m.config, "genTypeInfo(" & $t.kind & ')')
of tyUserTypeClasses: of tyUserTypeClasses:
internalAssert t.isResolvedUserTypeClass internalAssert m.config, t.isResolvedUserTypeClass
return genTypeInfo(m, t.lastSon, info) return genTypeInfo(m, t.lastSon, info)
of tyProc: of tyProc:
if t.callConv != ccClosure: if t.callConv != ccClosure:
genTypeInfoAuxBase(m, t, t, result, rope"0", info) genTypeInfoAuxBase(m, t, t, result, rope"0", info)
else: else:
let x = fakeClosureType(t.owner) let x = fakeClosureType(m, t.owner)
genTupleInfo(m, x, x, result, info) genTupleInfo(m, x, x, result, info)
of tySequence, tyRef, tyOptAsRef: of tySequence, tyRef, tyOptAsRef:
genTypeInfoAux(m, t, t, result, info) genTypeInfoAux(m, t, t, result, info)
@ -1253,7 +1253,7 @@ proc genTypeInfo(m: BModule, t: PType; info: TLineInfo): Rope =
# BUGFIX: use consistently RTTI without proper field names; otherwise # BUGFIX: use consistently RTTI without proper field names; otherwise
# results are not deterministic! # results are not deterministic!
genTupleInfo(m, t, origType, result, info) genTupleInfo(m, t, origType, result, info)
else: internalError("genTypeInfo(" & $t.kind & ')') else: internalError(m.config, "genTypeInfo(" & $t.kind & ')')
if t.deepCopy != nil: if t.deepCopy != nil:
genDeepCopyProc(m, t.deepCopy, result) genDeepCopyProc(m, t.deepCopy, result)
elif origType.deepCopy != nil: elif origType.deepCopy != nil:

View file

@ -53,7 +53,7 @@ proc hashString*(s: string): BiggestInt =
result = a result = a
var var
gTypeTable: array[TTypeKind, TIdTable] gTypeTable: array[TTypeKind, TIdTable] # XXX globals here
gCanonicalTypes: array[TTypeKind, PType] gCanonicalTypes: array[TTypeKind, PType]
proc initTypeTables() = proc initTypeTables() =

View file

@ -19,6 +19,7 @@ import
import strutils except `%` # collides with ropes.`%` import strutils except `%` # collides with ropes.`%`
from modulegraphs import ModuleGraph from modulegraphs import ModuleGraph
from configuration import warnGcMem, errXMustBeCompileTime, hintDependency, errGenerated
import dynlib import dynlib
when not declared(dynlib.libCandidates): when not declared(dynlib.libCandidates):
@ -230,7 +231,7 @@ proc postStmtActions(p: BProc) {.inline.} =
add(p.s(cpsStmts), p.module.injectStmt) add(p.s(cpsStmts), p.module.injectStmt)
proc accessThreadLocalVar(p: BProc, s: PSym) proc accessThreadLocalVar(p: BProc, s: PSym)
proc emulatedThreadVars(): bool {.inline.} proc emulatedThreadVars(conf: ConfigRef): bool {.inline.}
proc genProc(m: BModule, prc: PSym) proc genProc(m: BModule, prc: PSym)
template compileToCpp(m: BModule): untyped = template compileToCpp(m: BModule): untyped =
@ -263,7 +264,7 @@ proc rdCharLoc(a: TLoc): Rope =
proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc, proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc,
takeAddr: bool) = takeAddr: bool) =
if p.module.compileToCpp and t.isException and not isDefined("noCppExceptions"): if p.module.compileToCpp and t.isException and not isDefined(p.config, "noCppExceptions"):
# init vtable in Exception object for polymorphic exceptions # init vtable in Exception object for polymorphic exceptions
includeHeader(p.module, "<new>") includeHeader(p.module, "<new>")
linefmt(p, section, "new ($1) $2;$n", rdLoc(a), getTypeDesc(p.module, t)) linefmt(p, section, "new ($1) $2;$n", rdLoc(a), getTypeDesc(p.module, t))
@ -371,7 +372,7 @@ proc getIntTemp(p: BProc, result: var TLoc) =
linefmt(p, cpsLocals, "NI $1;$n", result.r) linefmt(p, cpsLocals, "NI $1;$n", result.r)
result.k = locTemp result.k = locTemp
result.storage = OnStack result.storage = OnStack
result.lode = lodeTyp getSysType(tyInt) result.lode = lodeTyp getSysType(p.module.g.graph, unknownLineInfo(), tyInt)
result.flags = {} result.flags = {}
proc initGCFrame(p: BProc): Rope = proc initGCFrame(p: BProc): Rope =
@ -549,7 +550,7 @@ proc loadDynamicLib(m: BModule, lib: PLib) =
if lib.path.kind in {nkStrLit..nkTripleStrLit}: if lib.path.kind in {nkStrLit..nkTripleStrLit}:
var s: TStringSeq = @[] var s: TStringSeq = @[]
libCandidates(lib.path.strVal, s) libCandidates(lib.path.strVal, s)
rawMessage(hintDependency, lib.path.strVal) rawMessage(m.config, hintDependency, lib.path.strVal)
var loadlib: Rope = nil var loadlib: Rope = nil
for i in countup(0, high(s)): for i in countup(0, high(s)):
inc(m.labels) inc(m.labels)
@ -573,7 +574,7 @@ proc loadDynamicLib(m: BModule, lib: PLib) =
"if (!($1 = #nimLoadLibrary($2))) #nimLoadLibraryError($2);$n", "if (!($1 = #nimLoadLibrary($2))) #nimLoadLibraryError($2);$n",
[tmp, rdLoc(dest)]) [tmp, rdLoc(dest)])
if lib.name == nil: internalError("loadDynamicLib") if lib.name == nil: internalError(m.config, "loadDynamicLib")
proc mangleDynLibProc(sym: PSym): Rope = proc mangleDynLibProc(sym: PSym): Rope =
if sfCompilerProc in sym.flags: if sfCompilerProc in sym.flags:
@ -604,14 +605,14 @@ proc symInDynamicLib(m: BModule, sym: PSym) =
[tmp, getTypeDesc(m, sym.typ), params, makeCString($extname)] [tmp, getTypeDesc(m, sym.typ), params, makeCString($extname)]
var last = lastSon(n) var last = lastSon(n)
if last.kind == nkHiddenStdConv: last = last.sons[1] if last.kind == nkHiddenStdConv: last = last.sons[1]
internalAssert(last.kind == nkStrLit) internalAssert(m.config, last.kind == nkStrLit)
let idx = last.strVal let idx = last.strVal
if idx.len == 0: if idx.len == 0:
add(m.initProc.s(cpsStmts), load) add(m.initProc.s(cpsStmts), load)
elif idx.len == 1 and idx[0] in {'0'..'9'}: elif idx.len == 1 and idx[0] in {'0'..'9'}:
add(m.extensionLoaders[idx[0]], load) add(m.extensionLoaders[idx[0]], load)
else: else:
internalError(sym.info, "wrong index: " & idx) internalError(m.config, sym.info, "wrong index: " & idx)
else: else:
appcg(m, m.s[cfsDynLibInit], appcg(m, m.s[cfsDynLibInit],
"\t$1 = ($2) #nimGetProcAddr($3, $4);$n", "\t$1 = ($2) #nimGetProcAddr($3, $4);$n",
@ -637,18 +638,18 @@ proc symInDynamicLibPartial(m: BModule, sym: PSym) =
sym.typ.sym = nil # generate a new name sym.typ.sym = nil # generate a new name
proc cgsym(m: BModule, name: string): Rope = proc cgsym(m: BModule, name: string): Rope =
let sym = magicsys.getCompilerProc(name) let sym = magicsys.getCompilerProc(m.g.graph, name)
if sym != nil: if sym != nil:
case sym.kind case sym.kind
of skProc, skFunc, skMethod, skConverter, skIterator: genProc(m, sym) of skProc, skFunc, skMethod, skConverter, skIterator: genProc(m, sym)
of skVar, skResult, skLet: genVarPrototype(m, newSymNode sym) of skVar, skResult, skLet: genVarPrototype(m, newSymNode sym)
of skType: discard getTypeDesc(m, sym.typ) of skType: discard getTypeDesc(m, sym.typ)
else: internalError("cgsym: " & name & ": " & $sym.kind) else: internalError(m.config, "cgsym: " & name & ": " & $sym.kind)
else: else:
# we used to exclude the system module from this check, but for DLL # we used to exclude the system module from this check, but for DLL
# generation support this sloppyness leads to hard to detect bugs, so # generation support this sloppyness leads to hard to detect bugs, so
# we're picky here for the system module too: # we're picky here for the system module too:
rawMessage(errSystemNeeds, name) rawMessage(m.config, errGenerated, "system module needs: " & name)
result = sym.loc.r result = sym.loc.r
proc generateHeaders(m: BModule) = proc generateHeaders(m: BModule) =
@ -685,7 +686,7 @@ proc closureSetup(p: BProc, prc: PSym) =
# prc.ast[paramsPos].last contains the type we're after: # prc.ast[paramsPos].last contains the type we're after:
var ls = lastSon(prc.ast[paramsPos]) var ls = lastSon(prc.ast[paramsPos])
if ls.kind != nkSym: if ls.kind != nkSym:
internalError(prc.info, "closure generation failed") internalError(p.config, prc.info, "closure generation failed")
var env = ls.sym var env = ls.sym
#echo "created environment: ", env.id, " for ", prc.name.s #echo "created environment: ", env.id, " for ", prc.name.s
assignLocalVar(p, ls) assignLocalVar(p, ls)
@ -725,7 +726,7 @@ proc genProcAux(m: BModule, prc: PSym) =
assert(prc.ast != nil) assert(prc.ast != nil)
if sfPure notin prc.flags and prc.typ.sons[0] != nil: if sfPure notin prc.flags and prc.typ.sons[0] != nil:
if resultPos >= prc.ast.len: if resultPos >= prc.ast.len:
internalError(prc.info, "proc has no result symbol") internalError(m.config, prc.info, "proc has no result symbol")
let resNode = prc.ast.sons[resultPos] let resNode = prc.ast.sons[resultPos]
let res = resNode.sym # get result symbol let res = resNode.sym # get result symbol
if not isInvalidReturnType(prc.typ.sons[0]): if not isInvalidReturnType(prc.typ.sons[0]):
@ -924,7 +925,7 @@ proc addIntTypes(result: var Rope) {.inline.} =
platform.CPU[targetCPU].intSize.rope]) platform.CPU[targetCPU].intSize.rope])
if useNimNamespace : result.add("#define USE_NIM_NAMESPACE" & tnl) if useNimNamespace : result.add("#define USE_NIM_NAMESPACE" & tnl)
proc getCopyright(cfile: Cfile): Rope = proc getCopyright(conf: ConfigRef; cfile: Cfile): Rope =
if optCompileOnly in gGlobalOptions: if optCompileOnly in gGlobalOptions:
result = ("/* Generated by Nim Compiler v$1 */$N" & result = ("/* Generated by Nim Compiler v$1 */$N" &
"/* (c) " & copyrightYear & " Andreas Rumpf */$N" & "/* (c) " & copyrightYear & " Andreas Rumpf */$N" &
@ -940,10 +941,10 @@ proc getCopyright(cfile: Cfile): Rope =
rope(platform.OS[targetOS].name), rope(platform.OS[targetOS].name),
rope(platform.CPU[targetCPU].name), rope(platform.CPU[targetCPU].name),
rope(extccomp.CC[extccomp.cCompiler].name), rope(extccomp.CC[extccomp.cCompiler].name),
rope(getCompileCFileCmd(cfile))] rope(getCompileCFileCmd(conf, cfile))]
proc getFileHeader(cfile: Cfile): Rope = proc getFileHeader(conf: ConfigRef; cfile: Cfile): Rope =
result = getCopyright(cfile) result = getCopyright(conf, cfile)
addIntTypes(result) addIntTypes(result)
proc genFilenames(m: BModule): Rope = proc genFilenames(m: BModule): Rope =
@ -1079,7 +1080,7 @@ proc genMainProc(m: BModule) =
inc(m.labels) inc(m.labels)
appcg(m, m.s[cfsProcs], PreMainBody, [ appcg(m, m.s[cfsProcs], PreMainBody, [
m.g.mainDatInit, m.g.breakpoints, m.g.otherModsInit, m.g.mainDatInit, m.g.breakpoints, m.g.otherModsInit,
if emulatedThreadVars() and platform.targetOS != osStandalone: if emulatedThreadVars(m.config) and platform.targetOS != osStandalone:
ropecg(m, "\t#initThreadVarsEmulation();$N") ropecg(m, "\t#initThreadVarsEmulation();$N")
else: else:
"".rope, "".rope,
@ -1138,11 +1139,11 @@ proc genInitCode(m: BModule) =
add(prc, initGCFrame(m.initProc)) add(prc, initGCFrame(m.initProc))
add(prc, genSectionStart(cpsLocals)) add(prc, genSectionStart(cpsLocals, m.config))
add(prc, m.preInitProc.s(cpsLocals)) add(prc, m.preInitProc.s(cpsLocals))
add(prc, m.initProc.s(cpsLocals)) add(prc, m.initProc.s(cpsLocals))
add(prc, m.postInitProc.s(cpsLocals)) add(prc, m.postInitProc.s(cpsLocals))
add(prc, genSectionEnd(cpsLocals)) add(prc, genSectionEnd(cpsLocals, m.config))
if optStackTrace in m.initProc.options and frameDeclared notin m.flags: if optStackTrace in m.initProc.options and frameDeclared notin m.flags:
# BUT: the generated init code might depend on a current frame, so # BUT: the generated init code might depend on a current frame, so
@ -1154,17 +1155,17 @@ proc genInitCode(m: BModule) =
else: else:
add(prc, ~"\tTFrame FR_; FR_.len = 0;$N") add(prc, ~"\tTFrame FR_; FR_.len = 0;$N")
add(prc, genSectionStart(cpsInit)) add(prc, genSectionStart(cpsInit, m.config))
add(prc, m.preInitProc.s(cpsInit)) add(prc, m.preInitProc.s(cpsInit))
add(prc, m.initProc.s(cpsInit)) add(prc, m.initProc.s(cpsInit))
add(prc, m.postInitProc.s(cpsInit)) add(prc, m.postInitProc.s(cpsInit))
add(prc, genSectionEnd(cpsInit)) add(prc, genSectionEnd(cpsInit, m.config))
add(prc, genSectionStart(cpsStmts)) add(prc, genSectionStart(cpsStmts, m.config))
add(prc, m.preInitProc.s(cpsStmts)) add(prc, m.preInitProc.s(cpsStmts))
add(prc, m.initProc.s(cpsStmts)) add(prc, m.initProc.s(cpsStmts))
add(prc, m.postInitProc.s(cpsStmts)) add(prc, m.postInitProc.s(cpsStmts))
add(prc, genSectionEnd(cpsStmts)) add(prc, genSectionEnd(cpsStmts, m.config))
if optStackTrace in m.initProc.options and preventStackTrace notin m.flags: if optStackTrace in m.initProc.options and preventStackTrace notin m.flags:
add(prc, deinitFrame(m.initProc)) add(prc, deinitFrame(m.initProc))
add(prc, deinitGCFrame(m.initProc)) add(prc, deinitGCFrame(m.initProc))
@ -1174,9 +1175,9 @@ proc genInitCode(m: BModule) =
[getDatInitName(m.module)]) [getDatInitName(m.module)])
for i in cfsTypeInit1..cfsDynLibInit: for i in cfsTypeInit1..cfsDynLibInit:
add(prc, genSectionStart(i)) add(prc, genSectionStart(i, m.config))
add(prc, m.s[i]) add(prc, m.s[i])
add(prc, genSectionEnd(i)) add(prc, genSectionEnd(i, m.config))
addf(prc, "}$N$N", []) addf(prc, "}$N$N", [])
# we cannot simply add the init proc to ``m.s[cfsProcs]`` anymore because # we cannot simply add the init proc to ``m.s[cfsProcs]`` anymore because
@ -1191,15 +1192,15 @@ proc genInitCode(m: BModule) =
add(m.s[cfsInitProc], ex) add(m.s[cfsInitProc], ex)
proc genModule(m: BModule, cfile: Cfile): Rope = proc genModule(m: BModule, cfile: Cfile): Rope =
result = getFileHeader(cfile) result = getFileHeader(m.config, cfile)
result.add(genMergeInfo(m)) result.add(genMergeInfo(m))
generateThreadLocalStorage(m) generateThreadLocalStorage(m)
generateHeaders(m) generateHeaders(m)
for i in countup(cfsHeaders, cfsProcs): for i in countup(cfsHeaders, cfsProcs):
add(result, genSectionStart(i)) add(result, genSectionStart(i, m.config))
add(result, m.s[i]) add(result, m.s[i])
add(result, genSectionEnd(i)) add(result, genSectionEnd(i, m.config))
if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim() if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim()
add(result, m.s[cfsInitProc]) add(result, m.s[cfsInitProc])
if useNimNamespace: result.add closeNamespaceNim() if useNimNamespace: result.add closeNamespaceNim()
@ -1246,7 +1247,7 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: string): BModule =
incl result.flags, preventStackTrace incl result.flags, preventStackTrace
excl(result.preInitProc.options, optStackTrace) excl(result.preInitProc.options, optStackTrace)
excl(result.postInitProc.options, optStackTrace) excl(result.postInitProc.options, optStackTrace)
let ndiName = if optCDebug in gGlobalOptions: changeFileExt(completeCFilePath(filename), "ndi") let ndiName = if optCDebug in gGlobalOptions: changeFileExt(completeCFilePath(g.config, filename), "ndi")
else: "" else: ""
open(result.ndi, ndiName) open(result.ndi, ndiName)
@ -1307,18 +1308,19 @@ proc newModule(g: BModuleList; module: PSym): BModule =
growCache g.modules, module.position growCache g.modules, module.position
g.modules[module.position] = result g.modules[module.position] = result
template injectG(config) {.dirty.} = template injectG() {.dirty.} =
if graph.backend == nil: if graph.backend == nil:
graph.backend = newModuleList(config) graph.backend = newModuleList(graph)
let g = BModuleList(graph.backend) let g = BModuleList(graph.backend)
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext = proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
injectG(graph.config) injectG()
result = newModule(g, module) result = newModule(g, module)
if optGenIndex in gGlobalOptions and g.generatedHeader == nil: if optGenIndex in gGlobalOptions and g.generatedHeader == nil:
let f = if graph.config.headerFile.len > 0: graph.config.headerFile else: gProjectFull let f = if graph.config.headerFile.len > 0: graph.config.headerFile
else: graph.config.projectFull
g.generatedHeader = rawNewModule(g, module, g.generatedHeader = rawNewModule(g, module,
changeFileExt(completeCFilePath(f), hExt)) changeFileExt(completeCFilePath(graph.config, f), hExt))
incl g.generatedHeader.flags, isHeaderFile incl g.generatedHeader.flags, isHeaderFile
proc writeHeader(m: BModule) = proc writeHeader(m: BModule) =
@ -1334,9 +1336,9 @@ proc writeHeader(m: BModule) =
generateThreadLocalStorage(m) generateThreadLocalStorage(m)
for i in countup(cfsHeaders, cfsProcs): for i in countup(cfsHeaders, cfsProcs):
add(result, genSectionStart(i)) add(result, genSectionStart(i, m.config))
add(result, m.s[i]) add(result, m.s[i])
add(result, genSectionEnd(i)) add(result, genSectionEnd(i, m.config))
if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim() if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim()
add(result, m.s[cfsInitProc]) add(result, m.s[cfsInitProc])
@ -1352,18 +1354,19 @@ proc getCFile(m: BModule): string =
if m.compileToCpp: ".cpp" if m.compileToCpp: ".cpp"
elif gCmd == cmdCompileToOC or sfCompileToObjC in m.module.flags: ".m" elif gCmd == cmdCompileToOC or sfCompileToObjC in m.module.flags: ".m"
else: ".c" else: ".c"
result = changeFileExt(completeCFilePath(m.cfilename.withPackageName), ext) result = changeFileExt(completeCFilePath(m.config, withPackageName(m.config, m.cfilename)), ext)
proc myOpenCached(graph: ModuleGraph; module: PSym, rd: PRodReader): PPassContext = proc myOpenCached(graph: ModuleGraph; module: PSym, rd: PRodReader): PPassContext =
injectG(graph.config) injectG()
var m = newModule(g, module) var m = newModule(g, module)
readMergeInfo(getCFile(m), m) readMergeInfo(getCFile(m), m)
result = m result = m
proc myProcess(b: PPassContext, n: PNode): PNode = proc myProcess(b: PPassContext, n: PNode): PNode =
result = n result = n
if b == nil or passes.skipCodegen(n): return if b == nil: return
var m = BModule(b) var m = BModule(b)
if passes.skipCodegen(m.config, n): return
m.initProc.options = initProcOptions(m) m.initProc.options = initProcOptions(m)
softRnl = if optLineDir in gOptions: noRnl else: rnl softRnl = if optLineDir in gOptions: noRnl else: rnl
genStmts(m.initProc, n) genStmts(m.initProc, n)
@ -1375,18 +1378,18 @@ proc finishModule(m: BModule) =
# a ``for`` loop here # a ``for`` loop here
var prc = m.forwardedProcs[i] var prc = m.forwardedProcs[i]
if sfForward in prc.flags: if sfForward in prc.flags:
internalError(prc.info, "still forwarded: " & prc.name.s) internalError(m.config, prc.info, "still forwarded: " & prc.name.s)
genProcNoForward(m, prc) genProcNoForward(m, prc)
inc(i) inc(i)
assert(m.g.forwardedProcsCounter >= i) assert(m.g.forwardedProcsCounter >= i)
dec(m.g.forwardedProcsCounter, i) dec(m.g.forwardedProcsCounter, i)
setLen(m.forwardedProcs, 0) setLen(m.forwardedProcs, 0)
proc shouldRecompile(code: Rope, cfile: Cfile): bool = proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
result = true result = true
if optForceFullMake notin gGlobalOptions: if optForceFullMake notin gGlobalOptions:
if not equalsFile(code, cfile.cname): if not equalsFile(code, cfile.cname):
if isDefined("nimdiff"): if isDefined(m.config, "nimdiff"):
if fileExists(cfile.cname): if fileExists(cfile.cname):
copyFile(cfile.cname, cfile.cname & ".backup") copyFile(cfile.cname, cfile.cname & ".backup")
echo "diff ", cfile.cname, ".backup ", cfile.cname echo "diff ", cfile.cname, ".backup ", cfile.cname
@ -1417,35 +1420,35 @@ proc writeModule(m: BModule, pending: bool) =
add(m.s[cfsProcHeaders], m.g.mainModProcs) add(m.s[cfsProcHeaders], m.g.mainModProcs)
generateThreadVarsSize(m) generateThreadVarsSize(m)
var cf = Cfile(cname: cfile, obj: completeCFilePath(toObjFile(cfile)), flags: {}) var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
var code = genModule(m, cf) var code = genModule(m, cf)
when hasTinyCBackend: when hasTinyCBackend:
if gCmd == cmdRun: if gCmd == cmdRun:
tccgen.compileCCode($code) tccgen.compileCCode($code)
return return
if not shouldRecompile(code, cf): cf.flags = {CfileFlag.Cached} if not shouldRecompile(m, code, cf): cf.flags = {CfileFlag.Cached}
addFileToCompile(cf) addFileToCompile(m.config, cf)
elif pending and mergeRequired(m) and sfMainModule notin m.module.flags: elif pending and mergeRequired(m) and sfMainModule notin m.module.flags:
let cf = Cfile(cname: cfile, obj: completeCFilePath(toObjFile(cfile)), flags: {}) let cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
mergeFiles(cfile, m) mergeFiles(cfile, m)
genInitCode(m) genInitCode(m)
finishTypeDescriptions(m) finishTypeDescriptions(m)
var code = genModule(m, cf) var code = genModule(m, cf)
writeRope(code, cfile) writeRope(code, cfile)
addFileToCompile(cf) addFileToCompile(m.config, cf)
else: else:
# Consider: first compilation compiles ``system.nim`` and produces # Consider: first compilation compiles ``system.nim`` and produces
# ``system.c`` but then compilation fails due to an error. This means # ``system.c`` but then compilation fails due to an error. This means
# that ``system.o`` is missing, so we need to call the C compiler for it: # that ``system.o`` is missing, so we need to call the C compiler for it:
var cf = Cfile(cname: cfile, obj: completeCFilePath(toObjFile(cfile)), flags: {}) var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
if not existsFile(cf.obj): cf.flags = {CfileFlag.Cached} if not existsFile(cf.obj): cf.flags = {CfileFlag.Cached}
addFileToCompile(cf) addFileToCompile(m.config, cf)
close(m.ndi) close(m.ndi)
proc updateCachedModule(m: BModule) = proc updateCachedModule(m: BModule) =
let cfile = getCFile(m) let cfile = getCFile(m)
var cf = Cfile(cname: cfile, obj: completeCFilePath(toObjFile(cfile)), flags: {}) var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
if mergeRequired(m) and sfMainModule notin m.module.flags: if mergeRequired(m) and sfMainModule notin m.module.flags:
mergeFiles(cfile, m) mergeFiles(cfile, m)
@ -1456,12 +1459,13 @@ proc updateCachedModule(m: BModule) =
writeRope(code, cfile) writeRope(code, cfile)
else: else:
cf.flags = {CfileFlag.Cached} cf.flags = {CfileFlag.Cached}
addFileToCompile(cf) addFileToCompile(m.config, cf)
proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode = proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode =
result = n result = n
if b == nil or passes.skipCodegen(n): return if b == nil: return
var m = BModule(b) var m = BModule(b)
if passes.skipCodegen(m.config, n): return
# if the module is cached, we don't regenerate the main proc # if the module is cached, we don't regenerate the main proc
# nor the dispatchers? But if the dispatchers changed? # nor the dispatchers? But if the dispatchers changed?
# XXX emit the dispatchers into its own .c file? # XXX emit the dispatchers into its own .c file?
@ -1495,7 +1499,7 @@ proc cgenWriteModules*(backend: RootRef, config: ConfigRef) =
m.updateCachedModule m.updateCachedModule
else: else:
m.writeModule(pending=true) m.writeModule(pending=true)
writeMapping(g.mapping) writeMapping(config, g.mapping)
if g.generatedHeader != nil: writeHeader(g.generatedHeader) if g.generatedHeader != nil: writeHeader(g.generatedHeader)
const cgenPass* = makePass(myOpen, myOpenCached, myProcess, myClose) const cgenPass* = makePass(myOpen, myOpenCached, myProcess, myClose)

View file

@ -14,6 +14,7 @@ import
tables, ndi tables, ndi
from msgs import TLineInfo from msgs import TLineInfo
from modulegraphs import ModuleGraph
type type
TLabel* = Rope # for the C generator a label is just a rope TLabel* = Rope # for the C generator a label is just a rope
@ -116,6 +117,7 @@ type
breakpoints*: Rope # later the breakpoints are inserted into the main proc breakpoints*: Rope # later the breakpoints are inserted into the main proc
typeInfoMarker*: TypeCache typeInfoMarker*: TypeCache
config*: ConfigRef config*: ConfigRef
graph*: ModuleGraph
strVersion*, seqVersion*: int # version of the string/seq implementation to use strVersion*, seqVersion*: int # version of the string/seq implementation to use
TCGen = object of TPassContext # represents a C source file TCGen = object of TPassContext # represents a C source file
@ -174,8 +176,9 @@ proc newProc*(prc: PSym, module: BModule): BProc =
result.finallySafePoints = @[] result.finallySafePoints = @[]
result.sigConflicts = initCountTable[string]() result.sigConflicts = initCountTable[string]()
proc newModuleList*(config: ConfigRef): BModuleList = proc newModuleList*(g: ModuleGraph): BModuleList =
BModuleList(modules: @[], typeInfoMarker: initTable[SigHash, Rope](), config: config) BModuleList(modules: @[], typeInfoMarker: initTable[SigHash, Rope](), config: g.config,
graph: g)
iterator cgenModules*(g: BModuleList): BModule = iterator cgenModules*(g: BModuleList): BModule =
for i in 0..high(g.modules): for i in 0..high(g.modules):

View file

@ -179,6 +179,9 @@ const
{low(TNoteKind)..high(TNoteKind)} - {hintStackTrace, warnUninit}, {low(TNoteKind)..high(TNoteKind)} - {hintStackTrace, warnUninit},
{low(TNoteKind)..high(TNoteKind)}] {low(TNoteKind)..high(TNoteKind)}]
const
errXMustBeCompileTime* = "'$1' can only be used in compile-time context"
#[ #[
errStringLiteralExpected: "string literal expected", errStringLiteralExpected: "string literal expected",
errIntLiteralExpected: "integer literal expected", errIntLiteralExpected: "integer literal expected",
@ -352,6 +355,5 @@ errXhasSideEffects: "'$1' can have side effects",
errWrongSymbolX:, errWrongSymbolX:,
errIllegalCaptureX: "illegal capture '$1'", errIllegalCaptureX: "illegal capture '$1'",
errXCannotBeClosure: "'$1' cannot have 'closure' calling convention", errXCannotBeClosure: "'$1' cannot have 'closure' calling convention",
errXMustBeCompileTime: "'$1' can only be used in compile-time context",
, ,
]# ]#