mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 20:00:19 +02:00
lexical binding macros
* module/language/elisp/boot.el (lexical-let, lexical-let*): New macros. * module/language/elisp/compile-tree-il.scm (bind-lexically?): Remove the check for a `lexical' flag, since `lexical-let' and `lexical-let*' are no longer special operators. (compile-lexical-let, compile-lexical-let*): Remove. * module/language/elisp/runtime/function-slot.scm: Update module definition.
This commit is contained in:
parent
13f022c9f7
commit
9083c48d37
3 changed files with 25 additions and 28 deletions
|
@ -93,6 +93,30 @@
|
||||||
,temp
|
,temp
|
||||||
(or ,@(cdr conditions))))))))
|
(or ,@(cdr conditions))))))))
|
||||||
|
|
||||||
|
(defmacro lexical-let (bindings &rest body)
|
||||||
|
(labels ((loop (list vars)
|
||||||
|
(if (null list)
|
||||||
|
`(let ,bindings
|
||||||
|
(declare (lexical ,@vars))
|
||||||
|
,@body)
|
||||||
|
(loop (cdr list)
|
||||||
|
(if (consp (car list))
|
||||||
|
`(,(car (car list)) ,@vars)
|
||||||
|
`(,(car list) ,@vars))))))
|
||||||
|
(loop bindings '())))
|
||||||
|
|
||||||
|
(defmacro lexical-let* (bindings &rest body)
|
||||||
|
(labels ((loop (list vars)
|
||||||
|
(if (null list)
|
||||||
|
`(let* ,bindings
|
||||||
|
(declare (lexical ,@vars))
|
||||||
|
,@body)
|
||||||
|
(loop (cdr list)
|
||||||
|
(if (consp (car list))
|
||||||
|
(cons (car (car list)) vars)
|
||||||
|
(cons (car list) vars))))))
|
||||||
|
(loop bindings '())))
|
||||||
|
|
||||||
(defmacro while (test &rest body)
|
(defmacro while (test &rest body)
|
||||||
(let ((loop (make-symbol "loop")))
|
(let ((loop (make-symbol "loop")))
|
||||||
`(labels ((,loop ()
|
`(labels ((,loop ()
|
||||||
|
|
|
@ -37,11 +37,9 @@
|
||||||
compile-defvar
|
compile-defvar
|
||||||
compile-setq
|
compile-setq
|
||||||
compile-let
|
compile-let
|
||||||
compile-lexical-let
|
|
||||||
compile-flet
|
compile-flet
|
||||||
compile-labels
|
compile-labels
|
||||||
compile-let*
|
compile-let*
|
||||||
compile-lexical-let*
|
|
||||||
compile-guile-ref
|
compile-guile-ref
|
||||||
compile-guile-primitive
|
compile-guile-primitive
|
||||||
compile-function
|
compile-function
|
||||||
|
@ -205,8 +203,7 @@
|
||||||
value))))
|
value))))
|
||||||
|
|
||||||
(define (bind-lexically? sym module decls)
|
(define (bind-lexically? sym module decls)
|
||||||
(or (eq? module 'lexical)
|
(or (eq? module function-slot)
|
||||||
(eq? module function-slot)
|
|
||||||
(let ((decl (assq-ref decls sym)))
|
(let ((decl (assq-ref decls sym)))
|
||||||
(and (equal? module value-slot)
|
(and (equal? module value-slot)
|
||||||
(or
|
(or
|
||||||
|
@ -273,10 +270,6 @@
|
||||||
|
|
||||||
;;; Compile let and let* expressions. The code here is used both for
|
;;; Compile let and let* expressions. The code here is used both for
|
||||||
;;; let/let* and flet, just with a different bindings module.
|
;;; let/let* and flet, just with a different bindings module.
|
||||||
;;;
|
|
||||||
;;; A special module value 'lexical means that we're doing a lexical-let
|
|
||||||
;;; instead and the bindings should not be saved to globals at all but
|
|
||||||
;;; be done with the lexical framework instead.
|
|
||||||
|
|
||||||
;;; Let is done with a single call to let-dynamic binding them locally
|
;;; Let is done with a single call to let-dynamic binding them locally
|
||||||
;;; to new values all "at once". If there is at least one variable to
|
;;; to new values all "at once". If there is at least one variable to
|
||||||
|
@ -621,14 +614,6 @@
|
||||||
(map (cut parse-let-binding loc <>) bindings)
|
(map (cut parse-let-binding loc <>) bindings)
|
||||||
body))))
|
body))))
|
||||||
|
|
||||||
(defspecial lexical-let (loc args)
|
|
||||||
(pmatch args
|
|
||||||
((,bindings . ,body)
|
|
||||||
(generate-let loc
|
|
||||||
'lexical
|
|
||||||
(map (cut parse-let-binding loc <>) bindings)
|
|
||||||
body))))
|
|
||||||
|
|
||||||
(defspecial flet (loc args)
|
(defspecial flet (loc args)
|
||||||
(pmatch args
|
(pmatch args
|
||||||
((,bindings . ,body)
|
((,bindings . ,body)
|
||||||
|
@ -665,14 +650,6 @@
|
||||||
(map (cut parse-let-binding loc <>) bindings)
|
(map (cut parse-let-binding loc <>) bindings)
|
||||||
body))))
|
body))))
|
||||||
|
|
||||||
(defspecial lexical-let* (loc args)
|
|
||||||
(pmatch args
|
|
||||||
((,bindings . ,body)
|
|
||||||
(generate-let* loc
|
|
||||||
'lexical
|
|
||||||
(map (cut parse-let-binding loc <>) bindings)
|
|
||||||
body))))
|
|
||||||
|
|
||||||
;;; guile-ref allows building TreeIL's module references from within
|
;;; guile-ref allows building TreeIL's module references from within
|
||||||
;;; elisp as a way to access data within the Guile universe. The module
|
;;; elisp as a way to access data within the Guile universe. The module
|
||||||
;;; and symbol referenced are static values, just like (@ module symbol)
|
;;; and symbol referenced are static values, just like (@ module symbol)
|
||||||
|
|
|
@ -26,11 +26,9 @@
|
||||||
(compile-defvar . defvar)
|
(compile-defvar . defvar)
|
||||||
(compile-setq . setq)
|
(compile-setq . setq)
|
||||||
(compile-let . let)
|
(compile-let . let)
|
||||||
(compile-lexical-let . lexical-let)
|
|
||||||
(compile-flet . flet)
|
(compile-flet . flet)
|
||||||
(compile-labels . labels)
|
(compile-labels . labels)
|
||||||
(compile-let* . let*)
|
(compile-let* . let*)
|
||||||
(compile-lexical-let* . lexical-let*)
|
|
||||||
(compile-guile-ref . guile-ref)
|
(compile-guile-ref . guile-ref)
|
||||||
(compile-guile-primitive . guile-primitive)
|
(compile-guile-primitive . guile-primitive)
|
||||||
(compile-function . function)
|
(compile-function . function)
|
||||||
|
@ -50,11 +48,9 @@
|
||||||
defvar
|
defvar
|
||||||
setq
|
setq
|
||||||
let
|
let
|
||||||
lexical-let
|
|
||||||
flet
|
flet
|
||||||
labels
|
labels
|
||||||
let*
|
let*
|
||||||
lexical-let*
|
|
||||||
guile-ref
|
guile-ref
|
||||||
guile-primitive
|
guile-primitive
|
||||||
function
|
function
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue