forked from alex-eg/sex
make a declaring case body a block
A case body shared the switch's scope, so two cases could not each declare `bits', and a label could not be followed by a declaration before C23; inference shared the scope too, and typed a later case's read of an outer name as the earlier case's local. Fixes #51.
This commit is contained in:
16
semen.scm
16
semen.scm
@@ -501,9 +501,8 @@
|
||||
;;; (while (< v 0) (var v char 1) ...)
|
||||
;;; (var m _ (+ v 1)) ; double, not char
|
||||
;;;
|
||||
;;; One frame per form, not one per arm: a `case' label opens no scope
|
||||
;;; in C, and an `if' arm can only declare inside a `do', which brings
|
||||
;;; its own.
|
||||
;;; A `case' body gets one too, being written as a block. An `if' arm
|
||||
;;; gets none: it can only declare inside a `do', which brings its own.
|
||||
|
||||
(define (declare-name! env name type)
|
||||
(hash-table-set! (car (hash-table-ref env :scopes)) name type))
|
||||
@@ -584,20 +583,13 @@
|
||||
(cons walk-embed-result (walk-body expansion env)))))
|
||||
(else
|
||||
(case (car form)
|
||||
((do)
|
||||
((do default)
|
||||
(parameterize ((operand-position? #f))
|
||||
(with-scope env (lambda () (walk-parts form env)))))
|
||||
|
||||
((for while if switch)
|
||||
((for while if switch case case/fallthrough)
|
||||
(with-scope env (lambda () (walk-control form env))))
|
||||
|
||||
((case case/fallthrough)
|
||||
(walk-control form env))
|
||||
|
||||
((default)
|
||||
(parameterize ((operand-position? #f))
|
||||
(walk-parts form env)))
|
||||
|
||||
((lambda)
|
||||
(let ((name (aux-name! env make-lambda-name)))
|
||||
(add-aux-code! env (lift-lambda name form))
|
||||
|
||||
Reference in New Issue
Block a user