mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 06:45:27 +00:00
minor codegen bugfix: don't use names for closures that are also mangled Nim names
This commit is contained in:
@@ -200,8 +200,8 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||
proc addComma(r: Rope): Rope =
|
||||
result = if r == nil: r else: r & ~", "
|
||||
|
||||
const PatProc = "$1.ClEnv? $1.ClPrc($3$1.ClEnv):(($4)($1.ClPrc))($2)"
|
||||
const PatIter = "$1.ClPrc($3$1.ClEnv)" # we know the env exists
|
||||
const PatProc = "$1.ClE_0? $1.ClP_0($3$1.ClE_0):(($4)($1.ClP_0))($2)"
|
||||
const PatIter = "$1.ClP_0($3$1.ClE_0)" # we know the env exists
|
||||
var op: TLoc
|
||||
initLocExpr(p, ri.sons[0], op)
|
||||
var pl: Rope
|
||||
|
||||
@@ -296,10 +296,10 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||
of tyProc:
|
||||
if needsComplexAssignment(dest.t):
|
||||
# optimize closure assignment:
|
||||
let a = optAsgnLoc(dest, dest.t, "ClEnv".rope)
|
||||
let b = optAsgnLoc(src, dest.t, "ClEnv".rope)
|
||||
let a = optAsgnLoc(dest, dest.t, "ClE_0".rope)
|
||||
let b = optAsgnLoc(src, dest.t, "ClE_0".rope)
|
||||
genRefAssign(p, a, b, flags)
|
||||
linefmt(p, cpsStmts, "$1.ClPrc = $2.ClPrc;$n", rdLoc(dest), rdLoc(src))
|
||||
linefmt(p, cpsStmts, "$1.ClP_0 = $2.ClP_0;$n", rdLoc(dest), rdLoc(src))
|
||||
else:
|
||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||
of tyTuple:
|
||||
@@ -602,14 +602,14 @@ proc genEqProc(p: BProc, e: PNode, d: var TLoc) =
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
if a.t.skipTypes(abstractInst).callConv == ccClosure:
|
||||
putIntoDest(p, d, e.typ,
|
||||
"($1.ClPrc == $2.ClPrc && $1.ClEnv == $2.ClEnv)" % [rdLoc(a), rdLoc(b)])
|
||||
"($1.ClP_0 == $2.ClP_0 && $1.ClE_0 == $2.ClE_0)" % [rdLoc(a), rdLoc(b)])
|
||||
else:
|
||||
putIntoDest(p, d, e.typ, "($1 == $2)" % [rdLoc(a), rdLoc(b)])
|
||||
|
||||
proc genIsNil(p: BProc, e: PNode, d: var TLoc) =
|
||||
let t = skipTypes(e.sons[1].typ, abstractRange)
|
||||
if t.kind == tyProc and t.callConv == ccClosure:
|
||||
unaryExpr(p, e, d, "($1.ClPrc == 0)")
|
||||
unaryExpr(p, e, d, "($1.ClP_0 == 0)")
|
||||
else:
|
||||
unaryExpr(p, e, d, "($1 == 0)")
|
||||
|
||||
@@ -1851,11 +1851,11 @@ proc genClosure(p: BProc, n: PNode, d: var TLoc) =
|
||||
# tasyncawait.nim breaks with this optimization:
|
||||
when false:
|
||||
if d.k != locNone:
|
||||
linefmt(p, cpsStmts, "$1.ClPrc = $2; $1.ClEnv = $3;$n",
|
||||
linefmt(p, cpsStmts, "$1.ClP_0 = $2; $1.ClE_0 = $3;$n",
|
||||
d.rdLoc, a.rdLoc, b.rdLoc)
|
||||
else:
|
||||
getTemp(p, n.typ, tmp)
|
||||
linefmt(p, cpsStmts, "$1.ClPrc = $2; $1.ClEnv = $3;$n",
|
||||
linefmt(p, cpsStmts, "$1.ClP_0 = $2; $1.ClE_0 = $3;$n",
|
||||
tmp.rdLoc, a.rdLoc, b.rdLoc)
|
||||
putLocIntoDest(p, d, tmp)
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ proc genBreakState(p: BProc, n: PNode) =
|
||||
else:
|
||||
initLocExpr(p, n.sons[0], a)
|
||||
# the environment is guaranteed to contain the 'state' field at offset 0:
|
||||
lineF(p, cpsStmts, "if ((((NI*) $1.ClEnv)[0]) < 0) break;$n", [rdLoc(a)])
|
||||
lineF(p, cpsStmts, "if ((((NI*) $1.ClE_0)[0]) < 0) break;$n", [rdLoc(a)])
|
||||
# lineF(p, cpsStmts, "if (($1) < 0) break;$n", [rdLoc(a)])
|
||||
|
||||
proc genVarPrototypeAux(m: BModule, sym: PSym)
|
||||
|
||||
@@ -87,7 +87,7 @@ proc genTraverseProc(c: var TTraversalClosure, accessor: Rope, typ: PType) =
|
||||
lineCg(p, cpsStmts, c.visitorFrmt, accessor)
|
||||
of tyProc:
|
||||
if typ.callConv == ccClosure:
|
||||
lineCg(p, cpsStmts, c.visitorFrmt, rfmt(nil, "$1.ClEnv", accessor))
|
||||
lineCg(p, cpsStmts, c.visitorFrmt, rfmt(nil, "$1.ClE_0", accessor))
|
||||
else:
|
||||
discard
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
|
||||
addf(params, " Result", [])
|
||||
if t.callConv == ccClosure and declareEnvironment:
|
||||
if params != nil: add(params, ", ")
|
||||
add(params, "void* ClEnv")
|
||||
add(params, "void* ClE_0")
|
||||
if tfVarargs in t.flags:
|
||||
if params != nil: add(params, ", ")
|
||||
add(params, "...")
|
||||
@@ -678,8 +678,8 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||
[rope(CallingConvToStr[t.callConv]), rettype, result, desc])
|
||||
else:
|
||||
addf(m.s[cfsTypes], "typedef struct {$n" &
|
||||
"N_NIMCALL_PTR($2, ClPrc) $3;$n" &
|
||||
"void* ClEnv;$n} $1;$n",
|
||||
"N_NIMCALL_PTR($2, ClP_0) $3;$n" &
|
||||
"void* ClE_0;$n} $1;$n",
|
||||
[result, rettype, desc])
|
||||
of tySequence:
|
||||
# we cannot use getTypeForward here because then t would be associated
|
||||
@@ -815,8 +815,8 @@ proc getClosureType(m: BModule, t: PType, kind: TClosureTypeKind): Rope =
|
||||
[rope(CallingConvToStr[t.callConv]), rettype, result, desc])
|
||||
else:
|
||||
addf(m.s[cfsTypes], "typedef struct {$n" &
|
||||
"N_NIMCALL_PTR($2, ClPrc) $3;$n" &
|
||||
"void* ClEnv;$n} $1;$n",
|
||||
"N_NIMCALL_PTR($2, ClP_0) $3;$n" &
|
||||
"void* ClE_0;$n} $1;$n",
|
||||
[result, rettype, desc])
|
||||
|
||||
proc finishTypeDescriptions(m: BModule) =
|
||||
|
||||
@@ -628,7 +628,7 @@ proc closureSetup(p: BProc, prc: PSym) =
|
||||
#echo "created environment: ", env.id, " for ", prc.name.s
|
||||
assignLocalVar(p, env)
|
||||
# generate cast assignment:
|
||||
linefmt(p, cpsStmts, "$1 = ($2) ClEnv;$n",
|
||||
linefmt(p, cpsStmts, "$1 = ($2) ClE_0;$n",
|
||||
rdLoc(env.loc), getTypeDesc(p.module, env.typ))
|
||||
|
||||
proc easyResultAsgn(n: PNode): PNode =
|
||||
|
||||
Reference in New Issue
Block a user