Module optparser

This module does parser-based optimizations.

Notes:

  • The processing load is quite significant, but since this is an off-line text processor, I believe we can wait a few seconds.
  • TODO: Might process "local a,a,a" wrongly... need tests!
  • TODO: Remove position handling if overlapped locals (rem < 0) needs more study, to check behaviour.
  • TODO: There are probably better ways to do allocation, e.g. by choosing better methods to sort and pick locals...
  • TODO: We don't need 53*63 two-letter identifiers; we can make do with significantly less depending on how many that are really needed and improve entropy; e.g. 13 needed -> choose 4*4 instead.

Functions

optimize (option, _toklist, _seminfolist, xinfo) The main entry point.

Local Functions

preprocess (infotable) Preprocesses information table to get lists of unique names.
recalc_for_entropy (option) Calculates actual symbol frequencies, in order to reduce entropy.
new_var_name () Returns a string containing a new local variable name to use, and a flag indicating whether it collides with a global variable.
stats_summary (globaluniq, localuniq, afteruniq, option) Calculates and prints some statistics.
optimize_func1 () Does experimental optimization for f("string") statements.
optimize_locals (option) Does local variable optimization.


Functions

optimize (option, _toklist, _seminfolist, xinfo)
The main entry point.

Parameters:

Local Functions

preprocess (infotable)
Preprocesses information table to get lists of unique names.

Parameters:

Returns:

    table
recalc_for_entropy (option)

Calculates actual symbol frequencies, in order to reduce entropy.

  • This may help further reduce the size of compressed sources.
  • Note that since parsing optimizations is put before lexing optimizations, the frequency table is not exact!
  • Yes, this will miss --keep block comments too...

Parameters:

new_var_name ()
Returns a string containing a new local variable name to use, and a flag indicating whether it collides with a global variable.

Trapping keywords and other names like 'self' is done elsewhere.

Returns:

  1. string A new local variable name.
  2. bool Whether the name collides with a global variable.
stats_summary (globaluniq, localuniq, afteruniq, option)
Calculates and prints some statistics.

Note: probably better in main source, put here for now.

Parameters:

optimize_func1 ()
Does experimental optimization for f("string") statements.

It's safe to delete parentheses without adding whitespace, as both kinds of strings can abut with anything else.

optimize_locals (option)
Does local variable optimization.

Parameters:

generated by LDoc 1.4.6