mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Hack to make identifiers in globals in non-global-expression mode work.
This commit is contained in:
parent
b441c1774f
commit
56d51b835c
3 changed files with 39 additions and 7 deletions
|
@ -100,6 +100,9 @@ class outscript(object):
|
|||
first = False
|
||||
self.indentlevel -= 1
|
||||
return ret + self.dent() + self.indent + ']'
|
||||
|
||||
if tvalue == tuple and value[0] == 'IDENT': # HACK
|
||||
return value[2]
|
||||
assert False, u'Value of unknown type in Value2LSL: ' + repr(value)
|
||||
|
||||
def dent(self):
|
||||
|
@ -180,7 +183,7 @@ class outscript(object):
|
|||
op = self.OutExpr(expr[2])
|
||||
return op + ' = ' + op + ' ' + node[:-1] + ' (' + self.OutExpr(expr[3]) + ')'
|
||||
|
||||
raise Exception('Internal error: expression type "' + node + '" not handled') # pragma: no cover
|
||||
assert False, 'Internal error: expression type "' + node + '" not handled' # pragma: no cover
|
||||
|
||||
def OutCode(self, code):
|
||||
#return self.dent() + '{\n' + self.dent() + '}\n'
|
||||
|
|
|
@ -1347,22 +1347,38 @@ class parser(object):
|
|||
return (S['IDENT'], S[tmp[1]], tok[1], self.FindScopeIndex(tok[1]))
|
||||
if tok[0] == '<':
|
||||
value = [self.Parse_simple_expr()]
|
||||
self.autocastcheck((0, self.PythonType2LSL[type(value[0])]), 'float')
|
||||
if type(value[0]) == tuple:
|
||||
typnode = value[0]
|
||||
else:
|
||||
typnode = (0, self.PythonType2LSL[type(value[0])])
|
||||
self.autocastcheck(typnode, 'float')
|
||||
self.expect(',')
|
||||
self.NextToken()
|
||||
value.append(self.Parse_simple_expr())
|
||||
self.autocastcheck((0, self.PythonType2LSL[type(value[1])]), 'float')
|
||||
if type(value[1]) == tuple:
|
||||
typnode = value[1]
|
||||
else:
|
||||
typnode = (0, self.PythonType2LSL[type(value[1])])
|
||||
self.autocastcheck(typnode, 'float')
|
||||
self.expect(',')
|
||||
self.NextToken()
|
||||
value.append(self.Parse_simple_expr())
|
||||
self.autocastcheck((0, self.PythonType2LSL[type(value[2])]), 'float')
|
||||
if type(value[2]) == tuple:
|
||||
typnode = value[2]
|
||||
else:
|
||||
typnode = (0, self.PythonType2LSL[type(value[2])])
|
||||
self.autocastcheck(typnode, 'float')
|
||||
if self.tok[0] == '>':
|
||||
self.NextToken()
|
||||
return Vector(value)
|
||||
self.expect(',')
|
||||
self.NextToken()
|
||||
value.append(self.Parse_simple_expr())
|
||||
self.autocastcheck((0, self.PythonType2LSL[type(value[3])]), 'float')
|
||||
if type(value[3]) == tuple:
|
||||
typnode = value[3]
|
||||
else:
|
||||
typnode = (0, self.PythonType2LSL[type(value[3])])
|
||||
self.autocastcheck(typnode, 'float')
|
||||
self.expect('>')
|
||||
self.NextToken()
|
||||
return Quaternion(value)
|
||||
|
|
|
@ -278,6 +278,19 @@ class Test03_Optimizer(UnitTestCase):
|
|||
''', ['extendedassignment'])
|
||||
self.opt.optimize(p, self.parser.functions)
|
||||
self.outscript.output(p)
|
||||
p = self.parser.parse('''
|
||||
key k = "blah";
|
||||
list L = [k, "xxxx", 1.0];
|
||||
float f;
|
||||
vector v = <f, 3, 4>;
|
||||
|
||||
default{timer(){}}
|
||||
''', ['extendedassignment'])
|
||||
self.opt.optimize(p, self.parser.functions)
|
||||
out = self.outscript.output(p)
|
||||
self.assertEqual(out, 'key k = "blah";\nlist L = [k, "xxxx", 1.];\n'
|
||||
'float f;\nvector v = <f, 3, 4>;\ndefault\n{\n timer()\n'
|
||||
' {\n }\n}\n')
|
||||
|
||||
def tearDown(self):
|
||||
del self.parser
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue