mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
When optimizing nonconst * const, cast the result to the type of the operator.
Per bug report by @Welcius. Fixes #8.
This commit is contained in:
parent
750465f17b
commit
1bdaff32ab
5 changed files with 46 additions and 5 deletions
|
@ -1204,24 +1204,29 @@ class foldconst(object):
|
||||||
and b == 1 and val in (-1, 1)
|
and b == 1 and val in (-1, 1)
|
||||||
):
|
):
|
||||||
if val == 1:
|
if val == 1:
|
||||||
parent[index] = child[a]
|
parent[index] = self.Cast(child[a], optype)
|
||||||
|
self.FoldTree(parent, index)
|
||||||
return
|
return
|
||||||
if val == 0:
|
if val == 0:
|
||||||
if child[a].SEF:
|
if child[a].SEF:
|
||||||
parent[index] = child[b]
|
parent[index] = self.Cast(child[b], optype)
|
||||||
|
self.FoldTree(parent, index)
|
||||||
return
|
return
|
||||||
if val == -1:
|
if val == -1:
|
||||||
# Note 0.0*-1 equals -0.0 in LSL, so this is safe
|
# Note 0.0*-1 equals -0.0 in LSL, so this is safe
|
||||||
node = parent[index] = nr(nt='NEG', t=node.t,
|
node = parent[index] = nr(nt='NEG', t=node.t,
|
||||||
ch=[child[a]], SEF=child[a].SEF)
|
ch=[self.Cast(child[a], optype)],
|
||||||
|
SEF=child[a].SEF)
|
||||||
|
self.FoldTree(parent, index)
|
||||||
return
|
return
|
||||||
# only -2, 2 remain
|
# only -2, 2 remain
|
||||||
if child[a].nt == 'IDENT' and self.isLocalVar(child[a]):
|
if child[a].nt == 'IDENT' and self.isLocalVar(child[a]):
|
||||||
child[b] = child[a].copy()
|
child[b] = self.Cast(child[a].copy(), optype)
|
||||||
node.nt = '+'
|
node.nt = '+'
|
||||||
if val == -2:
|
if val == -2:
|
||||||
parent[index] = nr(nt='NEG', t=node.t,
|
parent[index] = nr(nt='NEG', t=optype,
|
||||||
ch=[node], SEF=node.SEF)
|
ch=[node], SEF=node.SEF)
|
||||||
|
self.FoldTree(parent, index)
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -132,4 +132,7 @@
|
||||||
, llSin(-2147483648)
|
, llSin(-2147483648)
|
||||||
, llSin(2147483647)
|
, llSin(2147483647)
|
||||||
, llSin(2147483647.0)
|
, llSin(2147483647.0)
|
||||||
|
, 2147483647 * 1.0 * 2
|
||||||
|
, 3 * 1.0 / 2
|
||||||
|
, 3 / 2
|
||||||
]
|
]
|
||||||
|
|
|
@ -128,4 +128,7 @@
|
||||||
, 0.9713102
|
, 0.9713102
|
||||||
, -0.9713102
|
, -0.9713102
|
||||||
, -0.9713102
|
, -0.9713102
|
||||||
|
, 4294967296.
|
||||||
|
, 1.5
|
||||||
|
, 1
|
||||||
]
|
]
|
14
unit_tests/regression.suite/issue-8.lsl
Normal file
14
unit_tests/regression.suite/issue-8.lsl
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
default{timer(){
|
||||||
|
|
||||||
|
integer x = llGetNumberOfPrims();
|
||||||
|
integer y = llGetUnixTime();
|
||||||
|
llOwnerSay((string)(x * 1.0 / y));
|
||||||
|
llOwnerSay((string)(x / 1.0 / y));
|
||||||
|
llOwnerSay((string)(x / (-1.0) / y));
|
||||||
|
llOwnerSay((string)(x * 1.0 / y));
|
||||||
|
llOwnerSay((string)(x * (-1.0) / y));
|
||||||
|
llOwnerSay((string)(x * -2.0));
|
||||||
|
llOwnerSay((string)(x * 0.0 + y));
|
||||||
|
llOwnerSay((string)(x + 0.0 + y));
|
||||||
|
|
||||||
|
}}
|
16
unit_tests/regression.suite/issue-8.out
Normal file
16
unit_tests/regression.suite/issue-8.out
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
default
|
||||||
|
{
|
||||||
|
timer()
|
||||||
|
{
|
||||||
|
integer x = llGetNumberOfPrims();
|
||||||
|
integer y = llGetUnixTime();
|
||||||
|
llOwnerSay((string)((float)x / y));
|
||||||
|
llOwnerSay((string)((float)x / y));
|
||||||
|
llOwnerSay((string)(-(float)x / y));
|
||||||
|
llOwnerSay((string)((float)x / y));
|
||||||
|
llOwnerSay((string)(-(float)x / y));
|
||||||
|
llOwnerSay((string)(-(x + (float)x)));
|
||||||
|
llOwnerSay((string)((float)y));
|
||||||
|
llOwnerSay((string)((float)x + y));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue