Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Question about ingetc() vs. word-code

On Wed, Jul 5, 2017 at 4:37 AM, Sebastian Gniazdowski
<psprint@xxxxxxxxxxx> wrote:
> Hello,
> I noticed quite large number of ingetc() calls

ingetc() is the central function used for reading any shell input that
has to undergo alias expansion or any other sort of lookahead -- stdio
only provides one byte of input "put-back" [ungetc()], but in order to
properly manage aliases and to differentiate things like "((..." [as
either two subshells or one math expression], the shell lexer may need
to read, put back, and then re-read an arbitrary amount of the input

> Why the compiled, not-eval source still exist in hunks in ingetc() input? Many times. The eval-code also appears, but this is probably expected.

The compiled wordcode includes all the original text of most strings
and identifiers, so that XTRACE and VERBOSE output can be properly
reproduced.  Only shell lexical tokens are turned into numeric codes.
Identifiers that are referenced as well as assigned will appear at
each $NAME expansion or function name call.

A possible optimization for compiling whole digests of related
functions would be to build an identifier dictionary and refer to the
identifiers by a wordcode value followed by an offset into the
dictionary, but this would be wasteful for most small/single-function
compilations and would complicate the XTRACE playback.

Messages sorted by: Reverse Date, Date, Thread, Author