New option to optimize float-to-int conversion separately from sign optim.

The option is optfloats. Add support everywhere.
This commit is contained in:
Sei Lisa 2014-07-31 01:37:18 +02:00
parent efc7f4406a
commit 3ac4bc4f0d
2 changed files with 9 additions and 6 deletions

View file

@ -41,7 +41,7 @@ class outscript(object):
return '((integer)' + str(value) + ')'
return str(value)
if tvalue == float:
if self.optsigns and value.is_integer() and -2147483648.0 <= value < 2147483648.0:
if self.optfloats and value.is_integer() and -2147483648.0 <= value < 2147483648.0:
if self.globalmode and not self.listmode:
return str(int(value))
elif not self.globalmode:
@ -295,12 +295,13 @@ class outscript(object):
return self.dent() + self.OutExpr(node) + ';\n'
def output(self, treesymtab, options = ('optsigns',)):
def output(self, treesymtab, options = ('optsigns','optfloats')):
# Build a sorted list of dict entries
self.tree, self.symtab = treesymtab
# Optimize signs
self.optsigns = 'optsigns' in options
self.optfloats = 'optfloats' in options
ret = ''
self.indent = ' '

10
main.py
View file

@ -14,7 +14,7 @@ Usage: %s [-O [+|-]option[,[+|-]option[,...]]] filename
That's an upper case o, not the number zero.
If filename is a dash (-) then standard input is used.
Options (+ means default, - means not default, * means not implemented):
Options (+ means default, * means not implemented):
+extendedglobalexpr Enables arbitrary expressions in globals (as opposed to
dull simple expressions allowed by regular LSL). Needs
the optimizer to run for the result to be compilable.
@ -35,8 +35,9 @@ Options (+ means default, - means not default, * means not implemented):
the output of a preprocessor like cpp, which inserts
directives like: # 123 "filename".
+optimize Runs the optimizer.
+optsigns Optimize signs and float as int.
-foldtabs Tabs can't be copy-pasted, so they aren't optimized by
+optsigns Optimize signs in float and integer constants.
+optfloats Optimize a float when it is an integral value.
foldtabs Tabs can't be copy-pasted, so they aren't optimized by
default. But with support from the viewer, they can be
folded too and make it to the uploaded source. This
option overrides that check, enabling optimization of
@ -55,7 +56,8 @@ means that e.g. a + 3 + 5 is not optimized to a + 8; however a + (3 + 5) is.
return 1
options = set(('extendedglobalexpr','extendedtypecast','extendedassignment',
'allowkeyconcat','allowmultistrings','skippreproc','optimize','optsigns'
'allowkeyconcat','allowmultistrings','skippreproc','optimize',
'optsigns','optfloats'
))
if sys.argv[1] == '-O':