Minor cleanups; no functional changes.

lslcleanup: Variables renamed, order changed, comments added.

Other changes: remove semicolon at end of sentence, use self.Cast instead of creating a CAST node on the fly.
This commit is contained in:
Sei Lisa 2017-09-22 14:17:56 +02:00
parent 0a7e2a9e1d
commit a0d4c77081
3 changed files with 24 additions and 24 deletions

View file

@ -72,7 +72,7 @@ def llDetectedName(idx, event=None):
assert isinteger(idx) assert isinteger(idx)
if 0 <= idx <= 15 and (event in DetectionEvents or event is None): if 0 <= idx <= 15 and (event in DetectionEvents or event is None):
raise ELSLCantCompute raise ELSLCantCompute
return NULL_KEY; return NULL_KEY
def llDetectedOwner(idx, event=None): def llDetectedOwner(idx, event=None):
assert isinteger(idx) assert isinteger(idx)

View file

@ -195,10 +195,7 @@ def OptimizeFunc(self, parent, index):
node['nt'] = 'CAST' node['nt'] = 'CAST'
del child[1] del child[1]
del node['name'] del node['name']
child[0] = {'nt':'CAST', 't':'string', child[0] = self.Cast(child[0], 'string')
'ch':[child[0]]}
if 'SEF' in child[0]['ch'][0]:
child[0]['SEF'] = True
return return
# Check for type incompatibility or index out of range # Check for type incompatibility or index out of range

View file

@ -45,32 +45,35 @@ class lastpass(object):
# This transformation makes it difficult to handle lists during # This transformation makes it difficult to handle lists during
# optimization, that's why it's done in a separate pass. # optimization, that's why it's done in a separate pass.
top = child[0] if nt == '+' else None
elemnode = child[1] if nt == '+' else node # Make listnode be the LIST or CONST element.
if 'SEF' in elemnode: listnode = child[1] if nt == '+' else node
elements = (elemnode['value'] if elemnode['nt'] == 'CONST'
else elemnode['ch']) # left is the leftmost element in the addition.
for v in elements: # left = None means the first element of the list must be
elem = v if elemnode['nt'] != 'CONST' else { # turned into a cast within the loop.
'nt':'CONST', left = child[0] if nt == '+' else None
't':lslcommon.PythonType2LSL[type(v)], if 'SEF' in listnode:
for elem in (listnode['value'] if listnode['nt'] == 'CONST'
else listnode['ch']):
elemnode = {'nt':'CONST',
't':lslcommon.PythonType2LSL[type(elem)],
'SEF':True, 'SEF':True,
'value':v} 'value':elem
top = {'nt':'CAST', 't':'list', 'SEF':True, } if listnode['nt'] == 'CONST' else elem
'ch':[elem] left = self.Cast(elemnode, 'list') if left is None else {
} if top is None else {
'nt':'+', 't':'list', 'SEF':True, 'nt':'+', 't':'list', 'SEF':True,
'ch':[top, elem] 'ch':[left, elemnode]
} }
del elem del elemnode
if top is not None: if left is not None: # it's none for empty lists
parent[index] = top parent[index] = left
nt = top['nt']
# Do another pass on the result # Do another pass on the result
self.RecursiveLastPass(parent, index) self.RecursiveLastPass(parent, index)
del top
return return
del listnode, left
def LastPassPostOrder(self, parent, index): def LastPassPostOrder(self, parent, index):
pass pass