diff options
author | Araq <rumpf_a@web.de> | 2019-04-26 15:44:06 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-04-26 15:44:06 +0200 |
commit | b350a9fc52d67cabc778887d8f81d0332eb9db91 (patch) | |
tree | 8b87a40962503cedfcf0159e9e287b2f27b46d72 /compiler | |
parent | 1f7615ad9db3e8f90b20aa9932c3c11ee1793218 (diff) | |
download | Nim-b350a9fc52d67cabc778887d8f81d0332eb9db91.tar.gz |
preparations to make the twidgets test work
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 4 | ||||
-rw-r--r-- | compiler/injectdestructors.nim | 22 |
2 files changed, 15 insertions, 11 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 65cc6e42e..0ac6b42f4 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1918,14 +1918,14 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, e.sons[1], a) let etyp = skipTypes(e.typ, abstractRange+{tyOwned}) + let srcTyp = skipTypes(e.sons[1].typ, abstractRange) if etyp.kind in ValueTypes and lfIndirect notin a.flags: putIntoDest(p, d, e, "(*($1*) ($2))" % [getTypeDesc(p.module, e.typ), addrLoc(p.config, a)], a.storage) - elif etyp.kind == tyProc and etyp.callConv == ccClosure: + elif etyp.kind == tyProc and etyp.callConv == ccClosure and srcTyp.callConv != ccClosure: putIntoDest(p, d, e, "(($1) ($2))" % [getClosureType(p.module, etyp, clHalfWithEnv), rdCharLoc(a)], a.storage) else: - let srcTyp = skipTypes(e.sons[1].typ, abstractRange) # C++ does not like direct casts from pointer to shorter integral types if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes: putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" % diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 73ff0869c..197d15490 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -701,6 +701,15 @@ proc injectDefaultCalls(n: PNode, c: var Con) = proc isCursor(n: PNode): bool {.inline.} = result = n.kind == nkSym and sfCursor in n.sym.flags +proc keepVar(n, it: PNode, c: var Con): PNode = + # keep the var but transform 'ri': + result = copyNode(n) + var itCopy = copyNode(it) + for j in 0..it.len-2: + itCopy.add it[j] + itCopy.add p(it[it.len-1], c) + result.add itCopy + proc p(n: PNode; c: var Con): PNode = case n.kind of nkVarSection, nkLetSection: @@ -726,15 +735,10 @@ proc p(n: PNode; c: var Con): PNode = if ri.kind != nkEmpty: let r = moveOrCopy(v, ri, c) result.add r + else: + result.add keepVar(n, it, c) else: - # keep it, but transform 'ri': - var varSection = copyNode(n) - var itCopy = copyNode(it) - for j in 0..L-2: - itCopy.add it[j] - itCopy.add p(ri, c) - varSection.add itCopy - result.add varSection + result.add keepVar(n, it, c) of nkCallKinds: let parameters = n[0].typ let L = if parameters != nil: parameters.len else: 0 @@ -752,7 +756,7 @@ proc p(n: PNode; c: var Con): PNode = else: result = n of nkAsgn, nkFastAsgn: - if hasDestructor(n[0].typ): + if hasDestructor(n[0].typ) and n[1].kind notin {nkProcDef, nkDo, nkLambda, nkClosure}: result = moveOrCopy(n[0], n[1], c) else: result = copyNode(n) |