Check min and max to determine truth value of condition

Also added some min/max values for a few functions.

This allows optimizing things like:

  ! llGetNumberOfPrims()  ->  0
This commit is contained in:
Sei Lisa 2019-01-06 23:49:33 +01:00
parent 5bfb218505
commit 1b3c8a4d89
4 changed files with 42 additions and 6 deletions

View file

@ -578,6 +578,7 @@ string llGetLinkName(integer linknumber)
integer llGetLinkNumber() integer llGetLinkNumber()
- SEF - SEF
- min 0
integer llGetLinkNumberOfSides(integer link) integer llGetLinkNumberOfSides(integer link)
- SEF - SEF
@ -637,9 +638,12 @@ key llGetNumberOfNotecardLines(string name)
integer llGetNumberOfPrims() integer llGetNumberOfPrims()
- SEF - SEF
- min 1
integer llGetNumberOfSides() integer llGetNumberOfSides()
- SEF - SEF
- min 1
- max 9
list llGetObjectAnimationNames() list llGetObjectAnimationNames()
- SEF - SEF
@ -663,6 +667,9 @@ integer llGetObjectPermMask(integer mask)
integer llGetObjectPrimCount(key object_id) integer llGetObjectPrimCount(key object_id)
- SEF - SEF
- min 0
- max 256
- return 0 if nulluuid(object_id)
vector llGetOmega() vector llGetOmega()
# physics caveat # physics caveat
@ -684,12 +691,14 @@ integer llGetParcelFlags(vector pos)
integer llGetParcelMaxPrims(vector pos, integer sim_wide) integer llGetParcelMaxPrims(vector pos, integer sim_wide)
- SEF - SEF
- min 0
string llGetParcelMusicURL() string llGetParcelMusicURL()
- SEF - SEF
integer llGetParcelPrimCount(vector pos, integer category, integer sim_wide) integer llGetParcelPrimCount(vector pos, integer category, integer sim_wide)
- SEF - SEF
- min 0
list llGetParcelPrimOwners(vector pos) list llGetParcelPrimOwners(vector pos)
- delay 2.0 - delay 2.0

View file

@ -260,6 +260,27 @@ class foldconst(object):
return (node.nt == 'NEG' and self.IsBool(node.ch[0]) return (node.nt == 'NEG' and self.IsBool(node.ch[0])
or self.IsBool(node)) or self.IsBool(node))
def GetTruth(self, node):
"""Decode truth value of node when possible.
Returns True if it's always true, False if it's always false, and None
if it can't be determined.
"""
if node.nt == 'CONST':
return lslfuncs.cond(node.value)
min = getattr(node, 'min', None)
max = getattr(node, 'max', None)
if min is None or max is None:
if node.nt == 'FNCALL':
min = self.symtab[0][node.name].get('min', min)
max = self.symtab[0][node.name].get('max', max)
if min is not None and min > 0:
return True
if max is not None and max < 0:
return True
if min == max == 0:
return False
return None
def FoldCond(self, parent, index, ParentIsNegation = False): def FoldCond(self, parent, index, ParentIsNegation = False):
"""When we know that the parent is interested only in the truth value """When we know that the parent is interested only in the truth value
of the node, we can perform further optimizations. This function deals of the node, we can perform further optimizations. This function deals
@ -267,10 +288,12 @@ class foldconst(object):
""" """
node = parent[index] node = parent[index]
nt = node.nt nt = node.nt
if nt in ('CONST', 'IDENT', 'FLD'): truth = self.GetTruth(node)
if node.nt == 'CONST': if truth is not None and node.SEF:
node.t = 'integer' parent[index] = nr(nt='CONST',t='integer',value=1 if truth else 0,
node.value = 1 if lslfuncs.cond(node.value) else 0 SEF=True)
return
if nt in ('IDENT', 'FLD'):
return # Nothing to do if it's already simplified. return # Nothing to do if it's already simplified.
child = node.ch child = node.ch

View file

@ -4,7 +4,10 @@ if (llSameGroup(llGetOwner()) && llDetectedGroup(0)) llDie();
// TODO // TODO
// llGetEnergy() has min=0 and max=1, therefore (integer)llGetEnergy() is bool, // llGetEnergy() has min=0 and max=1, therefore (integer)llGetEnergy() is bool,
// however we don't yet handle it. // however we don't handle it yet (needs min and max applied to expressions).
if ((integer)llGetEnergy() && llSameGroup(llGetOwner())) llDie(); if ((integer)llGetEnergy() && llSameGroup(llGetOwner())) llDie();
// Check that min and max work as they should. This is always true.
if (llGetNumberOfPrims()) llDie();
}} }}

View file

@ -6,5 +6,6 @@ default
llDie(); llDie();
if ((integer)llGetEnergy() & -llSameGroup(llGetOwner())) if ((integer)llGetEnergy() & -llSameGroup(llGetOwner()))
llDie(); llDie();
llDie();
} }
} }