some progress on destroyer.nim
This commit is contained in:
parent
503248efde
commit
91981c07bd
2 changed files with 58 additions and 2 deletions
|
|
@ -186,10 +186,67 @@ when false:
|
||||||
of nkVarSection, nkLetSection: collectVarSection(c, n)
|
of nkVarSection, nkLetSection: collectVarSection(c, n)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
|
type
|
||||||
|
Con = object
|
||||||
|
owner: PSym
|
||||||
|
g: ControlFlowGraph
|
||||||
|
tmps: PType
|
||||||
|
|
||||||
|
proc isHarmlessVar*(s: PSym; c: Con): bool =
|
||||||
|
# 's' is harmless if it used only once and its
|
||||||
|
# definition/usage are not split by any labels:
|
||||||
|
#
|
||||||
|
# let s = foo()
|
||||||
|
# while true:
|
||||||
|
# a[i] = s
|
||||||
|
#
|
||||||
|
# produces:
|
||||||
|
#
|
||||||
|
# def s
|
||||||
|
# L1:
|
||||||
|
# use s
|
||||||
|
# goto L1
|
||||||
|
#
|
||||||
|
# let s = foo()
|
||||||
|
# if cond:
|
||||||
|
# a[i] = s
|
||||||
|
# else:
|
||||||
|
# a[j] = s
|
||||||
|
#
|
||||||
|
# produces:
|
||||||
|
#
|
||||||
|
# def s
|
||||||
|
# fork L2
|
||||||
|
# use s
|
||||||
|
# goto L3
|
||||||
|
# L2:
|
||||||
|
# use s
|
||||||
|
# L3
|
||||||
|
#
|
||||||
|
# So this analysis is for now overly conservative, but correct.
|
||||||
|
discard
|
||||||
|
|
||||||
|
template interestingSym(s: PSym): bool =
|
||||||
|
s.owner == owner and s.kind in InterestingSyms and hasDestructor(s.typ)
|
||||||
|
|
||||||
|
proc p(n, parent: PNode; c: var Con) =
|
||||||
|
case n.kind
|
||||||
|
of nkVarSection, nkLetSection:
|
||||||
|
discard "transform; var x = y to var x; x op y where op is a move or copy"
|
||||||
|
of nkCallKinds:
|
||||||
|
if n.typ != nil and hasDestructor(n.typ):
|
||||||
|
discard "produce temp creation"
|
||||||
|
of nkAsgn, nkFastAsgn:
|
||||||
|
if n[0].kind == nkSym and interestingSym(n[0].sym):
|
||||||
|
discard "use move or assignment"
|
||||||
|
else:
|
||||||
|
for i in 0..<n.len:
|
||||||
|
p(n[i], n, c)
|
||||||
|
|
||||||
proc injectDestructorCalls*(owner: PSym; n: PNode;
|
proc injectDestructorCalls*(owner: PSym; n: PNode;
|
||||||
disableExceptions = false): PNode =
|
disableExceptions = false): PNode =
|
||||||
when false:
|
when false:
|
||||||
var c = Con(t: initTable[int, VarInfo](), owner: owner)
|
var c = Con(t: initTable[int, VarInfo](), owner: owner)
|
||||||
collectData(c, n)
|
collectData(c, n)
|
||||||
var allTemps = createObj(owner, n.info)
|
var allTemps = createObj(owner, n.info)
|
||||||
|
let cfg = constructCfg(owner, n)
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -1,7 +1,6 @@
|
||||||
version 1.0 battle plan
|
version 1.0 battle plan
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
- disallow conversions from ``array`` to ``cstring``!
|
|
||||||
- make 'not nil' the default (produce warnings instead of errors for
|
- make 'not nil' the default (produce warnings instead of errors for
|
||||||
a smooth migration path)
|
a smooth migration path)
|
||||||
- case objects needs to be safe and need to support pattern matching
|
- case objects needs to be safe and need to support pattern matching
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue