Changeset 859


Ignore:
Timestamp:
Aug 10, 2004, 5:54:24 PM (20 years ago)
Author:
Gary Byers
Message:

Check for local macro functions (and complain if FUNCTION references them)
in cheap evaluator.

Pass a function and other information to *MACROEXPAND-HOOK* when expanding
symbol-macros.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-readloop.lisp

    r687 r859  
    212212
    213213(defun %symbol-macroexpand-1 (sym env)
    214   (if (and env (not (istruct-typep env 'lexical-environment)))
     214  (flet ((expand-it (expansion)
     215           (funcall *macroexpand-hook*
     216                    (constantly expansion)
     217                    sym
     218                    env)))
     219    (if (and env (not (istruct-typep env 'lexical-environment)))
    215220      (report-bad-arg env 'lexical-environment))
    216   (do* ((env env (lexenv.parent-env env)))
    217        ((null env))
    218     (if (eq (%svref env 0) 'definition-environment)
     221    (do* ((env env (lexenv.parent-env env)))
     222         ((null env))
     223      (if (eq (%svref env 0) 'definition-environment)
    219224        (let* ((info (assq sym (defenv.symbol-macros env))))
    220225          (if info
    221             (return-from %symbol-macroexpand-1 (values (cdr info) t))
     226            (return-from %symbol-macroexpand-1 (values (expand-it (cdr info)) t))
    222227            (return)))
    223228        (let* ((vars (lexenv.variables env)))
     
    225230            (let* ((info (dolist (var vars)
    226231                           (if (eq (var-name var) sym)
    227                                (return var)))))           
     232                             (return var)))))           
    228233              (when info
    229234                (if (and (consp (setq info (var-expansion info)))
    230235                         (eq (%car info) :symbol-macro))
    231                     (return-from %symbol-macroexpand-1 (values (%cdr info) t))
    232                     (return-from %symbol-macroexpand-1 (values sym nil)))))))))
    233   ;; Look it up globally.
    234   (multiple-value-bind (expansion win) (gethash sym *symbol-macros*)
    235     (if win (values expansion t) (values sym nil))))
     236                  (return-from %symbol-macroexpand-1 (values (expand-it (%cdr info)) t))
     237                  (return-from %symbol-macroexpand-1 (values sym nil)))))))))
     238    ;; Look it up globally.
     239    (multiple-value-bind (expansion win) (gethash sym *symbol-macros*)
     240      (if win (values (expand-it expansion) t) (values sym nil)))))
    236241
    237242(defun macroexpand-1 (form &optional env &aux fn)
     
    357362             (verify-arg-count form 1 1)
    358363             (cond ((symbolp (setq sym (%cadr form)))
     364                    (multiple-value-bind (kind local-p)
     365                        (function-information sym env)
     366                      (if (and local-p (eq kind :macro))
     367                        (error "~s can't be used to reference lexically defined macro ~S" 'function sym)))
    359368                    (%function sym))
    360369                   ((and (consp sym) (eq (%car sym) 'setf) (consp (%cdr sym)) (null (%cddr sym)))
     370                    (multiple-value-bind (kind local-p)
     371                        (function-information sym env)
     372                      (if (and local-p (eq kind :macro))
     373                        (error "~s can't be used to reference lexically defined macro ~S" 'function sym)))
    361374                    (%function (setf-function-name (%cadr sym))))
    362375                   (t (%make-function nil sym env))))
Note: See TracChangeset for help on using the changeset viewer.