Changeset 8513


Ignore:
Timestamp:
Feb 19, 2008, 8:07:56 AM (12 years ago)
Author:
gb
Message:

NX1-CHECK-VAR-BINDINGS: allow for the possibility of the source being
SPECIAL and do nothing in that case (new LET handling.) Remove
NX1-NOTE-VAR-BINDINGS.
NX1-LET: separate NOTE-VAR-BINDINGS processing from binding; have to
be aware of side-effects in initforms. (See ticket:243).

Location:
branches/1.1/ccl/compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1/ccl/compiler/nx0.lisp

    r6897 r8513  
    926926    (nx1-punt-var v (pop initforms))))
    927927
    928 ; at the beginning of a binding construct, note which lexical variables are bound to other
    929 ; variables and the number of setqs done so far on the initform.
    930 ; After executing the body, if neither variable has been closed over,
    931 ; the new variable hasn't been setq'ed, and the old guy wasn't setq'ed
    932 ; in the body, the binding can be punted.
    933 (defun nx1-note-var-bindings (vars initforms &aux alist)
    934   (dolist (var vars alist)
    935     (let* ((binding (nx1-note-var-binding var (pop initforms))))
    936       (if binding (push binding alist)))))
     928;;; at the beginning of a binding construct, note which lexical
     929;;; variables are bound to other variables and the number of setqs
     930;;; done so far on the initform.  After executing the body, if neither
     931;;; variable has been closed over, the new variable hasn't been
     932;;; setq'ed, and the old guy wasn't setq'ed in the body, the binding
     933;;; can be punted.
    937934
    938935(defun nx1-note-var-binding (var initform)
     
    960957              nil)))))))
    961958                     
     959;;; Process entries involving variables bound to other variables at
     960;;; the end of a binding construct.  Each entry is of the form
     961;;; (source-var setq-count . target-var), where setq-count is the
     962;;; assignment count of TARGET-VAR at the time that the binding's
     963;;; initform was evaluated (not, in the case of LET, at the time that
     964;;; the bindinw was established.).  If the target isn't closed-over
     965;;; and SETQed (somewhere), and wasn't setqed in the body (e.g.,
     966;;; still has the same assignment-count as it had when the initform
     967;;; was executed), then we can "punt" the source (and replace references
     968;;; to it with references to the target.)
     969;;; It obviously makes no sense to do this if the source is SPECIAL;
     970;;; in some cases (LET), we create the source variable and add it to
     971;;; this alist before it's known whether or not the source variable
     972;;; is SPECIAL. so we have to ignore that case here.
    962973(defun nx1-check-var-bindings (alist)
    963974  (dolist (pair alist)
     
    967978           (target-bits (nx-var-bits target)))
    968979      (unless (or
    969                ; var can't be setq'ed or closed; target can't be setq'ed AND closed.
    970                (neq (%ilogand vbits (%ilogior (%ilsl $vbitsetq 1) (%ilsl $vbitclosed 1))) 0)
     980               ;; var can't be special, setq'ed or closed; target can't be
     981               ;; setq'ed AND closed.
     982               (neq (%ilogand vbits (%ilogior (%ilsl $vbitsetq 1)
     983                                              (%ilsl $vbitclosed 1)
     984                                              (%ilsl $vbitspecial 1))) 0)
    971985               (eq (%ilogior (%ilsl $vbitsetq 1) (%ilsl $vbitclosed 1))
    972986                   (%ilogand
  • branches/1.1/ccl/compiler/nx1.lisp

    r6175 r8513  
    17721772
    17731773(defnx1 nx1-let let (pairs &body forms &environment old-env)
    1774   (let* ((vars nil)
    1775          (vals nil)
    1776          (varspecs nil))
     1774  (collect ((vars)
     1775            (vals)
     1776            (varbindings))
    17771777    (with-nx-declarations (pending)
    17781778      (multiple-value-bind (body decls)
    17791779                           (parse-body forms *nx-lexical-environment* nil)
    17801780        (nx-process-declarations pending decls)
    1781         ; Make sure that the initforms are processed in the outer
    1782         ; environment (in case any declaration handlers side-effected
    1783         ; the environment.)
     1781        ;; Make sure that the initforms are processed in the outer
     1782        ;; environment (in case any declaration handlers side-effected
     1783        ;; the environment.)
     1784       
    17841785        (let* ((*nx-lexical-environment* old-env))
    17851786          (dolist (pair pairs)
    1786             (push (nx-need-var (nx-pair-name pair)) vars)
    1787             (push (nx1-typed-var-initform pending (car vars) (nx-pair-initform pair)) vals)))
    1788         (let* ((*nx-bound-vars* (append vars *nx-bound-vars*))
    1789                (varbindings (nx1-note-var-bindings
    1790                              (dolist (sym vars varspecs)
    1791                                (push (nx-new-var pending sym) varspecs))
    1792                              (setq vals (nreverse vals))))
    1793                (form
    1794                 (make-acode
    1795                  (%nx1-operator let)
    1796                  varspecs
    1797                  vals
    1798                  (progn
    1799                    (nx-effect-other-decls pending *nx-lexical-environment*)
    1800                    (nx1-env-body body old-env))
     1787            (let* ((sym (nx-need-var (nx-pair-name pair)))
     1788                   (var (nx-cons-var sym))
     1789                   (val (nx1-typed-var-initform pending sym (nx-pair-initform pair)))
     1790                   (binding (nx1-note-var-binding var val)))
     1791              (vars var)
     1792              (vals val)
     1793              (when binding (varbindings binding)))))
     1794        (let* ((*nx-bound-vars* *nx-bound-vars*)
     1795               (varbindings (varbindings)))
     1796          (dolist (v (vars)) (nx-init-var pending v))
     1797          (let* ((form
     1798                  (make-acode
     1799                   (%nx1-operator let)
     1800                   (vars)
     1801                   (vals)
     1802                   (progn
     1803                     (nx-effect-other-decls pending *nx-lexical-environment*)
     1804                     (nx1-env-body body old-env))
    18011805                 *nx-new-p2decls*)))
    18021806          (nx1-check-var-bindings varbindings)
    1803           (nx1-punt-bindings varspecs vals)
    1804           form)))))
     1807          (nx1-punt-bindings (vars) (vals))
     1808          form))))))
    18051809
    18061810
Note: See TracChangeset for help on using the changeset viewer.