mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-02 08:08:20 +00:00
Add copyright notices to all files, to prepare the program for release.
This commit is contained in:
parent
d164b0fa44
commit
c68a1f4ad6
15 changed files with 977 additions and 11 deletions
|
@ -1,10 +1,37 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# This module is used by the optimizer for resolving constant values.
|
||||
|
||||
# The functions it implements are all functions that always return the same result when given the same input, and that have no side effects.
|
||||
|
||||
# For example, llAbs() is here, but llFrand() is not, because it doesn't always return the same result.
|
||||
|
||||
# This implies that functions present in this module can be precomputed if their arguments are constants.
|
||||
#
|
||||
# The functions it implements are all functions that always return the same
|
||||
# result when given the same input, and that have no side effects.
|
||||
#
|
||||
# For example, llAbs() is here, but llFrand() is not, because it doesn't always
|
||||
# return the same result.
|
||||
#
|
||||
# This implies that functions present in this module can be precomputed if
|
||||
# their arguments are constants.
|
||||
#
|
||||
# In some instances, the result can't be computed; in these cases the function
|
||||
# raises a LSLCantCompute exception that is caught by the optimizer to leave
|
||||
# the expression unchanged. For example, llBase64ToInteger("AA") returns
|
||||
# unpredictable garbage in the low bytes in LSL, so it is left unchanged.
|
||||
#
|
||||
# The JSON functions have been separated to their own module.
|
||||
|
||||
import re
|
||||
from lslcommon import *
|
||||
|
@ -102,10 +129,16 @@ def F32(f, f32=True):
|
|||
#from array import array
|
||||
#return array('f',(f,))[0]
|
||||
|
||||
# Using struct:
|
||||
#from struct import pack, unpack
|
||||
#return unpack('f', pack('f', f))[0]
|
||||
|
||||
# Using ctypes:
|
||||
#from ctypes import c_float
|
||||
return c_float(f).value
|
||||
|
||||
# These are other approaches that are not fully debugged:
|
||||
|
||||
# # Another alternative. frexp and ldexp solve a lot (but are still troublesome):
|
||||
# m, x = math.frexp(abs(f))
|
||||
# if x > 128:
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# These types just wrap the Python types to make type() work on them.
|
||||
# There are no ops defined on them or anything.
|
||||
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Dead Code Removal optimization
|
||||
|
||||
import lslfuncs
|
||||
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Extra functions that have predictable return values for certain arguments.
|
||||
|
||||
from lslcommon import *
|
||||
from lslbasefuncs import ELSLCantCompute, isinteger, iskey, islist, \
|
||||
isvector, NULL_KEY, ZERO_VECTOR, ZERO_ROTATION
|
||||
|
@ -182,3 +201,4 @@ def llGetDisplayName(id):
|
|||
return u''
|
||||
raise ELSLCantCompute
|
||||
|
||||
# TODO: Add more predictable functions.
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Constant folding and simplification of expressions and statements.
|
||||
|
||||
import lslfuncs
|
||||
from lslparse import warning
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Put all LSL functions together in one single module
|
||||
|
||||
from lslbasefuncs import *
|
||||
from lsljson import *
|
||||
from lslextrafuncs import *
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# JSON functions
|
||||
|
||||
import re
|
||||
import math
|
||||
from lslcommon import *
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Optimizer class that wraps and calls the other parts.
|
||||
|
||||
import lslfuncs
|
||||
from lslfuncs import Key, Vector, Quaternion
|
||||
|
@ -27,8 +45,9 @@ class optimizer(foldconst, renamer, deadcode):
|
|||
Quaternion: 'rotation', list: 'list'}
|
||||
|
||||
def Cast(self, value, newtype):
|
||||
# Return a CAST node if the types are not equal, otherwise the
|
||||
# value unchanged
|
||||
"""Return a CAST node if the types are not equal, otherwise the
|
||||
value unchanged.
|
||||
"""
|
||||
if value['t'] == newtype:
|
||||
return value
|
||||
ret = {'nt':'CAST', 't':newtype, 'ch':[value]}
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
# Convert a symbol table (with parse tree) back to a script.
|
||||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Convert an abstract syntax tree + symbol table back to a script as text.
|
||||
|
||||
import lslfuncs
|
||||
from lslcommon import Key, Vector, Quaternion
|
||||
from lslparse import warning
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Parser module. Converts the source into an abstract syntax tree,
|
||||
# generating also the symbol table.
|
||||
|
||||
# TODO: Add info to be able to propagate error position to the source.
|
||||
|
||||
from lslcommon import Key, Vector, Quaternion
|
||||
|
|
|
@ -1,3 +1,30 @@
|
|||
# (C) Copyright 2015 Sei Lisa. All rights reserved.
|
||||
#
|
||||
# This file is part of LSL PyOptimizer.
|
||||
#
|
||||
# LSL PyOptimizer is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# This module renames all kinds of variables. Globals and function/event
|
||||
# parameters take memory space, so shrinking the identifiers as much as
|
||||
# possible ensures their memory usage will be minimized. It also reuses some
|
||||
# preexisting names when possible. Locals are renamed also so that they don't
|
||||
# stand in the way of globals.
|
||||
#
|
||||
# A side effect of this change is that the script becomes unreadable gibberish.
|
||||
|
||||
# TODO: Rename locals to loc_<identifier> rather than random names.
|
||||
|
||||
import random
|
||||
from base64 import b64encode
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue