mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Be a bit smarter when optimizing out default labels.
(Was a TODO item). Also cosmetic changes.
This commit is contained in:
parent
3669bbb06e
commit
91ad438bb7
1 changed files with 16 additions and 11 deletions
|
@ -1695,21 +1695,26 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
if switchcasedefault is None:
|
if switchcasedefault is None:
|
||||||
if self.errmissingdefault:
|
if self.errmissingdefault:
|
||||||
raise EParseMissingDefault(self)
|
raise EParseMissingDefault(self)
|
||||||
# Check if it's worth adding a break. If there's no executable
|
# Check if it's worth adding a break label. If there's no
|
||||||
# code, there's no point. However, this check is insufficient.
|
# executable code, there's no point. However, this check is
|
||||||
# It misses SEF expressions. For that reason, this is best left
|
# insufficient. It misses SEF expressions. For that reason,
|
||||||
# up to a later optimizer that knows about SEF. But we do a
|
# this is best left up to a later optimizer that knows about
|
||||||
# preliminary elimination here.
|
# SEF. But we do a preliminary elimination here.
|
||||||
if self.does_something(blk):
|
if self.does_something(blk):
|
||||||
switchcasedefault = brk
|
switchcasedefault = brk
|
||||||
self.breakstack[-1][2] = True
|
self.breakstack[-1][2] = True
|
||||||
else:
|
else:
|
||||||
# TODO: Keep checking until there's output-generating code.
|
# Check if no code up to the default label does anything.
|
||||||
# For example, this isn't optimized due to the semicolon:
|
# If so, remove the label and don't generate the jump.
|
||||||
# switch(1) { ; default: 1; }
|
for i in xrange(len(blk)):
|
||||||
if blk and blk[0]['nt'] == '@' and blk[0]['name'] == switchcasedefault:
|
node = blk[i]
|
||||||
switchcasedefault = None
|
if node['nt'] == '@' and node['name'] == switchcasedefault:
|
||||||
del blk[0]
|
switchcasedefault = None
|
||||||
|
del blk[i]
|
||||||
|
break
|
||||||
|
if self.does_something([node]):
|
||||||
|
break
|
||||||
|
del i, node
|
||||||
|
|
||||||
if switchcasedefault is not None:
|
if switchcasedefault is not None:
|
||||||
prelude.append({'nt':'JUMP', 't':None, 'name':switchcasedefault,
|
prelude.append({'nt':'JUMP', 't':None, 'name':switchcasedefault,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue