lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Nov 09, 2004 at 11:18:38AM -0800, Nick Trout wrote:
 
> colours = [enum] {		-- note the hint
> ...
> #pragma fn_static
> 		foo(1, 2, "buckle", my, shoe)

Hints and pragmas can both be considered annotations to the program
graph, and could even be implemented as data in an attribute space,
available for processing by in-language code or by the compiler alike.

Unfortunately, without an official program graph, any such extensions
would live in a very unsatisfactory twilight limbo.

> -- in user script
> #macro_define \
> 	squares (x)	\
> 		local t = "{"
> 		for i = 1,x do t=t.."{"..i..","..i*i.."}," end \
> 		return t.."}" \
> 	end

Eeek. :-(  Crafting the textual representation lies somewhere between
hair-raising and appallingly dreadful. :-)  More importantly though,
it's not very powerful in an engineering sense, because the parts being
manipulated are dead text instead of active objects with introspection.

Before even considering that approach, I'd think seriously about defining
an unofficial syntax tree and creating a front-end to the current parser
to accept the tree form as input.  Then macro processing becomes a very
clear 2nd stage in a 3-stage but still single-pass process of parsing Lua
text into a tree, applying macros, and finally compiling the output tree.

Rich Artym.
-- 
Existing media are so disconnected from reality that our policy debates
spin around a fantasy world in which the future looks far too much like
the past.   http://www.zyvex.com/nanotech/MITtecRvwSmlWrld/article.html