preparations for --newruntime owned refs/callbacks
This commit is contained in:
parent
1c0b1e9d05
commit
a2ad069769
5 changed files with 30 additions and 30 deletions
|
|
@ -185,7 +185,7 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
var params: Rope
|
var params: Rope
|
||||||
# getUniqueType() is too expensive here:
|
# getUniqueType() is too expensive here:
|
||||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
var typ = skipTypes(ri.sons[0].typ, abstractInstOwned)
|
||||||
assert(typ.kind == tyProc)
|
assert(typ.kind == tyProc)
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
var length = sonsLen(ri)
|
var length = sonsLen(ri)
|
||||||
|
|
@ -531,7 +531,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
line(p, cpsStmts, pl)
|
line(p, cpsStmts, pl)
|
||||||
|
|
||||||
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if e.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink}).callConv == ccClosure:
|
if e.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink, tyOwned}).callConv == ccClosure:
|
||||||
genClosureCall(p, nil, e, d)
|
genClosureCall(p, nil, e, d)
|
||||||
elif e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags:
|
elif e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags:
|
||||||
genInfixCall(p, nil, e, d)
|
genInfixCall(p, nil, e, d)
|
||||||
|
|
@ -542,7 +542,7 @@ proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||||
postStmtActions(p)
|
postStmtActions(p)
|
||||||
|
|
||||||
proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
if ri.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink}).callConv == ccClosure:
|
if ri.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink, tyOwned}).callConv == ccClosure:
|
||||||
genClosureCall(p, le, ri, d)
|
genClosureCall(p, le, ri, d)
|
||||||
elif ri.sons[0].kind == nkSym and sfInfixCall in ri.sons[0].sym.flags:
|
elif ri.sons[0].kind == nkSym and sfInfixCall in ri.sons[0].sym.flags:
|
||||||
genInfixCall(p, le, ri, d)
|
genInfixCall(p, le, ri, d)
|
||||||
|
|
|
||||||
|
|
@ -613,7 +613,7 @@ proc genEqProc(p: BProc, e: PNode, d: var TLoc) =
|
||||||
assert(e.sons[2].typ != nil)
|
assert(e.sons[2].typ != nil)
|
||||||
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 a.t.skipTypes(abstractInst).callConv == ccClosure:
|
if a.t.skipTypes(abstractInstOwned).callConv == ccClosure:
|
||||||
putIntoDest(p, d, e,
|
putIntoDest(p, d, e,
|
||||||
"($1.ClP_0 == $2.ClP_0 && $1.ClE_0 == $2.ClE_0)" % [rdLoc(a), rdLoc(b)])
|
"($1.ClP_0 == $2.ClP_0 && $1.ClE_0 == $2.ClE_0)" % [rdLoc(a), rdLoc(b)])
|
||||||
else:
|
else:
|
||||||
|
|
@ -660,8 +660,8 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
|
|
||||||
proc isCppRef(p: BProc; typ: PType): bool {.inline.} =
|
proc isCppRef(p: BProc; typ: PType): bool {.inline.} =
|
||||||
result = p.module.compileToCpp and
|
result = p.module.compileToCpp and
|
||||||
skipTypes(typ, abstractInst).kind == tyVar and
|
skipTypes(typ, abstractInstOwned).kind == tyVar and
|
||||||
tfVarIsPtr notin skipTypes(typ, abstractInst).flags
|
tfVarIsPtr notin skipTypes(typ, abstractInstOwned).flags
|
||||||
|
|
||||||
proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
|
proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
|
||||||
let mt = mapType(p.config, e.sons[0].typ)
|
let mt = mapType(p.config, e.sons[0].typ)
|
||||||
|
|
@ -775,7 +775,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
|
||||||
genRecordFieldAux(p, e, d, a)
|
genRecordFieldAux(p, e, d, a)
|
||||||
var r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
var f = e.sons[1].sym
|
var f = e.sons[1].sym
|
||||||
let ty = skipTypes(a.t, abstractInst + tyUserTypeClasses)
|
let ty = skipTypes(a.t, abstractInstOwned + tyUserTypeClasses)
|
||||||
if ty.kind == tyTuple:
|
if ty.kind == tyTuple:
|
||||||
# we found a unique tuple type which lacks field information
|
# we found a unique tuple type which lacks field information
|
||||||
# so we use Field$i
|
# so we use Field$i
|
||||||
|
|
@ -1288,7 +1288,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# we skip this step here:
|
# we skip this step here:
|
||||||
if not p.module.compileToCpp:
|
if not p.module.compileToCpp:
|
||||||
if handleConstExpr(p, e, d): return
|
if handleConstExpr(p, e, d): return
|
||||||
var t = e.typ.skipTypes(abstractInst)
|
var t = e.typ.skipTypes(abstractInstOwned)
|
||||||
let isRef = t.kind == tyRef
|
let isRef = t.kind == tyRef
|
||||||
|
|
||||||
# check if we need to construct the object in a temporary
|
# check if we need to construct the object in a temporary
|
||||||
|
|
@ -1304,7 +1304,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
r = rdLoc(tmp)
|
r = rdLoc(tmp)
|
||||||
if isRef:
|
if isRef:
|
||||||
rawGenNew(p, tmp, nil)
|
rawGenNew(p, tmp, nil)
|
||||||
t = t.lastSon.skipTypes(abstractInst)
|
t = t.lastSon.skipTypes(abstractInstOwned)
|
||||||
r = "(*$1)" % [r]
|
r = "(*$1)" % [r]
|
||||||
gcUsage(p.config, e)
|
gcUsage(p.config, e)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1462,12 +1462,12 @@ proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
|
||||||
var dest = skipTypes(typ, typedescPtrs)
|
var dest = skipTypes(typ, typedescPtrs)
|
||||||
var r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
var nilCheck: Rope = nil
|
var nilCheck: Rope = nil
|
||||||
var t = skipTypes(a.t, abstractInst)
|
var t = skipTypes(a.t, abstractInstOwned)
|
||||||
while t.kind in {tyVar, tyLent, tyPtr, tyRef}:
|
while t.kind in {tyVar, tyLent, tyPtr, tyRef}:
|
||||||
if t.kind notin {tyVar, tyLent}: nilCheck = r
|
if t.kind notin {tyVar, tyLent}: nilCheck = r
|
||||||
if t.kind notin {tyVar, tyLent} or not p.module.compileToCpp:
|
if t.kind notin {tyVar, tyLent} or not p.module.compileToCpp:
|
||||||
r = ropecg(p.module, "(*$1)", [r])
|
r = ropecg(p.module, "(*$1)", [r])
|
||||||
t = skipTypes(t.lastSon, typedescInst)
|
t = skipTypes(t.lastSon, typedescInst+{tyOwned})
|
||||||
discard getTypeDesc(p.module, t)
|
discard getTypeDesc(p.module, t)
|
||||||
if not p.module.compileToCpp:
|
if not p.module.compileToCpp:
|
||||||
while t.kind == tyObject and t.sons[0] != nil:
|
while t.kind == tyObject and t.sons[0] != nil:
|
||||||
|
|
@ -1826,7 +1826,7 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# through its address:
|
# through its address:
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
let etyp = skipTypes(e.typ, abstractRange)
|
let etyp = skipTypes(e.typ, abstractRange+{tyOwned})
|
||||||
if etyp.kind in ValueTypes and lfIndirect notin a.flags:
|
if etyp.kind in ValueTypes and lfIndirect notin a.flags:
|
||||||
putIntoDest(p, d, e, "(*($1*) ($2))" %
|
putIntoDest(p, d, e, "(*($1*) ($2))" %
|
||||||
[getTypeDesc(p.module, e.typ), addrLoc(p.config, a)], a.storage)
|
[getTypeDesc(p.module, e.typ), addrLoc(p.config, a)], a.storage)
|
||||||
|
|
@ -2374,7 +2374,7 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, arg, a)
|
initLocExpr(p, arg, a)
|
||||||
var r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
let isRef = skipTypes(arg.typ, abstractInst).kind in {tyRef, tyPtr, tyVar, tyLent}
|
let isRef = skipTypes(arg.typ, abstractInstOwned).kind in {tyRef, tyPtr, tyVar, tyLent}
|
||||||
if isRef:
|
if isRef:
|
||||||
add(r, "->Sup")
|
add(r, "->Sup")
|
||||||
else:
|
else:
|
||||||
|
|
@ -2386,7 +2386,7 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) =
|
||||||
# (see bug #837). However sometimes using a temporary is not correct:
|
# (see bug #837). However sometimes using a temporary is not correct:
|
||||||
# init(TFigure(my)) # where it is passed to a 'var TFigure'. We test
|
# init(TFigure(my)) # where it is passed to a 'var TFigure'. We test
|
||||||
# this by ensuring the destination is also a pointer:
|
# this by ensuring the destination is also a pointer:
|
||||||
if d.k == locNone and skipTypes(n.typ, abstractInst).kind in {tyRef, tyPtr, tyVar, tyLent}:
|
if d.k == locNone and skipTypes(n.typ, abstractInstOwned).kind in {tyRef, tyPtr, tyVar, tyLent}:
|
||||||
getTemp(p, n.typ, d)
|
getTemp(p, n.typ, d)
|
||||||
linefmt(p, cpsStmts, "$1 = &$2;$n", [rdLoc(d), r])
|
linefmt(p, cpsStmts, "$1 = &$2;$n", [rdLoc(d), r])
|
||||||
else:
|
else:
|
||||||
|
|
@ -2618,7 +2618,7 @@ proc genNamedConstExpr(p: BProc, n: PNode): Rope =
|
||||||
else: result = genConstExpr(p, n)
|
else: result = genConstExpr(p, n)
|
||||||
|
|
||||||
proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
|
proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
|
||||||
var t = skipTypes(typ, abstractRange-{tyTypeDesc})
|
var t = skipTypes(typ, abstractRange+{tyOwned}-{tyTypeDesc})
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyBool: result = rope"NIM_FALSE"
|
of tyBool: result = rope"NIM_FALSE"
|
||||||
of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0"
|
of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0"
|
||||||
|
|
@ -2693,7 +2693,7 @@ proc getNullValueAuxT(p: BProc; orig, t: PType; obj, cons: PNode, result: var Ro
|
||||||
|
|
||||||
proc genConstObjConstr(p: BProc; n: PNode): Rope =
|
proc genConstObjConstr(p: BProc; n: PNode): Rope =
|
||||||
result = nil
|
result = nil
|
||||||
let t = n.typ.skipTypes(abstractInst)
|
let t = n.typ.skipTypes(abstractInstOwned)
|
||||||
var count = 0
|
var count = 0
|
||||||
#if not isObjLackingTypeField(t) and not p.module.compileToCpp:
|
#if not isObjLackingTypeField(t) and not p.module.compileToCpp:
|
||||||
# addf(result, "{$1}", [genTypeInfo(p.module, t)])
|
# addf(result, "{$1}", [genTypeInfo(p.module, t)])
|
||||||
|
|
@ -2760,7 +2760,7 @@ proc genConstExpr(p: BProc, n: PNode): Rope =
|
||||||
toBitSet(p.config, n, cs)
|
toBitSet(p.config, n, cs)
|
||||||
result = genRawSetData(cs, int(getSize(p.config, n.typ)))
|
result = genRawSetData(cs, int(getSize(p.config, n.typ)))
|
||||||
of nkBracket, nkPar, nkTupleConstr, nkClosure:
|
of nkBracket, nkPar, nkTupleConstr, nkClosure:
|
||||||
var t = skipTypes(n.typ, abstractInst)
|
var t = skipTypes(n.typ, abstractInstOwned)
|
||||||
if t.kind == tySequence:
|
if t.kind == tySequence:
|
||||||
if p.config.selectedGc == gcDestructors:
|
if p.config.selectedGc == gcDestructors:
|
||||||
result = genConstSeqV2(p, n, n.typ)
|
result = genConstSeqV2(p, n, n.typ)
|
||||||
|
|
|
||||||
|
|
@ -591,7 +591,7 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
|
||||||
# so these all act like 'sink' parameters:
|
# so these all act like 'sink' parameters:
|
||||||
ri2[i].sons[1] = pArg(ri[i][1], c, isSink = true)
|
ri2[i].sons[1] = pArg(ri[i][1], c, isSink = true)
|
||||||
result.add ri2
|
result.add ri2
|
||||||
of nkTupleConstr:
|
of nkTupleConstr, nkClosure:
|
||||||
result = genSink(c, dest.typ, dest, ri)
|
result = genSink(c, dest.typ, dest, ri)
|
||||||
let ri2 = copyTree(ri)
|
let ri2 = copyTree(ri)
|
||||||
for i in 0..<ri.len:
|
for i in 0..<ri.len:
|
||||||
|
|
@ -686,7 +686,7 @@ proc p(n: PNode; c: var Con): PNode =
|
||||||
elif it.kind == nkIdentDefs and hasDestructor(it[0].typ) and not isCursor(it[0]):
|
elif it.kind == nkIdentDefs and hasDestructor(it[0].typ) and not isCursor(it[0]):
|
||||||
for j in 0..L-3:
|
for j in 0..L-3:
|
||||||
let v = it[j]
|
let v = it[j]
|
||||||
doAssert v.kind == nkSym
|
if v.kind == nkSym:
|
||||||
# move the variable declaration to the top of the frame:
|
# move the variable declaration to the top of the frame:
|
||||||
c.addTopVar v
|
c.addTopVar v
|
||||||
# make sure it's destroyed at the end of the proc:
|
# make sure it's destroyed at the end of the proc:
|
||||||
|
|
|
||||||
|
|
@ -396,7 +396,7 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
xx.typ = getSysType(c.graph, c.info, tyPointer)
|
xx.typ = getSysType(c.graph, c.info, tyPointer)
|
||||||
var actions = newNodeI(nkStmtList, c.info)
|
var actions = newNodeI(nkStmtList, c.info)
|
||||||
let elemType = t.lastSon
|
let elemType = t.lastSon
|
||||||
discard addDestructorCall(c, elemType, newNodeI(nkStmtList, c.info), genDeref(xx))
|
#discard addDestructorCall(c, elemType, newNodeI(nkStmtList, c.info), genDeref(xx))
|
||||||
actions.add callCodegenProc(c.graph, "nimDestroyAndDispose", c.info, xx)
|
actions.add callCodegenProc(c.graph, "nimDestroyAndDispose", c.info, xx)
|
||||||
case c.kind
|
case c.kind
|
||||||
of attachedSink, attachedAsgn:
|
of attachedSink, attachedAsgn:
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,9 @@ const
|
||||||
abstractRange* = {tyGenericInst, tyRange, tyDistinct, tyOrdinal, tyTypeDesc,
|
abstractRange* = {tyGenericInst, tyRange, tyDistinct, tyOrdinal, tyTypeDesc,
|
||||||
tyAlias, tyInferred, tySink, tyOwned}
|
tyAlias, tyInferred, tySink, tyOwned}
|
||||||
abstractVarRange* = {tyGenericInst, tyRange, tyVar, tyDistinct, tyOrdinal,
|
abstractVarRange* = {tyGenericInst, tyRange, tyVar, tyDistinct, tyOrdinal,
|
||||||
tyTypeDesc, tyAlias, tyInferred, tySink}
|
tyTypeDesc, tyAlias, tyInferred, tySink, tyOwned}
|
||||||
abstractInst* = {tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias,
|
abstractInst* = {tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias,
|
||||||
tyInferred, tySink}
|
tyInferred, tySink, tyOwned}
|
||||||
abstractInstOwned* = abstractInst + {tyOwned}
|
abstractInstOwned* = abstractInst + {tyOwned}
|
||||||
skipPtrs* = {tyVar, tyPtr, tyRef, tyGenericInst, tyTypeDesc, tyAlias,
|
skipPtrs* = {tyVar, tyPtr, tyRef, tyGenericInst, tyTypeDesc, tyAlias,
|
||||||
tyInferred, tySink, tyLent, tyOwned}
|
tyInferred, tySink, tyLent, tyOwned}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue