From: Russell M. <rus...@ya...> - 2009-04-22 13:47:52
|
Erik Huelsmann <eh...@gm...> writes: > Now, there are supposedly 2 ways of resolving this issue: > 1) Make the context available to processArgs() by creating a lexical > environment at run time when needed > 2) Compile the parsing of arguments into each function which needs > that, using the lexical environment as established by the compiler > > Last October, I was working on (1), but I estimate runtime cost: > environment records need to be created for every call to a function > with non-constant init forms. Now, I'm thinking (2) may be favorable, > but will cost a lot more storage space: nearly the same code will be > repeated in lots of places, depending on whether we *always* compile > argument parsing or that we do it only for non-constant cases. > > So, I'm basically posting this because of 2 reasons: first of all, I'd > like your opinions, but second of all, I'm hoping some of you may know > how other implementations handle this issue. I think it makes perfect sense to effectively have the compiler inline arg parsing code into the body of the defun being compiled. It will increase the size of the generated bytecode a little, but it's conceptually simple, and should be fast. I'm pretty sure that sbcl takes a similar approach. The body of a compiled function has an arg-parsing prelude, and then a label later in the body where the real processing starts assuming that the args are all computed and in the right place. If a direct call is made to a function with keyword args (i.e. not #'apply or #'funcall) then at the call site this can be compiled into a call that skips the arg parsing prelude. -russ |