Page 2 of 2

Re: define-compiler-macro

Posted: Fri Aug 01, 2008 4:59 am
by nikodemus
makia wrote:yes, i know that ... but then there is no huge impact in real programs if you can only optimize literal arguments ?
Nope. For example, SBCL uses a compiler-macro to optimize MAKE-INSTANCE when the class argument and all the keywords (not keyword argument values) are constant. There are many, many kinds of functions that can be optimized if one or two of the arguments are constants. FORMAT is another good example.

Cheers,

-- Nikodemus

Re: define-compiler-macro

Posted: Sun Aug 03, 2008 5:56 am
by Geoff Wozniak
makia wrote:yes, i know that ... but then there is no huge impact in real programs if you can only optimize literal arguments ?
As nikodemus pointed out, there are certainly ways to use them in "real programs", but they can also be used in other interesting ways.

In my research, I used compiler macros to specialize forms after profiling the code. I would collect data on the use of various types and upon the next compilation of the code, compiler macros would access the profiling database and optimize the code. A simple example would be realizing that an array representation for something was best and change an accessor to a direct access instead of a function call.

Compiler macros aren't just useful for real programs, they're good for research too! ;)