mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Reduce the scope of the try...except block to only cover the call.
Major indentation changes, but minor actual changes.
This commit is contained in:
parent
44a9c9a40c
commit
a8231586c1
1 changed files with 38 additions and 38 deletions
|
@ -940,52 +940,52 @@ class foldconst(object):
|
||||||
if CONSTargs:
|
if CONSTargs:
|
||||||
# Call it
|
# Call it
|
||||||
fn = sym['Fn']
|
fn = sym['Fn']
|
||||||
|
args = [arg['value'] for arg in child]
|
||||||
|
argtypes = sym['ParamTypes']
|
||||||
|
assert(len(args) == len(argtypes))
|
||||||
|
for argnum in range(len(args)):
|
||||||
|
# Adapt types of params
|
||||||
|
if argtypes[argnum] == 'string':
|
||||||
|
args[argnum] = lslfuncs.fs(args[argnum])
|
||||||
|
elif argtypes[argnum] == 'key':
|
||||||
|
args[argnum] = lslfuncs.fk(args[argnum])
|
||||||
|
elif argtypes[argnum] == 'float':
|
||||||
|
args[argnum] = lslfuncs.ff(args[argnum])
|
||||||
|
elif argtypes[argnum] == 'vector':
|
||||||
|
args[argnum] = lslfuncs.v2f(args[argnum])
|
||||||
|
elif argtypes[argnum] == 'quaternion':
|
||||||
|
args[argnum] = lslfuncs.q2f(args[argnum])
|
||||||
|
elif argtypes[argnum] == 'list':
|
||||||
|
# ensure vectors and quaternions passed to
|
||||||
|
# functions have only float components
|
||||||
|
assert type(args[argnum]) == list
|
||||||
|
# make a shallow copy
|
||||||
|
args[argnum] = args[argnum][:]
|
||||||
|
for i in range(len(args[argnum])):
|
||||||
|
if type(args[argnum][i]) == lslcommon.Quaternion:
|
||||||
|
args[argnum][i] = lslfuncs.q2f(args[argnum][i])
|
||||||
|
elif type(args[argnum][i]) == lslcommon.Vector:
|
||||||
|
args[argnum][i] = lslfuncs.v2f(args[argnum][i])
|
||||||
|
del argtypes
|
||||||
try:
|
try:
|
||||||
args = [arg['value'] for arg in child]
|
|
||||||
argtypes = sym['ParamTypes']
|
|
||||||
assert(len(args) == len(argtypes))
|
|
||||||
for argnum in range(len(args)):
|
|
||||||
# Adapt types of params
|
|
||||||
if argtypes[argnum] == 'string':
|
|
||||||
args[argnum] = lslfuncs.fs(args[argnum])
|
|
||||||
elif argtypes[argnum] == 'key':
|
|
||||||
args[argnum] = lslfuncs.fk(args[argnum])
|
|
||||||
elif argtypes[argnum] == 'float':
|
|
||||||
args[argnum] = lslfuncs.ff(args[argnum])
|
|
||||||
elif argtypes[argnum] == 'vector':
|
|
||||||
args[argnum] = lslfuncs.v2f(args[argnum])
|
|
||||||
elif argtypes[argnum] == 'quaternion':
|
|
||||||
args[argnum] = lslfuncs.q2f(args[argnum])
|
|
||||||
elif argtypes[argnum] == 'list':
|
|
||||||
# ensure vectors and quaternions passed to
|
|
||||||
# functions have only float components
|
|
||||||
assert type(args[argnum]) == list
|
|
||||||
# make a shallow copy
|
|
||||||
args[argnum] = args[argnum][:]
|
|
||||||
for i in range(len(args[argnum])):
|
|
||||||
if type(args[argnum][i]) == lslcommon.Quaternion:
|
|
||||||
args[argnum][i] = lslfuncs.q2f(args[argnum][i])
|
|
||||||
elif type(args[argnum][i]) == lslcommon.Vector:
|
|
||||||
args[argnum][i] = lslfuncs.v2f(args[argnum][i])
|
|
||||||
del argtypes
|
|
||||||
if node['name'][:10] == 'llDetected':
|
if node['name'][:10] == 'llDetected':
|
||||||
value = fn(*args, event=self.CurEvent)
|
value = fn(*args, event=self.CurEvent)
|
||||||
else:
|
else:
|
||||||
value = fn(*args)
|
value = fn(*args)
|
||||||
del args
|
|
||||||
if not self.foldtabs:
|
|
||||||
generatesTabs = (
|
|
||||||
isinstance(value, unicode) and '\t' in value
|
|
||||||
or type(value) == list and any(isinstance(x, unicode) and '\t' in x for x in value)
|
|
||||||
)
|
|
||||||
if generatesTabs:
|
|
||||||
if self.warntabs:
|
|
||||||
warning(u"Can't optimize call to %s because it would generate a tab character (you can force the optimization with the 'foldtabs' option, or disable this warning by disabling the 'warntabs' option)." % node['name'].decode('utf8'))
|
|
||||||
return
|
|
||||||
parent[index] = {'nt':'CONST', 't':node['t'], 'value':value}
|
|
||||||
except lslfuncs.ELSLCantCompute:
|
except lslfuncs.ELSLCantCompute:
|
||||||
# Don't transform the tree if function is not computable
|
# Don't transform the tree if function is not computable
|
||||||
pass
|
pass
|
||||||
|
del args
|
||||||
|
if not self.foldtabs:
|
||||||
|
generatesTabs = (
|
||||||
|
isinstance(value, unicode) and '\t' in value
|
||||||
|
or type(value) == list and any(isinstance(x, unicode) and '\t' in x for x in value)
|
||||||
|
)
|
||||||
|
if generatesTabs:
|
||||||
|
if self.warntabs:
|
||||||
|
warning(u"Can't optimize call to %s because it would generate a tab character (you can force the optimization with the 'foldtabs' option, or disable this warning by disabling the 'warntabs' option)." % node['name'].decode('utf8'))
|
||||||
|
return
|
||||||
|
parent[index] = {'nt':'CONST', 't':node['t'], 'value':value}
|
||||||
elif node['name'] == 'llGetListLength':
|
elif node['name'] == 'llGetListLength':
|
||||||
# Convert llGetListLength(expr) to (expr != [])
|
# Convert llGetListLength(expr) to (expr != [])
|
||||||
node = {'nt':'CONST', 't':'list', 'value':[]}
|
node = {'nt':'CONST', 't':'list', 'value':[]}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue