mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-14 15:40:19 +02:00
emacs-compatible lexical binding
* module/language/elisp/bindings.scm (global?): New function. * module/language/elisp/compile-tree-il.scm (lexical-binding): New variable. (bind-lexically?): If lexical binding is enabled, bind lexically unless a special binding exists. (compile-%set-lexical-binding-mode): New function. * module/language/elisp/lexer.scm (lexical-binding-regexp): New variable. (lex): Return a `set-lexical-binding-mode!' token if a comment is found while reading the first line. * module/language/elisp/parser.scm (get-expression): Add support for `set-lexical-binding-mode!' tokens. * module/language/elisp/runtime/function-slot.scm: Import and re-export the `%set-lexical-binding-mode' special form. * test-suite/tests/elisp-compiler.test ("Let and Let*")["lambda args inside lexical-let"]: Update.
This commit is contained in:
parent
d4cb18ad9c
commit
03e00c5c9d
6 changed files with 47 additions and 10 deletions
|
@ -50,7 +50,8 @@
|
|||
compile-defmacro
|
||||
compile-defun
|
||||
#{compile-`}#
|
||||
compile-quote))
|
||||
compile-quote
|
||||
compile-%set-lexical-binding-mode))
|
||||
|
||||
;;; Certain common parameters (like the bindings data structure or
|
||||
;;; compiler options) are not always passed around but accessed using
|
||||
|
@ -66,6 +67,8 @@
|
|||
|
||||
(define always-lexical (make-fluid))
|
||||
|
||||
(define lexical-binding (make-fluid))
|
||||
|
||||
;;; Find the source properties of some parsed expression if there are
|
||||
;;; any associated with it.
|
||||
|
||||
|
@ -245,7 +248,10 @@
|
|||
(let ((always (fluid-ref always-lexical)))
|
||||
(or (eq? always 'all)
|
||||
(memq sym always)
|
||||
(get-lexical-binding (fluid-ref bindings-data) sym))))))
|
||||
(get-lexical-binding (fluid-ref bindings-data) sym)
|
||||
(and
|
||||
(fluid-ref lexical-binding)
|
||||
(not (global? (fluid-ref bindings-data) sym module))))))))
|
||||
|
||||
(define (split-let-bindings bindings module)
|
||||
(let iterate ((tail bindings)
|
||||
|
@ -854,6 +860,12 @@
|
|||
((,val)
|
||||
(make-const loc val))))
|
||||
|
||||
(defspecial %set-lexical-binding-mode (loc args)
|
||||
(pmatch args
|
||||
((,val)
|
||||
(fluid-set! lexical-binding val)
|
||||
(make-void loc))))
|
||||
|
||||
;;; Compile a compound expression to Tree-IL.
|
||||
|
||||
(define (compile-pair loc expr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue