1
//! `DO*` (sequential-step variant) entry points. Inits and steps apply one
2
//! variable at a time; the shared `DoLoop.sequential` flag carries that to the
3
//! DO code in `do_form`.
4

            
5
use crate::ast::{Expr, WasmType};
6
use crate::compiler::context::CompileContext;
7
use crate::compiler::emit::FunctionEmitter;
8
use crate::error::{Error, Result};
9
use crate::runtime::SymbolTable;
10

            
11
use super::do_form::{compile_in, eval_loop};
12
use super::unroll::Pos;
13

            
14
const KIND: (&str, bool) = ("DO*", true);
15

            
16
1485
pub(super) fn compile_do_star_for_stack(
17
1485
    ctx: &mut CompileContext,
18
1485
    emit: &mut FunctionEmitter,
19
1485
    symbols: &mut SymbolTable,
20
1485
    args: &[Expr],
21
1485
) -> Result<WasmType> {
22
1485
    compile_in(ctx, emit, symbols, KIND, args, Pos::Stack)?
23
        .ok_or_else(|| Error::Compile("internal: DO* in stack position left no value".to_string()))
24
1485
}
25

            
26
2531
pub(super) fn compile_do_star(
27
2531
    ctx: &mut CompileContext,
28
2531
    emit: &mut FunctionEmitter,
29
2531
    symbols: &mut SymbolTable,
30
2531
    args: &[Expr],
31
2531
) -> Result<()> {
32
2531
    compile_in(ctx, emit, symbols, KIND, args, Pos::Value).map(|_| ())
33
2531
}
34

            
35
224
pub(super) fn compile_do_star_for_effect(
36
224
    ctx: &mut CompileContext,
37
224
    emit: &mut FunctionEmitter,
38
224
    symbols: &mut SymbolTable,
39
224
    args: &[Expr],
40
224
) -> Result<()> {
41
224
    compile_in(ctx, emit, symbols, KIND, args, Pos::Effect).map(|_| ())
42
224
}
43

            
44
3472
pub(super) fn do_star_form(symbols: &mut SymbolTable, args: &[Expr]) -> Result<Expr> {
45
3472
    eval_loop(symbols, KIND, args)
46
3472
}