mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Fold again after applying distributibity or absortion.
Failure to do so was blocking some constant folding, like in: if (a&1 || a&2 || a&4) -> if (a&(3|4)) Fixed. Now it correctly outputs if (a&7).
This commit is contained in:
parent
6c73ba95c2
commit
4cbdbefe1b
1 changed files with 7 additions and 0 deletions
|
@ -1125,6 +1125,7 @@ class foldconst(object):
|
|||
parent[index] = child[b]
|
||||
|
||||
# Apply boolean distributivity
|
||||
applied = False
|
||||
opposite = '&' if nt == '|' else '|'
|
||||
if child[0]['nt'] == child[1]['nt'] == opposite:
|
||||
left = child[0]['ch']
|
||||
|
@ -1136,6 +1137,7 @@ class foldconst(object):
|
|||
opposite = child[1]['nt']
|
||||
right[d] = left[1 - c]
|
||||
child[0] = left[c]
|
||||
applied = True
|
||||
break
|
||||
|
||||
# Apply absorption, possibly after distributivity
|
||||
|
@ -1148,8 +1150,13 @@ class foldconst(object):
|
|||
node = parent[index] = child[c]
|
||||
nt = node['nt']
|
||||
child = node['ch'] if 'ch' in node else None
|
||||
applied = True
|
||||
break
|
||||
|
||||
if applied:
|
||||
# Re-fold
|
||||
self.FoldTree(parent, index)
|
||||
|
||||
return
|
||||
|
||||
if nt == '^':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue