Changeset 11915


Ignore:
Timestamp:
05/21/09 17:14:40 (9 years ago)
Author:
ehuelsmann
Message:

Reuse available infrastructure in Environment,
instead of keeping track of locals (and their
shadowing effect) ourselves.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/precompiler.lisp

    r11913 r11915  
    257257             (symbolp (cadr callee))
    258258             (not (special-operator-p (cadr callee)))
    259              (not (macro-function (cadr callee) sys:*compile-file-environment*))
     259             (not (macro-function (cadr callee) *compile-file-environment*))
    260260             (memq (symbol-package (cadr callee))
    261261                   (list (find-package "CL") (find-package "SYS"))))
     
    356356(defvar *in-jvm-compile* nil)
    357357
    358 (defvar *local-variables* nil
    359   "An alist with all local variables visible in the context
    360 of the form being preprocessed.")
    361 
    362 (declaim (ftype (function (t) t) find-varspec))
    363 (defun find-varspec (sym)
    364   (dolist (varspec *local-variables*)
    365     (when (eq sym (car varspec))
    366       (return varspec))))
    367 
    368358(declaim (ftype (function (t) t) precompile1))
    369359(defun precompile1 (form)
    370360  (cond ((symbolp form)
    371          (let ((varspec (find-varspec form)))
    372            (cond ((and varspec (eq (second varspec) :symbol-macro))
    373                   (precompile1 (copy-tree (third varspec))))
    374                  ((null varspec)
    375                   (let ((expansion (expand-macro form)))
    376                     (if (eq expansion form)
    377                         form
    378                         (precompile1 expansion))))
    379                  (t
    380                   form))))
     361         (multiple-value-bind
     362               (expansion expanded)
     363             (expand-macro form)
     364           (if expanded
     365               (precompile1 expansion)
     366               form)))
    381367        ((atom form)
    382368         form)
     
    518504     (precompile1 (expand-macro form)))
    519505    ((symbolp place)
    520            (let ((varspec (find-varspec place)))
    521              (if (and varspec (eq (second varspec) :symbol-macro))
    522                  (precompile1 (list* 'SETF (copy-tree (third varspec)) (cddr form)))
     506           (multiple-value-bind
     507                 (expansion expanded)
     508               (expand-macro place)
     509             (if expanded
     510                 (precompile1 (list* 'SETF expansion
     511                                     (cddr form)))
    523512                 (precompile1 (expand-macro form)))))
    524513          (t
     
    533522    (if (= len 2)
    534523        (let* ((sym (%car args))
    535                (val (%cadr args))
    536                (varspec (find-varspec sym)))
    537           (if (and varspec (eq (second varspec) :symbol-macro))
    538               (precompile1 (list 'SETF (copy-tree (third varspec)) val))
    539               (list 'SETQ sym (precompile1 val))))
     524               (val (%cadr args)))
     525          (multiple-value-bind
     526                (expansion expanded)
     527              (expand-macro sym)
     528            (if expanded
     529                (precompile1 (list 'SETF expansion val))
     530                (list 'SETQ sym (precompile1 val))
     531                )))
    540532        (let ((result ()))
    541533          (loop
     
    629621
    630622(defun precompile-symbol-macrolet (form)
    631   (let ((*local-variables* *local-variables*)
    632         (*compile-file-environment*
     623  (let ((*compile-file-environment*
    633624         (make-environment *compile-file-environment*))
    634625        (defs (cadr form)))
     
    640631                 :format-control "Attempt to bind the special variable ~S with SYMBOL-MACROLET."
    641632                 :format-arguments (list sym)))
    642         (push (list sym :symbol-macro expansion) *local-variables*)
    643633        (environment-add-symbol-binding *compile-file-environment*
    644634                                        sym
     
    689679                        :format-arguments (list v)))
    690680               (push (list v (precompile1 expr)) result)
    691                (push (list v :variable) *local-variables*)))
     681               (environment-add-symbol-binding *compile-file-environment*
     682                                               v nil))) ;; any value will do
    692683            (t
    693684             (push var result)
    694              (push (list var :variable) *local-variables*))))
     685             (environment-add-symbol-binding *compile-file-environment*
     686                                             var nil)
     687)))
    695688    (nreverse result)))
    696689
    697690(defun precompile-let (form)
    698   (let ((*local-variables* *local-variables*))
     691  (let ((*compile-file-environment*
     692         (make-environment *compile-file-environment*)))
    699693    (list* 'LET
    700694           (precompile-let/let*-vars (cadr form))
     
    713707(defun precompile-let* (form)
    714708  (setf form (maybe-fold-let* form))
    715   (let ((*local-variables* *local-variables*))
     709  (let ((*compile-file-environment*
     710         (make-environment *compile-file-environment*)))
    716711    (list* 'LET*
    717712           (precompile-let/let*-vars (cadr form))
     
    857852        (values-form (caddr form))
    858853        (body (cdddr form))
    859         (*local-variables* *local-variables*))
     854        (*compile-file-environment*
     855         (make-environment *compile-file-environment*))
     856)
    860857    (dolist (var vars)
    861       (push (list var :variable) *local-variables*))
     858      (environment-add-symbol-binding *compile-file-environment* var nil))
    862859    (list* 'MULTIPLE-VALUE-BIND
    863860           vars
     
    915912;; operator, so interpreted code can use the special operator implementation.
    916913(defun expand-macro (form)
    917   (loop
    918     (unless *in-jvm-compile*
    919       (when (and (consp form)
    920                  (symbolp (%car form))
    921                  (special-operator-p (%car form)))
    922         (return-from expand-macro form)))
    923     (multiple-value-bind (result expanded)
    924         (macroexpand-1 form *compile-file-environment*)
    925       (unless expanded
    926         (return-from expand-macro result))
    927       (setf form result))))
     914  (let (exp)
     915    (loop
     916       (unless *in-jvm-compile*
     917         (when (and (consp form)
     918                    (symbolp (%car form))
     919                    (special-operator-p (%car form)))
     920           (return-from expand-macro form)))
     921       (multiple-value-bind (result expanded)
     922           (macroexpand-1 form *compile-file-environment*)
     923         (unless expanded
     924           (return-from expand-macro (values result exp)))
     925         (setf form result
     926               exp t)))))
    928927
    929928(declaim (ftype (function (t t) t) precompile-form))
Note: See TracChangeset for help on using the changeset viewer.