diff options
| author | Stefan Monnier | 2022-05-25 17:53:39 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2022-05-26 12:21:32 -0400 |
| commit | 80ba4c170756049a101b4e6692882ac30ba5e1a5 (patch) | |
| tree | 6dd293220256c8ce06e474c9457a4e448f7dd7ee /doc | |
| parent | 77b5840d4ab37c1485745def5ec0c9b9f6cb137f (diff) | |
| download | emacs-scratch/bug-55156.tar.gz emacs-scratch/bug-55156.zip | |
eval.c: New functions `defvar-1` and `defconst-1` (bug#55156)scratch/bug-55156
The bytecode interpreter can't directly call special forms, so
the byte-compiler usually converts special forms into some sequence of
byte codes (basically, providing a duplicate definition of the special
form). There are still two exceptions to this: `defconst` and `defvar`,
where the compiler instead generates a convoluted chunk of code like:
(funcall '(lambda (x) (defvar <sym> x <doc>)) <value>)
where the quote makes sure we keep the function non-compiled, so as
to end up running the special form at run time.
Get rid of this workaround by introducing `defvar-1` and `defconst-1`
which provide a *functional* interface to the functionality of the
corresponding special form.
* src/eval.c (defvar, Fdefvar_1, Fdefconst_1): New functions, extracted from
`Fdefvar` and `Fdefconst`.
(Fdefvar, Fdefconst): Use them.
(syms_of_eval): `defsubr` the new functions.
* lisp/emacs-lisp/bytecomp.el (byte-compile-tmp-var): Delete const.
(byte-compile-defvar): Simplify using the new functions.
* doc/lispref/variables.texi (Defining Variables): Adjust the doc of
`defvar` to reflect the actual semantics implemented.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/variables.texi | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index f0e3f337a69..c29547d00db 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -527,10 +527,11 @@ If @var{symbol} has a buffer-local binding in the current buffer, | |||
| 527 | rather than the buffer-local binding. It sets the default value if | 527 | rather than the buffer-local binding. It sets the default value if |
| 528 | the default value is void. @xref{Buffer-Local Variables}. | 528 | the default value is void. @xref{Buffer-Local Variables}. |
| 529 | 529 | ||
| 530 | If @var{symbol} is already lexically bound (e.g., if the @code{defvar} | 530 | If @var{symbol} is already let bound (e.g., if the @code{defvar} |
| 531 | form occurs in a @code{let} form with lexical binding enabled), then | 531 | form occurs in a @code{let} form), then @code{defvar} sets the toplevel |
| 532 | @code{defvar} sets the dynamic value. The lexical binding remains in | 532 | default value, like @code{set-default-toplevel-value}. |
| 533 | effect until its binding construct exits. @xref{Variable Scoping}. | 533 | The let binding remains in effect until its binding construct exits. |
| 534 | @xref{Variable Scoping}. | ||
| 534 | 535 | ||
| 535 | @cindex @code{eval-defun}, and @code{defvar} forms | 536 | @cindex @code{eval-defun}, and @code{defvar} forms |
| 536 | @cindex @code{eval-last-sexp}, and @code{defvar} forms | 537 | @cindex @code{eval-last-sexp}, and @code{defvar} forms |