cas_compiler/expr/
break_expr.rs

1use cas_compute::numerical::value::Value;
2use cas_error::Error;
3use cas_parser::parser::ast::loop_expr::Break;
4use crate::{Compile, Compiler, InstructionKind};
5
6impl Compile for Break {
7    fn compile(&self, compiler: &mut Compiler) -> Result<(), Error> {
8        if let Some(value) = &self.value {
9            value.compile(compiler)?;
10        } else {
11            compiler.add_instr(InstructionKind::LoadConst(Value::Unit));
12        }
13
14        let loop_end = compiler.state.loop_end.unwrap();
15        compiler.add_instr(InstructionKind::Jump(loop_end));
16        Ok(())
17    }
18}