define-compiler-macro

Discussion of Common Lisp

Re: define-compiler-macro

Postby nikodemus » Fri Aug 01, 2008 4:59 am

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
nikodemus
 
Posts: 7
Joined: Fri Jul 04, 2008 8:32 am

Re: define-compiler-macro

Postby Geoff Wozniak » Sun Aug 03, 2008 5:56 am

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! ;)
Geoff Wozniak
 
Posts: 9
Joined: Wed Jul 16, 2008 5:38 pm
Location: Canada

Previous

Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron