use super::*;
impl StructuredBodyLowerer<'_, '_> {
pub(super) fn generic_for_header_instrs(
&self,
header: BlockRef,
) -> Option<(
InstrRef,
crate::transformer::GenericForCallInstr,
crate::transformer::GenericForLoopInstr,
)> {
let range = self.lowering.cfg.blocks[header.index()].instrs;
if range.len < 2 {
return None;
}
let call_instr_ref = InstrRef(range.end() - 2);
let loop_instr_ref = InstrRef(range.end() - 1);
let LowInstr::GenericForCall(call) =
self.lowering.proto.instrs.get(call_instr_ref.index())?
else {
return None;
};
let LowInstr::GenericForLoop(loop_instr) =
self.lowering.proto.instrs.get(loop_instr_ref.index())?
else {
return None;
};
Some((call_instr_ref, *call, *loop_instr))
}
pub(super) fn lower_generic_for_iterator(
&self,
header: BlockRef,
call_instr_ref: InstrRef,
call: crate::transformer::GenericForCallInstr,
) -> Vec<HirExpr> {
(0..call.state.len)
.map(|offset| {
expr_for_reg_use(
self.lowering,
header,
call_instr_ref,
Reg(call.state.start.index() + offset),
)
})
.collect()
}
}