Lines
100 %
Functions
Branches
//! Extra DO / DO* / DOLIST paths — value-position dispatch
//! (`compile_do_runtime_for_stack`) and edge cases.
use super::common::{compile_and_validate, wrap_with_runtime_i32, wrap_with_runtime_ratio};
/// DO at value position — the loop's result form lands on the wasm
/// stack. Exercises `compile_do_runtime_for_stack`.
#[test]
fn do_for_stack_result() {
compile_and_validate(&wrap_with_runtime_ratio(
"(+ (do ((i 0 (+ i 1))) ((>= i 3) i)) X)",
));
}
fn do_star_for_stack_result() {
"(+ (do* ((i 0 (+ i 1))) ((>= i 3) i)) X)",
fn do_with_constant_iteration_static_folds() {
compile_and_validate("(do ((i 0 (+ i 1))) ((= i 3) i))");
fn dolist_at_value_position_returns_nil() {
compile_and_validate("(+ (begin (dolist (x '(1 2)) x) 0) 0)");
fn dolist_with_unbounded_runtime_chain() {
// Iteration over a runtime pair chain — locks in the
// compile_dolist_runtime path.
compile_and_validate(
"(let* ((acc 0)) \
(dolist (i (cons 1 (cons 2 nil))) (setf acc (+ acc i))) \
acc)",
);
fn do_with_nested_do() {
"(let* ((sum 0)) \
(do ((i 0 (+ i 1))) ((>= i 2)) \
(do ((j 0 (+ j 1))) ((>= j 2)) \
(setf sum (+ sum 1)))) \
sum)",
/// DO* with sequential init — the second var's init can reference
/// the first.
fn do_star_sequential_init_visibility() {
// IDX is a runtime Index; `limit` (init IDX, step 0) and the counter `i`
// stay in the Index stratum so the loop var types are consistent.
compile_and_validate(&wrap_with_runtime_i32(
"(do* ((i 0 (+ i 1)) (limit IDX 0)) ((>= i limit) limit))",