lua-users home
lua-l archive

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


That's funny, I don't think I got the message that this is
in reply to...

Nodir Temirhodzhaev wrote:
[http://lua-users.org/lists/lua-l/2001-01/msg00156.html]
http://lua-users.org/lists/lua-l/2000-04/msg00000.html

Note that simple constant substitution in Lua code with
the C preprocessor this only covers the most trivial of
constants -- numbers and strings -- though it covers
them well, and the const-defining 'header' files can be
#included in both your C and your lua (you could #define
them just in your C source and then #include the actual
C source inside a lua block-comment, though lua block-
comments have a big weakness for ]] naturally
occurring in code that's commented out :( ).

Personally I'm more interested in 'constant' functions and
fields in tables (methods!) which the lua code generator could
potentially inline (or not, on a case-by-case basis depending
on speed-vs-space that it estimates).  I can see this being
quite tricky to implement (definitely tricky from preprocessing ;))
for the most interesting cases (ie. methods) without table indices
carrying a const flag with them and some possibly-hairy global
analysis at compile-time to verify that a particular instance of a call
is guaranteed to always end up calling that same constant
(quite hard, unless you design your code to make this more
obvious to the inliner, ie. don't expect consts to be inlinable
across compilation units, accept that they are implicitly 'local',
they can't be overwritten or removed from a table they're
placed or copied into [a vm const flag on values could enforce
this], etc).

Apologies if my mailer has inexplicably decided to turn this
into HTML mail, which I suspect.

--Adam
--
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3
That gum you like is going to come back in style.