boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit f56b58ee2704af5c3ce44b5734fa9f05cb371054
parent c0af21b7d2e5511016c8989f404945b0d697b8ba
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Sun, 26 Apr 2026 22:24:21 -0700

cc tests: do { } while (cond) fixtures (§F.1)

Composes existing cg-loop + cg-if + cg-break primitives. cc-cg drives
the API directly; cc-parse exercises parse-do-stmt end-to-end.

Diffstat:
Atests/cc-cg/63-do-while.expected-exit | 1+
Atests/cc-cg/63-do-while.scm | 39+++++++++++++++++++++++++++++++++++++++
Atests/cc-parse/63-do-while.c | 6++++++
Atests/cc-parse/63-do-while.expected-exit | 1+
4 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/tests/cc-cg/63-do-while.expected-exit b/tests/cc-cg/63-do-while.expected-exit @@ -0,0 +1 @@ +3 diff --git a/tests/cc-cg/63-do-while.scm b/tests/cc-cg/63-do-while.scm @@ -0,0 +1,39 @@ +;; tests/cc-cg/63-do-while.scm — `do { x = x + 1; } while (x < 3);` (§F.1) +;; Models: int main(void) { int x = 0; do x = x + 1; while (x < 3); return x; } +;; Exercises composing cg-loop + cg-if + cg-break for do-while. +;; Expected exit: 3. + +(let* ((cg (cg-init)) + (params (cg-fn-begin cg "main" '() %t-i32)) + (x-slot (cg-alloc-slot cg 4 4)) + (x-sym (%sym "x" 'var 'auto %t-i32 x-slot))) + ;; x = 0 + (cg-push-sym cg x-sym) + (cg-push-imm cg %t-i32 0) + (cg-assign cg) (cg-pop cg) + ;; do { x = x + 1; } while (x < 3); + ;; + ;; Encoding (per parse-do-stmt): cg-loop with empty head-thunk; body + ;; runs the user body, then evaluates the while-cond and if zero + ;; (lnot then if), break. + (let ((tag (cg-loop + cg + (lambda () #t) ; do-while: head is empty (cond at bottom) + (lambda (tag) + ;; x = x + 1 + (cg-push-sym cg x-sym) + (cg-push-sym cg x-sym) (cg-load cg) + (cg-push-imm cg %t-i32 1) + (cg-binop cg 'add) + (cg-assign cg) (cg-pop cg) + ;; while cond: x < 3 ; if !cond, break + (cg-push-sym cg x-sym) (cg-load cg) + (cg-push-imm cg %t-i32 3) + (cg-binop cg 'lt) + (cg-unop cg 'lnot) + (cg-if cg (lambda () (cg-break cg tag))))))) + (cg-loop-end cg tag)) + (cg-push-sym cg x-sym) (cg-load cg) + (cg-return cg) + (cg-fn-end cg) + (write-bv-fd 1 (cg-finish cg))) diff --git a/tests/cc-parse/63-do-while.c b/tests/cc-parse/63-do-while.c @@ -0,0 +1,6 @@ +int main(void) { + int x; + x = 0; + do { x = x + 1; } while (x < 3); + return x; +} diff --git a/tests/cc-parse/63-do-while.expected-exit b/tests/cc-parse/63-do-while.expected-exit @@ -0,0 +1 @@ +3