08b-while-continue.scm (972B)
1 ;; tests/cc-cg/08b-while-continue.scm — loop with continue + decrementing 2 ;; param to ensure termination. 3 ;; Models: int main(int x) { while (x) { x = x - 1; continue; } return 9; } 4 ;; Run: with no argv, argc=1 → x=1 → body runs once, x becomes 0, 5 ;; continue → head sees x=0 → exit loop → return 9. 6 7 (let* ((cg (cg-init)) 8 (params (cg-fn-begin cg "main" 9 (list (cons "x" %t-i32)) 10 %t-i32)) 11 (x* (cdr (car params)))) 12 (cg-loop cg 13 (lambda () 14 (cg-push-sym cg x*) (cg-load cg)) 15 (lambda (tag) 16 ;; x = x - 1 17 (cg-push-sym cg x*) 18 (cg-push-sym cg x*) (cg-load cg) 19 (cg-push-imm cg %t-i32 1) 20 (cg-binop cg 'sub) 21 (cg-assign cg) 22 (cg-pop cg) 23 (cg-continue cg tag))) 24 (cg-push-imm cg %t-i32 9) 25 (cg-return cg) 26 (cg-fn-end cg) 27 (write-bv-fd 1 (cg-finish cg)))