diff --git a/test-find-local-vars.scm b/test-find-local-vars.scm index 3ef2edd0..ee51ce98 100644 --- a/test-find-local-vars.scm +++ b/test-find-local-vars.scm @@ -1,5 +1,37 @@ (import (scheme base) (scheme write) (scheme cyclone ast) (scheme cyclone util) (scheme cyclone pretty-print)) +;; TODO: scan sexp, is sym only called in tail-call position? +(define (local-tail-call-only? sexp sym) + (call/cc + (lambda (return) + (define (scan exp fail?) + (cond + ((ast:lambda? exp) + (return #f)) ;; Could be OK if not ref'd... + ;((quote? exp) exp) + ;((const? exp) exp) + ((ref? exp) + (if (equal? exp sym) + (return #f))) ;; Assume not a tail call + ((define? exp) + (return #f)) ;; Fail fast + ((set!? exp) + (return #f)) ;; Fail fast + ((if? exp) + (scan (if->condition exp) #t) ;; fail if found under here + (scan (if->then exp) fail?) + (scan (if->else exp) fail?)) + ((app? exp) + (cond + ((and (equal? (car exp) sym) + (not fail?)) + (map (lambda (e) (scan e fail?)) (cdr exp))) ;; Sym is OK, skip + (else + (map (lambda (e) (scan e fail?)) exp)))) + (else exp))) + (scan sexp #f) + (return #t)))) + (define (find-local-vars sexp) (define (scan exp) (cond @@ -24,27 +56,14 @@ (scan (if->else exp))) ((app? exp) (cond - ((ast:lambda? (car exp)) -;; TODO: want to find this: -;; ((lambda -;; (k$1080) -;; (if (Cyc-fast-eq -;; (car first$89$683) -;; (car row$90$684)) -;; (k$1080 if-equal$76$674) -;; (k$1080 if-different$77$675))) -;; (lambda -;; (r$1079) -;; (Cyc-seq -;; (vector-set! -;; vec$79$677 -;; i$88$682 -;; r$1079) -;; ((cell-get lp$80$87$681) -;; k$1073 -;; (Cyc-fast-plus i$88$682 1) -;; (cdr first$89$683) -;; (cdr row$90$684)))))))) + ((and + (ast:lambda? (car exp)) + (equal? (length exp) 2) + (ast:lambda? (cadr exp)) + (local-tail-call-only? + (ast:lambda-body (car exp)) + (car (ast:lambda-args (car exp))))) + (write `(tail-call-only? passed for ,exp)) (newline) 'TODO) (else (map scan exp))))