Rename VARIABLE/FREE-IN-EXPRESSION? to EXPRESSION/FREE-VARIABLE?
authorJoe Marshall <jmarshall@alum.mit.edu>
Mon, 8 Mar 2010 20:03:48 +0000 (12:03 -0800)
committerJoe Marshall <jmarshall@alum.mit.edu>
Mon, 8 Mar 2010 20:03:48 +0000 (12:03 -0800)
src/sf/analyze.scm
src/sf/sf.pkg
src/sf/subst.scm

index 13683f3dce54833b7e10c5687616bc03c83309c9..cdab38b27f2cedf505968f6b0d27268c1500beba 100644 (file)
@@ -138,104 +138,97 @@ USA.
 (define-integrable (singleton-variable variable)
   (list variable))
 \f
-;;; VARIABLE/FREE-IN-EXPRESSION? <variable> <expression>
-;;; Test if a particular <variable> occurs free in <expression>.  Faster
-;;; and cheaper than collecting the entire free variable set and then
-;;; using memq.
-(define (variable/free-in-expression? variable expression)
-  ((expression/method is-free-dispatch-vector expression) variable expression))
-
-(define (is-free/expressions variable expressions)
+;;; EXPRESSION/FREE-VARIABLE? <expression> <variable>
+;;
+;; Test if a particular <variable> occurs free in <expression>.  Faster
+;; and cheaper than collecting the entire free variable set and then
+;; using memq.
+
+(define (expression/free-variable? expression variable)
+  ((expression/method is-free-dispatch-vector expression) expression variable))
+
+(define (expressions/free-variable? expressions variable)
   (fold-left (lambda (answer expression)
               (or answer
-                  (variable/free-in-expression? variable expression)))
+                  (expression/free-variable? expression variable)))
             #f
             expressions))
 
 (define is-free-dispatch-vector
   (expression/make-dispatch-vector))
 
-(define define-method/is-free
+(define define-method/free-variable?
   (expression/make-method-definer is-free-dispatch-vector))
 
-(define-method/is-free 'ACCESS
-  (lambda (variable expression)
-    (variable/free-in-expression? variable (access/environment expression))))
+(define-method/free-variable? 'ACCESS
+  (lambda (expression variable)
+    (expression/free-variable? (access/environment expression) variable)))
 
-(define-method/is-free 'ASSIGNMENT
-  (lambda (variable expression)
+(define-method/free-variable? 'ASSIGNMENT
+  (lambda (expression variable)
     (or (eq? variable (assignment/variable expression))
-       (variable/free-in-expression? variable (assignment/value expression)))))
+       (expression/free-variable? (assignment/value expression) variable))))
 
-(define-method/is-free 'COMBINATION
-  (lambda (variable expression)
-    (or (variable/free-in-expression? variable (combination/operator expression))
-       (is-free/expressions variable (combination/operands expression)))))
+(define-method/free-variable? 'COMBINATION
+  (lambda (expression variable)
+    (or (expression/free-variable? (combination/operator expression) variable)
+       (expressions/free-variable? (combination/operands expression) variable))))
 
-(define-method/is-free 'CONDITIONAL
-  (lambda (variable expression)
-    (or (variable/free-in-expression? variable (conditional/predicate expression))
+(define-method/free-variable? 'CONDITIONAL
+  (lambda (expression variable)
+    (or (expression/free-variable? (conditional/predicate expression) variable)
        (cond ((expression/always-false? (conditional/predicate expression))
-              (variable/free-in-expression? variable (conditional/alternative expression)))
+              (expression/free-variable? (conditional/alternative expression) variable))
              ((expression/never-false? (conditional/predicate expression))
-              (variable/free-in-expression? variable (conditional/consequent expression)))
-             ((variable/free-in-expression? variable (conditional/consequent expression)))
-             (else (variable/free-in-expression? variable (conditional/alternative expression)))))))
-
-(define-method/is-free 'CONSTANT
-  (lambda (variable expression)
-    (declare (ignore variable expression))
-    #f))
-
-(define-method/is-free 'DECLARATION
-  (lambda (variable expression)
-    (variable/free-in-expression? variable (declaration/expression expression))))
+              (expression/free-variable? (conditional/consequent expression) variable))
+             ((expression/free-variable? (conditional/consequent expression) variable))
+             (else (expression/free-variable? (conditional/alternative expression) variable))))))
+
+(define-method/free-variable? 'CONSTANT false-procedure)
+
+(define-method/free-variable? 'DECLARATION
+  (lambda (expression variable)
+    (expression/free-variable? (declaration/expression expression) variable)))
 \f
-(define-method/is-free 'DELAY
-  (lambda (variable expression)
-    (variable/free-in-expression? variable (delay/expression expression))))
+(define-method/free-variable? 'DELAY
+  (lambda (expression variable)
+    (expression/free-variable? (delay/expression expression) variable)))
 
-(define-method/is-free 'DISJUNCTION
-  (lambda (variable expression)
-    (or (variable/free-in-expression? variable (disjunction/predicate expression))
+(define-method/free-variable? 'DISJUNCTION
+  (lambda (expression variable)
+    (or (expression/free-variable? (disjunction/predicate expression) variable)
        (if (expression/never-false? (disjunction/predicate expression))
            #f
-           (variable/free-in-expression? variable (disjunction/alternative expression))))))
+           (expression/free-variable? (disjunction/alternative expression) variable)))))
 
-(define-method/is-free 'OPEN-BLOCK
-  (lambda (variable expression)
+(define-method/free-variable? 'OPEN-BLOCK
+  (lambda (expression variable)
     (fold-left (lambda (answer action)
                 (or answer
                     (if (eq? action open-block/value-marker)
                         #f
-                        (variable/free-in-expression? variable action))))
+                        (expression/free-variable? action variable))))
               #f
               (open-block/actions expression))))
 
-(define-method/is-free 'PROCEDURE
-  (lambda (variable expression)
-    (variable/free-in-expression? variable (procedure/body expression))))
+(define-method/free-variable? 'PROCEDURE
+  (lambda (expression variable)
+    (expression/free-variable? (procedure/body expression) variable)))
 
-(define-method/is-free 'QUOTATION
-  (lambda (variable expression)
-    (declare (ignore variable expression))
-    #f))
+(define-method/free-variable? 'QUOTATION false-procedure)
 
-(define-method/is-free 'REFERENCE
-  (lambda (variable expression)
-    (eq? variable (reference/variable expression))))
+(define-method/free-variable? 'REFERENCE
+  (lambda (expression variable)
+    (eq? (reference/variable expression) variable)))
 
-(define-method/is-free 'SEQUENCE
-  (lambda (variable expression)
+(define-method/free-variable? 'SEQUENCE
+  (lambda (expression variable)
   (fold-left (lambda (answer action)
               (or answer
                   (if (eq? action open-block/value-marker)
                       #f
-                      (variable/free-in-expression? variable action))))
+                      (expression/free-variable? action variable))))
             #f
             (sequence/actions expression))))
 
-(define-method/is-free 'THE-ENVIRONMENT
-  (lambda (variable expression)
-    (declare (ignore variable expression))
-    #f))
\ No newline at end of file
+(define-method/free-variable? 'THE-ENVIRONMENT false-procedure)
index 42fc2f5592047b42737338d2015337417a04795b..50b27aad723cd29f9e51948b71c9a76f4a309672 100644 (file)
@@ -148,8 +148,8 @@ USA.
   (files "analyze")
   (parent (scode-optimizer))
   (export (scode-optimizer)
-         expression/free-variables
-         variable/free-in-expression?))
+         expression/free-variable?
+         expression/free-variables))
 
 (define-package (scode-optimizer change-type)
   (files "chtype")
index 489c15bf0981f01dc8df4252254c9ecac8cae66d..d70036ed31383954164f427ce29512a588f30cd2 100644 (file)
@@ -395,7 +395,7 @@ USA.
                                      ;; re-integrate e4 to eliminate it as a known false.
                                      (if (and (reference? e2)
                                               (variable/safely-integrable? (reference/variable e2) operations)
-                                              (variable/free-in-expression? (reference/variable e2) e4)
+                                              (expression/free-variable? e4 (reference/variable e2))
                                               (noisy-test sf:enable-conditional-propagation? "Propagating conditional information"))
                                          (integrate/expression
                                           (operations/bind operations
@@ -410,14 +410,14 @@ USA.
                ;; first see if e1 is a variable that appears in e4
                (cond ((and (reference? e1)
                            (variable/safely-integrable? (reference/variable e1) operations)
-                           (variable/free-in-expression? (reference/variable e1) e4)
+                           (expression/free-variable? e4 (reference/variable e1))
                            (noisy-test sf:enable-conditional-propagation? "Propagating condition information"))
                       ;; re-integrate e4 to take advantage of information about e1
                       (let ((e4b (integrate/expression
                                   (operations/bind
                                    (if (and (reference? e3)
                                             (variable/safely-integrable? (reference/variable e3) operations)
-                                            (variable/free-in-expression? (reference/variable e3) e4))
+                                            (expression/free-variable? e4 (reference/variable e3)))
                                        (operations/bind operations
                                                         'integrate
                                                         (reference/variable e3)
@@ -439,7 +439,7 @@ USA.
                                              ;; re-integrate e4 to eliminate it as a known false.
                                              (if (and (reference? e3)
                                                       (variable/safely-integrable? (reference/variable e3) operations)
-                                                      (variable/free-in-expression? (reference/variable e3) e4)
+                                                      (expression/free-variable? e4 (reference/variable e3))
                                                       (noisy-test sf:enable-conditional-propagation? "Propagating conditional information"))
                                                  (integrate/expression
                                                   (operations/bind operations