From d0e806bf84776ebfdf93c6a55de78b5ad6ed70b5 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Wed, 14 Oct 2026 20:08:39 +0300 Subject: [PATCH] tell a grouped for header by its shape, not by a var in it (for ((= s 0) (< s n) (++ s)) ...) passed the check and reached cc as a call of (= s 0). --- fmt-c-writer.scm | 6 +++--- tests/codegen.scm | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index de7562f..0d82244 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"))