boot2

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

commit 2d93b00ae781c4fcee00fa1713297f02c5801315
parent 231ff72e8f0ade010834887bf0fe0b197a096a19
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon, 27 Apr 2026 03:04:41 -0700

cc/cg: drop vestigial cg-loop-end no-op

cg-loop-end was a placeholder reserved for future per-loop teardown
that never materialized — its body is just `0`. parse.scm doesn't
call it; only four cc-cg fixtures did, for symmetry. Remove the
definition and the four call sites.

cg-loop already returns the tag for any caller that needs it, so the
fixture cleanups also drop their useless let-bindings of tag.

Diffstat:
Mcc/cg.scm | 2--
Mtests/cc-cg/08-while-break.scm | 8+++-----
Mtests/cc-cg/08b-while-continue.scm | 26++++++++++++--------------
Mtests/cc-cg/63-do-while.scm | 32+++++++++++++++-----------------
Mtests/cc-cg/69-vararg-recv.scm | 38++++++++++++++++++--------------------
5 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/cc/cg.scm b/cc/cg.scm @@ -968,8 +968,6 @@ (%cg-emit-many cg (list "})\n")) tag)) -(define (cg-loop-end cg tag) 0) - (define (cg-break cg tag) (%cg-emit-many cg (list "%break(" tag ")\n"))) diff --git a/tests/cc-cg/08-while-break.scm b/tests/cc-cg/08-while-break.scm @@ -4,11 +4,9 @@ (let ((cg (cg-init))) (cg-fn-begin cg "main" '() %t-i32) - (let ((tag (cg-loop - cg - (lambda () (cg-push-imm cg %t-i32 1)) - (lambda (tag) (cg-break cg tag))))) - (cg-loop-end cg tag)) + (cg-loop cg + (lambda () (cg-push-imm cg %t-i32 1)) + (lambda (tag) (cg-break cg tag))) (cg-push-imm cg %t-i32 5) (cg-return cg) (cg-fn-end cg) diff --git a/tests/cc-cg/08b-while-continue.scm b/tests/cc-cg/08b-while-continue.scm @@ -9,20 +9,18 @@ (list (cons "x" %t-i32)) %t-i32)) (x* (cdr (car params)))) - (let ((tag (cg-loop - cg - (lambda () - (cg-push-sym cg x*) (cg-load cg)) - (lambda (tag) - ;; x = x - 1 - (cg-push-sym cg x*) - (cg-push-sym cg x*) (cg-load cg) - (cg-push-imm cg %t-i32 1) - (cg-binop cg 'sub) - (cg-assign cg) - (cg-pop cg) - (cg-continue cg tag))))) - (cg-loop-end cg tag)) + (cg-loop cg + (lambda () + (cg-push-sym cg x*) (cg-load cg)) + (lambda (tag) + ;; x = x - 1 + (cg-push-sym cg x*) + (cg-push-sym cg x*) (cg-load cg) + (cg-push-imm cg %t-i32 1) + (cg-binop cg 'sub) + (cg-assign cg) + (cg-pop cg) + (cg-continue cg tag))) (cg-push-imm cg %t-i32 9) (cg-return cg) (cg-fn-end cg) diff --git a/tests/cc-cg/63-do-while.scm b/tests/cc-cg/63-do-while.scm @@ -16,23 +16,21 @@ ;; 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-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-push-sym cg x-sym) (cg-load cg) (cg-return cg) (cg-fn-end cg) diff --git a/tests/cc-cg/69-vararg-recv.scm b/tests/cc-cg/69-vararg-recv.scm @@ -41,26 +41,24 @@ (cg-push-sym cg i-sym) (cg-push-imm cg %t-i32 0) (cg-assign cg) (cg-pop cg) ;; while (i < n) - (let ((tag (cg-loop - cg - (lambda () - (cg-push-sym cg i-sym) (cg-load cg) - (cg-push-sym cg n*) (cg-load cg) - (cg-binop cg 'lt)) - (lambda (tag) - ;; total = total + va_arg(ap, int) - (cg-push-sym cg tot-sym) - (cg-push-sym cg tot-sym) (cg-load cg) - (cg-push-sym cg ap-sym) (cg-va-arg cg %t-i32) - (cg-binop cg 'add) - (cg-assign cg) (cg-pop cg) - ;; i = i + 1 - (cg-push-sym cg i-sym) - (cg-push-sym cg i-sym) (cg-load cg) - (cg-push-imm cg %t-i32 1) - (cg-binop cg 'add) - (cg-assign cg) (cg-pop cg))))) - (cg-loop-end cg tag)) + (cg-loop cg + (lambda () + (cg-push-sym cg i-sym) (cg-load cg) + (cg-push-sym cg n*) (cg-load cg) + (cg-binop cg 'lt)) + (lambda (tag) + ;; total = total + va_arg(ap, int) + (cg-push-sym cg tot-sym) + (cg-push-sym cg tot-sym) (cg-load cg) + (cg-push-sym cg ap-sym) (cg-va-arg cg %t-i32) + (cg-binop cg 'add) + (cg-assign cg) (cg-pop cg) + ;; i = i + 1 + (cg-push-sym cg i-sym) + (cg-push-sym cg i-sym) (cg-load cg) + (cg-push-imm cg %t-i32 1) + (cg-binop cg 'add) + (cg-assign cg) (cg-pop cg))) ;; va_end(ap) (cg-push-sym cg ap-sym) (cg-va-end cg)