document compiler procs regarding & (#20257)
This commit is contained in:
parent
fdb781c713
commit
8fc19b9e12
3 changed files with 8 additions and 2 deletions
|
|
@ -1197,7 +1197,7 @@ proc strLoc(p: BProc; d: TLoc): Rope =
|
||||||
|
|
||||||
proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
|
proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# <Nim code>
|
# <Nim code>
|
||||||
# s = 'Hello ' & name & ', how do you feel?' & 'z'
|
# s = "Hello " & name & ", how do you feel?" & 'z'
|
||||||
#
|
#
|
||||||
# <generated C code>
|
# <generated C code>
|
||||||
# {
|
# {
|
||||||
|
|
@ -1240,7 +1240,7 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
|
||||||
|
|
||||||
proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# <Nim code>
|
# <Nim code>
|
||||||
# s &= 'Hello ' & name & ', how do you feel?' & 'z'
|
# s &= "Hello " & name & ", how do you feel?" & 'z'
|
||||||
# // BUG: what if s is on the left side too?
|
# // BUG: what if s is on the left side too?
|
||||||
# <generated C code>
|
# <generated C code>
|
||||||
# {
|
# {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
# This include implements the high level optimization pass.
|
# This include implements the high level optimization pass.
|
||||||
|
# included from sem.nim
|
||||||
|
|
||||||
when defined(nimPreviewSlimSystem):
|
when defined(nimPreviewSlimSystem):
|
||||||
import std/assertions
|
import std/assertions
|
||||||
|
|
|
||||||
|
|
@ -806,6 +806,8 @@ proc getMergeOp(n: PNode): PSym =
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc flattenTreeAux(d, a: PNode, op: PSym) =
|
proc flattenTreeAux(d, a: PNode, op: PSym) =
|
||||||
|
## Optimizes away the `&` calls in the children nodes and
|
||||||
|
## lifts the leaf nodes to the same level as `op2`.
|
||||||
let op2 = getMergeOp(a)
|
let op2 = getMergeOp(a)
|
||||||
if op2 != nil and
|
if op2 != nil and
|
||||||
(op2.id == op.id or op.magic != mNone and op2.magic == op.magic):
|
(op2.id == op.id or op.magic != mNone and op2.magic == op.magic):
|
||||||
|
|
@ -898,6 +900,9 @@ proc transformExceptBranch(c: PTransf, n: PNode): PNode =
|
||||||
result = transformSons(c, n)
|
result = transformSons(c, n)
|
||||||
|
|
||||||
proc commonOptimizations*(g: ModuleGraph; idgen: IdGenerator; c: PSym, n: PNode): PNode =
|
proc commonOptimizations*(g: ModuleGraph; idgen: IdGenerator; c: PSym, n: PNode): PNode =
|
||||||
|
## Merges adjacent constant expressions of the children of the `&` call into
|
||||||
|
## a single constant expression. It also inlines constant expressions which are not
|
||||||
|
## complex.
|
||||||
result = n
|
result = n
|
||||||
for i in 0..<n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
result[i] = commonOptimizations(g, idgen, c, n[i])
|
result[i] = commonOptimizations(g, idgen, c, n[i])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue