reject a for whose header is grouped
C's parens carried over, ((var i int 0) (< i 4) (++ i)), left the writer short of slots, and it died in caddr with no location; with a long enough body it would have compiled the body into the header. Fixes #42.
This commit is contained in:
@@ -94,6 +94,15 @@ forms, and what remains."
|
||||
form
|
||||
`(%begin ,@(map walk-expr comments) ,form)))
|
||||
|
||||
;;; (for init test step body ...). C's parens around the header, carried
|
||||
;;; over, leave a call of a `var' in init's slot and the body in test's
|
||||
(define (check-for-header form slots)
|
||||
(cond ((and (pair? slots) (pair? (car slots)) (pair? (caar slots))
|
||||
(eq? 'var (car (caar slots))))
|
||||
(sex-error form "a for header is not grouped: write (for init test step body ...)"))
|
||||
((< (length slots) 3)
|
||||
(sex-error form "malformed for: write (for init test step body ...)"))))
|
||||
|
||||
;;; A case body that declares is a block, so two cases can each declare
|
||||
;;; a `bits', and a declaration can follow the label before C23
|
||||
(define (walk-case-body body)
|
||||
@@ -246,6 +255,7 @@ forms, and what remains."
|
||||
(cons* 'while (walk-expr (car slots)) (walk-body body)))))
|
||||
(('for . rest)
|
||||
(let-values (((comments slots body) (take-slots rest 3)))
|
||||
(check-for-header form slots)
|
||||
(with-comments comments
|
||||
(cons* 'for (walk-expr (car slots)) (walk-expr (cadr slots))
|
||||
(walk-expr (caddr slots))
|
||||
|
||||
Reference in New Issue
Block a user