From 8c0ce30c2ec75efc03b5ae92523535d1d7bdc1e5 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 20 May 2015 22:39:57 -0400 Subject: [PATCH] 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. --- trans.scm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trans.scm b/trans.scm index f512f026..f76092a9 100644 --- a/trans.scm +++ b/trans.scm @@ -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)