mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Implement ~-~-~-expr -> expr + -3
Gets rid of a TODO
This commit is contained in:
parent
464797020a
commit
a33dc8540f
1 changed files with 14 additions and 1 deletions
|
@ -688,7 +688,20 @@ class foldconst(object):
|
||||||
subexpr = child[0]
|
subexpr = child[0]
|
||||||
node.SEF = subexpr.SEF
|
node.SEF = subexpr.SEF
|
||||||
|
|
||||||
# TODO: ~-~-~-expr -> expr + -3 (see NEG for similar exp + 3)
|
if child[0].nt == 'NEG':
|
||||||
|
track = child[0].ch[0]
|
||||||
|
const = -1
|
||||||
|
while track.nt == '~' and track.ch[0].nt == 'NEG':
|
||||||
|
const -= 1
|
||||||
|
track = track.ch[0].ch[0]
|
||||||
|
if const < -2:
|
||||||
|
# ~-~-~-expr -> expr + (-3)
|
||||||
|
node = nr(nt='CONST', t='integer', SEF=True, value=const)
|
||||||
|
node = nr(nt='+', t='integer', ch=[node, track],
|
||||||
|
SEF=track.SEF)
|
||||||
|
parent[index] = node
|
||||||
|
self.FoldTree(parent, index)
|
||||||
|
return
|
||||||
|
|
||||||
if subexpr.nt == '~':
|
if subexpr.nt == '~':
|
||||||
# Double negation: ~~expr
|
# Double negation: ~~expr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue