diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index 77e54e6..c3f6219 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -95,10 +95,10 @@ forms, and what remains." `(%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 +;;; over, leave all three parts 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)))) + (cond ((and (pair? slots) (list? (car slots)) (= 3 (length (car slots))) + (every pair? (car 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 ...)")))) diff --git a/tests/codegen.scm b/tests/codegen.scm index 03638e4..6e8855f 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -338,6 +338,9 @@ whitespace aside, THEN?" (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 "whatever its init is" + (reports? (in-fn "(for ((= a 0) (< a 4) (++ a)) (g a))") + "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"))