lexical binding macros
authorBT Templeton <bpt@hcoop.net>
Tue, 9 Aug 2011 00:20:16 +0000 (20:20 -0400)
committerBT Templeton <bpt@hcoop.net>
Fri, 3 Feb 2012 23:53:50 +0000 (18:53 -0500)
* 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.

module/language/elisp/boot.el
module/language/elisp/compile-tree-il.scm
module/language/elisp/runtime/function-slot.scm

index bfaba4d..f14ab46 100644 (file)
                     ,temp
                   (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)
   (let ((loop (make-symbol "loop")))
     `(labels ((,loop ()
index fb8189b..ae950bf 100644 (file)
             compile-defvar
             compile-setq
             compile-let
-            compile-lexical-let
             compile-flet
             compile-labels
             compile-let*
-            compile-lexical-let*
             compile-guile-ref
             compile-guile-primitive
             compile-function
                      value))))
 
 (define (bind-lexically? sym module decls)
-  (or (eq? module 'lexical)
-      (eq? module function-slot)
+  (or (eq? module function-slot)
       (let ((decl (assq-ref decls sym)))
         (and (equal? module value-slot)
              (or
 
 ;;; Compile let and let* expressions.  The code here is used both for
 ;;; 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
 ;;; to new values all "at once".  If there is at least one variable to
                    (map (cut parse-let-binding loc <>) bindings)
                    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)
   (pmatch args
     ((,bindings . ,body)
                     (map (cut parse-let-binding loc <>) bindings)
                     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
 ;;; elisp as a way to access data within the Guile universe.  The module
 ;;; and symbol referenced are static values, just like (@ module symbol)
index 03fd454..3b10205 100644 (file)
                  (compile-defvar . defvar)
                  (compile-setq . setq)
                  (compile-let . let)
-                 (compile-lexical-let . lexical-let)
                  (compile-flet . flet)
                  (compile-labels . labels)
                  (compile-let* . let*)
-                 (compile-lexical-let* . lexical-let*)
                  (compile-guile-ref . guile-ref)
                  (compile-guile-primitive . guile-primitive)
                  (compile-function . function)
                defvar
                setq
                let
-               lexical-let
                flet
                labels
                let*
-               lexical-let*
                guile-ref
                guile-primitive
                function