Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: remove obsolete nkExprColonExpr detection #808

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions compiler/backend/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,7 @@ proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) =
let t = n.typ
discard getTypeDesc(p.module, t) # so that any fields are initialized
if d.k == locNone: getTemp(p, t, d)
for i in 0..<n.len:
var it = n[i]
if it.kind == nkExprColonExpr: it = it[1]
for i, it in n.pairs:
initLoc(rec, locExpr, it, d.storage)
rec.r = "$1.Field$2" % [rdLoc(d), rope(i)]
rec.flags.incl(lfEnforceDeref)
Expand Down Expand Up @@ -2373,12 +2371,9 @@ proc getNullValueAux(p: BProc; t: PType; obj, constOrNil: PNode,
if constOrNil != nil:
## find kind value, default is zero if not specified
for i in 1..<constOrNil.safeLen:
if constOrNil[i].kind == nkExprColonExpr:
if constOrNil[i][0].sym.name.id == obj[0].sym.name.id:
branch = getOrdValue(constOrNil[i][1])
break
elif i == obj[0].sym.position:
branch = getOrdValue(constOrNil[i])
assert constOrNil[i].kind == nkExprColonExpr
if constOrNil[i][0].sym.name.id == obj[0].sym.name.id:
branch = getOrdValue(constOrNil[i][1])
break

let selectedBranch = caseObjDefaultBranch(obj, branch)
Expand All @@ -2401,12 +2396,9 @@ proc getNullValueAux(p: BProc; t: PType; obj, constOrNil: PNode,
let field = obj.sym
if constOrNil != nil:
for i in 1..<constOrNil.safeLen:
if constOrNil[i].kind == nkExprColonExpr:
if constOrNil[i][0].sym.name.id == field.name.id:
result.add genBracedInit(p, constOrNil[i][1], isConst, field.typ)
return
elif i == field.position:
result.add genBracedInit(p, constOrNil[i], isConst, field.typ)
assert constOrNil[i].kind == nkExprColonExpr
if constOrNil[i][0].sym.name.id == field.name.id:
result.add genBracedInit(p, constOrNil[i][1], isConst, field.typ)
return
# not found, produce default value:
result.add getDefaultValue(p, field.typ, info)
Expand Down Expand Up @@ -2444,8 +2436,7 @@ proc genConstSimpleList(p: BProc, n: PNode; isConst: bool): Rope =
for i in 0..<n.len:
let it = n[i]
if i > 0: result.add ",\n"
if it.kind == nkExprColonExpr: result.add genBracedInit(p, it[1], isConst, it[0].typ)
else: result.add genBracedInit(p, it, isConst, it.typ)
result.add genBracedInit(p, it, isConst, it.typ)
result.add("}\n")

proc genConstTuple(p: BProc, n: PNode; isConst: bool; tup: PType): Rope =
Expand Down
15 changes: 4 additions & 11 deletions compiler/vm/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2957,17 +2957,10 @@ proc genTupleConstr(c: var TCtx, n: PNode, dest: var TDest) =
if n.typ.kind != tyTypeDesc:
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
# XXX x = (x.old, 22) produces wrong code ... stupid self assignments
for i in 0..<n.len:
let it = n[i]
if it.kind == nkExprColonExpr:
let idx = genField(c, it[0])
let tmp = c.genAsgnSource(it[1], wantsPtr = true)
c.gABC(it[1], opcWrObj, dest, idx, tmp)
c.freeTemp(tmp)
else:
let tmp = c.genAsgnSource(it, wantsPtr = true)
c.gABC(it, opcWrObj, dest, i.TRegister, tmp)
c.freeTemp(tmp)
for i, it in n.pairs:
let tmp = c.genAsgnSource(it, wantsPtr = true)
c.gABC(it, opcWrObj, dest, i.TRegister, tmp)
c.freeTemp(tmp)

proc genClosureConstr(c: var TCtx, n: PNode, dest: var TDest) =
if dest.isUnset: dest = c.getTemp(n.typ)
Expand Down
Loading