(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)
;; 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
;; 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)
;; 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