mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix type conversion on calling LSL functions.
We had a big chaos with type conversion. That caused a bug where passing a key to a function that required a string, or vice versa, crashed the script. Diminish the chaos by modifying the parameters just prior to invocation (in lslfoldconst). We also remove the, now unnecessary, calls to force floats, either alone or within vectors or quaternions.
This commit is contained in:
parent
27eeec06cf
commit
6879037735
4 changed files with 80 additions and 47 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
# Constant folding and simplification of expressions and statements.
|
||||
|
||||
import lslcommon
|
||||
import lslfuncs
|
||||
import math
|
||||
from lslparse import warning
|
||||
|
@ -930,20 +931,48 @@ class foldconst(object):
|
|||
if child[idx]['nt'] != 'CONST':
|
||||
CONSTargs = False
|
||||
|
||||
OptimizeParams(node, self.symtab[0][node['name']])
|
||||
if 'Fn' in self.symtab[0][node['name']]:
|
||||
sym = self.symtab[0][node['name']]
|
||||
OptimizeParams(node, sym)
|
||||
if 'Fn' in sym:
|
||||
# Guaranteed to be side-effect free if the children are.
|
||||
if SEFargs:
|
||||
node['SEF'] = True
|
||||
if CONSTargs:
|
||||
# Call it
|
||||
fn = self.symtab[0][node['name']]['Fn']
|
||||
fn = sym['Fn']
|
||||
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':
|
||||
value = fn(*tuple(arg['value'] for arg in child),
|
||||
event=self.CurEvent)
|
||||
value = fn(*args, event=self.CurEvent)
|
||||
else:
|
||||
value = fn(*tuple(arg['value'] for arg in child))
|
||||
value = fn(*args)
|
||||
del args
|
||||
if not self.foldtabs:
|
||||
generatesTabs = (
|
||||
isinstance(value, unicode) and '\t' in value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue