From 8a00c24ebba3924ad6aa820ef722c4f5df783170 Mon Sep 17 00:00:00 2001 From: Joe Marshall Date: Mon, 8 Mar 2010 12:03:48 -0800 Subject: [PATCH] Rename VARIABLE/FREE-IN-EXPRESSION? to EXPRESSION/FREE-VARIABLE? --- src/sf/analyze.scm | 119 +++++++++++++++++++++------------------------ src/sf/sf.pkg | 4 +- src/sf/subst.scm | 8 +-- 3 files changed, 62 insertions(+), 69 deletions(-) diff --git a/src/sf/analyze.scm b/src/sf/analyze.scm index 13683f3dc..cdab38b27 100644 --- a/src/sf/analyze.scm +++ b/src/sf/analyze.scm @@ -138,104 +138,97 @@ USA. (define-integrable (singleton-variable variable) (list variable)) -;;; VARIABLE/FREE-IN-EXPRESSION? -;;; Test if a particular occurs free in . 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? +;; +;; Test if a particular occurs free in . 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))) -(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) diff --git a/src/sf/sf.pkg b/src/sf/sf.pkg index 42fc2f559..50b27aad7 100644 --- a/src/sf/sf.pkg +++ b/src/sf/sf.pkg @@ -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") diff --git a/src/sf/subst.scm b/src/sf/subst.scm index 489c15bf0..d70036ed3 100644 --- a/src/sf/subst.scm +++ b/src/sf/subst.scm @@ -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 -- 2.25.1