mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Get rid of StSw craziness and use lsllastpass to make another pass.
This has been a TODO item for long. Now that we have lsllastpass, it's actually easy to implement. Adds an LSLTypeDefaults dictionary to lslcommon, just in case the state-changing function returns a value and we need to insert a return statement. We've also added subtree-local info to lsllastpass (lost when we return to the parent after visiting a subtree). This fixes a bug where naked switch statements could appear as a result of optimization, and cause the compilation to fail.
This commit is contained in:
parent
e4eaab9e84
commit
a87022b73f
4 changed files with 77 additions and 29 deletions
|
@ -1543,8 +1543,6 @@ class foldconst(object):
|
|||
or child[idx]['nt'] == '{}' and not child[idx]['ch']:
|
||||
del child[idx]
|
||||
else:
|
||||
if 'StSw' in child[idx]:
|
||||
node['StSw'] = True
|
||||
idx += 1
|
||||
if issef:
|
||||
node['SEF'] = True
|
||||
|
@ -1558,27 +1556,14 @@ class foldconst(object):
|
|||
# We might be able to remove one of the branches.
|
||||
if lslfuncs.cond(child[0]['value']):
|
||||
self.FoldTree(child, 1)
|
||||
# If it has a state switch, the if() must be preserved
|
||||
# (but the else branch may be removed).
|
||||
if 'StSw' in child[1]:
|
||||
# TODO: Get rid of StSw craziness and make another pass
|
||||
# to put them under conditionals if present (if bald
|
||||
# state switches are present, it means they are the
|
||||
# result of optimization so they must be wrapped in an
|
||||
# IF statement). The current approach leaves unnecessary
|
||||
# IFs behind.
|
||||
if len(child) == 3 and child[2]['nt'] != '@':
|
||||
del child[2] # Delete ELSE if present
|
||||
return
|
||||
else:
|
||||
self.FoldStmt(child, 1)
|
||||
if len(child) == 3 and child[2]['nt'] == '@':
|
||||
# Corner case. The label is in the same scope as
|
||||
# this statement, so it must be preserved just in
|
||||
# case it's jumped to.
|
||||
return
|
||||
parent[index] = child[1]
|
||||
self.FoldStmt(child, 1)
|
||||
if len(child) == 3 and child[2]['nt'] == '@':
|
||||
# Corner case. The label is in the same scope as
|
||||
# this statement, so it must be preserved just in
|
||||
# case it's jumped to.
|
||||
return
|
||||
parent[index] = child[1]
|
||||
return
|
||||
elif len(child) == 3:
|
||||
self.FoldTree(child, 2)
|
||||
self.FoldStmt(child, 2)
|
||||
|
@ -1788,7 +1773,6 @@ class foldconst(object):
|
|||
|
||||
if nt == 'STSW':
|
||||
# State switch always has side effects.
|
||||
node['StSw'] = True
|
||||
return
|
||||
|
||||
if nt == 'SUBIDX':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue