RapydScript
RapydScript copied to clipboard
separate out optimization tricks into a separate parser
There are some compile-time optimizations RS already does, here are some examples:
for i in range(n):
...
for i in range(n, -1, -1):
...
for i in dir(obj):
...
Which compile into i++, i--, and for ... in loops respectively. These are scattered and hard to follow in the code. Also, due to them occurring at the time of output, the compiler doesn't have the ability to retroactively modify code that has already been output (i.e. removing the range implementation since the only call to it got optimized out). Moving the optimizer out into its own module would allow it to be more durable, consistent and aggressive.
For example, in addition to optimizing [1 to 5] to range(1, 5), we could also optimize it to [1,2,3,4,5] because both start and end are constants.