Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler leaking globals when (define var) not direct member of a lambda #43

Open
jniewerth opened this issue Feb 15, 2017 · 1 comment
Labels

Comments

@jniewerth
Copy link
Contributor

jniewerth commented Feb 15, 2017

The following code leaks a as a global:

(define (func)
   (if #t 
             (define a 5)
   ))

I could fix this by duplicating get-defined-vars from compiler.lsp (was used by expander + compiler) and changing get-defined-vars for the compiler like this:

(define (get-defined-vars expr)
  (letrec ((get-defined-vars-
            (lambda (expr)
              (cond
               ((atom? expr) ())
               ((and
                 (eq? (car expr) 'define)
                 (pair? (cdr expr))
                 )
                (or
                 (and
                  (symbol? (cadr expr))
                  (list* (cadr expr) (get-defined-vars- (caddr expr )))
                  )
                 (and (pair? (cadr expr))
                      (symbol? (caadr expr))
                      (list (caadr expr)))
                 ()
                 )
                )
               ((not (member (car expr) (list 'lambda 'trycatch )))
                (apply nconc (map get-defined-vars- (cdr expr))))
               (else ())))))
    (delete-duplicates (get-defined-vars- expr))))

Before that change the scanner did only descent into "begin" blocks but not deeper.

@JeffBezanson
Copy link
Owner

Thanks for finding this. Is there a reason not to use the corrected code in both the expander and compiler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants