Skip to content

Commit

Permalink
get sysimg building with new binding behavior (ref #1571)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JeffBezanson committed Aug 1, 2013
1 parent f811533 commit 905adb2
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,8 @@
(_while (call (top <=) ,cnt ,lim)
(scope-block
(block
(local ,lhs)
;; NOTE: enable this to force loop-local var
#;(local ,lhs)
(= ,lhs ,cnt)
(break-block loop-cont
,body)
Expand All @@ -1459,7 +1460,8 @@
(while (call (top !) (call (top done) ,coll ,state))
(scope-block
(block
,@(map (lambda (v) `(local ,v)) (lhs-vars lhs))
;; NOTE: enable this to force loop-local var
#;,@(map (lambda (v) `(local ,v)) (lhs-vars lhs))
,(lower-tuple-assignment (list lhs state)
`(call (top next) ,coll ,state))
,body)))))))
Expand Down Expand Up @@ -1660,7 +1662,11 @@
(boundscheck pop)
(= ,ri (call (top +) ,ri 1)))
`(for (= ,(cadr (car ranges)) ,(car rs))
,(construct-loops (cdr ranges) (cdr rs)))))
(block
;; *** either this or force all for loop vars local
,@(map (lambda (r) `(local ,r))
(lhs-vars (cadr (car ranges))))
,(construct-loops (cdr ranges) (cdr rs))))))

;; Evaluate the comprehension
`(block
Expand Down Expand Up @@ -1694,7 +1700,11 @@
(type_goto ,initlabl ,onekey ,oneval)
(call (top setindex!) ,result ,oneval ,onekey))
`(for ,(car ranges)
,(construct-loops (cdr ranges)))))
(block
;; *** either this or force all for loop vars local
,@(map (lambda (r) `(local ,r))
(lhs-vars (cadr (car ranges))))
,(construct-loops (cdr ranges))))))

;; Evaluate the comprehension
(let ((loopranges
Expand Down Expand Up @@ -1730,7 +1740,11 @@
(if (null? ranges)
`(call (top setindex!) ,result ,(caddr expr) ,(cadr expr))
`(for (= ,(cadr (car ranges)) ,(car rs))
,(construct-loops (cdr ranges) (cdr rs)))))
(block
;; *** either this or force all for loop vars local
,@(map (lambda (r) `(local ,r))
(lhs-vars (cadr (car ranges))))
,(construct-loops (cdr ranges) (cdr rs))))))

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

0 comments on commit 905adb2

Please sign in to comment.