[SPL] Static Subexpression Elimination
Clifford Wolf
clifford at clifford.at
Fri Oct 7 18:50:54 CEST 2005
Hi,
the optimizer in the SPL compiler can do static subexpression elimination
now (subversion rev. 615, it is not part of todays snapshot). E.g.:
debug "This is a ${ "lit"~"tle" } test: ${ (3+4+5)*4 - 6 }";
This script is compiled to the following SPL assembler code if the
optimizer is used:
$ ./splrun -AN demo.spl
# SPL Assembler Dump
:16 PUSHC "This is a little test: 42" # (1 byte arg) 0
:18 DEBUG
:19 HALT
# Total size: 30 bytes (4 text, 26 data).
The unoptimized assembler code looks like this:
$ ./splrun -oAN demo.spl
# SPL Assembler Dump
:16 PUSHC "This is a " # (4 byte arg) 0
:21 PUSHC "lit" # (4 byte arg) 11
:26 PUSHC "tle" # (4 byte arg) 15
:31 CAT
:32 CAT
:33 PUSHC " test: " # (4 byte arg) 19
:38 CAT
:39 PUSHC "3" # (4 byte arg) 27
:44 PUSHC "4" # (4 byte arg) 29
:49 IADD
:50 PUSHC "5" # (4 byte arg) 31
:55 IADD
:56 PUSHC "4" # (4 byte arg) 29
:61 IMUL
:62 PUSHC "6" # (4 byte arg) 33
:67 ISUB
:68 CAT
:69 PUSHC "" # (4 byte arg) 10
:74 CAT
:75 DEBUG
:76 HALT
# Total size: 96 bytes (61 text, 35 data).
I think more optimization can't be expected from a scripting language
compiler.. ;-)
Please let me know if you encounter any problems or strange behavior with
the optimizer enabled. I have done my best to implement it bugfree and test
it well, but nobody is perfect - especially when writing compilers.
yours,
- clifford
--
SSSS PPPP L The SPL Programming Language
S P P L http://www.clifford.at/spl/
SSSS PPPP L ----------------------------------------------------
S P L An object oriented, stateful, simple, small, c-like,
SSSS P LLLL embeddable, feature rich, dynamic scripting language
More information about the SPL
mailing list