Correcting issue 95. Set! on global variables will check that the variable is defined
before proceeding.
This commit is contained in:
parent
60dda32c2e
commit
04f0aec996
|
@ -482,28 +482,31 @@
|
||||||
(define (compile-toplevel-set exp cenv target linkage)
|
(define (compile-toplevel-set exp cenv target linkage)
|
||||||
(define prefix (ensure-prefix (list-ref cenv (ToplevelSet-depth exp))))
|
(define prefix (ensure-prefix (list-ref cenv (ToplevelSet-depth exp))))
|
||||||
(define prefix-element (list-ref (Prefix-names prefix) (ToplevelSet-pos exp)))
|
(define prefix-element (list-ref (Prefix-names prefix) (ToplevelSet-pos exp)))
|
||||||
|
|
||||||
|
(define top-target
|
||||||
|
(cond
|
||||||
|
[(ModuleVariable? prefix-element)
|
||||||
|
(make-EnvPrefixReference (ToplevelSet-depth exp)
|
||||||
|
(ToplevelSet-pos exp)
|
||||||
|
#t)]
|
||||||
|
[(GlobalBucket? prefix-element)
|
||||||
|
(make-GlobalsReference (GlobalBucket-name prefix-element))]
|
||||||
|
|
||||||
|
[(or (eq? prefix-element #f)
|
||||||
|
(symbol? prefix-element))
|
||||||
|
(make-EnvPrefixReference (ToplevelSet-depth exp)
|
||||||
|
(ToplevelSet-pos exp)
|
||||||
|
#f)]))
|
||||||
(let ([get-value-code
|
(let ([get-value-code
|
||||||
(cond
|
(cond
|
||||||
[(ModuleVariable? prefix-element)
|
;; Special case: when set!-ing globals, see that they're defined first.
|
||||||
(compile (ToplevelSet-value exp)
|
|
||||||
cenv
|
|
||||||
(make-EnvPrefixReference (ToplevelSet-depth exp)
|
|
||||||
(ToplevelSet-pos exp)
|
|
||||||
#t)
|
|
||||||
next-linkage/expects-single)]
|
|
||||||
[(GlobalBucket? prefix-element)
|
[(GlobalBucket? prefix-element)
|
||||||
(compile (ToplevelSet-value exp)
|
(append-instruction-sequences
|
||||||
cenv
|
(compile (ToplevelSet-value exp) cenv 'val next-linkage/expects-single)
|
||||||
(make-GlobalsReference (GlobalBucket-name prefix-element))
|
(make-Perform (make-CheckGlobalBound! (GlobalBucket-name prefix-element)))
|
||||||
next-linkage/expects-single)]
|
(make-AssignImmediate top-target (make-Reg 'val)))]
|
||||||
[(or (eq? prefix-element #f)
|
[else
|
||||||
(symbol? prefix-element))
|
(compile (ToplevelSet-value exp) cenv top-target next-linkage/expects-single)])]
|
||||||
(compile (ToplevelSet-value exp)
|
|
||||||
cenv
|
|
||||||
(make-EnvPrefixReference (ToplevelSet-depth exp)
|
|
||||||
(ToplevelSet-pos exp)
|
|
||||||
#f)
|
|
||||||
next-linkage/expects-single)])]
|
|
||||||
[singular-context-check (emit-singular-context linkage)])
|
[singular-context-check (emit-singular-context linkage)])
|
||||||
(end-with-linkage
|
(end-with-linkage
|
||||||
linkage
|
linkage
|
||||||
|
|
Loading…
Reference in New Issue
Block a user