Skip to content

Commit 905adb2

Browse files
committed
get sysimg building with new binding behavior (ref #1571)
the most problematic change was forcing for loop variables to be loop-local, instead of reusing existing local vars. for example local i for i = 1:2 end return i currently works and returns 2. for now, the behavior is to introduce new variables for each iteration unless we are overwriting an existing local. comprehensions, however, always introduce fresh variables and never overwrite existing ones.
1 parent f811533 commit 905adb2

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/julia-syntax.scm

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,8 @@
14401440
(_while (call (top <=) ,cnt ,lim)
14411441
(scope-block
14421442
(block
1443-
(local ,lhs)
1443+
;; NOTE: enable this to force loop-local var
1444+
#;(local ,lhs)
14441445
(= ,lhs ,cnt)
14451446
(break-block loop-cont
14461447
,body)
@@ -1459,7 +1460,8 @@
14591460
(while (call (top !) (call (top done) ,coll ,state))
14601461
(scope-block
14611462
(block
1462-
,@(map (lambda (v) `(local ,v)) (lhs-vars lhs))
1463+
;; NOTE: enable this to force loop-local var
1464+
#;,@(map (lambda (v) `(local ,v)) (lhs-vars lhs))
14631465
,(lower-tuple-assignment (list lhs state)
14641466
`(call (top next) ,coll ,state))
14651467
,body)))))))
@@ -1660,7 +1662,11 @@
16601662
(boundscheck pop)
16611663
(= ,ri (call (top +) ,ri 1)))
16621664
`(for (= ,(cadr (car ranges)) ,(car rs))
1663-
,(construct-loops (cdr ranges) (cdr rs)))))
1665+
(block
1666+
;; *** either this or force all for loop vars local
1667+
,@(map (lambda (r) `(local ,r))
1668+
(lhs-vars (cadr (car ranges))))
1669+
,(construct-loops (cdr ranges) (cdr rs))))))
16641670

16651671
;; Evaluate the comprehension
16661672
`(block
@@ -1694,7 +1700,11 @@
16941700
(type_goto ,initlabl ,onekey ,oneval)
16951701
(call (top setindex!) ,result ,oneval ,onekey))
16961702
`(for ,(car ranges)
1697-
,(construct-loops (cdr ranges)))))
1703+
(block
1704+
;; *** either this or force all for loop vars local
1705+
,@(map (lambda (r) `(local ,r))
1706+
(lhs-vars (cadr (car ranges))))
1707+
,(construct-loops (cdr ranges))))))
16981708

16991709
;; Evaluate the comprehension
17001710
(let ((loopranges
@@ -1730,7 +1740,11 @@
17301740
(if (null? ranges)
17311741
`(call (top setindex!) ,result ,(caddr expr) ,(cadr expr))
17321742
`(for (= ,(cadr (car ranges)) ,(car rs))
1733-
,(construct-loops (cdr ranges) (cdr rs)))))
1743+
(block
1744+
;; *** either this or force all for loop vars local
1745+
,@(map (lambda (r) `(local ,r))
1746+
(lhs-vars (cadr (car ranges))))
1747+
,(construct-loops (cdr ranges) (cdr rs))))))
17341748

17351749
;; Evaluate the comprehension
17361750
`(block
@@ -2208,7 +2222,7 @@ So far only the second case can actually occur.
22082222
(body (add-local-decls (cadr e) (append vars glob env))))
22092223
`(scope-block ,@(map (lambda (v) `(local ,v))
22102224
vars)
2211-
,(prn (remove-local-decls (prn body))))))
2225+
,(remove-local-decls body))))
22122226
(else
22132227
;; form (local! x) adds a local to a normal (non-scope) block
22142228
(let ((newenv (append (declared-local!-vars e) env)))

0 commit comments

Comments
 (0)