bugfixes #66
@@ -94,6 +94,15 @@ forms, and what remains."
|
|||||||
form
|
form
|
||||||
`(%begin ,@(map walk-expr comments) ,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 case body that declares is a block, so two cases can each declare
|
||||||
;;; a `bits', and a declaration can follow the label before C23
|
;;; a `bits', and a declaration can follow the label before C23
|
||||||
(define (walk-case-body body)
|
(define (walk-case-body body)
|
||||||
@@ -245,6 +254,7 @@ forms, and what remains."
|
|||||||
(cons* 'while (walk-expr (car slots)) (walk-body body)))))
|
(cons* 'while (walk-expr (car slots)) (walk-body body)))))
|
||||||
(('for . rest)
|
(('for . rest)
|
||||||
(let-values (((comments slots body) (take-slots rest 3)))
|
(let-values (((comments slots body) (take-slots rest 3)))
|
||||||
|
(check-for-header form slots)
|
||||||
(with-comments comments
|
(with-comments comments
|
||||||
(cons* 'for (walk-expr (car slots)) (walk-expr (cadr slots))
|
(cons* 'for (walk-expr (car slots)) (walk-expr (cadr slots))
|
||||||
(walk-expr (caddr slots))
|
(walk-expr (caddr slots))
|
||||||
|
|||||||
@@ -309,6 +309,22 @@ whitespace aside, THEN?"
|
|||||||
|
|
||||||
;; A nested pointer chain used to silently lose a level:
|
;; A nested pointer chain used to silently lose a level:
|
||||||
;; (var p (* (* char))) emitted `char *p'
|
;; (var p (* (* char))) emitted `char *p'
|
||||||
|
;; A grouped header, C's parens carried over, died in the writer with
|
||||||
|
;; `(caddr) bad argument type' and no location
|
||||||
|
(test-group "malformed for"
|
||||||
|
(test-assert "a grouped header is named"
|
||||||
|
(reports? (in-fn "(for ((var i int 0) (< i 4) (++ i)) (g i))")
|
||||||
|
"header is not grouped"))
|
||||||
|
(test-assert "even when the body fills the slots it left"
|
||||||
|
(reports? (in-fn "(for ((var i int 0) (< i 4) (++ i)) (g i) (g i) (g i))")
|
||||||
|
"header is not grouped"))
|
||||||
|
(test-assert "a short one gets the shape"
|
||||||
|
(reports? (in-fn "(for (var i int 0) (< i 4))")
|
||||||
|
"(for init test step body ...)"))
|
||||||
|
(test-assert "and both name the line"
|
||||||
|
(reports? "(fn f () void\n (for ((var i int 0) (< i 4) (++ i)) (g i)))"
|
||||||
|
"codegen.sex:2:")))
|
||||||
|
|
||||||
(test-group "malformed types are rejected"
|
(test-group "malformed types are rejected"
|
||||||
(test-assert "nested pointer chain"
|
(test-assert "nested pointer chain"
|
||||||
(reports? (in-fn "(var p (* (* char)))") "pointer chains are written flat"))
|
(reports? (in-fn "(var p (* (* char)))") "pointer chains are written flat"))
|
||||||
|
|||||||
Reference in New Issue
Block a user