new destroyer pass works with procs too
This commit is contained in:
parent
ffe52a7f7b
commit
5dca695bcf
4 changed files with 11 additions and 9 deletions
|
|
@ -290,4 +290,7 @@ proc injectDestructorCalls*(owner: PSym; n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
result.add body
|
result.add body
|
||||||
|
|
||||||
#echo "transformed into: ", result
|
when false:
|
||||||
|
echo "------------------------------------"
|
||||||
|
echo owner.name.s, " transformed from: ", n
|
||||||
|
echo result
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ proc addToVarSection(c: PContext; result: var PNode; orig, identDefs: PNode) =
|
||||||
# in order for this transformation to be correct.
|
# in order for this transformation to be correct.
|
||||||
let L = identDefs.len
|
let L = identDefs.len
|
||||||
let value = identDefs[L-1]
|
let value = identDefs[L-1]
|
||||||
if value.typ != nil and tfHasAsgn in value.typ.flags and c.p.owner.kind != skFunc:
|
if value.typ != nil and tfHasAsgn in value.typ.flags and not newDestructors:
|
||||||
# the spec says we need to rewrite 'var x = T()' to 'var x: T; x = T()':
|
# the spec says we need to rewrite 'var x = T()' to 'var x: T; x = T()':
|
||||||
identDefs.sons[L-1] = emptyNode
|
identDefs.sons[L-1] = emptyNode
|
||||||
if result.kind != nkStmtList:
|
if result.kind != nkStmtList:
|
||||||
|
|
|
||||||
|
|
@ -971,11 +971,11 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
|
||||||
result = processTransf(c, result, prc)
|
result = processTransf(c, result, prc)
|
||||||
liftDefer(c, result)
|
liftDefer(c, result)
|
||||||
#result = liftLambdas(prc, result)
|
#result = liftLambdas(prc, result)
|
||||||
incl(result.flags, nfTransf)
|
|
||||||
when useEffectSystem: trackProc(prc, result)
|
when useEffectSystem: trackProc(prc, result)
|
||||||
if c.needsDestroyPass and newDestructors:
|
if c.needsDestroyPass and newDestructors:
|
||||||
result = injectDestructorCalls(prc, result)
|
result = injectDestructorCalls(prc, result)
|
||||||
#if prc.name.s == "testbody":
|
incl(result.flags, nfTransf)
|
||||||
|
#if prc.name.s == "testbody":
|
||||||
# echo renderTree(result)
|
# echo renderTree(result)
|
||||||
|
|
||||||
proc transformStmt*(module: PSym, n: PNode): PNode =
|
proc transformStmt*(module: PSym, n: PNode): PNode =
|
||||||
|
|
@ -986,12 +986,12 @@ proc transformStmt*(module: PSym, n: PNode): PNode =
|
||||||
result = processTransf(c, n, module)
|
result = processTransf(c, n, module)
|
||||||
liftDefer(c, result)
|
liftDefer(c, result)
|
||||||
#result = liftLambdasForTopLevel(module, result)
|
#result = liftLambdasForTopLevel(module, result)
|
||||||
incl(result.flags, nfTransf)
|
|
||||||
when useEffectSystem: trackTopLevelStmt(module, result)
|
when useEffectSystem: trackTopLevelStmt(module, result)
|
||||||
#if n.info ?? "temp.nim":
|
#if n.info ?? "temp.nim":
|
||||||
# echo renderTree(result, {renderIds})
|
# echo renderTree(result, {renderIds})
|
||||||
if c.needsDestroyPass and newDestructors:
|
if c.needsDestroyPass and newDestructors:
|
||||||
result = injectDestructorCalls(module, result)
|
result = injectDestructorCalls(module, result)
|
||||||
|
incl(result.flags, nfTransf)
|
||||||
|
|
||||||
proc transformExpr*(module: PSym, n: PNode): PNode =
|
proc transformExpr*(module: PSym, n: PNode): PNode =
|
||||||
if nfTransf in n.flags:
|
if nfTransf in n.flags:
|
||||||
|
|
@ -1000,6 +1000,6 @@ proc transformExpr*(module: PSym, n: PNode): PNode =
|
||||||
var c = openTransf(module, "")
|
var c = openTransf(module, "")
|
||||||
result = processTransf(c, n, module)
|
result = processTransf(c, n, module)
|
||||||
liftDefer(c, result)
|
liftDefer(c, result)
|
||||||
incl(result.flags, nfTransf)
|
|
||||||
if c.needsDestroyPass and newDestructors:
|
if c.needsDestroyPass and newDestructors:
|
||||||
result = injectDestructorCalls(module, result)
|
result = injectDestructorCalls(module, result)
|
||||||
|
incl(result.flags, nfTransf)
|
||||||
|
|
|
||||||
|
|
@ -78,11 +78,11 @@ proc create*(lit: string): mystring =
|
||||||
copyMem(addr result.data[result.len], unsafeAddr lit[0], newLen + 1)
|
copyMem(addr result.data[result.len], unsafeAddr lit[0], newLen + 1)
|
||||||
result.len = newLen
|
result.len = newLen
|
||||||
|
|
||||||
func `&`*(a, b: mystring): mystring =
|
proc `&`*(a, b: mystring): mystring =
|
||||||
result = a
|
result = a
|
||||||
result.add b
|
result.add b
|
||||||
|
|
||||||
func main(n: int) =
|
proc main(n: int) =
|
||||||
var a: mystring
|
var a: mystring
|
||||||
let b = create" to append"
|
let b = create" to append"
|
||||||
for i in 0..<n:
|
for i in 0..<n:
|
||||||
|
|
@ -92,6 +92,5 @@ func main(n: int) =
|
||||||
a.add c
|
a.add c
|
||||||
echo cstring(a.data)
|
echo cstring(a.data)
|
||||||
|
|
||||||
|
|
||||||
main(1000)
|
main(1000)
|
||||||
echo "after ", allocCount, " ", deallocCount
|
echo "after ", allocCount, " ", deallocCount
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue