Add a global's initialization to the top-level if

it is assigned to another global. EG: (define a b). If b is not initialized until the top-level, then a must be initialized there as well, otherwise it will pick up the old value of b.
This commit is contained in:
Justin Ethier 2015-05-20 22:39:57 -04:00
parent 4e953b64c3
commit 8c0ce30c2e

View file

@ -926,8 +926,13 @@
;; into two parts - use the define to initialize it to false (CPS is fine),
;; and place the expression into a top-level (set!), which can be
;; handled by the existing CPS conversion.
((and (list? (car (define->exp (car top-lvl))))
(not (lambda? (car (define->exp (car top-lvl))))))
((or
;; TODO: the following line may not be good enough, a global assigned to another
;; global may still be init'd to nil if the order is incorrect in the "top level"
;; initialization code.
(symbol? (car (define->exp (car top-lvl)))) ;; TODO: put these at the end of top-lvl???
(and (list? (car (define->exp (car top-lvl))))
(not (lambda? (car (define->exp (car top-lvl)))))))
(loop (cdr top-lvl)
(cons
`(define ,(define->var (car top-lvl)) #f)